AssetInjectorCssTest.php in Asset Injector 8.2
File
tests/src/Functional/AssetInjectorCssTest.php
View source
<?php
namespace Drupal\Tests\asset_injector\Functional;
use Drupal\Tests\BrowserTestBase;
use Drupal\Core\StringTranslation\StringTranslationTrait;
class AssetInjectorCssTest extends BrowserTestBase {
use StringTranslationTrait;
protected $defaultTheme = 'stark';
protected static $modules = [
'asset_injector',
'toolbar',
'block',
];
public function setUp() {
parent::setUp();
$this
->drupalPlaceBlock('local_tasks_block');
$this
->drupalPlaceBlock('page_title_block');
$this
->drupalPlaceBlock('system_messages_block');
}
public function testCssPermissionDenied() {
$account = $this
->drupalCreateUser();
$this
->drupalLogin($account);
$this
->drupalGet('admin/config/development/asset-injector/css');
$this
->assertSession()
->statusCodeEquals(403);
}
public function testCssPermissionGranted() {
$account = $this
->drupalCreateUser([
'administer css assets injector',
]);
$this
->drupalLogin($account);
$this
->drupalGet('admin/config/development/asset-injector/css');
$this
->assertSession()
->statusCodeEquals(200);
}
public function testCssInjector() {
$this
->testCssPermissionGranted();
$this
->drupalGet('admin/config/development/asset-injector/css/add');
$this
->assertSession()
->statusCodeEquals(200);
$this
->assertSession()
->pageTextContains($this
->t('Code'));
$this
->submitForm([
'label' => $this
->t('Blocks'),
'id' => $this
->t('blocks'),
'code' => '.block {border:1px solid black;}',
], $this
->t('Save'));
$this
->getSession()
->getPage()
->hasContent('asset_injector/css/blocks');
foreach (asset_injector_get_assets(NULL, [
'asset_injector_css',
]) as $asset) {
$path = parse_url(file_create_url($asset
->internalFileUri()), PHP_URL_PATH);
$path = str_replace(base_path(), '/', $path);
$this
->drupalGet($path);
$this
->assertSession()
->statusCodeEquals(200);
}
}
public function testSaveContinue() {
$page = $this
->getSession()
->getPage();
$this
->testCssPermissionGranted();
$this
->drupalGet('admin/config/development/asset-injector/css/add');
$this
->assertSession()
->statusCodeEquals(200);
$this
->assertSession()
->pageTextContains($this
->t('Code'));
$page
->fillField('Label', 'test save continue');
$page
->fillField('Machine-readable name', 'test_save_continue');
$page
->fillField('Code', '.block{}');
$page
->pressButton('Save and Continue Editing');
$this
->assertSession()
->pageTextContains('Created the test save continue Asset Injector');
$this
->assertSession()
->addressEquals('admin/config/development/asset-injector/css/test_save_continue');
}
}