diff --git a/core/includes/common.inc b/core/includes/common.inc index 0eab240..68123cf 100644 --- a/core/includes/common.inc +++ b/core/includes/common.inc @@ -774,7 +774,6 @@ function valid_email_address($mail) { } /** - * * Verifies the syntax of the given URL. * * This function should only be used on actual URLs. It should not be used for @@ -5586,7 +5585,6 @@ function watchdog_severity_levels() { /** - * * Explodes a string of tags into an array. * * @see drupal_implode_tags() diff --git a/core/tests/Drupal/Tests/Core/Common/AttributesTest.php b/core/tests/Drupal/Tests/Core/Common/AttributesTest.php index dc0d339..bccd205 100644 --- a/core/tests/Drupal/Tests/Core/Common/AttributesTest.php +++ b/core/tests/Drupal/Tests/Core/Common/AttributesTest.php @@ -13,7 +13,7 @@ /** * Tests the Drupal\Core\Template\Attribute functionality. */ -class AttributesUnitTest extends UnitTestCase { +class AttributesTest extends UnitTestCase { public static function getInfo() { return array( @@ -24,33 +24,53 @@ public static function getInfo() { } /** - * Tests that drupal_html_class() cleans the class name properly. + * Provides data for the Attribute test. + * + * @return array */ - function testDrupalAttributes() { - // Verify that special characters are HTML encoded. - $this->assertSame((string) new Attribute(array('title' => '&"\'<>')), ' title="&"'<>"', 'HTML encode attribute values.'); - - // Verify multi-value attributes are concatenated with spaces. - $this->assertSame((string) new Attribute(array('class' => array('first', 'last'))), ' class="first last"', 'Concatenate multi-value attributes.'); - - // Verify empty attribute values are rendered. - $this->assertSame((string) new Attribute(array('alt' => '')), ' alt=""', 'Empty attribute value #1.'); - $this->assertSame((string) new Attribute(array('alt' => NULL)), ' alt=""', 'Empty attribute value #2.'); - - // Verify multiple attributes are rendered. - $attributes = array( - 'id' => 'id-test', - 'class' => array('first', 'last'), - 'alt' => 'Alternate', + public function provideAttributeData() { + return array( + // Verify that special characters are HTML encoded. + array(array('title' => '&"\'<>'), ' title="&"'<>"', 'HTML encode attribute values.'), + // Verify multi-value attributes are concatenated with spaces. + array(array('class' => array('first', 'last')), ' class="first last"', 'Concatenate multi-value attributes.'), + // Verify empty attribute values are rendered. + array(array('alt' => ''), ' alt=""', 'Empty attribute value #1.'), + array(array('alt' => NULL), ' alt=""', 'Empty attribute value #2.'), + // Verify multiple attributes are rendered. + array( + array( + 'id' => 'id-test', + 'class' => array('first', 'last'), + 'alt' => 'Alternate', + ), + ' id="id-test" class="first last" alt="Alternate"', + 'Multiple attributes.' + ), + // Verify empty attributes array is rendered. + array(array(), '', 'Empty attributes array.'), ); - $this->assertSame((string) new Attribute($attributes), ' id="id-test" class="first last" alt="Alternate"', 'Multiple attributes.'); + } - // Verify empty attributes array is rendered. - $this->assertSame((string) new Attribute(array()), '', 'Empty attributes array.'); + /** + * Tests casting an Attribute object to a string. + * + * @see \Drupal\Core\Template\Attribute::__toString() + * + * @dataProvider provideAttributeData + */ + function testDrupalAttributes($attributes, $expected, $message) { + $this->assertSame($expected, (string) new Attribute($attributes), $message); + } + /** + * Test attribute iteration + */ + public function testAttributeIteration() { $attribute = new Attribute(array('key1' => 'value1')); foreach ($attribute as $value) { $this->assertSame((string) $value, 'value1', 'Iterate over attribute.'); } } + } diff --git a/core/tests/Drupal/Tests/Core/Common/TagsTest.php b/core/tests/Drupal/Tests/Core/Common/TagsTest.php index 0888b19..7106d73 100644 --- a/core/tests/Drupal/Tests/Core/Common/TagsTest.php +++ b/core/tests/Drupal/Tests/Core/Common/TagsTest.php @@ -2,7 +2,7 @@ /** * @file - * Contains \Drupal\Tests\Core\Common\AutocompleteTagsTest. + * Contains \Drupal\Tests\Core\Common\TagsTest. */ namespace Drupal\Tests\Core\Common; @@ -42,7 +42,7 @@ public function explodeTags() { /** * Implodes a series of tags. */ - function testImplodeTags() { + public function testImplodeTags() { $tags = array_values($this->validTags); // Let's explode and implode to our heart's content. for ($i = 0; $i < 10; $i++) { diff --git a/core/tests/Drupal/Tests/Core/Common/UrlValidatorTest.php b/core/tests/Drupal/Tests/Core/Common/UrlValidatorTest.php index bbfba71..a6329f7 100644 --- a/core/tests/Drupal/Tests/Core/Common/UrlValidatorTest.php +++ b/core/tests/Drupal/Tests/Core/Common/UrlValidatorTest.php @@ -2,7 +2,7 @@ /** * @file - * Contains \Drupal\Tests\Core\Common\ValidUrlTest. + * Contains \Drupal\Tests\Core\Common\UrlValidatorTest. */ namespace Drupal\Tests\Core\Common; @@ -15,6 +15,7 @@ * Tests URL validation by valid_url(). */ class UrlValidatorTest extends UnitTestCase { + public static function getInfo() { return array( 'name' => 'URL validation', @@ -26,27 +27,29 @@ public static function getInfo() { /** * Data provider for absolute URLs. */ - public function validAbsoluteProvider() { - return array( - array('example.com'), - array('www.example.com'), - array('ex-ample.com'), - array('3xampl3.com'), - array('example.com/paren(the)sis'), - array('example.com/index.html#pagetop'), - array('example.com:8080'), - array('subdomain.example.com'), - array('example.com/index.php/node'), - array('example.com/index.php/node?param=false'), - array('user@www.example.com'), - array('user:pass@www.example.com:8080/login.php?do=login&style=%23#pagetop'), - array('127.0.0.1'), - array('example.org?'), - array('john%20doe:secret:foo@example.org/'), - array('example.org/~,$\'*;'), - array('caf%C3%A9.example.org'), - array('[FEDC:BA98:7654:3210:FEDC:BA98:7654:3210]:80/index.html'), + public function providerValidAbsolute() { + $urls = array( + 'example.com', + 'www.example.com', + 'ex-ample.com', + '3xampl3.com', + 'example.com/parenthesis', + 'example.com/index.html#pagetop', + 'example.com:8080', + 'subdomain.example.com', + 'example.com/index.php/node', + 'example.com/index.php/node?param=false', + 'user@www.example.com', + 'user:pass@www.example.com:8080/login.php?do=login&style=%23#pagetop', + '127.0.0.1', + 'example.org?', + 'john%20doe:secret:foo@example.org/', + 'example.org/~,$\'*;', + 'caf%C3%A9.example.org', + '[FEDC:BA98:7654:3210:FEDC:BA98:7654:3210]:80/index.html', ); + + return $this->dataEnhanceWithScheme($urls); } /** @@ -54,27 +57,27 @@ public function validAbsoluteProvider() { * * @param string $url * The url to test. + * @param string $scheme + * The scheme to test. * - * @dataProvider validAbsoluteProvider + * @dataProvider providerValidAbsolute */ - public function testValidAbsolute($url) { - $url_schemes = array('http', 'https', 'ftp'); - foreach ($url_schemes as $scheme) { - $test_url = $scheme . '://' . $url; - $valid_url = UrlValidator::isValid($test_url, TRUE); - $this->assertTrue($valid_url, String::format('@url is a valid URL.', array('@url' => $test_url))); - } + public function testValidAbsolute($url, $scheme) { + $test_url = $scheme . '://' . $url; + $valid_url = UrlValidator::isValid($test_url, TRUE); + $this->assertTrue($valid_url, String::format('@url is a valid URL.', array('@url' => $test_url))); } /** * Provides invalid absolute URLs. */ - public function invalidAbsoluteProvider() { - return array( - array(''), - array('ex!ample.com'), - array('ex%ample.com'), + public function providerInvalidAbsolute() { + $data = array( + '', + 'ex!ample.com', + 'ex%ample.com', ); + return $this->dataEnhanceWithScheme($data); } /** @@ -82,23 +85,21 @@ public function invalidAbsoluteProvider() { * * @param string $url * The url to test. + * @param string $scheme + * The scheme to test. * - * @dataProvider invalidAbsoluteProvider + * @dataProvider providerInvalidAbsolute */ - public function testInvalidAbsolute($url) { - $url_schemes = array('http', 'https', 'ftp'); - - foreach ($url_schemes as $scheme) { - $test_url = $scheme . '://' . $url; - $valid_url = UrlValidator::isValid($test_url, TRUE); - $this->assertFalse($valid_url, String::format('@url is NOT a valid URL.', array('@url' => $test_url))); - } + public function testInvalidAbsolute($url, $scheme) { + $test_url = $scheme . '://' . $url; + $valid_url = UrlValidator::isValid($test_url, TRUE); + $this->assertFalse($valid_url, String::format('@url is NOT a valid URL.', array('@url' => $test_url))); } /** * Provides valid relative URLs */ - public function validRelativeProvider() { + public function providerValidRelative() { return array( array('paren(the)sis'), array('index.html#pagetop'), @@ -114,7 +115,7 @@ public function validRelativeProvider() { * @param string $url * The url to test. * - * @dataProvider validRelativeProvider + * @dataProvider providerValidRelative */ public function testValidRelative($url) { foreach (array('', '/') as $front) { @@ -127,7 +128,7 @@ public function testValidRelative($url) { /** * Provides invalid relative URLs. */ - public function invalidRelativeProvider() { + public function providerInvalidRelative() { return array( array('ex^mple'), array('example<>'), @@ -141,7 +142,7 @@ public function invalidRelativeProvider() { * @param string $url * The url to test. * - * @dataProvider invalidRelativeProvider + * @dataProvider providerInvalidRelative */ public function testInvalidRelative($url) { foreach (array('', '/') as $front) { @@ -151,4 +152,23 @@ public function testInvalidRelative($url) { } } + /** + * Enhancers test urls with schemes + * + * @param array $urls + * The list of urls. + * + * @return array + * A list of provider data with schemes. + */ + public function dataEnhanceWithScheme($urls) { + $url_schemes = array('http', 'https', 'ftp'); + foreach ($url_schemes as $scheme) { + foreach ($urls as $url) { + $data[] = array($url, $scheme); + } + } + return $data; + } + }