You are here

public function StaticGeneratorTest::testComplexHtml in Tome 8

@covers \Drupal\tome_static\StaticGenerator::requestPath @covers \Drupal\tome_static\StaticGenerator::getCssAssets @covers \Drupal\tome_static\StaticGenerator::getHtmlAssets @covers \Drupal\tome_static\StaticGenerator::exportPaths

File

modules/tome_static/tests/src/Kernel/StaticGeneratorTest.php, line 207

Class

StaticGeneratorTest
Tests that static site generation works.

Namespace

Drupal\Tests\tome_static\Kernel

Code

public function testComplexHtml() {
  $this
    ->enableModules([
    'tome_test',
  ]);

  /** @var \Drupal\tome_static\StaticGenerator $static */
  $static = \Drupal::service('tome_static.generator');
  $invoke_paths = $static
    ->requestPath('/tome-test/complex-page');
  $module_path = drupal_get_path('module', 'tome_test');
  $base_dir = Settings::get('tome_static_directory');
  $this
    ->assertContains("/{$module_path}/assets/srcset-test1.png", $invoke_paths);
  $this
    ->assertContains("/{$module_path}/assets/srcset-test2.png", $invoke_paths);
  $this
    ->assertContains("/{$module_path}/assets/srcset-test3.png", $invoke_paths);
  $this
    ->assertContains("/{$module_path}/assets/poster-test.png", $invoke_paths);
  $this
    ->assertContains('/random/path', $invoke_paths);
  $this
    ->assertContains('/absolute/path', $invoke_paths);
  $this
    ->assertNotContains('http://www.google.com/external/path', $invoke_paths);
  $this
    ->assertContains('/path/with/destination?bar=baz', $invoke_paths);
  $this
    ->assertContains('/random/iframe', $invoke_paths);
  $this
    ->assertContains("/{$module_path}/js/complex.js?v=1", $invoke_paths);
  $this
    ->assertContains('/use.svg', $invoke_paths);
  $this
    ->assertContains('/twitter_image.png', $invoke_paths);
  $this
    ->assertContains('/og_image.png', $invoke_paths);
  $this
    ->assertNotContains('data:image/jpeg;base64,x', $invoke_paths);
  $static
    ->exportPaths($invoke_paths);
  $this
    ->assertStringContainsString('Hello, complex world', file_get_contents("{$base_dir}/tome-test/complex-page/index.html"));
  $this
    ->assertFileExists("{$base_dir}/{$module_path}/css/complex.css");
  $this
    ->assertFileExists("{$base_dir}/{$module_path}/js/complex.js");
  $this
    ->assertFileExists("{$base_dir}/{$module_path}/assets/druplicon-1.png");
  $this
    ->assertFileExists("{$base_dir}/{$module_path}/assets/file with space.png");
  $this
    ->assertFileExists("{$base_dir}/core/misc/druplicon.png");
}