| @@ 13-62 (lines=50) @@ | ||
| 10 | /** |
|
| 11 | * @internal |
|
| 12 | */ |
|
| 13 | class LowercaseProcessorTest extends BasePipelineTest |
|
| 14 | { |
|
| 15 | /** |
|
| 16 | * @group unit |
|
| 17 | */ |
|
| 18 | public function testLowercase(): void |
|
| 19 | { |
|
| 20 | $processor = new LowercaseProcessor('foo'); |
|
| 21 | ||
| 22 | $expected = [ |
|
| 23 | 'lowercase' => [ |
|
| 24 | 'field' => 'foo', |
|
| 25 | ], |
|
| 26 | ]; |
|
| 27 | ||
| 28 | $this->assertEquals($expected, $processor->toArray()); |
|
| 29 | } |
|
| 30 | ||
| 31 | /** |
|
| 32 | * @group functional |
|
| 33 | */ |
|
| 34 | public function testLowercaseField(): void |
|
| 35 | { |
|
| 36 | $lcase = new LowercaseProcessor('name'); |
|
| 37 | ||
| 38 | $pipeline = $this->_createPipeline('my_custom_pipeline', 'pipeline for Lowercase'); |
|
| 39 | $pipeline->addProcessor($lcase)->create(); |
|
| 40 | ||
| 41 | $index = $this->_createIndex(); |
|
| 42 | $bulk = new Bulk($index->getClient()); |
|
| 43 | $bulk->setIndex($index); |
|
| 44 | ||
| 45 | $bulk->addDocuments([ |
|
| 46 | new Document(null, ['name' => 'RUFLIN']), |
|
| 47 | new Document(null, ['name' => 'NICOLAS']), |
|
| 48 | ]); |
|
| 49 | $bulk->setRequestParam('pipeline', 'my_custom_pipeline'); |
|
| 50 | ||
| 51 | $bulk->send(); |
|
| 52 | $index->refresh(); |
|
| 53 | ||
| 54 | $result = $index->search('*'); |
|
| 55 | ||
| 56 | $this->assertCount(2, $result->getResults()); |
|
| 57 | ||
| 58 | $results = $result->getResults(); |
|
| 59 | $this->assertSame('ruflin', ($results[0]->getHit())['_source']['name']); |
|
| 60 | $this->assertSame('nicolas', ($results[1]->getHit())['_source']['name']); |
|
| 61 | } |
|
| 62 | } |
|
| 63 | ||
| @@ 13-62 (lines=50) @@ | ||
| 10 | /** |
|
| 11 | * @internal |
|
| 12 | */ |
|
| 13 | class TrimProcessorTest extends BasePipelineTest |
|
| 14 | { |
|
| 15 | /** |
|
| 16 | * @group unit |
|
| 17 | */ |
|
| 18 | public function testTrim(): void |
|
| 19 | { |
|
| 20 | $processor = new TrimProcessor('foo'); |
|
| 21 | ||
| 22 | $expected = [ |
|
| 23 | 'trim' => [ |
|
| 24 | 'field' => 'foo', |
|
| 25 | ], |
|
| 26 | ]; |
|
| 27 | ||
| 28 | $this->assertEquals($expected, $processor->toArray()); |
|
| 29 | } |
|
| 30 | ||
| 31 | /** |
|
| 32 | * @group functional |
|
| 33 | */ |
|
| 34 | public function testTrimField(): void |
|
| 35 | { |
|
| 36 | $trim = new TrimProcessor('name'); |
|
| 37 | ||
| 38 | $pipeline = $this->_createPipeline('my_custom_pipeline', 'pipeline for Trim'); |
|
| 39 | $pipeline->addProcessor($trim)->create(); |
|
| 40 | ||
| 41 | $index = $this->_createIndex(); |
|
| 42 | $bulk = new Bulk($index->getClient()); |
|
| 43 | $bulk->setIndex($index); |
|
| 44 | ||
| 45 | $bulk->addDocuments([ |
|
| 46 | new Document(null, ['name' => ' ruflin ']), |
|
| 47 | new Document(null, ['name' => ' nicolas ']), |
|
| 48 | ]); |
|
| 49 | $bulk->setRequestParam('pipeline', 'my_custom_pipeline'); |
|
| 50 | ||
| 51 | $bulk->send(); |
|
| 52 | $index->refresh(); |
|
| 53 | ||
| 54 | $result = $index->search('*'); |
|
| 55 | ||
| 56 | $this->assertCount(2, $result->getResults()); |
|
| 57 | ||
| 58 | $results = $result->getResults(); |
|
| 59 | $this->assertSame('ruflin', ($results[0]->getHit())['_source']['name']); |
|
| 60 | $this->assertSame('nicolas', ($results[1]->getHit())['_source']['name']); |
|
| 61 | } |
|
| 62 | } |
|
| 63 | ||
| @@ 13-62 (lines=50) @@ | ||
| 10 | /** |
|
| 11 | * @internal |
|
| 12 | */ |
|
| 13 | class UppercaseProcessorTest extends BasePipelineTest |
|
| 14 | { |
|
| 15 | /** |
|
| 16 | * @group unit |
|
| 17 | */ |
|
| 18 | public function testUppercase(): void |
|
| 19 | { |
|
| 20 | $processor = new UppercaseProcessor('foo'); |
|
| 21 | ||
| 22 | $expected = [ |
|
| 23 | 'uppercase' => [ |
|
| 24 | 'field' => 'foo', |
|
| 25 | ], |
|
| 26 | ]; |
|
| 27 | ||
| 28 | $this->assertEquals($expected, $processor->toArray()); |
|
| 29 | } |
|
| 30 | ||
| 31 | /** |
|
| 32 | * @group functional |
|
| 33 | */ |
|
| 34 | public function testUppercaseField(): void |
|
| 35 | { |
|
| 36 | $ucase = new UppercaseProcessor('name'); |
|
| 37 | ||
| 38 | $pipeline = $this->_createPipeline('my_custom_pipeline', 'pipeline for Uppercase'); |
|
| 39 | $pipeline->addProcessor($ucase)->create(); |
|
| 40 | ||
| 41 | $index = $this->_createIndex(); |
|
| 42 | $bulk = new Bulk($index->getClient()); |
|
| 43 | $bulk->setIndex($index); |
|
| 44 | ||
| 45 | $bulk->addDocuments([ |
|
| 46 | new Document(null, ['name' => 'ruflin']), |
|
| 47 | new Document(null, ['name' => 'nicolas']), |
|
| 48 | ]); |
|
| 49 | $bulk->setRequestParam('pipeline', 'my_custom_pipeline'); |
|
| 50 | ||
| 51 | $bulk->send(); |
|
| 52 | $index->refresh(); |
|
| 53 | ||
| 54 | $result = $index->search('*'); |
|
| 55 | ||
| 56 | $this->assertCount(2, $result->getResults()); |
|
| 57 | ||
| 58 | $results = $result->getResults(); |
|
| 59 | $this->assertSame('RUFLIN', ($results[0]->getHit())['_source']['name']); |
|
| 60 | $this->assertSame('NICOLAS', ($results[1]->getHit())['_source']['name']); |
|
| 61 | } |
|
| 62 | } |
|
| 63 | ||