Projet

Général

Profil

Paste
Télécharger (2,19 ko) Statistiques
| Branche: | Révision:

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

1
<?php
2

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

    
8
/**
9
 * Class for testing Feeds unique callbacks.
10
 */
11
class FeedsMapperUniqueTestCase extends FeedsMapperTestCase {
12

    
13
  /**
14
   * {@inheritdoc}
15
   */
16
  public static function getInfo() {
17
    return array(
18
      'name' => 'Unique target callbacks',
19
      'description' => 'Test unique target callbacks in mappers.',
20
      'group' => 'Feeds',
21
    );
22
  }
23

    
24
  /**
25
   * Test mapping target "unique_callbacks".
26
   */
27
  public function test() {
28
    // Create content type.
29
    $typename = $this->createContentType(array(), array('alpha' => 'text'));
30

    
31
    // Create two nodes. Put unique value into field field_alpha.
32
    $node1 = $this->drupalCreateNode(array(
33
      'type' => $typename,
34
      'field_alpha' => array(
35
        LANGUAGE_NONE => array(
36
          0 => array(
37
            'value' => 'Ut wisi',
38
          ),
39
        ),
40
      ),
41
    ));
42
    $node2 = $this->drupalCreateNode(array(
43
      'type' => $typename,
44
      'field_alpha' => array(
45
        LANGUAGE_NONE => array(
46
          0 => array(
47
            'value' => 'Lorem',
48
          ),
49
        ),
50
      ),
51
    ));
52

    
53
    // Create and configure importer.
54
    $this->createImporterConfiguration('Syndication', 'syndication');
55
    $this->setPlugin('syndication', 'FeedsFileFetcher');
56
    $this->setPlugin('syndication', 'FeedsCSVParser');
57
    $this->setSettings('syndication', 'FeedsNodeProcessor', array('bundle' => $typename, 'update_existing' => 2));
58
    $this->addMappings('syndication', array(
59
      0 => array(
60
        'source' => 'title',
61
        'target' => 'title',
62
      ),
63
      1 => array(
64
        'source' => 'alpha',
65
        'target' => 'test_unique_target',
66
        'unique' => TRUE,
67
      ),
68
    ));
69

    
70
    // Import CSV file.
71
    $this->importFile('syndication', $this->absolutePath() . '/tests/feeds/content.csv');
72
    $this->assertText('Updated 2 nodes');
73

    
74
    // Ensure the updated nodes have the expected title now.
75
    $node1 = node_load($node1->nid, NULL, TRUE);
76
    $this->assertEqual('Ut wisi enim ad minim veniam', $node1->title, 'Node 1 has the expected title.');
77
    $node2 = node_load($node2->nid, NULL, TRUE);
78
    $this->assertEqual('Lorem ipsum', $node2->title, 'Node 2 has the expected title.');
79
  }
80

    
81
}