You are here

public function AssetInjectorCssTest::testCssInjector in Asset Injector 8.2

Test a created css injector is added to the page and the css file exists.

Throws

\Exception

File

tests/src/Functional/AssetInjectorCssTest.php, line 71

Class

AssetInjectorCssTest
Class AssetInjectorCssTest.

Namespace

Drupal\Tests\asset_injector\Functional

Code

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');

  /** @var \Drupal\asset_injector\Entity\AssetInjectorCss $asset */
  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);
  }
}