public function StaticGeneratorTest::testGetPaths in Tome 8
@covers \Drupal\tome_static\StaticGenerator::getPaths @covers \Drupal\tome_static\EventSubscriber\LanguagePathSubscriber::collectPaths @covers \Drupal\tome_static\EventSubscriber\EntityPathSubscriber::collectPaths @covers \Drupal\tome_static\EventSubscriber\EntityPathSubscriber::replacePathPlaceholder
File
- modules/
tome_static/ tests/ src/ Kernel/ StaticGeneratorTest.php, line 49
Class
- StaticGeneratorTest
- Tests that static site generation works.
Namespace
Drupal\Tests\tome_static\KernelCode
public function testGetPaths() {
/** @var \Drupal\tome_static\StaticGenerator $static */
$static = \Drupal::service('tome_static.generator');
$base_dir = Settings::get('tome_static_directory');
DateFormat::create([
'pattern' => 'D, m/d/Y - H:i',
'id' => 'medium',
])
->save();
$this
->assertUnsortedEquals([
'/',
'/french',
'_entity:user:en:0',
], $static
->getPaths());
$article = Node::create([
'type' => 'article',
'title' => 'My article',
]);
$article
->addTranslation('fr', [
'title' => 'My french article',
]);
$article
->save();
$this
->assertUnsortedEquals([
'/',
'_entity:node:en:1',
'_entity:node:fr:1',
'/french',
'_entity:user:en:0',
], $static
->getPaths());
$settings = Settings::getInstance() ? Settings::getAll() : [];
$settings['tome_static_path_exclude'] = [
'_entity:node:fr:1',
'/french',
];
new Settings($settings);
$this
->assertUnsortedEquals([
'/',
'_entity:node:en:1',
'_entity:user:en:0',
], $static
->getPaths());
$static
->requestPath('_entity:node:en:1');
$this
->assertFileExists("{$base_dir}/node/1/index.html");
$static
->requestPath('_entity:node:fr:1');
$this
->assertFileExists("{$base_dir}/french/node/1/index.html");
\Drupal::service('file_system')
->delete("{$base_dir}/node/1/index.html");
\Drupal::service('file_system')
->delete("{$base_dir}/french/node/1/index.html");
$article
->setUnpublished();
$article
->save();
\Drupal::entityTypeManager()
->getAccessControlHandler('node')
->resetCache();
$static
->requestPath('/');
$static
->requestPath('_entity:node:en:1');
$this
->assertFileNotExists("{$base_dir}/node/1/index.html");
$static
->requestPath('_entity:node:fr:1');
$this
->assertFileExists("{$base_dir}/french/node/1/index.html");
}