Mercurial > hg > isophonics-drupal-site
comparison core/modules/migrate/tests/src/Unit/MigrateSqlIdMapTest.php @ 14:1fec387a4317
Update Drupal core to 8.5.2 via Composer
author | Chris Cannam |
---|---|
date | Mon, 23 Apr 2018 09:46:53 +0100 |
parents | 4c8ae668cc8c |
children | c2387f117808 |
comparison
equal
deleted
inserted
replaced
13:5fb285c0d0e3 | 14:1fec387a4317 |
---|---|
209 foreach ($expected_results as $key => $expected_result) { | 209 foreach ($expected_results as $key => $expected_result) { |
210 $id_map->saveMessage(['source_id_property' => $key], $message); | 210 $id_map->saveMessage(['source_id_property' => $key], $message); |
211 } | 211 } |
212 | 212 |
213 // Truncate and check that 4 messages were deleted. | 213 // Truncate and check that 4 messages were deleted. |
214 $this->assertEquals($id_map->messageCount(), 4); | 214 $this->assertSame($id_map->messageCount(), 4); |
215 $id_map->clearMessages(); | 215 $id_map->clearMessages(); |
216 $count = $id_map->messageCount(); | 216 $count = $id_map->messageCount(); |
217 $this->assertEquals($count, 0); | 217 $this->assertSame($count, 0); |
218 } | 218 } |
219 | 219 |
220 /** | 220 /** |
221 * Tests the getRowsNeedingUpdate method for rows that need an update. | 221 * Tests the getRowsNeedingUpdate method for rows that need an update. |
222 */ | 222 */ |
282 $id_map = $this->getIdMap(); | 282 $id_map = $this->getIdMap(); |
283 | 283 |
284 // Test count message multiple times starting from 0. | 284 // Test count message multiple times starting from 0. |
285 foreach ($expected_results as $key => $expected_result) { | 285 foreach ($expected_results as $key => $expected_result) { |
286 $count = $id_map->messageCount(); | 286 $count = $id_map->messageCount(); |
287 $this->assertEquals($expected_result, $count); | 287 $this->assertSame($expected_result, $count); |
288 $id_map->saveMessage(['source_id_property' => $key], $message); | 288 $id_map->saveMessage(['source_id_property' => $key], $message); |
289 } | 289 } |
290 } | 290 } |
291 | 291 |
292 /** | 292 /** |
682 // Add a single failed row and assert zero imported rows. | 682 // Add a single failed row and assert zero imported rows. |
683 $source = ['source_id_property' => 'source_value_failed']; | 683 $source = ['source_id_property' => 'source_value_failed']; |
684 $row = new Row($source, ['source_id_property' => []]); | 684 $row = new Row($source, ['source_id_property' => []]); |
685 $destination = ['destination_id_property' => 'destination_value_failed']; | 685 $destination = ['destination_id_property' => 'destination_value_failed']; |
686 $id_map->saveIdMapping($row, $destination, MigrateIdMapInterface::STATUS_FAILED); | 686 $id_map->saveIdMapping($row, $destination, MigrateIdMapInterface::STATUS_FAILED); |
687 $this->assertSame(0, (int) $id_map->importedCount()); | 687 $this->assertSame(0, $id_map->importedCount()); |
688 | 688 |
689 // Add an imported row and assert single count. | 689 // Add an imported row and assert single count. |
690 $source = ['source_id_property' => 'source_value_imported']; | 690 $source = ['source_id_property' => 'source_value_imported']; |
691 $row = new Row($source, ['source_id_property' => []]); | 691 $row = new Row($source, ['source_id_property' => []]); |
692 $destination = ['destination_id_property' => 'destination_value_imported']; | 692 $destination = ['destination_id_property' => 'destination_value_imported']; |
693 $id_map->saveIdMapping($row, $destination, MigrateIdMapInterface::STATUS_IMPORTED); | 693 $id_map->saveIdMapping($row, $destination, MigrateIdMapInterface::STATUS_IMPORTED); |
694 $this->assertSame(1, (int) $id_map->importedCount()); | 694 $this->assertSame(1, $id_map->importedCount()); |
695 | 695 |
696 // Add a row needing update and assert multiple imported rows. | 696 // Add a row needing update and assert multiple imported rows. |
697 $source = ['source_id_property' => 'source_value_update']; | 697 $source = ['source_id_property' => 'source_value_update']; |
698 $row = new Row($source, ['source_id_property' => []]); | 698 $row = new Row($source, ['source_id_property' => []]); |
699 $destination = ['destination_id_property' => 'destination_value_update']; | 699 $destination = ['destination_id_property' => 'destination_value_update']; |
700 $id_map->saveIdMapping($row, $destination, MigrateIdMapInterface::STATUS_NEEDS_UPDATE); | 700 $id_map->saveIdMapping($row, $destination, MigrateIdMapInterface::STATUS_NEEDS_UPDATE); |
701 $this->assertSame(2, (int) $id_map->importedCount()); | 701 $this->assertSame(2, $id_map->importedCount()); |
702 } | 702 } |
703 | 703 |
704 /** | 704 /** |
705 * Tests the number of processed source rows. | 705 * Tests the number of processed source rows. |
706 * | 706 * |
710 * - Multiple processed rows. | 710 * - Multiple processed rows. |
711 */ | 711 */ |
712 public function testProcessedCount() { | 712 public function testProcessedCount() { |
713 $id_map = $this->getIdMap(); | 713 $id_map = $this->getIdMap(); |
714 // Assert zero rows have been processed before adding rows. | 714 // Assert zero rows have been processed before adding rows. |
715 $this->assertSame(0, (int) $id_map->processedCount()); | 715 $this->assertSame(0, $id_map->processedCount()); |
716 $row_statuses = [ | 716 $row_statuses = [ |
717 MigrateIdMapInterface::STATUS_IMPORTED, | 717 MigrateIdMapInterface::STATUS_IMPORTED, |
718 MigrateIdMapInterface::STATUS_NEEDS_UPDATE, | 718 MigrateIdMapInterface::STATUS_NEEDS_UPDATE, |
719 MigrateIdMapInterface::STATUS_IGNORED, | 719 MigrateIdMapInterface::STATUS_IGNORED, |
720 MigrateIdMapInterface::STATUS_FAILED, | 720 MigrateIdMapInterface::STATUS_FAILED, |
725 $row = new Row($source, ['source_id_property' => []]); | 725 $row = new Row($source, ['source_id_property' => []]); |
726 $destination = ['destination_id_property' => 'destination_value_' . $status]; | 726 $destination = ['destination_id_property' => 'destination_value_' . $status]; |
727 $id_map->saveIdMapping($row, $destination, $status); | 727 $id_map->saveIdMapping($row, $destination, $status); |
728 if ($status == MigrateIdMapInterface::STATUS_IMPORTED) { | 728 if ($status == MigrateIdMapInterface::STATUS_IMPORTED) { |
729 // Assert a single row has been processed. | 729 // Assert a single row has been processed. |
730 $this->assertSame(1, (int) $id_map->processedCount()); | 730 $this->assertSame(1, $id_map->processedCount()); |
731 } | 731 } |
732 } | 732 } |
733 // Assert multiple rows have been processed. | 733 // Assert multiple rows have been processed. |
734 $this->assertSame(count($row_statuses), (int) $id_map->processedCount()); | 734 $this->assertSame(count($row_statuses), $id_map->processedCount()); |
735 } | 735 } |
736 | 736 |
737 /** | 737 /** |
738 * Data provider for testUpdateCount(). | 738 * Data provider for testUpdateCount(). |
739 * | 739 * |
777 $row['destid1'] = "destination_id_value_$i"; | 777 $row['destid1'] = "destination_id_value_$i"; |
778 $row['source_row_status'] = MigrateIdMapInterface::STATUS_NEEDS_UPDATE; | 778 $row['source_row_status'] = MigrateIdMapInterface::STATUS_NEEDS_UPDATE; |
779 $this->saveMap($row); | 779 $this->saveMap($row); |
780 } | 780 } |
781 $id_map = $this->getIdMap(); | 781 $id_map = $this->getIdMap(); |
782 $this->assertSame($num_update_rows, (int) $id_map->updateCount()); | 782 $this->assertSame($num_update_rows, $id_map->updateCount()); |
783 } | 783 } |
784 | 784 |
785 /** | 785 /** |
786 * Data provider for testErrorCount(). | 786 * Data provider for testErrorCount(). |
787 * | 787 * |
825 $row['destid1'] = "destination_id_value_$i"; | 825 $row['destid1'] = "destination_id_value_$i"; |
826 $row['source_row_status'] = MigrateIdMapInterface::STATUS_FAILED; | 826 $row['source_row_status'] = MigrateIdMapInterface::STATUS_FAILED; |
827 $this->saveMap($row); | 827 $this->saveMap($row); |
828 } | 828 } |
829 | 829 |
830 $this->assertSame($num_error_rows, (int) $this->getIdMap()->errorCount()); | 830 $this->assertSame($num_error_rows, $this->getIdMap()->errorCount()); |
831 } | 831 } |
832 | 832 |
833 /** | 833 /** |
834 * Tests setting a row source_row_status to STATUS_NEEDS_UPDATE. | 834 * Tests setting a row source_row_status to STATUS_NEEDS_UPDATE. |
835 */ | 835 */ |