date_ical_parser_location.test 5.48 KB
Newer Older
Robert Rollins's avatar
Robert Rollins committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
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
158
159
160
161
162
163
164
165
166
<?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.',
      'group' => 'Parser iCal',
    );
  }

  public function configureParser() {
    $this->setPlugin('ical', 'DateIcalDateModuleParser');
  }

  /**
   * Date module location assertions; restricted set as some are 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.');
    /**
     * Broken as per https://drupal.org/node/282521
     *
    $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.');
    */
  }
}

/**
 * Class for testing iCal (iCalCreator) location mapping.
 */
class DateIcalIcalcreatorLocationCase extends DateIcalFeedsParserLocationTestCase {
  public static function getInfo() {
    return array(
      'name' => 'Location (iCalCreator)',
      'description' => 'Test location import support.',
      'group' => 'Parser iCal',
    );
  }

  public function configureParser() {
    $this->setPlugin('ical', 'DateIcalIcalcreatorParser');
  }

  /**
   * Test location altrep. Only present in iCalCreator.
   */
  public function testLocationAlt() {
    // 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:altrep',
        'target' => 'field_alpha',
      ),
    ));

    // Import iCal file
    $this->importFile('ical', $this->absolutePath() . '/tests/feeds/location.ics');
    $this->assertText('Created 3 nodes');

    $this->drupalGet('node/1/edit');
    $this->assertFieldByName('field_alpha[und][0][value]', '', 'Feed item 1 location altparam text correct.');
    $this->drupalGet('node/2/edit');
    $this->assertFieldByName('field_alpha[und][0][value]', 'http://example.com/conf-rooms/f123.vcf', 'Feed item 2 location altparam text correct.');
    $this->drupalGet('node/3/edit');
    $this->assertFieldByName('field_alpha[und][0][value]', 'http://upcoming.yahoo.com/venue/915640/', 'Feed item 3 location altparam text correct.');
  }
}