mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-17 15:03:25 +00:00

- Replace Database/Collection/Type/RecordIdentifier specific AST with a generic KeyValueExpression - « IN » queries in regular fields are still using InExpression right now - Add some tests for « type:XXXX » queries
41 lines
1.1 KiB
PHP
41 lines
1.1 KiB
PHP
<?php
|
|
|
|
namespace Alchemy\Tests\Phrasea\SearchEngine\AST;
|
|
|
|
use Alchemy\Phrasea\SearchEngine\Elastic\AST\Key;
|
|
use Alchemy\Phrasea\SearchEngine\Elastic\AST\KeyValueExpression;
|
|
use Alchemy\Phrasea\SearchEngine\Elastic\Search\QueryContext;
|
|
|
|
/**
|
|
* @group unit
|
|
* @group searchengine
|
|
* @group ast
|
|
*/
|
|
class KeyValueExpressionTest extends \PHPUnit_Framework_TestCase
|
|
{
|
|
public function testSerialization()
|
|
{
|
|
$this->assertTrue(method_exists(KeyValueExpression::class, '__toString'), 'Class does not have method __toString');
|
|
$node = new KeyValueExpression(Key::database(), 'bar');
|
|
$this->assertEquals('<database:bar>', (string) $node);
|
|
}
|
|
|
|
public function testQueryBuild()
|
|
{
|
|
$query_context = $this->prophesize(QueryContext::class);
|
|
$key = $this->prophesize(Key::class);
|
|
$key->getIndexField()->willReturn('foo');
|
|
|
|
$node = new KeyValueExpression($key->reveal(), 'bar');
|
|
$query = $node->buildQuery($query_context->reveal());
|
|
|
|
$expected = '{
|
|
"term": {
|
|
"foo": "bar"
|
|
}
|
|
}';
|
|
|
|
$this->assertEquals(json_decode($expected, true), $query);
|
|
}
|
|
}
|