You are here

public function FeedsTamperUIWebTestCase::testBasic in Feeds Tamper 7

Same name and namespace in other branches
  1. 8.2 legacy/feeds_tamper_ui/tests/feeds_tamper_ui.test \FeedsTamperUIWebTestCase::testBasic()
  2. 6 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_name = $this
    ->randomName();
  $importer_id = drupal_strtolower($importer_name);
  $mapping_url = 'admin/structure/feeds/' . $importer_id . '/mapping';
  $tamper_url = 'admin/structure/feeds/' . $importer_id . '/tamper';
  $this
    ->createImporterConfiguration($importer_name, $importer_id);

  // Check help text when there are no mappings.
  $this
    ->drupalGet($tamper_url);
  $this
    ->assertText('There are no mappings defined for this importer.');
  $this
    ->addMappings($importer_id, array(
    0 => array(
      'source' => 'title',
      'target' => 'title',
      'unique' => FALSE,
    ),
    1 => array(
      'source' => 'guid',
      'target' => 'guid',
      'unique' => TRUE,
    ),
    2 => array(
      'source' => 'description',
      'target' => 'body',
    ),
  ));

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

  // Check help text and link.
  $this
    ->drupalGet($tamper_url);
  $this
    ->assertLinkByHref($mapping_url);
  $this
    ->assertText('Configure plugins to modify Feeds data before it gets saved. Each mapping can be manipulated individually.');

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

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

  // Assert that all titles were uppercased.
  $this
    ->drupalGet('node');
  $this
    ->assertUppercaseDevseedFeedContent();
  $this
    ->toggleTamperPlugin($importer_id, 0, $id);
  $this
    ->toggleTamperPlugin($importer_id, 0, $id, TRUE);
  $this
    ->setTamperPluginWeight($importer_id, 0, $id, 2);
  $this
    ->deleteTamperPlugin($id);
  $settings = array(
    'settings[mode]' => 0,
  );
  $case = $this
    ->addTamperPlugin($importer_id, 'title', 'convert_case', $settings);
  $settings = array(
    'settings[side]' => 'trim',
  );
  $trim = $this
    ->addTamperPlugin($importer_id, 'title', 'trim', $settings);
  $this
    ->toggleTamperPlugin($importer_id, 0, $case);
  $this
    ->toggleTamperPlugin($importer_id, 0, $case, TRUE);
  $this
    ->setTamperPluginWeight($importer_id, 0, $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('admin/structure/feeds');
  $this
    ->assertText('Edit | Export | Clone | Delete');
  $this
    ->assertNoText('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_id,
  ));
  $this
    ->drupalLogin($this->feeds_user);

  // Check that things are back.
  $this
    ->drupalGet('admin/structure/feeds');
  $this
    ->assertText('Edit | Export | Clone | Delete | 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_id, array(
    2 => 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_id, 'Blank source 1', 'hash');

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

  // Verify that removing a mapping removes the plugins.
  $plugins = feeds_tamper_load_all_instances(TRUE, TRUE);
  $this
    ->assertTrue(reset($plugins)->plugin_id === 'hash', 'Hash plugin exists before removal.');
  $settings = array(
    'remove_flags[2]' => TRUE,
  );
  $this
    ->drupalPost($mapping_url, $settings, 'Save');
  $plugins = feeds_tamper_load_all_instances(TRUE, TRUE);
  $this
    ->assertTrue(empty($plugins), 'Hash plugin removed with mapping');

  // Get to a somewhat clean state.
  $this
    ->drupalPost('node/' . $nid . '/delete-items', array(), 'Delete');
  node_delete($nid);
  $this
    ->drupalPost('admin/structure/feeds/' . $importer_id . '/delete', array(), 'Delete');
}