Drupal 8.0.0 beta 12. More info: https://www.drupal.org/node/2514176

This commit is contained in:
Pantheon Automation 2015-08-17 17:00:26 -07:00 committed by Greg Anderson
commit 9921556621
13277 changed files with 1459781 additions and 0 deletions

View file

@ -0,0 +1,124 @@
<?php
/**
* @file
* Contains \Drupal\simpletest\Tests\BrokenSetUpTest.
*/
namespace Drupal\simpletest\Tests;
use Drupal\simpletest\WebTestBase;
/**
* Tests a test case that does not call parent::setUp().
*
* If a test case does not call parent::setUp(), running
* \Drupal\simpletest\WebTestBase::tearDown() would destroy the main site's
* database tables. Therefore, we ensure that tests which are not set up
* properly are skipped.
*
* @group simpletest
* @see \Drupal\simpletest\WebTestBase
*/
class BrokenSetUpTest extends WebTestBase {
/**
* Modules to enable.
*
* @var array
*/
public static $modules = array('simpletest');
/**
* The path to the shared trigger file.
*
* @var string
*/
protected $sharedTriggerFile;
protected function setUp() {
// If the test is being run from the main site, set up normally.
if (!$this->isInChildSite()) {
parent::setUp();
$this->sharedTriggerFile = $this->publicFilesDirectory . '/trigger';
// Create and log in user.
$admin_user = $this->drupalCreateUser(array('administer unit tests'));
$this->drupalLogin($admin_user);
}
// If the test is being run from within simpletest, set up the broken test.
else {
$this->sharedTriggerFile = $this->originalFileDirectory . '/trigger';
if (file_get_contents($this->sharedTriggerFile) === 'setup') {
throw new \Exception('Broken setup');
}
$this->pass('The setUp() method has run.');
}
}
protected function tearDown() {
// If the test is being run from the main site, tear down normally.
if (!$this->isInChildSite()) {
unlink($this->sharedTriggerFile);
parent::tearDown();
}
// If the test is being run from within simpletest, output a message.
else {
if (file_get_contents($this->sharedTriggerFile) === 'teardown') {
throw new \Exception('Broken teardown');
}
$this->pass('The tearDown() method has run.');
}
}
/**
* Runs this test case from within the simpletest child site.
*/
function testMethod() {
// If the test is being run from the main site, run it again from the web
// interface within the simpletest child site.
if (!$this->isInChildSite()) {
// Verify that a broken setUp() method is caught.
file_put_contents($this->sharedTriggerFile, 'setup');
$edit['tests[Drupal\simpletest\Tests\BrokenSetUpTest]'] = TRUE;
$this->drupalPostForm('admin/config/development/testing', $edit, t('Run tests'));
$this->assertRaw('Broken setup');
$this->assertNoRaw('The setUp() method has run.');
$this->assertNoRaw('Broken test');
$this->assertNoRaw('The test method has run.');
$this->assertNoRaw('Broken teardown');
$this->assertNoRaw('The tearDown() method has run.');
// Verify that a broken tearDown() method is caught.
file_put_contents($this->sharedTriggerFile, 'teardown');
$edit['tests[Drupal\simpletest\Tests\BrokenSetUpTest]'] = TRUE;
$this->drupalPostForm('admin/config/development/testing', $edit, t('Run tests'));
$this->assertNoRaw('Broken setup');
$this->assertRaw('The setUp() method has run.');
$this->assertNoRaw('Broken test');
$this->assertRaw('The test method has run.');
$this->assertRaw('Broken teardown');
$this->assertNoRaw('The tearDown() method has run.');
// Verify that a broken test method is caught.
file_put_contents($this->sharedTriggerFile, 'test');
$edit['tests[Drupal\simpletest\Tests\BrokenSetUpTest]'] = TRUE;
$this->drupalPostForm('admin/config/development/testing', $edit, t('Run tests'));
$this->assertNoRaw('Broken setup');
$this->assertRaw('The setUp() method has run.');
$this->assertRaw('Broken test');
$this->assertNoRaw('The test method has run.');
$this->assertNoRaw('Broken teardown');
$this->assertRaw('The tearDown() method has run.');
}
// If the test is being run from within simpletest, output a message.
else {
if (file_get_contents($this->sharedTriggerFile) === 'test') {
throw new \Exception('Broken test');
}
$this->pass('The test method has run.');
}
}
}

View file

