You are here

class AttributeDestinationTest in Commerce Migrate 8.2

Same name and namespace in other branches
  1. 3.1.x modules/csv_example/tests/src/Unit/Plugin/migrate/process/AttributeDestinationTest.php \Drupal\Tests\commerce_migrate_csv_example\Unit\Plugin\migrate\process\AttributeDestinationTest
  2. 3.0.x modules/csv_example/tests/src/Unit/Plugin/migrate/process/AttributeDestinationTest.php \Drupal\Tests\commerce_migrate_csv_example\Unit\Plugin\migrate\process\AttributeDestinationTest

Tests the Attribute Destination process plugin.

@coversDefaultClass \Drupal\commerce_migrate_csv_example\Plugin\migrate\process\AttributeDestination

@group commerce_migrate_csv_example

Hierarchy

Expanded class hierarchy of AttributeDestinationTest

File

modules/csv_example/tests/src/Unit/Plugin/migrate/process/AttributeDestinationTest.php, line 16

Namespace

Drupal\Tests\commerce_migrate_csv_example\Unit\Plugin\migrate\process
View source
class AttributeDestinationTest extends MigrateProcessTestCase {

  /**
   * Tests Attribute Destination plugin.
   *
   * @dataProvider providerTestAttributeDestination
   */
  public function testAttributeDestination($value = NULL, $expected = NULL) {
    $configuration = [];
    $this->row = $this
      ->getMockBuilder('Drupal\\migrate\\Row')
      ->setMethods([
      'get',
    ])
      ->disableOriginalConstructor()
      ->getMock();
    $this->row
      ->expects($this
      ->once())
      ->method('get')
      ->with("attribute_{$value[0]}")
      ->willReturn($value[1]);
    $this->plugin = new AttributeDestination($configuration, 'map', []);
    $this->plugin
      ->transform($value, $this->migrateExecutable, $this->row, 'foo');
    $property = $this->row
      ->get($expected[0]);
    $this
      ->assertSame($expected[1], $property);
  }

  /**
   * Data provider for testAttributeDestination().
   */
  public function providerTestAttributeDestination() {
    return [
      'one' => [
        [
          'able',
          'baker',
        ],
        [
          'attribute_able',
          'baker',
        ],
      ],
    ];
  }

  /**
   * Tests that exception is thrown when input is not valid.
   *
   * @dataProvider providerTestInvalidValue
   */
  public function testInvalidValue($value = NULL) {
    $this
      ->expectException(MigrateException::class);
    $this
      ->expectExceptionMessage("There must be an even number of input values.");
    $this->plugin = new AttributeDestination([], 'test_format_date', []);
    $this->plugin
      ->transform($value, $this->migrateExecutable, $this->row, 'foo');
  }

  /**
   * Data provider for testInvalidValue().
   */
  public function providerTestInvalidValue() {
    return [
      'one argument' => [
        [
          'a',
        ],
      ],
      'three arguments' => [
        [
          'a',
          'b',
          'c',
        ],
      ],
    ];
  }

}

Members

Namesort descending Modifiers Type Description Overrides
AttributeDestinationTest::providerTestAttributeDestination public function Data provider for testAttributeDestination().
AttributeDestinationTest::providerTestInvalidValue public function Data provider for testInvalidValue().
AttributeDestinationTest::testAttributeDestination public function Tests Attribute Destination plugin.
AttributeDestinationTest::testInvalidValue public function Tests that exception is thrown when input is not valid.
MigrateProcessTestCase::$migrateExecutable protected property
MigrateProcessTestCase::$plugin protected property
MigrateProcessTestCase::$row protected property
MigrateProcessTestCase::setUp protected function Overrides UnitTestCase::setUp 19
MigrateTestCase::$idMap protected property The migration ID map.
MigrateTestCase::$migrationConfiguration protected property An array of migration configuration values. 16
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 Gets an SQLite database connection object for use in tests.
MigrateTestCase::getMigration protected function Retrieves a mocked migration. 1
MigrateTestCase::getValue protected function Gets the value on a row for a given key. 1
MigrateTestCase::queryResultTest public function Tests a query.
MigrateTestCase::retrievalAssertHelper protected function Asserts tested values during test retrieval.
PhpunitCompatibilityTrait::getMock Deprecated public function Returns a mock object for the specified class using the available method.
PhpunitCompatibilityTrait::setExpectedException Deprecated public function Compatibility layer for PHPUnit 6 to support PHPUnit 4 code.
UnitTestCase::$randomGenerator protected property The random generator.
UnitTestCase::$root protected property The app root. 1
UnitTestCase::assertArrayEquals protected function Asserts if two arrays are equal by sorting them first.
UnitTestCase::getBlockMockWithMachineName Deprecated protected function Mocks a block with a block plugin. 1
UnitTestCase::getClassResolverStub protected function Returns a stub class resolver.
UnitTestCase::getConfigFactoryStub public function Returns a stub config factory that behaves according to the passed 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.