You are here

class GetTest in Zircon Profile 8.0

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

Tests the get process plugin.

@group migrate

Hierarchy

Expanded class hierarchy of GetTest

File

core/modules/migrate/tests/src/Unit/process/GetTest.php, line 16
Contains \Drupal\Tests\migrate\Unit\process\GetTest.

Namespace

Drupal\Tests\migrate\Unit\process
View source
class GetTest extends MigrateProcessTestCase {

  /**
   * {@inheritdoc}
   */
  protected function setUp() {
    $this->plugin = new TestGet();
    parent::setUp();
  }

  /**
   * Tests the Get plugin when source is a string.
   */
  public function testTransformSourceString() {
    $this->row
      ->expects($this
      ->once())
      ->method('getSourceProperty')
      ->with('test')
      ->will($this
      ->returnValue('source_value'));
    $this->plugin
      ->setSource('test');
    $value = $this->plugin
      ->transform(NULL, $this->migrateExecutable, $this->row, 'destinationproperty');
    $this
      ->assertSame($value, 'source_value');
  }

  /**
   * Tests the Get plugin when source is an array.
   */
  public function testTransformSourceArray() {
    $map = array(
      'test1' => 'source_value1',
      'test2' => 'source_value2',
    );
    $this->plugin
      ->setSource(array(
      'test1',
      'test2',
    ));
    $this->row
      ->expects($this
      ->exactly(2))
      ->method('getSourceProperty')
      ->will($this
      ->returnCallback(function ($argument) use ($map) {
      return $map[$argument];
    }));
    $value = $this->plugin
      ->transform(NULL, $this->migrateExecutable, $this->row, 'destinationproperty');
    $this
      ->assertSame($value, array(
      'source_value1',
      'source_value2',
    ));
  }

  /**
   * Tests the Get plugin when source is a string pointing to destination.
   */
  public function testTransformSourceStringAt() {
    $this->row
      ->expects($this
      ->once())
      ->method('getSourceProperty')
      ->with('@test')
      ->will($this
      ->returnValue('source_value'));
    $this->plugin
      ->setSource('@@test');
    $value = $this->plugin
      ->transform(NULL, $this->migrateExecutable, $this->row, 'destinationproperty');
    $this
      ->assertSame($value, 'source_value');
  }

  /**
   * Tests the Get plugin when source is an array pointing to destination.
   */
  public function testTransformSourceArrayAt() {
    $map = array(
      'test1' => 'source_value1',
      '@test2' => 'source_value2',
      '@test3' => 'source_value3',
      'test4' => 'source_value4',
    );
    $this->plugin
      ->setSource(array(
      'test1',
      '@@test2',
      '@@test3',
      'test4',
    ));
    $this->row
      ->expects($this
      ->exactly(4))
      ->method('getSourceProperty')
      ->will($this
      ->returnCallback(function ($argument) use ($map) {
      return $map[$argument];
    }));
    $value = $this->plugin
      ->transform(NULL, $this->migrateExecutable, $this->row, 'destinationproperty');
    $this
      ->assertSame($value, array(
      'source_value1',
      'source_value2',
      'source_value3',
      'source_value4',
    ));
  }

}

Members

Namesort descending Modifiers Type Description Overrides
GetTest::setUp protected function Overrides MigrateProcessTestCase::setUp
GetTest::testTransformSourceArray public function Tests the Get plugin when source is an array.
GetTest::testTransformSourceArrayAt public function Tests the Get plugin when source is an array pointing to destination.
GetTest::testTransformSourceString public function Tests the Get plugin when source is a string.
GetTest::testTransformSourceStringAt public function Tests the Get plugin when source is a string pointing to destination.
MigrateProcessTestCase::$migrateExecutable protected property
MigrateProcessTestCase::$plugin protected property
MigrateProcessTestCase::$row protected property
MigrateTestCase::$idMap protected property
MigrateTestCase::$migrationConfiguration protected property 74
MigrateTestCase::$migrationStatus protected property Local store for mocking setStatus()/getStatus().
MigrateTestCase::createSchemaFromRow protected function Generates a table schema from a row.
MigrateTestCase::getDatabase protected function Get an SQLite database connection object for use in tests.
MigrateTestCase::getMigration protected function Retrieve a mocked migration.
MigrateTestCase::getValue protected function 1
MigrateTestCase::queryResultTest public function Tests a query
MigrateTestCase::retrievalAssertHelper protected function Asserts tested values during test retrieval.
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.