@ -0,0 +1,116 @@
<?php
/**
* @file
* Contains \Drupal\simpletest\Tests\BrowserTest.
*/
namespace Drupal\simpletest\Tests;
use Drupal\simpletest\WebTestBase;
/**
* Tests the internal browser of the testing framework.
*
* @group simpletest
*/
class BrowserTest extends WebTestBase {
/**
* A flag indicating whether a cookie has been set in a test.
*
* @var bool
*/
protected static $cookieSet = FALSE;
/**
* Test \Drupal\simpletest\WebTestBase::getAbsoluteUrl().
*/
function testGetAbsoluteUrl() {
$url = 'user/login';
$this->drupalGet($url);
$absolute = \Drupal::url('user.login', array(), array('absolute' => TRUE));
$this->assertEqual($absolute, $this->url, 'Passed and requested URL are equal.');
$this->assertEqual($this->url, $this->getAbsoluteUrl($this->url), 'Requested and returned absolute URL are equal.');
$this->drupalPostForm(NULL, array(), t('Log in'));
$this->assertEqual($absolute, $this->url, 'Passed and requested URL are equal.');
$this->assertEqual($this->url, $this->getAbsoluteUrl($this->url), 'Requested and returned absolute URL are equal.');
$this->clickLink('Create new account');
$absolute = \Drupal::url('user.register', array(), array('absolute' => TRUE));
$this->assertEqual($absolute, $this->url, 'Passed and requested URL are equal.');
$this->assertEqual($this->url, $this->getAbsoluteUrl($this->url), 'Requested and returned absolute URL are equal.');
}
/**
* Tests XPath escaping.
*/
function testXPathEscaping() {
$testpage = <<< EOF
<html>
<body>
<a href="link1">A "weird" link, just to bother the dumb "XPath 1.0"</a>
<a href="link2">A second "even more weird" link, in memory of George O'Malley</a>
<a href="link3">A \$third$ link, so weird it's worth $1 million</a>
<a href="link4">A fourth link, containing alternative \\1 regex backreferences \\2</a>
</body>
</html>
EOF;
$this->setRawContent($testpage);
// Matches the first link.
$urls = $this->xpath('//a[text()=:text]', array(':text' => 'A "weird" link, just to bother the dumb "XPath 1.0"'));
$this->assertEqual($urls[0]['href'], 'link1', 'Match with quotes.');
$urls = $this->xpath('//a[text()=:text]', array(':text' => 'A second "even more weird" link, in memory of George O\'Malley'));
$this->assertEqual($urls[0]['href'], 'link2', 'Match with mixed single and double quotes.');
$urls = $this->xpath('//a[text()=:text]', array(':text' => 'A $third$ link, so weird it\'s worth $1 million'));
$this->assertEqual($urls[0]['href'], 'link3', 'Match with a regular expression back reference symbol (dollar sign).');
$urls = $this->xpath('//a[text()=:text]', array(':text' => 'A fourth link, containing alternative \\1 regex backreferences \\2'));
$this->assertEqual($urls[0]['href'], 'link4', 'Match with another regular expression back reference symbol (double backslash).');
}
/**
* Tests that cookies set during a request are available for testing.
*/
public function testCookies() {
// Check that the $this->cookies property is populated when a user logs in.
$user = $this->drupalCreateUser();
$edit = ['name' => $user->getUsername(), 'pass' => $user->pass_raw];
$this->drupalPostForm('<front>', $edit, t('Log in'));
$this->assertEqual(count($this->cookies), 1, 'A cookie is set when the user logs in.');
// Check that the name and value of the cookie match the request data.
$cookie_header = $this->drupalGetHeader('set-cookie', TRUE);
// The name and value are located at the start of the string, separated by
// an equals sign and ending in a semicolon.
preg_match('/^([^=]+)=([^;]+)/', $cookie_header, $matches);
$name = $matches[1];
$value = $matches[2];
$this->assertTrue(array_key_exists($name, $this->cookies), 'The cookie name is correct.');
$this->assertEqual($value, $this->cookies[$name]['value'], 'The cookie value is correct.');
// Set a flag indicating that a cookie has been set in this test.
// @see testCookieDoesNotBleed()
static::$cookieSet = TRUE;
}
/**
* Tests that the cookies from a previous test do not bleed into a new test.
*
* @see static::testCookies()
*/
public function testCookieDoesNotBleed() {
// In order for this test to be effective it should always run after the
// testCookies() test.
$this->assertTrue(static::$cookieSet, 'Tests have been executed in the expected order.');
$this->assertEqual(count($this->cookies), 0, 'No cookies are present at the start of a new test.');
}
}

View file

@ -0,0 +1,31 @@
<?php
/**
* @file
* Contains \Drupal\simpletest\Tests\FolderTest.
*/
namespace Drupal\simpletest\Tests;
use Drupal\simpletest\WebTestBase;
/**
* This test will check SimpleTest's treatment of hook_install during setUp.
* Image module is used for test.
*
* @group simpletest
*/
class FolderTest extends WebTestBase {
/**
* Modules to enable.
*
* @var array
*/
public static $modules = array('image');
function testFolderSetup() {
$directory = file_default_scheme() . '://styles';
$this->assertTrue(file_prepare_directory($directory, FALSE), 'Directory created.');
}
}

View file

@ -0,0 +1,66 @@
<?php
/**
* @file
* Contains \Drupal\simpletest\Tests\InstallationProfileModuleTestsTest.
*/
namespace Drupal\simpletest\Tests;
use Drupal\simpletest\WebTestBase;
/**
* Verifies that tests bundled with installation profile modules are found.
*
* @group simpletest
*/
class InstallationProfileModuleTestsTest extends WebTestBase {
/**
* Modules to enable.
*
* @var array
*/
public static $modules = array('simpletest');
/**
* An administrative user with permission to adminsiter unit tests.
*
* @var \Drupal\user\UserInterface
*/
protected $adminUser;
/**
* Use the Testing profile.
*
* The Testing profile contains drupal_system_listing_compatible_test.test,
* which attempts to:
* - run tests using the Minimal profile (which does not contain the
* drupal_system_listing_compatible_test.module)
* - but still install the drupal_system_listing_compatible_test.module
* contained in the Testing profile.
*
* @see \Drupal\drupal_system_listing_compatible_test\Tests\SystemListingCompatibleTest
*/
protected $profile = 'testing';
protected function setUp() {
parent::setUp();
$this->adminUser = $this->drupalCreateUser(array('administer unit tests'));
$this->drupalLogin($this->adminUser);
}
/**
* Tests existence of test case located in an installation profile module.
*/
function testInstallationProfileTests() {
$this->drupalGet('admin/config/development/testing');
$this->assertText('Drupal\drupal_system_listing_compatible_test\Tests\SystemListingCompatibleTest');
$edit = array(
'tests[Drupal\drupal_system_listing_compatible_test\Tests\SystemListingCompatibleTest]' => TRUE,
);
$this->drupalPostForm(NULL, $edit, t('Run tests'));
$this->assertText('SystemListingCompatibleTest test executed.');
}
}

View file

