Skip to content
Snippets Groups Projects
feeds_defaults.test 14.8 KiB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445
<?php
// $Id$

/**
 * @file
 * Tests for default configurations.
 */

// Require FeedsWebTestCase class definition.
require_once(dirname(__FILE__) .'/../../tests/feeds.test.inc');

/**
 * Base class for default tests.
 */
class FeedsDefaultsTestCase extends FeedsWebTestCase {

  /**
   * Enable a default configuration and verify it.
   */
  public function enable($ids) {
    if (is_string($ids)) {
      $ids = array($ids);
    }
    $edit = array();
    foreach ($ids as $id) {
      $edit[$id] = TRUE;
    }
    $this->drupalPost('admin/build/feeds', $edit, 'Save');
    foreach ($ids as $id) {
      $this->assertRaw('admin/build/feeds/edit/'. $id .'">Override', 'Enabled '. $id);
    }
  }

  /**
   * Disable a default configuration and verify it.
   */
  public function disable($ids) {
    if (is_string($ids)) {
      $ids = array($ids);
    }
    $edit = array();
    foreach ($ids as $id) {
      $edit[$id] = FALSE;
    }
    $this->drupalPost('admin/build/feeds', $edit, 'Save');
    foreach ($ids as $id) {
      $this->assertNoRaw('admin/build/feeds/edit/'. $id .'">Override', 'Disabled '. $id);
    }
  }
}

/**
 * Test Feed configuration.
 */
class FeedsDefaultsFeedTestCase extends FeedsDefaultsTestCase {

  /**
   * Set up test.
   */
  public function setUp() {
    parent::setUp('feeds', 'feeds_ui', 'ctools', 'feeds_defaults');

    $this->drupalLogin(
      $this->drupalCreateUser(
        array(
          'administer feeds', 'administer nodes',
        )
      )
    );
  }

  /**
   * Describe this test.
   */
  public function getInfo() {
    return array(
      'name' => t('Defaults: Feed'),
      'description' => t('Test "Feed" default configuration.'),
      'group' => t('Feeds'),
    );
  }

  /**
   * Run tests.
   */
  public function test() {
    $this->enable('feed');
    $nid = $this->createFeedNode('feed', NULL, '', 'feed');

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

    $count = db_result(db_query('SELECT COUNT(*) FROM {feeds_node_item}'));
    $this->assertEqual($count, 10, 'Found the correct number of records in feeds_node_item.');

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

    $count = db_result(db_query('SELECT COUNT(*) FROM {feeds_node_item} WHERE url = "http://developmentseed.org/blog/2009/oct/06/open-atrium-translation-workflow-two-way-updating"'));
    $this->assertEqual($count, 1, 'Found feed_node_item record.');
    $count = db_result(db_query('SELECT COUNT(*) FROM {feeds_node_item} WHERE url = "http://developmentseed.org/blog/2009/oct/05/week-dc-tech-october-5th-edition"'));
    $this->assertEqual($count, 1, 'Found feed_node_item record.');
    $count = db_result(db_query('SELECT COUNT(*) FROM {feeds_node_item} WHERE guid = "974 at http://developmentseed.org"'));
    $this->assertEqual($count, 1, 'Found feed_node_item record.');
    $count = db_result(db_query('SELECT COUNT(*) FROM {feeds_node_item} WHERE guid = "970 at http://developmentseed.org"'));
    $this->assertEqual($count, 1, 'Found feed_node_item record.');

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

    // Import again.
    $this->drupalPost('node/'. $nid .'/import', array(), 'Import');
    $this->assertText('Created 10 Feed item nodes.');

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

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

    $count = db_result(db_query('SELECT COUNT(*) FROM {feeds_node_item}'));
    $this->assertEqual($count, 0, 'Found the correct number of records in feeds_node_item.');

    // Create a batch of nodes.
    $this->createFeedNodes('feed', 10, 'feed');
    $count = db_result(db_query('SELECT COUNT(*) from {node} WHERE type = "feed_item"'));
    $this->assertEqual($count, 100, 'Imported 100 nodes.');
    $count = db_result(db_query('SELECT COUNT(*) FROM {feeds_node_item}'));
    $this->assertEqual($count, 100, 'Found 100 records in feeds_node_item.');

    // Disable the configuration.
    $this->disable('feed');
    $this->drupalGet('node/add');
    $this->assertNoRaw('node/add/feed');
    $this->assertNoText('node/add/feed-item');
  }
}

/**
 * Test Feed fast configuration.
 */
class FeedsDefaultsFastFeedTestCase extends FeedsDefaultsTestCase {

  /**
   * Set up test.
   */
  public function setUp() {
    parent::setUp('feeds', 'feeds_ui', 'ctools', 'feeds_defaults', 'data', 'data_ui', 'views', 'views_ui');

    $this->drupalLogin(
      $this->drupalCreateUser(
        array(
          'administer feeds', 'administer nodes', 'administer data tables',
        )
      )
    );
  }

