Projet

Général

Profil

Révision ed9a13f1

Ajouté par Assos Assos il y a presque 4 ans

Weekly update of contrib modules

Voir les différences:

drupal7/sites/all/modules/feeds/tests/feeds.test
11 11
class FeedsWebTestCase extends DrupalWebTestCase {
12 12
  protected $profile = 'testing';
13 13

  
14
  /**
15
   * {@inheritdoc}
16
   */
14 17
  public function setUp() {
15 18
    $args = func_get_args();
16 19

  
......
96 99
    $this->admin_user = $this->drupalCreateUser($permissions);
97 100
    $this->drupalLogin($this->admin_user);
98 101

  
102
    // Create two content types if they don't exist yet.
103
    $existing_node_types = node_type_get_names();
99 104
    $types = array(
100 105
      array(
101 106
        'type' => 'page',
......
111 116
      ),
112 117
    );
113 118
    foreach ($types as $type) {
119
      // Check if the content type to add already exists. Other tests which
120
      // inherit from FeedsWebTestCase might already have added one of the
121
      // content types in one of the modules they have enabled in their startup.
122
      if (isset($existing_node_types[$type['type']])) {
123
        // Content type already exists. Continue to the next one.
124
        continue;
125
      }
126

  
114 127
      $this->drupalPost('admin/structure/types/add', $type, 'Save content type');
115 128
      $this->assertText("The content type " . $type['name'] . " has been added.");
116 129
    }
......
127 140
   * Get the absolute directory path of the feeds module.
128 141
   */
129 142
  public function absolutePath() {
130
    return  $this->absolute() . '/' . drupal_get_path('module', 'feeds');
143
    return $this->absolute() . '/' . drupal_get_path('module', 'feeds');
131 144
  }
132 145

  
133 146
  /**
......
139 152
  public function generateOPML() {
140 153
    $path = $GLOBALS['base_url'] . '/' . drupal_get_path('module', 'feeds') . '/tests/feeds/';
141 154

  
142
  $output =
143
'<?xml version="1.0" encoding="utf-8"?>
155
    $output =
156
    '<?xml version="1.0" encoding="utf-8"?>
144 157
<opml version="1.1">
145 158
<head>
146 159
    <title>Feeds test OPML</title>
......
156 169
</body>
157 170
</opml>';
158 171

  
159
    // UTF 8 encode output string and write it to disk
172
    // UTF 8 encode output string and write it to disk.
160 173
    $output = utf8_encode($output);
161 174
    $filename = file_default_scheme() . '://test-opml-' . $this->randomName() . '.opml';
162 175

  
......
232 245
  }
233 246

  
234 247
  /**
235
   * Create a test feed node. Test user has to have sufficient permissions:
248
   * Create a test feed node. Test user has to have sufficient permissions:.
236 249
   *
237 250
   * * create [type] content
238
   * * use feeds
251
   * * use feeds.
239 252
   *
240 253
   * Assumes that page content type has been configured with
241 254
   * createImporterConfiguration() as a feed content type.
......
250 263

  
251 264
    // If content type not given, retrieve it.
252 265
    if (!$content_type) {
253
      $result= db_select('feeds_importer', 'f')
266
      $result = db_select('feeds_importer', 'f')
254 267
        ->condition('f.id', $id, '=')
255 268
        ->fields('f', array('config'))
256 269
        ->execute();
......
342 355

  
343 356
    // Check whether feed got recorded in feeds_source table.
344 357
    $this->assertEqual(1, db_query("SELECT COUNT(*) FROM {feeds_source} WHERE id = :id AND feed_nid = 0", array(':id' => $id))->fetchField());
345
    $source = db_query("SELECT * FROM {feeds_source} WHERE id = :id AND feed_nid = 0",  array(':id' => $id))->fetchObject();
358
    $source = db_query("SELECT * FROM {feeds_source} WHERE id = :id AND feed_nid = 0", array(':id' => $id))->fetchObject();
346 359
    $config = unserialize($source->config);
347 360
    $this->assertEqual($config['FeedsHTTPFetcher']['source'], $feed_url, t('URL in DB correct.'));
348 361

  
......
616 629
   *
617 630
   * @param string $id
618 631
   *   ID of the importer.
619
   * @param integer $i
632
   * @param int $i
620 633
   *   The key of the mapping.
621 634
   * @param string $source
622 635
   *   The source field.
623 636
   * @param string $target
624 637
   *   The target field.
625 638
   *
626
   * @return integer
639
   * @return int
627 640
   *   -1 if the mapping doesn't exist, the key of the mapping otherwise.
628 641
   */
629 642
  public function mappingExists($id, $i, $source, $target) {
......
655 668
    return $nid;
656 669
  }
657 670

  
671
  /**
672
   * Changes the author of a node and asserts the change in the UI.
673
   *
674
   * @param int $nid
675
   *   The ID of the node to change author.
676
   * @param object $account
677
   *   The new author.
678
   */
679
  protected function changeNodeAuthor($nid, $account) {
680
    $node = node_load($nid);
681
    $node->uid = $account->uid;
682
    node_save($node);
683
    // Assert that author was in fact changed.
684
    $this->drupalGet('node/' . $nid);
685
    $this->assertText($account->name);
686
  }
687

  
658 688
  /**
659 689
   * Copies a directory.
660 690
   *
......
684 714
   * Sets the 'feeds_simplepie_library_dir' variable to the directory where
685 715
   * SimplePie is downloaded.
686 716
   */
687
  function downloadExtractSimplePie($version) {
688
    $url = "http://simplepie.org/downloads/simplepie_$version.mini.php";
689
    $filename = 'simplepie.mini.php';
717
  public function downloadExtractSimplePie($version) {
718
    $url = "https://codeload.github.com/simplepie/simplepie/zip/$version";
690 719

  
691
    // Avoid downloading the file dozens of times
720
    // Avoid downloading the file dozens of times.
692 721
    $library_dir = DRUPAL_ROOT . '/' . $this->originalFileDirectory . '/simpletest/feeds';
693 722
    $simplepie_library_dir = $library_dir . '/simplepie';
694 723

  
......
696 725
      drupal_mkdir($library_dir);
697 726
    }
698 727

  
699
    if (!file_exists($simplepie_library_dir)) {
700
      drupal_mkdir($simplepie_library_dir);
701
    }
702

  
703 728
    // Local file name.
704
    $local_file = $simplepie_library_dir . '/' . $filename;
729
    $local_file = $library_dir . '/simplepie/library/SimplePie.php';
730
    $zip_file = $library_dir . '/simplepie.zip';
705 731

  
706 732
    // Begin single threaded code.
707 733
    if (function_exists('sem_get')) {
......
709 735
      sem_acquire($semaphore);
710 736
    }
711 737

  
712
    // Download and extact the archive, but only in one thread.
738
    // Download the archive, but only in one thread.
713 739
    if (!file_exists($local_file)) {
714
      $local_file = system_retrieve_file($url, $local_file, FALSE, FILE_EXISTS_REPLACE);
740
      if (!file_exists($zip_file)) {
741
        $zip_file = system_retrieve_file($url, $zip_file, FALSE, FILE_EXISTS_REPLACE);
742
      }
743

  
744
      // Extract the archive.
745
      $zip = new ZipArchive();
746
      if ($zip->open($zip_file) === TRUE) {
747
        $zip->extractTo($library_dir);
748
        $zip->close();
749
      }
750

  
751
      // Rename directory.
752
      rename($library_dir . '/simplepie-' . $version, $simplepie_library_dir);
715 753
    }
716 754

  
717 755
    if (function_exists('sem_get')) {
718 756
      sem_release($semaphore);
719 757
    }
720 758
    // End single threaded code.
721

  
722 759
    // Verify that files were successfully extracted.
723 760
    $this->assertTrue(file_exists($local_file), t('@file found.', array('@file' => $local_file)));
724 761

  
725 762
    // Set the simpletest library directory.
726 763
    variable_set('feeds_library_dir', $library_dir);
727 764
  }
765

  
728 766
}
729 767

  
730 768
/**
731 769
 * Provides a wrapper for DrupalUnitTestCase for Feeds unit testing.
732 770
 */
733 771
class FeedsUnitTestHelper extends DrupalUnitTestCase {
772

  
773
  /**
774
   * {@inheritdoc}
775
   */
734 776
  public function setUp() {
735 777
    parent::setUp();
736 778

  
......
738 780
    // @todo Allow an array of modules from the child class.
739 781
    drupal_load('module', 'feeds');
740 782
  }
741
}
742 783

  
784
}
785
/**
786
 *
787
 */
743 788
class FeedsUnitTestCase extends FeedsUnitTestHelper {
789

  
790
  /**
791
   * {@inheritdoc}
792
   */
744 793
  public static function getInfo() {
745 794
    return array(
746 795
      'name' => 'Unit tests',
......
756 805
   *
757 806
   * @todo Remove when http://drupal.org/node/1191252 is fixed.
758 807
   */
759
  function testFeedsValidURL() {
808
  public function testFeedsValidURL() {
760 809
    $url_schemes = array('http', 'https', 'ftp', 'feed', 'webcal');
761 810
    $valid_absolute_urls = array(
762 811
      'example.com',
......
802 851
      }
803 852
    }
804 853
  }
854

  
805 855
}

Formats disponibles : Unified diff