@ -0,0 +1,327 @@
<?php
/**
* @file
* Contains \Drupal\simpletest\Tests\KernelTestBaseTest.
*/
namespace Drupal\simpletest\Tests;
use Drupal\simpletest\KernelTestBase;
/**
* Tests KernelTestBase functionality.
*
* @group simpletest
*/
class KernelTestBaseTest extends KernelTestBase {
/**
* Modules to enable.
*
* @var array
*/
public static $modules = array('entity_test');
/**
* {@inheritdoc}
*/
protected function setUp() {
$php = <<<'EOS'
<?php
# Make sure that the $test_class variable is defined when this file is included.
if ($test_class) {
}
# Define a function to be able to check that this file was loaded with
# function_exists().
if (!function_exists('simpletest_test_stub_settings_function')) {
function simpletest_test_stub_settings_function() {}
}
EOS;
$settings_testing_file = $this->siteDirectory . '/settings.testing.php';
file_put_contents($settings_testing_file, $php);
$original_container = $this->originalContainer;
parent::setUp();
$this->assertNotIdentical(\Drupal::getContainer(), $original_container, 'KernelTestBase test creates a new container.');
}
/**
* Tests expected behavior of setUp().
*/
function testSetUp() {
$modules = array('entity_test');
$table = 'entity_test';
// Verify that specified $modules have been loaded.
$this->assertTrue(function_exists('entity_test_entity_bundle_info'), 'entity_test.module was loaded.');
// Verify that there is a fixed module list.
$this->assertIdentical(array_keys(\Drupal::moduleHandler()->getModuleList()), $modules);
$this->assertIdentical(\Drupal::moduleHandler()->getImplementations('entity_bundle_info'), ['entity_test']);
$this->assertIdentical(\Drupal::moduleHandler()->getImplementations('entity_type_alter'), ['entity_test']);
// Verify that no modules have been installed.
$this->assertFalse(db_table_exists($table), "'$table' database table not found.");
// Verify that the settings.testing.php got taken into account.
$this->assertTrue(function_exists('simpletest_test_stub_settings_function'));
}
/**
* Tests expected load behavior of enableModules().
*/
function testEnableModulesLoad() {
$module = 'field_test';
// Verify that the module does not exist yet.
$this->assertFalse(\Drupal::moduleHandler()->moduleExists($module), "$module module not found.");
$list = array_keys(\Drupal::moduleHandler()->getModuleList());
$this->assertFalse(in_array($module, $list), "$module module not found in the extension handler's module list.");
$list = \Drupal::moduleHandler()->getImplementations('entity_display_build_alter');
$this->assertFalse(in_array($module, $list), "{$module}_entity_display_build_alter() in \Drupal::moduleHandler()->getImplementations() not found.");
// Enable the module.
$this->enableModules(array($module));
// Verify that the module exists.
$this->assertTrue(\Drupal::moduleHandler()->moduleExists($module), "$module module found.");
$list = array_keys(\Drupal::moduleHandler()->getModuleList());
$this->assertTrue(in_array($module, $list), "$module module found in the extension handler's module list.");
$list = \Drupal::moduleHandler()->getImplementations('query_efq_table_prefixing_test_alter');
$this->assertTrue(in_array($module, $list), "{$module}_query_efq_table_prefixing_test_alter() in \Drupal::moduleHandler()->getImplementations() found.");
}
/**
* Tests expected installation behavior of enableModules().
*/
function testEnableModulesInstall() {
$module = 'module_test';
$table = 'module_test';
// Verify that the module does not exist yet.
$this->assertFalse(\Drupal::moduleHandler()->moduleExists($module), "$module module not found.");
$list = array_keys(\Drupal::moduleHandler()->getModuleList());
$this->assertFalse(in_array($module, $list), "$module module not found in the extension handler's module list.");
$list = \Drupal::moduleHandler()->getImplementations('hook_info');
$this->assertFalse(in_array($module, $list), "{$module}_hook_info() in \Drupal::moduleHandler()->getImplementations() not found.");
$this->assertFalse(db_table_exists($table), "'$table' database table not found.");
// Install the module.
\Drupal::service('module_installer')->install(array($module));
// Verify that the enabled module exists.
$this->assertTrue(\Drupal::moduleHandler()->moduleExists($module), "$module module found.");
$list = array_keys(\Drupal::moduleHandler()->getModuleList());
$this->assertTrue(in_array($module, $list), "$module module found in the extension handler's module list.");
$list = \Drupal::moduleHandler()->getImplementations('hook_info');
$this->assertTrue(in_array($module, $list), "{$module}_hook_info() in \Drupal::moduleHandler()->getImplementations() found.");
$this->assertTrue(db_table_exists($table), "'$table' database table found.");
$schema = drupal_get_module_schema($module, $table);
$this->assertTrue($schema, "'$table' table schema found.");
}
/**
* Tests installing modules with DependencyInjection services.
*/
function testEnableModulesInstallContainer() {
// Install Node module.
$this->enableModules(array('user', 'field', 'node'));
$this->installEntitySchema('node', array('node', 'node_field_data'));
// Perform an entity query against node.
$query = \Drupal::entityQuery('node');
// Disable node access checks, since User module is not enabled.
$query->accessCheck(FALSE);
$query->condition('nid', 1);
$query->execute();
$this->pass('Entity field query was executed.');
}
/**
* Tests expected behavior of installSchema().
*/
function testInstallSchema() {
$module = 'entity_test';
$table = 'entity_test_example';
// Verify that we can install a table from the module schema.
$this->installSchema($module, $table);
$this->assertTrue(db_table_exists($table), "'$table' database table found.");
// Verify that the schema is known to Schema API.
$schema = drupal_get_module_schema($module, $table);
$this->assertTrue($schema, "'$table' table schema found.");
// Verify that a unknown table from an enabled module throws an error.
$table = 'unknown_entity_test_table';
try {
$this->installSchema($module, $table);
$this->fail('Exception for non-retrievable schema found.');
}
catch (\Exception $e) {
$this->pass('Exception for non-retrievable schema found.');
}
$this->assertFalse(db_table_exists($table), "'$table' database table not found.");
$schema = drupal_get_module_schema($module, $table);
$this->assertFalse($schema, "'$table' table schema not found.");
// Verify that a table from a unknown module cannot be installed.
$module = 'database_test';
$table = 'test';
try {
$this->installSchema($module, $table);
$this->fail('Exception for non-retrievable schema found.');
}
catch (\Exception $e) {
$this->pass('Exception for non-retrievable schema found.');
}
$this->assertFalse(db_table_exists($table), "'$table' database table not found.");
$schema = drupal_get_module_schema($module, $table);
$this->assertTrue($schema, "'$table' table schema found.");
// Verify that the same table can be installed after enabling the module.
$this->enableModules(array($module));
$this->installSchema($module, $table);
$this->assertTrue(db_table_exists($table), "'$table' database table found.");
$schema = drupal_get_module_schema($module, $table);
$this->assertTrue($schema, "'$table' table schema found.");
}
/**
* Tests expected behavior of installEntitySchema().
*/
function testInstallEntitySchema() {
$entity = 'entity_test';
// The entity_test Entity has a field that depends on the User module.
$this->enableModules(array('user'));
// Verity that the entity schema is created properly.
$this->installEntitySchema($entity);
$this->assertTrue(db_table_exists($entity), "'$entity' database table found.");
}
/**
* Tests expected behavior of installConfig().
*/
function testInstallConfig() {
// The user module has configuration that depends on system.
$this->enableModules(array('system'));
$module = 'user';
// Verify that default config can only be installed for enabled modules.
try {
$this->installConfig(array($module));
$this->fail('Exception for non-enabled module found.');
}
catch (\Exception $e) {
$this->pass('Exception for non-enabled module found.');
}
$this->assertFalse($this->container->get('config.storage')->exists('user.settings'));
// Verify that default config can be installed.
$this->enableModules(array('user'));
$this->installConfig(array('user'));
$this->assertTrue($this->container->get('config.storage')->exists('user.settings'));
$this->assertTrue($this->config('user.settings')->get('register'));
}
/**
* Tests that the module list is retained after enabling/installing/disabling.
*/
function testEnableModulesFixedList() {
// Install system module.
$this->container->get('module_installer')->install(array('system', 'menu_link_content'));
$entity_manager = \Drupal::entityManager();
// entity_test is loaded via $modules; its entity type should exist.
$this->assertEqual($this->container->get('module_handler')->moduleExists('entity_test'), TRUE);
$this->assertTrue(TRUE == $entity_manager->getDefinition('entity_test'));
// Load some additional modules; entity_test should still exist.
$this->enableModules(array('field', 'text', 'entity_test'));
$this->assertEqual($this->container->get('module_handler')->moduleExists('entity_test'), TRUE);
$this->assertTrue(TRUE == $entity_manager->getDefinition('entity_test'));
// Install some other modules; entity_test should still exist.
$this->container->get('module_installer')->install(array('user', 'field', 'field_test'), FALSE);
$this->assertEqual($this->container->get('module_handler')->moduleExists('entity_test'), TRUE);
$this->assertTrue(TRUE == $entity_manager->getDefinition('entity_test'));
// Uninstall one of those modules; entity_test should still exist.
$this->container->get('module_installer')->uninstall(array('field_test'));
$this->assertEqual($this->container->get('module_handler')->moduleExists('entity_test'), TRUE);
$this->assertTrue(TRUE == $entity_manager->getDefinition('entity_test'));
// Set the weight of a module; entity_test should still exist.
module_set_weight('field', -1);
$this->assertEqual($this->container->get('module_handler')->moduleExists('entity_test'), TRUE);
$this->assertTrue(TRUE == $entity_manager->getDefinition('entity_test'));
// Reactivate the previously uninstalled module.
$this->enableModules(array('field_test'));
// Create a field.
entity_create('entity_view_display', array(
'targetEntityType' => 'entity_test',
'bundle' => 'entity_test',
'mode' => 'default',
));
$field_storage = entity_create('field_storage_config', array(
'field_name' => 'test_field',
'entity_type' => 'entity_test',
'type' => 'test_field'
));
$field_storage->save();
entity_create('field_config', array(
'field_storage' => $field_storage,
'bundle' => 'entity_test',
))->save();
}
/**
* Tests that _theme() works right after loading a module.
*/
function testEnableModulesTheme() {
/** @var \Drupal\Core\Render\RendererInterface $renderer */
$renderer = $this->container->get('renderer');
$original_element = $element = array(
'#type' => 'container',
'#markup' => 'Foo',
'#attributes' => array(),
);
$this->enableModules(array('system'));
// _theme() throws an exception if modules are not loaded yet.
$this->assertTrue($renderer->renderRoot($element));
$element = $original_element;
$this->disableModules(array('entity_test'));
$this->assertTrue($renderer->renderRoot($element));
}
/**
* Tests that there is no theme by default.
*/
function testNoThemeByDefault() {
$themes = $this->config('core.extension')->get('theme');
$this->assertEqual($themes, array());
$extensions = $this->container->get('config.storage')->read('core.extension');
$this->assertEqual($extensions['theme'], array());
$active_theme = $this->container->get('theme.manager')->getActiveTheme();
$this->assertEqual($active_theme->getName(), 'core');
}
/**
* Tests that drupal_get_profile() returns NULL.
*
* As the currently active installation profile is used when installing
* configuration, for example, this is essential to ensure test isolation.
*/
public function testDrupalGetProfile() {
$this->assertNull(drupal_get_profile());
}
}

