Skip to content

Commit 89af3ed

Browse files
committed
Merge pull request #26 from mansimas/patch_tests
added HighlightTest
2 parents 5d6df6e + 9483225 commit 89af3ed

File tree

1 file changed

+113
-0
lines changed

1 file changed

+113
-0
lines changed

tests/Highlight/HighlightTest.php

+113
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the ONGR package.
5+
*
6+
* (c) NFQ Technologies UAB <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace ONGR\ElasticsearchDSL\Tests\Unit\DSL\Highlight;
13+
14+
use ONGR\ElasticsearchDSL\Highlight\Highlight;
15+
16+
class HighlightTest extends \PHPUnit_Framework_TestCase
17+
{
18+
/**
19+
* Tests GetType method, it should return 'highlight'.
20+
*/
21+
public function testGetType()
22+
{
23+
$highlight = new Highlight();
24+
$result = $highlight->getType();
25+
$this->assertEquals('highlight', $result);
26+
}
27+
28+
/**
29+
* Tests ParametersTrait hasParameter method.
30+
*/
31+
public function testTraitHasParameter()
32+
{
33+
$highlight = new Highlight();
34+
$highlight->addParameter('_source', ['include' => ['title']]);
35+
$result = $highlight->hasParameter('_source');
36+
$this->assertTrue($result);
37+
}
38+
39+
/**
40+
* Tests ParametersTrait removeParameter method.
41+
*/
42+
public function testTraitRemoveParameter()
43+
{
44+
$highlight = new Highlight();
45+
$highlight->addParameter('_source', ['include' => ['title']]);
46+
$highlight->removeParameter('_source');
47+
$result = $highlight->hasParameter('_source');
48+
$this->assertFalse($result);
49+
}
50+
51+
/**
52+
* Tests ParametersTrait getParameter method.
53+
*/
54+
public function testTraitGetParameter()
55+
{
56+
$highlight = new Highlight();
57+
$highlight->addParameter('_source', ['include' => 'title']);
58+
$expectedResult = ['include' => 'title'];
59+
$this->assertEquals($expectedResult, $highlight->getParameter('_source'));
60+
}
61+
62+
/**
63+
* Tests ParametersTrait getParameters and setParameters methods.
64+
*/
65+
public function testTraitSetGetParameters()
66+
{
67+
$highlight = new Highlight();
68+
$highlight->setParameters(
69+
[
70+
'_source',
71+
['include' => 'title'],
72+
'content',
73+
['force_source' => true],
74+
]
75+
);
76+
$expectedResult = [
77+
'_source',
78+
['include' => 'title'],
79+
'content',
80+
['force_source' => true],
81+
];
82+
$this->assertEquals($expectedResult, $highlight->getParameters());
83+
}
84+
85+
/**
86+
* Test toArray method.
87+
*/
88+
public function testToArray()
89+
{
90+
$highlight = new Highlight();
91+
$highlight->addField('ok');
92+
$highlight->addParameter('_source', ['include' => ['title']]);
93+
$highlight->setTags(['<tag>'], ['</tag>']);
94+
$result = $highlight->toArray();
95+
$expectedResult = [
96+
'fields' => [
97+
'ok' => new \StdClass,
98+
],
99+
'_source' => [
100+
'include' => [
101+
'title',
102+
],
103+
],
104+
'pre_tags' => [
105+
'<tag>',
106+
],
107+
'post_tags' => [
108+
'</tag>',
109+
],
110+
];
111+
$this->assertEquals($expectedResult, $result);
112+
}
113+
}

0 commit comments

Comments
 (0)