public function ExporterTest::testDeleteContentExport in Tome 8
@covers \Drupal\tome_sync\Exporter::deleteContentExport
File
- modules/
tome_sync/ tests/ src/ Kernel/ ExporterTest.php, line 93
Class
- ExporterTest
- Tests that the exporter works.
Namespace
Drupal\Tests\tome_sync\KernelCode
public function testDeleteContentExport() {
/** @var \Drupal\Core\Config\StorageInterface $storage */
$storage = \Drupal::service('tome_sync.storage.content');
$article = Node::create([
'type' => 'article',
'title' => 'My article',
]);
$article
->save();
$this
->assertTrue($storage
->exists(TomeSyncHelper::getContentName($article)));
$article_name = TomeSyncHelper::getContentName($article);
$index_file = Settings::get('tome_content_directory', '../content') . '/meta/index.json';
$this
->assertFileExists($index_file);
$index = json_decode(file_get_contents($index_file), TRUE);
$this
->assertArrayHasKey($article_name, $index);
$article
->addTranslation('fr', [
'title' => 'My french article',
])
->save();
$name = TomeSyncHelper::getContentName($article
->getTranslation('fr'));
$this
->assertTrue($storage
->exists($name));
$article
->removeTranslation('fr');
$article
->save();
$this
->assertFalse($storage
->exists($name));
$article
->addTranslation('fr', [
'title' => 'My french article',
])
->save();
$this
->assertTrue($storage
->exists($name));
$article
->delete();
$this
->assertFalse($storage
->exists(TomeSyncHelper::getContentName($article)));
$this
->assertFalse($storage
->exists($name));
$index = json_decode(file_get_contents($index_file), TRUE);
$this
->assertArrayNotHasKey($article_name, $index);
}