class TermsParseModeTest in Search API 8
Tests functionality of the "Multiple words" parse mode.
@coversDefaultClass \Drupal\search_api\Plugin\search_api\parse_mode\Terms
@group search_api
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses PhpunitCompatibilityTrait
- class \Drupal\Tests\search_api\Unit\TermsParseModeTest
 
 
Expanded class hierarchy of TermsParseModeTest
File
- tests/
src/ Unit/ TermsParseModeTest.php, line 15  
Namespace
Drupal\Tests\search_api\UnitView source
class TermsParseModeTest extends UnitTestCase {
  /**
   * The parse mode plugin to test.
   *
   * @var \Drupal\search_api\Plugin\search_api\parse_mode\Terms
   */
  protected $plugin;
  /**
   * {@inheritdoc}
   */
  protected function setUp() {
    parent::setUp();
    $this->plugin = new Terms([], '', []);
  }
  /**
   * Tests parsing the keys.
   *
   * @param mixed $keys
   *   The keywords to parse.
   * @param array $expected
   *   The expected parsed keys array.
   *
   * @dataProvider parseInputTestDataProvider
   */
  public function testParseInput($keys, array $expected) {
    $parsed = $this->plugin
      ->parseInput($keys);
    $this
      ->assertEquals($expected, $parsed);
  }
  /**
   * Provides test data for testParseInput().
   *
   * @return array[]
   *   An array of argument arrays for testParseInput().
   *
   * @see \Drupal\Tests\search_api\Unit\TermsParseModeTest::testParseInput()
   */
  public function parseInputTestDataProvider() {
    return [
      'normal keywords' => [
        'keys' => 'foo bar',
        'expected' => [
          '#conjunction' => 'AND',
          'foo',
          'bar',
        ],
      ],
      'quoted phrase' => [
        'keys' => '"cogito ergo sum"',
        'expected' => [
          '#conjunction' => 'AND',
          'cogito ergo sum',
        ],
      ],
      'single-word quotes' => [
        'keys' => '"foo"',
        'expected' => [
          '#conjunction' => 'AND',
          'foo',
        ],
      ],
      'negated keyword' => [
        'keys' => '-foo',
        'expected' => [
          '#conjunction' => 'AND',
          [
            '#negation' => TRUE,
            '#conjunction' => 'AND',
            'foo',
          ],
        ],
      ],
      'negated phrase' => [
        'keys' => '-"cogito ergo sum"',
        'expected' => [
          '#conjunction' => 'AND',
          [
            '#conjunction' => 'AND',
            '#negation' => TRUE,
            'cogito ergo sum',
          ],
        ],
      ],
      'keywords with stand-alone dash' => [
        'keys' => 'foo - bar',
        'expected' => [
          '#conjunction' => 'AND',
          'foo',
          'bar',
        ],
      ],
      'really complicated search' => [
        'keys' => 'pos  -neg "quoted pos with -minus" - -"quoted neg"',
        'expected' => [
          '#conjunction' => 'AND',
          'pos',
          [
            '#negation' => TRUE,
            '#conjunction' => 'AND',
            'neg',
          ],
          'quoted pos with -minus',
          [
            '#negation' => TRUE,
            '#conjunction' => 'AND',
            'quoted neg',
          ],
        ],
      ],
      'multi-byte space' => [
        'keys' => '神奈川県 連携',
        'expected' => [
          '#conjunction' => 'AND',
          '神奈川県',
          '連携',
        ],
      ],
    ];
  }
}Members
| 
            Name | 
                  Modifiers | Type | Description | Overrides | 
|---|---|---|---|---|
| 
            PhpunitCompatibilityTrait:: | 
                  public | function | Returns a mock object for the specified class using the available method. | |
| 
            PhpunitCompatibilityTrait:: | 
                  public | function | Compatibility layer for PHPUnit 6 to support PHPUnit 4 code. | |
| 
            TermsParseModeTest:: | 
                  protected | property | The parse mode plugin to test. | |
| 
            TermsParseModeTest:: | 
                  public | function | Provides test data for testParseInput(). | |
| 
            TermsParseModeTest:: | 
                  protected | function | 
            Overrides UnitTestCase:: | 
                  |
| 
            TermsParseModeTest:: | 
                  public | function | Tests parsing the keys. | |
| 
            UnitTestCase:: | 
                  protected | property | The random generator. | |
| 
            UnitTestCase:: | 
                  protected | property | The app root. | 1 | 
| 
            UnitTestCase:: | 
                  protected | function | Asserts if two arrays are equal by sorting them first. | |
| 
            UnitTestCase:: | 
                  protected | function | Mocks a block with a block plugin. | 1 | 
| 
            UnitTestCase:: | 
                  protected | function | Returns a stub class resolver. | |
| 
            UnitTestCase:: | 
                  public | function | Returns a stub config factory that behaves according to the passed array. | |
| 
            UnitTestCase:: | 
                  public | function | Returns a stub config storage that returns the supplied configuration. | |
| 
            UnitTestCase:: | 
                  protected | function | Sets up a container with a cache tags invalidator. | |
| 
            UnitTestCase:: | 
                  protected | function | Gets the random generator for the utility methods. | |
| 
            UnitTestCase:: | 
                  public | function | Returns a stub translation manager that just returns the passed string. | |
| 
            UnitTestCase:: | 
                  public | function | Generates a unique random string containing letters and numbers. |