oracle.test 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. <?php
  2. /**
  3. * @file
  4. * Tests for the Oracle source plugin.
  5. */
  6. /**
  7. * Test migration from Oracle.
  8. *
  9. * NOTE: Test won't run correctly due to http://drupal.org/node/362373, enable
  10. * when that is fixed.
  11. */
  12. class MigrateOracleUnitTest extends DrupalWebTestCase {
  13. public static function getInfo() {
  14. return array(
  15. 'name' => 'Oracle migration',
  16. 'description' => 'Test migration from an Oracle source',
  17. 'group' => 'Migrate',
  18. );
  19. }
  20. function setUp() {
  21. global $conf;
  22. if (empty($conf['oracle_db']) || empty($conf['oracle_db']['username']) ||
  23. empty($conf['oracle_db']['password']) || empty($conf['oracle_db']['connection_string'])) {
  24. parent::setUp();
  25. }
  26. else {
  27. parent::setUp('features', 'migrate', 'migrate_example_oracle');
  28. }
  29. }
  30. function testOracleImport() {
  31. global $conf;
  32. if (empty($conf['oracle_db'])) {
  33. $this->pass(t('To run the Oracle test, you need to defined $conf[\'oracle_db\']
  34. in settings.php - see migrate_example_oracle.migrate.inc.'));
  35. }
  36. $migration = Migration::getInstance('MigrateExampleOracle');
  37. $result = $migration->processImport();
  38. $this->assertEqual($result, Migration::RESULT_COMPLETED,
  39. t('Region term import returned RESULT_COMPLETED'));
  40. // Gather destination nodes, and their corresponding input data
  41. $rawnodes = node_load_multiple(FALSE, array('type' => 'migrate_example_oracle'), TRUE);
  42. $data = migrate_example_oracle_sample_data();
  43. $this->assertEqual(count($rawnodes), count($data), t('Counts of nodes and input rows match'));
  44. // Index nodes by title
  45. $nodes = array();
  46. foreach ($rawnodes as $node) {
  47. $nodes[$node->title] = $node;
  48. }
  49. // Test each value
  50. foreach ($data as $row) {
  51. $node = $nodes[$row['title']];
  52. if (!$this->assertEqual($node->title, $row['title'], 'Titles match')) {
  53. $this->error(t('Source title !source does not match node title !destination',
  54. array('!source' => $row['title'], '!destination' => $node->title)));
  55. }
  56. if (!$this->assertEqual($node->body[LANGUAGE_NONE][0]['value'], $row['body'], 'Bodies match')) {
  57. $this->error(t('Source body !source does not match node body !destination',
  58. array('!source' => $row['body'], '!destination' => $node->body)));
  59. }
  60. $created = format_date($node->created, 'custom', 'Y/m/d H:i:s');
  61. if (!$this->assertEqual($created, $row['created'], 'Created timestamps match')) {
  62. $this->error(t('Source created !source does not match node created !destination',
  63. array('!source' => $row['created'], '!destination' => $created)));
  64. }
  65. $updated = format_date($node->changed, 'custom', 'Y/m/d H:i:s');
  66. if (!$this->assertEqual($updated, $row['updated'], 'Updated timestamps match')) {
  67. $this->error(t('Source updated !source does not match node changed !destination',
  68. array('!source' => $row['updated'], '!destination' => $updated)));
  69. }
  70. }
  71. // Test rollback
  72. $result = $migration->processRollback();
  73. $this->assertEqual($result, Migration::RESULT_COMPLETED,
  74. t('Node rollback returned RESULT_COMPLETED'));
  75. $rawnodes = node_load_multiple(FALSE, array('type' => 'migrate_example_oracle'), TRUE);
  76. $this->assertEqual(count($rawnodes), 0, t('All nodes deleted'));
  77. $count = db_select('migrate_map_migrateexampleoracle', '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_migrateexampleoracle', 'msg')
  84. ->fields('msg', array('sourceid1'))
  85. ->countQuery()
  86. ->execute()
  87. ->fetchField();
  88. $this->assertEqual($count, 0, t('Messages cleared'));
  89. }
  90. }