You are here

public function HttpFetcherTest::testChangedSource in Feeds 8.3

Tests if a changed source is refetched.

File

tests/src/Functional/Feeds/Fetcher/HttpFetcherTest.php, line 206

Class

HttpFetcherTest
@coversDefaultClass \Drupal\feeds\Feeds\Fetcher\HttpFetcher @group feeds

Namespace

Drupal\Tests\feeds\Functional\Feeds\Fetcher

Code

public function testChangedSource() {

  // Install module that dynamically generates a CSV file.
  $this->container
    ->get('module_installer')
    ->install([
    'feeds_test_files',
  ]);
  $this
    ->rebuildContainer();

  // Create a feed type.
  $feed_type = $this
    ->createFeedTypeForCsv([
    'guid' => 'GUID',
    'title' => 'Title',
  ], [
    'fetcher' => 'http',
    'fetcher_configuration' => [],
    'processor_configuration' => [
      'update_existing' => ProcessorInterface::UPDATE_EXISTING,
      'values' => [
        'type' => 'article',
      ],
    ],
  ]);

  // Import feed.
  $feed = $this
    ->createFeed($feed_type
    ->id(), [
    'source' => \Drupal::request()
      ->getSchemeAndHttpHost() . '/testing/feeds/nodes.csv',
  ]);
  $this
    ->batchImport($feed);
  $this
    ->assertText('Created 8');
  $this
    ->assertNodeCount(8);

  // Import again.
  $this
    ->batchImport($feed);
  $this
    ->assertText('There are no new');

  // Now change the source to test if the source is refetched.
  // - Items 1 and 4 changed.
  // - Items 2 and 7 were removed.
  \Drupal::state()
    ->set('feeds_test_nodes_last_modified', strtotime('Sun, 30 Mar 2016 10:19:55 GMT'));
  $this
    ->batchImport($feed);
  $this
    ->assertText('Updated 2');
}