View file

@ -0,0 +1,82 @@
<?php
/**
* @file
* Contains \Drupal\simpletest\Tests\MailCaptureTest.
*/
namespace Drupal\simpletest\Tests;
use Drupal\simpletest\WebTestBase;
/**
* Tests the SimpleTest email capturing logic, the assertMail assertion and the
* drupalGetMails function.
*
* @group simpletest
*/
class MailCaptureTest extends WebTestBase {
/**
* Test to see if the wrapper function is executed correctly.
*/
function testMailSend() {
// Create an email.
$subject = $this->randomString(64);
$body = $this->randomString(128);
$message = array(
'id' => 'drupal_mail_test',
'headers' => array('Content-type'=> 'text/html'),
'subject' => $subject,
'to' => 'foobar@example.com',
'body' => $body,
);
// Before we send the email, drupalGetMails should return an empty array.
$captured_emails = $this->drupalGetMails();
$this->assertEqual(count($captured_emails), 0, 'The captured emails queue is empty.', 'Email');
// Send the email.
\Drupal::service('plugin.manager.mail')->getInstance(array('module' => 'simpletest', 'key' => 'drupal_mail_test'))->mail($message);
// Ensure that there is one email in the captured emails array.
$captured_emails = $this->drupalGetMails();
$this->assertEqual(count($captured_emails), 1, 'One email was captured.', 'Email');
// Assert that the email was sent by iterating over the message properties
// and ensuring that they are captured intact.
foreach ($message as $field => $value) {
$this->assertMail($field, $value, format_string('The email was sent and the value for property @field is intact.', array('@field' => $field)), 'Email');
}
// Send additional emails so more than one email is captured.
for ($index = 0; $index < 5; $index++) {
$message = array(
'id' => 'drupal_mail_test_' . $index,
'headers' => array('Content-type'=> 'text/html'),
'subject' => $this->randomString(64),
'to' => $this->randomMachineName(32) . '@example.com',
'body' => $this->randomString(512),
);
\Drupal::service('plugin.manager.mail')->getInstance(array('module' => 'drupal_mail_test', 'key' => $index))->mail($message);
}
// There should now be 6 emails captured.
$captured_emails = $this->drupalGetMails();
$this->assertEqual(count($captured_emails), 6, 'All emails were captured.', 'Email');
// Test different ways of getting filtered emails via drupalGetMails().
$captured_emails = $this->drupalGetMails(array('id' => 'drupal_mail_test'));
$this->assertEqual(count($captured_emails), 1, 'Only one email is returned when filtering by id.', 'Email');
$captured_emails = $this->drupalGetMails(array('id' => 'drupal_mail_test', 'subject' => $subject));
$this->assertEqual(count($captured_emails), 1, 'Only one email is returned when filtering by id and subject.', 'Email');
$captured_emails = $this->drupalGetMails(array('id' => 'drupal_mail_test', 'subject' => $subject, 'from' => 'this_was_not_used@example.com'));
$this->assertEqual(count($captured_emails), 0, 'No emails are returned when querying with an unused from address.', 'Email');
// Send the last email again, so we can confirm that the
// drupalGetMails-filter correctly returns all emails with a given
// property/value.
\Drupal::service('plugin.manager.mail')->getInstance(array('module' => 'drupal_mail_test', 'key' => $index))->mail($message);
$captured_emails = $this->drupalGetMails(array('id' => 'drupal_mail_test_4'));
$this->assertEqual(count($captured_emails), 2, 'All emails with the same id are returned when filtering by id.', 'Email');
}
}