  /**
   * Describe this test.
   */
  public function getInfo() {
    return array(
      'name' => t('Defaults: Fast feed'),
      'description' => t('Test "Fast feed" default configuration <strong>Requires Data and Views.</strong>.'),
      'group' => t('Feeds'),
    );
  }

  /**
   * Run tests.
   */
  public function test() {

    // Enable configuration and assert status.
    $this->enable('feed_fast');
    $this->drupalGet('admin/build/data');
    $this->assertText('feeds_data_feed_fast');
    $this->drupalGet('admin/content/data/view/feeds_data_feed_fast');
    $this->assertText('Fast feed');
    $this->assertText('There is no data in this table.');

    // Create feed node.
    $nid = $this->createFeedNode('feed_fast', NULL, '', 'feed_fast');
    $this->assertText('Created 10 items.');

    // Verify presence of aggregated items.
    $this->drupalGet('admin/content/data/view/feeds_data_feed_fast');
    $this->assertText('Open Atrium Translation Workflow: Two Way Translation Updates');
    $this->assertText('n a word, nothing. There has been a major improvement on this front. Now your translation');
    $this->assertLink('http://developmentseed.org/blog/2009/oct/06/open-atrium-translation-workflow-two-way-updating');

    // Delete and re import.
    $this->drupalPost('node/'. $nid .'/delete-items', array(), 'Delete');
    $this->assertText('Deleted 10 items.');
    $count = db_result(db_query('SELECT COUNT(*) FROM {feeds_data_feed_fast}'));
    $this->assertEqual($count, 0, 'Found correct number of items.');

    $this->drupalPost('node/'. $nid .'/delete-items', array(), 'Delete');
    $this->assertText('Deleted 0 items.');
    $count = db_result(db_query('SELECT COUNT(*) FROM {feeds_data_feed_fast}'));
    $this->assertEqual($count, 0, 'Found correct number of items.');

    $this->drupalPost('node/'. $nid .'/import', array(), 'Import');
    $this->assertText('Created 10 items.');
    $count = db_result(db_query('SELECT COUNT(*) FROM {feeds_data_feed_fast}'));
    $this->assertEqual($count, 10, 'Found correct number of items.');

    $this->drupalPost('node/'. $nid .'/import', array(), 'Import');
    $this->assertText('There are no new items.');
    $count = db_result(db_query('SELECT COUNT(*) FROM {feeds_data_feed_fast}'));
    $this->assertEqual($count, 10, 'Found correct number of items.');

    // Disable.
    $this->disable('feed_fast');
    $this->drupalGet('node/add');
    $this->assertNoRaw('node/add/feed-fast');
  }
}

/**
 * Test Node import configuration.
 */
class FeedsDefaultsNodeTestCase extends FeedsDefaultsTestCase {

  /**
   * Set up test.
   */
  public function setUp() {
    parent::setUp('feeds', 'feeds_ui', 'ctools', 'feeds_defaults');

    $this->drupalLogin(
      $this->drupalCreateUser(
        array(
          'administer feeds', 'administer nodes',
        )
      )
    );
  }

  /**
   * Describe this test.
   */
  public function getInfo() {
    return array(
      'name' => t('Defaults: Node import'),
      'description' => t('Test "Node import" default configuration.'),
      'group' => t('Feeds'),
    );
  }

