You are here

public function FeedsContentTypeTest::testSwitchToStandaloneForm in Feeds 7.2

Tests behavior when switching from attach to content type to standalone.

When switching to a standalone form, the source form should be empty on this form. Furthermore, the source from the feed node that was created should no longer get updated on cron runs.

In the end, when switching back to attach to content type, the source from the feed node should be 'restored' and updated during cron runs.

File

tests/feeds_content_type.test, line 184
Contains FeedsContentTypeTest.

Class

FeedsContentTypeTest
Tests for when an importer is attached to a content type.

Code

public function testSwitchToStandaloneForm() {

  // Set to import as often as possible. This way we can test if the source
  // gets updated on cron runs.
  $this
    ->setSettings('syndication', NULL, array(
    'import_period' => 0,
  ));

  // Perform an import.
  $url = $GLOBALS['base_url'] . '/' . drupal_get_path('module', 'feeds') . '/tests/feeds/developmentseed.rss2';
  $edit = array(
    'feeds[FeedsHTTPFetcher][source]' => $url,
  );
  $this
    ->drupalPost('node/add/page', $edit, 'Save');
  $this
    ->assertText('Created 10 nodes');

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

  // Only the feed node exist.
  $this
    ->assertEqual(1, db_query("SELECT COUNT(*) FROM {node}")
    ->fetchField(), 'Only the feed node exists.');

  // Now switch back to standalone form.
  $this
    ->setSettings('syndication', NULL, array(
    'content_type' => '',
  ));

  // Go to 'import' page.
  $this
    ->drupalGet('import/syndication');
  $this
    ->assertFieldByName('feeds[FeedsHTTPFetcher][source]', '');
  $this
    ->assertNoFieldByName('feeds[FeedsHTTPFetcher][source]', $url);

  // Ensure that a cron task does not import content that was set using the
  // standalone form.
  $this
    ->cronRun();
  $this
    ->assertEqual(1, db_query("SELECT COUNT(*) FROM {node}")
    ->fetchField(), 'Only one node exists.');

  // Go to the edit page of the feed node and ensure that the feeds source
  // form no longer exists.
  $this
    ->drupalGet('node/1/edit');
  $this
    ->assertNoFieldByName('feeds[FeedsHTTPFetcher][source]');

  // Switch back to attach to content type. Sources should get restored.
  $this
    ->setSettings('syndication', NULL, array(
    'content_type' => 'page',
  ));
  $this
    ->drupalGet('node/1/edit');
  $this
    ->assertFieldByName('feeds[FeedsHTTPFetcher][source]', $url);

  // Run cron, nodes should get imported again.
  $this
    ->cronRun();
  $this
    ->assertEqual(11, db_query("SELECT COUNT(*) FROM {node}")
    ->fetchField(), 'Eleven nodes exist.');
}