You are here

class MigrationStorageTest in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/migrate/tests/src/Unit/MigrationStorageTest.php \Drupal\Tests\migrate\Unit\MigrationStorageTest

@coversDefaultClass \Drupal\migrate\MigrationStorage @group migrate

Hierarchy

Expanded class hierarchy of MigrationStorageTest

File

core/modules/migrate/tests/src/Unit/MigrationStorageTest.php, line 23
Contains \Drupal\Tests\migrate\Unit\MigrationStorageTest.

Namespace

Drupal\Tests\migrate\Unit
View source
class MigrationStorageTest extends UnitTestCase {

  /**
   * @var \Drupal\Tests\migrate\Unit\TestMigrationStorage
   */
  protected $storage;

  /**
   * @var \Drupal\Core\Entity\Query\QueryInterface|\PHPUnit_Framework_MockObject_MockObject
   */
  protected $query;

  /**
   * {@inheritdoc}
   */
  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);
  }

  /**
   * Tests getVariantIds() when variants exist.
   *
   * @covers ::getVariantIds
   */
  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);
  }

  /**
   * Tests getVariantIds() when no variants exist.
   *
   * @covers ::getVariantIds
   */
  public function testGetVariantIdsNoVariants() {
    $this->query
      ->method('execute')
      ->willReturn([]);
    $ids = $this->storage
      ->getVariantIds([
      'd6_node:*',
      'd6_user',
    ]);
    $this
      ->assertSame([
      'd6_user',
    ], $ids);
  }

  /**
   * Tests getVariantIds() when no variants exist and there are no static
   * (non-variant) dependencies.
   *
   * @covers ::getVariantIds
   */
  public function testGetVariantIdsNoVariantsOrStaticDependencies() {
    $this->query
      ->method('execute')
      ->willReturn([]);
    $ids = $this->storage
      ->getVariantIds([
      'd6_node:*',
      'd6_node_revision:*',
    ]);
    $this
      ->assertSame([], $ids);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
MigrationStorageTest::$query protected property
MigrationStorageTest::$storage protected property
MigrationStorageTest::setUp public function Overrides UnitTestCase::setUp
MigrationStorageTest::testGetVariantIdsNoVariants public function Tests getVariantIds() when no variants exist.
MigrationStorageTest::testGetVariantIdsNoVariantsOrStaticDependencies public function Tests getVariantIds() when no variants exist and there are no static (non-variant) dependencies.
MigrationStorageTest::testGetVariantIdsWithVariants public function Tests getVariantIds() when variants exist.
UnitTestCase::$randomGenerator protected property The random generator.
UnitTestCase::$root protected property The app root.
UnitTestCase::assertArrayEquals protected function Asserts if two arrays are equal by sorting them first.
UnitTestCase::getBlockMockWithMachineName protected function Mocks a block with a block plugin.
UnitTestCase::getClassResolverStub protected function Returns a stub class resolver.
UnitTestCase::getConfigFactoryStub public function Returns a stub config factory that behaves according to the passed in array.
UnitTestCase::getConfigStorageStub public function Returns a stub config storage that returns the supplied configuration.
UnitTestCase::getContainerWithCacheTagsInvalidator protected function Sets up a container with a cache tags invalidator.
UnitTestCase::getRandomGenerator protected function Gets the random generator for the utility methods.
UnitTestCase::getStringTranslationStub public function Returns a stub translation manager that just returns the passed string.
UnitTestCase::randomMachineName public function Generates a unique random string containing letters and numbers.