mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-16 14:33:14 +00:00
Test equality expressions
This commit is contained in:
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
|
||||
namespace Alchemy\Tests\Phrasea\SearchEngine\AST;
|
||||
|
||||
use Alchemy\Phrasea\SearchEngine\Elastic\AST\Field as ASTField;
|
||||
use Alchemy\Phrasea\SearchEngine\Elastic\AST\FieldEqualsExpression;
|
||||
use Alchemy\Phrasea\SearchEngine\Elastic\Search\QueryContext;
|
||||
use Alchemy\Phrasea\SearchEngine\Elastic\Structure\Field as StructureField;
|
||||
|
||||
/**
|
||||
* @group unit
|
||||
* @group searchengine
|
||||
* @group ast
|
||||
*/
|
||||
class FieldEqualsExpressionTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testSerialization()
|
||||
{
|
||||
$this->assertTrue(method_exists(FieldEqualsExpression::class, '__toString'), 'Class does not have method __toString');
|
||||
$field = $this->prophesize(ASTField::class);
|
||||
$field->__toString()->willReturn('foo');
|
||||
$node = new FieldEqualsExpression($field->reveal(), 'bar');
|
||||
$this->assertEquals('(foo == <value:"bar">)', (string) $node);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider queryProvider
|
||||
*/
|
||||
public function testQueryBuild($index_field, $value, $compatible_value, $private, $expected_json)
|
||||
{
|
||||
$structure_field = $this->prophesize(StructureField::class);
|
||||
$structure_field->isValueCompatible($value)->willReturn($compatible_value);
|
||||
$structure_field->getIndexField(true)->willReturn($index_field);
|
||||
$structure_field->isPrivate()->willReturn($private);
|
||||
if ($private) {
|
||||
$structure_field->getDependantCollections()->willReturn(['baz', 'qux']);
|
||||
}
|
||||
|
||||
$ast_field = $this->prophesize(ASTField::class);
|
||||
$query_context = $this->prophesize(QueryContext::class);
|
||||
$query_context->get($ast_field->reveal())->willReturn($structure_field);
|
||||
|
||||
$node = new FieldEqualsExpression($ast_field->reveal(), 'bar');
|
||||
$query = $node->buildQuery($query_context->reveal());
|
||||
|
||||
$this->assertEquals(json_decode($expected_json, true), $query);
|
||||
}
|
||||
|
||||
public function queryProvider()
|
||||
{
|
||||
return [
|
||||
['foo.raw', 'bar', true, true, '{
|
||||
"filtered": {
|
||||
"filter": {
|
||||
"terms": {
|
||||
"base_id": ["baz","qux"] } },
|
||||
"query": {
|
||||
"term": {
|
||||
"foo.raw": "bar" } } } }'],
|
||||
['foo.raw', 'bar', true, false, '{
|
||||
"term": {
|
||||
"foo.raw": "bar" } }'],
|
||||
['foo.raw', 'bar', false, true, 'null'],
|
||||
['foo.raw', 'bar', false, false, 'null'],
|
||||
];
|
||||
}
|
||||
}
|
@@ -48,7 +48,7 @@ foo EXCEPT (bar AND baz)|(<text:"foo"> EXCEPT (<text:"bar"> AND <text:"baz">))
|
||||
foo EXCEPT (bar OR baz)|(<text:"foo"> EXCEPT (<text:"bar"> OR <text:"baz">))
|
||||
foo EXCEPT (bar EXCEPT baz)|(<text:"foo"> EXCEPT (<text:"bar"> EXCEPT <text:"baz">))
|
||||
|
||||
# Inequality operators
|
||||
# Comparison operators
|
||||
foo < 42|<range:foo lt="42">
|
||||
foo ≤ 42|<range:foo lte="42">
|
||||
foo > 42|<range:foo gt="42">
|
||||
@@ -61,6 +61,9 @@ foo < "2015/01/01"|<range:foo lt="2015/01/01">
|
||||
foo ≤ "2015/01/01"|<range:foo lte="2015/01/01">
|
||||
foo > "2015/01/01"|<range:foo gt="2015/01/01">
|
||||
foo ≥ "2015/01/01"|<range:foo gte="2015/01/01">
|
||||
foo = 42|(<field:foo> == <value:"42">)
|
||||
foo = bar|(<field:foo> == <value:"bar">)
|
||||
foo = "bar"|(<field:foo> == <value:"bar">)
|
||||
|
||||
# Field narrowing
|
||||
foo:bar|(<field:foo> MATCHES <text:"bar">)
|
||||
|
Can't render this file because it contains an unexpected character in line 1 and column 11.
|
Reference in New Issue
Block a user