public function TomeStaticGeneratorFormTest::testStaticGeneratorForm in Tome 8
Tests the static generator form.
File
- modules/
tome_static/ tests/ src/ Functional/ TomeStaticGeneratorFormTest.php, line 71
Class
- TomeStaticGeneratorFormTest
- Tests the functionality of the Tome Static form.
Namespace
Drupal\Tests\tome_static\FunctionalCode
public function testStaticGeneratorForm() {
/** @var \Drupal\tome_static\StaticGeneratorInterface $static */
$static = \Drupal::service('tome_static.generator');
$valid_images = [];
foreach ($this
->getTestFiles('image') as $image) {
$regex = '/\\.png$/i';
if (preg_match($regex, $image->filename)) {
$valid_images[] = $image;
}
}
$file = File::create([
'uri' => $valid_images[0]->uri,
'status' => FILE_STATUS_PERMANENT,
]);
$file
->save();
$image_factory = $this->container
->get('image.factory');
$image = $image_factory
->get($valid_images[0]->uri);
$node = $this
->drupalCreateNode([
'type' => 'article',
'title' => 'Test node',
'field_image' => [
'target_id' => $file
->id(),
'width' => $image
->getWidth(),
'height' => $image
->getHeight(),
],
]);
$filename = $static
->getStaticDirectory() . base_path() . 'node/' . $node
->id() . '/index.html';
$image_filename = $static
->getStaticDirectory() . file_url_transform_relative(file_create_url(ImageStyle::load('large')
->buildUri($file
->getFileUri())));
$this
->assertFileNotExists($filename);
$this
->assertFileNotExists($image_filename);
$this
->drupalGet('/admin/config/tome/static/generate');
$this
->submitForm([], 'Submit');
$this
->assertFileExists($filename);
$this
->assertFileExists($image_filename);
$this
->assertStringContainsString('Test node', file_get_contents($filename));
}