You are here

public function FeedsTamperKeyWordFilterTestCase::test in Feeds Tamper 7

Same name and namespace in other branches
  1. 6 tests/feeds_tamper_plugins.test \FeedsTamperKeyWordFilterTestCase::test()

File

tests/feeds_tamper_plugins.test, line 576
Unit tests for feeds tamper plugins.

Class

FeedsTamperKeyWordFilterTestCase
Tests for keyword_filter.inc

Code

public function test() {
  $item = array(
    'title' => 'This is a title',
    'body' => 'hello body',
  );

  // Test stripos(), filter.
  $settings = array(
    'words' => 'booya',
    'word_boundaries' => FALSE,
    'case_sensitive' => FALSE,
  );
  $this
    ->executeKey($item, array(), 'title', $settings);

  // Test stripos(), pass.
  $settings = array(
    'words' => 'this',
    'word_boundaries' => FALSE,
    'case_sensitive' => FALSE,
  );
  $this
    ->executeKey($item, array(
    $item,
  ), 'title', $settings);

  // Test strpos(), filter.
  $settings = array(
    'words' => 'this',
    'word_boundaries' => FALSE,
    'case_sensitive' => TRUE,
  );
  $this
    ->executeKey($item, array(), 'title', $settings);

  // Test exact, filter.
  $settings = array(
    'words' => 'a title',
    'word_boundaries' => TRUE,
    'case_sensitive' => FALSE,
    'exact' => TRUE,
  );
  $this
    ->executeKey($item, array(), 'title', $settings);

  // Test exact, filter.
  $settings = array(
    'words' => 'This is a Title',
    'case_sensitive' => FALSE,
    'exact' => TRUE,
  );
  $this
    ->executeKey($item, array(
    $item,
  ), 'title', $settings);

  // Test word boundaries.
  $item = array(
    'title' => 'This is atitle',
    'body' => 'hello body',
  );
  $settings = array(
    'words' => 'title',
    'word_boundaries' => TRUE,
    'case_sensitive' => FALSE,
    'invert' => FALSE,
  );
  $this
    ->executeKey($item, array(), 'title', $settings);

  // Test invert = TRUE.
  $item = array(
    'title' => 'This is a title',
    'body' => 'hello body',
  );

  // Test stripos() pass.
  $settings = array(
    'words' => 'booya',
    'word_boundaries' => FALSE,
    'case_sensitive' => FALSE,
    'invert' => TRUE,
  );
  $this
    ->executeKey($item, array(
    $item,
  ), 'title', $settings);

  // Test stripos() filter.
  $settings = array(
    'words' => 'this',
    'word_boundaries' => FALSE,
    'case_sensitive' => FALSE,
    'invert' => TRUE,
  );
  $this
    ->executeKey($item, array(), 'title', $settings);

  // Test strpos(), pass.
  $settings = array(
    'words' => 'this',
    'word_boundaries' => FALSE,
    'case_sensitive' => TRUE,
    'invert' => TRUE,
  );
  $this
    ->executeKey($item, array(
    $item,
  ), 'title', $settings);

  // Test exact, pass.
  $settings = array(
    'words' => 'a title',
    'word_boundaries' => TRUE,
    'case_sensitive' => FALSE,
    'invert' => TRUE,
    'exact' => TRUE,
  );
  $this
    ->executeKey($item, array(
    $item,
  ), 'title', $settings);

  // Test exact, filter.
  $settings = array(
    'words' => 'This is a title',
    'word_boundaries' => TRUE,
    'case_sensitive' => FALSE,
    'invert' => TRUE,
    'exact' => TRUE,
  );
  $this
    ->executeKey($item, array(), 'title', $settings);

  // Test word boundaries, pass.
  $item = array(
    'title' => 'This is atitle',
    'body' => 'hello body',
  );
  $settings = array(
    'words' => 'title',
    'word_boundaries' => TRUE,
    'case_sensitive' => FALSE,
    'invert' => TRUE,
  );
  $this
    ->executeKey($item, array(
    $item,
  ), 'title', $settings);
}