  /**
   * Run tests.
   */
  public function test() {
    $this->enable('node');

    // Import file.
    $this->importFile('node', $this->absolutePath() .'/tests/feeds/nodes.csv');

    // Assert returning page.
    $this->assertText('Created 8 Story nodes.');
    $this->assertText('Import CSV files with one or more of these columns: title, body, published, guid.');
    $this->assertText('Column guid is mandatory and considered unique: only one item per guid value will be created.');
    $this->assertRaw('feeds/nodes.csv');

    // Assert created nodes.
    $this->drupalGet('node');
    $this->assertText('Typi non habent');
    $this->assertText('Eodem modo typi');
    $this->assertText('Eodem modo typi, qui nunc nobis videntur parum clari, fiant sollemnes in futurum.');
    $this->assertText('Lorem ipsum');
    $this->assertText('Ut wisi enim ad minim veniam');
    $this->assertText('1976');

    // Click through to one node.
    $this->clickLink('Lorem ipsum');
    $this->assertText('Lorem ipsum');
    $this->assertText('Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat.');
    $this->assertText('Anonymous');

    // Assert DB status as is and again after an additional import.
    for ($i = 0; $i < 2; $i++) {
      $count = db_result(db_query('SELECT COUNT(*) FROM {feeds_node_item}'));
      $this->assertEqual($count, 8, 'Found correct number of items.');
      $count = db_result(db_query('SELECT COUNT(*) FROM {node} WHERE type = "story" AND status = 1 AND uid = 0'));
      $this->assertEqual($count, 8, 'Found correct number of items.');
      // Do not filter on type intentionally. There shouldn't be more than 8 nodes total.
      $count = db_result(db_query('SELECT COUNT(*) FROM {node_revisions}'));
      $this->assertEqual($count, 8, 'Found correct number of items.');

      // Import again. There are updates to 9 nodes because two nodes in the
      // import have the same guid.
      $this->drupalPost('import/node/import', array(), 'Import');
      $this->assertText('Updated 9 Story nodes.');
    }

    // Remove all nodes.
    $this->drupalPost('import/node/delete-items', array(), 'Delete');
    $this->assertText('Story Lorem ipsum has been deleted.');
    $this->assertText('Story Ut wisi enim ad minim veniam has been deleted.');
    $this->assertText('Story Duis autem vel eum iriure dolor has been deleted.');
    $this->assertText('Story Typi non habent has been deleted.');
    $this->assertText('Story Investigationes demonstraverunt has been deleted.');
    $this->assertText('Story Claritas est etiam has been deleted.');
    $this->assertText('Story Mirum est notare has been deleted.');
    $this->assertText('Story Eodem modo typi has been deleted.');
    $this->assertText('Deleted 8 nodes.');

    // Import once again.
    $this->drupalPost('import/node/import', array(), 'Import');
    $this->assertText('Created 8 Story nodes.');

    // Disable.
    $this->disable('node');

    // Nodes should be still present.
    $count = db_result(db_query('SELECT COUNT(*) FROM {feeds_node_item}'));
    $this->assertEqual($count, 8, 'Found correct number of items.');
    $count = db_result(db_query('SELECT COUNT(*) FROM {node} WHERE type = "story" AND status = 1 AND uid = 0'));
    $this->assertEqual($count, 8, 'Found correct number of items.');
    // Do not filter on type intentionally. There shouldn't be more than 8 nodes total.
    $count = db_result(db_query('SELECT COUNT(*) FROM {node_revisions}'));
    $this->assertEqual($count, 8, 'Found correct number of items.');
  }
}

/**
 * Test OPML import configuration.
 */
class FeedsDefaultsOPMLTestCase extends FeedsDefaultsTestCase {

  /**
   * Set up test.
   */
  public function setUp() {
    parent::setUp('feeds', 'feeds_ui', 'ctools', 'feeds_defaults');

    $this->drupalLogin(
      $this->drupalCreateUser(
        array(
          'administer feeds', 'administer nodes',
        )
      )
    );
  }

  /**
   * Describe this test.
   */
  public function getInfo() {
    return array(
      'name' => t('Defaults: OPML import'),
      'description' => t('Test "OPML import" default configuration.'),
      'group' => t('Feeds'),
    );
  }

  /**
   * Run tests.
   */
  public function test() {
    $this->enable('feed');
    $this->enable('opml');

    // Import OPML and assert.
    $file = $this->generateOPML();
    $this->importFile('opml', $file);
    $this->assertText('Created 3 feed nodes.');
    $count = db_result(db_query('SELECT COUNT(*) FROM {feeds_source}'));
    $this->assertEqual($count, 4, 'Found correct number of items.');

    // Import a feed and then delete all items from it.
    $this->drupalPost('node/1/import', array(), 'Import');
    $this->assertText('Created 10 Feed item nodes.');
    $this->drupalPost('node/1/delete-items', array(), 'Delete');
    $this->assertText('Deleted 10 nodes.');

    // Disable.
    $this->disable('feed');
    $this->disable('opml');
  }
}

/**
 * Test User import configuration.
 */
class FeedsDefaultsUserTestCase extends FeedsDefaultsTestCase {

  /**
   * Set up test.
   */
  public function setUp() {
    parent::setUp('feeds', 'feeds_ui', 'ctools', 'feeds_defaults');

    $this->drupalLogin(
      $this->drupalCreateUser(
        array(
          'administer feeds', 'administer users',
        )
      )
    );
  }

  /**
   * Describe this test.
   */
  public function getInfo() {
    return array(
      'name' => t('Defaults: User import'),
      'description' => t('Test "User import" default configuration.'),
      'group' => t('Feeds'),
    );
  }

  /**
   * Run tests.
   */
  public function test() {
    $this->enable('user');

    // Import CSV file.
    $this->importFile('user', $this->absolutePath() .'/tests/feeds/users.csv');

    // Assert result.
    $this->assertText('Created 4 users.');
    // 1 user has an invalid email address.
    $this->assertText('There were 1 users that could not be imported because either their name or their email was empty or not valid. Check import data and mapping settings on User processor.');
    $this->drupalGet('admin/user/user');
    $this->assertText('Morticia');
    $this->assertText('Fester');
    $this->assertText('Gomez');
    $this->assertText('Pugsley');

    $this->disable('user');
  }
}