1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Oro\Bundle\SearchBundle\Tests\Functional\Controller\Api; |
4
|
|
|
|
5
|
|
|
use Oro\Bundle\TestFrameworkBundle\Test\WebTestCase; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* @outputBuffering enabled |
9
|
|
|
* @dbIsolation |
10
|
|
|
* @dbReindex |
11
|
|
|
*/ |
12
|
|
|
class SoapSearchApiTest extends WebTestCase |
13
|
|
|
{ |
14
|
|
|
/** Default value for offset and max_records */ |
15
|
|
|
const DEFAULT_VALUE = 0; |
16
|
|
|
|
17
|
|
|
protected function setUp() |
18
|
|
|
{ |
19
|
|
|
$this->initClient([], $this->generateWsseAuthHeader()); |
20
|
|
|
$this->initSoapClient(); |
21
|
|
|
|
22
|
|
|
$this->loadFixtures(['Oro\Bundle\SearchBundle\Tests\Functional\Controller\DataFixtures\LoadSearchItemData']); |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @param array $request |
27
|
|
|
* @param array $response |
28
|
|
|
* @SuppressWarnings(PHPMD.NPathComplexity) |
29
|
|
|
* @dataProvider searchDataProvider |
30
|
|
|
*/ |
31
|
|
|
public function testSearch(array $request, array $response) |
32
|
|
|
{ |
33
|
|
View Code Duplication |
if (array_key_exists('supported_engines', $request)) { |
34
|
|
|
$engine = $this->getContainer()->getParameter('oro_search.engine'); |
35
|
|
|
if (!in_array($engine, $request['supported_engines'])) { |
36
|
|
|
$this->markTestIncomplete('Test should not be executed on this engine'); |
37
|
|
|
} |
38
|
|
|
unset($request['supported_engines']); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
if (is_null($request['search'])) { |
42
|
|
|
$request['search'] =''; |
43
|
|
|
} |
44
|
|
|
if (is_null($request['offset'])) { |
45
|
|
|
$request['offset'] = self::DEFAULT_VALUE; |
46
|
|
|
} |
47
|
|
|
if (is_null($request['max_results'])) { |
48
|
|
|
$request['max_results'] = self::DEFAULT_VALUE; |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
$result = $this->soapClient->search( |
|
|
|
|
52
|
|
|
$request['search'], |
53
|
|
|
$request['offset'], |
54
|
|
|
$request['max_results'] |
55
|
|
|
); |
56
|
|
|
$result = $this->valueToArray($result); |
57
|
|
|
|
58
|
|
|
$this->assertEquals($response['records_count'], $result['recordsCount']); |
59
|
|
|
$this->assertEquals($response['count'], $result['count']); |
60
|
|
|
|
61
|
|
|
if (empty($result['elements']['item'])) { |
62
|
|
|
$result['elements']['item'] = []; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
// if only one element |
66
|
|
View Code Duplication |
if (empty($result['elements']['item'][0])) { |
67
|
|
|
$result['elements']['item'] = [$result['elements']['item']]; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
// remove ID references |
71
|
|
|
$recordsRequired = !empty($response['soap']['item'][0]['recordTitle']); |
72
|
|
|
foreach (array_keys($result['elements']['item']) as $key) { |
73
|
|
|
unset($result['elements']['item'][$key]['recordId']); |
74
|
|
|
if (!$recordsRequired) { |
75
|
|
|
unset($result['elements']['item'][$key]['recordTitle']); |
76
|
|
|
} |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
$this->assertResultHasItems($response['soap']['item'], $result['elements']['item']); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* Data provider for SOAP API tests |
84
|
|
|
* |
85
|
|
|
* @return array |
86
|
|
|
*/ |
87
|
|
|
public function searchDataProvider() |
88
|
|
|
{ |
89
|
|
|
return $this->getApiRequestsData( |
90
|
|
|
__DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'requests' |
91
|
|
|
); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* @param array $items |
96
|
|
|
* @param array $result |
97
|
|
|
*/ |
98
|
|
|
protected function assertResultHasItems(array $items, array $result) |
99
|
|
|
{ |
100
|
|
|
foreach ($items as $item) { |
101
|
|
|
$this->assertContains($item, $result); |
102
|
|
|
} |
103
|
|
|
} |
104
|
|
|
} |
105
|
|
|
|
If you implement
__call
and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.This is often the case, when
__call
is implemented by a parent class and only the child class knows which methods exist: