class RowTest in Zircon Profile 8
Same name in this branch
- 8 core/modules/migrate/tests/src/Unit/RowTest.php \Drupal\Tests\migrate\Unit\RowTest
- 8 core/modules/views/tests/modules/views_test_data/src/Plugin/views/row/RowTest.php \Drupal\views_test_data\Plugin\views\row\RowTest
Same name and namespace in other branches
- 8.0 core/modules/migrate/tests/src/Unit/RowTest.php \Drupal\Tests\migrate\Unit\RowTest
@coversDefaultClass \Drupal\migrate\Row @group migrate
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \Drupal\Tests\PHPUnit_Framework_TestCase
- class \Drupal\Tests\migrate\Unit\RowTest
Expanded class hierarchy of RowTest
3 string references to 'RowTest'
- RowTest::calculateDependencies in core/
modules/ views/ tests/ modules/ views_test_data/ src/ Plugin/ views/ row/ RowTest.php - Calculates dependencies for the configured plugin.
- ViewEntityDependenciesTest::testGetDependencies in core/
modules/ views/ src/ Tests/ Entity/ ViewEntityDependenciesTest.php - Tests the getDependencies method.
- views.view.test_plugin_dependencies.yml in core/
modules/ views/ tests/ modules/ views_test_config/ test_views/ views.view.test_plugin_dependencies.yml - core/modules/views/tests/modules/views_test_config/test_views/views.view.test_plugin_dependencies.yml
File
- core/
modules/ migrate/ tests/ src/ Unit/ RowTest.php, line 18 - Contains \Drupal\Tests\migrate\Unit\RowTest.
Namespace
Drupal\Tests\migrate\UnitView source
class RowTest extends UnitTestCase {
/**
* The source IDs.
*
* @var array
*/
protected $testSourceIds = array(
'nid' => 'Node ID',
);
/**
* The test values.
*
* @var array
*/
protected $testValues = array(
'nid' => 1,
'title' => 'node 1',
);
/**
* The test hash.
*
* @var string
*/
protected $testHash = '85795d4cde4a2425868b812cc88052ecd14fc912e7b9b4de45780f66750e8b1e';
/**
* The test hash after changing title value to 'new title'.
*
* @var string
*/
protected $testHashMod = '9476aab0b62b3f47342cc6530441432e5612dcba7ca84115bbab5cceaca1ecb3';
/**
* Tests object creation: empty.
*/
public function testRowWithoutData() {
$row = new Row(array(), array());
$this
->assertSame(array(), $row
->getSource(), 'Empty row');
}
/**
* Tests object creation: basic.
*/
public function testRowWithBasicData() {
$row = new Row($this->testValues, $this->testSourceIds);
$this
->assertSame($this->testValues, $row
->getSource(), 'Row with data, simple id.');
}
/**
* Tests object creation: multiple source IDs.
*/
public function testRowWithMultipleSourceIds() {
$multi_source_ids = $this->testSourceIds + array(
'vid' => 'Node revision',
);
$multi_source_ids_values = $this->testValues + array(
'vid' => 1,
);
$row = new Row($multi_source_ids_values, $multi_source_ids);
$this
->assertSame($multi_source_ids_values, $row
->getSource(), 'Row with data, multifield id.');
}
/**
* Tests object creation: invalid values.
*
* @expectedException \Exception
*/
public function testRowWithInvalidData() {
$invalid_values = array(
'title' => 'node X',
);
$row = new Row($invalid_values, $this->testSourceIds);
}
/**
* Tests source immutability after freeze.
*
* @expectedException \Exception
*/
public function testSourceFreeze() {
$row = new Row($this->testValues, $this->testSourceIds);
$row
->rehash();
$this
->assertSame($this->testHash, $row
->getHash(), 'Correct hash.');
$row
->setSourceProperty('title', 'new title');
$row
->rehash();
$this
->assertSame($this->testHashMod, $row
->getHash(), 'Hash changed correctly.');
$row
->freezeSource();
$row
->setSourceProperty('title', 'new title');
}
/**
* Tests setting on a frozen row.
*
* @expectedException \Exception
* @expectedExceptionMessage The source is frozen and can't be changed any more
*/
public function testSetFrozenRow() {
$row = new Row($this->testValues, $this->testSourceIds);
$row
->freezeSource();
$row
->setSourceProperty('title', 'new title');
}
/**
* Tests hashing.
*/
public function testHashing() {
$row = new Row($this->testValues, $this->testSourceIds);
$this
->assertSame('', $row
->getHash(), 'No hash at creation');
$row
->rehash();
$this
->assertSame($this->testHash, $row
->getHash(), 'Correct hash.');
$row
->rehash();
$this
->assertSame($this->testHash, $row
->getHash(), 'Correct hash even doing it twice.');
// Set the map to needs update.
$test_id_map = array(
'original_hash' => '',
'hash' => '',
'source_row_status' => MigrateIdMapInterface::STATUS_NEEDS_UPDATE,
);
$row
->setIdMap($test_id_map);
$this
->assertTrue($row
->needsUpdate());
$row
->rehash();
$this
->assertSame($this->testHash, $row
->getHash(), 'Correct hash even if id_mpa have changed.');
$row
->setSourceProperty('title', 'new title');
$row
->rehash();
$this
->assertSame($this->testHashMod, $row
->getHash(), 'Hash changed correctly.');
// Check hash calculation algorithm.
$hash = hash('sha256', serialize($row
->getSource()));
$this
->assertSame($hash, $row
->getHash());
// Check length of generated hash used for mapping schema.
$this
->assertSame(64, strlen($row
->getHash()));
// Set the map to successfully imported.
$test_id_map = array(
'original_hash' => '',
'hash' => '',
'source_row_status' => MigrateIdMapInterface::STATUS_IMPORTED,
);
$row
->setIdMap($test_id_map);
$this
->assertFalse($row
->needsUpdate());
// Set the same hash value and ensure it was not changed.
$random = $this
->randomMachineName();
$test_id_map = array(
'original_hash' => $random,
'hash' => $random,
'source_row_status' => MigrateIdMapInterface::STATUS_NEEDS_UPDATE,
);
$row
->setIdMap($test_id_map);
$this
->assertFalse($row
->changed());
// Set different has values to ensure it is marked as changed.
$test_id_map = array(
'original_hash' => $this
->randomMachineName(),
'hash' => $this
->randomMachineName(),
'source_row_status' => MigrateIdMapInterface::STATUS_NEEDS_UPDATE,
);
$row
->setIdMap($test_id_map);
$this
->assertTrue($row
->changed());
}
/**
* Tests getting/setting the ID Map.
*
* @covers ::setIdMap
* @covers ::getIdMap
*/
public function testGetSetIdMap() {
$row = new Row($this->testValues, $this->testSourceIds);
$test_id_map = array(
'original_hash' => '',
'hash' => '',
'source_row_status' => MigrateIdMapInterface::STATUS_NEEDS_UPDATE,
);
$row
->setIdMap($test_id_map);
$this
->assertEquals($test_id_map, $row
->getIdMap());
}
/**
* Tests the source ID.
*/
public function testSourceIdValues() {
$row = new Row($this->testValues, $this->testSourceIds);
$this
->assertSame(array(
'nid' => $this->testValues['nid'],
), $row
->getSourceIdValues());
}
/**
* Tests getting the source property.
*
* @covers ::getSourceProperty
*/
public function testGetSourceProperty() {
$row = new Row($this->testValues, $this->testSourceIds);
$this
->assertSame($this->testValues['nid'], $row
->getSourceProperty('nid'));
$this
->assertSame($this->testValues['title'], $row
->getSourceProperty('title'));
$this
->assertNull($row
->getSourceProperty('non_existing'));
}
/**
* Tests setting and getting the destination.
*/
public function testDestination() {
$row = new Row($this->testValues, $this->testSourceIds);
$this
->assertEmpty($row
->getDestination());
$this
->assertFalse($row
->hasDestinationProperty('nid'));
// Set a destination.
$row
->setDestinationProperty('nid', 2);
$this
->assertTrue($row
->hasDestinationProperty('nid'));
$this
->assertEquals(array(
'nid' => 2,
), $row
->getDestination());
}
/**
* Tests setting/getting multiple destination IDs.
*/
public function testMultipleDestination() {
$row = new Row($this->testValues, $this->testSourceIds);
// Set some deep nested values.
$row
->setDestinationProperty('image/alt', 'alt text');
$row
->setDestinationProperty('image/fid', 3);
$this
->assertTrue($row
->hasDestinationProperty('image'));
$this
->assertFalse($row
->hasDestinationProperty('alt'));
$this
->assertFalse($row
->hasDestinationProperty('fid'));
$destination = $row
->getDestination();
$this
->assertEquals('alt text', $destination['image']['alt']);
$this
->assertEquals(3, $destination['image']['fid']);
$this
->assertEquals('alt text', $row
->getDestinationProperty('image/alt'));
$this
->assertEquals(3, $row
->getDestinationProperty('image/fid'));
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
RowTest:: |
protected | property | The test hash. | |
RowTest:: |
protected | property | The test hash after changing title value to 'new title'. | |
RowTest:: |
protected | property | The source IDs. | |
RowTest:: |
protected | property | The test values. | |
RowTest:: |
public | function | Tests setting and getting the destination. | |
RowTest:: |
public | function | Tests getting/setting the ID Map. | |
RowTest:: |
public | function | Tests getting the source property. | |
RowTest:: |
public | function | Tests hashing. | |
RowTest:: |
public | function | Tests setting/getting multiple destination IDs. | |
RowTest:: |
public | function | Tests object creation: basic. | |
RowTest:: |
public | function | Tests object creation: invalid values. | |
RowTest:: |
public | function | Tests object creation: multiple source IDs. | |
RowTest:: |
public | function | Tests object creation: empty. | |
RowTest:: |
public | function | Tests setting on a frozen row. | |
RowTest:: |
public | function | Tests source immutability after freeze. | |
RowTest:: |
public | function | Tests the source ID. | |
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. | |
UnitTestCase:: |
protected | function | 259 |