View file

@ -0,0 +1,61 @@
<?php
/**
* @file
* Contains \Drupal\simpletest\Tests\MissingCheckedRequirementsTest.
*/
namespace Drupal\simpletest\Tests;
use Drupal\simpletest\WebTestBase;
/**
* Tests a test case with missing requirements.
*
* @group simpletest
*/
class MissingCheckedRequirementsTest extends WebTestBase {
/**
* Modules to enable.
*
* @var array
*/
public static $modules = array('simpletest');
protected function setUp() {
parent::setUp();
$admin_user = $this->drupalCreateUser(array('administer unit tests'));
$this->drupalLogin($admin_user);
}
/**
* Overrides checkRequirements().
*/
protected function checkRequirements() {
if ($this->isInChildSite()) {
return array(
'Test is not allowed to run.'
);
}
return parent::checkRequirements();
}
/**
* Ensures test will not run when requirements are missing.
*/
public function testCheckRequirements() {
// If this is the main request, run the web test script and then assert
// that the child tests did not run.
if (!$this->isInChildSite()) {
// Run this test from web interface.
$edit['tests[Drupal\simpletest\Tests\MissingCheckedRequirementsTest]'] = TRUE;
$this->drupalPostForm('admin/config/development/testing', $edit, t('Run tests'));
$this->assertRaw('Test is not allowed to run.', 'Test check for requirements came up.');
$this->assertNoText('Test ran when it failed requirements check.', 'Test requirements stopped test from running.');
}
else {
$this->fail('Test ran when it failed requirements check.');
}
}
}

View file

@ -0,0 +1,26 @@
<?php
/**
* @file
* Contains \Drupal\simpletest\Tests\MissingDependentModuleUnitTest.
*/
namespace Drupal\simpletest\Tests;
use Drupal\simpletest\KernelTestBase;
/**
* This test should not load since it requires a module that is not found.
*
* @group simpletest
* @dependencies simpletest_missing_module
*/
class MissingDependentModuleUnitTest extends KernelTestBase {
/**
* Ensure that this test will not be loaded despite its dependency.
*/
function testFail() {
$this->fail('Running test with missing required module.');
}
}

View file

@ -0,0 +1,69 @@
<?php
/**
* @file
* Contains \Drupal\simpletest\Tests\OtherInstallationProfileTestsTest.
*/
namespace Drupal\simpletest\Tests;
use Drupal\simpletest\WebTestBase;
/**
* Verifies that tests in other installation profiles are found.
*
* @group simpletest
* @see SimpleTestInstallationProfileModuleTestsTestCase
*/
class OtherInstallationProfileTestsTest extends WebTestBase {
/**
* Modules to enable.
*
* @var array
*/
public static $modules = array('simpletest');
/**
* Use the Minimal profile.
*
* The Testing profile contains drupal_system_listing_compatible_test.test,
* which should be found.
*
* The Standard profile contains \Drupal\standard\Tests\StandardTest, which
* should be found.
*
* @see \Drupal\simpletest\Tests\InstallationProfileModuleTestsTest
* @see \Drupal\drupal_system_listing_compatible_test\Tests\SystemListingCompatibleTest
*/
protected $profile = 'minimal';
/**
* An administrative user with permission to administer unit tests.
*
* @var \Drupal\user\UserInterface
*/
protected $adminUser;
protected function setUp() {
parent::setUp();
$this->adminUser = $this->drupalCreateUser(array('administer unit tests'));
$this->drupalLogin($this->adminUser);
}
/**
* Tests that tests located in another installation profile appear.
*/
function testOtherInstallationProfile() {
// Assert the existence of a test in a different installation profile than
// the current.
$this->drupalGet('admin/config/development/testing');
$this->assertText('Tests Standard installation profile expectations.');
// Assert the existence of a test for a module in a different installation
// profile than the current.
$this->assertText('Drupal\drupal_system_listing_compatible_test\Tests\SystemListingCompatibleTest');
}
}

View file

