diff --git a/browsertest-convert.php b/browsertest-convert.php new file mode 100644 index 0000000..65c0dbe --- /dev/null +++ b/browsertest-convert.php @@ -0,0 +1,617 @@ +=5.3.9", + "symfony/polyfill-mbstring": "~1.0" + }, + "require-dev": { + "symfony/css-selector": "~2.8|~3.0.0" + }, + "suggest": { + "symfony/css-selector": "" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.8-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Component\\DomCrawler\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony DomCrawler Component", + "homepage": "https://symfony.com", + "time": "2016-10-18 15:35:45" + }, + { "name": "symfony/event-dispatcher", "version": "v2.8.4", "source": { @@ -2759,16 +2815,16 @@ "packages-dev": [ { "name": "behat/mink", - "version": "v1.7.1", + "version": "dev-master", "source": { "type": "git", "url": "https://github.com/minkphp/Mink.git", - "reference": "e6930b9c74693dff7f4e58577e1b1743399f3ff9" + "reference": "12e09bf56d4892998518eff6e9be897ba23b7dc1" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/minkphp/Mink/zipball/e6930b9c74693dff7f4e58577e1b1743399f3ff9", - "reference": "e6930b9c74693dff7f4e58577e1b1743399f3ff9", + "url": "https://api.github.com/repos/minkphp/Mink/zipball/12e09bf56d4892998518eff6e9be897ba23b7dc1", + "reference": "12e09bf56d4892998518eff6e9be897ba23b7dc1", "shasum": "" }, "require": { @@ -2813,7 +2869,7 @@ "testing", "web" ], - "time": "2016-03-05 08:26:18" + "time": "2016-10-17 08:31:38" }, { "name": "behat/mink-browserkit-driver", @@ -4147,63 +4203,14 @@ "description": "Symfony CssSelector Component", "homepage": "https://symfony.com", "time": "2016-03-04 07:54:35" - }, - { - "name": "symfony/dom-crawler", - "version": "v2.7.6", - "source": { - "type": "git", - "url": "https://github.com/symfony/dom-crawler.git", - "reference": "5fef7d8b80d8f9992df99d8ee283f420484c9612" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/symfony/dom-crawler/zipball/5fef7d8b80d8f9992df99d8ee283f420484c9612", - "reference": "5fef7d8b80d8f9992df99d8ee283f420484c9612", - "shasum": "" - }, - "require": { - "php": ">=5.3.9" - }, - "require-dev": { - "symfony/css-selector": "~2.3" - }, - "suggest": { - "symfony/css-selector": "" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "2.7-dev" - } - }, - "autoload": { - "psr-4": { - "Symfony\\Component\\DomCrawler\\": "" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Fabien Potencier", - "email": "fabien@symfony.com" - }, - { - "name": "Symfony Community", - "homepage": "https://symfony.com/contributors" - } - ], - "description": "Symfony DomCrawler Component", - "homepage": "https://symfony.com", - "time": "2015-10-11 09:39:48" } ], "aliases": [], "minimum-stability": "dev", - "stability-flags": [], + "stability-flags": { + "symfony/dom-crawler": 20, + "behat/mink": 20 + }, "prefer-stable": true, "prefer-lowest": false, "platform": { diff --git a/core/composer.json b/core/composer.json index 53ab8fa..d0e279e 100644 --- a/core/composer.json +++ b/core/composer.json @@ -8,6 +8,7 @@ "symfony/class-loader": "~2.8", "symfony/console": "~2.8", "symfony/dependency-injection": "~2.8", + "symfony/dom-crawler": "2.8.x-dev", "symfony/event-dispatcher": "~2.8", "symfony/http-foundation": "~2.8", "symfony/http-kernel": "~2.8", @@ -35,7 +36,7 @@ "asm89/stack-cors": "~1.0" }, "require-dev": { - "behat/mink": "~1.7", + "behat/mink": "1.7.x-dev", "behat/mink-goutte-driver": "~1.2", "jcalderonzumba/gastonjs": "~1.0.2", "jcalderonzumba/mink-phantomjs-driver": "~0.3.1", diff --git a/core/modules/action/src/Tests/ActionListTest.php b/core/modules/action/tests/src/Functional/ActionListTest.php similarity index 87% rename from core/modules/action/src/Tests/ActionListTest.php rename to core/modules/action/tests/src/Functional/ActionListTest.php index f533cdf..2510e86 100644 --- a/core/modules/action/src/Tests/ActionListTest.php +++ b/core/modules/action/tests/src/Functional/ActionListTest.php @@ -1,15 +1,15 @@ pass('Success!'); + } + +} diff --git a/core/modules/simpletest/src/Tests/UserHelpersTest.php b/core/modules/simpletest/tests/src/Functional/UserHelpersTest.php similarity index 92% rename from core/modules/simpletest/src/Tests/UserHelpersTest.php rename to core/modules/simpletest/tests/src/Functional/UserHelpersTest.php index c3fb00b..ace0e49 100644 --- a/core/modules/simpletest/src/Tests/UserHelpersTest.php +++ b/core/modules/simpletest/tests/src/Functional/UserHelpersTest.php @@ -1,15 +1,15 @@ 'Bad html ']; } + /** + * Renders a page with pipe character in link test. + * + * @return array + * A render array as expected by drupal_render() + */ + public function renderPipeInLink() { + return ['#markup' => 'foo|bar|baz']; + } + } diff --git a/core/modules/system/tests/modules/test_page_test/test_page_test.routing.yml b/core/modules/system/tests/modules/test_page_test/test_page_test.routing.yml index cbcf6d8..9d07a34 100644 --- a/core/modules/system/tests/modules/test_page_test/test_page_test.routing.yml +++ b/core/modules/system/tests/modules/test_page_test/test_page_test.routing.yml @@ -66,3 +66,11 @@ test_page_test.encoded: _controller: '\Drupal\test_page_test\Controller\Test::renderEncodedMarkup' requirements: _access: 'TRUE' + +test_page_test.pipe: + path: '/test-pipe-char' + defaults: + _title: 'Page with pipe char in link' + _controller: '\Drupal\test_page_test\Controller\Test::renderPipeInLink' + requirements: + _access: 'TRUE' diff --git a/core/modules/system/src/Tests/Bootstrap/DrupalSetMessageTest.php b/core/modules/system/tests/src/Functional/Bootstrap/DrupalSetMessageTest.php similarity index 90% rename from core/modules/system/src/Tests/Bootstrap/DrupalSetMessageTest.php rename to core/modules/system/tests/src/Functional/Bootstrap/DrupalSetMessageTest.php index 29ca02f..1b0f31a 100644 --- a/core/modules/system/src/Tests/Bootstrap/DrupalSetMessageTest.php +++ b/core/modules/system/tests/src/Functional/Bootstrap/DrupalSetMessageTest.php @@ -1,15 +1,15 @@ xpath() instead and check the values directly in the test. + */ + protected function assertFieldByXPath($xpath, $value = NULL, $message = '') { + $fields = $this->xpath($xpath); + + $this->assertFieldsByValue($fields, $value, $message); + } + + /** + * Asserts that a field does not exist or its value does not match, by XPath. + * + * @param string $xpath + * XPath used to find the field. + * @param string $value + * (optional) Value of the field, to assert that the field's value on the + * page does not match it. + * @param string $message + * (optional) A message to display with the assertion. Do not translate + * messages with t(). + * + * @deprecated Scheduled for removal in Drupal 9.0.0. + * Use $this->assertSession()->fieldNotExists() or + * $this->assertSession()->fieldValueNotEquals() instead. + */ + protected function assertNoFieldByXPath($xpath, $value = NULL, $message = '') { + $fields = $this->xpath($xpath); + + // If value specified then check array for match. + $found = TRUE; + if (isset($value)) { + $found = FALSE; + if ($fields) { + foreach ($fields as $field) { + if ($field->getAttribute('value') == $value) { + $found = TRUE; + } + } + } + } + return $this->assertFalse($fields && $found, $message); + } + + /** + * Asserts that a field exists in the current page with a given Xpath result. + * + * @param \Behat\Mink\Element\NodeElement[] $fields + * Xml elements. + * @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. + * @param string $message + * (optional) A message to display with the assertion. Do not translate + * messages with t(). + * + * @deprecated Scheduled for removal in Drupal 9.0.0. + * Iterate over the fields yourself instead and directly check the values in + * the test. + */ + protected function assertFieldsByValue($fields, $value = NULL, $message = '') { + // If value specified then check array for match. + $found = TRUE; + if (isset($value)) { + $found = FALSE; + if ($fields) { + foreach ($fields as $field) { + if ($field->getAttribute('value') == $value) { + // Input element with correct value. + $found = TRUE; + } + elseif ($field->find('xpath', '//option[@value = ' . (new Escaper())->escapeLiteral($value) . ' and @selected = "selected"]')) { + // Select element with an option. + $found = TRUE; + } + elseif ($field->getText() == $value) { + // Text area with correct text. + $found = TRUE; + } + } + } + } + $this->assertTrue($fields && $found, $message); + } + + /** * Passes if the raw text IS found escaped on the loaded page, fail otherwise. * * Raw text refers to the raw HTML that the page generated. diff --git a/core/tests/Drupal/FunctionalTests/BrowserTestBaseTest.php b/core/tests/Drupal/FunctionalTests/BrowserTestBaseTest.php index 81fa024..6cba6b9 100644 --- a/core/tests/Drupal/FunctionalTests/BrowserTestBaseTest.php +++ b/core/tests/Drupal/FunctionalTests/BrowserTestBaseTest.php @@ -124,9 +124,19 @@ public function testError() { } /** - * Tests legacy asserts. + * Tests linkExists() with pipe character (|) in locator. + * + * @see \Drupal\Tests\WebAssert::linkExists() */ - public function testLegacyAsserts() { + public function testPipeCharInLocator() { + $this->drupalGet('test-pipe-char'); + $this->assertSession()->linkExists('foo|bar|baz'); + } + + /** + * Tests legacy text asserts. + */ + public function testLegacyTextAsserts() { $this->drupalGet('test-encoded'); $dangerous = 'Bad html '; $sanitized = Html::escape($dangerous); @@ -134,4 +144,26 @@ public function testLegacyAsserts() { $this->assertText($sanitized); } + /** + * Tests legacy XPath asserts. + */ + public function testLegacyXPathAsserts() { + $account = $this->drupalCreateUser(['administer users'], 'test'); + $this->drupalLogin($account); + + $this->drupalGet('admin/people'); + $this->assertFieldsByValue($this->xpath("//h1[@class = 'page-title']")); + $this->assertFieldsByValue($this->xpath('//table/tbody/tr[2]/td[1]/span'), $account->getAccountName()); + $this->assertFieldByXPath('//table/tbody/tr[2]/td[1]/span', $account->getAccountName()); + + $this->drupalGet('user/' . $account->id() . '/edit'); + $this->assertFieldsByValue($this->xpath("//input[@id = 'edit-name']"), $account->getAccountName()); + $this->assertFieldByXPath("//input[@id = 'edit-name']", $account->getAccountName()); + $this->assertFieldsByValue($this->xpath("//select[@id = 'edit-timezone--2']"), 'Australia/Sydney'); + $this->assertFieldByXPath("//select[@id = 'edit-timezone--2']", 'Australia/Sydney'); + + $this->assertNoFieldByXPath('//notexisting'); + $this->assertNoFieldByXPath("//input[@id = 'edit-name']", 'wrong value'); + } + } diff --git a/core/tests/Drupal/Tests/BrowserTestBase.php b/core/tests/Drupal/Tests/BrowserTestBase.php index 74a0635..22431b2 100644 --- a/core/tests/Drupal/Tests/BrowserTestBase.php +++ b/core/tests/Drupal/Tests/BrowserTestBase.php @@ -22,6 +22,7 @@ use Drupal\Core\Session\UserSession; use Drupal\Core\Site\Settings; use Drupal\Core\StreamWrapper\StreamWrapperInterface; +use Drupal\Core\Test\AssertMailTrait; use Drupal\Core\Test\TestRunnerKernel; use Drupal\Core\Url; use Drupal\Core\Utility\Error; @@ -67,6 +68,9 @@ createUser as drupalCreateUser; } use XdebugRequestTrait; + use AssertMailTrait { + getMails as drupalGetMails; + } /** * Class loader.