Newer
Older
Alex Barth
committed
<?php
/**
* @file
* Test case for CCK link mapper mappers/date.inc.
*/
Alex Barth
committed
/**
* Class for testing Feeds <em>link</em> mapper.
*/
class FeedsMapperLinkTestCase extends FeedsMapperTestCase {
public static function getInfo() {
return array(
Dave Reid
committed
'name' => 'Mapper: Link',
'description' => 'Test Feeds Mapper support for Link fields.',
'group' => 'Feeds',
'dependencies' => array('link'),
Alex Barth
committed
);
}
public function setUp() {
parent::setUp(array('link'));
Alex Barth
committed
}
/**
* Basic test loading a single entry CSV file.
*/
public function test() {
$static_title = $this->randomName();
// Create content type.
$typename = $this->createContentType(array(), array(
Alex Barth
committed
'alpha' => array(
'instance_settings' => array(
'instance[settings][title]' => 'required',
Alex Barth
committed
),
),
'beta' => array(
'instance_settings' => array(
'instance[settings][title]' => 'none',
Alex Barth
committed
),
),
'gamma' => array(
'instance_settings' => array(
'instance[settings][title]' => 'optional',
Alex Barth
committed
),
),
'omega' => array(
'instance_settings' => array(
'instance[settings][title]' => 'value',
'instance[settings][title_value]' => $static_title,
Alex Barth
committed
),
),
));
// Create importer configuration.
$this->createImporterConfiguration(); //Create a default importer configuration
$this->setSettings('syndication', 'FeedsNodeProcessor', array('bundle' => $typename)); //Processor settings
Alex Barth
committed
$this->addMappings('syndication', array(
niklas
committed
0 => array(
Alex Barth
committed
'source' => 'title',
'target' => 'title'
),
niklas
committed
1 => array(
Alex Barth
committed
'source' => 'timestamp',
'target' => 'created'
),
niklas
committed
2 => array(
Alex Barth
committed
'source' => 'description',
'target' => 'body'
),
niklas
committed
3 => array(
Alex Barth
committed
'source' => 'url',
'target' => 'field_alpha:url'
),
niklas
committed
4 => array(
Alex Barth
committed
'source' => 'title',
'target' => 'field_alpha:title'
),
niklas
committed
5 => array(
Alex Barth
committed
'source' => 'url',
'target' => 'field_beta:url'
),
niklas
committed
6 => array(
Alex Barth
committed
'source' => 'url',
'target' => 'field_gamma:url'
),
niklas
committed
7 => array(
Alex Barth
committed
'source' => 'title',
'target' => 'field_gamma:title'
),
niklas
committed
8 => array(
Alex Barth
committed
'source' => 'url',
'target' => 'field_omega:url'
),
));
// Import RSS file.
$nid = $this->createFeedNode();
// Assert 10 items aggregated after creation of the node.
$this->assertText('Created 10 nodes');
Alex Barth
committed
// Edit the imported node.
$this->drupalGet('node/2/edit');
$url = 'http://developmentseed.org/blog/2009/oct/06/open-atrium-translation-workflow-two-way-updating';
$title = 'Open Atrium Translation Workflow: Two Way Translation Updates';
$this->assertNodeFieldValue('alpha', array('url' => $url, 'static' => $title));
$this->assertNodeFieldValue('beta', array('url' => $url));
$this->assertNodeFieldValue('gamma', array('url' => $url, 'static' => $title));
$this->assertNodeFieldValue('omega', array('url' => $url, 'static' => $static_title));
Alex Barth
committed
// Test the static title.
$this->drupalGet('node/2');
$this->assertText($static_title, 'Static title link found.');
}
/**
* Override parent::getFormFieldsNames().
*/
protected function getFormFieldsNames($field_name, $index) {
if (in_array($field_name, array('alpha', 'beta', 'gamma', 'omega'))) {
$fields = array("field_{$field_name}[und][{$index}][url]");
Alex Barth
committed
if (in_array($field_name, array('alpha', 'gamma'))) {
$fields[] = "field_{$field_name}[und][{$index}][title]";
Alex Barth
committed
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
}
return $fields;
}
else {
return parent::getFormFieldsNames($field_name, $index);
}
}
/**
* Override parent::getFormFieldsValues().
*/
protected function getFormFieldsValues($field_name, $value) {
if (in_array($field_name, array('alpha', 'beta', 'gamma', 'omega'))) {
if (!is_array($value)) {
$value = array('url' => $value);
}
$values = array($value['url']);
if (in_array($field_name, array('alpha', 'gamma'))) {
$values[] = isset($value['title']) ? $value['title'] : '';
}
return $values;
}
else {
return parent::getFormFieldsValues($field_name, $index);
}
}
}