function SimpleTestTest::stubTest in Zircon Profile 8.0
Same name and namespace in other branches
- 8 core/modules/simpletest/src/Tests/SimpleTestTest.php \Drupal\simpletest\Tests\SimpleTestTest::stubTest()
Test to be run and the results confirmed.
Here we force test results which must match the expected results from confirmStubResults().
1 call to SimpleTestTest::stubTest()
- SimpleTestTest::testWebTestRunner in core/
modules/ simpletest/ src/ Tests/ SimpleTestTest.php - Ensures the tests selected through the web interface are run and displayed.
File
- core/
modules/ simpletest/ src/ Tests/ SimpleTestTest.php, line 155 - Contains \Drupal\simpletest\Tests\SimpleTestTest.
Class
- SimpleTestTest
- Tests SimpleTest's web interface: check that the intended tests were run and ensure that test reports display the intended results. Also test SimpleTest's internal browser and APIs implicitly.
Namespace
Drupal\simpletest\TestsCode
function stubTest() {
// Ensure the .htkey file exists since this is only created just before a
// request. This allows the stub test to make requests. The event does not
// fire here and drupal_generate_test_ua() can not generate a key for a
// test in a test since the prefix has changed.
// @see \Drupal\Core\Test\HttpClientMiddleware\TestHttpClientMiddleware::onBeforeSendRequest()
// @see drupal_generate_test_ua();
$key_file = DRUPAL_ROOT . '/sites/simpletest/' . substr($this->databasePrefix, 10) . '/.htkey';
$private_key = Crypt::randomBytesBase64(55);
$site_path = $this->container
->get('site.path');
file_put_contents($key_file, $private_key);
// Check to see if runtime assertions are indeed on, if successful this
// will be the first of sixteen passes asserted in confirmStubResults()
try {
// Test with minimum possible arguments to make sure no notice for
// missing argument is thrown.
assert(FALSE);
$this
->fail('Runtime assertions are not working.');
} catch (\AssertionError $e) {
try {
// Now test with an error message to ensure it is correctly passed
// along by the rethrow.
assert(FALSE, 'Lorem Ipsum');
} catch (\AssertionError $e) {
$this
->assertEqual($e
->getMessage(), 'Lorem Ipsum', 'Runtime assertions Enabled and running.');
}
}
// This causes the second of the sixteen passes asserted in
// confirmStubResults().
$this
->pass($this->passMessage);
// The first three fails are caused by enabling a non-existent module in
// setUp().
// This causes the fourth of the five fails asserted in
// confirmStubResults().
$this
->fail($this->failMessage);
// This causes the third to fifth of the sixteen passes asserted in
// confirmStubResults().
$user = $this
->drupalCreateUser(array(
$this->validPermission,
), 'SimpleTestTest');
// This causes the fifth of the five fails asserted in confirmStubResults().
$this
->drupalCreateUser(array(
$this->invalidPermission,
));
// Test logging in as a user.
// This causes the sixth to tenth of the sixteen passes asserted in
// confirmStubResults().
$this
->drupalLogin($user);
// This causes the eleventh of the sixteen passes asserted in
// confirmStubResults().
$this
->pass(t('Test ID is @id.', array(
'@id' => $this->testId,
)));
// These cause the twelfth to fifteenth of the sixteen passes asserted in
// confirmStubResults().
$this
->assertTrue(file_exists($site_path . '/settings.testing.php'));
// Check the settings.testing.php file got included.
$this
->assertTrue(function_exists('simpletest_test_stub_settings_function'));
// Check that the test-specific service file got loaded.
$this
->assertTrue($this->container
->has('site.service.yml'));
$this
->assertIdentical(get_class($this->container
->get('cache.backend.database')), 'Drupal\\Core\\Cache\\MemoryBackendFactory');
// These cause the two exceptions asserted in confirmStubResults().
// Call trigger_error() without the required argument to trigger an E_WARNING.
trigger_error();
// Generates a warning inside a PHP function.
array_key_exists(NULL, NULL);
// This causes the sixteenth of the sixteen passes asserted in
// confirmStubResults().
$this
->assertNothing();
// This causes the debug message asserted in confirmStubResults().
debug('Foo', 'Debug', FALSE);
}