IndexStorageTest.php in Search API 8
File
tests/src/Kernel/Index/IndexStorageTest.php
View source
<?php
namespace Drupal\Tests\search_api\Kernel\Index;
use Drupal\Core\Config\Entity\ConfigEntityStorage;
use Drupal\search_api\IndexInterface;
use Drupal\KernelTests\KernelTestBase;
class IndexStorageTest extends KernelTestBase {
public static $modules = [
'search_api',
'user',
'system',
];
protected $storage;
protected function setUp() {
parent::setUp();
$this
->installSchema('system', 'key_value_expire');
$this
->installEntitySchema('search_api_task');
$this
->installConfig('search_api');
$this->storage = $this->container
->get('entity_type.manager')
->getStorage('search_api_index');
}
public function testIndexCrud() {
$this
->assertInstanceOf(ConfigEntityStorage::class, $this->storage, 'The Search API Index storage controller is loaded.');
$index = $this
->indexCreate();
$this
->indexLoad($index);
$this
->indexDelete($index);
}
protected function indexCreate() {
$index_data = [
'id' => 'test',
'name' => 'Index test name',
];
$index = $this->storage
->create($index_data);
$this
->assertInstanceOf(IndexInterface::class, $index, 'The newly created entity is a search index.');
$index
->save();
return $index;
}
protected function indexLoad(IndexInterface $index) {
$loaded_index = $this->storage
->load($index
->id());
$this
->assertSame($index
->label(), $loaded_index
->label());
}
protected function indexDelete(IndexInterface $index) {
$this->storage
->delete([
$index,
]);
$loaded_index = $this->storage
->load($index
->id());
$this
->assertNull($loaded_index);
}
}