ServerImportTest.php in Search API 8
File
tests/src/Kernel/Server/ServerImportTest.php
View source
<?php
namespace Drupal\Tests\search_api\Kernel\Server;
use Drupal\Component\Uuid\Php;
use Drupal\KernelTests\KernelTestBase;
use Drupal\search_api\Entity\Server;
class ServerImportTest extends KernelTestBase {
protected $server;
public static $modules = [
'search_api',
'search_api_test',
'user',
'system',
];
public function setUp() {
parent::setUp();
$this
->installEntitySchema('user');
$this
->installSchema('search_api', [
'search_api_item',
]);
$this
->installSchema('system', [
'key_value_expire',
]);
$this
->installEntitySchema('search_api_task');
$this
->installConfig('search_api');
$this->server = Server::create([
'name' => 'Test Server',
'id' => 'test_server',
'status' => 1,
'backend' => 'search_api_test',
'backend_config' => [
'test' => 'foo',
],
]);
$this->server
->save();
$config_storage = $this->container
->get('config.storage');
$config_sync = $this->container
->get('config.storage.sync');
$config_storage
->write('system.site', [
'uuid' => (new Php())
->generate(),
]);
$this
->copyConfig($config_storage, $config_sync);
}
public function testServerImport() {
$name = $this->server
->getConfigDependencyName();
$original_data = $this->server
->toArray();
$custom_data = $original_data;
$custom_data['name'] = 'Old test server';
$custom_data['backend_config']['test'] = 'bar';
$this->container
->get('config.storage.sync')
->write($name, $custom_data);
$config = $this
->config($name);
$this
->assertSame($config
->get(), $original_data);
$this
->configImporter()
->import();
$this->container
->get('config.factory')
->reset($name);
$config = $this
->config($name);
$this
->assertSame($config
->get(), $custom_data);
}
}