Commit 36860ab8 authored by Robert Rollins's avatar Robert Rollins

Issue [#2082699]: The test code doesn't work, so I took it out.

parent cef545e0
<?php
/**
* @file
* Test case for CCK ical date field text mapper.
*/
/**
* Class for testing Feeds <em>content</em> mapper.
*/
class DateIcalFeedsParserTestCase extends FeedsMapperTestCase {
public function absolutePath() {
return $this->absolute() . '/' . drupal_get_path('module', 'date_ical');
}
/**
* Set up the test.
*/
public function setUp() {
$modules = func_get_args();
if (!empty($modules[0]) && is_array($modules[0])) {
$modules = $modules[0];
}
$modules[] = 'date_ical';
parent::setUp($modules);
// site date settings : consistent site timezone to against
variable_set('date_default_timezone', 'Pacific/Apia');
// and just because I'll make mistakes working with tests with the US date format
variable_set('date_format_short', 'Y-m-d H:i');
}
}
<?php
/**
* @file
* Test case for CCK ical categories mapper.
*/
/**
* Common class for testing ical parsers categories mapping.
*/
abstract class DateIcalFeedsParserCategoriesTestCase extends DateIcalFeedsParserTestCase {
/**
* Additional set up.
*/
function setUp() {
parent::setUp();
// Add a new taxonomy vocabulay.
$edit = array(
'name' => 'Tags',
'machine_name' => 'tags',
);
$this->drupalPost('admin/structure/taxonomy/add', $edit, 'Save');
}
/**
* Categories test on simple ical file.
*/
function test() {
// create content type with taxonomy field attached.
$typename = $this->createContentType(array(), array(
'alpha' => array(
'type' => 'taxonomy_term_reference',
'widget' => 'taxonomy_autocomplete',
'settings' => array(
'field[settings][allowed_values][0][vocabulary]' => 'tags',
),
),
));
// There's a quirk in taxonomy; fieldwide setting for
// ordinality is just on the content type page
$edit = array('field[cardinality]' => '-1');
$this->drupalPost("admin/structure/types/manage/$typename/fields/field_alpha", $edit, 'Save settings');
$this->assertText('Saved alpha_taxonomy_term_reference_label configuration.');
$this->createImporterConfiguration('iCal importer', 'ical');
$this->setSettings('ical', NULL, array('content_type' => '', 'import_period' => FEEDS_SCHEDULE_NEVER));
$this->setPlugin('ical', 'FeedsFileFetcher');
$this->setSettings('ical', 'FeedsFileFetcher', array('allowed_extensions' => 'ics ical'));
$this->configureParser();
$this->setSettings('ical', 'FeedsNodeProcessor', array('content_type' => $typename));
$this->addMappings('ical', array(
array(
'source' => 'summary',
'target' => 'title',
),
array(
'source' => 'description',
'target' => 'body',
),
array(
'source' => 'categories',
'target' => 'field_alpha',
),
));
// Import iCal file
$this->importFile('ical', $this->absolutePath() . '/tests/feeds/categories.ics');
$this->assertText('Created 3 nodes');
$this->drupalGet('node/1/edit');
$this->assertFieldByName('field_alpha[und]', 'General, Athletics, QC Junior High School, QC Senior High School, Volleyball', 'Feed item 1 categories correct.');
$this->drupalGet('node/2/edit');
$this->assertFieldByName('field_alpha[und]', 'Office Hours', 'Feed item 2 categories correct.');
$this->drupalGet('node/3/edit');
$this->assertFieldByName('field_alpha[und]', '', 'Feed item 3 categories correct.');
}
/**
* Set and configure the parser plugin.
*/
abstract function configureParser();
}
/**
* Class for testing iCal (date api) categories mapping.
*
class DateIcalDateModuleCategoriesCase extends DateIcalFeedsParserCategoriesTestCase {
public static function getInfo() {
return array(
'name' => 'Categories (date api)',
'description' => 'Test categories import support.',
'group' => 'Parser iCal',
);
}
public function configureParser() {
$this->setPlugin('ical', 'DateIcalDateModuleParser');
}
}
*/
/**
* Class for testing iCal (iCalCreator) categories mapping.
*/
class DateIcalIcalcreatorCategoriesCase extends DateIcalFeedsParserCategoriesTestCase {
public static function getInfo() {
return array(
'name' => 'Categories (iCalCreator)',
'description' => 'Test categories import support.',
'group' => 'Parser iCal',
);
}
public function configureParser() {
$this->setPlugin('ical', 'DateIcalIcalcreatorParser');
}
}
<?php
/**
* @file
* Test case for CCK ical date field text mapper.
*/
/**
* Class for testing Feeds <em>content</em> mapper.
*/
abstract class DateIcalFeedsParserDateTestCase extends DateIcalFeedsParserTestCase {
/**
* Basic test.
*
* Covers: mapping onto different types of date field;
* Start and End dates;
* All day events; single and multiple day.
*/
function testBasic() {
// Create content type for feed items.
$fields = array(
'pidt_date' => array(
'type' => 'date',
'settings' => array(
'field[settings][enddate_get]' => 1,
),
),
'pidt_datetime' => array(
'type' => 'datetime',
'settings' => array(
'field[settings][enddate_get]' => 1,
),
),
'pidt_datestamp' => array(
'type' => 'datestamp',
'settings' => array(
'field[settings][enddate_get]' => 1,
),
),
);
$typename = $this->createContentType(array(), $fields);
// Create and configure feed importer.
$this->createImporterConfiguration('iCal importer', 'ical');
$this->setSettings('ical', NULL, array('import_period' => FEEDS_SCHEDULE_NEVER));
$this->setPlugin('ical', 'FeedsFileFetcher');
$this->setSettings('ical', 'FeedsFileFetcher', array('allowed_extensions' => 'ics ical'));
$this->configureParser();
$this->setSettings('ical', 'FeedsNodeProcessor', array('content_type' => $typename));
$mappings = array(
array('source' => 'summary', 'target' => 'title', ),
array('source' => 'description', 'target' => 'body', ),
);
foreach ($fields as $name => $field) {
$mappings[] = array('source' => 'dtstart', 'target' => "field_{$name}:start", );
$mappings[] = array('source' => 'dtend', 'target' => "field_{$name}:end", );
}
$this->addMappings('ical', $mappings);
// Import iCal file
$this->importFile('ical', $this->absolutePath() . '/tests/feeds/date.ics');
$this->assertText('Created 7 nodes');
// Check dates
$dates = array(
// all timezone Pacific/Apia
1 => array('start' => '2009-01-31 19:30', 'end' => '2009-01-31 20:30'),
2 => array('start' => '2009-01-01 07:00', 'end' => '2009-01-01 08:00'),
// 3 => array('start' => '2009-09-01 19:00', 'end' => '2009-09-01 20:00'), // broken but shouldn't be
4 => array('start' => '2009-09-30 08:00', 'end' => '2009-10-01 09:00'),
// Failing Tests @see DateIcalIcalcreatorParser::formatDateTime 'aniversary' events comment.
// 5 => array('start' => '2009-10-02 00:00', 'end' => '2009-10-02 00:00'),
// 6 => array('start' => '2009-01-05 00:00', 'end' => ''), // end is correct
// 7 => array('start' => '2009-10-05 00:00', 'end' => '2009-10-05 00:00'),
);
foreach ($dates as $nid => $date) {
$this->drupalGet("node/$nid/edit");
foreach ($fields as $name => $field) {
$this->assertNodeFieldValue($name, $date['start'], array(0, 'value'));
$this->assertNodeFieldValue($name, $date['end'], array(0, 'value2'));
}
}
}
/**
* Test timezone handling.
*
* Using feed node to have a user timezone
*/
public function testTimezones() {
// set users timezone
$this->drupalPost("user/{$this->admin_user->uid}/edit", array('timezone' => 'Africa/Bangui'), t('Save'));
// Create content type for feed items.
$fields = array(
// Pacific/Apia
'pidt_site' => array(
'type' => 'date',
'settings' => array(
'field[settings][enddate_get]' => 1,
'field[settings][tz_handling]' => 'site',
),
),
// in field
'pidt_date' => array(
'type' => 'date',
'settings' => array(
'field[settings][enddate_get]' => 1,
'field[settings][tz_handling]' => 'date',
),
),
// Africa/Bangui (same user entering and viewing)
'pidt_user' => array(
'type' => 'date',
'settings' => array(
'field[settings][enddate_get]' => 1,
'field[settings][tz_handling]' => 'user',
),
),
// utc
'pidt_utc' => array(
'type' => 'date',
'settings' => array(
'field[settings][enddate_get]' => 1,
'field[settings][tz_handling]' => 'utc',
),
),
// none
'pidt_none' => array(
'type' => 'date',
'settings' => array(
'field[settings][enddate_get]' => 1,
'field[settings][tz_handling]' => 'none',
),
),
);
$typename = $this->createContentType(array(), $fields);
$this->createImporterConfiguration('iCal importer', 'ical');
// $this->setSettings('ical', NULL, array('content_type' => '', 'import_period' => FEEDS_SCHEDULE_NEVER));
$this->setPlugin('ical', 'DateIcalIcalcreatorParser');
$this->setSettings('ical', 'FeedsNodeProcessor', array('content_type' => $typename));
$mappings = array(
array('source' => 'summary', 'target' => 'title', ),
array('source' => 'description', 'target' => 'body', ),
array('source' => 'parent:uid', 'target' => 'uid', ),
);
foreach ($fields as $name => $field) {
$mappings[] = array('source' => 'dtstart', 'target' => "field_{$name}:start", );
$mappings[] = array('source' => 'dtend', 'target' => "field_{$name}:end", );
}
$this->addMappings('ical', $mappings);
$feed_url = $GLOBALS['base_url'] . '/' . drupal_get_path('module', 'date_ical') . '/tests/feeds/timezone.ics';
$nid = $this->createFeedNode('ical', $feed_url);
$this->assertText('Created 2 nodes');
$dates = array(
// X-WR-TIMEZONE:America/Los_Angeles
// DTSTART;VALUE=DATE-TIME:20110730T120001
// DTEND;VALUE=DATE-TIME:20110730T120002
$nid + 1 => array(
// it's the site field, but being displayed in the users timezone
'pidt_site' => array('start' => '2011-07-30 20:00', 'end' => '2011-07-30 20:00'),
// this should have the orginial time and zone
'pidt_date' => array('start' => '2011-07-30 12:00', 'end' => '2011-07-30 12:00', 'timezone' => 'America/Los_Angeles'),
// user timezone version (so in this case as site field)
'pidt_user' => array('start' => '2011-07-30 20:00', 'end' => '2011-07-30 20:00'),
// ah simple utc
'pidt_utc' => array('start' => '2011-07-30 19:00', 'end' => '2011-07-30 19:00'),
// this should not have under gone conversion on saving, but is altered for the user on display
// which is a date module feature - not an ical standard.
'pidt_none' => array('start' => '2011-07-30 12:00', 'end' => '2011-07-30 12:00'),
),
// DTSTART;TZID=Indian/Maldives:19980119T020000
// DTEND;TZID=Indian/Maldives:19980119T030000
$nid + 2 => array(
'pidt_site' => array('start' => '1998-01-18 22:00', 'end' => '1998-01-18 23:00'),
'pidt_date' => array('start' => '1998-01-19 02:00', 'end' => '1998-01-19 03:00', 'timezone' => 'Indian/Maldives'),
'pidt_user' => array('start' => '1998-01-18 22:00', 'end' => '1998-01-18 23:00'),
'pidt_utc' => array('start' => '1998-01-18 21:00', 'end' => '1998-01-18 22:00'),
'pidt_none' => array('start' => '1998-01-19 02:00', 'end' => '1998-01-19 03:00'),
),
);
foreach ($dates as $nid => $date) {
$this->drupalGet("node/$nid/edit");
foreach ($fields as $name => $field) {
$this->assertNodeFieldValue($name, $date[$name]['start'], array(0, 'value'));
$this->assertNodeFieldValue($name, $date[$name]['end'], array(0, 'value2'));
if (isset($date[$name]['timezone'])) {
$this->assertNodeFieldValue($name, $date[$name]['timezone'], array(0, 'timezone'));
}
}
}
// Import date.ics iCal file
$feed_url = $GLOBALS['base_url'] . '/' . drupal_get_path('module', 'date_ical') . '/tests/feeds/date.ics';
$nid = $this->createFeedNode('ical', $feed_url);
$this->assertText('Created 7 nodes');
// of interest here is the 3rd entry, it has no timezone;
// and neither does the feed. This is defined as a 'floating' event, and
// should be set to the 'atendees' timezone, thus the timezone appropriate to the field.
$dates = array(
// DTSTART:20090901T190000
// DTEND:20090901T200000
$nid + 3 => array(
// This should be stored as site local time 1900; but it's being displayed in user timezone
'pidt_site' => array('start' => '2009-09-01 19:00', 'end' => '2009-09-01 20:00'),
'pidt_date' => array('start' => '2009-09-01 19:00', 'end' => '2009-09-01 20:00', 'timezone' => 'Pacific/Apia'),
// Again once in the site this doesn't work as the iCalander value 'floating' value.
// Suggest it should be entered as the user's timezone; if a user zone then the sites;
// it is then displayed at the users timezone. So in this case it should be the
// same as entered.
'pidt_user' => array('start' => '2009-09-01 19:00', 'end' => '2009-09-01 20:00'),
'pidt_utc' => array('start' => '2009-09-01 19:00', 'end' => '2009-09-01 20:00'),
'pidt_none' => array('start' => '2009-09-01 19:00', 'end' => '2009-09-01 20:00'),
),
);
foreach ($dates as $nid => $date) {
$this->drupalGet("node/$nid/edit");
foreach ($fields as $name => $field) {
$this->assertNodeFieldValue($name, $date[$name]['start'], array(0, 'value'));
$this->assertNodeFieldValue($name, $date[$name]['end'], array(0, 'value2'));
if (isset($date[$name]['timezone'])) {
$this->assertNodeFieldValue($name, $date[$name]['start'], array(0, 'timezone'));
}
}
}
}
/**
* Override parent::getFormFieldsNames().
*/
protected function getFormFieldsNames($field_name, $index) {
if (substr($field_name, 0, 5) == 'pidt_') {
list($delta, $value) = $index;
if ($value == 'timezone') {
return array("field_{$field_name}[und][{$delta}][timezone][timezone]");
}
else {
return array("field_{$field_name}[und][{$delta}][{$value}][date]");
}
}
else {
return parent::getFormFieldsNames($field_name, $index);
}
}
/**
* Override parent::getFormFieldsValues().
*
* Actually probably not needed, but left to check before other tests are sorted.
*/
protected function getFormFieldsValues($field_name, $value) {
if (substr($field_name, 0, 5) == 'pidt_') {
if (!is_array($value)) {
$value = array('date' => $value);
}
$values = array($value['date']);
$values[] = isset($value['timezone']) ? $value['timezone'] : ''; // @todo
return $values;
}
else {
return parent::getFormFieldsValues($field_name, $value);
}
}
/**
* Set and configure the parser plugin.
*/
abstract function configureParser();
}
class DateIcalDateTestCase extends DateIcalFeedsParserDateTestCase {
public static function getInfo() {
return array(
'name' => 'Basic date handling (iCalCreator)',
'description' => 'Date import support.',
'group' => 'Parser iCal',
);
}
public function configureParser() {
$this->setPlugin('ical', 'DateIcalDateParser');
}
}
<?php
/**
* @file
* Test case for CCK ical date field text mapper.
*/
/**
* Common class for testing ical parsers link and guid mapping.
*/
abstract class DateIcalFeedsParserLinkTestCase extends DateIcalFeedsParserTestCase {
/**
* Set up the test.
*/
public function setUp() {
parent::setUp('link');
}
/**
* Basic test on simple ical file.
*/
function test() {
// Create content type.
$typename = $this->createContentType(array(), array(
'alpha' => 'link_field',
));
$this->createImporterConfiguration('iCal importer', 'ical');
$this->setSettings('ical', NULL, array('content_type' => '', 'import_period' => FEEDS_SCHEDULE_NEVER));
$this->setPlugin('ical', 'FeedsFileFetcher');
$this->setSettings('ical', 'FeedsFileFetcher', array('allowed_extensions' => 'ics ical'));
$this->configureParser();
$this->setSettings('ical', 'FeedsNodeProcessor', array('content_type' => $typename));
$this->addMappings('ical', array(
array(
'source' => 'uid',
'target' => 'guid',
),
array(
'source' => 'url',
'target' => 'url',
),
array(
'source' => 'url',
'target' => 'field_alpha:url',
),
));
// Import iCal file
$this->importFile('ical', $this->absolutePath() . '/tests/feeds/basic.ics');
$this->assertText('Created 2 nodes');
$item = db_query("SELECT * FROM {feeds_item} WHERE entity_type = 'node' AND entity_id = 1")->fetchObject();
$this->assertEqual($item->url, 'http://example.com/node/1', 'Feed item 1 correct url');
$this->assertEqual($item->guid, '36457EF9-C015-4DBF-91FA-057B7799FBF9', 'Feed item 1 correct uid');
$item = db_query("SELECT * FROM {feeds_item} WHERE entity_type = 'node' AND entity_id = 2")->fetchObject();
$this->assertEqual($item->url, 'http://example.com/node/2', 'Feed item 2 correct url');
$this->assertEqual($item->guid, '36726712-0001-41F3-A733-53FE5DBCD575', 'Feed item 2 correct uid');
$this->drupalGet('node/2/edit');
$this->assertFieldByName('field_alpha[und][0][url]', 'http://example.com/node/2', 'Feed item 2 correct url field value');
}
/**
* Set and configure the parser plugin.
*/
abstract function configureParser();
}
/**
* Class for testing iCal (date api) link and uid mapping.
*/
class DateIcalDateModuleLinkCase extends DateIcalFeedsParserLinkTestCase {
public static function getInfo() {
return array(
'name' => 'Link & UID (date api)',
'description' => 'Test link and uid import support.',
'group' => 'Parser iCal',
);
}
public function configureParser() {
$this->setPlugin('ical', 'DateIcalDateModuleParser');
}
}
/**
* Class for testing iCal (iCalCreator) link and uid mapping.
*/
class DateIcalIcalcreatorLinkCase extends DateIcalFeedsParserLinkTestCase {
public static function getInfo() {
return array(
'name' => 'Link & UID (iCalCreator)',
'description' => 'Test link and uid import support.',
'group' => 'Parser iCal',
);
}
public function configureParser() {
$this->setPlugin('ical', 'DateIcalIcalcreatorParser');
}
}
<?php
/**
* @file
* Test case for CCK ical date field text mapper.
*/
/**
* Common class for testing ical parsers link and guid mapping.
*/
abstract class DateIcalFeedsParserLocationTestCase extends DateIcalFeedsParserTestCase {
/**
* Set up the test.
*
public function setUp() {
// @todo additional location modules to test
parent::setUp();
}*/
/**
* Basic test on simple ical file.
*/
function testLocation() {
// Create content type.
$typename = $this->createContentType(array(), array(
'alpha' => 'text',
));
$this->createImporterConfiguration('iCal importer', 'ical');
$this->setSettings('ical', NULL, array('content_type' => '', 'import_period' => FEEDS_SCHEDULE_NEVER));
$this->setPlugin('ical', 'FeedsFileFetcher');
$this->setSettings('ical', 'FeedsFileFetcher', array('allowed_extensions' => 'ics ical'));
$this->configureParser();
$this->setSettings('ical', 'FeedsNodeProcessor', array('content_type' => $typename));
$this->addMappings('ical', array(
array(
'source' => 'uid',
'target' => 'guid',
),
array(
'source' => 'summary',
'target' => 'title',
),
array(
'source' => 'location',
'target' => 'field_alpha',
),
));
// Import iCal file
$this->importFile('ical', $this->absolutePath() . '/tests/feeds/location.ics');
$this->assertText('Created 3 nodes');
$this->locationAssertions();
}
/**
* Correct assertions. This is overridden in the (date api) test,
* as it's slightly broken.
*/
function locationAssertions() {
$this->drupalGet('node/1/edit');
$this->assertFieldByName('field_alpha[und][0][value]', 'Conference Room - F123, Bldg. 002', 'Feed item 1 location text correct.');
$this->drupalGet('node/2/edit');
$this->assertFieldByName('field_alpha[und][0][value]', 'Conference Room - F123, Bldg. 002', 'Feed item 2 location text correct.');
$this->drupalGet('node/3/edit');
$this->assertFieldByName('field_alpha[und][0][value]', 'Regardz Meeting Center Eenhoorn @ Koningin Wilhelminalaan 33, Amersfoort, Utrecht 3818 HN', 'Feed item 3 location text correct.');
}
/**
* Set and configure the parser plugin.
*/
abstract function configureParser();
}
/**
* Class for testing iCal (date api) location mapping.
*/
class DateIcalDateModuleLocationCase extends DateIcalFeedsParserLocationTestCase {
public static function getInfo() {
return array(
'name' => 'Location (date api)',
'description' => 'Test location import support.',