DirectoryTest.php in XML sitemap 2.x
File
tests/src/Kernel/DirectoryTest.php
View source
<?php
namespace Drupal\Tests\xmlsitemap\Kernel;
class DirectoryTest extends KernelTestBase {
public function testClearDirectory() {
$fileSystem = $this->container
->get('file_system');
$directory = 'public://not-xmlsitemap';
$fileSystem
->prepareDirectory($directory, $fileSystem::CREATE_DIRECTORY | $fileSystem::MODIFY_PERMISSIONS);
$directory = 'public://xmlsitemap/test';
$fileSystem
->prepareDirectory($directory, $fileSystem::CREATE_DIRECTORY | $fileSystem::MODIFY_PERMISSIONS);
$fileSystem
->saveData('File unrelated to XML sitemap', 'public://not-xmlsitemap/file.txt');
$fileSystem
->saveData('File unrelated to XML sitemap', 'public://file.txt');
$fileSystem
->saveData('Test contents', 'public://xmlsitemap/test/index.xml');
$result = xmlsitemap_clear_directory(NULL, TRUE);
$this
->assertDirectoryNotExists('public://xmlsitemap/test');
$this
->assertDirectoryExists('public://not-xmlsitemap');
$this
->assertFileExists('public://file.txt');
$this
->assertTrue($result);
}
}