Skip to content
Snippets Groups Projects
Select Git revision
  • fa6b3d95dde97ed50c1a3e24638f8439d560055b
  • 11.x default protected
  • 10.5.x protected
  • 10.6.x protected
  • 11.2.x protected
  • 11.1.x protected
  • 10.4.x protected
  • 11.0.x protected
  • 10.3.x protected
  • 7.x protected
  • 10.2.x protected
  • 10.1.x protected
  • 9.5.x protected
  • 10.0.x protected
  • 9.4.x protected
  • 9.3.x protected
  • 9.2.x protected
  • 9.1.x protected
  • 8.9.x protected
  • 9.0.x protected
  • 8.8.x protected
  • 10.5.1 protected
  • 11.2.2 protected
  • 11.2.1 protected
  • 11.2.0 protected
  • 10.5.0 protected
  • 11.2.0-rc2 protected
  • 10.5.0-rc1 protected
  • 11.2.0-rc1 protected
  • 10.4.8 protected
  • 11.1.8 protected
  • 10.5.0-beta1 protected
  • 11.2.0-beta1 protected
  • 11.2.0-alpha1 protected
  • 10.4.7 protected
  • 11.1.7 protected
  • 10.4.6 protected
  • 11.1.6 protected
  • 10.3.14 protected
  • 10.4.5 protected
  • 11.0.13 protected
41 results

ImportOpmlTest.php

Blame
  • xjm's avatar
    Revert "Issue #2822382 by voleger, pfrenssen, erozqba, RytoEX, borisson_,...
    Jess authored
    Revert "Issue #2822382 by voleger, pfrenssen, erozqba, RytoEX, borisson_, sidharthap, Jo Fitzgerald, shashikant_chauhan: Make every  property protected on classes extending BrowserTestBase and KernelTestBase"
    
    This reverts commit 69501f30.
    fa6b3d95
    History
    Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    ImportOpmlTest.php 4.66 KiB
    <?php
    
    namespace Drupal\Tests\aggregator\Functional;
    
    /**
     * Tests OPML import.
     *
     * @group aggregator
     */
    class ImportOpmlTest extends AggregatorTestBase {
    
      /**
       * Modules to install.
       *
       * @var array
       */
      public static $modules = ['block', 'help'];
    
      /**
       * {@inheritdoc}
       */
      protected function setUp() {
        parent::setUp();
    
        $admin_user = $this->drupalCreateUser(['administer news feeds', 'access news feeds', 'create article content', 'administer blocks']);
        $this->drupalLogin($admin_user);
      }
    
      /**
       * Opens OPML import form.
       */
      public function openImportForm() {
        // Enable the help block.
        $this->drupalPlaceBlock('help_block', ['region' => 'help']);
    
        $this->drupalGet('admin/config/services/aggregator/add/opml');
        $this->assertText('A single OPML document may contain many feeds.', 'Found OPML help text.');
        $this->assertField('files[upload]', 'Found file upload field.');
        $this->assertField('remote', 'Found Remote URL field.');
        $this->assertField('refresh', '', 'Found Refresh field.');
      }
    
      /**
       * Submits form filled with invalid fields.
       */
      public function validateImportFormFields() {
        $before = db_query('SELECT COUNT(*) FROM {aggregator_feed}')->fetchField();
    
        $edit = [];
        $this->drupalPostForm('admin/config/services/aggregator/add/opml', $edit, t('Import'));
        $this->assertRaw(t('<em>Either</em> upload a file or enter a URL.'), 'Error if no fields are filled.');
    
        $path = $this->getEmptyOpml();
        $edit = [
          'files[upload]' => $path,
          'remote' => file_create_url($path),
        ];
        $this->drupalPostForm('admin/config/services/aggregator/add/opml', $edit, t('Import'));
        $this->assertRaw(t('<em>Either</em> upload a file or enter a URL.'), 'Error if both fields are filled.');
    
        $edit = ['remote' => 'invalidUrl://empty'];
        $this->drupalPostForm('admin/config/services/aggregator/add/opml', $edit, t('Import'));
        $this->assertText(t('The URL invalidUrl://empty is not valid.'), 'Error if the URL is invalid.');
    
        $after = db_query('SELECT COUNT(*) FROM {aggregator_feed}')->fetchField();
        $this->assertEqual($before, $after, 'No feeds were added during the three last form submissions.');
      }
    
      /**
       * Submits form with invalid, empty, and valid OPML files.
       */
      protected function submitImportForm() {
        $before = db_query('SELECT COUNT(*) FROM {aggregator_feed}')->fetchField();
    
        $form['files[upload]'] = $this->getInvalidOpml();
        $this->drupalPostForm('admin/config/services/aggregator/add/opml', $form, t('Import'));
        $this->assertText(t('No new feed has been added.'), 'Attempting to upload invalid XML.');
    
        $edit = ['remote' => file_create_url($this->getEmptyOpml())];
        $this->drupalPostForm('admin/config/services/aggregator/add/opml', $edit, t('Import'));
        $this->assertText(t('No new feed has been added.'), 'Attempting to load empty OPML from remote URL.');
    
        $after = db_query('SELECT COUNT(*) FROM {aggregator_feed}')->fetchField();
        $this->assertEqual($before, $after, 'No feeds were added during the two last form submissions.');
    
        db_delete('aggregator_feed')->execute();
    
        $feeds[0] = $this->getFeedEditArray();
        $feeds[1] = $this->getFeedEditArray();
        $feeds[2] = $this->getFeedEditArray();
        $edit = [
          'files[upload]' => $this->getValidOpml($feeds),
          'refresh'       => '900',
        ];
        $this->drupalPostForm('admin/config/services/aggregator/add/opml', $edit, t('Import'));
        $this->assertRaw(t('A feed with the URL %url already exists.', ['%url' => $feeds[0]['url[0][value]']]), 'Verifying that a duplicate URL was identified');
        $this->assertRaw(t('A feed named %title already exists.', ['%title' => $feeds[1]['title[0][value]']]), 'Verifying that a duplicate title was identified');
    
        $after = db_query('SELECT COUNT(*) FROM {aggregator_feed}')->fetchField();
        $this->assertEqual($after, 2, 'Verifying that two distinct feeds were added.');
    
        $feeds_from_db = db_query("SELECT title, url, refresh FROM {aggregator_feed}");
        $refresh = TRUE;
        foreach ($feeds_from_db as $feed) {
          $title[$feed->url] = $feed->title;
          $url[$feed->title] = $feed->url;
          $refresh = $refresh && $feed->refresh == 900;
        }
    
        $this->assertEqual($title[$feeds[0]['url[0][value]']], $feeds[0]['title[0][value]'], 'First feed was added correctly.');
        $this->assertEqual($url[$feeds[1]['title[0][value]']], $feeds[1]['url[0][value]'], 'Second feed was added correctly.');
        $this->assertTrue($refresh, 'Refresh times are correct.');
      }
    
      /**
       * Tests the import of an OPML file.
       */
      public function testOpmlImport() {
        $this->openImportForm();
        $this->validateImportFormFields();
        $this->submitImportForm();
      }
    
    }