| [ Index ] |
PHP Cross Reference of Drupal 6 (yi-drupal) |
[Summary view] [Print] [Text view]
1 <?php 2 // $Id: migrate_ui.test,v 1.1.2.5 2009/09/18 15:25:09 mikeryan Exp $ 3 /** 4 * @file 5 * Tests for the Migrate UI. 6 * 7 * These are all the cases to be tested (TBD are cases not currently tested): 8 * 9 * Permissions 10 * Content sets: 11 * Valid content set 12 * Missing description 13 * Invalid weight 14 * Validate listing (TBD) 15 * Change primary key int->int, int->string, string->int, string->string (TBD) 16 * Weight change 17 * Source field present/none, default value present/empty (TBD) 18 * Delete (TBD) 19 * Dashboard page: 20 * Combos for clear/import/scan (TBD) 21 * Tools page: 22 * Delete node types (TBD) 23 * Settings page: 24 * Validate each setting, operation of refresh (TBD) 25 */ 26 27 /** 28 * UI tests for the Migrate module 29 * 30 */ 31 class MigrateFunctionalTest extends DrupalWebTestCase { 32 function getInfo() { 33 return array( 34 'name' => t('Migrate UI'), 35 'description' => t('Test Migrate user interface'), 36 'group' => t('Migrate'), 37 ); 38 } 39 40 function setUp() { 41 // Somehow, we're running in E_STRICT, and Views generates notices. 42 error_reporting(E_ALL & ~E_NOTICE); 43 parent::setUp('views', 'schema', 'tw', 'migrate'); 44 45 // Create and login user 46 $migrate_user = $this->drupalCreateUser(array('access administration pages', 47 MIGRATE_ACCESS_BASIC, MIGRATE_ACCESS_ADVANCED)); 48 $this->drupalLogin($migrate_user); 49 50 // Create test table 51 $ret = array(); 52 $schema = array( 53 'fields' => array( 54 'id' => array( 55 'type' => 'int', 56 'unsigned' => TRUE, 57 'not null' => TRUE, 58 ), 59 'title' => array( 60 'type' => 'varchar', 61 'length' => 255, 62 'not null' => TRUE, 63 ), 64 'body' => array( 65 'type' => 'varchar', 66 'length' => 255, 67 'not null' => TRUE, 68 ), 69 ), 70 'primary key' => array('id'), 71 ); 72 $this->tablename = 'migrate_simpletest_sample'; 73 db_create_table($ret, $this->tablename, $schema); 74 $sql = "INSERT INTO {" . $this->tablename . "} (id, title, body) VALUES(%d, '%s', '%s')"; 75 db_query($sql, 893, 'Title 1', 'This is a body'); 76 db_query($sql, 1027, 'Title 2', 'This is another body'); 77 db_query($sql, 653223, 'Title 3', 'This is yet another body'); 78 79 // Creates default view '$tablename' 80 tw_add_tables($this->tablename, TRUE); 81 } 82 83 function tearDown() { 84 parent::tearDown(); 85 } 86 87 /** 88 * Test UI for listing/creating/editing content sets 89 */ 90 function testContentSetsPages() { 91 // Create content set - missing description 92 $edit = array(); 93 $edit['contenttype'] = 'node/page'; 94 $edit['sourceview'] = $this->tablename; 95 $edit['weight'] = 5; 96 $this->drupalPost('admin/content/migrate/content_sets', $edit, t('Add')); 97 $this->assertText(t('A description is required.'), t('Post with no description')); 98 $edit['description'] = t('Simple page test'); 99 $this->drupalPost(NULL, $edit, t('Add')); 100 $mcsid = db_result(db_query("SELECT mcsid FROM {migrate_content_sets} WHERE view_name='%s'", 101 $this->tablename)); 102 if ($this->assertNotNull($mcsid, t('Create simple page content set'))) { 103 $path = parse_url($this->getUrl(), PHP_URL_PATH); 104 if ($this->assertEqual($path, "/admin/content/migrate/content_sets/$mcsid", 105 t('Redirected to content set edit page'))) { 106 $edit = array(); 107 $edit['weight'] = 'abc'; 108 $this->drupalPost(NULL, $edit, t('Submit changes')); 109 $this->assertText(t('Weight must be an integer value (positive or negative)'), 110 t('Non-numeric weight')); 111 $edit = array(); 112 $edit['weight'] = 5.8; 113 $this->drupalPost(NULL, $edit, t('Submit changes')); 114 $this->assertText(t('Weight must be an integer value (positive or negative)'), 115 t('Floating-point weight')); 116 $edit = array(); 117 $edit['weight'] = -3; 118 $this->drupalPost(NULL, $edit, t('Submit changes')); 119 $this->assertText(t('Changes saved'), t('Negative integer weight')); 120 121 // Add mappings to content set 122 $edit = array(); 123 $edit['srcfield[title]'] = $this->tablename . '_title'; 124 $edit['srcfield[body]'] = $this->tablename . '_body'; 125 $this->drupalPost(NULL, $edit, t('Submit changes')); 126 if ($this->assertText(t('Changes saved'), t('Create field mappings'))) { 127 $sql = "SELECT mcmid FROM {migrate_content_mappings} 128 WHERE mcsid=%d AND destfield='%s'"; 129 $mcmid = db_result(db_query($sql, $mcsid, 'title')); 130 if (!$this->assertTrue($mcmid, t('Title mapping saved'))) { 131 return; 132 } 133 $mcmid = db_result(db_query($sql, $mcsid, 'body')); 134 if (!$this->assertTrue($mcmid, t('Body mapping saved'))) { 135 return; 136 } 137 } 138 } 139 else { 140 $this->error(t('Post went to page !url, mcsid=!mcsid', 141 array('!url' => $path, '!mcsid' => $mcsid))); 142 } 143 } 144 } 145 146 /** 147 * Test UI for processing 148 */ 149 function testProcessPage() { 150 // Create content set 151 $edit = array(); 152 $edit['description'] = 'Node test'; 153 $edit['contenttype'] = 'node/page'; 154 $edit['sourceview'] = $this->tablename; 155 $edit['weight'] = 2; 156 $this->drupalPost('admin/content/migrate/content_sets', $edit, t('Add')); 157 $mcsid = db_result(db_query("SELECT mcsid FROM {migrate_content_sets} WHERE view_name='%s'", 158 $this->tablename)); 159 if ($this->assertNotNull($mcsid, t('Create simple page content set'))) { 160 $path = parse_url($this->getUrl(), PHP_URL_PATH); 161 if ($this->assertEqual($path, "/admin/content/migrate/content_sets/$mcsid", 162 t('Redirected to content set edit page'))) { 163 // Add mappings to content set 164 $edit = array(); 165 $edit['srcfield[title]'] = $this->tablename . '_title'; 166 $edit['srcfield[body]'] = $this->tablename . '_body'; 167 $this->drupalPost(NULL, $edit, t('Submit changes')); 168 if ($this->assertText(t('Changes saved'), t('Create field mappings'))) { 169 $sql = "SELECT mcmid FROM {migrate_content_mappings} 170 WHERE mcsid=%d AND destfield='%s'"; 171 $mcmid = db_result(db_query($sql, $mcsid, 'title')); 172 if (!$this->assertTrue($mcmid, t('Title mapping saved'))) { 173 return; 174 } 175 $mcmid = db_result(db_query($sql, $mcsid, 'body')); 176 if (!$this->assertTrue($mcmid, t('Body mapping saved'))) { 177 return; 178 } 179 $edit = array(); 180 $edit["importing[$mcsid]"] = $mcsid; 181 $this->drupalPost('admin/content/migrate/process', $edit, t('Submit')); 182 if (!$this->assertText('3 items imported in', t('Migration completed successfully'))) { 183 $result = preg_match('|<div class="messages status">(.*?)</div>|si', 184 $this->content, $matches); 185 $this->error('Actual messages: ' . $matches[1]); 186 return; 187 } 188 189 $node = node_load(array('title' => 'Title 1')); 190 if (!$this->assertEqual($node->body, 'This is a body', t('Validate first node'))) { 191 $this->error('Actual node: '.print_r($node, TRUE)); 192 } 193 $node = node_load(array('title' => 'Title 2')); 194 if (!$this->assertEqual($node->body, 'This is another body', t('Validate second node'))) { 195 $this->error('Actual node: '.print_r($node, TRUE)); 196 } 197 $node = node_load(array('title' => 'Title 3')); 198 if (!$this->assertEqual($node->body, 'This is yet another body', t('Validate third node'))) { 199 $this->error('Actual node: '.print_r($node, TRUE)); 200 } 201 } 202 } 203 else { 204 $this->error(t('Post went to page !url', array('!url' => $path))); 205 } 206 } 207 } 208 209 /** 210 * Test UI for tools 211 */ 212 function testToolsPage() { 213 } 214 215 /** 216 * Test UI for settings 217 */ 218 function testSettingsPage() { 219 } 220 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Mon Jul 9 18:01:44 2012 | Cross-referenced by PHPXref 0.7 |