View source
<?php
namespace Drupal\Tests\bamboo_twig\Functional;
use Drupal\Tests\taxonomy\Functional\TaxonomyTestTrait;
use Drupal\Core\StreamWrapper\PublicStream;
class BambooTwigLoaderTest extends BambooTwigTestBase {
use TaxonomyTestTrait;
public static $modules = [
'locale',
'language',
'node',
'user',
'taxonomy',
'file',
'bamboo_twig',
'bamboo_twig_loader',
'bamboo_twig_test',
];
protected $articles;
protected $tags;
public function setUp() {
parent::setUp();
$this
->setUpLanguages();
$this
->setUpTags();
$this
->setUpArticles();
$this->admin_user = $this
->drupalCreateUser();
$this->file = $this
->createFile();
$this->container
->get('router.builder')
->rebuild();
}
public function testCurrentUser() {
$this
->drupalGet('/bamboo-twig-loader');
$this
->assertElementPresent('.test-loaders div.loader-current-user');
$this
->assertElementContains('.test-loaders div.loader-current-user', '');
$this
->drupalLogin($this->admin_user);
$this
->drupalGet('/bamboo-twig-loader');
$this
->assertElementPresent('.test-loaders div.loader-current-user');
$this
->assertElementContains('.test-loaders div.loader-current-user', $this->admin_user
->getUsername());
}
public function testEntity() {
$this
->drupalGet('/bamboo-twig-loader');
$this
->assertElementContains('.test-loaders div.loader-entity-node-1', 'News N°1');
$this
->assertElementContains('.test-loaders div.loader-entity-node-2', 'News N°2');
$this
->assertElementContains('.test-loaders div.loader-entity-node-3', 'News N°3');
$this
->assertElementContains('.test-loaders div.loader-entity-node-4', 'Article N°4');
$this
->assertElementContains('.test-loaders div.loader-entity-node-5', 'News N°5');
$this
->assertElementContains('.test-loaders div.loader-entity-taxonomy-term-1', 'Tag N°1');
$this
->assertElementContains('.test-loaders div.loader-entity-taxonomy-term-2', 'Tag N°2');
$this
->assertElementContains('.test-loaders div.loader-entity-taxonomy-term-3', 'Tag N°3');
$this
->assertElementContains('.test-loaders div.loader-entity-taxonomy-term-4', 'Mot clé N°4');
$this
->assertElementContains('.test-loaders div.loader-entity-taxonomy-term-5', 'Tag N°5');
$this
->assertElementContains('.test-loaders div.loader-entity-reference-field-1', 'Mot clé N°4');
$this
->assertElementContains('.test-loaders div.loader-entity-reference-field-2', 'Tag N°2');
$this
->assertElementContains('.test-loaders div.loader-entity-reference-field-3', 'Tag N°3');
$this
->assertElementContains('.test-loaders div.loader-entity-reference-field-4', 'Tag N°1');
$this
->assertElementContains('.test-loaders div.loader-entity-reference-field-5', 'Mot clé N°5');
$this
->assertElementPresent('.test-loaders div.loader-entity-file');
$this
->assertElementContains('.test-loaders div.loader-entity-file', 'antistatique.jpg');
$this
->assertElementPresent('.test-loaders div.loader-entity-user');
$this
->assertElementContains('.test-loaders div.loader-entity-user', 'admin');
$this
->drupalGet('/fr/bamboo-twig-loader');
$this
->assertElementContains('.test-loaders div.loader-entity-node-1', 'News N°1');
$this
->assertElementContains('.test-loaders div.loader-entity-node-2', 'Article N°2');
$this
->assertElementContains('.test-loaders div.loader-entity-node-3', 'Article N°3');
$this
->assertElementContains('.test-loaders div.loader-entity-node-4', 'Article N°4');
$this
->assertElementContains('.test-loaders div.loader-entity-node-5', 'Article N°5');
$this
->assertElementContains('.test-loaders div.loader-entity-taxonomy-term-1', 'Tag N°1');
$this
->assertElementContains('.test-loaders div.loader-entity-taxonomy-term-2', 'Mot clé N°2');
$this
->assertElementContains('.test-loaders div.loader-entity-taxonomy-term-3', 'Mot clé N°3');
$this
->assertElementContains('.test-loaders div.loader-entity-taxonomy-term-4', 'Mot clé N°4');
$this
->assertElementContains('.test-loaders div.loader-entity-taxonomy-term-5', 'Mot clé N°5');
$this
->assertElementContains('.test-loaders div.loader-entity-reference-field-1', 'Mot clé N°4');
$this
->assertElementContains('.test-loaders div.loader-entity-reference-field-2', 'Tag N°2');
$this
->assertElementContains('.test-loaders div.loader-entity-reference-field-3', 'Tag N°3');
$this
->assertElementContains('.test-loaders div.loader-entity-reference-field-4', 'Tag N°1');
$this
->assertElementContains('.test-loaders div.loader-entity-reference-field-5', 'Mot clé N°5');
$this
->drupalGet('/de/bamboo-twig-loader');
$this
->assertElementContains('.test-loaders div.loader-entity-node-1', 'News N°1');
$this
->assertElementContains('.test-loaders div.loader-entity-node-2', 'News N°2');
$this
->assertElementContains('.test-loaders div.loader-entity-node-3', 'Artikel N°3');
$this
->assertElementContains('.test-loaders div.loader-entity-node-4', 'Article N°4');
$this
->assertElementContains('.test-loaders div.loader-entity-node-5', 'News N°5');
$this
->assertElementContains('.test-loaders div.loader-entity-taxonomy-term-1', 'Tag N°1');
$this
->assertElementContains('.test-loaders div.loader-entity-taxonomy-term-2', 'Tag N°2');
$this
->assertElementContains('.test-loaders div.loader-entity-taxonomy-term-3', 'Stichworte N°3');
$this
->assertElementContains('.test-loaders div.loader-entity-taxonomy-term-4', 'Mot clé N°4');
$this
->assertElementContains('.test-loaders div.loader-entity-taxonomy-term-5', 'Tag N°5');
$this
->assertElementContains('.test-loaders div.loader-entity-reference-field-1', 'Mot clé N°4');
$this
->assertElementContains('.test-loaders div.loader-entity-reference-field-2', 'Tag N°2');
$this
->assertElementContains('.test-loaders div.loader-entity-reference-field-3', 'Tag N°3');
$this
->assertElementContains('.test-loaders div.loader-entity-reference-field-4', 'Tag N°1');
$this
->assertElementContains('.test-loaders div.loader-entity-reference-field-5', 'Mot clé N°5');
}
public function testField() {
$this
->drupalGet('/bamboo-twig-loader');
$this
->assertElementContains('.test-loaders div.loader-field-node-1', 'News N°1');
$this
->assertElementContains('.test-loaders div.loader-field-node-2', 'News N°2');
$this
->assertElementContains('.test-loaders div.loader-field-node-3', 'News N°3');
$this
->assertElementContains('.test-loaders div.loader-field-node-4', 'Article N°4');
$this
->assertElementContains('.test-loaders div.loader-field-node-5', 'News N°5');
$this
->assertElementContains('.test-loaders div.loader-field-taxonomy-term-1', 'Tag N°1');
$this
->assertElementContains('.test-loaders div.loader-field-taxonomy-term-2', 'Tag N°2');
$this
->assertElementContains('.test-loaders div.loader-field-taxonomy-term-3', 'Tag N°3');
$this
->assertElementContains('.test-loaders div.loader-field-taxonomy-term-4', 'Mot clé N°4');
$this
->assertElementContains('.test-loaders div.loader-field-taxonomy-term-5', 'Tag N°5');
$this
->assertElementContains('.test-loaders div.loader-field-reference-1', 'Mot clé N°4');
$this
->assertElementContains('.test-loaders div.loader-field-reference-2', 'Tag N°2');
$this
->assertElementContains('.test-loaders div.loader-field-reference-3', 'Tag N°3');
$this
->assertElementContains('.test-loaders div.loader-field-reference-4', 'Tag N°1');
$this
->assertElementContains('.test-loaders div.loader-field-reference-5', 'Mot clé N°5');
$this
->assertElementContains('.test-loaders div.loader-field-file', $this->file->filename->value);
$this
->assertElementContains('.test-loaders div.loader-field-user', 'admin');
$this
->drupalGet('/fr/bamboo-twig-loader');
$this
->assertElementContains('.test-loaders div.loader-field-node-1', 'News N°1');
$this
->assertElementContains('.test-loaders div.loader-field-node-2', 'Article N°2');
$this
->assertElementContains('.test-loaders div.loader-field-node-3', 'Article N°3');
$this
->assertElementContains('.test-loaders div.loader-field-node-4', 'Article N°4');
$this
->assertElementContains('.test-loaders div.loader-field-node-5', 'Article N°5');
$this
->assertElementContains('.test-loaders div.loader-field-taxonomy-term-1', 'Tag N°1');
$this
->assertElementContains('.test-loaders div.loader-field-taxonomy-term-2', 'Mot clé N°2');
$this
->assertElementContains('.test-loaders div.loader-field-taxonomy-term-3', 'Mot clé N°3');
$this
->assertElementContains('.test-loaders div.loader-field-taxonomy-term-4', 'Mot clé N°4');
$this
->assertElementContains('.test-loaders div.loader-field-taxonomy-term-5', 'Mot clé N°5');
$this
->assertElementContains('.test-loaders div.loader-field-reference-1', 'Mot clé N°4');
$this
->assertElementContains('.test-loaders div.loader-field-reference-2', 'Tag N°2');
$this
->assertElementContains('.test-loaders div.loader-field-reference-3', 'Tag N°3');
$this
->assertElementContains('.test-loaders div.loader-field-reference-4', 'Tag N°1');
$this
->assertElementContains('.test-loaders div.loader-field-reference-5', 'Mot clé N°5');
$this
->drupalGet('/de/bamboo-twig-loader');
$this
->assertElementContains('.test-loaders div.loader-field-node-1', 'News N°1');
$this
->assertElementContains('.test-loaders div.loader-field-node-2', 'News N°2');
$this
->assertElementContains('.test-loaders div.loader-field-node-3', 'Artikel N°3');
$this
->assertElementContains('.test-loaders div.loader-field-node-4', 'Article N°4');
$this
->assertElementContains('.test-loaders div.loader-field-node-5', 'News N°5');
$this
->assertElementContains('.test-loaders div.loader-field-taxonomy-term-1', 'Tag N°1');
$this
->assertElementContains('.test-loaders div.loader-field-taxonomy-term-2', 'Tag N°2');
$this
->assertElementContains('.test-loaders div.loader-field-taxonomy-term-3', 'Stichworte N°3');
$this
->assertElementContains('.test-loaders div.loader-field-taxonomy-term-4', 'Mot clé N°4');
$this
->assertElementContains('.test-loaders div.loader-field-taxonomy-term-5', 'Tag N°5');
$this
->assertElementContains('.test-loaders div.loader-field-reference-1', 'Mot clé N°4');
$this
->assertElementContains('.test-loaders div.loader-field-reference-2', 'Tag N°2');
$this
->assertElementContains('.test-loaders div.loader-field-reference-3', 'Tag N°3');
$this
->assertElementContains('.test-loaders div.loader-field-reference-4', 'Tag N°1');
$this
->assertElementContains('.test-loaders div.loader-field-reference-5', 'Mot clé N°5');
}
public function testImage() {
$this
->drupalGet('/bamboo-twig-loader');
$this
->assertElementPresent('.test-loaders div.loader-image-uri');
$this
->assertElementContains('.test-loaders div.loader-image-uri', $this->file
->getFileUri());
$this
->assertElementPresent('.test-loaders div.loader-image-path');
$this
->assertElementContains('.test-loaders div.loader-image-path', 'bamboo_twig_test/files/antistatique.jpg');
}
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;
}
}