Projet

Général

Profil

Révision a192dc0b

Ajouté par Assos Assos il y a environ 8 ans

Weekly update of contrib modules

Voir les différences:

drupal7/sites/all/modules/feeds/tests/feeds_processor_node.test
12 12

  
13 13
  public static function getInfo() {
14 14
    return array(
15
      'name' => 'RSS import to nodes',
16
      'description' => 'Tests a feed configuration that is attached to a content type, uses HTTP fetcher, common syndication parser and a node processor. Repeats the same test for an importer configuration that is not attached to a content type and for a configuration that is attached to a content type and uses the file fetcher.',
15
      'name' => 'Processor: Node',
16
      'description' => 'Tests for the node processor.',
17 17
      'group' => 'Feeds',
18 18
    );
19 19
  }
......
577 577

  
578 578
    // The feed should still be scheduled because it is being processed.
579 579
    // @see https://drupal.org/node/2275893
580
    feeds_source('syndication', 0)->scheduleImport();
581

  
582 580
    $this->cronRun();
583 581
    $this->assertEqual(86, db_query("SELECT COUNT(*) FROM {node}")->fetchField());
584 582
  }
585 583

  
584
  /**
585
   * Tests skip new items.
586
   */
587
  public function testSkipNewItems() {
588
    // Include FeedsProcessor.inc so processor related constants are available.
589
    module_load_include('inc', 'feeds', 'plugins/FeedsProcessor');
590

  
591
    // Attach to standalone importer.
592
    $this->setSettings('syndication', NULL, array('content_type' => ''));
593
    // Set that new items should not be imported.
594
    $this->setSettings('syndication', 'FeedsNodeProcessor', array(
595
      'insert_new' => FEEDS_SKIP_NEW,
596
      'update_existing' => FEEDS_SKIP_EXISTING,
597
    ));
598

  
599
    // Make title unique target.
600
    $this->removeMappings('syndication', $this->getCurrentMappings('syndication'));
601
    $this->addMappings('syndication', array(
602
      0 => array(
603
        'source' => 'title',
604
        'target' => 'title',
605
        'unique' => TRUE,
606
      ),
607
      1 => array(
608
        'source' => 'description',
609
        'target' => 'body',
610
      ),
611
      2 => array(
612
        'source' => 'timestamp',
613
        'target' => 'created',
614
      ),
615
    ));
616

  
617
    // Do a first import, no nodes should be created.
618
    $edit = array(
619
      'feeds[FeedsHTTPFetcher][source]' => $GLOBALS['base_url'] . '/' . drupal_get_path('module', 'feeds') . '/tests/feeds/developmentseed.rss2',
620
    );
621
    $this->drupalPost('import/syndication', $edit, 'Import');
622
    $this->assertText('There are no new nodes');
623

  
624
    // Now create two nodes with titles that are present in the source
625
    // "developmentseed.rss2".
626
    $this->drupalCreateNode(array(
627
      'type' => 'article',
628
      'title' => 'Open Atrium Translation Workflow: Two Way Translation Updates',
629
    ));
630
    $this->drupalCreateNode(array(
631
      'type' => 'article',
632
      'title' => 'Week in DC Tech: October 5th Edition',
633
    ));
634

  
635
    // Import again. Since the processor is set to not update as well, nothing
636
    // should be imported.
637
    $this->drupalPost('import/syndication', array(), 'Import');
638
    $this->assertText('There are no new nodes');
639

  
640
    // Now set importer to update existing.
641
    $this->setSettings('syndication', 'FeedsNodeProcessor', array(
642
      'update_existing' => FEEDS_UPDATE_EXISTING,
643
    ));
644
    // And import again. Two nodes should be updated.
645
    $this->drupalPost('import/syndication', array(), 'Import');
646
    $this->assertText('Updated 2 nodes.');
647

  
648
    // Change "insert_new" setting to insert new items to verify if changing the
649
    // setting later has the effect that new items will be imported as yet.
650
    $this->setSettings('syndication', 'FeedsNodeProcessor', array(
651
      'insert_new' => FEEDS_INSERT_NEW,
652
    ));
653
    // Import. Eight nodes should be created. No nodes should be updated.
654
    $this->drupalPost('import/syndication', array(), 'Import');
655
    $this->assertText('Created 8 nodes.');
656
    $this->assertNoText('Updated 2 nodes.');
657
  }
658

  
659
  /**
660
   * Tests if the target "changed" works as expected.
661
   */
