Projet

Général

Profil

Paste
Télécharger (3,82 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / feeds / tests / feeds_mapper_date_multiple.test @ ed9a13f1

1
<?php
2

    
3
/**
4
 * @file
5
 * Contains FeedsMapperDateMultipleTestCase.
6
 */
7

    
8
/**
9
 * Test case for CCK date multi-field mapper mappers/date.inc.
10
 *
11
 * @todo: Add test method iCal
12
 * @todo: Add test method for end date
13
 */
14
class FeedsMapperDateMultipleTestCase extends FeedsMapperTestCase {
15

    
16
  /**
17
   * {@inheritdoc}
18
   */
19
  public static function getInfo() {
20
    return array(
21
      'name' => 'Mapper: Date, multi value fields',
22
      'description' => 'Test Feeds Mapper support for CCK multi valiue Date fields.',
23
      'group' => 'Feeds',
24
      'dependencies' => array('date', 'feeds_xpathparser'),
25
    );
26
  }
27

    
28
  /**
29
   * {@inheritdoc}
30
   */
31
  public function setUp() {
32
    parent::setUp(array('date_api', 'date', 'feeds_xpathparser'));
33
    variable_set('date_default_timezone', 'UTC');
34
  }
35

    
36
  /**
37
   * Testing import by loading a 4 item XML file.
38
   */
39
  public function test() {
40
    $this->drupalGet('admin/config/regional/settings');
41

    
42
    // Create content type.
43
    $typename = $this->createContentType(array(), array(
44
      'date' => 'date',
45
    ));
46
    // Make the field hold unlimited values.
47
    $edit = array(
48
      'field[cardinality]' => -1,
49
    );
50
    $this->drupalPost('admin/structure/types/manage/' . $typename . '/fields/field_date', $edit, 'Save settings');
51
    $this->assertText('Saved date_date_label configuration');
52

    
53
    // Create and configure importer.
54
    $this->createImporterConfiguration('Multi dates', 'multidates');
55
    $this->setSettings('multidates', NULL, array(
56
      'content_type' => '',
57
      'import_period' => FEEDS_SCHEDULE_NEVER,
58
    ));
59
    $this->setPlugin('multidates', 'FeedsFileFetcher');
60
    $this->setPlugin('multidates', 'FeedsXPathParserXML');
61

    
62
    $this->setSettings('multidates', 'FeedsNodeProcessor', array(
63
      'bundle' => $typename,
64
    ));
65
    $this->addMappings('multidates', array(
66
      0 => array(
67
        'source' => 'xpathparser:0',
68
        'target' => 'title',
69
      ),
70
      1 => array(
71
        'source' => 'xpathparser:1',
72
        'target' => 'guid',
73
      ),
74
      2 => array(
75
        'source' => 'xpathparser:2',
76
        'target' => 'field_date:start',
77
      ),
78
    ));
79

    
80
    $edit = array(
81
      'xpath[context]' => '//item',
82
      'xpath[sources][xpathparser:0]' => 'title',
83
      'xpath[sources][xpathparser:1]' => 'guid',
84
      'xpath[sources][xpathparser:2]' => 'date',
85
      'xpath[allow_override]' => FALSE,
86
    );
87
    $this->setSettings('multidates', 'FeedsXPathParserXML', $edit);
88

    
89
    $edit = array(
90
      'allowed_extensions' => 'xml',
91
      'directory' => 'public://feeds',
92
    );
93
    $this->setSettings('multidates', 'FeedsFileFetcher', $edit);
94

    
95
    // Import XML file.
96
    $this->importFile('multidates', $this->absolutePath() . '/tests/feeds/multi-date.xml');
97
    $this->assertText('Created 4 nodes');
98

    
99
    // Check the imported nodes.
100
    $values = array(
101
      1 => array(
102
        '01/06/2010 - 15:00',
103
        '01/07/2010 - 15:15',
104
      ),
105
      2 => array(
106
        '01/06/2010 - 15:00',
107
        '01/07/2010 - 15:00',
108
        '01/08/2010 - 15:00',
109
        '01/09/2010 - 15:00',
110
      ),
111
      // Bogus date was filtered out.
112
      3 => array(
113
        '',
114
      ),
115
      4 => array(
116
        '01/06/2010 - 14:00',
117
      ),
118
    );
119
    foreach ($values as $v => $key) {
120
      $this->drupalGet("node/$v/edit");
121
      foreach ($key as $delta => $value) {
122
        $id = 'edit-field-date-und-' . $delta . '-value-date';
123

    
124
        // Find actual value.
125
        $xpath = $this->constructFieldXpath('id', $id);
126
        $fields = $this->xpath($xpath);
127
        $field = reset($fields);
128
        $actual = (string) $field['value'];
129

    
130
        // Compose assert message.
131
        $message = format_string('Found field by id @id with value @value (actual: @actual).', array(
132
          '@id' => $id,
133
          '@value' => $value,
134
          '@actual' => $actual,
135
        ));
136

    
137
        $this->assertFieldById($id, $value, $message);
138
      }
139
    }
140
  }
141

    
142
}