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 @ ed9a13f1

1
<?php
2

    
3
/**
4
 * @coversDefaultClass FeedsSource
5
 * @group feeds
6
 */
7
class FeedsSourceTest extends FeedsWebTestCase {
8

    
9
  /**
10
   * {@inheritdoc}
11
   */
12
  public static function getInfo() {
13
    return array(
14
      'name' => 'FeedsSource class test',
15
      'description' => 'Covers class FeedsSource.',
16
      'group' => 'Feeds',
17
    );
18
  }
19

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

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

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

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

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

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

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

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

    
76
}