@ -0,0 +1,150 @@
<?php
/**
* @file
* Contains \Drupal\simpletest\Tests\SimpleTestBrowserTest.
*/
namespace Drupal\simpletest\Tests;
use Drupal\Core\Url;
use Drupal\simpletest\WebTestBase;
/**
* Tests the Simpletest UI internal browser.
*
* @group simpletest
*/
class SimpleTestBrowserTest extends WebTestBase {
/**
* Modules to enable.
*
* @var array
*/
public static $modules = array('simpletest', 'test_page_test');
public function setUp() {
parent::setUp();
// Create and log in an admin user.
$this->drupalLogin($this->drupalCreateUser(array('administer unit tests')));
}
/**
* Test the internal browsers functionality.
*/
public function testInternalBrowser() {
// Retrieve the test page and check its title and headers.
$this->drupalGet('test-page');
$this->assertTrue($this->drupalGetHeader('Date'), 'An HTTP header was received.');
$this->assertTitle(t('Test page | @site-name', array(
'@site-name' => $this->config('system.site')->get('name'),
)));
$this->assertNoTitle('Foo');
$old_user_id = $this->container->get('current_user')->id();
$user = $this->drupalCreateUser();
$this->drupalLogin($user);
// Check that current user service updated.
$this->assertNotEqual($old_user_id, $this->container->get('current_user')->id(), 'Current user service updated.');
$headers = $this->drupalGetHeaders(TRUE);
$this->assertEqual(count($headers), 2, 'There was one intermediate request.');
$this->assertTrue(strpos($headers[0][':status'], '303') !== FALSE, 'Intermediate response code was 303.');
$this->assertFalse(empty($headers[0]['location']), 'Intermediate request contained a Location header.');
$this->assertEqual($this->getUrl(), $headers[0]['location'], 'HTTP redirect was followed');
$this->assertFalse($this->drupalGetHeader('Location'), 'Headers from intermediate request were reset.');
$this->assertResponse(200, 'Response code from intermediate request was reset.');
$this->drupalLogout();
// Check that current user service updated to anonymous user.
$this->assertEqual(0, $this->container->get('current_user')->id(), 'Current user service updated.');
// Test the maximum redirection option.
$this->maximumRedirects = 1;
$edit = array(
'name' => $user->getUsername(),
'pass' => $user->pass_raw
);
$this->drupalPostForm('user/login', $edit, t('Log in'), array(
'query' => array('destination' => 'user/logout'),
));
$headers = $this->drupalGetHeaders(TRUE);
$this->assertEqual(count($headers), 2, 'Simpletest stopped following redirects after the first one.');
// Remove the Simpletest private key file so we can test the protection
// against requests that forge a valid testing user agent to gain access
// to the installer.
// @see drupal_valid_test_ua()
// Not using File API; a potential error must trigger a PHP warning.
unlink($this->siteDirectory . '/.htkey');
$this->drupalGet(Url::fromUri('base:core/install.php', array('external' => TRUE, 'absolute' => TRUE))->toString());
$this->assertResponse(403, 'Cannot access install.php.');
}
/**
* Test validation of the User-Agent header we use to perform test requests.
*/
public function testUserAgentValidation() {
global $base_url;
// Logout the user which was logged in during test-setup.
$this->drupalLogout();
$system_path = $base_url . '/' . drupal_get_path('module', 'system');
$HTTP_path = $system_path .'/tests/http.php/user/login';
$https_path = $system_path .'/tests/https.php/user/login';
// Generate a valid simpletest User-Agent to pass validation.
$this->assertTrue(preg_match('/simpletest\d+/', $this->databasePrefix, $matches), 'Database prefix contains simpletest prefix.');
$test_ua = drupal_generate_test_ua($matches[0]);
$this->additionalCurlOptions = array(CURLOPT_USERAGENT => $test_ua);
// Test pages only available for testing.
$this->drupalGet($HTTP_path);
$this->assertResponse(200, 'Requesting http.php with a legitimate simpletest User-Agent returns OK.');
$this->drupalGet($https_path);
$this->assertResponse(200, 'Requesting https.php with a legitimate simpletest User-Agent returns OK.');
// Now slightly modify the HMAC on the header, which should not validate.
$this->additionalCurlOptions = array(CURLOPT_USERAGENT => $test_ua . 'X');
$this->drupalGet($HTTP_path);
$this->assertResponse(403, 'Requesting http.php with a bad simpletest User-Agent fails.');
$this->drupalGet($https_path);
$this->assertResponse(403, 'Requesting https.php with a bad simpletest User-Agent fails.');
// Use a real User-Agent and verify that the special files http.php and
// https.php can't be accessed.
$this->additionalCurlOptions = array(CURLOPT_USERAGENT => 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; en-US; rv:1.9.2.12) Gecko/20101026 Firefox/3.6.12');
$this->drupalGet($HTTP_path);
$this->assertResponse(403, 'Requesting http.php with a normal User-Agent fails.');
$this->drupalGet($https_path);
$this->assertResponse(403, 'Requesting https.php with a normal User-Agent fails.');
}
/**
* Tests that PHPUnit and KernelTestBase tests work through the UI.
*/
public function testTestingThroughUI() {
// We can not test WebTestBase tests here since they require a valid .htkey
// to be created. However this scenario is covered by the testception of
// \Drupal\simpletest\Tests\SimpleTestTest.
$tests = array(
// A KernelTestBase test.
'Drupal\system\Tests\DrupalKernel\DrupalKernelTest',
// A PHPUnit unit test.
'Drupal\Tests\action\Unit\Menu\ActionLocalTasksTest',
// A PHPUnit functional test.
'Drupal\Tests\simpletest\Functional\BrowserTestBaseTest',
);
foreach ($tests as $test) {
$this->drupalGet('admin/config/development/testing');
$edit = array(
"tests[$test]" => TRUE,
);
$this->drupalPostForm(NULL, $edit, t('Run tests'));
$this->assertText('0 fails, 0 exceptions');
}
}
}

View file

@ -0,0 +1,39 @@
<?php
/**
* @file
* Contains \Drupal\simpletest\Tests\SimpleTestInstallBatchTest.
*/
namespace Drupal\simpletest\Tests;
use Drupal\simpletest\WebTestBase;
/**
* Tests batch operations during tests execution.
*
* This demonstrates that a batch will be successfully executed during module
* installation when running tests.
*
* @group simpletest
*/
class SimpleTestInstallBatchTest extends WebTestBase {
/**
* Modules to enable.
*
* @var array
*/
public static $modules = array('simpletest', 'simpletest_test', 'entity_test');
/**
* Tests loading entities created in a batch in simpletest_test_install().
*/
public function testLoadingEntitiesCreatedInBatch() {
$entity1 = entity_load('entity_test', 1);
$this->assertNotNull($entity1, 'Successfully loaded entity 1.');
$entity2 = entity_load('entity_test', 2);
$this->assertNotNull($entity2, 'Successfully loaded entity 2.');
}
}

