class DedupeEntityTest in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/modules/migrate/tests/src/Unit/process/DedupeEntityTest.php \Drupal\Tests\migrate\Unit\process\DedupeEntityTest
@coversDefaultClass \Drupal\migrate\Plugin\migrate\process\DedupeEntity @group migrate
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \Drupal\Tests\PHPUnit_Framework_TestCase
- class \Drupal\Tests\migrate\Unit\MigrateTestCase
- class \Drupal\Tests\migrate\Unit\process\MigrateProcessTestCase
- class \Drupal\Tests\migrate\Unit\process\DedupeEntityTest
- class \Drupal\Tests\migrate\Unit\process\MigrateProcessTestCase
- class \Drupal\Tests\migrate\Unit\MigrateTestCase
Expanded class hierarchy of DedupeEntityTest
File
- core/
modules/ migrate/ tests/ src/ Unit/ process/ DedupeEntityTest.php, line 16 - Contains \Drupal\Tests\migrate\Unit\process\DedupeEntityTest.
Namespace
Drupal\Tests\migrate\Unit\processView source
class DedupeEntityTest extends MigrateProcessTestCase {
/**
* The mock entity query.
*
* @var \Drupal\Core\Entity\Query\QueryInterface
* @var \Drupal\Core\Entity\Query\QueryFactory
*/
protected $entityQuery;
/**
* The mock entity query factory.
*
* @var \Drupal\Core\Entity\Query\QueryFactory|\PHPUnit_Framework_MockObject_MockObject
*/
protected $entityQueryFactory;
/**
* The migration configuration, initialized to set the ID to test.
*
* @var array
*/
protected $migrationConfiguration = array(
'id' => 'test',
);
/**
* {@inheritdoc}
*/
protected function setUp() {
$this->entityQuery = $this
->getMockBuilder('Drupal\\Core\\Entity\\Query\\QueryInterface')
->disableOriginalConstructor()
->getMock();
$this->entityQueryFactory = $this
->getMockBuilder('Drupal\\Core\\Entity\\Query\\QueryFactory')
->disableOriginalConstructor()
->getMock();
$this->entityQueryFactory
->expects($this
->any())
->method('get')
->will($this
->returnValue($this->entityQuery));
parent::setUp();
}
/**
* Tests entity based deduplication based on providerTestDedupe() values.
*
* @dataProvider providerTestDedupe
*/
public function testDedupe($count, $postfix = '', $start = NULL, $length = NULL) {
$configuration = array(
'entity_type' => 'test_entity_type',
'field' => 'test_field',
);
if ($postfix) {
$configuration['postfix'] = $postfix;
}
$configuration['start'] = isset($start) ? $start : NULL;
$configuration['length'] = isset($length) ? $length : NULL;
$plugin = new DedupeEntity($configuration, 'dedupe_entity', array(), $this
->getMigration(), $this->entityQueryFactory);
$this
->entityQueryExpects($count);
$value = $this
->randomMachineName(32);
$actual = $plugin
->transform($value, $this->migrateExecutable, $this->row, 'testproperty');
$expected = Unicode::substr($value, $start, $length);
$expected .= $count ? $postfix . $count : '';
$this
->assertSame($expected, $actual);
}
/**
* Tests that invalid start position throws an exception.
*/
public function testDedupeEntityInvalidStart() {
$configuration = array(
'entity_type' => 'test_entity_type',
'field' => 'test_field',
'start' => 'foobar',
);
$plugin = new DedupeEntity($configuration, 'dedupe_entity', array(), $this
->getMigration(), $this->entityQueryFactory);
$this
->setExpectedException('Drupal\\migrate\\MigrateException', 'The start position configuration key should be an integer. Omit this key to capture from the beginning of the string.');
$plugin
->transform('test_start', $this->migrateExecutable, $this->row, 'testproperty');
}
/**
* Tests that invalid length option throws an exception.
*/
public function testDedupeEntityInvalidLength() {
$configuration = array(
'entity_type' => 'test_entity_type',
'field' => 'test_field',
'length' => 'foobar',
);
$plugin = new DedupeEntity($configuration, 'dedupe_entity', array(), $this
->getMigration(), $this->entityQueryFactory);
$this
->setExpectedException('Drupal\\migrate\\MigrateException', 'The character length configuration key should be an integer. Omit this key to capture the entire string.');
$plugin
->transform('test_length', $this->migrateExecutable, $this->row, 'testproperty');
}
/**
* Data provider for testDedupe().
*/
public function providerTestDedupe() {
return array(
// Tests no duplication.
array(
0,
),
// Tests no duplication and start position.
array(
0,
NULL,
10,
),
// Tests no duplication, start position, and length.
array(
0,
NULL,
5,
10,
),
// Tests no duplication and length.
array(
0,
NULL,
NULL,
10,
),
// Tests duplication.
array(
3,
),
// Tests duplication and start position.
array(
3,
NULL,
10,
),
// Tests duplication, start position, and length.
array(
3,
NULL,
5,
10,
),
// Tests duplication and length.
array(
3,
NULL,
NULL,
10,
),
// Tests no duplication and postfix.
array(
0,
'_',
),
// Tests no duplication, postfix, and start position.
array(
0,
'_',
5,
),
// Tests no duplication, postfix, start position, and length.
array(
0,
'_',
5,
10,
),
// Tests no duplication, postfix, and length.
array(
0,
'_',
NULL,
10,
),
// Tests duplication and postfix.
array(
2,
'_',
),
// Tests duplication, postfix, and start position.
array(
2,
'_',
5,
),
// Tests duplication, postfix, start position, and length.
array(
2,
'_',
5,
10,
),
// Tests duplication, postfix, and length.
array(
2,
'_',
NULL,
10,
),
);
}
/**
* Helper function to add expectations to the mock entity query object.
*
* @param int $count
* The number of deduplications to be set up.
*/
protected function entityQueryExpects($count) {
$this->entityQuery
->expects($this
->exactly($count + 1))
->method('condition')
->will($this
->returnValue($this->entityQuery));
$this->entityQuery
->expects($this
->exactly($count + 1))
->method('count')
->will($this
->returnValue($this->entityQuery));
$this->entityQuery
->expects($this
->exactly($count + 1))
->method('execute')
->will($this
->returnCallback(function () use (&$count) {
return $count--;
}));
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DedupeEntityTest:: |
protected | property | The mock entity query. | |
DedupeEntityTest:: |
protected | property | The mock entity query factory. | |
DedupeEntityTest:: |
protected | property |
The migration configuration, initialized to set the ID to test. Overrides MigrateTestCase:: |
|
DedupeEntityTest:: |
protected | function | Helper function to add expectations to the mock entity query object. | |
DedupeEntityTest:: |
public | function | Data provider for testDedupe(). | |
DedupeEntityTest:: |
protected | function |
Overrides MigrateProcessTestCase:: |
|
DedupeEntityTest:: |
public | function | Tests entity based deduplication based on providerTestDedupe() values. | |
DedupeEntityTest:: |
public | function | Tests that invalid length option throws an exception. | |
DedupeEntityTest:: |
public | function | Tests that invalid start position throws an exception. | |
MigrateProcessTestCase:: |
protected | property | ||
MigrateProcessTestCase:: |
protected | property | ||
MigrateProcessTestCase:: |
protected | property | ||
MigrateTestCase:: |
protected | property | ||
MigrateTestCase:: |
protected | property | Local store for mocking setStatus()/getStatus(). | |
MigrateTestCase:: |
protected | function | Generates a table schema from a row. | |
MigrateTestCase:: |
protected | function | Get an SQLite database connection object for use in tests. | |
MigrateTestCase:: |
protected | function | Retrieve a mocked migration. | |
MigrateTestCase:: |
protected | function | 1 | |
MigrateTestCase:: |
public | function | Tests a query | |
MigrateTestCase:: |
protected | function | Asserts tested values during test retrieval. | |
UnitTestCase:: |
protected | property | The random generator. | |
UnitTestCase:: |
protected | property | The app root. | |
UnitTestCase:: |
protected | function | Asserts if two arrays are equal by sorting them first. | |
UnitTestCase:: |
protected | function | Mocks a block with a block plugin. | |
UnitTestCase:: |
protected | function | Returns a stub class resolver. | |
UnitTestCase:: |
public | function | Returns a stub config factory that behaves according to the passed in 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. |