function MigrateFunctionalTest::testProcessPage in Migrate 6
Test UI for processing
File
- tests/
migrate_ui.test, line 150 - Tests for the Migrate UI.
Class
- MigrateFunctionalTest
- UI tests for the Migrate module
Code
function testProcessPage() {
// Create content set
$edit = array();
$edit['machine_name'] = 'node_test';
$edit['description'] = 'Node test';
$edit['contenttype'] = 'node/page';
$edit['view_name'] = $this->tablename;
$edit['weight'] = 2;
$this
->drupalPost('admin/content/migrate', $edit, t('Add'));
$mcsid = db_result(db_query("SELECT mcsid FROM {migrate_content_sets} WHERE view_name='%s'", $this->tablename));
if ($this
->assertNotNull($mcsid, t('Create simple page content set'))) {
$path = parse_url($this
->getUrl(), PHP_URL_PATH);
if ($this
->assertEqual($path, "/admin/content/migrate/content_set/{$mcsid}", t('Redirected to content set edit page'))) {
// Add mappings to content set
$edit = array();
$edit['srcfield[title]'] = $this->tablename . '_title';
$edit['srcfield[body]'] = $this->tablename . '_body';
$this
->drupalPost(NULL, $edit, t('Submit changes'));
if ($this
->assertText(t('Changes saved'), t('Create field mappings'))) {
$sql = "SELECT mcmid FROM {migrate_content_mappings}\n WHERE mcsid=%d AND destfield='%s'";
$mcmid = db_result(db_query($sql, $mcsid, 'title'));
if (!$this
->assertTrue($mcmid, t('Title mapping saved'))) {
return;
}
$mcmid = db_result(db_query($sql, $mcsid, 'body'));
if (!$this
->assertTrue($mcmid, t('Body mapping saved'))) {
return;
}
$edit = array();
$edit["importing[{$mcsid}]"] = $mcsid;
$this
->drupalPost('admin/content/migrate', $edit, t('Run'));
if (!$this
->assertText('Imported 3 in', t('Migration completed successfully'))) {
$result = preg_match('|<div class="messages status">(.*?)</div>|si', $this->content, $matches);
$this
->error('Actual messages: ' . $matches[1]);
return;
}
$node = node_load(array(
'title' => 'Title 1',
));
if (!$this
->assertEqual($node->body, 'This is a body', t('Validate first node'))) {
$this
->error('Actual node: ' . print_r($node, TRUE));
}
$node = node_load(array(
'title' => 'Title 2',
));
if (!$this
->assertEqual($node->body, 'This is another body', t('Validate second node'))) {
$this
->error('Actual node: ' . print_r($node, TRUE));
}
$node = node_load(array(
'title' => 'Title 3',
));
if (!$this
->assertEqual($node->body, 'This is yet another body', t('Validate third node'))) {
$this
->error('Actual node: ' . print_r($node, TRUE));
}
}
}
else {
$this
->error(t('Post went to page !url', array(
'!url' => $path,
)));
}
}
}