You are here

class KeywordFilterTest in Tamper 8

Tests the keyword filter plugin.

@coversDefaultClass \Drupal\tamper\Plugin\Tamper\KeywordFilter @group tamper

Hierarchy

Expanded class hierarchy of KeywordFilterTest

File

tests/src/Unit/Plugin/Tamper/KeywordFilterTest.php, line 13

Namespace

Drupal\Tests\tamper\Unit\Plugin\Tamper
View source
class KeywordFilterTest extends TamperPluginTestBase {

  /**
   * {@inheritdoc}
   */
  protected function instantiatePlugin() {
    return new KeywordFilter([], 'keyword_filter', [], $this
      ->getMockSourceDefinition());
  }

  /**
   * @covers ::tamper
   * @dataProvider providerKeywordFilter
   */
  public function testKeywordFilter($expected, $config) {
    $this->plugin = new KeywordFilter($config, 'keyword_filter', [], $this
      ->getMockSourceDefinition());
    $this
      ->assertEquals($expected, $this->plugin
      ->tamper('This is atitle'));
  }

  /**
   * Data provider for testKeywordFilter().
   */
  public function providerKeywordFilter() {
    return [
      'StriPosFilter' => [
        '',
        [
          KeywordFilter::WORDS => 'booya',
          KeywordFilter::WORD_BOUNDARIES => FALSE,
          KeywordFilter::EXACT => FALSE,
          KeywordFilter::CASE_SENSITIVE => FALSE,
          KeywordFilter::INVERT => FALSE,
          KeywordFilter::WORD_LIST => [
            'booya',
          ],
          KeywordFilter::REGEX => FALSE,
          KeywordFilter::FUNCTION => 'stripos',
        ],
      ],
      'StriPosPass' => [
        'This is atitle',
        [
          KeywordFilter::WORDS => 'this',
          KeywordFilter::WORD_BOUNDARIES => FALSE,
          KeywordFilter::EXACT => FALSE,
          KeywordFilter::CASE_SENSITIVE => FALSE,
          KeywordFilter::INVERT => FALSE,
          KeywordFilter::WORD_LIST => [
            'this',
          ],
          KeywordFilter::REGEX => FALSE,
          KeywordFilter::FUNCTION => 'stripos',
        ],
      ],
      'StrPosFilter' => [
        '',
        [
          KeywordFilter::WORDS => 'this',
          KeywordFilter::WORD_BOUNDARIES => FALSE,
          KeywordFilter::EXACT => FALSE,
          KeywordFilter::CASE_SENSITIVE => TRUE,
          KeywordFilter::INVERT => FALSE,
          KeywordFilter::WORD_LIST => [
            'this',
          ],
          KeywordFilter::REGEX => FALSE,
          KeywordFilter::FUNCTION => 'strpos',
        ],
      ],
      'ExactFilter' => [
        '',
        [
          KeywordFilter::WORDS => '/^a title$/ui',
          KeywordFilter::WORD_BOUNDARIES => TRUE,
          KeywordFilter::EXACT => TRUE,
          KeywordFilter::CASE_SENSITIVE => FALSE,
          KeywordFilter::INVERT => FALSE,
          KeywordFilter::WORD_LIST => [
            '/^a title$/ui',
          ],
          KeywordFilter::REGEX => TRUE,
          KeywordFilter::FUNCTION => 'matchRegex',
        ],
      ],
      'ExactFilterDataNotExact' => [
        '',
        [
          KeywordFilter::WORDS => '/^This is a Title$/ui',
          KeywordFilter::WORD_BOUNDARIES => FALSE,
          KeywordFilter::EXACT => TRUE,
          KeywordFilter::CASE_SENSITIVE => FALSE,
          KeywordFilter::INVERT => FALSE,
          KeywordFilter::WORD_LIST => [
            '/^This is a Title$/ui',
          ],
          KeywordFilter::REGEX => TRUE,
          KeywordFilter::FUNCTION => 'matchRegex',
        ],
      ],
      'WordBoundariesFilter' => [
        '',
        [
          KeywordFilter::WORDS => '/\\btitle\\b/ui',
          KeywordFilter::WORD_BOUNDARIES => TRUE,
          KeywordFilter::EXACT => FALSE,
          KeywordFilter::CASE_SENSITIVE => FALSE,
          KeywordFilter::INVERT => FALSE,
          KeywordFilter::WORD_LIST => [
            '/\\btitle\\b/ui',
          ],
          KeywordFilter::REGEX => TRUE,
          KeywordFilter::FUNCTION => 'matchRegex',
        ],
      ],
      'InvertEnablingResult' => [
        'This is atitle',
        [
          KeywordFilter::WORDS => 'booya',
          KeywordFilter::WORD_BOUNDARIES => FALSE,
          KeywordFilter::EXACT => FALSE,
          KeywordFilter::CASE_SENSITIVE => FALSE,
          KeywordFilter::INVERT => TRUE,
          KeywordFilter::WORD_LIST => [
            'booya',
          ],
          KeywordFilter::REGEX => FALSE,
          KeywordFilter::FUNCTION => 'stripos',
        ],
      ],
      'InvertFilteringResult' => [
        '',
        [
          KeywordFilter::WORDS => 'this',
          KeywordFilter::WORD_BOUNDARIES => FALSE,
          KeywordFilter::EXACT => FALSE,
          KeywordFilter::CASE_SENSITIVE => FALSE,
          KeywordFilter::INVERT => TRUE,
          KeywordFilter::WORD_LIST => [
            'this',
          ],
          KeywordFilter::REGEX => FALSE,
          KeywordFilter::FUNCTION => 'stripos',
        ],
      ],
      'InvertEnablingFailedCaseResult' => [
        'This is atitle',
        [
          KeywordFilter::WORDS => 'this',
          KeywordFilter::WORD_BOUNDARIES => FALSE,
          KeywordFilter::EXACT => FALSE,
          KeywordFilter::CASE_SENSITIVE => TRUE,
          KeywordFilter::INVERT => TRUE,
          KeywordFilter::WORD_LIST => [
            'this',
          ],
          KeywordFilter::REGEX => FALSE,
          KeywordFilter::FUNCTION => 'strpos',
        ],
      ],
      'InvertEnablingFailedExactResult' => [
        'This is atitle',
        [
          KeywordFilter::WORDS => '/^a title$/ui',
          KeywordFilter::WORD_BOUNDARIES => TRUE,
          KeywordFilter::EXACT => TRUE,
          KeywordFilter::CASE_SENSITIVE => FALSE,
          KeywordFilter::INVERT => TRUE,
          KeywordFilter::WORD_LIST => [
            '/^a title$/ui',
          ],
          KeywordFilter::REGEX => TRUE,
          KeywordFilter::FUNCTION => 'matchRegex',
        ],
      ],
      'InvertFilteringPassedExactResult' => [
        'This is atitle',
        [
          KeywordFilter::WORDS => '/^This is a title$/ui',
          KeywordFilter::WORD_BOUNDARIES => TRUE,
          KeywordFilter::EXACT => TRUE,
          KeywordFilter::CASE_SENSITIVE => FALSE,
          KeywordFilter::INVERT => TRUE,
          KeywordFilter::WORD_LIST => [
            '/^This is a title$/ui',
          ],
          KeywordFilter::REGEX => TRUE,
          KeywordFilter::FUNCTION => 'matchRegex',
        ],
      ],
      'InvertWordBoundariesFilter' => [
        'This is atitle',
        [
          KeywordFilter::WORDS => '/\\btitle\\b/ui',
          KeywordFilter::WORD_BOUNDARIES => TRUE,
          KeywordFilter::EXACT => FALSE,
          KeywordFilter::CASE_SENSITIVE => FALSE,
          KeywordFilter::INVERT => TRUE,
          KeywordFilter::WORD_LIST => [
            '/\\btitle\\b/ui',
          ],
          KeywordFilter::REGEX => TRUE,
          KeywordFilter::FUNCTION => 'matchRegex',
        ],
      ],
    ];
  }

}

