Commit 8fa8911c authored by alexpott's avatar alexpott

Issue #2824267 by quietone, shashikant_chauhan, faline, mikeryan, OnkelTem,...

Issue #2824267 by quietone, shashikant_chauhan, faline, mikeryan, OnkelTem, ohthehugemanatee: Highwater condition isn't added (on remote databases)
parent d65d76f9
......@@ -274,6 +274,7 @@ protected function initializeIterator() {
$high_water_field = $this->getHighWaterField();
$conditions->condition($high_water_field, $high_water, '>');
$this->query->orderBy($high_water_field);
$condition_added = TRUE;
}
if ($condition_added) {
$this->query->condition($conditions);
......
<?php
namespace Drupal\Tests\migrate\Kernel;
/**
* Tests the high water handling.
*
* @covers \Drupal\migrate_sql_test\Plugin\migrate\source\HighWaterTest
* @group migrate
*/
class HighWaterNotJoinableTest extends MigrateSqlSourceTestBase {
/**
* {@inheritdoc}
*/
public static $modules = ['migrate', 'migrate_drupal', 'migrate_sql_test'];
/**
* {@inheritdoc}
*/
public function providerSource() {
$tests = [];
// The source data.
$tests[0]['source_data']['high_water_node'] = [
[
'id' => 1,
'title' => 'Item 1',
'changed' => 1,
],
[
'id' => 2,
'title' => 'Item 2',
'changed' => 2,
],
[
'id' => 3,
'title' => 'Item 3',
'changed' => 3,
],
];
// The expected results.
$tests[0]['expected_data'] = [
[
'id' => 2,
'title' => 'Item 2',
'changed' => 2,
],
[
'id' => 3,
'title' => 'Item 3',
'changed' => 3,
],
];
$tests[0]['expected_count'] = NULL;
$tests[0]['configuration'] = [
'high_water_property' => [
'name' => 'changed',
],
];
$tests[0]['high_water'] = $tests[0]['source_data']['high_water_node'][0]['changed'];
return $tests;
}
}
......@@ -136,6 +136,64 @@ public function testHighWater() {
$this->assertNodeDoesNotExist('Item 3');
}
/**
* Tests high water property of SqlBase when rows marked for update.
*/
public function testHighWaterUpdate() {
// Assert all of the nodes have been imported.
$this->assertNodeExists('Item 1');
$this->assertNodeExists('Item 2');
$this->assertNodeExists('Item 3');
// Update Item 1 setting its high_water_property to value that is below
// current high water mark.
$this->sourceDatabase->update('high_water_node')
->fields([
'title' => 'Item 1 updated',
'changed' => 2,
])
->condition('title', 'Item 1')
->execute();
// Update Item 2 setting its high_water_property to value equal to
// current high water mark.
$this->sourceDatabase->update('high_water_node')
->fields([
'title' => 'Item 2 updated',
'changed' => 3,
])
->condition('title', 'Item 2')
->execute();
// Update Item 3 setting its high_water_property to value that is above
// current high water mark.
$this->sourceDatabase->update('high_water_node')
->fields([
'title' => 'Item 3 updated',
'changed' => 4,
])
->condition('title', 'Item 3')
->execute();
// Set all rows as needing an update.
$id_map = $this->getMigration('high_water_test')->getIdMap();
$id_map->prepareUpdate();
$this->executeMigration('high_water_test');
// Item with lower highwater should be updated.
$this->assertNodeExists('Item 1 updated');
$this->assertNodeDoesNotExist('Item 1');
// Item with equal highwater should be updated.
$this->assertNodeExists('Item 2 updated');
$this->assertNodeDoesNotExist('Item 2');
// Item with greater highwater should be updated.
$this->assertNodeExists('Item 3 updated');
$this->assertNodeDoesNotExist('Item 3');
}
/**
* Assert that node with given title exists.
*
......
......@@ -135,23 +135,33 @@ protected function getPlugin(array $configuration) {
* value (like FALSE or 'nope'), the source plugin will not be counted.
* @param array $configuration
* (optional) Configuration for the source plugin.
* @param mixed $high_water
* (optional) The value of the high water field.
*
* @dataProvider providerSource
*/
public function testSource(array $source_data, array $expected_data, $expected_count = NULL, array $configuration = []) {
public function testSource(array $source_data, array $expected_data, $expected_count = NULL, array $configuration = [], $high_water = NULL) {
$plugin = $this->getPlugin($configuration);
// All source plugins must define IDs.
$this->assertNotEmpty($plugin->getIds());
// If there is a high water mark, set it in the high water storage.
if (isset($high_water)) {
$this->container
->get('keyvalue')
->get('migrate:high_water')
->set($this->migration->reveal()->id(), $high_water);
}
if (is_null($expected_count)) {
$expected_count = count($expected_data);
}
// If an expected count was given, assert it only if the plugin is
// countable.
if (is_numeric($expected_count)) {
$this->assertInstanceOf('\Countable', $plugin);
$this->assertCount($expected_count, $plugin);
$this->assertInstanceOf('\Iterator', $plugin);
$this->assertSame($expected_count, iterator_count($plugin));
}
$i = 0;
......
......@@ -63,12 +63,14 @@ protected function getDatabase(array $source_data) {
* (optional) How many rows the source plugin is expected to return.
* @param array $configuration
* (optional) Configuration for the source plugin.
* @param mixed $high_water
* (optional) The value of the high water field.
*
* @dataProvider providerSource
*
* @requires extension pdo_sqlite
*/
public function testSource(array $source_data, array $expected_data, $expected_count = NULL, array $configuration = []) {
public function testSource(array $source_data, array $expected_data, $expected_count = NULL, array $configuration = [], $high_water = NULL) {
$plugin = $this->getPlugin($configuration);
// Since we don't yet inject the database connection, we need to use a
......@@ -78,7 +80,7 @@ public function testSource(array $source_data, array $expected_data, $expected_c
$property->setAccessible(TRUE);
$property->setValue($plugin, $this->getDatabase($source_data));
parent::testSource($source_data, $expected_data, $expected_count, $configuration);
parent::testSource($source_data, $expected_data, $expected_count, $configuration, $high_water);
}
}
......@@ -106,9 +106,12 @@ protected function setUp() {
\Drupal::setContainer($container);
$migration = $this->getMigration();
$migration->expects($this->any())
->method('getHighWater')
->will($this->returnValue(static::ORIGINAL_HIGH_WATER));
// Set the high water value.
\Drupal::keyValue('migrate:high_water')
->expects($this->any())
->method('get')
->willReturn(static::ORIGINAL_HIGH_WATER);
// Setup the plugin.
$plugin_class = static::PLUGIN_CLASS;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment