Chris@0: setAccessible(TRUE); Chris@0: $property->setValue(NULL); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Tests the Html::cleanCssIdentifier() method. Chris@0: * Chris@0: * @param string $expected Chris@0: * The expected result. Chris@0: * @param string $source Chris@0: * The string being transformed to an ID. Chris@0: * @param array|null $filter Chris@0: * (optional) An array of string replacements to use on the identifier. If Chris@0: * NULL, no filter will be passed and a default will be used. Chris@0: * Chris@0: * @dataProvider providerTestCleanCssIdentifier Chris@0: * Chris@0: * @covers ::cleanCssIdentifier Chris@0: */ Chris@0: public function testCleanCssIdentifier($expected, $source, $filter = NULL) { Chris@0: if ($filter !== NULL) { Chris@0: $this->assertSame($expected, Html::cleanCssIdentifier($source, $filter)); Chris@0: } Chris@0: else { Chris@0: $this->assertSame($expected, Html::cleanCssIdentifier($source)); Chris@0: } Chris@0: } Chris@0: Chris@0: /** Chris@0: * Provides test data for testCleanCssIdentifier(). Chris@0: * Chris@0: * @return array Chris@0: * Test data. Chris@0: */ Chris@0: public function providerTestCleanCssIdentifier() { Chris@0: $id1 = 'abcdefghijklmnopqrstuvwxyz_ABCDEFGHIJKLMNOPQRSTUVWXYZ-0123456789'; Chris@0: $id2 = '¡¢£¤¥'; Chris@0: $id3 = 'css__identifier__with__double__underscores'; Chris@0: return [ Chris@0: // Verify that no valid ASCII characters are stripped from the identifier. Chris@0: [$id1, $id1, []], Chris@0: // Verify that valid UTF-8 characters are not stripped from the identifier. Chris@0: [$id2, $id2, []], Chris@12: // Verify that double underscores are not stripped from the identifier. Chris@0: [$id3, $id3], Chris@12: // Verify that invalid characters (including non-breaking space) are Chris@12: // stripped from the identifier. Chris@0: ['invalididentifier', 'invalid !"#$%&\'()*+,./:;<=>?@[\\]^`{|}~ identifier', []], Chris@0: // Verify that an identifier starting with a digit is replaced. Chris@0: ['_cssidentifier', '1cssidentifier', []], Chris@0: // Verify that an identifier starting with a hyphen followed by a digit is Chris@0: // replaced. Chris@0: ['__cssidentifier', '-1cssidentifier', []], Chris@0: // Verify that an identifier starting with two hyphens is replaced. Chris@0: ['__cssidentifier', '--cssidentifier', []], Chris@0: // Verify that passing double underscores as a filter is processed. Chris@0: ['_cssidentifier', '__cssidentifier', ['__' => '_']], Chris@0: ]; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Tests that Html::getClass() cleans the class name properly. Chris@0: * Chris@0: * @coversDefaultClass ::getClass Chris@0: */ Chris@0: public function testHtmlClass() { Chris@0: // Verify Drupal coding standards are enforced. Chris@0: $this->assertSame('class-name--ü', Html::getClass('CLASS NAME_[Ü]'), 'Enforce Drupal coding standards.'); Chris@0: Chris@0: // Test Html::getClass() handles Drupal\Component\Render\MarkupInterface Chris@0: // input. Chris@0: $markup = HtmlTestMarkup::create('CLASS_FROM_OBJECT'); Chris@0: $this->assertSame('class-from-object', Html::getClass($markup), 'Markup object is converted to CSS class.'); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Tests the Html::getUniqueId() method. Chris@0: * Chris@0: * @param string $expected Chris@0: * The expected result. Chris@0: * @param string $source Chris@0: * The string being transformed to an ID. Chris@0: * @param bool $reset Chris@0: * (optional) If TRUE, reset the list of seen IDs. Defaults to FALSE. Chris@0: * Chris@0: * @dataProvider providerTestHtmlGetUniqueId Chris@0: * Chris@0: * @covers ::getUniqueId Chris@0: */ Chris@0: public function testHtmlGetUniqueId($expected, $source, $reset = FALSE) { Chris@0: if ($reset) { Chris@0: Html::resetSeenIds(); Chris@0: } Chris@0: $this->assertSame($expected, Html::getUniqueId($source)); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Provides test data for testHtmlGetId(). Chris@0: * Chris@0: * @return array Chris@0: * Test data. Chris@0: */ Chris@0: public function providerTestHtmlGetUniqueId() { Chris@0: $id = 'abcdefghijklmnopqrstuvwxyz-0123456789'; Chris@0: return [ Chris@0: // Verify that letters, digits, and hyphens are not stripped from the ID. Chris@0: [$id, $id], Chris@0: // Verify that invalid characters are stripped from the ID. Chris@0: ['invalididentifier', 'invalid,./:@\\^`{Üidentifier'], Chris@0: // Verify Drupal coding standards are enforced. Chris@0: ['id-name-1', 'ID NAME_[1]'], Chris@0: // Verify that a repeated ID is made unique. Chris@0: ['test-unique-id', 'test-unique-id', TRUE], Chris@0: ['test-unique-id--2', 'test-unique-id'], Chris@0: ['test-unique-id--3', 'test-unique-id'], Chris@0: ]; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Tests the Html::getUniqueId() method. Chris@0: * Chris@0: * @param string $expected Chris@0: * The expected result. Chris@0: * @param string $source Chris@0: * The string being transformed to an ID. Chris@0: * Chris@0: * @dataProvider providerTestHtmlGetUniqueIdWithAjaxIds Chris@0: * Chris@0: * @covers ::getUniqueId Chris@0: */ Chris@0: public function testHtmlGetUniqueIdWithAjaxIds($expected, $source) { Chris@0: Html::setIsAjax(TRUE); Chris@0: $id = Html::getUniqueId($source); Chris@0: Chris@0: // Note, we truncate two hyphens at the end. Chris@0: // @see \Drupal\Component\Utility\Html::getId() Chris@0: if (strpos($source, '--') !== FALSE) { Chris@0: $random_suffix = substr($id, strlen($source) + 1); Chris@0: } Chris@0: else { Chris@0: $random_suffix = substr($id, strlen($source) + 2); Chris@0: } Chris@0: $expected = $expected . $random_suffix; Chris@0: $this->assertSame($expected, $id); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Provides test data for testHtmlGetId(). Chris@0: * Chris@0: * @return array Chris@0: * Test data. Chris@0: */ Chris@0: public function providerTestHtmlGetUniqueIdWithAjaxIds() { Chris@0: return [ Chris@0: ['test-unique-id1--', 'test-unique-id1'], Chris@0: // Note, we truncate two hyphens at the end. Chris@0: // @see \Drupal\Component\Utility\Html::getId() Chris@0: ['test-unique-id1---', 'test-unique-id1--'], Chris@0: ['test-unique-id2--', 'test-unique-id2'], Chris@0: ]; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Tests the Html::getUniqueId() method. Chris@0: * Chris@0: * @param string $expected Chris@0: * The expected result. Chris@0: * @param string $source Chris@0: * The string being transformed to an ID. Chris@0: * Chris@0: * @dataProvider providerTestHtmlGetId Chris@0: * Chris@0: * @covers ::getId Chris@0: */ Chris@0: public function testHtmlGetId($expected, $source) { Chris@0: Html::setIsAjax(FALSE); Chris@0: $this->assertSame($expected, Html::getId($source)); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Provides test data for testHtmlGetId(). Chris@0: * Chris@0: * @return array Chris@0: * Test data. Chris@0: */ Chris@0: public function providerTestHtmlGetId() { Chris@0: $id = 'abcdefghijklmnopqrstuvwxyz-0123456789'; Chris@0: return [ Chris@0: // Verify that letters, digits, and hyphens are not stripped from the ID. Chris@0: [$id, $id], Chris@0: // Verify that invalid characters are stripped from the ID. Chris@0: ['invalididentifier', 'invalid,./:@\\^`{Üidentifier'], Chris@0: // Verify Drupal coding standards are enforced. Chris@0: ['id-name-1', 'ID NAME_[1]'], Chris@0: // Verify that a repeated ID is made unique. Chris@0: ['test-unique-id', 'test-unique-id'], Chris@0: ['test-unique-id', 'test-unique-id'], Chris@0: ]; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Tests Html::decodeEntities(). Chris@0: * Chris@0: * @dataProvider providerDecodeEntities Chris@0: * @covers ::decodeEntities Chris@0: */ Chris@0: public function testDecodeEntities($text, $expected) { Chris@0: $this->assertEquals($expected, Html::decodeEntities($text)); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Data provider for testDecodeEntities(). Chris@0: * Chris@0: * @see testDecodeEntities() Chris@0: */ Chris@0: public function providerDecodeEntities() { Chris@0: return [ Chris@0: ['Drupal', 'Drupal'], Chris@0: ['