diff --git a/core/includes/common.inc b/core/includes/common.inc index 8b9d9e3..d193350 100644 --- a/core/includes/common.inc +++ b/core/includes/common.inc @@ -6,6 +6,8 @@ use Symfony\Component\Yaml\Parser; use Drupal\Component\PhpStorage\PhpStorageFactory; use Drupal\Component\Utility\NestedArray; +use Drupal\Component\Utility\String; +use Drupal\Component\Utility\Unicode; use Drupal\Core\Cache\CacheBackendInterface; use Drupal\Core\Datetime\DrupalDateTime; use Drupal\Core\Database\Database; @@ -3121,7 +3123,7 @@ function drupal_html_class($class) { static $classes = array(); if (!isset($classes[$class])) { - $classes[$class] = drupal_clean_css_identifier(drupal_strtolower($class)); + $classes[$class] = drupal_clean_css_identifier(Unicode::strtolower($class)); } return $classes[$class]; } @@ -3197,7 +3199,7 @@ function drupal_html_id($id) { } $seen_ids = &drupal_static(__FUNCTION__, $seen_ids_init); - $id = strtr(drupal_strtolower($id), array(' ' => '-', '_' => '-', '[' => '-', ']' => '')); + $id = strtr(Unicode::strtolower($id), array(' ' => '-', '_' => '-', '[' => '-', ']' => '')); // As defined in http://www.w3.org/TR/html4/types.html#type-name, HTML IDs can // only contain letters, digits ([0-9]), hyphens ("-"), underscores ("_"), @@ -5976,44 +5978,20 @@ function watchdog_severity_levels() { * Explodes a string of tags into an array. * * @see drupal_implode_tags() + * @see \Drupal\Component\Utility\String::explodeTags(). */ function drupal_explode_tags($tags) { - // This regexp allows the following types of user input: - // this, "somecompany, llc", "and ""this"" w,o.rks", foo bar - $regexp = '%(?:^|,\ *)("(?>[^"]*)(?>""[^"]* )*"|(?: [^",]*))%x'; - preg_match_all($regexp, $tags, $matches); - $typed_tags = array_unique($matches[1]); - - $tags = array(); - foreach ($typed_tags as $tag) { - // If a user has escaped a term (to demonstrate that it is a group, - // or includes a comma or quote character), we remove the escape - // formatting so to save the term into the database as the user intends. - $tag = trim(str_replace('""', '"', preg_replace('/^"(.*)"$/', '\1', $tag))); - if ($tag != "") { - $tags[] = $tag; - } - } - - return $tags; + return String::explodeTags($tags); } /** * Implodes an array of tags into a string. * * @see drupal_explode_tags() + * @see \Drupal\Component\Utility\String::implodeTags(). */ function drupal_implode_tags($tags) { - $encoded_tags = array(); - foreach ($tags as $tag) { - // Commas and quotes in tag names are special cases, so encode them. - if (strpos($tag, ',') !== FALSE || strpos($tag, '"') !== FALSE) { - $tag = '"' . str_replace('"', '""', $tag) . '"'; - } - - $encoded_tags[] = $tag; - } - return implode(', ', $encoded_tags); + return String::implodeTags($tags); } /** diff --git a/core/lib/Drupal/Component/Utility/String.php b/core/lib/Drupal/Component/Utility/String.php index a6df8fe..943ec24 100644 --- a/core/lib/Drupal/Component/Utility/String.php +++ b/core/lib/Drupal/Component/Utility/String.php @@ -122,4 +122,43 @@ public static function placeholder($text) { return '' . static::checkPlain($text) . ''; } + /** + * Explodes a string of tags into an array. + */ + public static function explodeTags($tags) { + // This regexp allows the following types of user input: + // this, "somecompany, llc", "and ""this"" w,o.rks", foo bar + $regexp = '%(?:^|,\ *)("(?>[^"]*)(?>""[^"]* )*"|(?: [^",]*))%x'; + preg_match_all($regexp, $tags, $matches); + $typed_tags = array_unique($matches[1]); + + $tags = array(); + foreach ($typed_tags as $tag) { + // If a user has escaped a term (to demonstrate that it is a group, + // or includes a comma or quote character), we remove the escape + // formatting so to save the term into the database as the user intends. + $tag = trim(str_replace('""', '"', preg_replace('/^"(.*)"$/', '\1', $tag))); + if ($tag != "") { + $tags[] = $tag; + } + } + + return $tags; + } + + /** + * Implodes an array of tags into a string. + */ + function implodeTags($tags) { + $encoded_tags = array(); + foreach ($tags as $tag) { + // Commas and quotes in tag names are special cases, so encode them. + if (strpos($tag, ',') !== FALSE || strpos($tag, '"') !== FALSE) { + $tag = '"' . str_replace('"', '""', $tag) . '"'; + } + + $encoded_tags[] = $tag; + } + return implode(', ', $encoded_tags); + } } diff --git a/core/lib/Drupal/Core/Template/AttributeArray.php b/core/lib/Drupal/Core/Template/AttributeArray.php index d3521e0..a32201e 100644 --- a/core/lib/Drupal/Core/Template/AttributeArray.php +++ b/core/lib/Drupal/Core/Template/AttributeArray.php @@ -7,6 +7,7 @@ namespace Drupal\Core\Template; +use Drupal\Component\Utility\String; /** * A class that defines a type of Attribute that can be added to as an array. @@ -66,7 +67,7 @@ public function offsetExists($offset) { */ public function __toString() { $this->printed = TRUE; - return implode(' ', array_map('check_plain', $this->value)); + return implode(' ', array_map(array('Drupal\Component\Utility\String', 'checkPlain'), $this->value)); } /** diff --git a/core/lib/Drupal/Core/Template/AttributeString.php b/core/lib/Drupal/Core/Template/AttributeString.php index 9776467..2c3ca24 100644 --- a/core/lib/Drupal/Core/Template/AttributeString.php +++ b/core/lib/Drupal/Core/Template/AttributeString.php @@ -7,6 +7,8 @@ namespace Drupal\Core\Template; +use Drupal\Component\Utility\String; + /** * A class that represents most standard HTML attributes. * @@ -29,7 +31,7 @@ class AttributeString extends AttributeValueBase { */ public function __toString() { $this->printed = TRUE; - return check_plain($this->value); + return String::checkPlain($this->value); } } diff --git a/core/lib/Drupal/Core/Utility/Color.php b/core/lib/Drupal/Core/Utility/Color.php index 27ba440..141d136 100644 --- a/core/lib/Drupal/Core/Utility/Color.php +++ b/core/lib/Drupal/Core/Utility/Color.php @@ -7,6 +7,8 @@ namespace Drupal\Core\Utility; +use Drupal\Component\Utility\Unicode; + /** * Performs color conversions. */ @@ -28,7 +30,7 @@ public static function validateHex($hex) { // Hash prefix is optional. $hex = ltrim($hex, '#'); // Must be either RGB or RRGGBB. - $length = drupal_strlen($hex); + $length = Unicode::strlen($hex); $valid = $valid && ($length === 3 || $length === 6); // Must be a valid hex value. $valid = $valid && ctype_xdigit($hex); diff --git a/core/modules/system/lib/Drupal/system/Tests/Common/ParseInfoFileUnitTest.php b/core/modules/system/lib/Drupal/system/Tests/Common/ParseInfoFileUnitTest.php deleted file mode 100644 index c02e006..0000000 --- a/core/modules/system/lib/Drupal/system/Tests/Common/ParseInfoFileUnitTest.php +++ /dev/null @@ -1,33 +0,0 @@ - 'Parsing .info.yml files', - 'description' => 'Tests the drupal_parse_info_file() API function.', - 'group' => 'Common', - ); - } - - /** - * Parses an example .info.yml file and verifies the results. - */ - function testParseInfoFile() { - $info_values = drupal_parse_info_file(drupal_get_path('module', 'system') . '/tests/common_test_info.txt'); - $this->assertEqual($info_values['simple_string'], 'A simple string', 'Simple string value was parsed correctly.', 'System'); - $this->assertEqual($info_values['version'], VERSION, 'Constant value was parsed correctly.', 'System'); - $this->assertEqual($info_values['double_colon'], 'dummyClassName::', 'Value containing double-colon was parsed correctly.', 'System'); - } -} diff --git a/core/modules/system/lib/Drupal/system/Tests/Common/AttributesUnitTest.php b/core/tests/Drupal/Tests/Core/Common/AttributesUnitTest.php similarity index 53% rename from core/modules/system/lib/Drupal/system/Tests/Common/AttributesUnitTest.php rename to core/tests/Drupal/Tests/Core/Common/AttributesUnitTest.php index 6910f7a..6cd652f 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Common/AttributesUnitTest.php +++ b/core/tests/Drupal/Tests/Core/Common/AttributesUnitTest.php @@ -5,15 +5,15 @@ * Definition of Drupal\system\Tests\Common\AttributesUnitTest. */ -namespace Drupal\system\Tests\Common; +namespace Drupal\Tests\Core\Common; use Drupal\Core\Template\Attribute; -use Drupal\simpletest\UnitTestBase; +use Drupal\Tests\UnitTestCase; /** * Tests the Drupal\Core\Template\Attribute functionality. */ -class AttributesUnitTest extends UnitTestBase { +class AttributesUnitTest extends UnitTestCase { public static function getInfo() { return array( 'name' => 'HTML Attributes', @@ -27,15 +27,15 @@ public static function getInfo() { */ function testDrupalAttributes() { // Verify that special characters are HTML encoded. - $this->assertIdentical((string) new Attribute(array('title' => '&"\'<>')), ' title="&"'<>"', 'HTML encode attribute values.'); + $this->assertSame((string) new Attribute(array('title' => '&"\'<>')), ' title="&"'<>"', 'HTML encode attribute values.'); // Verify multi-value attributes are concatenated with spaces. $attributes = array('class' => array('first', 'last')); - $this->assertIdentical((string) new Attribute(array('class' => array('first', 'last'))), ' class="first last"', 'Concatenate multi-value attributes.'); + $this->assertSame((string) new Attribute(array('class' => array('first', 'last'))), ' class="first last"', 'Concatenate multi-value attributes.'); // Verify empty attribute values are rendered. - $this->assertIdentical((string) new Attribute(array('alt' => '')), ' alt=""', 'Empty attribute value #1.'); - $this->assertIdentical((string) new Attribute(array('alt' => NULL)), ' alt=""', 'Empty attribute value #2.'); + $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( @@ -43,15 +43,15 @@ function testDrupalAttributes() { 'class' => array('first', 'last'), 'alt' => 'Alternate', ); - $this->assertIdentical((string) new Attribute($attributes), ' id="id-test" class="first last" alt="Alternate"', 'Multiple attributes.'); + $this->assertSame((string) new Attribute($attributes), ' id="id-test" class="first last" alt="Alternate"', 'Multiple attributes.'); // Verify empty attributes array is rendered. - $this->assertIdentical((string) new Attribute(array()), '', 'Empty attributes array.'); + $this->assertSame((string) new Attribute(array()), '', 'Empty attributes array.'); $attributes_array = array('key1' => 'value1'); $attribute = new Attribute($attributes_array); foreach($attribute as $value) { - $this->assertIdentical((string) $value, 'value1', 'Iterate over attribute.'); + $this->assertSame((string) $value, 'value1', 'Iterate over attribute.'); } } } diff --git a/core/modules/system/lib/Drupal/system/Tests/Common/AutocompleteTagsUnitTest.php b/core/tests/Drupal/Tests/Core/Common/AutocompleteTagsUnitTest.php similarity index 73% rename from core/modules/system/lib/Drupal/system/Tests/Common/AutocompleteTagsUnitTest.php rename to core/tests/Drupal/Tests/Core/Common/AutocompleteTagsUnitTest.php index 8240536..321daf1 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Common/AutocompleteTagsUnitTest.php +++ b/core/tests/Drupal/Tests/Core/Common/AutocompleteTagsUnitTest.php @@ -5,14 +5,15 @@ * Definition of Drupal\system\Tests\Common\AutocompleteTagsUnitTest. */ -namespace Drupal\system\Tests\Common; +namespace Drupal\Tests\Core\Common; -use Drupal\simpletest\UnitTestBase; +use Drupal\Component\Utility\String; +use Drupal\Tests\UnitTestCase; /** * Tests drupal_explode_tags() and drupal_implode_tags(). */ -class AutocompleteTagsUnitTest extends UnitTestBase { +class AutocompleteTagsUnitTest extends UnitTestCase { var $validTags = array( 'Drupal' => 'Drupal', 'Drupal with some spaces' => 'Drupal with some spaces', @@ -33,7 +34,7 @@ public static function getInfo() { */ function testDrupalExplodeTags() { $string = implode(', ', array_keys($this->validTags)); - $tags = drupal_explode_tags($string); + $tags = String::explodeTags($string); $this->assertTags($tags); } @@ -44,8 +45,8 @@ function testDrupalImplodeTags() { $tags = array_values($this->validTags); // Let's explode and implode to our heart's content. for ($i = 0; $i < 10; $i++) { - $string = drupal_implode_tags($tags); - $tags = drupal_explode_tags($string); + $string = String::implodeTags($tags); + $tags = String::explodeTags($string); } $this->assertTags($tags); } @@ -57,11 +58,11 @@ function assertTags($tags) { $original = $this->validTags; foreach ($tags as $tag) { $key = array_search($tag, $original); - $this->assertTrue($key, format_string('Make sure tag %tag shows up in the final tags array (originally %original)', array('%tag' => $tag, '%original' => $key))); + $this->assertTrue((bool) $key, $tag, sprintf('Make sure tag %s shows up in the final tags array (originally %s)', $tag, $key)); unset($original[$key]); } foreach ($original as $leftover) { - $this->fail(format_string('Leftover tag %leftover was left over.', array('%leftover' => $leftover))); + $this->fail(sprintf('Leftover tag %s was left over.', $leftover)); } } } diff --git a/core/modules/system/lib/Drupal/system/Tests/Common/ColorTest.php b/core/tests/Drupal/Tests/Core/Common/ColorTest.php similarity index 87% rename from core/modules/system/lib/Drupal/system/Tests/Common/ColorTest.php rename to core/tests/Drupal/Tests/Core/Common/ColorTest.php index 2c32b31..9d9e721 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Common/ColorTest.php +++ b/core/tests/Drupal/Tests/Core/Common/ColorTest.php @@ -5,15 +5,15 @@ * Definition of Drupal\system\Tests\Common\ColorTest. */ -namespace Drupal\system\Tests\Common; +namespace Drupal\Tests\Core\Common; use Drupal\Core\Utility\Color; -use Drupal\simpletest\UnitTestBase; +use Drupal\Tests\UnitTestCase; /** * Tests color conversion functions. */ -class ColorTest extends UnitTestBase { +class ColorTest extends UnitTestCase { public static function getInfo() { return array( @@ -48,7 +48,7 @@ function testHexToRgb() { $this->fail('Color::hexToRgb(' . var_export($test, TRUE) . ') did not throw an exception.'); } catch (\InvalidArgumentException $e) { - $this->pass('Color::hexToRgb(' . var_export($test, TRUE) . ') threw an exception.'); + // The exception was appropriatly thrown. } } @@ -68,7 +68,7 @@ function testHexToRgb() { ); foreach ($tests as $test) { $result = Color::hexToRgb($test['hex']); - $this->assertIdentical($result, $test['rgb']); + $this->assertSame($result, $test['rgb']); } } @@ -84,17 +84,17 @@ function testRgbToHex() { ); // Input using named RGB array (e.g., as returned by Color::hexToRgb()). foreach ($tests as $expected => $rgb) { - $this->assertIdentical(Color::rgbToHex($rgb), $expected); + $this->assertSame(Color::rgbToHex($rgb), $expected); } // Input using indexed RGB array (e.g.: array(10, 10, 10)). foreach ($tests as $expected => $rgb) { $rgb = array_values($rgb); - $this->assertIdentical(Color::rgbToHex($rgb), $expected); + $this->assertSame(Color::rgbToHex($rgb), $expected); } // Input using CSS RGB string notation (e.g.: 10, 10, 10). foreach ($tests as $expected => $rgb) { $rgb = implode(', ', $rgb); - $this->assertIdentical(Color::rgbToHex($rgb), $expected); + $this->assertSame(Color::rgbToHex($rgb), $expected); } } } diff --git a/core/modules/system/lib/Drupal/system/Tests/Common/DiffArrayUnitTest.php b/core/tests/Drupal/Tests/Core/Common/DiffArrayUnitTest.php similarity index 88% rename from core/modules/system/lib/Drupal/system/Tests/Common/DiffArrayUnitTest.php rename to core/tests/Drupal/Tests/Core/Common/DiffArrayUnitTest.php index a5ae7d2..6bccaaa 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Common/DiffArrayUnitTest.php +++ b/core/tests/Drupal/Tests/Core/Common/DiffArrayUnitTest.php @@ -5,15 +5,15 @@ * Contains \Drupal\system\Tests\Common\DiffArrayUnitTest. */ -namespace Drupal\system\Tests\Common; +namespace Drupal\Tests\Core\Common; use Drupal\Component\Utility\DiffArray; -use Drupal\simpletest\UnitTestBase; +use Drupal\Tests\UnitTestCase; /** * Tests the DiffArray helper class. */ -class DiffArrayUnitTest extends UnitTestBase { +class DiffArrayUnitTest extends UnitTestCase { /** * Array to use for testing. @@ -77,7 +77,7 @@ public function testDiffAssocRecursive() { 'new' => 'new', ); - $this->assertIdentical(DiffArray::diffAssocRecursive($this->array1, $this->array2), $expected); + $this->assertSame(DiffArray::diffAssocRecursive($this->array1, $this->array2), $expected); } } diff --git a/core/modules/system/lib/Drupal/system/Tests/Common/HtmlIdentifierUnitTest.php b/core/tests/Drupal/Tests/Core/Common/HtmlIdentifierUnitTest.php similarity index 53% rename from core/modules/system/lib/Drupal/system/Tests/Common/HtmlIdentifierUnitTest.php rename to core/tests/Drupal/Tests/Core/Common/HtmlIdentifierUnitTest.php index df4046c..28146a1 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Common/HtmlIdentifierUnitTest.php +++ b/core/tests/Drupal/Tests/Core/Common/HtmlIdentifierUnitTest.php @@ -5,14 +5,14 @@ * Definition of Drupal\system\Tests\Common\HtmlIdentifierUnitTest. */ -namespace Drupal\system\Tests\Common; +namespace Drupal\Tests\Core\Common; -use Drupal\simpletest\UnitTestBase; +use Drupal\Tests\UnitTestCase; /** * Tests cleaning HTML identifiers. */ -class HtmlIdentifierUnitTest extends UnitTestBase { +class HtmlIdentifierUnitTest extends UnitTestCase { public static function getInfo() { return array( 'name' => 'HTML identifiers', @@ -21,20 +21,24 @@ public static function getInfo() { ); } + function setUp() { + require_once __DIR__ . '/../../../../../includes/common.inc'; + } + /** * Tests that drupal_clean_css_identifier() cleans the identifier properly. */ function testDrupalCleanCSSIdentifier() { // Verify that no valid ASCII characters are stripped from the identifier. $identifier = 'abcdefghijklmnopqrstuvwxyz_ABCDEFGHIJKLMNOPQRSTUVWXYZ-0123456789'; - $this->assertIdentical(drupal_clean_css_identifier($identifier, array()), $identifier, 'Verify valid ASCII characters pass through.'); + $this->assertSame(drupal_clean_css_identifier($identifier, array()), $identifier, 'Verify valid ASCII characters pass through.'); // Verify that valid UTF-8 characters are not stripped from the identifier. $identifier = '¡¢£¤¥'; - $this->assertIdentical(drupal_clean_css_identifier($identifier, array()), $identifier, 'Verify valid UTF-8 characters pass through.'); + $this->assertSame(drupal_clean_css_identifier($identifier, array()), $identifier, 'Verify valid UTF-8 characters pass through.'); // Verify that invalid characters (including non-breaking space) are stripped from the identifier. - $this->assertIdentical(drupal_clean_css_identifier('invalid !"#$%&\'()*+,./:;<=>?@[\\]^`{|}~ identifier', array()), 'invalididentifier', 'Strip invalid characters.'); + $this->assertSame(drupal_clean_css_identifier('invalid !"#$%&\'()*+,./:;<=>?@[\\]^`{|}~ identifier', array()), 'invalididentifier', 'Strip invalid characters.'); } /** @@ -42,7 +46,7 @@ function testDrupalCleanCSSIdentifier() { */ function testDrupalHTMLClass() { // Verify Drupal coding standards are enforced. - $this->assertIdentical(drupal_html_class('CLASS NAME_[Ü]'), 'class-name--ü', 'Enforce Drupal coding standards.'); + $this->assertSame(drupal_html_class('CLASS NAME_[Ü]'), 'class-name--ü', 'Enforce Drupal coding standards.'); } /** @@ -51,20 +55,20 @@ function testDrupalHTMLClass() { function testDrupalHTMLId() { // Verify that letters, digits, and hyphens are not stripped from the ID. $id = 'abcdefghijklmnopqrstuvwxyz-0123456789'; - $this->assertIdentical(drupal_html_id($id), $id, 'Verify valid characters pass through.'); + $this->assertSame(drupal_html_id($id), $id, 'Verify valid characters pass through.'); // Verify that invalid characters are stripped from the ID. - $this->assertIdentical(drupal_html_id('invalid,./:@\\^`{Üidentifier'), 'invalididentifier', 'Strip invalid characters.'); + $this->assertSame(drupal_html_id('invalid,./:@\\^`{Üidentifier'), 'invalididentifier', 'Strip invalid characters.'); // Verify Drupal coding standards are enforced. - $this->assertIdentical(drupal_html_id('ID NAME_[1]'), 'id-name-1', 'Enforce Drupal coding standards.'); + $this->assertSame(drupal_html_id('ID NAME_[1]'), 'id-name-1', 'Enforce Drupal coding standards.'); // Reset the static cache so we can ensure the unique id count is at zero. drupal_static_reset('drupal_html_id'); // Clean up IDs with invalid starting characters. - $this->assertIdentical(drupal_html_id('test-unique-id'), 'test-unique-id', 'Test the uniqueness of IDs #1.'); - $this->assertIdentical(drupal_html_id('test-unique-id'), 'test-unique-id--2', 'Test the uniqueness of IDs #2.'); - $this->assertIdentical(drupal_html_id('test-unique-id'), 'test-unique-id--3', 'Test the uniqueness of IDs #3.'); + $this->assertSame(drupal_html_id('test-unique-id'), 'test-unique-id', 'Test the uniqueness of IDs #1.'); + $this->assertSame(drupal_html_id('test-unique-id'), 'test-unique-id--2', 'Test the uniqueness of IDs #2.'); + $this->assertSame(drupal_html_id('test-unique-id'), 'test-unique-id--3', 'Test the uniqueness of IDs #3.'); } } diff --git a/core/modules/system/lib/Drupal/system/Tests/Common/JsonUnitTest.php b/core/tests/Drupal/Tests/Core/Common/JsonUnitTest.php similarity index 81% rename from core/modules/system/lib/Drupal/system/Tests/Common/JsonUnitTest.php rename to core/tests/Drupal/Tests/Core/Common/JsonUnitTest.php index 3e771e4..7ced3f3 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Common/JsonUnitTest.php +++ b/core/tests/Drupal/Tests/Core/Common/JsonUnitTest.php @@ -5,14 +5,14 @@ * Definition of Drupal\system\Tests\Common\JsonUnitTest. */ -namespace Drupal\system\Tests\Common; +namespace Drupal\Tests\Core\Common; -use Drupal\simpletest\UnitTestBase; +use Drupal\Tests\UnitTestCase; /** * Tests the drupal_json_encode() and drupal_json_decode() functions. */ -class JsonUnitTest extends UnitTestBase { +class JsonUnitTest extends UnitTestCase { public static function getInfo() { return array( 'name' => 'JSON', @@ -38,7 +38,7 @@ function testJSON() { $html_unsafe_escaped = array('\u003C', '\u003E', '\u0027', '\u0026', '\u0022'); // Verify there aren't character encoding problems with the source string. - $this->assertIdentical(strlen($str), 128, 'A string with the full ASCII table has the correct length.'); + $this->assertSame(strlen($str), 128, 'A string with the full ASCII table has the correct length.'); foreach ($html_unsafe as $char) { $this->assertTrue(strpos($str, $char) > 0, format_string('A string with the full ASCII table includes @s.', array('@s' => $char))); } @@ -54,7 +54,7 @@ function testJSON() { // Verify that encoding/decoding is reversible. $json_decoded = drupal_json_decode($json); - $this->assertIdentical($str, $json_decoded, 'Encoding a string to JSON and decoding back results in the original string.'); + $this->assertSame($str, $json_decoded, 'Encoding a string to JSON and decoding back results in the original string.'); // Verify reversibility for structured data. Also verify that necessary // characters are escaped. @@ -68,7 +68,7 @@ function testJSON() { $this->assertTrue(strpos($json, $char) > 0, format_string('A JSON encoded string contains @s.', array('@s' => $char))); } $json_decoded = drupal_json_decode($json); - $this->assertNotIdentical($source, $json, 'An array encoded in JSON is not identical to the source.'); - $this->assertIdentical($source, $json_decoded, 'Encoding structured data to JSON and decoding back results in the original data.'); + $this->assertNotSame($source, $json, 'An array encoded in JSON is not identical to the source.'); + $this->assertSame($source, $json_decoded, 'Encoding structured data to JSON and decoding back results in the original data.'); } } diff --git a/core/tests/Drupal/Tests/Core/Common/ParseInfoFileUnitTest.php b/core/tests/Drupal/Tests/Core/Common/ParseInfoFileUnitTest.php new file mode 100644 index 0000000..b951b17 --- /dev/null +++ b/core/tests/Drupal/Tests/Core/Common/ParseInfoFileUnitTest.php @@ -0,0 +1,34 @@ + 'Parsing .info.yml files', + 'description' => 'Tests the drupal_parse_info_file() API function.', + 'group' => 'Common', + ); + } + + /** + * Parses an example .info.yml file and verifies the results. + */ + function testParseInfoFile() { + $path = __DIR__ . '/../../../../../modules/system/tests/common_test_info.txt'; + $info_values = drupal_parse_info_file($path); + $this->assertEquals($info_values['simple_string'], 'A simple string', 'Simple string value was parsed correctly.'); + $this->assertEquals($info_values['version'], VERSION, 'Constant value was parsed correctly.'); + $this->assertEquals($info_values['double_colon'], 'dummyClassName::', 'Value containing double-colon was parsed correctly.'); + } +} diff --git a/core/modules/system/lib/Drupal/system/Tests/Common/SizeUnitTest.php b/core/tests/Drupal/Tests/Core/Common/SizeUnitTest.php similarity index 91% rename from core/modules/system/lib/Drupal/system/Tests/Common/SizeUnitTest.php rename to core/tests/Drupal/Tests/Core/Common/SizeUnitTest.php index a8a2662..3893333 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Common/SizeUnitTest.php +++ b/core/tests/Drupal/Tests/Core/Common/SizeUnitTest.php @@ -5,14 +5,14 @@ * Definition of Drupal\system\Tests\Common\SizeUnitTest. */ -namespace Drupal\system\Tests\Common; +namespace Drupal\Tests\Core\Common; -use Drupal\simpletest\UnitTestBase; +use Drupal\Tests\UnitTestCase; /** * Tests file size parsing and formatting functions. */ -class SizeUnitTest extends UnitTestBase { +class SizeUnitTest extends UnitTestCase { protected $exact_test_cases; protected $rounded_test_cases; @@ -53,7 +53,7 @@ function setUp() { function testCommonFormatSize() { foreach (array($this->exact_test_cases, $this->rounded_test_cases) as $test_cases) { foreach ($test_cases as $expected => $input) { - $this->assertEqual( + $this->assertEquals( ($result = format_size($input, NULL)), $expected, $expected . ' == ' . $result . ' (' . $input . ' bytes)' @@ -67,7 +67,7 @@ function testCommonFormatSize() { */ function testCommonParseSize() { foreach ($this->exact_test_cases as $string => $size) { - $this->assertEqual( + $this->assertEquals( $parsed_size = parse_size($string), $size, $size . ' == ' . $parsed_size . ' (' . $string . ')' @@ -76,19 +76,19 @@ function testCommonParseSize() { // Some custom parsing tests $string = '23476892 bytes'; - $this->assertEqual( + $this->assertEquals( ($parsed_size = parse_size($string)), $size = 23476892, $string . ' == ' . $parsed_size . ' bytes' ); $string = '76MRandomStringThatShouldBeIgnoredByParseSize.'; // 76 MB - $this->assertEqual( + $this->assertEquals( $parsed_size = parse_size($string), $size = 79691776, $string . ' == ' . $parsed_size . ' bytes' ); $string = '76.24 Giggabyte'; // Misspeld text -> 76.24 GB - $this->assertEqual( + $this->assertEquals( $parsed_size = parse_size($string), $size = 81862076662, $string . ' == ' . $parsed_size . ' bytes' @@ -100,7 +100,7 @@ function testCommonParseSize() { */ function testCommonParseSizeFormatSize() { foreach ($this->exact_test_cases as $size) { - $this->assertEqual( + $this->assertEquals( $size, ($parsed_size = parse_size($string = format_size($size, NULL))), $size . ' == ' . $parsed_size . ' (' . $string . ')' diff --git a/core/modules/system/lib/Drupal/system/Tests/Common/TableSortExtenderUnitTest.php b/core/tests/Drupal/Tests/Core/Common/TableSortExtenderUnitTest.php similarity index 73% rename from core/modules/system/lib/Drupal/system/Tests/Common/TableSortExtenderUnitTest.php rename to core/tests/Drupal/Tests/Core/Common/TableSortExtenderUnitTest.php index c7cc2a9..b25b013 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Common/TableSortExtenderUnitTest.php +++ b/core/tests/Drupal/Tests/Core/Common/TableSortExtenderUnitTest.php @@ -5,14 +5,14 @@ * Definition of Drupal\system\Tests\Common\TableSortExtenderTest. */ -namespace Drupal\system\Tests\Common; +namespace Drupal\Tests\Core\Common; -use Drupal\simpletest\UnitTestBase; +use Drupal\Tests\UnitTestCase; /** * Tests unicode handling features implemented in unicode.inc. */ -class TableSortExtenderUnitTest extends UnitTestBase { +class TableSortExtenderUnitTest extends UnitTestCase { /** * Storage for initial value of $_GET. @@ -34,6 +34,7 @@ function setUp() { $this->GET = $_GET; parent::setUp(); + require __DIR__ . '/../../../../../includes/tablesort.inc'; } function tearDown() { @@ -61,8 +62,7 @@ function testTableSortInit() { 'query' => array(), ); $ts = tablesort_init($headers); - $this->verbose(strtr('$ts:
!ts', array('!ts' => check_plain(var_export($ts, TRUE))))); - $this->assertEqual($ts, $expected_ts, 'Simple table headers sorted correctly.'); + $this->assertEquals($ts, $expected_ts, 'Simple table headers sorted correctly.'); // Test with simple table headers plus $_GET parameters that should _not_ // override the default. @@ -73,8 +73,7 @@ function testTableSortInit() { 'order' => 'bar', ); $ts = tablesort_init($headers); - $this->verbose(strtr('$ts:
!ts', array('!ts' => check_plain(var_export($ts, TRUE))))); - $this->assertEqual($ts, $expected_ts, 'Simple table headers plus non-overriding $_GET parameters sorted correctly.'); + $this->assertEquals($ts, $expected_ts, 'Simple table headers plus non-overriding $_GET parameters sorted correctly.'); // Test with simple table headers plus $_GET parameters that _should_ // override the default. @@ -88,8 +87,7 @@ function testTableSortInit() { $expected_ts['sort'] = 'desc'; $expected_ts['query'] = array('alpha' => 'beta'); $ts = tablesort_init($headers); - $this->verbose(strtr('$ts:
!ts', array('!ts' => check_plain(var_export($ts, TRUE))))); - $this->assertEqual($ts, $expected_ts, 'Simple table headers plus $_GET parameters sorted correctly.'); + $this->assertEquals($ts, $expected_ts, 'Simple table headers plus $_GET parameters sorted correctly.'); // Test complex table headers. @@ -118,8 +116,7 @@ function testTableSortInit() { 'sort' => 'desc', 'query' => array(), ); - $this->verbose(strtr('$ts:
!ts', array('!ts' => check_plain(var_export($ts, TRUE))))); - $this->assertEqual($ts, $expected_ts, 'Complex table headers sorted correctly.'); + $this->assertEquals($ts, $expected_ts, 'Complex table headers sorted correctly.'); // Test complex table headers plus $_GET parameters that should _not_ // override the default. @@ -136,8 +133,7 @@ function testTableSortInit() { 'sort' => 'asc', 'query' => array(), ); - $this->verbose(strtr('$ts:
!ts', array('!ts' => check_plain(var_export($ts, TRUE))))); - $this->assertEqual($ts, $expected_ts, 'Complex table headers plus non-overriding $_GET parameters sorted correctly.'); + $this->assertEquals($ts, $expected_ts, 'Complex table headers plus non-overriding $_GET parameters sorted correctly.'); unset($_GET['sort'], $_GET['order'], $_GET['alpha']); // Test complex table headers plus $_GET parameters that _should_ @@ -157,8 +153,7 @@ function testTableSortInit() { 'query' => array('alpha' => 'beta'), ); $ts = tablesort_init($headers); - $this->verbose(strtr('$ts:
!ts', array('!ts' => check_plain(var_export($ts, TRUE))))); - $this->assertEqual($ts, $expected_ts, 'Complex table headers plus $_GET parameters sorted correctly.'); + $this->assertEquals($ts, $expected_ts, 'Complex table headers plus $_GET parameters sorted correctly.'); unset($_GET['sort'], $_GET['order'], $_GET['alpha']); } diff --git a/core/modules/system/lib/Drupal/system/Tests/Common/ValidNumberStepUnitTest.php b/core/tests/Drupal/Tests/Core/Common/ValidNumberStepUnitTest.php similarity index 94% rename from core/modules/system/lib/Drupal/system/Tests/Common/ValidNumberStepUnitTest.php rename to core/tests/Drupal/Tests/Core/Common/ValidNumberStepUnitTest.php index 2d5d314..fe267c4 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Common/ValidNumberStepUnitTest.php +++ b/core/tests/Drupal/Tests/Core/Common/ValidNumberStepUnitTest.php @@ -5,14 +5,14 @@ * Definition of Drupal\system\Tests\Common\ValidNumberStepUnitTest. */ -namespace Drupal\system\Tests\Common; +namespace Drupal\Tests\Core\Common; -use Drupal\simpletest\UnitTestBase; +use Drupal\Tests\UnitTestCase; /** * Tests number step validation by valid_number_step(). */ -class ValidNumberStepUnitTest extends UnitTestBase { +class ValidNumberStepUnitTest extends UnitTestCase { public static function getInfo() { return array( 'name' => 'Number step validation', diff --git a/core/modules/system/lib/Drupal/system/Tests/Common/ValidUrlUnitTest.php b/core/tests/Drupal/Tests/Core/Common/ValidUrlUnitTest.php similarity index 96% rename from core/modules/system/lib/Drupal/system/Tests/Common/ValidUrlUnitTest.php rename to core/tests/Drupal/Tests/Core/Common/ValidUrlUnitTest.php index 6750d27..d88b472 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Common/ValidUrlUnitTest.php +++ b/core/tests/Drupal/Tests/Core/Common/ValidUrlUnitTest.php @@ -5,14 +5,14 @@ * Definition of Drupal\system\Tests\Common\ValidUrlUnitTest. */ -namespace Drupal\system\Tests\Common; +namespace Drupal\Tests\Core\Common; -use Drupal\simpletest\UnitTestBase; +use Drupal\Tests\UnitTestCase; /** * Tests URL validation by valid_url(). */ -class ValidUrlUnitTest extends UnitTestBase { +class ValidUrlUnitTest extends UnitTestCase { public static function getInfo() { return array( 'name' => 'URL validation', diff --git a/core/tests/bootstrap.php b/core/tests/bootstrap.php index 08d8871..180a0cb 100644 --- a/core/tests/bootstrap.php +++ b/core/tests/bootstrap.php @@ -18,8 +18,8 @@ } require __DIR__ . "/../../core/lib/Drupal.php"; -// Look into removing this later. -define('REQUEST_TIME', (int) $_SERVER['REQUEST_TIME']); +// @todo Look into removing this later. +require_once __DIR__ . '/../includes/bootstrap.inc'; // Set sane locale settings, to ensure consistent string, dates, times and // numbers handling.