diff --git a/core/modules/config/src/Tests/SchemaCheckTestTrait.php b/core/modules/config/src/Tests/SchemaCheckTestTrait.php index ede1e56..6946157 100644 --- a/core/modules/config/src/Tests/SchemaCheckTestTrait.php +++ b/core/modules/config/src/Tests/SchemaCheckTestTrait.php @@ -28,19 +28,19 @@ public function assertConfigSchema(TypedConfigManagerInterface $typed_config, $c if ($errors === FALSE) { // @todo Since the use of this trait is under TestBase, it works. // Can be fixed as part of https://www.drupal.org/node/2260053. - $this->fail(SafeMarkup::format('No schema for @config_name', array('@config_name' => $config_name))); + $this->assertTrue(FALSE, SafeMarkup::format('No schema for @config_name', array('@config_name' => $config_name))); return; } elseif ($errors === TRUE) { // @todo Since the use of this trait is under TestBase, it works. // Can be fixed as part of https://www.drupal.org/node/2260053. - $this->pass(SafeMarkup::format('Schema found for @config_name and values comply with schema.', array('@config_name' => $config_name))); + $this->assertTrue(TRUE, SafeMarkup::format('Schema found for @config_name and values comply with schema.', array('@config_name' => $config_name))); } else { foreach ($errors as $key => $error) { // @todo Since the use of this trait is under TestBase, it works. // Can be fixed as part of https://www.drupal.org/node/2260053. - $this->fail(SafeMarkup::format('Schema key @key failed with: @error', array('@key' => $key, '@error' => $error))); + $this->assertTrue(FALSE, SafeMarkup::format('Schema key @key failed with: @error', array('@key' => $key, '@error' => $error))); } } } @@ -52,7 +52,8 @@ public function assertConfigSchema(TypedConfigManagerInterface $typed_config, $c * The configuration name. */ public function assertConfigSchemaByName($config_name) { - $config = $this->config($config_name); + $config_factory = \Drupal::configFactory(); + $config = $config_factory->get($config_name); $this->assertConfigSchema(\Drupal::service('config.typed'), $config->getName(), $config->get()); } diff --git a/core/modules/system/config/schema/system.schema.yml b/core/modules/system/config/schema/system.schema.yml index e34d375..732798e 100644 --- a/core/modules/system/config/schema/system.schema.yml +++ b/core/modules/system/config/schema/system.schema.yml @@ -279,6 +279,9 @@ system.file: temporary: type: string label: 'Temporary directory' + private: + type: string + label: 'Private directory' temporary_maximum_age: type: integer label: 'Maximum age for temporary files' diff --git a/core/profiles/standard/src/Tests/StandardTest.php b/core/profiles/standard/tests/src/Functional/StandardProfileTest.php similarity index 64% rename from core/profiles/standard/src/Tests/StandardTest.php rename to core/profiles/standard/tests/src/Functional/StandardProfileTest.php index bff61a9..8f61683 100644 --- a/core/profiles/standard/src/Tests/StandardTest.php +++ b/core/profiles/standard/tests/src/Functional/StandardProfileTest.php @@ -1,24 +1,32 @@ drupalGet(''); - $this->assertLink(t('Contact')); - $this->clickLink(t('Contact')); - $this->assertResponse(200); + $assert_session = $this->assertSession(); + $this->drupalGet(''); + $page = $this->getSession()->getPage(); + $contact = $page->findLink('Contact'); + $contact->click(); + $assert_session->statusCodeEquals(200); // Test anonymous user can access 'Main navigation' block. $this->adminUser = $this->drupalCreateUser(array( @@ -48,34 +58,29 @@ function testStandard() { $this->drupalLogin($this->adminUser); // Configure the block. $this->drupalGet('admin/structure/block/add/system_menu_block:main/bartik'); - $this->drupalPostForm(NULL, array( + $this->submitForm(array( 'region' => 'sidebar_first', 'id' => 'main_navigation', ), t('Save block')); // Verify admin user can see the block. - $this->drupalGet(''); - $this->assertText('Main navigation'); + $this->drupalGet(''); + $assert_session->pageTextContains('Main navigation'); // Verify we have role = aria on system_powered_by and help_block // blocks. $this->drupalGet('admin/structure/block'); - $elements = $this->xpath('//div[@role=:role and @id=:id]', array( - ':role' => 'complementary', - ':id' => 'block-bartik-help', - )); + $page = $this->getSession()->getPage(); + $element = $page->findById('block-bartik-help'); + $this->assertEquals('complementary', $element->getAttribute('role'), 'Found complementary role on help block.'); - $this->assertEqual(count($elements), 1, 'Found complementary role on help block.'); - - $this->drupalGet(''); - $elements = $this->xpath('//div[@role=:role and @id=:id]', array( - ':role' => 'complementary', - ':id' => 'block-bartik-powered', - )); - $this->assertEqual(count($elements), 1, 'Found complementary role on powered by block.'); + $this->drupalGet(''); + $page = $this->getSession()->getPage(); + $element = $page->findById('block-bartik-powered'); + $this->assertEquals('complementary', $element->getAttribute('role'), 'Found complementary role on powered by block.'); // Verify anonymous user can see the block. $this->drupalLogout(); - $this->assertText('Main navigation'); + $assert_session->pageTextContains('Main navigation'); // Ensure comments don't show in the front page RSS feed. // Create an article. @@ -90,19 +95,24 @@ function testStandard() { // Add a comment. $this->drupalLogin($this->adminUser); $this->drupalGet('node/1'); - $this->assertRaw('Then she picked out two somebodies,
Sally and me', 'Found a line break.'); - $this->drupalPostForm(NULL, array( + $page = $this->getSession()->getPage(); + $this->assertContains('Then she picked out two somebodies,
Sally and me', $page->getHtml(), 'Found a line break.'); + $this->submitForm(array( 'subject[0][value]' => 'Barfoo', 'comment_body[0][value]' => 'Then she picked out two somebodies, Sally and me', ), t('Save')); // Fetch the feed. $this->drupalGet('rss.xml'); - $this->assertText('Foobar'); - $this->assertNoText('Then she picked out two somebodies, Sally and me'); + // Mink session by default initialized html document so to get xml we use + // last response of the driver. + $xml = $this->getSession()->getDriver()->getContent(); + $this->assertContains('Foobar', $xml); + $this->assertNotContains('Then she picked out two somebodies, Sally and me', $xml); // Ensure block body exists. $this->drupalGet('block/add'); - $this->assertFieldByName('body[0][value]'); + $page = $this->getSession()->getPage(); + $this->assertNotNull($page->findField('body[0][value]'), 'Found field with name body[0][value]'); // Now we have all configuration imported, test all of them for schema // conformance. Ensures all imported default configuration is valid when @@ -110,8 +120,9 @@ function testStandard() { $names = $this->container->get('config.storage')->listAll(); /** @var \Drupal\Core\Config\TypedConfigManagerInterface $typed_config */ $typed_config = $this->container->get('config.typed'); + $config_factory = \Drupal::configFactory(); foreach ($names as $name) { - $config = $this->config($name); + $config = $config_factory->get($name); $this->assertConfigSchema($typed_config, $name, $config->get()); } @@ -137,7 +148,7 @@ function testStandard() { /** @var \Drupal\contact\ContactFormInterface $contact_form */ $contact_form = ContactForm::load('feedback'); $recipients = $contact_form->getRecipients(); - $this->assertEqual(['simpletest@example.com'], $recipients); + $this->assertEquals(['simpletest@example.com'], $recipients); $role = Role::create([ 'id' => 'admin_theme', @@ -148,32 +159,34 @@ function testStandard() { $this->adminUser->addRole($role->id()); $this->adminUser->save(); $this->drupalGet('node/add'); - $this->assertResponse(200); + $assert_session->statusCodeEquals(200); + $this->drupalLogout(); // Ensure that there are no pending updates after installation. - $this->drupalLogin($this->rootUser); + $root_user = User::load(1); + $this->drupalLogin($root_user); $this->drupalGet('update.php/selection'); - $this->assertText('No pending updates.'); + $assert_session->pageTextContains('No pending updates.'); // Ensure that there are no pending entity updates after installation. $this->assertFalse($this->container->get('entity.definition_update_manager')->needsUpdates(), 'After installation, entity schema is up to date.'); // Make sure the optional image styles are not installed. $this->drupalGet('admin/config/media/image-styles'); - $this->assertNoText('Max 325x325'); - $this->assertNoText('Max 650x650'); - $this->assertNoText('Max 1300x1300'); - $this->assertNoText('Max 2600x2600'); + $assert_session->pageTextNotContains('Max 325x325'); + $assert_session->pageTextNotContains('Max 650x650'); + $assert_session->pageTextNotContains('Max 1300x1300'); + $assert_session->pageTextNotContains('Max 2600x2600'); // Make sure the optional image styles are installed after enabling // the responsive_image module. \Drupal::service('module_installer')->install(array('responsive_image')); $this->rebuildContainer(); $this->drupalGet('admin/config/media/image-styles'); - $this->assertText('Max 325x325'); - $this->assertText('Max 650x650'); - $this->assertText('Max 1300x1300'); - $this->assertText('Max 2600x2600'); + $assert_session->pageTextContains('Max 325x325'); + $assert_session->pageTextContains('Max 650x650'); + $assert_session->pageTextContains('Max 1300x1300'); + $assert_session->pageTextContains('Max 2600x2600'); // Verify certain routes' responses are cacheable by Dynamic Page Cache, to // ensure these responses are very fast for authenticated users. @@ -181,22 +194,22 @@ function testStandard() { $this->drupalLogin($this->adminUser); $url = Url::fromRoute('contact.site_page'); $this->drupalGet($url); - $this->assertEqual('UNCACHEABLE', $this->drupalGetHeader(DynamicPageCacheSubscriber::HEADER), 'Site-wide contact page cannot be cached by Dynamic Page Cache.'); + $assert_session->responseHeaderContains(DynamicPageCacheSubscriber::HEADER, 'UNCACHEABLE'); $url = Url::fromRoute(''); $this->drupalGet($url); $this->drupalGet($url); - $this->assertEqual('HIT', $this->drupalGetHeader(DynamicPageCacheSubscriber::HEADER), 'Frontpage is cached by Dynamic Page Cache.'); + $assert_session->responseHeaderContains(DynamicPageCacheSubscriber::HEADER, 'HIT'); $url = Url::fromRoute('entity.node.canonical', ['node' => 1]); $this->drupalGet($url); $this->drupalGet($url); - $this->assertEqual('HIT', $this->drupalGetHeader(DynamicPageCacheSubscriber::HEADER), 'Full node page is cached by Dynamic Page Cache.'); + $assert_session->responseHeaderContains(DynamicPageCacheSubscriber::HEADER, 'HIT'); $url = Url::fromRoute('entity.user.canonical', ['user' => 1]); $this->drupalGet($url); $this->drupalGet($url); - $this->assertEqual('HIT', $this->drupalGetHeader(DynamicPageCacheSubscriber::HEADER), 'User profile page is cached by Dynamic Page Cache.'); + $assert_session->responseHeaderContains(DynamicPageCacheSubscriber::HEADER, 'HIT'); } } diff --git a/core/tests/Drupal/Tests/BrowserTestBase.php b/core/tests/Drupal/Tests/BrowserTestBase.php index a8700b4..acdce5d 100644 --- a/core/tests/Drupal/Tests/BrowserTestBase.php +++ b/core/tests/Drupal/Tests/BrowserTestBase.php @@ -274,6 +274,13 @@ protected $baseUrl; /** + * The original array of shutdown function callbacks. + * + * @var array + */ + protected $originalShutdownCallbacks = []; + + /** * Initializes Mink sessions. */ protected function initMink() { @@ -505,6 +512,10 @@ protected function tearDown() { if ($this->mink) { $this->mink->stopSessions(); } + + // Restore original shutdown callbacks. + $callbacks = &drupal_register_shutdown_function(); + $callbacks = $this->originalShutdownCallbacks; } /** @@ -806,7 +817,7 @@ protected function drupalLogin(AccountInterface $account) { // @see BrowserTestBase::drupalUserIsLoggedIn() $account->sessionId = $this->getSession()->getCookie($this->getSessionName()); - $this->assertTrue($this->drupalUserIsLoggedIn($account), SafeMarkup::format('User %name successfully logged in.', array('name' => $account->getUsername()))); + $this->assertTrue($this->drupalUserIsLoggedIn($account), SafeMarkup::format('User %name successfully logged in.', array('%name' => $account->getUsername()))); $this->loggedInUser = $account; $this->container->get('current_user')->setAccount($account); @@ -1241,6 +1252,14 @@ protected function prepareEnvironment() { )); drupal_set_time_limit($this->timeLimit); + + // Save and clean the shutdown callbacks array because it is static cached + // and will be changed by the test run. Otherwise it will contain callbacks + // from both environments and the testing environment will try to call the + // handlers defined by the original one. + $callbacks = &drupal_register_shutdown_function(); + $this->originalShutdownCallbacks = $callbacks; + $callbacks = []; } /**