View source
<?php
namespace Drupal\Tests\bamboo_twig\Functional;
use Drupal\Tests\taxonomy\Functional\TaxonomyTestTrait;
use Drupal\Core\StreamWrapper\PublicStream;
class BambooTwigRenderTest extends BambooTwigTestBase {
use TaxonomyTestTrait;
public static $modules = [
'locale',
'language',
'node',
'user',
'taxonomy',
'image',
'file',
'system',
'views',
'bamboo_twig',
'bamboo_twig_loader',
'bamboo_twig_test',
];
public function setUp() {
parent::setUp();
$this
->setUpLanguages();
$this
->setUpTags();
$this
->setUpArticles();
$this->admin_user = $this
->drupalCreateUser([
'access content',
'administer blocks',
'administer content types',
'bypass node access',
'administer site configuration',
'view the administration theme',
'administer menu',
'access administration pages',
]);
$this->file = $this
->createFile();
$this->container
->get('router.builder')
->rebuild();
}
public function testBlock() {
$this
->drupalGet('/bamboo-twig-render');
$this
->assertElementPresent('.test-render div.render-block-plugin');
$this
->assertElementContains('.test-render div.render-block-plugin', '<span>Powered by <a href="https://www.drupal.org">Drupal</a></span>');
$this
->assertElementPresent('.test-render div.render-block-entity');
$this
->assertElementPresent('.test-render div.render-block-entity #block-stark-branding');
}
public function testRegion() {
$this
->drupalGet('/bamboo-twig-render');
$this
->assertElementPresent('.test-render div.render-region');
$this
->assertElementPresent('.test-render div.render-region #block-stark-branding');
}
public function testEntity() {
$this
->drupalGet('/bamboo-twig-render');
$this
->assertElementContains('.test-render div.render-entity-node-1 h2 a', 'News N°1');
$this
->assertElementContains('.test-render div.render-entity-node-1 footer', 'Submitted by');
$this
->assertElementContains('.test-render div.render-entity-node-1', 'Mot clé N°4');
$this
->assertElementContains('.test-render div.render-entity-node-1-teaser h2 a', 'News N°1');
$this
->assertElementContains('.test-render div.render-entity-node-1-teaser footer', 'Submitted by');
$this
->assertElementContains('.test-render div.render-entity-node-1-teaser .links', 'Read more');
$this
->assertElementContains('.test-render div.render-entity-node-2 h2 a', 'News N°2');
$this
->assertElementContains('.test-render div.render-entity-node-2', 'Tag N°2');
$this
->assertElementContains('.test-render div.render-entity-node-2-teaser h2 a', 'News N°2');
$this
->assertElementContains('.test-render div.render-entity-node-3 h2 a', 'News N°3');
$this
->assertElementContains('.test-render div.render-entity-node-3', 'Tag N°3');
$this
->assertElementContains('.test-render div.render-entity-node-3-teaser h2 a', 'News N°3');
$this
->assertElementContains('.test-render div.render-entity-node-4 h2 a', 'Article N°4');
$this
->assertElementContains('.test-render div.render-entity-node-4', 'Tag N°1');
$this
->assertElementContains('.test-render div.render-entity-node-4-teaser h2 a', 'Article N°4');
$this
->assertElementContains('.test-render div.render-entity-node-5 h2 a', 'News N°5');
$this
->assertElementContains('.test-render div.render-entity-node-5', 'Tag N°5');
$this
->assertElementContains('.test-render div.render-entity-node-5-teaser h2 a', 'News N°5');
$this
->assertElementContains('.test-render div.render-entity-taxonomy-term-1 h2 a', 'Tag N°1');
$this
->assertElementContains('.test-render div.render-entity-taxonomy-term-1-link h2 a', 'Tag N°1');
$this
->assertElementContains('.test-render div.render-entity-taxonomy-term-2 h2 a', 'Tag N°2');
$this
->assertElementContains('.test-render div.render-entity-taxonomy-term-2-link h2 a', 'Tag N°2');
$this
->assertElementContains('.test-render div.render-entity-taxonomy-term-3 h2 a', 'Tag N°3');
$this
->assertElementContains('.test-render div.render-entity-taxonomy-term-3-link h2 a', 'Tag N°3');
$this
->assertElementContains('.test-render div.render-entity-taxonomy-term-4 h2 a', 'Mot clé N°4');
$this
->assertElementContains('.test-render div.render-entity-taxonomy-term-4-link h2 a', 'Mot clé N°4');
$this
->assertElementContains('.test-render div.render-entity-taxonomy-term-5 h2 a', 'Tag N°5');
$this
->assertElementContains('.test-render div.render-entity-taxonomy-term-5-link h2 a', 'Tag N°5');
$this
->assertElementContains('.test-render div.render-entity-user', 'Member for');
$this
->assertElementContains('.test-render div.render-entity-user-compact', 'Member for');
$this
->drupalGet('/fr/bamboo-twig-render');
$this
->assertElementContains('.test-render div.render-entity-node-1 h2 a', 'News N°1');
$this
->assertElementContains('.test-render div.render-entity-node-1', 'Mot clé N°4');
$this
->assertElementContains('.test-render div.render-entity-node-1-teaser h2 a', 'News N°1');
$this
->assertElementContains('.test-render div.render-entity-node-2 h2 a', 'Article N°2');
$this
->assertElementContains('.test-render div.render-entity-node-2', 'Mot clé N°2');
$this
->assertElementContains('.test-render div.render-entity-node-2-teaser h2 a', 'Article N°2');
$this
->assertElementContains('.test-render div.render-entity-node-3 h2 a', 'Article N°3');
$this
->assertElementContains('.test-render div.render-entity-node-3', 'Mot clé N°3');
$this
->assertElementContains('.test-render div.render-entity-node-3-teaser h2 a', 'Article N°3');
$this
->assertElementContains('.test-render div.render-entity-node-4 h2 a', 'Article N°4');
$this
->assertElementContains('.test-render div.render-entity-node-4', 'Tag N°1');
$this
->assertElementContains('.test-render div.render-entity-node-4-teaser h2 a', 'Article N°4');
$this
->assertElementContains('.test-render div.render-entity-node-5 h2 a', 'Article N°5');
$this
->assertElementContains('.test-render div.render-entity-node-5', 'Mot clé N°5');
$this
->assertElementContains('.test-render div.render-entity-node-5-teaser h2 a', 'Article N°5');
$this
->assertElementContains('.test-render div.render-entity-taxonomy-term-1 h2 a', 'Tag N°1');
$this
->assertElementContains('.test-render div.render-entity-taxonomy-term-1-link h2 a', 'Tag N°1');
$this
->assertElementContains('.test-render div.render-entity-taxonomy-term-2 h2 a', 'Mot clé N°2');
$this
->assertElementContains('.test-render div.render-entity-taxonomy-term-2-link h2 a', 'Mot clé N°2');
$this
->assertElementContains('.test-render div.render-entity-taxonomy-term-3 h2 a', 'Mot clé N°3');
$this
->assertElementContains('.test-render div.render-entity-taxonomy-term-3-link h2 a', 'Mot clé N°3');
$this
->assertElementContains('.test-render div.render-entity-taxonomy-term-4 h2 a', 'Mot clé N°4');
$this
->assertElementContains('.test-render div.render-entity-taxonomy-term-4-link h2 a', 'Mot clé N°4');
$this
->assertElementContains('.test-render div.render-entity-taxonomy-term-5 h2 a', 'Mot clé N°5');
$this
->assertElementContains('.test-render div.render-entity-taxonomy-term-5-link h2 a', 'Mot clé N°5');
$this
->drupalGet('/de/bamboo-twig-render');
$this
->assertElementContains('.test-render div.render-entity-node-1 h2 a', 'News N°1');
$this
->assertElementContains('.test-render div.render-entity-node-1', 'Mot clé N°4');
$this
->assertElementContains('.test-render div.render-entity-node-1-teaser h2 a', 'News N°1');
$this
->assertElementContains('.test-render div.render-entity-node-2 h2 a', 'News N°2');
$this
->assertElementContains('.test-render div.render-entity-node-2', 'Tag N°2');
$this
->assertElementContains('.test-render div.render-entity-node-2-teaser h2 a', 'News N°2');
$this
->assertElementContains('.test-render div.render-entity-node-3 h2 a', 'Artikel N°3');
$this
->assertElementContains('.test-render div.render-entity-node-3', 'Stichworte N°3');
$this
->assertElementContains('.test-render div.render-entity-node-3-teaser h2 a', 'Artikel N°3');
$this
->assertElementContains('.test-render div.render-entity-node-4 h2 a', 'Article N°4');
$this
->assertElementContains('.test-render div.render-entity-node-4', 'Tag N°1');
$this
->assertElementContains('.test-render div.render-entity-node-4-teaser h2 a', 'Article N°4');
$this
->assertElementContains('.test-render div.render-entity-node-5 h2 a', 'News N°5');
$this
->assertElementContains('.test-render div.render-entity-node-5', 'Tag N°5');
$this
->assertElementContains('.test-render div.render-entity-node-5-teaser h2 a', 'News N°5');
$this
->assertElementContains('.test-render div.render-entity-taxonomy-term-1 h2 a', 'Tag N°1');
$this
->assertElementContains('.test-render div.render-entity-taxonomy-term-1-link h2 a', 'Tag N°1');
$this
->assertElementContains('.test-render div.render-entity-taxonomy-term-2 h2 a', 'Tag N°2');
$this
->assertElementContains('.test-render div.render-entity-taxonomy-term-2-link h2 a', 'Tag N°2');
$this
->assertElementContains('.test-render div.render-entity-taxonomy-term-3 h2 a', 'Stichworte N°3');
$this
->assertElementContains('.test-render div.render-entity-taxonomy-term-3-link h2 a', 'Stichworte N°3');
$this
->assertElementContains('.test-render div.render-entity-taxonomy-term-4 h2 a', 'Mot clé N°4');
$this
->assertElementContains('.test-render div.render-entity-taxonomy-term-4-link h2 a', 'Mot clé N°4');
$this
->assertElementContains('.test-render div.render-entity-taxonomy-term-5 h2 a', 'Tag N°5');
$this
->assertElementContains('.test-render div.render-entity-taxonomy-term-5-link h2 a', 'Tag N°5');
}
public function testImage() {
$this
->drupalGet('/bamboo-twig-render');
$this
->assertElementPresent('.test-render div.render-image');
$this
->assertElementPresent('.test-render div.render-image img');
}
public function testImageStyle() {
$this
->drupalGet('/bamboo-twig-render');
$this
->assertElementPresent('.test-render div.render-image-style-uri');
$this
->assertElementContains('.test-render div.render-image-style-uri', 'files/styles/thumbnail/public/antistatique.jpg');
$this
->assertElementPresent('.test-render div.render-image-style-uri-preprocess');
$this
->assertElementContains('.test-render div.render-image-style-uri-preprocess', 'files/styles/thumbnail/public/antistatique.jpg');
}
public function testField() {
$this
->drupalGet('/bamboo-twig-render');
$this
->assertElementContains('.test-render div.render-field-title-node-1', '<span>News N°1</span>');
$this
->assertElementContains('.test-render div.render-field-title-node-2', '<span>News N°2</span>');
$this
->assertElementContains('.test-render div.render-field-title-node-3', '<span>News N°3</span>');
$this
->assertElementContains('.test-render div.render-field-title-node-4', '<span>Article N°4</span>');
$this
->assertElementContains('.test-render div.render-field-title-node-5', '<span>Article N°5</span>');
$this
->assertElementContains('.test-render div.render-field-taxonomy-term-1', '<div>Tag N°1</div>');
$this
->assertElementContains('.test-render div.render-field-taxonomy-term-2', '<div>Tag N°2</div>');
$this
->assertElementContains('.test-render div.render-field-taxonomy-term-3', '<div>Tag N°3</div>');
$this
->assertElementContains('.test-render div.render-field-taxonomy-term-4', '<div>Mot clé N°4</div>');
$this
->assertElementContains('.test-render div.render-field-taxonomy-term-5', '<div>Mot clé N°5</div>');
$this
->assertElementContains('.test-render div.render-field-reference-node-1', 'Mot clé N°4');
$this
->assertElementContains('.test-render div.render-field-reference-node-2', 'Tag N°2');
$this
->assertElementContains('.test-render div.render-field-reference-node-3', 'Tag N°3');
$this
->assertElementContains('.test-render div.render-field-reference-node-4', 'Tag N°1');
$this
->assertElementContains('.test-render div.render-field-reference-node-5', 'Tag N°5');
$this
->assertElementContains('.test-render div.render-field-file', $this->file->filename->value);
$this
->assertElementContains('.test-render div.render-field-user', 'admin');
$this
->drupalGet('/fr/bamboo-twig-render');
$this
->assertElementContains('.test-render div.render-field-title-node-1', '<span>News N°1</span>');
$this
->assertElementContains('.test-render div.render-field-title-node-2', '<span>News N°2</span>');
$this
->assertElementContains('.test-render div.render-field-title-node-3', '<span>News N°3</span>');
$this
->assertElementContains('.test-render div.render-field-title-node-4', '<span>Article N°4</span>');
$this
->assertElementContains('.test-render div.render-field-title-node-5', '<span>Article N°5</span>');
$this
->assertElementContains('.test-render div.render-field-taxonomy-term-1', '<div>Tag N°1</div>');
$this
->assertElementContains('.test-render div.render-field-taxonomy-term-2', '<div>Tag N°2</div>');
$this
->assertElementContains('.test-render div.render-field-taxonomy-term-3', '<div>Tag N°3</div>');
$this
->assertElementContains('.test-render div.render-field-taxonomy-term-4', '<div>Mot clé N°4</div>');
$this
->assertElementContains('.test-render div.render-field-taxonomy-term-5', '<div>Mot clé N°5</div>');
$this
->assertElementContains('.test-render div.render-field-reference-node-1', 'Mot clé N°4');
$this
->assertElementContains('.test-render div.render-field-reference-node-2', 'Mot clé N°2');
$this
->assertElementContains('.test-render div.render-field-reference-node-3', 'Mot clé N°3');
$this
->assertElementContains('.test-render div.render-field-reference-node-4', 'Tag N°1');
$this
->assertElementContains('.test-render div.render-field-reference-node-5', 'Mot clé N°5');
$this
->drupalGet('/de/bamboo-twig-render');
$this
->assertElementContains('.test-render div.render-field-title-node-1', '<span>News N°1</span>');
$this
->assertElementContains('.test-render div.render-field-title-node-2', '<span>News N°2</span>');
$this
->assertElementContains('.test-render div.render-field-title-node-3', '<span>News N°3</span>');
$this
->assertElementContains('.test-render div.render-field-title-node-4', '<span>Article N°4</span>');
$this
->assertElementContains('.test-render div.render-field-title-node-5', '<span>Article N°5</span>');
$this
->assertElementContains('.test-render div.render-field-taxonomy-term-1', '<div>Tag N°1</div>');
$this
->assertElementContains('.test-render div.render-field-taxonomy-term-2', '<div>Tag N°2</div>');
$this
->assertElementContains('.test-render div.render-field-taxonomy-term-3', '<div>Tag N°3</div>');
$this
->assertElementContains('.test-render div.render-field-taxonomy-term-4', '<div>Mot clé N°4</div>');
$this
->assertElementContains('.test-render div.render-field-taxonomy-term-5', '<div>Mot clé N°5</div>');
$this
->assertElementContains('.test-render div.render-field-reference-node-1', 'Mot clé N°4');
$this
->assertElementContains('.test-render div.render-field-reference-node-2', 'Tag N°2');
$this
->assertElementContains('.test-render div.render-field-reference-node-3', 'Stichworte N°3');
$this
->assertElementContains('.test-render div.render-field-reference-node-4', 'Tag N°1');
$this
->assertElementContains('.test-render div.render-field-reference-node-5', 'Tag N°5');
}
public function testMenu() {
$this
->drupalGet('/bamboo-twig-render');
$this
->assertElementPresent('.test-render div.render-menu-no-access');
$this
->assertElementNotPresent('.test-render div.render-menu-no-access ul');
$this
->drupalLogin($this->admin_user);
$this
->drupalGet('/bamboo-twig-render');
$this
->assertElementPresent('.test-render div.render-menu-all');
$this
->assertElementCount('ul', 9, '.test-render div.render-menu-all');
$this
->assertElementCount('li', 25, '.test-render div.render-menu-all');
$this
->assertElementPresent('.test-render div.render-menu-level');
$this
->assertElementCount('ul', 8, '.test-render div.render-menu-level');
$this
->assertElementCount('li', 24, '.test-render div.render-menu-level');
$this
->assertElementPresent('.test-render div.render-menu-depth');
$this
->assertElementCount('ul', 2, '.test-render div.render-menu-depth');
$this
->assertElementCount('li', 3, '.test-render div.render-menu-depth');
}
public function testForm() {
$this
->drupalGet('/bamboo-twig-render');
$this
->assertElementPresent('.test-render div.render-form');
$this
->assertElementPresent('.test-render div.render-form form.system-cron-settings');
}
public function testViews() {
$this
->drupalGet('/bamboo-twig-render');
$this
->assertElementPresent('.test-render div.render-views');
$this
->assertElementPresent('.test-render div.render-views .views-element-container');
}
protected function createFile() {
$fileStorage = $this->container
->get('entity_type.manager')
->getStorage('file');
file_unmanaged_copy(drupal_get_path('module', 'bamboo_twig_test') . '/files/antistatique.jpg', PublicStream::basePath());
$file = $fileStorage
->create([
'uri' => 'public://antistatique.jpg',
'status' => FILE_STATUS_PERMANENT,
]);
$file
->save();
return $file;
}
}