View file

@ -0,0 +1,356 @@
<?php
/**
* @file
* Contains \Drupal\simpletest\Tests\SimpleTestTest.
*/
namespace Drupal\simpletest\Tests;
use Drupal\Component\Utility\Crypt;
use Drupal\simpletest\WebTestBase;
/**
* 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.
*
* @group simpletest
*/
class SimpleTestTest extends WebTestBase {
/**
* Modules to enable.
*
* @var array
*/
public static $modules = ['simpletest'];
/**
* The results array that has been parsed by getTestResults().
*
* @var array
*/
protected $childTestResults;
/**
* Stores the test ID from each test run for comparison.
*
* Used to ensure they are incrementing.
*/
protected $testIds = array();
/**
* Translated fail message.
*
* @var string
*/
private $failMessage = '';
/**
* Translated pass message.
* @var string
*/
private $passMessage = '';
/**
* A valid and recognized permission.
*
* @var string
*/
protected $validPermission;
/**
* An invalid or unrecognized permission.
*
* @var string
*/
protected $invalidPermission;
protected function setUp() {
if (!$this->isInChildSite()) {
$php = <<<'EOD'
<?php
# Make sure that the $test_class variable is defined when this file is included.
if ($test_class) {
}
# Define a function to be able to check that this file was loaded with
# function_exists().
if (!function_exists('simpletest_test_stub_settings_function')) {
function simpletest_test_stub_settings_function() {}
}
EOD;
file_put_contents($this->siteDirectory. '/' . 'settings.testing.php', $php);
// @see \Drupal\system\Tests\DrupalKernel\DrupalKernelSiteTest
$class = __CLASS__;
$yaml = <<<EOD
services:
# Add a new service.
site.service.yml:
class: $class
# Swap out a core service.
cache.backend.database:
class: Drupal\Core\Cache\MemoryBackendFactory
EOD;
file_put_contents($this->siteDirectory . '/testing.services.yml', $yaml);
$original_container = $this->originalContainer;
parent::setUp();
$this->assertNotIdentical(\Drupal::getContainer(), $original_container, 'WebTestBase test creates a new container.');
// Create and log in an admin user.
$this->drupalLogin($this->drupalCreateUser(array('administer unit tests')));
}
else {
// This causes three of the five fails that are asserted in
// confirmStubResults().
self::$modules = array('non_existent_module');
parent::setUp();
}
}
/**
* Ensures the tests selected through the web interface are run and displayed.
*/
function testWebTestRunner() {
$this->passMessage = t('SimpleTest pass.');
$this->failMessage = t('SimpleTest fail.');
$this->validPermission = 'access administration pages';
$this->invalidPermission = 'invalid permission';
if ($this->isInChildSite()) {
// Only run following code if this test is running itself through a CURL
// request.
$this->stubTest();
}
else {
// Run twice so test_ids can be accumulated.
for ($i = 0; $i < 2; $i++) {
// Run this test from web interface.
$this->drupalGet('admin/config/development/testing');
$edit = array();
$edit['tests[Drupal\simpletest\Tests\SimpleTestTest]'] = TRUE;
$this->drupalPostForm(NULL, $edit, t('Run tests'));
// Parse results and confirm that they are correct.
$this->getTestResults();
$this->confirmStubTestResults();
}
// Regression test for #290316.
// Check that test_id is incrementing.
$this->assertTrue($this->testIds[0] != $this->testIds[1], 'Test ID is incrementing.');
}
}
/**
* Test to be run and the results confirmed.
*
* Here we force test results which must match the expected results from
* confirmStubResults().
*/
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\EventSubscriber\HttpRequestSubscriber::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);
// This causes the first of the fifteen 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 second to fourth of the fifteen 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 fifth to ninth of the fifteen passes asserted in
// confirmStubResults().
$this->drupalLogin($user);
// This causes the tenth of the fifteen passes asserted in
// confirmStubResults().
$this->pass(t('Test ID is @id.', array('@id' => $this->testId)));
// These cause the eleventh to fourteenth of the fifteen 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 fifteenth of the fifteen passes asserted in
// confirmStubResults().
$this->assertNothing();
// This causes the debug message asserted in confirmStubResults().
debug('Foo', 'Debug', FALSE);
}
/**
* Assert nothing.
*/
function assertNothing() {
$this->pass("This is nothing.");
}
/**
* Confirm that the stub test produced the desired results.
*/
function confirmStubTestResults() {
$this->assertAssertion(t('Unable to install modules %modules due to missing modules %missing.', array('%modules' => 'non_existent_module', '%missing' => 'non_existent_module')), 'Other', 'Fail', 'SimpleTestTest.php', 'Drupal\simpletest\Tests\SimpleTestTest->setUp()');
$this->assertAssertion($this->passMessage, 'Other', 'Pass', 'SimpleTestTest.php', 'Drupal\simpletest\Tests\SimpleTestTest->stubTest()');
$this->assertAssertion($this->failMessage, 'Other', 'Fail', 'SimpleTestTest.php', 'Drupal\simpletest\Tests\SimpleTestTest->stubTest()');
$this->assertAssertion(t('Created permissions: @perms', array('@perms' => $this->validPermission)), 'Role', 'Pass', 'SimpleTestTest.php', 'Drupal\simpletest\Tests\SimpleTestTest->stubTest()');
$this->assertAssertion(t('Invalid permission %permission.', array('%permission' => $this->invalidPermission)), 'Role', 'Fail', 'SimpleTestTest.php', 'Drupal\simpletest\Tests\SimpleTestTest->stubTest()');
// Check that the user was logged in successfully.
$this->assertAssertion('User SimpleTestTest successfully logged in.', 'User login', 'Pass', 'SimpleTestTest.php', 'Drupal\simpletest\Tests\SimpleTestTest->stubTest()');
// Check that a warning is caught by simpletest. The exact error message
// differs between PHP versions so only the function name is checked.
$this->assertAssertion('trigger_error()', 'Warning', 'Fail', 'SimpleTestTest.php', 'Drupal\simpletest\Tests\SimpleTestTest->stubTest()');
// Check that the backtracing code works for specific assert function.
$this->assertAssertion('This is nothing.', 'Other', 'Pass', 'SimpleTestTest.php', 'Drupal\simpletest\Tests\SimpleTestTest->stubTest()');
// Check that errors that occur inside PHP internal functions are correctly
// reported. The exact error message differs between PHP versions so we
// check only the function name 'array_key_exists'.
$this->assertAssertion('array_key_exists', 'Warning', 'Fail', 'SimpleTestTest.php', 'Drupal\simpletest\Tests\SimpleTestTest->stubTest()');
$this->assertAssertion("Debug: 'Foo'", 'Debug', 'Fail', 'SimpleTestTest.php', 'Drupal\simpletest\Tests\SimpleTestTest->stubTest()');
$this->assertEqual('15 passes, 3 fails, 2 exceptions, 3 debug messages', $this->childTestResults['summary']);
$this->testIds[] = $test_id = $this->getTestIdFromResults();
$this->assertTrue($test_id, 'Found test ID in results.');
}
/**
* Fetch the test id from the test results.
*/
function getTestIdFromResults() {
foreach ($this->childTestResults['assertions'] as $assertion) {
if (preg_match('@^Test ID is ([0-9]*)\.$@', $assertion['message'], $matches)) {
return $matches[1];
}
}
return NULL;
}
/**
* Asserts that an assertion with specified values is displayed in results.
*
* @param string $message Assertion message.
* @param string $type Assertion type.
* @param string $status Assertion status.
* @param string $file File where the assertion originated.
* @param string $function Function where the assertion originated.
*
* @return Assertion result.
*/
function assertAssertion($message, $type, $status, $file, $function) {
$message = trim(strip_tags($message));
$found = FALSE;
foreach ($this->childTestResults['assertions'] as $assertion) {
if ((strpos($assertion['message'], $message) !== FALSE) &&
$assertion['type'] == $type &&
$assertion['status'] == $status &&
$assertion['file'] == $file &&
$assertion['function'] == $function) {
$found = TRUE;
break;
}
}
return $this->assertTrue($found, format_string('Found assertion {"@message", "@type", "@status", "@file", "@function"}.', array('@message' => $message, '@type' => $type, '@status' => $status, "@file" => $file, "@function" => $function)));
}
/**
* Get the results from a test and store them in the class array $results.
*/
function getTestResults() {
$results = array();
if ($this->parse()) {
if ($details = $this->getResultFieldSet()) {
// Code assumes this is the only test in group.
$results['summary'] = $this->asText($details->div->div[1]);
$results['name'] = $this->asText($details->summary);
$results['assertions'] = array();
$tbody = $details->div->table->tbody;
foreach ($tbody->tr as $row) {
$assertion = array();
$assertion['message'] = $this->asText($row->td[0]);
$assertion['type'] = $this->asText($row->td[1]);
$assertion['file'] = $this->asText($row->td[2]);
$assertion['line'] = $this->asText($row->td[3]);
$assertion['function'] = $this->asText($row->td[4]);
$ok_url = file_create_url('core/misc/icons/73b355/check.svg');
$assertion['status'] = ($row->td[5]->img['src'] == $ok_url) ? 'Pass' : 'Fail';
$results['assertions'][] = $assertion;
}
}
}
$this->childTestResults = $results;
}
/**
* Get the details containing the results for group this test is in.
*/
function getResultFieldSet() {
$all_details = $this->xpath('//details');
foreach ($all_details as $details) {
if ($this->asText($details->summary) == __CLASS__) {
return $details;
}
}
return FALSE;
}
/**
* Extract the text contained by the element.
*
* @param $element
* Element to extract text from.
*
* @return
* Extracted text.
*/
function asText(\SimpleXMLElement $element) {
if (!is_object($element)) {
return $this->fail('The element is not an element.');
}
return trim(html_entity_decode(strip_tags($element->asXML())));
}
}