Members

Namesort descending Modifiers Type Description Overrides
KeywordFilterTest::instantiatePlugin protected function Instantiates a plugin. Overrides TamperPluginTestBase::instantiatePlugin
KeywordFilterTest::providerKeywordFilter public function Data provider for testKeywordFilter().
KeywordFilterTest::testKeywordFilter public function @covers ::tamper @dataProvider providerKeywordFilter
PhpunitCompatibilityTrait::getMock Deprecated public function Returns a mock object for the specified class using the available method.
PhpunitCompatibilityTrait::setExpectedException Deprecated public function Compatibility layer for PHPUnit 6 to support PHPUnit 4 code.
TamperPluginTestBase::$plugin protected property The tamper plugin under test.
TamperPluginTestBase::getMockSourceDefinition protected function Returns a mocked source definition.
TamperPluginTestBase::setUp protected function Overrides UnitTestCase::setUp 3
TamperPluginTestBase::testBuildConfigurationForm public function @covers ::buildConfigurationForm
TamperPluginTestBase::testDefaultConfiguration public function @covers ::defaultConfiguration
TamperPluginTestBase::testGetConfiguration public function @covers ::getConfiguration
TamperPluginTestBase::testGetPluginDefinition public function @covers ::getPluginDefinition
TamperPluginTestBase::testGetPluginId public function @covers ::getPluginId
TamperPluginTestBase::testMultiple public function @covers ::multiple
UnitTestCase::$randomGenerator protected property The random generator.
UnitTestCase::$root protected property The app root. 1
UnitTestCase::assertArrayEquals protected function Asserts if two arrays are equal by sorting them first.
UnitTestCase::getBlockMockWithMachineName Deprecated protected function Mocks a block with a block plugin. 1
UnitTestCase::getClassResolverStub protected function Returns a stub class resolver.
UnitTestCase::getConfigFactoryStub public function Returns a stub config factory that behaves according to the passed array.
UnitTestCase::getConfigStorageStub public function Returns a stub config storage that returns the supplied configuration.
UnitTestCase::getContainerWithCacheTagsInvalidator protected function Sets up a container with a cache tags invalidator.
UnitTestCase::getRandomGenerator protected function Gets the random generator for the utility methods.
UnitTestCase::getStringTranslationStub public function Returns a stub translation manager that just returns the passed string.
UnitTestCase::randomMachineName public function Generates a unique random string containing letters and numbers.