diff -u b/core/modules/simpletest/lib/Drupal/simpletest/TestBase.php b/core/modules/simpletest/lib/Drupal/simpletest/TestBase.php --- b/core/modules/simpletest/lib/Drupal/simpletest/TestBase.php +++ b/core/modules/simpletest/lib/Drupal/simpletest/TestBase.php @@ -1184,26 +1184,22 @@ * TRUE if the random string is valid, FALSE if not. */ public function randomStringValidate($str) { - // Consecutive spaces causes issues for xpath + // Consecutive spaces causes issues for + // Drupal\simpletest\WebTestBase::assertLink(). if (preg_match('/\s{2,}/', $str)) { return FALSE; } - // Starting with a space we can not guarantee length in UI. + // Starting with a space means that length might not be what is expected. if (preg_match('/^\s/', $str)) { return FALSE; } - // Ending with a space we can not guarantee length in UI. + // Ending with a space means that length might not be what is expected. if (preg_match('/\s$/', $str)) { return FALSE; } - // Containing \1 or $1 matches regex back references. - if (preg_match('/[\\\\|\$][0-9]/', $str)) { - return FALSE; - } - return TRUE; } diff -u b/core/modules/simpletest/tests/Drupal/simpletest/Tests/TestBaseTest.php b/core/modules/simpletest/tests/Drupal/simpletest/Tests/TestBaseTest.php --- b/core/modules/simpletest/tests/Drupal/simpletest/Tests/TestBaseTest.php +++ b/core/modules/simpletest/tests/Drupal/simpletest/Tests/TestBaseTest.php @@ -10,7 +10,7 @@ use Drupal\Tests\UnitTestCase; /** - * Test PHPUnit errors are getting converted to Simpletest errors. + * Tests helper methods provided by the abstract TestBase class. */ class TestBaseTest extends UnitTestCase { @@ -24,7 +24,7 @@ public static function getInfo() { return array( 'name' => 'TestBase helper functions test', - 'description' => 'Test helper functions provided by the TetsBase abstract class.', + 'description' => 'Test helper functions provided by the TestBase abstract class.', 'group' => 'Simpletest', ); @@ -34,6 +34,12 @@ $this->stub = $this->getMockForAbstractClass('Drupal\simpletest\TestBase'); } + /** + * Provides data for the random string validation test. + * + * @return array + * An array of values passed to the test method. + */ public function randomStringValidateProvider () { return array( array(' curry paste', FALSE), @@ -42,17 +48,18 @@ array('curry paste', FALSE), array('curry paste', TRUE), array('thai green curry paste', TRUE), - array('Number\\9', FALSE), - array('Number\9', FALSE), - array('Number9', TRUE), - array('Number9\\', TRUE), - array('$7@|{v$S', FALSE) ); } /** + * Tests the random strings validation rules. + * * @param string $str + * The string to validate. * @param bool $expected + * The expected result of the validation. + * + * @see \Drupal\simpletest\TestBase::randomStringValidate(). * * @dataProvider randomStringValidateProvider */ diff -u b/core/tests/Drupal/Tests/Component/Utility/RandomTest.php b/core/tests/Drupal/Tests/Component/Utility/RandomTest.php --- b/core/tests/Drupal/Tests/Component/Utility/RandomTest.php +++ b/core/tests/Drupal/Tests/Component/Utility/RandomTest.php @@ -152,7 +152,7 @@ public function testRandomStringValidator() { $random = new Random(); $this->firstStringGenerated = ''; - $str = $random::string(1, FALSE, array($this, '_RandomStringValidate')); + $str = $random::string(1, TRUE, array($this, '_RandomStringValidate')); $this->assertNotEquals($this->firstStringGenerated, $str); } only in patch2: unchanged: --- /dev/null +++ b/core/modules/simpletest/lib/Drupal/simpletest/Tests/WebTestBaseTest.php @@ -0,0 +1,51 @@ + 'WebTestBase helper functions test', + 'description' => 'Test helper functions provided by the WebTestBase class.', + 'group' => 'Simpletest', + ); + } + + /** + * Tests the behaviour of Drupal\simpletest\WebTestBase::assertLink(). + */ + public function testAsertLink() { + $link_texts = array( + 'curry paste', + 'thai green curry paste', + 'Number\\9', + 'Number\9', + 'Number9', + 'Number9\\', + '$7@|{v$S', + ); + + // Set up some links to test. + $this->content = ''; + foreach ($link_texts as $link) { + $this->content .= '' . $link .''; + } + + foreach ($link_texts as $link) { + $result = $this->assertLink($link); + $this->assertTrue($result, 'The assertLink method found link.'); + } + } + +} only in patch2: unchanged: --- a/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php +++ b/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php @@ -1877,7 +1877,7 @@ protected function buildXPathQuery($xpath, array $args = array()) { // Return the string. $value = count($parts) > 1 ? 'concat(' . implode(', \'"\', ', $parts) . ')' : $parts[0]; } - $xpath = preg_replace('/' . preg_quote($placeholder) . '\b/', $value, $xpath); + $xpath = str_replace($placeholder, $value, $xpath); } return $xpath; }