View source
<?php
require_once drupal_get_path('module', 'feeds') . '/tests/feeds_mapper_test.inc';
class FeedsMapperLinkTestCase extends FeedsMapperTestCase {
public static function getInfo() {
return array(
'name' => t('Mapper: Link'),
'description' => t('Test Feeds Mapper support for Link CCK fields. <strong>Requires CCK and Link module</strong>.'),
'group' => t('Feeds'),
);
}
public function setUp() {
parent::setUp('feeds', 'feeds_ui', 'ctools', 'job_scheduler', 'content', 'link');
$this
->drupalLogin($this
->drupalCreateUser(array(
'administer content types',
'administer feeds',
'administer nodes',
'administer site configuration',
)));
}
public function test() {
$static_title = $this
->randomName();
$typename = $this
->createContentType(NULL, array(
'alpha' => array(
'type' => 'link',
'settings' => array(
'title' => 'required',
'multiple' => '0',
),
),
'beta' => array(
'type' => 'link',
'settings' => array(
'title' => 'none',
'multiple' => '0',
),
),
'gamma' => array(
'type' => 'link',
'settings' => array(
'title' => 'optional',
'multiple' => '0',
),
),
'omega' => array(
'type' => 'link',
'settings' => array(
'title' => 'value',
'title_value' => $static_title,
'multiple' => '0',
),
),
));
$this
->createImporterConfiguration();
$this
->setSettings('syndication', 'FeedsNodeProcessor', array(
'content_type' => $typename,
));
$this
->addMappings('syndication', array(
array(
'source' => 'title',
'target' => 'title',
),
array(
'source' => 'timestamp',
'target' => 'created',
),
array(
'source' => 'description',
'target' => 'body',
),
array(
'source' => 'url',
'target' => 'field_alpha:url',
),
array(
'source' => 'title',
'target' => 'field_alpha:title',
),
array(
'source' => 'url',
'target' => 'field_beta:url',
),
array(
'source' => 'url',
'target' => 'field_gamma:url',
),
array(
'source' => 'title',
'target' => 'field_gamma:title',
),
array(
'source' => 'url',
'target' => 'field_omega:url',
),
));
$nid = $this
->createFeedNode();
$this
->assertText('Created 10 ' . $typename . ' nodes.');
$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
->assertCCKFieldValue('alpha', array(
'url' => $url,
'static' => $title,
));
$this
->assertCCKFieldValue('beta', array(
'url' => $url,
));
$this
->assertCCKFieldValue('gamma', array(
'url' => $url,
'static' => $title,
));
$this
->assertCCKFieldValue('omega', array(
'url' => $url,
'static' => $static_title,
));
$this
->drupalGet('node/2');
$this
->assertText($static_title, 'Static title link found.');
}
protected function getFormFieldsNames($field_name, $index) {
if (in_array($field_name, array(
'alpha',
'beta',
'gamma',
'omega',
))) {
$fields = array(
"field_{$field_name}[{$index}][url]",
);
if (in_array($field_name, array(
'alpha',
'gamma',
))) {
$fields[] = "field_{$field_name}[{$index}][title]";
}
return $fields;
}
else {
return parent::getFormFieldsNames($field_name, $index);
}
}
protected function getFormFieldsValues($field_name, $value) {
$field = content_fields($field_name);
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);
}
}
}