Completed
Push — ezp26352-skip_csrf_check_on_re... ( 19f37a )
by
unknown
36:29
created

ResourceEmbeddingTest::testEmbed()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 16
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 10
nc 1
nop 0
dl 0
loc 16
rs 9.4285
c 0
b 0
f 0
1
<?php
2
/**
3
 * @copyright Copyright (C) eZ Systems AS. All rights reserved.
4
 * @license For full copyright and license information view LICENSE file distributed with this source code.
5
 */
6
namespace eZ\Bundle\EzPublishRestBundle\Tests\Functional;
7
8
use eZ\Bundle\EzPublishRestBundle\Tests\Functional\TestCase as RESTFunctionalTestCase;
9
use eZ\Publish\Core\REST\Common\Tests\AssertXmlTagTrait;
10
11
class ResourceEmbeddingTest extends RESTFunctionalTestCase
12
{
13
    use AssertXmlTagTrait;
14
15
    public function testEmbed()
16
    {
17
        $request = $this->createHttpRequest('GET', '/api/ezp/v2/content/objects/1');
18
        $request->addHeader('x-ez-embed-value: Content.MainLocation,Content.Owner.Section');
19
20
        $response = $this->sendHttpRequest($request);
21
22
        self::assertHttpResponseCodeEquals($response, 200);
23
24
        $doc = new \DOMDocument();
25
        $doc->loadXML($response->getContent());
26
27
        $this->assertXPath($doc, '/Content/MainLocation/id');
28
        $this->assertXPath($doc, '/Content/Owner/name');
29
        $this->assertXPath($doc, '/Content/Owner/Section/sectionId');
30
    }
31
32
    protected function assertXPath(\DOMDocument $document, $xpathExpression)
33
    {
34
        $xpath = new \DOMXPath($document);
35
36
        $this->assertTrue(
37
            $xpath->evaluate("boolean({$xpathExpression})"),
38
            "XPath expression '{$xpathExpression}' resulted in an empty node set."
39
        );
40
    }
41
}
42