View file

@ -0,0 +1,57 @@
<?php
/**
* @file
* Contains \Drupal\simpletest\Tests\UserHelpersTest.
*/
namespace Drupal\simpletest\Tests;
use Drupal\simpletest\WebTestBase;
/**
* Tests User related helper methods of WebTestBase.
*
* @group simpletest
*/
class UserHelpersTest extends WebTestBase {
/**
* Tests WebTestBase::drupalUserIsLoggedIn().
*/
function testDrupalUserIsLoggedIn() {
$first_user = $this->drupalCreateUser();
$second_user = $this->drupalCreateUser();
// After logging in, the first user should be logged in, the second not.
$this->drupalLogin($first_user);
$this->assertTrue($this->drupalUserIsLoggedIn($first_user));
$this->assertFalse($this->drupalUserIsLoggedIn($second_user));
// Verify that logged in state is retained across pages.
$this->drupalGet('');
$this->assertTrue($this->drupalUserIsLoggedIn($first_user));
$this->assertFalse($this->drupalUserIsLoggedIn($second_user));
// After logging out, both users should be logged out.
$this->drupalLogout();
$this->assertFalse($this->drupalUserIsLoggedIn($first_user));
$this->assertFalse($this->drupalUserIsLoggedIn($second_user));
// After logging back in, the second user should still be logged out.
$this->drupalLogin($first_user);
$this->assertTrue($this->drupalUserIsLoggedIn($first_user));
$this->assertFalse($this->drupalUserIsLoggedIn($second_user));
// After logging in the second user, the first one should be logged out.
$this->drupalLogin($second_user);
$this->assertTrue($this->drupalUserIsLoggedIn($second_user));
$this->assertFalse($this->drupalUserIsLoggedIn($first_user));
// After logging out, both should be logged out.
$this->drupalLogout();
$this->assertFalse($this->drupalUserIsLoggedIn($first_user));
$this->assertFalse($this->drupalUserIsLoggedIn($second_user));
}
}