MDL-41419 - unit tests: Fixed up sporadic test failures in externallib_test.php.

Also added much needed comments to the unit test.