1 | <?php |
||
11 | use stdClass; |
||
12 | |||
13 | class ViewTest extends TestCase |
||
14 | { |
||
15 | /** @var array */ |
||
16 | private static $createdContentRemoteIds = []; |
||
17 | |||
18 | /** |
||
19 | * Covers POST /views. |
||
20 | * |
||
21 | * @dataProvider providerForTestViewRequest |
||
22 | * |
||
23 | * @param string $body |
||
24 | * @param string $format |
||
25 | * @param int $expectedResultsCount |
||
26 | * @param \stdClass[] $contentDataList list of items containing name and remoteId properties |
||
27 | */ |
||
28 | public function testViewRequest($body, $format, $expectedResultsCount, array $contentDataList) |
||
29 | { |
||
30 | $this->createTestContentItems($contentDataList); |
||
31 | |||
32 | // search for Content |
||
33 | $request = $this->createHttpRequest( |
||
34 | 'POST', |
||
35 | '/api/ezp/v2/views', |
||
36 | "ViewInput+{$format}", |
||
37 | 'View+json' |
||
38 | ); |
||
39 | $request->setContent($body); |
||
40 | $response = $this->sendHttpRequest($request); |
||
41 | $responseData = json_decode($response->getContent(), true); |
||
42 | |||
43 | if (isset($responseData['ErrorMessage'])) { |
||
44 | self::fail(var_export($responseData, true)); |
||
45 | } |
||
46 | |||
47 | self::assertEquals($expectedResultsCount, $responseData['View']['Result']['count']); |
||
48 | } |
||
49 | |||
50 | /** |
||
51 | * Data provider for testViewRequestWithOrStatement. |
||
52 | * |
||
53 | * @return array |
||
54 | */ |
||
55 | public function providerForTestViewRequest() |
||
56 | { |
||
57 | $foo = new stdClass(); |
||
58 | $foo->name = uniqid('View test content foo'); |
||
59 | $foo->remoteId = md5($foo->name); |
||
60 | |||
61 | $bar = new stdClass(); |
||
62 | $bar->name = uniqid('View test content bar'); |
||
63 | $bar->remoteId = md5($bar->name); |
||
64 | |||
65 | return [ |
||
66 | [ |
||
67 | <<< XML |
||
68 | <?xml version="1.0" encoding="UTF-8"?> |
||
69 | <ViewInput> |
||
70 | <identifier>TitleView</identifier> |
||
71 | <Query> |
||
72 | <Filter> |
||
73 | <OR> |
||
74 | <ContentRemoteIdCriterion>{$foo->remoteId}</ContentRemoteIdCriterion> |
||
75 | <ContentRemoteIdCriterion>{$bar->remoteId}</ContentRemoteIdCriterion> |
||
76 | </OR> |
||
77 | </Filter> |
||
78 | <limit>10</limit> |
||
79 | <offset>0</offset> |
||
80 | </Query> |
||
81 | </ViewInput> |
||
82 | XML, |
||
83 | 'xml', |
||
84 | 2, |
||
85 | [$foo, $bar], |
||
86 | ], |
||
87 | [ |
||
88 | <<< JSON |
||
89 | { |
||
90 | "ViewInput": { |
||
91 | "identifier": "TitleView", |
||
92 | "Query": { |
||
93 | "Filter": { |
||
94 | "OR": { |
||
187 |