You are here

public function FeedsTamperUIWebTestCase::testBasic in Feeds Tamper 6

Same name and namespace in other branches
  1. 8.2 legacy/feeds_tamper_ui/tests/feeds_tamper_ui.test \FeedsTamperUIWebTestCase::testBasic()
  2. 7 feeds_tamper_ui/tests/feeds_tamper_ui.test \FeedsTamperUIWebTestCase::testBasic()

File

feeds_tamper_ui/tests/feeds_tamper_ui.test, line 24
Tests for feeds_tamper_ui.module.

Class

FeedsTamperUIWebTestCase
Test Feeds Tamper UI.

Code

public function testBasic() {
  $importer = $this
    ->randomName();
  $importer_name = $this
    ->randomString();
  $mapping_url = FEEDS_TAMPER_UI_FEEDS_BASE . '/edit/' . $importer . '/mapping';
  $this
    ->createImporterConfiguration($importer_name, $importer);
  $this
    ->drupalGet(FEEDS_TAMPER_UI_BASE . '/list/' . $importer);
  $this
    ->assertText('There are no mappings defined for this importer.');
  $this
    ->addMappings($importer, array(
    0 => array(
      'source' => 'title',
      'target' => 'title',
      'unique' => FALSE,
    ),
    1 => array(
      'source' => 'guid',
      'target' => 'guid',
      'unique' => TRUE,
    ),
    2 => array(
      'source' => 'description',
      'target' => 'body',
      'unique' => FALSE,
    ),
  ));

  // Check that tamper operation exists on feeds page.
  $this
    ->drupalGet(FEEDS_TAMPER_UI_FEEDS_BASE . '/list');
  $this
    ->assertText('Edit | Export | Clone | Delete | Tamper');

  // Check that configure link exists on mappings page.
  $this
    ->drupalGet($mapping_url);
  $this
    ->assertRaw('<a href="' . url(FEEDS_TAMPER_UI_BASE . '/list/' . $importer) . '">Configure Feeds Tamper</a>');

  // Check help text when there are no mappings.
  $this
    ->drupalGet(FEEDS_TAMPER_UI_BASE . '/list/' . $importer);
  $this
    ->assertRaw('Configure plugins to modify Feeds data before it gets saved. Each <a href="' . url(FEEDS_TAMPER_UI_FEEDS_BASE . '/edit/' . $importer . '/mapping') . '">mapping</a> can be manipulated individually.');

  // Test basic plugin adding.
  $settings = array(
    'settings[mode]' => 0,
  );
  $id = $this
    ->addTamperPlugin($importer, 'title', 'convert_case', $settings);

  // Create feed node, running import automatically.
  $nid = $this
    ->createFeedNode($importer);

  // Assert that all titles were uppercased.
  $this
    ->drupalGet('node');
  $this
    ->assertUppercaseDevseedFeedContent();
  $this
    ->toggleTamperPlugin($importer, 'title', $id);
  $this
    ->toggleTamperPlugin($importer, 'title', $id, TRUE);
  $this
    ->setTamperPluginWeight($importer, 'title', $id, 2);
  $this
    ->deleteTamperPlugin($id);
  $settings = array(
    'settings[mode]' => 0,
  );
  $case = $this
    ->addTamperPlugin($importer, 'title', 'convert_case', $settings);
  $settings = array(
    'settings[side]' => 'trim',
  );
  $trim = $this
    ->addTamperPlugin($importer, 'title', 'trim', $settings);
  $this
    ->toggleTamperPlugin($importer, 'title', $case);
  $this
    ->toggleTamperPlugin($importer, 'title', $case, TRUE);
  $this
    ->setTamperPluginWeight($importer, 'title', $case, 2);
  $this
    ->deleteTamperPlugin($case);
  $this
    ->deleteTamperPlugin($trim);

  // Login with user who can't tamper.
  $this->feeds_user = $this
    ->drupalCreateUser(array(
    'administer feeds',
  ));
  $this
    ->drupalLogin($this->feeds_user);

  // Check that tamper operation is gone.
  $this
    ->drupalGet(FEEDS_TAMPER_UI_FEEDS_BASE . '/list');
  $this
    ->assertText('Edit | Export | Clone | Delete');
  $this
    ->assertNoText('Tamper');

  // Check that configure link does not exist.
  $this
    ->drupalGet($mapping_url);
  $this
    ->assertNoText('Configure Feeds Tamper');

  // Check that "tamper importer_id" permissions work. Reset permission static
  // cache.
  $this
    ->checkPermissions(array(), TRUE);
  $this->feeds_user = $this
    ->drupalCreateUser(array(
    'administer feeds',
    'tamper ' . $importer,
  ));
  $this
    ->drupalLogin($this->feeds_user);

  // Check that things are back.
  $this
    ->drupalGet(FEEDS_TAMPER_UI_FEEDS_BASE . '/list');
  $this
    ->assertText('Edit | Export | Clone | Delete | Tamper');

  // Check that configure link exists.
  $this
    ->drupalGet($mapping_url);
  $this
    ->assertText('Configure Feeds Tamper');
  $this
    ->drupalLogin($this->admin_user);

  // Verify that sources with spaces in the name work. See #1093958.
  $settings = array(
    'remove_flags[0]' => TRUE,
  );
  $this
    ->drupalPost($mapping_url, $settings, 'Save');
  $this
    ->addMappings($importer, array(
    array(
      'source' => 'Blank source 1',
      'target' => 'title',
    ),
  ));

  // Test that form_alter is working properly.
  $this
    ->assertFieldByXPath('id("edit-source")/option[text() = "Blank source"]/@value', 'Blank source 2');

  // Delete feed items.
  $this
    ->drupalPost('node/' . $nid . '/delete-items', array(), 'Delete');

  // Verify that Blank source behaves properly.
  $id = $this
    ->addTamperPlugin($importer, 'Blank source 1', 'hash');

  // Reimport.
  $this
    ->drupalPost('node/' . $nid . '/import', array(), 'Import');
  $this
    ->assertHashedDevseedFeedContent();

  // Get to a somewhat clean state.
  $this
    ->drupalPost('node/' . $nid . '/delete-items', array(), 'Delete');
  node_delete($nid);
  $this
    ->drupalPost(FEEDS_TAMPER_UI_FEEDS_BASE . '/delete/' . $importer, array(), 'Delete');

  // Test that UI works with CSV parser.
  $this
    ->_testCSV();
}