Projet

Général

Profil

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

root / drupal7 / sites / all / modules / feeds / tests / FeedsSourceTest.test @ ec2b0e7b

1
<?php
2

    
3
/**
4
 * @coversDefaultClass FeedsSource
5
 * @group feeds
6
 */
7
class FeedsSourceTest extends FeedsWebTestCase {
8
  /**
9
   * {@inheritdoc}
10
   */
11
  public static function getInfo() {
12
    return array(
13
      'name' => 'FeedsSource class test',
14
      'description' => 'Covers class FeedsSource.',
15
      'group' => 'Feeds',
16
    );
17
  }
18

    
19
  /**
20
   * Tests if two sources can be imported in the same request.
21
   */
22
  public function testProgrammaticImport() {
23
    // Create an importer configuration.
24
    $this->createImporterConfiguration('Content CSV', 'csv');
25
    $this->setSettings('csv', NULL, array(
26
      'content_type' => '',
27
      'import_period' => FEEDS_SCHEDULE_NEVER,
28
    ));
29
    $this->setPlugin('csv', 'FeedsCSVParser');
30
    $this->addMappings('csv',
31
      array(
32
        0 => array(
33
          'source' => 'guid',
34
          'target' => 'guid',
35
          'unique' => TRUE,
36
        ),
37
        1 => array(
38
          'source' => 'title',
39
          'target' => 'title',
40
        ),
41
      )
42
    );
43

    
44
    // Create a source.
45
    $source = feeds_source('csv');
46
    $source->save();
47

    
48
    // First source import.
49
    $source->addConfig(array(
50
      'FeedsHTTPFetcher' => array(
51
        'source' => $GLOBALS['base_url'] . '/' . drupal_get_path('module', 'feeds') . '/tests/feeds/content.csv',
52
      ),
53
    ));
54

    
55
    // Perform import.
56
    while (FEEDS_BATCH_COMPLETE != $source->import());
57

    
58
    // Assert two created nodes.
59
    $this->assertNodeCount(2);
60

    
61
    // Set second source file.
62
    $source->addConfig(array(
63
      'FeedsHTTPFetcher' => array(
64
        'source' => $GLOBALS['base_url'] . '/' . drupal_get_path('module', 'feeds') . '/tests/feeds/many_nodes_ordered.csv',
65
      ),
66
    ));
67

    
68
    // And perform import again.
69
    while (FEEDS_BATCH_COMPLETE != $source->import());
70

    
71
    // Assert that there are 86 nodes now.
72
    $this->assertNodeCount(86);
73
  }
74

    
75
}