class PlaceholderGeneratorTest

Same name in other branches
  1. 9 core/tests/Drupal/Tests/Core/Render/PlaceholderGeneratorTest.php \Drupal\Tests\Core\Render\PlaceholderGeneratorTest
  2. 10 core/tests/Drupal/Tests/Core/Render/PlaceholderGeneratorTest.php \Drupal\Tests\Core\Render\PlaceholderGeneratorTest
  3. 11.x core/tests/Drupal/Tests/Core/Render/PlaceholderGeneratorTest.php \Drupal\Tests\Core\Render\PlaceholderGeneratorTest

@coversDefaultClass \Drupal\Core\Render\PlaceholderGenerator @group Render

Hierarchy

Expanded class hierarchy of PlaceholderGeneratorTest

File

core/tests/Drupal/Tests/Core/Render/PlaceholderGeneratorTest.php, line 11

Namespace

Drupal\Tests\Core\Render
View source
class PlaceholderGeneratorTest extends RendererTestBase {
    
    /**
     * The tested placeholder generator.
     *
     * @var \Drupal\Core\Render\PlaceholderGenerator
     */
    protected $placeholderGenerator;
    
    /**
     * @covers ::createPlaceholder
     * @dataProvider providerCreatePlaceholderGeneratesValidHtmlMarkup
     *
     * Ensure that the generated placeholder markup is valid. If it is not, then
     * simply using DOMDocument on HTML that contains placeholders may modify the
     * placeholders' markup, which would make it impossible to replace the
     * placeholders: the placeholder markup in #attached versus that in the HTML
     * processed by DOMDocument would no longer match.
     */
    public function testCreatePlaceholderGeneratesValidHtmlMarkup(array $element) {
        $build = $this->placeholderGenerator
            ->createPlaceholder($element);
        $original_placeholder_markup = (string) $build['#markup'];
        $processed_placeholder_markup = Html::serialize(Html::load($build['#markup']));
        $this->assertEquals($original_placeholder_markup, $processed_placeholder_markup);
    }
    
    /**
     * @return array
     */
    public function providerCreatePlaceholderGeneratesValidHtmlMarkup() {
        return [
            'multiple-arguments' => [
                [
                    '#lazy_builder' => [
                        'Drupal\\Tests\\Core\\Render\\PlaceholdersTest::callback',
                        [
                            'foo',
                            'bar',
                        ],
                    ],
                ],
            ],
            'special-character-&' => [
                [
                    '#lazy_builder' => [
                        'Drupal\\Tests\\Core\\Render\\PlaceholdersTest::callback',
                        [
                            'foo&bar',
                        ],
                    ],
                ],
            ],
            'special-character-"' => [
                [
                    '#lazy_builder' => [
                        'Drupal\\Tests\\Core\\Render\\PlaceholdersTest::callback',
                        [
                            'foo"bar',
                        ],
                    ],
                ],
            ],
            'special-character-<' => [
                [
                    '#lazy_builder' => [
                        'Drupal\\Tests\\Core\\Render\\PlaceholdersTest::callback',
                        [
                            'foo<bar',
                        ],
                    ],
                ],
            ],
            'special-character->' => [
                [
                    '#lazy_builder' => [
                        'Drupal\\Tests\\Core\\Render\\PlaceholdersTest::callback',
                        [
                            'foo>bar',
                        ],
                    ],
                ],
            ],
        ];
    }

}

Members

Title Sort descending Deprecated Modifiers Object type Summary Overriden Title Overrides
PhpunitCompatibilityTrait::getMock Deprecated public function Returns a mock object for the specified class using the available method.
PhpunitCompatibilityTrait::setExpectedException Deprecated public function Compatibility layer for PHPUnit 6 to support PHPUnit 4 code.
PlaceholderGeneratorTest::$placeholderGenerator protected property The tested placeholder generator. Overrides RendererTestBase::$placeholderGenerator
PlaceholderGeneratorTest::providerCreatePlaceholderGeneratesValidHtmlMarkup public function
PlaceholderGeneratorTest::testCreatePlaceholderGeneratesValidHtmlMarkup public function @covers ::createPlaceholder
@dataProvider providerCreatePlaceholderGeneratesValidHtmlMarkup
RendererTestBase::$cacheContexts protected property
RendererTestBase::$cacheFactory protected property
RendererTestBase::$controllerResolver protected property The mocked controller resolver.
RendererTestBase::$currentUserRole protected property The simulated &quot;current&quot; user role, for use in tests with cache contexts.
RendererTestBase::$elementInfo protected property The mocked element info.
RendererTestBase::$memoryCache protected property
RendererTestBase::$renderCache protected property The tested render cache.
RendererTestBase::$renderer protected property The tested renderer.
RendererTestBase::$rendererConfig protected property The mocked renderer configuration.
RendererTestBase::$requestStack protected property
RendererTestBase::$themeManager protected property The mocked theme manager.
RendererTestBase::assertRenderCacheItem protected function Asserts a render cache item.
RendererTestBase::randomContextValue protected function Generates a random context value for the placeholder tests.
RendererTestBase::setUp protected function Overrides UnitTestCase::setUp 3
RendererTestBase::setupMemoryCache protected function Sets up a memory-based render cache back-end.
RendererTestBase::setUpRequest protected function Sets up a request object on the request stack.
RendererTestBase::setUpUnusedCache protected function Sets up a render cache back-end that is asserted to be never used.
UnitTestCase::$randomGenerator protected property The random generator.
UnitTestCase::$root protected property The app root. 1
UnitTestCase::assertArrayEquals protected function Asserts if two arrays are equal by sorting them first.
UnitTestCase::getBlockMockWithMachineName Deprecated protected function Mocks a block with a block plugin. 1
UnitTestCase::getClassResolverStub protected function Returns a stub class resolver.
UnitTestCase::getConfigFactoryStub public function Returns a stub config factory that behaves according to the passed array.
UnitTestCase::getConfigStorageStub public function Returns a stub config storage that returns the supplied configuration.
UnitTestCase::getContainerWithCacheTagsInvalidator protected function Sets up a container with a cache tags invalidator.
UnitTestCase::getRandomGenerator protected function Gets the random generator for the utility methods.
UnitTestCase::getStringTranslationStub public function Returns a stub translation manager that just returns the passed string.
UnitTestCase::randomMachineName public function Generates a unique random string containing letters and numbers.

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.