You are here

class ParserIcalFeedsTestCase in iCal feed parser 7

Same name and namespace in other branches
  1. 6.2 tests/parser_ical_feeds.test \ParserIcalFeedsTestCase
  2. 7.2 tests/parser_ical.test \ParserIcalFeedsTestCase

Class for testing Feeds <em>content</em> mapper.

@todo: Add test method iCal @todo: Add common feeds tests to mapping test Apple (School.ics), Google, Upcoming, include one with only feed timezone, not per item @todo: Repeating rules

Hierarchy

Expanded class hierarchy of ParserIcalFeedsTestCase

File

tests/parser_ical_feeds.test, line 18

View source
class ParserIcalFeedsTestCase extends FeedsMapperTestCase {
  public function absolutePath() {
    return $this
      ->absolute() . '/' . drupal_get_path('module', 'parser_ical');
  }

  /**
   * Set up the test.
   */
  public function setUp() {
    $modules = array_merge(array(
      'feeds',
      'feeds_ui',
      'ctools',
      'content',
      'date_api',
      'date',
      'parser_ical',
    ), func_get_args());

    // Call parent setup with the required modules
    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);
    }

    // date module : consistent site timezone to against
    variable_set('date_default_timezone_name', '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');

    // Create user and login.
    $this
      ->drupalLogin($this
      ->drupalCreateUser(array(
      'administer content types',
      'administer feeds',
      'administer nodes',
      'administer site configuration',
    )));
  }

  /**
   * Basic test configured feed item, to import feed into.
   */
  public function createConfiguredFeed($fields = array()) {

    // Create content type.
    $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);

    // Create and configure importer.
    $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;
  }

  /**
   * assertCCKFieldValue uses an XPath on the CCK fields on the form,
   * the method looks in 'value' and for plain text the end date is a 'value2'
   *
   * Can't quickly see a nice extend on it so this _yet_ but sure it's there
   * so this is a simple version of the function making assumtions that we
   * know of the date field.
   *
   * @todo this properly.
   */
  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);
  }

  /**
   * Return the form field name for a given CCK field. Special handling for date
   * fields.
   */
  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);
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ParserIcalFeedsTestCase::absolutePath public function
ParserIcalFeedsTestCase::assertCCKFieldTimezone protected function
ParserIcalFeedsTestCase::assertCCKFieldValue2 protected function assertCCKFieldValue uses an XPath on the CCK fields on the form, the method looks in 'value' and for plain text the end date is a 'value2'
ParserIcalFeedsTestCase::createConfiguredFeed public function Basic test configured feed item, to import feed into. 1
ParserIcalFeedsTestCase::getFormFieldsNames protected function Return the form field name for a given CCK field. Special handling for date fields.
ParserIcalFeedsTestCase::setUp public function Set up the test. 1