mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-23 18:03:17 +00:00
Update tests according to latest changes (PHRAS-688)
This commit is contained in:
@@ -2,8 +2,8 @@
|
|||||||
|
|
||||||
namespace Alchemy\Tests\Phrasea\SearchEngine\AST;
|
namespace Alchemy\Tests\Phrasea\SearchEngine\AST;
|
||||||
|
|
||||||
use Alchemy\Phrasea\SearchEngine\Elastic\AST\Key;
|
use Alchemy\Phrasea\SearchEngine\Elastic\AST\KeyValue\Key;
|
||||||
use Alchemy\Phrasea\SearchEngine\Elastic\AST\KeyValueExpression;
|
use Alchemy\Phrasea\SearchEngine\Elastic\AST\KeyValue\Expression as KeyValueExpression;
|
||||||
use Alchemy\Phrasea\SearchEngine\Elastic\Search\QueryContext;
|
use Alchemy\Phrasea\SearchEngine\Elastic\Search\QueryContext;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -16,25 +16,20 @@ class KeyValueExpressionTest extends \PHPUnit_Framework_TestCase
|
|||||||
public function testSerialization()
|
public function testSerialization()
|
||||||
{
|
{
|
||||||
$this->assertTrue(method_exists(KeyValueExpression::class, '__toString'), 'Class does not have method __toString');
|
$this->assertTrue(method_exists(KeyValueExpression::class, '__toString'), 'Class does not have method __toString');
|
||||||
$node = new KeyValueExpression(Key::database(), 'bar');
|
$key = $this->prophesize(Key::class);
|
||||||
$this->assertEquals('<database:bar>', (string) $node);
|
$key->__toString()->willReturn('foo');
|
||||||
|
$node = new KeyValueExpression($key->reveal(), 'bar');
|
||||||
|
$this->assertEquals('<foo:bar>', (string) $node);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testQueryBuild()
|
public function testQueryBuild()
|
||||||
{
|
{
|
||||||
$query_context = $this->prophesize(QueryContext::class);
|
$query_context = $this->prophesize(QueryContext::class);
|
||||||
$key = $this->prophesize(Key::class);
|
$key = $this->prophesize(Key::class);
|
||||||
$key->getIndexField()->willReturn('foo');
|
$key->buildQueryForValue('bar', $query_context->reveal())->willReturn('baz');
|
||||||
|
|
||||||
$node = new KeyValueExpression($key->reveal(), 'bar');
|
$node = new KeyValueExpression($key->reveal(), 'bar');
|
||||||
$query = $node->buildQuery($query_context->reveal());
|
$query = $node->buildQuery($query_context->reveal());
|
||||||
|
$this->assertEquals('baz', $query);
|
||||||
$expected = '{
|
|
||||||
"term": {
|
|
||||||
"foo": "bar"
|
|
||||||
}
|
|
||||||
}';
|
|
||||||
|
|
||||||
$this->assertEquals(json_decode($expected, true), $query);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -0,0 +1,83 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Alchemy\Tests\Phrasea\SearchEngine\AST;
|
||||||
|
|
||||||
|
use Alchemy\Phrasea\SearchEngine\Elastic\AST\KeyValue\NativeKey;
|
||||||
|
use Alchemy\Phrasea\SearchEngine\Elastic\Search\QueryContext;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @group unit
|
||||||
|
* @group searchengine
|
||||||
|
* @group ast
|
||||||
|
*/
|
||||||
|
class NativeKeyTest extends \PHPUnit_Framework_TestCase
|
||||||
|
{
|
||||||
|
public function testSerialization()
|
||||||
|
{
|
||||||
|
$this->assertTrue(method_exists(NativeKey::class, '__toString'), 'Class does not have method __toString');
|
||||||
|
$this->assertEquals('database', (string) NativeKey::database());
|
||||||
|
$this->assertEquals('collection', (string) NativeKey::collection());
|
||||||
|
$this->assertEquals('media_type', (string) NativeKey::mediaType());
|
||||||
|
$this->assertEquals('record_identifier', (string) NativeKey::recordIdentifier());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testDatabaseQuery()
|
||||||
|
{
|
||||||
|
$query_context = $this->prophesize(QueryContext::class);
|
||||||
|
$key = NativeKey::database();
|
||||||
|
$query = $key->buildQueryForValue('bar', $query_context->reveal());
|
||||||
|
|
||||||
|
$expected = '{
|
||||||
|
"term": {
|
||||||
|
"databox_name": "bar"
|
||||||
|
}
|
||||||
|
}';
|
||||||
|
|
||||||
|
$this->assertEquals(json_decode($expected, true), $query);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testCollectionQuery()
|
||||||
|
{
|
||||||
|
$query_context = $this->prophesize(QueryContext::class);
|
||||||
|
$key = NativeKey::collection();
|
||||||
|
$query = $key->buildQueryForValue('bar', $query_context->reveal());
|
||||||
|
|
||||||
|
$expected = '{
|
||||||
|
"term": {
|
||||||
|
"collection_name": "bar"
|
||||||
|
}
|
||||||
|
}';
|
||||||
|
|
||||||
|
$this->assertEquals(json_decode($expected, true), $query);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testMediaTypeQuery()
|
||||||
|
{
|
||||||
|
$query_context = $this->prophesize(QueryContext::class);
|
||||||
|
$key = NativeKey::mediaType();
|
||||||
|
$query = $key->buildQueryForValue('bar', $query_context->reveal());
|
||||||
|
|
||||||
|
$expected = '{
|
||||||
|
"term": {
|
||||||
|
"type": "bar"
|
||||||
|
}
|
||||||
|
}';
|
||||||
|
|
||||||
|
$this->assertEquals(json_decode($expected, true), $query);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testRecordIdentifierQuery()
|
||||||
|
{
|
||||||
|
$query_context = $this->prophesize(QueryContext::class);
|
||||||
|
$key = NativeKey::recordIdentifier();
|
||||||
|
$query = $key->buildQueryForValue('bar', $query_context->reveal());
|
||||||
|
|
||||||
|
$expected = '{
|
||||||
|
"term": {
|
||||||
|
"record_id": "bar"
|
||||||
|
}
|
||||||
|
}';
|
||||||
|
|
||||||
|
$this->assertEquals(json_decode($expected, true), $query);
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user