StringLoader example

public function testActiveTheme() {
    $active_theme = $this->getMockBuilder('\Drupal\Core\Theme\ActiveTheme')
      ->disableOriginalConstructor()
      ->getMock();
    $active_theme->expects($this->once())
      ->method('getName')
      ->willReturn('test_theme');
    $this->themeManager->expects($this->once())
      ->method('getActiveTheme')
      ->willReturn($active_theme);

    $loader = new StringLoader();
    $twig = new Environment($loader);
    $twig->addExtension($this->systemUnderTest);
    $result = $twig->render('{{ active_theme() }}');
    $this->assertEquals('test_theme', $result);
  }

  /** * Tests the format_date filter. */
  public function testFormatDate() {
    $this->dateFormatter->expects($this->exactly(1))
      
$this->assertEquals($expected$attribute['class']->value(), 'Attributes chained');
  }

  /** * Tests the twig calls to the Attribute. * @dataProvider providerTestAttributeClassHelpers * * @covers ::removeClass * @covers ::addClass */
  public function testTwigAddRemoveClasses($template$expected$seed_attributes = []) {
    $loader = new StringLoader();
    $twig = new Environment($loader);
    $data = ['attributes' => new Attribute($seed_attributes)];
    $result = $twig->createTemplate($template)->render($data);
    $this->assertEquals($expected$result);
  }

  /** * Provides tests data for testEscaping. * * @return array * An array of test data each containing of a twig template string, * a resulting string of classes and an optional array of attributes. */

  protected $twig;

  /** * {@inheritdoc} */
  protected function setUp(): void {
    parent::setUp();

    $loader = new StringLoader();
    $this->twig = new Environment($loader);
    $policy = new TwigSandboxPolicy();
    $sandbox = new SandboxExtension($policy, TRUE);
    $this->twig->addExtension($sandbox);
  }

  /** * Tests that dangerous methods cannot be called in entity objects. * * @dataProvider getTwigEntityDangerousMethods */
  
Home | Imprint | This part of the site doesn't use cookies.