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/tests/src/Functional/StandardTest.php b/core/profiles/standard/tests/src/Functional/StandardTest.php index f54c4de..4f9e756 100644 --- a/core/profiles/standard/tests/src/Functional/StandardTest.php +++ b/core/profiles/standard/tests/src/Functional/StandardTest.php @@ -64,14 +64,14 @@ function testStandard() { ':id' => 'block-bartik-help', )); - $this->assertEquals(1, count($elements), '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->assertEquals(1, count($elements), 'Found complementary role on powered by block.'); + $this->assertEqual(count($elements), 1, 'Found complementary role on powered by block.'); // Verify anonymous user can see the block. $this->drupalLogout(); @@ -96,9 +96,9 @@ function testStandard() { 'comment_body[0][value]' => 'Then she picked out two somebodies, Sally and me', ), t('Save')); // Fetch the feed. - $rss_xml = $this->drupalGet('rss.xml'); - $this->assertContains('Foobar', $rss_xml); - $this->assertNotContains('Then she picked out two somebodies, Sally and me', $rss_xml); + $this->drupalGet('rss.xml'); + $this->assertText('Foobar'); + $this->assertNoText('Then she picked out two somebodies, Sally and me'); // Ensure block body exists. $this->drupalGet('block/add'); diff --git a/core/tests/Drupal/Tests/BrowserAssertTrait.php b/core/tests/Drupal/Tests/BrowserAssertTrait.php new file mode 100644 index 0000000..2c24302 --- /dev/null +++ b/core/tests/Drupal/Tests/BrowserAssertTrait.php @@ -0,0 +1,203 @@ +getSession($name)); + } + + /** + * Asserts that the element with the given CSS selector is present. + * + * @param string $css_selector + * The CSS selector identifying the element to check. + * @param string $message + * Optional message to show alongside the assertion. + */ + protected function assertElementPresent($css_selector, $message = '') { + $this->assertNotEmpty($this->getSession()->getDriver()->find($this->cssSelectToXpath($css_selector)), $message); + } + + /** + * Asserts that the element with the given CSS selector is not present. + * + * @param string $css_selector + * The CSS selector identifying the element to check. + * @param string $message + * Optional message to show alongside the assertion. + */ + protected function assertElementNotPresent($css_selector, $message = '') { + $this->assertEmpty($this->getSession()->getDriver()->find($this->cssSelectToXpath($css_selector)), $message); + } + + /** + * Passes if the page (with HTML stripped) contains the text. + * + * Note that stripping HTML tags also removes their attributes, such as + * the values of text fields. + * + * @param string $text + * Plain text to look for. + */ + protected function assertText($text) { + $this->assertSession()->responseContains($text); + } + + /** + * Passes if the page (with HTML stripped) does not contains the text. + * + * Note that stripping HTML tags also removes their attributes, such as + * the values of text fields. + * + * @param string $text + * Plain text to look for. + */ + protected function assertNoText($text) { + $this->assertSession()->responseNotContains($text); + } + + /** + * Asserts the page responds with the specified response code. + * + * @param int $code + * Response code. For example 200 is a successful page request. For a list + * of all codes see http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html. + */ + protected function assertResponse($code) { + $this->assertSession()->statusCodeEquals($code); + } + + /** + * Pass if the page title is the given string. + * + * @param string $expected_title + * The string the page title should be. + */ + protected function assertTitle($expected_title) { + $title_element = $this->getSession()->getPage()->find('css', 'title'); + if (!$title_element) { + $this->fail('No title element found on the page.'); + return; + } + $actual_title = $title_element->getText(); + $this->assertSame($expected_title, $actual_title); + } + + /** + * Passes if a link with the specified label is found. + * + * An optional link index may be passed. + * + * @param string|\Drupal\Component\Render\MarkupInterface $label + * Text between the anchor tags. + * @param int $index + * Link position counting from zero. + * @param string $message + * (optional) A message to display with the assertion. Do not translate + * messages: use strtr() to embed variables in the message text, not + * t(). If left blank, a default message will be displayed. + */ + protected function assertLink($label, $index = 0, $message = '') { + // Cast MarkupInterface objects to string. + $label = (string) $label; + $message = ($message ? $message : strtr('Link with label %label found.', ['%label' => $label])); + $links = $this->getSession()->getPage()->findAll('named', ['link', $label]); + if (empty($links[$index])) { + $this->fail($message); + } + $this->assertNotNull($links[$index], $message); + } + + /** + * Passes if the raw text IS NOT found escaped on the loaded page. + * + * Raw text refers to the raw HTML that the page generated. + * + * @param string $raw + * Raw (HTML) string to look for. + */ + protected function assertNoEscaped($raw) { + $this->assertSession()->pageTextNotContains(Html::escape($raw)); + } + + /** + * Passes if the raw text IS found on the loaded page, fail otherwise. + * + * Raw text refers to the raw HTML that the page generated. + * + * @param string $raw + * Raw (HTML) string to look for. + */ + protected function assertRaw($raw) { + $this->assertSession()->responseContains($raw); + } + + /** + * Asserts that a field exists with the given name and value. + * + * @param string $name + * Name of field to assert. + * @param string $value + * (optional) Value of the field to assert. You may pass in NULL (default) + * to skip checking the actual value, while still checking that the field + * exists. + */ + protected function assertFieldByName($name, $value = NULL) { + $this->assertSession()->fieldExists($name); + if ($value !== NULL) { + $this->assertSession()->fieldValueEquals($name, $value); + } + } + + /** + * Check to see if two values are equal. + * + * Compatibility function for ::assertEquals(). + * + * @param $first + * The first value to check. + * @param $second + * The second value to check. + * @param $message + * (optional) A message to display with the assertion. Do not translate + * messages: use \Drupal\Component\Utility\SafeMarkup::format() to embed + * variables in the message text, not t(). If left blank, a default message + * will be displayed. + */ + protected function assertEqual($first, $second, $message = '') { + // Cast objects implementing MarkupInterface to string instead of + // relying on PHP casting them to string depending on what they are being + // comparing with. + $first = $this->castSafeStrings($first); + $second = $this->castSafeStrings($second); + $this->assertEquals($second, $first, $message); + } + + /** + * Fire an assertion that is always positive. + * + * @param string $message + * (optional) A message to display with the assertion. Do not translate + * messages: use \Drupal\Component\Utility\SafeMarkup::format() to embed + * variables in the message text, not t(). If left blank, a default message + * will be displayed. + */ + protected function pass($message = '') { + return $this->assertTrue(TRUE, $message); + } + +} diff --git a/core/tests/Drupal/Tests/BrowserTestBase.php b/core/tests/Drupal/Tests/BrowserTestBase.php index ededc7e..5d25a41 100644 --- a/core/tests/Drupal/Tests/BrowserTestBase.php +++ b/core/tests/Drupal/Tests/BrowserTestBase.php @@ -38,6 +38,7 @@ */ abstract class BrowserTestBase extends \PHPUnit_Framework_TestCase { use AssertHelperTrait; + use BrowserAssertTrait; use RandomGeneratorTrait; use SessionTestTrait; use NodeCreationTrait { @@ -537,19 +538,6 @@ public function getSession($name = NULL) { } /** - * Returns WebAssert object. - * - * @param string $name - * (optional) Name of the session. Defaults to the active session. - * - * @return \Drupal\Tests\WebAssert - * A new web-assert option for asserting the presence of elements with. - */ - public function assertSession($name = NULL) { - return new WebAssert($this->getSession($name)); - } - - /** * Prepare for a request to testing site. * * The testing site is protected via a SIMPLETEST_USER_AGENT cookie that is @@ -1528,30 +1516,6 @@ protected function drupalUserIsLoggedIn(AccountInterface $account) { } /** - * Asserts that the element with the given CSS selector is present. - * - * @param string $css_selector - * The CSS selector identifying the element to check. - * @param string $message - * Optional message to show alongside the assertion. - */ - protected function assertElementPresent($css_selector, $message = '') { - $this->assertNotEmpty($this->getSession()->getDriver()->find($this->cssSelectToXpath($css_selector)), $message); - } - - /** - * Asserts that the element with the given CSS selector is not present. - * - * @param string $css_selector - * The CSS selector identifying the element to check. - * @param string $message - * Optional message to show alongside the assertion. - */ - protected function assertElementNotPresent($css_selector, $message = '') { - $this->assertEmpty($this->getSession()->getDriver()->find($this->cssSelectToXpath($css_selector)), $message); - } - - /** * Clicks the element with the given CSS selector. * * @param string $css_selector @@ -1653,138 +1617,6 @@ protected function cssSelect($selector) { } /** - * Passes if the page (with HTML stripped) contains the text. - * - * Note that stripping HTML tags also removes their attributes, such as - * the values of text fields. - * - * @param string $text - * Plain text to look for. - */ - protected function assertText($text) { - $this->assertSession()->pageTextContains($text); - } - - /** - * Passes if the page (with HTML stripped) does not contains the text. - * - * Note that stripping HTML tags also removes their attributes, such as - * the values of text fields. - * - * @param string $text - * Plain text to look for. - */ - protected function assertNoText($text) { - $this->assertSession()->pageTextNotContains($text); - } - - /** - * Asserts the page responds with the specified response code. - * - * @param int $code - * Response code. For example 200 is a successful page request. For a list - * of all codes see http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html. - */ - protected function assertResponse($code) { - $this->assertSession()->statusCodeEquals($code); - } - - /** - * Pass if the page title is the given string. - * - * @param string $expected_title - * The string the page title should be. - */ - protected function assertTitle($expected_title) { - $title_element = $this->getSession()->getPage()->find('css', 'title'); - if (!$title_element) { - $this->fail('No title element found on the page.'); - return; - } - $actual_title = $title_element->getText(); - $this->assertSame($expected_title, $actual_title); - } - - /** - * Passes if a link with the specified label is found. - * - * An optional link index may be passed. - * - * @param string|\Drupal\Component\Render\MarkupInterface $label - * Text between the anchor tags. - * @param int $index - * Link position counting from zero. - * @param string $message - * (optional) A message to display with the assertion. Do not translate - * messages: use strtr() to embed variables in the message text, not - * t(). If left blank, a default message will be displayed. - */ - protected function assertLink($label, $index = 0, $message = '') { - // Cast MarkupInterface objects to string. - $label = (string) $label; - $message = ($message ? $message : strtr('Link with label %label found.', ['%label' => $label])); - $links = $this->getSession()->getPage()->findAll('named', ['link', $label]); - if (empty($links[$index])) { - $this->fail($message); - } - $this->assertNotNull($links[$index], $message); - } - - /** - * Passes if the raw text IS NOT found escaped on the loaded page. - * - * Raw text refers to the raw HTML that the page generated. - * - * @param string $raw - * Raw (HTML) string to look for. - */ - protected function assertNoEscaped($raw) { - $this->assertSession()->pageTextNotContains(Html::escape($raw)); - } - - /** - * Passes if the raw text IS found on the loaded page, fail otherwise. - * - * Raw text refers to the raw HTML that the page generated. - * - * @param string $raw - * Raw (HTML) string to look for. - */ - protected function assertRaw($raw) { - $this->assertSession()->responseContains($raw); - } - - /** - * Asserts that a field exists with the given name and value. - * - * @param string $name - * Name of field to assert. - * @param string $value - * (optional) Value of the field to assert. You may pass in NULL (default) - * to skip checking the actual value, while still checking that the field - * exists. - */ - protected function assertFieldByName($name, $value = NULL) { - $this->assertSession()->fieldExists($name); - if ($value !== NULL) { - $this->assertSession()->fieldValueEquals($name, $value); - } - } - - /** - * Fire an assertion that is always positive. - * - * @param string $message - * (optional) A message to display with the assertion. Do not translate - * messages: use \Drupal\Component\Utility\SafeMarkup::format() to embed - * variables in the message text, not t(). If left blank, a default message - * will be displayed. - */ - protected function pass($message = '') { - return $this->assertTrue(TRUE, $message); - } - - /** * Follows a link by complete name. * * Will click the first link found with this link text. @@ -1818,10 +1650,8 @@ protected function getTextContent() { * placeholders in the query. The values may be either strings or numeric * values. * - * @return \SimpleXMLElement[] - * The return value of the xpath search or FALSE on failure. For details on - * the xpath string format and return values see the SimpleXML - * documentation. + * @return \Behat\Mink\Element\NodeElement[] + * The list of elements matching the xpath expression. */ protected function xpath($xpath, array $arguments = []) { $xpath = $this->buildXPathQuery($xpath, $arguments); @@ -1894,4 +1724,21 @@ protected function config($name) { return \Drupal::configFactory()->getEditable($name); } + /** + * Gets the value of an HTTP response header. + * + * If multiple requests were required to retrieve the page, only the headers + * from the last request will be checked by default. + * + * @param string $name + * The name of the header to retrieve. Names are case-insensitive (see RFC + * 2616 section 4.2). + * + * @return string|null + * The HTTP header value or NULL if not found. + */ + protected function drupalGetHeader($name) { + return $this->getSession()->getResponseHeader($name); + } + }