class StorageComparerTest in Drupal 9
Same name and namespace in other branches
- 8 core/tests/Drupal/Tests/Core/Config/StorageComparerTest.php \Drupal\Tests\Core\Config\StorageComparerTest
@coversDefaultClass \Drupal\Core\Config\StorageComparer @group Config
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses \Symfony\Bridge\PhpUnit\ExpectDeprecationTrait, PhpUnitCompatibilityTrait, PhpUnitWarnings
- class \Drupal\Tests\Core\Config\StorageComparerTest
Expanded class hierarchy of StorageComparerTest
File
- core/
tests/ Drupal/ Tests/ Core/ Config/ StorageComparerTest.php, line 13
Namespace
Drupal\Tests\Core\ConfigView source
class StorageComparerTest extends UnitTestCase {
/**
* @var \Drupal\Core\Config\StorageInterface|\PHPUnit\Framework\MockObject\MockObject
*/
protected $sourceStorage;
/**
* @var \Drupal\Core\Config\StorageInterface|\PHPUnit\Framework\MockObject\MockObject
*/
protected $targetStorage;
/**
* The storage comparer to test.
*
* @var \Drupal\Core\Config\StorageComparer
*/
protected $storageComparer;
/**
* An array of test configuration data keyed by configuration name.
*
* @var array
*/
protected $configData;
protected function setUp() : void {
$this->sourceStorage = $this
->createMock('Drupal\\Core\\Config\\StorageInterface');
$this->targetStorage = $this
->createMock('Drupal\\Core\\Config\\StorageInterface');
$this->storageComparer = new StorageComparer($this->sourceStorage, $this->targetStorage);
}
protected function getConfigData() {
$uuid = new Php();
// Mock data using minimal data to use ConfigDependencyManger.
$this->configData = [
// Simple config that controls configuration sync.
'system.site' => [
'title' => 'Drupal',
'uuid' => $uuid
->generate(),
],
// Config entity which requires another config entity.
'field.field.node.article.body' => [
'id' => 'node.article.body',
'uuid' => $uuid
->generate(),
'dependencies' => [
'config' => [
'field.storage.node.body',
],
],
],
// Config entity which is required by another config entity.
'field.storage.node.body' => [
'id' => 'node.body',
'uuid' => $uuid
->generate(),
'dependencies' => [
'module' => [
'text',
],
],
],
// Config entity not which has no dependencies on configuration.
'views.view.test_view' => [
'id' => 'test_view',
'uuid' => $uuid
->generate(),
'dependencies' => [
'module' => [
'node',
],
],
],
// Simple config.
'system.performance' => [
'stale_file_threshold' => 2592000,
],
];
return $this->configData;
}
/**
* @covers ::createChangelist
*/
public function testCreateChangelistNoChange() {
$config_data = $this
->getConfigData();
$config_files = array_keys($config_data);
$this->sourceStorage
->expects($this
->once())
->method('listAll')
->will($this
->returnValue($config_files));
$this->targetStorage
->expects($this
->once())
->method('listAll')
->will($this
->returnValue($config_files));
$this->sourceStorage
->expects($this
->once())
->method('readMultiple')
->will($this
->returnValue($config_data));
$this->targetStorage
->expects($this
->once())
->method('readMultiple')
->will($this
->returnValue($config_data));
$this->sourceStorage
->expects($this
->once())
->method('getAllCollectionNames')
->will($this
->returnValue([]));
$this->targetStorage
->expects($this
->once())
->method('getAllCollectionNames')
->will($this
->returnValue([]));
$this->storageComparer
->createChangelist();
$this
->assertEmpty($this->storageComparer
->getChangelist('create'));
$this
->assertEmpty($this->storageComparer
->getChangelist('delete'));
$this
->assertEmpty($this->storageComparer
->getChangelist('update'));
}
/**
* @covers ::createChangelist
*/
public function testCreateChangelistCreate() {
$target_data = $source_data = $this
->getConfigData();
unset($target_data['field.storage.node.body']);
unset($target_data['field.field.node.article.body']);
unset($target_data['views.view.test_view']);
$this->sourceStorage
->expects($this
->once())
->method('listAll')
->will($this
->returnValue(array_keys($source_data)));
$this->targetStorage
->expects($this
->once())
->method('listAll')
->will($this
->returnValue(array_keys($target_data)));
$this->sourceStorage
->expects($this
->once())
->method('readMultiple')
->will($this
->returnValue($source_data));
$this->targetStorage
->expects($this
->once())
->method('readMultiple')
->will($this
->returnValue($target_data));
$this->sourceStorage
->expects($this
->once())
->method('getAllCollectionNames')
->will($this
->returnValue([]));
$this->targetStorage
->expects($this
->once())
->method('getAllCollectionNames')
->will($this
->returnValue([]));
$this->storageComparer
->createChangelist();
$expected = [
'field.storage.node.body',
'field.field.node.article.body',
'views.view.test_view',
];
$this
->assertEquals($expected, $this->storageComparer
->getChangelist('create'));
$this
->assertEmpty($this->storageComparer
->getChangelist('delete'));
$this
->assertEmpty($this->storageComparer
->getChangelist('update'));
}
/**
* @covers ::createChangelist
*/
public function testCreateChangelistDelete() {
$target_data = $source_data = $this
->getConfigData();
unset($source_data['field.storage.node.body']);
unset($source_data['field.field.node.article.body']);
unset($source_data['views.view.test_view']);
$this->sourceStorage
->expects($this
->once())
->method('listAll')
->will($this
->returnValue(array_keys($source_data)));
$this->targetStorage
->expects($this
->once())
->method('listAll')
->will($this
->returnValue(array_keys($target_data)));
$this->sourceStorage
->expects($this
->once())
->method('readMultiple')
->will($this
->returnValue($source_data));
$this->targetStorage
->expects($this
->once())
->method('readMultiple')
->will($this
->returnValue($target_data));
$this->sourceStorage
->expects($this
->once())
->method('getAllCollectionNames')
->will($this
->returnValue([]));
$this->targetStorage
->expects($this
->once())
->method('getAllCollectionNames')
->will($this
->returnValue([]));
$this->storageComparer
->createChangelist();
$expected = [
'views.view.test_view',
'field.field.node.article.body',
'field.storage.node.body',
];
$this
->assertEquals($expected, $this->storageComparer
->getChangelist('delete'));
$this
->assertEmpty($this->storageComparer
->getChangelist('create'));
$this
->assertEmpty($this->storageComparer
->getChangelist('update'));
}
/**
* @covers ::createChangelist
*/
public function testCreateChangelistUpdate() {
$target_data = $source_data = $this
->getConfigData();
$source_data['system.site']['title'] = 'Drupal New!';
$source_data['field.field.node.article.body']['new_config_key'] = 'new data';
$source_data['field.storage.node.body']['new_config_key'] = 'new data';
$this->sourceStorage
->expects($this
->once())
->method('listAll')
->will($this
->returnValue(array_keys($source_data)));
$this->targetStorage
->expects($this
->once())
->method('listAll')
->will($this
->returnValue(array_keys($target_data)));
$this->sourceStorage
->expects($this
->once())
->method('readMultiple')
->will($this
->returnValue($source_data));
$this->targetStorage
->expects($this
->once())
->method('readMultiple')
->will($this
->returnValue($target_data));
$this->sourceStorage
->expects($this
->once())
->method('getAllCollectionNames')
->will($this
->returnValue([]));
$this->targetStorage
->expects($this
->once())
->method('getAllCollectionNames')
->will($this
->returnValue([]));
$this->storageComparer
->createChangelist();
$expected = [
'field.storage.node.body',
'field.field.node.article.body',
'system.site',
];
$this
->assertEquals($expected, $this->storageComparer
->getChangelist('update'));
$this
->assertEmpty($this->storageComparer
->getChangelist('create'));
$this
->assertEmpty($this->storageComparer
->getChangelist('delete'));
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
PhpUnitWarnings:: |
private static | property | Deprecation warnings from PHPUnit to raise with @trigger_error(). | |
PhpUnitWarnings:: |
public | function | Converts PHPUnit deprecation warnings to E_USER_DEPRECATED. | |
StorageComparerTest:: |
protected | property | An array of test configuration data keyed by configuration name. | |
StorageComparerTest:: |
protected | property | ||
StorageComparerTest:: |
protected | property | The storage comparer to test. | |
StorageComparerTest:: |
protected | property | ||
StorageComparerTest:: |
protected | function | ||
StorageComparerTest:: |
protected | function |
Overrides UnitTestCase:: |
|
StorageComparerTest:: |
public | function | @covers ::createChangelist | |
StorageComparerTest:: |
public | function | @covers ::createChangelist | |
StorageComparerTest:: |
public | function | @covers ::createChangelist | |
StorageComparerTest:: |
public | function | @covers ::createChangelist | |
UnitTestCase:: |
protected | property | The random generator. | |
UnitTestCase:: |
protected | property | The app root. | 1 |
UnitTestCase:: |
protected | function | Asserts if two arrays are equal by sorting them first. | |
UnitTestCase:: |
protected | function | Returns a stub class resolver. | |
UnitTestCase:: |
public | function | Returns a stub config factory that behaves according to the passed array. | |
UnitTestCase:: |
public | function | Returns a stub config storage that returns the supplied configuration. | |
UnitTestCase:: |
protected | function | Sets up a container with a cache tags invalidator. | |
UnitTestCase:: |
protected | function | Gets the random generator for the utility methods. | |
UnitTestCase:: |
public | function | Returns a stub translation manager that just returns the passed string. | |
UnitTestCase:: |
public | function | Generates a unique random string containing letters and numbers. | |
UnitTestCase:: |
public static | function |