662
  public function testChangedTarget() {
663
    // Create and configure importer.
664
    $this->createImporterConfiguration('Content CSV', 'csv');
665
    $this->setSettings('csv', NULL, array('content_type' => '', 'import_period' => FEEDS_SCHEDULE_NEVER));
666
    $this->setPlugin('csv', 'FeedsFileFetcher');
667
    $this->setPlugin('csv', 'FeedsCSVParser');
668
    $this->addMappings('csv', array(
669
      0 => array(
670
        'source' => 'title',
671
        'target' => 'title',
672
      ),
673
      // Borrow the timestamp value from the "created" column in the csv.
674
      1 => array(
675
        'source' => 'created',
676
        'target' => 'changed',
677
      ),
678
    ));
679

  
680
    // Import CSV file.
681
    $this->importFile('csv', $this->absolutePath() . '/tests/feeds/content.csv');
682
    $this->assertText('Created 2 nodes');
683

  
684
    // Assert changed date of nodes.
685
    $expected_values = array(
686
      1 => array(
687
        'changed' => 1251936720,
688
      ),
689
      2 => array(
690
        'changed' => 1251932360,
691
      ),
692
    );
693
    for ($i = 1; $i <= 2; $i++) {
694
      $node = node_load($i);
695
      $this->assertEqual($expected_values[$i]['changed'], $node->changed);
696
    }
697
  }
698

  
699
  /**
700
   * Tests the FeedsSource::pushImport() method.
701
   */
702
  public function testPushImport() {
703
    // Attach to standalone importer.
704
    $this->setSettings('syndication', NULL, array('content_type' => ''));
705

  
706
    $raw = file_get_contents(dirname(__FILE__) . '/feeds/developmentseed.rss2');
707
    feeds_source('syndication', 0)->pushImport(new FeedsFetcherResult($raw));
708
    $this->assertEqual(10, db_query("SELECT COUNT(*) FROM {node}")->fetchField());
709
  }
710

  
711
  /**
712
   * Tests the FeedsSource::pushImport() method with a CSV file.
713
   */
714
  public function testPushImportWithCSV() {
715
    // Attach to standalone importer and configure.
716
    $this->setSettings('syndication', NULL, array('content_type' => ''));
717
    $this->setPlugin('syndication', 'FeedsCSVParser');
718
    $this->removeMappings('syndication', $this->getCurrentMappings('syndication'));
719
    $this->addMappings('syndication', array(
720
      0 => array(
721
        'source' => 'title',
722
        'target' => 'title',
723
      ),
724
    ));
725

  
726
    $raw = file_get_contents($this->absolutePath() . '/tests/feeds/many_nodes.csv');
727
    feeds_source('syndication', 0)->pushImport(new FeedsFetcherResult($raw));
728
    $this->assertEqual(86, db_query("SELECT COUNT(*) FROM {node}")->fetchField());
729
  }
730

  
731
  /**
732
   * Tests if target item is not updated when only non-mapped data on the source changed.
733
   */
734
  public function testIrrelevantUpdate() {
735
    // Include FeedsProcessor.inc so processor related constants are available.
736
    module_load_include('inc', 'feeds', 'plugins/FeedsProcessor');
737

  
738
    // Attach to standalone importer and configure.
739
    $this->setSettings('syndication', NULL, array('content_type' => ''));
740
    $this->setPlugin('syndication', 'FeedsFileFetcher');
741
    $this->setPlugin('syndication', 'FeedsCSVParser');
742
    $this->removeMappings('syndication', $this->getCurrentMappings('syndication'));
743
    $this->addMappings('syndication', array(
744
      0 => array(
745
        'source' => 'name',
746
        'target' => 'title',
747
        'unique' => TRUE,
748
      ),
749
    ));
750

  
751
    // Import file.
752
    $this->importFile('syndication', $this->absolutePath() . '/tests/feeds/users.csv');
753
    $this->assertText('Created 5 nodes');
754

  
755
    // Ensure that no nodes are updated when only non-mapped columns changed.
756
    $this->setSettings('syndication', 'FeedsNodeProcessor', array(
757
      'skip_hash_check' => FALSE,
758
      'update_existing' => FEEDS_UPDATE_EXISTING,
759
    ));
760
    $this->importFile('syndication', $this->absolutePath() . '/tests/feeds/users_updated.csv');
761
    $this->assertText('There are no new nodes.');
762
  }
763

  
586 764
}

Formats disponibles : Unified diff