| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157 | 
							- <?php
 
- /**
 
-  * @file
 
-  * Tests for the comment destination plugin.
 
-  */
 
- /**
 
-  * Test comment migration.
 
-  */
 
- class MigrateCommentUnitTest extends DrupalWebTestCase {
 
-   public static function getInfo() {
 
-     return array(
 
-       'name' => 'Comment migration',
 
-       'description' => 'Test migration of comment data',
 
-       'group' => 'Migrate',
 
-     );
 
-   }
 
-   function setUp() {
 
-     parent::setUp('taxonomy', 'image', 'comment', 'migrate', 'migrate_example');
 
-   }
 
-   function testCommentImport() {
 
-     $migration = Migration::getInstance('WineVariety');
 
-     $result = $migration->processImport();
 
-     $this->assertEqual($result, Migration::RESULT_COMPLETED,
 
-       t('Variety term import returned RESULT_COMPLETED'));
 
-     $migration = Migration::getInstance('WineRegion');
 
-     $result = $migration->processImport();
 
-     $this->assertEqual($result, Migration::RESULT_COMPLETED,
 
-       t('Region term import returned RESULT_COMPLETED'));
 
-     $migration = Migration::getInstance('WineBestWith');
 
-     $result = $migration->processImport();
 
-     $this->assertEqual($result, Migration::RESULT_COMPLETED,
 
-       t('"Best With" term import returned RESULT_COMPLETED'));
 
-     $migration = Migration::getInstance('WineFileCopy');
 
-     $result = $migration->processImport();
 
-     $this->assertEqual($result, Migration::RESULT_COMPLETED,
 
-       t('File import returned RESULT_COMPLETED'));
 
-     $migration = Migration::getInstance('WineRole');
 
-     $result = $migration->processImport();
 
-     $this->assertEqual($result, Migration::RESULT_COMPLETED,
 
-       t('Role import returned RESULT_COMPLETED'));
 
-     $migration = Migration::getInstance('WineUser');
 
-     $result = $migration->processImport();
 
-     $this->assertEqual($result, Migration::RESULT_COMPLETED,
 
-       t('User import returned RESULT_COMPLETED'));
 
-     $migration = Migration::getInstance('WineProducer');
 
-     $result = $migration->processImport();
 
-     $this->assertEqual($result, Migration::RESULT_COMPLETED,
 
-       t('Producer node import returned RESULT_COMPLETED'));
 
-     $migration = Migration::getInstance('WineWine');
 
-     $result = $migration->processImport();
 
-     $this->assertEqual($result, Migration::RESULT_COMPLETED,
 
-       t('Wine node import returned RESULT_COMPLETED'));
 
-     $migration = Migration::getInstance('WineComment');
 
-     $result = $migration->processImport();
 
-     $this->assertEqual($result, Migration::RESULT_COMPLETED,
 
-       t('Comment import returned RESULT_COMPLETED'));
 
-     $result = db_select('migrate_message_winecomment', 'w')
 
-               ->fields('w', array('message'))
 
-               ->execute();
 
-     foreach ($result as $row) {
 
-       $this->error($row->message);
 
-     }
 
-     $result = db_select('migrate_example_wine_comment', 'wc')
 
-               ->fields('wc', array('commentid', 'comment_parent', 'name', 'mail',
 
-                 'accountid', 'body', 'wineid', 'subject', 'commenthost', 'userpage',
 
-                 'posted', 'lastchanged'))
 
-               ->orderBy('comment_parent')
 
-               ->execute();
 
-     $rawcomments = comment_load_multiple(FALSE);
 
-     // Index by subject
 
-     $comments = array();
 
-     foreach ($rawcomments as $comment) {
 
-       $comments[$comment->subject] = $comment;
 
-     }
 
-     $rows = array();
 
-     foreach ($result as $row) {
 
-       $rows[$row->subject] = $row;
 
-     }
 
-     if (!$this->assertEqual(count($comments), count($rows), t('Counts of comments and input rows match'))) {
 
-       $this->error(t('!comments comments, should be !rows',
 
-         array('!comments' => count($comments), '!rows' => count($rows))));
 
-     }
 
-     $comment = $comments['im second'];
 
-     $row = $rows['im second'];
 
-     $this->assertEqual($comment->mail, $row->mail, t('Mail matches'));
 
-     $this->assertEqual($comment->name, $row->name, t('Name matches'));
 
-     $this->assertEqual($comment->status, COMMENT_PUBLISHED, t('Status matches'));
 
-     $wine_migration = MigrationBase::getInstance('WineWine');
 
-     $destid = $wine_migration->getMap()->lookupDestinationID(array($row->wineid));
 
-     $this->assertEqual($comment->nid, reset($destid), t('Nid matches'));
 
-     $body = field_get_items('comment', $comment, 'comment_body');
 
-     $this->assertEqual($body[0]['value'], $row->body, t('Body matches'));
 
-     $this->assertEqual($comment->hostname, $row->commenthost, t('Hostname matches'));
 
-     $this->assertEqual($comment->homepage, $row->userpage, t('Homepage matches'));
 
-     $this->assertEqual($comment->created, $row->posted, t('Created matches'));
 
-     $this->assertEqual($comment->changed, $row->lastchanged, t('Changed matches'));
 
-     $comment = $comments['im child'];
 
-     $row = $rows['im child'];
 
-     $user_migration = MigrationBase::getInstance('WineUser');
 
-     $destid = $user_migration->getMap()->lookupDestinationID(array($row->accountid));
 
-     $this->assertEqual($comment->uid, reset($destid), t('Uid matches'));
 
-     $this->assertEqual($comment->pid, $comments['im parent']->cid, t('Parent matches'));
 
-     // Test updates
 
-     // Capture original comments
 
-     $original_comments = comment_load_multiple(FALSE);
 
-     $update_migration = Migration::getInstance('WineCommentUpdates');
 
-     $result = $update_migration->processImport();
 
-     $this->assertEqual($result, Migration::RESULT_COMPLETED,
 
-       t('Wine comment updates import returned RESULT_COMPLETED'));
 
-     $final_comments = comment_load_multiple(FALSE);
 
-     foreach ($original_comments as $cid => $original_comment) {
 
-       foreach ($original_comment as $field => $value) {
 
-         if ($field == 'subject') {
 
-           if ($value == $final_comments[$cid]->$field) {
 
-             $this->error(t('Field !field should have changed but did not, value=!value',
 
-               array('!field' => $field, '!value' => print_r($value, TRUE))));
 
-           }
 
-         }
 
-         else {
 
-           if ($value != $final_comments[$cid]->$field) {
 
-             $this->error(t('Field !field mismatch: original !value1, result !value2',
 
-               array('!field' => $field, '!value1' => print_r($value, TRUE),
 
-                 '!value2' => print_r($final_comments[$cid]->$field, TRUE))));
 
-           }
 
-         }
 
-       }
 
-     }
 
-     // Test rollback
 
-     $result = $migration->processRollback(array('force' => TRUE));
 
-     $this->assertEqual($result, Migration::RESULT_COMPLETED,
 
-       t('Comment rollback returned RESULT_COMPLETED'));
 
-     $rawcomments = comment_load_multiple(FALSE);
 
-     $this->assertEqual(count($rawcomments), 0, t('All comments deleted'));
 
-     $count = db_select('migrate_map_winecomment', 'map')
 
-               ->fields('map', array('sourceid1'))
 
-               ->countQuery()
 
-               ->execute()
 
-               ->fetchField();
 
-     $this->assertEqual($count, 0, t('Map cleared'));
 
-     $count = db_select('migrate_message_winecomment', 'msg')
 
-               ->fields('msg', array('sourceid1'))
 
-               ->countQuery()
 
-               ->execute()
 
-               ->fetchField();
 
-     $this->assertEqual($count, 0, t('Messages cleared'));
 
-   }
 
- }
 
 
  |