View source
<?php
require_once drupal_get_path('module', 'feeds') . '/tests/feeds_mapper_test.inc';
class ParserIcalFeedsTestCase extends FeedsMapperTestCase {
public function absolutePath() {
return $this
->absolute() . '/' . drupal_get_path('module', 'parser_ical');
}
public function setUp() {
$modules = array_merge(array(
'feeds',
'feeds_ui',
'ctools',
'content',
'date_api',
'date',
'parser_ical',
), func_get_args());
if (version_compare(PHP_VERSION, '5.3.0') >= 0) {
call_user_func_array('parent::setUp', $modules);
}
else {
call_user_func_array(array(
'parent',
'setUp',
), $modules);
}
variable_set('date_default_timezone_name', 'Pacific/Apia');
variable_set('date_format_short', 'Y-m-d H:i');
$this
->drupalLogin($this
->drupalCreateUser(array(
'administer content types',
'administer feeds',
'administer nodes',
'administer site configuration',
)));
}
public function createConfiguredFeed($fields = array()) {
$fields = array_merge($fields, array(
'datefield' => array(
'type' => 'date',
'settings' => array(
'todate' => 'optional',
'tz_handling' => 'date',
),
),
'datesite' => array(
'type' => 'date',
'settings' => array(
'todate' => 'optional',
'tz_handling' => 'site',
),
),
));
$typename = $this
->createContentType(NULL, $fields);
$this
->createFeedConfiguration('iCal Feed', 'ical');
$this
->setSettings('ical', NULL, array(
'content_type' => '',
'import_period' => FEEDS_SCHEDULE_NEVER,
));
$this
->setPlugin('ical', 'FeedsFileFetcher');
$this
->setPlugin('ical', 'ParserIcalFeedsParser');
$this
->setSettings('ical', 'FeedsNodeProcessor', array(
'content_type' => $typename,
'update_existing' => 1,
));
$this
->addMappings('ical', array(
array(
'source' => 'title',
'target' => 'title',
),
array(
'source' => 'description',
'target' => 'body',
),
array(
'source' => 'ical_date',
'target' => 'field_datefield:start',
),
array(
'source' => 'ical_date',
'target' => 'field_datesite:start',
),
array(
'source' => 'guid',
'target' => 'guid',
'unique' => '1',
),
));
return $typename;
}
protected function assertCCKFieldValue2($field_name, $value) {
$xpath = '//input[@name="field_' . $field_name . '[0][value2][date]"]';
$message = t('Found form %field_name with the expected value.', array(
'%field_name' => $field_name,
));
$this
->assertFieldByXPath($xpath, $value, $message);
}
protected function assertCCKFieldTimezone($field_name, $value) {
$xpath = '//select[@name="field_' . $field_name . '[0][timezone][timezone]"]';
$message = t('Found form %field_name timezone with the expected value.', array(
'%field_name' => $field_name,
));
$this
->assertFieldByXPath($xpath, $value, $message);
}
protected function getFormFieldsNames($field_name, $index) {
if (in_array($field_name, array(
'date',
'datetime',
'datestamp',
'datefield',
'datesite',
))) {
return array(
"field_{$field_name}[{$index}][value][date]",
);
}
else {
return parent::getFormFieldsNames($field_name, $index);
}
}
}
class ParserIcalFeedsDateTestCase extends ParserIcalFeedsTestCase {
public static function getInfo() {
return array(
'name' => t('Basic feeds integration'),
'description' => t('Test Feeds iCal parser support and date mapping. <strong>Requires Feeds and Date module.</strong>'),
'group' => t('iCal Parser'),
);
}
public function testBasicFeed() {
$typename = $this
->createConfiguredFeed();
$this
->importFile('ical', $this
->absolutePath() . '/tests/feeds/Basic.ics');
$this
->assertText('Created 7 ' . $typename . ' nodes.');
$data = array(
array(
'title' => 'Simple start and end',
'field' => '2009-01-31 19:30',
'site' => '2009-01-31 19:30',
'field2' => '2009-01-31 20:30',
'site2' => '2009-01-31 20:30',
'timezone' => 'Pacific/Apia',
),
array(
'title' => 'Different start and end',
'field' => '2009-01-01 19:00',
'site' => '2009-01-01 07:00',
'field2' => '2009-01-01 20:00',
'site2' => '2009-01-01 08:00',
'timezone' => 'Europe/Paris',
),
array(
'title' => 'No timezone this time',
'field' => '2009-09-01 19:00',
'site' => '2009-09-01 19:00',
'field2' => '2009-09-01 20:00',
'site2' => '2009-09-01 20:00',
'timezone' => 'Pacific/Apia',
),
array(
'title' => 'UTC demarked with Z, over midnight.',
'field' => '2009-09-30 19:00',
'site' => '2009-09-30 08:00',
'field2' => '2009-10-01 20:00',
'site2' => '2009-10-01 09:00',
'timezone' => 'UTC',
),
);
for ($i = 1; $i <= count($data); $i++) {
$this
->drupalGet("node/{$i}/edit");
$this
->pass('Checking : ' . $d['title']);
$this
->assertNodeFieldValue('datefield', $d['field']);
$this
->assertCCKFieldValue('datesite', $d['site']);
$this
->assertCCKFieldValue2('datefield', $d['field2']);
$this
->assertCCKFieldValue2('datesite', $d['site2']);
$this
->assertCCKFieldTimezone('datefield', $d['timezone']);
}
$this
->importFile('ical', $this
->absolutePath() . '/tests/feeds/Basic1.ics');
$this
->assertText('Updated 1 ' . $typename . ' node.');
}
}
class ParserIcalFeedsLocationTestCase extends ParserIcalFeedsTestCase {
public function setUp() {
parent::setup('text');
}
public static function getInfo() {
return array(
'name' => t('Location'),
'description' => t('Location parsing and mapping. <strong>Requires Feeds, Date, CCK Text (and in the future geo) module.</strong>'),
'group' => t('iCal Parser'),
);
}
public function createConfiguredFeed() {
$typename = parent::createConfiguredFeed(array(
'location' => array(
'type' => 'text',
),
));
$this
->addMappings('ical', array(
array(
'source' => 'ical_location',
'target' => 'field_location',
),
));
return $typename;
}
public function testLocationFeed() {
$typename = $this
->createConfiguredFeed();
$this
->importFile('ical', $this
->absolutePath() . '/tests/feeds/Location.ics');
$this
->assertText('Created 3 ' . $typename . ' nodes.');
$data = array(
array(
'title' => 'Basic location',
'location' => 'Text location',
),
);
for ($i = 1; $i <= count($data); $i++) {
$this
->drupalGet("node/{$i}/edit");
$this
->assertNodeFieldValue('location', $d['location']);
}
}
}