options.test 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. /**
  3. * @file
  4. * Tests for import options.
  5. */
  6. /**
  7. * Test node migration.
  8. */
  9. class MigrateImportOptionsTest extends DrupalWebTestCase {
  10. public static function getInfo() {
  11. return array(
  12. 'name' => 'Import options',
  13. 'description' => 'Test the import options',
  14. 'group' => 'Migrate',
  15. );
  16. }
  17. function setUp() {
  18. parent::setUp('migrate_example');
  19. }
  20. function testItemLimitOption() {
  21. $migration = Migration::getInstance('BeerTerm');
  22. $limit = 1;
  23. $options = array(
  24. 'limit' => array(
  25. 'unit' => 'item',
  26. 'value' => $limit,
  27. ),
  28. );
  29. // We use the timers to track how many times prepareRow() is called.
  30. global $timers, $_migrate_track_timer;
  31. $_migrate_track_timer = TRUE;
  32. $result = $migration->processImport($options);
  33. $this->verbose(print_r($timers, 1));
  34. $successes = $migration->importedCount();
  35. $this->verbose("Total successes: {$successes}");
  36. $assertion = format_plural($limit, 'The migration successfully processed 1 item.',
  37. 'The migration successfully processed @count items.');
  38. $this->assertEqual($limit, $successes, $assertion);
  39. $prepare_row_count = $timers['BeerTermMigration prepareRow']['count'];
  40. $this->verbose("prepareRow() count: {$prepare_row_count}");
  41. $processed = $migration->processedCount();
  42. $this->verbose("Total processed count: {$processed}");
  43. $assertion = format_plural($processed, 'The migration executed processRow() on 1 item.',
  44. 'The migration executed processRow() on @count items.');
  45. $this->assertEqual($prepare_row_count, $processed, $assertion);
  46. }
  47. }