function DevelTwigExtensionTest::testDumpFunctionsRegistered

Same name in other branches
  1. 4.x tests/src/Kernel/DevelTwigExtensionTest.php \Drupal\Tests\devel\Kernel\DevelTwigExtensionTest::testDumpFunctionsRegistered()

Tests that the Twig dump functions are registered properly.

File

tests/src/Kernel/DevelTwigExtensionTest.php, line 82

Class

DevelTwigExtensionTest
Tests Twig extensions.

Namespace

Drupal\Tests\devel\Kernel

Code

public function testDumpFunctionsRegistered() : void {
    
    /** @var \Drupal\Core\Template\TwigEnvironment $environment */
    $environment = $this->container
        ->get('twig');
    $functions = $environment->getFunctions();
    $dump_functions = [
        'devel_dump',
        'kpr',
    ];
    $message_functions = [
        'devel_message',
        'dpm',
        'dsm',
    ];
    $registered_functions = $dump_functions + $message_functions;
    foreach ($registered_functions as $name) {
        $this->assertArrayHasKey($name, $functions);
        $function = $functions[$name];
        $this->assertEquals($function->getName(), $name);
        $this->assertTrue($function->needsContext());
        $this->assertTrue($function->needsEnvironment());
        $this->assertTrue($function->isVariadic());
        is_callable($function->getCallable(), TRUE, $callable);
        if (in_array($name, $dump_functions)) {
            $this->assertEquals($callable, Debug::class . '::dump');
        }
        else {
            $this->assertEquals($callable, Debug::class . '::message');
        }
    }
}