MigrationStorageTest.php in Zircon Profile 8.0
File
core/modules/migrate/tests/src/Unit/MigrationStorageTest.php
View source
<?php
namespace Drupal\Tests\migrate\Unit;
use Drupal\Component\Uuid\UuidInterface;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Entity\Query\QueryFactoryInterface;
use Drupal\Core\Entity\Query\QueryInterface;
use Drupal\Core\Language\LanguageManagerInterface;
use Drupal\migrate\MigrationStorage;
use Drupal\Tests\UnitTestCase;
class MigrationStorageTest extends UnitTestCase {
protected $storage;
protected $query;
public function setUp() {
$this->query = $this
->getMock(QueryInterface::class);
$this->query
->method('condition')
->willReturnSelf();
$query_factory = $this
->getMock(QueryFactoryInterface::class);
$query_factory
->method('get')
->willReturn($this->query);
$this->storage = new TestMigrationStorage($this
->getMock(EntityTypeInterface::class), $this
->getMock(ConfigFactoryInterface::class), $this
->getMock(UuidInterface::class), $this
->getMock(LanguageManagerInterface::class), $query_factory);
}
public function testGetVariantIdsWithVariants() {
$this->query
->method('execute')
->willReturn([
'd6_node__page',
'd6_node__article',
]);
$ids = $this->storage
->getVariantIds([
'd6_node:*',
'd6_user',
]);
$this
->assertSame([
'd6_node__page',
'd6_node__article',
'd6_user',
], $ids);
}
public function testGetVariantIdsNoVariants() {
$this->query
->method('execute')
->willReturn([]);
$ids = $this->storage
->getVariantIds([
'd6_node:*',
'd6_user',
]);
$this
->assertSame([
'd6_user',
], $ids);
}
public function testGetVariantIdsNoVariantsOrStaticDependencies() {
$this->query
->method('execute')
->willReturn([]);
$ids = $this->storage
->getVariantIds([
'd6_node:*',
'd6_node_revision:*',
]);
$this
->assertSame([], $ids);
}
}
class TestMigrationStorage extends MigrationStorage {
public function getVariantIds(array $ids) {
return parent::getVariantIds($ids);
}
}