Projet

Général

Profil

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

root / drupal7 / sites / all / modules / feeds / feeds_news / feeds_news.test @ ed9a13f1

1
<?php
2

    
3
/**
4
 * @file
5
 * Tests for feeds_news feature.
6
 */
7

    
8
/**
9
 * Test Feed configuration.
10
 */
11
class FeedsExamplesFeedTestCase extends FeedsWebTestCase {
12

    
13
  /**
14
   * {@inheritdoc}
15
   */
16
  public static function getInfo() {
17
    return array(
18
      'name' => 'Feature: Feed',
19
      'description' => 'Test "Feed" default configuration.',
20
      'group' => 'Feeds',
21
      'dependencies' => array('features', 'views'),
22
    );
23
  }
24

    
25
  /**
26
   * {@inheritdoc}
27
   */
28
  public function setUp() {
29
    parent::setUp(array('features', 'views', 'feeds_news'));
30
  }
31

    
32
  /**
33
   * Run tests.
34
   */
35
  public function test() {
36
    $nid = $this->createFeedNode('feed', NULL, '', 'feed');
37

    
38
    // Assert menu tabs for feed nodes does not show up on non-feed nodes.
39
    $this->drupalGet("node/{$nid}/feed-items");
40
    $this->assertResponse(200);
41
    $not_feed_node = $this->drupalCreateNode();
42
    $this->drupalGet("node/{$not_feed_node->nid}/feed-items");
43
    $this->assertResponse(404);
44

    
45
    // Assert results.
46
    $count = db_query("SELECT COUNT(*) FROM {node} WHERE type = 'feed_item'")->fetchField();
47
    $this->assertEqual($count, 10, 'Found the correct number of feed item nodes in database.');
48

    
49
    $count = db_query("SELECT COUNT(*) FROM {feeds_item} WHERE entity_type = 'node'")->fetchField();
50
    $this->assertEqual($count, 10, 'Found the correct number of records in feeds_item.');
51

    
52
    $count = db_query("SELECT COUNT(*) FROM {node} WHERE title = 'Open Atrium Translation Workflow: Two Way Translation Updates'")->fetchField();
53
    $this->assertEqual($count, 1, 'Found title.');
54
    $count = db_query("SELECT COUNT(*) FROM {node} WHERE title = 'Week in DC Tech: October 5th Edition'")->fetchField();
55
    $this->assertEqual($count, 1, 'Found title.');
56
    $count = db_query("SELECT COUNT(*) FROM {node} WHERE title = 'Integrating the Siteminder Access System in an Open Atrium-based Intranet'")->fetchField();
57
    $this->assertEqual($count, 1, 'Found title.');
58
    $count = db_query("SELECT COUNT(*) FROM {node} WHERE title = 'Scaling the Open Atrium UI'")->fetchField();
59
    $this->assertEqual($count, 1, 'Found title.');
60

    
61
    $count = db_query("SELECT COUNT(*) FROM {feeds_item} WHERE entity_type = 'node' AND url = 'http://developmentseed.org/blog/2009/oct/06/open-atrium-translation-workflow-two-way-updating'")->fetchField();
62
    $this->assertEqual($count, 1, 'Found feed_node_item record.');
63
    $count = db_query("SELECT COUNT(*) FROM {feeds_item} WHERE entity_type = 'node' AND url = 'http://developmentseed.org/blog/2009/oct/05/week-dc-tech-october-5th-edition'")->fetchField();
64
    $this->assertEqual($count, 1, 'Found feed_node_item record.');
65
    $count = db_query("SELECT COUNT(*) FROM {feeds_item} WHERE entity_type = 'node' AND guid = '974 at http://developmentseed.org'")->fetchField();
66
    $this->assertEqual($count, 1, 'Found feed_node_item record.');
67
    $count = db_query("SELECT COUNT(*) FROM {feeds_item} WHERE entity_type = 'node' AND guid = '970 at http://developmentseed.org'")->fetchField();
68
    $this->assertEqual($count, 1, 'Found feed_node_item record.');
69

    
70
    // Remove all items.
71
    $this->drupalPost("node/$nid/delete-items", array(), 'Delete');
72
    $this->assertText('Deleted 10 nodes');
73

    
74
    // Import again.
75
    $this->drupalPost("node/$nid/import", array(), 'Import');
76
    $this->assertText('Created 10 nodes');
77

    
78
    // Delete and assert all items gone.
79
    $this->drupalPost("node/$nid/delete-items", array(), 'Delete');
80

    
81
    $count = db_query("SELECT COUNT(*) FROM {node} WHERE type = 'feed_item'")->fetchField();
82
    $this->assertEqual($count, 0, 'Found the correct number of feed item nodes in database.');
83

    
84
    $count = db_query("SELECT COUNT(*) FROM {feeds_item} WHERE entity_type = 'node'")->fetchField();
85
    $this->assertEqual($count, 0, 'Found the correct number of records in feeds_item.');
86

    
87
    // Create a batch of nodes.
88
    $this->createFeedNodes('feed', 10, 'feed');
89
    $count = db_query("SELECT COUNT(*) FROM {node} WHERE type = 'feed_item'")->fetchField();
90
    $this->assertEqual($count, 100, 'Imported 100 nodes.');
91
    $count = db_query("SELECT COUNT(*) FROM {feeds_item} WHERE entity_type = 'node'")->fetchField();
92
    $this->assertEqual($count, 100, 'Found 100 records in feeds_item.');
93
  }
94

    
95
}
96

    
97
/**
98
 * Test OPML import configuration.
99
 */
100
class FeedsExamplesOPMLTestCase extends FeedsWebTestCase {
101

    
102
  /**
103
   * {@inheritdoc}
104
   */
105
  public static function getInfo() {
106
    return array(
107
      'name' => 'Feature: OPML import',
108
      'description' => 'Test "OPML import" default configuration.',
109
      'group' => 'Feeds',
110
    );
111
  }
112

    
113
  /**
114
   * Enable feeds_news feature.
115
   */
116
  public function setUp() {
117
    parent::setUp(array('feeds_news'));
118
  }
119

    
120
  /**
121
   * Run tests.
122
   */
123
  public function test() {
124

    
125
    // Import OPML and assert.
126
    $file = $this->generateOPML();
127
    $this->importFile('opml', $file);
128
    $this->assertText('Created 3 nodes');
129
    $count = db_query("SELECT COUNT(*) FROM {feeds_source}")->fetchField();
130
    $this->assertEqual($count, 4, 'Found correct number of items.');
131

    
132
    // Import a feed and then delete all items from it.
133
    $this->drupalPost('node/1/import', array(), 'Import');
134
    $this->assertText('Created 10 nodes');
135
    $this->drupalPost('node/1/delete-items', array(), 'Delete');
136
    $this->assertText('Deleted 10 nodes');
137
  }
138

    
139
}