public function FeedsMapperLinkTestCase::testClearOutValues in Feeds 7.2
Tests if values are cleared out when an empty value or no value is provided.
File
- tests/
feeds_mapper_link.test, line 149 - Contains FeedsMapperLinkTestCase.
Class
- FeedsMapperLinkTestCase
- Test case for CCK link mapper mappers/date.inc.
Code
public function testClearOutValues() {
// Create and configure importer.
$this
->createImporterConfiguration('Content CSV', 'csv');
$this
->setSettings('csv', NULL, array(
'content_type' => '',
'import_period' => FEEDS_SCHEDULE_NEVER,
));
$this
->setPlugin('csv', 'FeedsFileFetcher');
$this
->setPlugin('csv', 'FeedsCSVParser');
$this
->setSettings('csv', 'FeedsNodeProcessor', array(
'bundle' => $this->contentType,
'update_existing' => 1,
));
$this
->addMappings('csv', array(
0 => array(
'source' => 'guid',
'target' => 'guid',
'unique' => TRUE,
),
1 => array(
'source' => 'title',
'target' => 'title',
),
2 => array(
'source' => 'url',
'target' => 'field_alpha:url',
),
3 => array(
'source' => 'link_title',
'target' => 'field_alpha:title',
),
4 => array(
'source' => 'url',
'target' => 'field_beta:url',
),
5 => array(
'source' => 'link_title',
'target' => 'field_beta:title',
),
6 => array(
'source' => 'url',
'target' => 'field_gamma:url',
),
7 => array(
'source' => 'link_title',
'target' => 'field_gamma:title',
),
8 => array(
'source' => 'url',
'target' => 'field_omega:url',
),
9 => array(
'source' => 'link_title',
'target' => 'field_omega:title',
),
));
// Import CSV file.
$this
->importFile('csv', $this
->absolutePath() . '/tests/feeds/content_link.csv');
$this
->assertText('Created 2 nodes');
// Check the imported nodes.
$link_values = array(
1 => array(
'title' => 'Feeds',
'url' => 'https://www.drupal.org/project/feeds',
),
2 => array(
'title' => 'Framework for expected behavior when importing empty/blank values',
'url' => 'https://www.drupal.org/node/1107522',
),
);
for ($i = 1; $i <= 2; $i++) {
$this
->drupalGet("node/{$i}/edit");
$this
->assertNodeFieldValue('alpha', array(
'url' => $link_values[$i]['url'],
'title' => $link_values[$i]['title'],
));
$this
->assertNodeFieldValue('beta', array(
'url' => $link_values[$i]['url'],
));
$this
->assertNodeFieldValue('gamma', array(
'url' => $link_values[$i]['url'],
'title' => $link_values[$i]['title'],
));
$this
->assertNodeFieldValue('omega', array(
'url' => $link_values[$i]['url'],
));
// Test static title.
$this
->drupalGet("node/{$i}");
$this
->assertText($this->staticTitle, 'Static title link found.');
}
// Import CSV file with empty values.
$this
->importFile('csv', $this
->absolutePath() . '/tests/feeds/content_empty.csv');
$this
->assertText('Updated 2 nodes');
// Check if all values were cleared out for both nodes.
for ($i = 1; $i <= 2; $i++) {
$this
->drupalGet("node/{$i}/edit");
$this
->assertNoNodeFieldValue('alpha', array(
'url' => $link_values[$i]['url'],
'title' => $link_values[$i]['title'],
));
$this
->assertNoNodeFieldValue('beta', array(
'url' => $link_values[$i]['url'],
));
$this
->assertNoNodeFieldValue('gamma', array(
'url' => $link_values[$i]['url'],
'title' => $link_values[$i]['title'],
));
$this
->assertNoNodeFieldValue('omega', array(
'url' => $link_values[$i]['url'],
));
// Check labels.
$this
->drupalGet('node/' . $i);
$this
->assertNoText('alpha_link_field_label');
$this
->assertNoText('beta_link_field_label');
$this
->assertNoText('gamma_link_field_label');
$this
->assertNoText('omega_link_field_label');
// Assert that the static title is no longer shown.
$this
->assertNoText($this->staticTitle, 'Static title link not found.');
}
// Re-import the first file again and check if the values returned.
$this
->importFile('csv', $this
->absolutePath() . '/tests/feeds/content_link.csv');
$this
->assertText('Updated 2 nodes');
for ($i = 1; $i <= 2; $i++) {
$this
->drupalGet("node/{$i}/edit");
$this
->assertNodeFieldValue('alpha', array(
'url' => $link_values[$i]['url'],
'title' => $link_values[$i]['title'],
));
$this
->assertNodeFieldValue('beta', array(
'url' => $link_values[$i]['url'],
));
$this
->assertNodeFieldValue('gamma', array(
'url' => $link_values[$i]['url'],
'title' => $link_values[$i]['title'],
));
$this
->assertNodeFieldValue('omega', array(
'url' => $link_values[$i]['url'],
));
}
// Import CSV file with non-existent values.
$this
->importFile('csv', $this
->absolutePath() . '/tests/feeds/content_non_existent.csv');
$this
->assertText('Updated 2 nodes');
// Check if all values were cleared out for node 1.
$this
->drupalGet("node/1/edit");
$this
->assertNoNodeFieldValue('alpha', array(
'url' => $link_values[1]['url'],
'title' => $link_values[1]['title'],
));
$this
->assertNoNodeFieldValue('beta', array(
'url' => $link_values[1]['url'],
));
$this
->assertNoNodeFieldValue('gamma', array(
'url' => $link_values[1]['url'],
'title' => $link_values[1]['title'],
));
$this
->assertNoNodeFieldValue('omega', array(
'url' => $link_values[1]['url'],
));
$this
->drupalGet('node/1');
$this
->assertNoText('alpha_link_field_label');
$this
->assertNoText('beta_link_field_label');
$this
->assertNoText('gamma_link_field_label');
$this
->assertNoText('omega_link_field_label');
// Assert that the static title is no longer shown.
$this
->assertNoText($this->staticTitle, 'Static title link not found.');
}