xml.test 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <?php
  2. /**
  3. * @file
  4. * Tests for the XML source plugins.
  5. */
  6. /**
  7. * Test node migration.
  8. */
  9. class MigrateXMLUnitTest extends DrupalWebTestCase {
  10. public static function getInfo() {
  11. return array(
  12. 'name' => 'XML migration',
  13. 'description' => 'Test migration from XML source',
  14. 'group' => 'Migrate',
  15. );
  16. }
  17. function setUp() {
  18. parent::setUp('taxonomy', 'migrate', 'migrate_example');
  19. }
  20. function testNodeImport() {
  21. $migration = Migration::getInstance('WineRegion');
  22. $result = $migration->processImport();
  23. $this->assertEqual($result, Migration::RESULT_COMPLETED,
  24. t('Region term import returned RESULT_COMPLETED'));
  25. $migration = Migration::getInstance('WineFileCopy');
  26. $result = $migration->processImport();
  27. $this->assertEqual($result, Migration::RESULT_COMPLETED,
  28. t('File import returned RESULT_COMPLETED'));
  29. $migration = Migration::getInstance('WineRole');
  30. $result = $migration->processImport();
  31. $this->assertEqual($result, Migration::RESULT_COMPLETED,
  32. t('Role import returned RESULT_COMPLETED'));
  33. $migration = Migration::getInstance('WineUser');
  34. $result = $migration->processImport();
  35. $this->assertEqual($result, Migration::RESULT_COMPLETED,
  36. t('User import returned RESULT_COMPLETED'));
  37. $migration = Migration::getInstance('WineProducerXML');
  38. $result = $migration->processImport();
  39. $this->assertEqual($result, Migration::RESULT_COMPLETED,
  40. t('Producer node import returned RESULT_COMPLETED'));
  41. // Gather producer nodes, and their corresponding input data
  42. $rawnodes = node_load_multiple(FALSE, array('type' => 'migrate_example_producer'), TRUE);
  43. // Index by title
  44. $producer_nodes = array();
  45. foreach ($rawnodes as $node) {
  46. $producer_nodes[$node->title] = $node;
  47. }
  48. $this->assertEqual(count($producer_nodes), 1,
  49. t('Counts of producer nodes and input rows match'));
  50. // Test each base node field
  51. $producer_node = $producer_nodes['Lolonis Winery'];
  52. $user_migration = MigrationBase::getInstance('WineUser');
  53. $mapped_uid = $user_migration->getMap()->lookupDestinationID(array(3));
  54. if (is_array($mapped_uid)) {
  55. $this->assertEqual($producer_node->uid, reset($mapped_uid),
  56. t('uid properly migrated'));
  57. }
  58. else {
  59. $this->error(t('Account ID !id not migrated', array('!id' => 3)));
  60. }
  61. // Test Field API fields of all types
  62. // body_with_summary
  63. $body = field_get_items('node', $producer_node, 'body');
  64. $this->assertEqual($body[0]['value'], 'Makers of Ladybug Red',
  65. t('body properly migrated'));
  66. $region = field_get_items('node', $producer_node, 'migrate_example_wine_regions');
  67. $term = taxonomy_get_term_by_name('Redwood Valley');
  68. $term = reset($term);
  69. $this->assertEqual($region[0]['tid'], $term->tid,
  70. t('region properly migrated'));
  71. // Test rollback
  72. $result = $migration->processRollback();
  73. $this->assertEqual($result, Migration::RESULT_COMPLETED,
  74. t('Producer node rollback returned RESULT_COMPLETED'));
  75. $rawnodes = node_load_multiple(FALSE, array('type' => 'migrate_example_producer'), TRUE);
  76. $this->assertEqual(count($rawnodes), 0, t('All nodes deleted'));
  77. $count = db_select('migrate_map_wineproducerxml', 'map')
  78. ->fields('map', array('sourceid1'))
  79. ->countQuery()
  80. ->execute()
  81. ->fetchField();
  82. $this->assertEqual($count, 0, t('Map cleared'));
  83. $count = db_select('migrate_message_wineproducerxml', 'msg')
  84. ->fields('msg', array('sourceid1'))
  85. ->countQuery()
  86. ->execute()
  87. ->fetchField();
  88. $this->assertEqual($count, 0, t('Messages cleared'));
  89. }
  90. }