View source
<?php
require_once drupal_get_path('module', 'node_import') . '/tests/NodeImportTestCase.php';
class NodeImportNode extends NodeImportTestCase {
public static function getInfo() {
return array(
'name' => 'Node',
'description' => 'Test import of basic nodes (Title, Body, Input format, Authored on, Authored by, Publishing options).',
'group' => 'Node import',
);
}
public function setUp() {
parent::setUp('node');
}
public function tearDown() {
parent::tearDown();
}
public function testBasicNode() {
$type = $this
->drupalCreateContentType(array(
'title_label' => $this
->randomName() . ' (title)',
'body_label' => $this
->randomName() . ' (body)',
'min_word_count' => 1,
));
$perms = array(
'create ' . $type->name . ' content',
);
$admin = $this
->nodeImportCreateUser($perms);
$admin_role = array_pop(array_diff(array_keys($admin->roles), array(
DRUPAL_ANONYMOUS_RID,
DRUPAL_AUTHENTICATED_RID,
)));
$filter_admin = $this
->drupalCreateUser(array(
'administer filters',
));
$this
->drupalLogin($filter_admin);
$filter_allow = array(
'name' => 'filter admin role (' . $admin_role . ') can use',
);
$filter_deny = array(
'name' => 'filter admin role (' . $admin_role . ') can not use',
);
$filter_default = array(
'format' => variable_get('filter_default_format', 1),
);
foreach (user_roles() as $rid => $role) {
$filter_allow["roles[{$rid}]"] = $rid == $admin_role;
$filter_deny["roles[{$rid}]"] = FALSE;
}
$this
->drupalPost('admin/settings/filters/add', $filter_allow, t('Save configuration'));
$this
->drupalPost('admin/settings/filters/add', $filter_deny, t('Save configuration'));
$result = db_query("SELECT format, name FROM {filter_formats}");
while ($filter = db_fetch_object($result)) {
if ($filter->name == $filter_allow['name']) {
$filter_allow['format'] = $filter->format;
}
if ($filter->name == $filter_deny['name']) {
$filter_deny['format'] = $filter->format;
}
if ($filter->format == variable_get('filter_default_format', 1)) {
$filter_default['name'] = $filter->name;
}
}
$this
->drupalLogout();
$data = array(
array(
$type->title_label,
$type->body_label,
'format',
),
array(
$this
->randomName(),
$this
->randomName(),
'',
),
array(
'',
$this
->randomName(),
'',
),
array(
$this
->randomName(),
'',
'',
),
array(
$this
->randomName(),
$this
->randomName(),
$filter_default['name'],
),
array(
$this
->randomName(),
$this
->randomName(),
$filter_default['format'],
),
array(
$this
->randomName(),
$this
->randomName(),
$filter_allow['name'],
),
array(
$this
->randomName(),
$this
->randomName(),
$filter_allow['format'],
),
array(
$this
->randomName(),
$this
->randomName(),
$filter_deny['name'],
),
array(
$this
->randomName(),
$this
->randomName(),
$filter_deny['format'],
),
);
$path = $this
->nodeImportCreateFile($data);
$edit = array(
'type' => "node:" . $type->name,
'file' => $path,
);
$this
->drupalLogin($admin);
$taskid = $this
->nodeImportCreateTask($edit);
if ($taskid === FALSE) {
return;
}
$this
->nodeImportDoAllTasks();
$results = db_query("SELECT * FROM {node_import_status} WHERE taskid = %d", $taskid);
$i = 0;
while ($result = db_fetch_array($results)) {
$i++;
$result['errors'] = unserialize($result['errors']);
$node = NULL;
if ($result['status'] == NODE_IMPORT_STATUS_DONE) {
$node = node_load($result['objid']);
}
switch ($i) {
case 1:
$this
->assertRowStatusDONE($result);
$this
->assertNotNull($node, t('Node exists (nid: %nid).', array(
'%nid' => $result['objid'],
)), 'Node import');
$this
->assertEqual($node->title, $data[$i][0], t('Title correctly set.'), 'Node import');
$this
->assertEqual($node->body, $data[$i][1], t('Body correctly set.'), 'Node import');
$this
->assertEqual($node->format, variable_get('filter_default_format', 1), t('Input format correctly set.'), 'Node import');
break;
case 2:
$this
->assertRowStatusERROR($result);
$this
->assertRowErrorContains($result, t('!name field is required.', array(
'!name' => $data[0][0],
)), t('Error on empty title.'));
break;
case 3:
$this
->assertRowStatusERROR($result);
$this
->assertRowErrorContains($result, t('!name field is required.', array(
'!name' => $data[0][1],
)), t('Error on empty body.'));
break;
case 4:
case 5:
$this
->assertRowStatusDONE($result);
$this
->assertNotNull($node, t('Node exists (nid: %nid).', array(
'%nid' => $result['objid'],
)), 'Node import');
$this
->assertEqual($node->title, $data[$i][0], t('Title correctly set.'), 'Node import');
$this
->assertEqual($node->body, $data[$i][1], t('Body correctly set.'), 'Node import');
$this
->assertEqual($node->format, $filter_default['format'], t('Input format correctly set.'), 'Node import');
break;
case 6:
case 7:
$this
->assertRowStatusDONE($result);
$this
->assertNotNull($node, t('Node exists (nid: %nid).', array(
'%nid' => $result['objid'],
)), 'Node import');
$this
->assertEqual($node->title, $data[$i][0], t('Title correctly set.'), 'Node import');
$this
->assertEqual($node->body, $data[$i][1], t('Body correctly set.'), 'Node import');
$this
->assertEqual($node->format, $filter_allow['format'], t('Input format correctly set.'), 'Node import');
break;
case 8:
$this
->assertRowStatusERROR($result);
$this
->assertRowErrorContains($result, t('Input error: %value is not allowed for %name (not in allowed values list).', array(
'%value' => $filter_deny['name'],
'%name' => t('Input format'),
)), t('Error on non-existing filter.'));
break;
case 9:
$this
->assertRowStatusERROR($result);
$this
->assertRowErrorContains($result, t('Input error: %value is not allowed for %name (not in allowed values list).', array(
'%value' => $filter_deny['format'],
'%name' => t('Input format'),
)), t('Error on non-existing filter.'));
break;
}
}
$this
->assertTrue($i == 9, t('Correct number of rows (%d) were imported.', array(
'%d' => $i,
)), 'Node import');
}
}