View source
<?php
namespace Drupal\Tests\bamboo_twig\Functional;
use Drupal\taxonomy\Tests\TaxonomyTestTrait;
use Drupal\Core\StreamWrapper\PublicStream;
class BambooTwigLoaderTest extends BambooTwigTestBase {
use TaxonomyTestTrait;
public static $modules = [
'bamboo_twig',
'bamboo_twig_loader',
'bamboo_twig_test',
'node',
'user',
'taxonomy',
'file',
];
public function setUp() {
parent::setUp();
$this
->drupalCreateContentType([
'type' => 'article',
'name' => 'Article',
]);
$this->article = $this
->drupalCreateNode([
'title' => 'Hello, world!',
'type' => 'article',
]);
$this->article
->save();
$this->admin_user = $this
->drupalCreateUser();
$this->vocabulary = $this
->createVocabulary();
$this->term = $this
->createTerm($this->vocabulary);
$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
->assertElementPresent('.test-loaders div.loader-entity-node');
$this
->assertElementContains('.test-loaders div.loader-entity-node', $this->article
->getTitle());
$this
->assertElementPresent('.test-loaders div.loader-entity-taxonomy-term');
$this
->assertElementContains('.test-loaders div.loader-entity-taxonomy-term', $this->term
->getName());
$this
->assertElementPresent('.test-loaders div.loader-entity-file');
$this
->assertElementContains('.test-loaders div.loader-entity-file', $this->file->filename->value);
$this
->assertElementPresent('.test-loaders div.loader-entity-user');
$this
->assertElementContains('.test-loaders div.loader-entity-user', 'admin');
}
public function testField() {
$this
->drupalGet('/bamboo-twig-loader');
$this
->assertElementPresent('.test-loaders div.loader-field-node');
$this
->assertElementContains('.test-loaders div.loader-field-node', $this->article
->getTitle());
$this
->assertElementPresent('.test-loaders div.loader-field-taxonomy-term');
$this
->assertElementContains('.test-loaders div.loader-field-taxonomy-term', $this->term
->getName());
$this
->assertElementPresent('.test-loaders div.loader-field-file');
$this
->assertElementContains('.test-loaders div.loader-field-file', $this->file->filename->value);
$this
->assertElementPresent('.test-loaders div.loader-field-user');
$this
->assertElementContains('.test-loaders div.loader-field-user', 'admin');
}
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', drupal_get_path('module', 'bamboo_twig_test') . '/files/antistatique.png');
}
protected function createFile() {
$fileStorage = $this->container
->get('entity_type.manager')
->getStorage('file');
file_unmanaged_copy(drupal_get_path('module', 'bamboo_twig_test') . '/files/antistatique.png', PublicStream::basePath());
$file = $fileStorage
->create([
'uri' => 'public://antistatique.png',
'status' => FILE_STATUS_PERMANENT,
]);
$file
->save();
return $file;
}
}