Skip to content
Snippets Groups Projects
Commit b65d08a1 authored by Mantas Simkus's avatar Mantas Simkus
Browse files

Added Unit/DSL/Highlight tests

parent e55b5e7a
No related branches found
No related tags found
No related merge requests found
...@@ -9,8 +9,9 @@ ...@@ -9,8 +9,9 @@
* file that was distributed with this source code. * file that was distributed with this source code.
*/ */
namespace ONGR\ElasticsearchBundle\Tests\Unit\DSL\Aggregation; namespace ONGR\ElasticsearchBundle\Tests\Unit\DSL\Highlight;
use ONGR\ElasticsearchBundle\DSL\Filter\TermFilter;
use ONGR\ElasticsearchBundle\DSL\Highlight\Field; use ONGR\ElasticsearchBundle\DSL\Highlight\Field;
/** /**
...@@ -39,4 +40,41 @@ class FieldTest extends \PHPUnit_Framework_TestCase ...@@ -39,4 +40,41 @@ class FieldTest extends \PHPUnit_Framework_TestCase
$field->setHighlighterType('wrongValue'); $field->setHighlighterType('wrongValue');
$this->assertEquals($initValue, $field->getType()); $this->assertEquals($initValue, $field->getType());
} }
/**
* Tests toArray method.
*/
public function testFieldToArray()
{
$field = new Field('test');
$field->setFragmentSize(5);
$field->setNumberOfFragments(5);
$field->setHighlightQuery(new TermFilter('key1', 'value1'));
$field->setNoMatchSize(3);
$field->setForceSource(true);
$result = [
'fragment_size' => 5,
'number_of_fragments' => 5,
'matched_fields' => ['test'],
'highlight_query' => [
'term' => [
'key1' => 'value1',
],
],
'no_match_size' => 3,
'force_source' => true,
];
$this->assertEquals($result, $field->toArray());
}
/**
* Tests getName method.
*/
public function testFieldGetName()
{
$field = new Field('test');
$result = $field->getName();
$this->assertEquals('test', $result);
}
} }
<?php
/*
* This file is part of the ONGR package.
*
* (c) NFQ Technologies UAB <info@nfq.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace ONGR\ElasticsearchBundle\Tests\Unit\DSL\Highlight;
use ONGR\ElasticsearchBundle\DSL\Highlight\Field;
use ONGR\ElasticsearchBundle\DSL\Highlight\Highlight;
/**
* Unit test for Highlight.
*/
class HighlightTest extends \PHPUnit_Framework_TestCase
{
/**
* Tests toArray method.
*/
public function testHighlightToArray()
{
$highlight = new Highlight([new Field('name')]);
$highlight->setOrder('test');
$highlight->setHighlighterType('postings');
$highlight->setFragmentSize(5);
$highlight->setNumberOfFragments(5);
$highlight->setTagsSchema('styled');
$highlight->setTag('tag', 'class');
$highlight->setTag('only_tag');
$result = [
'order' => 'test',
'type' => 'postings',
'fragment_size' => 5,
'number_of_fragments' => 5,
'tags_schema' => 'styled',
'post_tags' => ['</tag>', '</only_tag>'],
'pre_tags' => ['<tag class="class">', '<only_tag>'],
'fields' => [
'name' => [
'matched_fields' => ['name'],
],
],
];
$this->assertEquals($result, $highlight->toArray());
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment