Completed
Push — 6.7 ( ac76ae...75fc90 )
by
unknown
52:22 queued 30:20
created

ViewTest   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 73
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
dl 0
loc 73
rs 10
c 0
b 0
f 0
wmc 2
lcom 1
cbo 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A testViewRequestWithOrStatement() 0 30 1
A testViewRequestWithAndStatement() 0 31 1
1
<?php
2
3
/**
4
 * File containing the Functional\ViewTest class.
5
 *
6
 * @copyright Copyright (C) eZ Systems AS. All rights reserved.
7
 * @license For full copyright and license information view LICENSE file distributed with this source code.
8
 */
9
namespace eZ\Bundle\EzPublishRestBundle\Tests\Functional;
10
11
class ViewTest extends TestCase
12
{
13
    /**
14
     * Covers POST /views.
15
     */
16
    public function testViewRequestWithOrStatement()
17
    {
18
        $fooRemoteId = md5('View test content foo');
19
        $barRemoteId = md5('View test content bar');
20
        $this->createFolder('View test content foo', '/api/ezp/v2/content/locations/1/2', $fooRemoteId);
21
        $this->createFolder('View test content bar', '/api/ezp/v2/content/locations/1/2', $barRemoteId);
22
23
        $request = $this->createHttpRequest('POST', '/api/ezp/v2/views', 'ViewInput+xml', 'View+json');
24
        $body = <<< XML
25
<?xml version="1.0" encoding="UTF-8"?>
26
<ViewInput>
27
  <identifier>TitleView</identifier>
28
  <Query>
29
    <Filter>
30
        <OR>
31
            <ContentRemoteIdCriterion>{$fooRemoteId}</ContentRemoteIdCriterion>
32
            <ContentRemoteIdCriterion>{$barRemoteId}</ContentRemoteIdCriterion>
33
        </OR>
34
    </Filter>
35
    <limit>10</limit>
36
    <offset>0</offset>
37
  </Query>
38
</ViewInput>
39
XML;
40
        $request->setContent($body);
41
        $response = $this->sendHttpRequest($request);
42
        $responseData = json_decode($response->getContent(), true);
43
44
        self::assertEquals(2, $responseData['View']['Result']['count']);
45
    }
46
47
    /**
48
     * Covers POST /views.
49
     *
50
     * @depends testViewRequestWithOrStatement
51
     */
52
    public function testViewRequestWithAndStatement()
53
    {
54
        $fooRemoteId = md5('View test content foo');
55
        $barRemoteId = md5('View test content bar');
56
57
        $request = $this->createHttpRequest('POST', '/api/ezp/v2/views', 'ViewInput+xml', 'View+json');
58
        $body = <<< XML
59
<?xml version="1.0" encoding="UTF-8"?>
60
<ViewInput>
61
  <identifier>TitleView</identifier>
62
  <Query>
63
    <Filter>
64
        <AND>
65
            <OR>
66
                <ContentRemoteIdCriterion>{$fooRemoteId}</ContentRemoteIdCriterion>
67
                <ContentRemoteIdCriterion>{$barRemoteId}</ContentRemoteIdCriterion>
68
            </OR>
69
            <ContentRemoteIdCriterion>{$fooRemoteId}</ContentRemoteIdCriterion>
70
        </AND>
71
    </Filter>
72
    <limit>10</limit>
73
    <offset>0</offset>
74
  </Query>
75
</ViewInput>
76
XML;
77
        $request->setContent($body);
78
        $response = $this->sendHttpRequest($request);
79
        $responseData = json_decode($response->getContent(), true);
80
81
        self::assertEquals(1, $responseData['View']['Result']['count']);
82
    }
83
}
84