Projet

Général

Profil

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

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

1
<?php
2

    
3
/**
4
 * @file
5
 * Test case for CCK date multi-field mapper mappers/date.inc.
6
 */
7

    
8
/**
9
 * Class for testing Feeds <em>content</em> mapper.
10
 *
11
 * @todo: Add test method iCal
12
 * @todo: Add test method for end date
13
 */
14
class FeedsMapperDateMultipleTestCase extends FeedsMapperTestCase {
15
  public static function getInfo() {
16
    return array(
17
      'name' => 'Mapper: Date, multi value fields',
18
      'description' => 'Test Feeds Mapper support for CCK multi valiue Date fields.',
19
      'group' => 'Feeds',
20
      'dependencies' => array('date', 'feeds_xpathparser'),
21
    );
22
  }
23

    
24
  public function setUp() {
25
    parent::setUp(array('date_api', 'date', 'feeds_xpathparser'));
26
    variable_set('date_default_timezone', 'UTC');
27
  }
28

    
29
  /**
30
   * Testing import by loading a 4 item XML file.
31
   */
32
  public function test() {
33
    $this->drupalGet('admin/config/regional/settings');
34

    
35
    // Create content type.
36
    $typename = $this->createContentType(array(), array(
37
      'date' => 'date',
38
    ));
39
    // Make the field hold unlimited values
40
    $edit = array(
41
      'field[cardinality]' => -1,
42
    );
43
    $this->drupalPost('admin/structure/types/manage/' . $typename . '/fields/field_date', $edit, 'Save settings');
44
    $this->assertText('Saved date_date_label configuration');
45

    
46
    // Create and configure importer.
47
    $this->createImporterConfiguration('Multi dates', 'multidates');
48
    $this->setSettings('multidates', NULL, array(
49
      'content_type' => '',
50
      'import_period' => FEEDS_SCHEDULE_NEVER,
51
    ));
52
    $this->setPlugin('multidates', 'FeedsFileFetcher');
53
    $this->setPlugin('multidates', 'FeedsXPathParserXML');
54

    
55
    $this->setSettings('multidates', 'FeedsNodeProcessor', array(
56
      'bundle' => $typename,
57
    ));
58
    $this->addMappings('multidates', array(
59
      0 => array(
60
        'source' => 'xpathparser:0',
61
        'target' => 'title',
62
      ),
63
      1 => array(
64
        'source' => 'xpathparser:1',
65
        'target' => 'guid',
66
      ),
67
      2 => array(
68
        'source' => 'xpathparser:2',
69
        'target' => 'field_date:start',
70
      ),
71
    ));
72

    
73
    $edit = array(
74
      'xpath[context]' => '//item',
75
      'xpath[sources][xpathparser:0]' => 'title',
76
      'xpath[sources][xpathparser:1]' => 'guid',
77
      'xpath[sources][xpathparser:2]' => 'date',
78
      'xpath[allow_override]' => FALSE,
79
    );
80
    $this->setSettings('multidates', 'FeedsXPathParserXML', $edit);
81

    
82
    $edit = array(
83
      'allowed_extensions' => 'xml',
84
      'directory' => 'public://feeds',
85
    );
86
    $this->setSettings('multidates', 'FeedsFileFetcher', $edit);
87

    
88
    // Import XML file.
89
    $this->importFile('multidates', $this->absolutePath() . '/tests/feeds/multi-date.xml');
90
    $this->assertText('Created 4 nodes');
91

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