Completed
Push — ezp26297-rest_embedding_http_c... ( 6dcd26...7b4207 )
by
unknown
44:13 queued 12:57
created

BinaryContentTest::createImage()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 45
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 13
nc 1
nop 0
dl 0
loc 45
rs 8.8571
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * File containing the Functional\BinaryContentTest 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
 * @version //autogentag//
10
 */
11
namespace eZ\Bundle\EzPublishRestBundle\Tests\Functional;
12
13
use eZ\Bundle\EzPublishRestBundle\Tests\Functional\TestCase as RESTFunctionalTestCase;
14
use eZ\Publish\SPI\Variation\Values\ImageVariation;
15
16
class BinaryContentTest extends RESTFunctionalTestCase
17
{
18
    const IMAGE_FILE = __DIR__ . '/../../../../Publish/API/Repository/Tests/FieldType/_fixtures/image.jpg';
19
20
    public function testGetImageVariation()
21
    {
22
        $imageArray = $this->createImage();
23
        $variationHref = $imageArray['CurrentVersion']['Version']['Fields']['field'][1]['fieldValue']['variations']['large']['href'];
24
25
        $response = $this->sendHttpRequest(
26
            $this->createHttpRequest('GET', $variationHref, '', 'ContentImageVariation+json')
27
        );
28
29
        $this->assertHttpResponseCodeEquals($response, 200);
30
        $this->assertHttpResponseHasCacheTags(
31
            $response,
32
            [
33
                'content-' . $imageArray['_id'],
34
                'content-type-5',
35
                // we can't test the location, as we don't have it. Test it without the id ?
36
            ]
37
        );
38
    }
39
40
    private function createImage()
41
    {
42
        $name = uniqid('createImage');
43
        $remoteId = md5($name);
44
        $imageBase64 = base64_encode(file_get_contents(self::IMAGE_FILE));
45
        $fileSize = filesize(self::IMAGE_FILE);
46
47
        $xml = <<< XML
48
<?xml version="1.0" encoding="UTF-8"?>
49
<ContentCreate>
50
  <ContentType href="/api/ezp/v2/content/types/5" />
51
  <mainLanguageCode>eng-GB</mainLanguageCode>
52
  <LocationCreate>
53
    <ParentLocation href="/api/ezp/v2/content/locations/1/2" />
54
    <priority>0</priority>
55
    <hidden>false</hidden>
56
    <sortField>PATH</sortField>
57
    <sortOrder>ASC</sortOrder>
58
  </LocationCreate>
59
  <Section href="/api/ezp/v2/content/sections/1" />
60
  <alwaysAvailable>true</alwaysAvailable>
61
  <remoteId>{$remoteId}</remoteId>
62
  <User href="/api/ezp/v2/user/users/14" />
63
  <modificationDate>2012-09-30T12:30:00</modificationDate>
64
  <fields>
65
    <field>
66
      <fieldDefinitionIdentifier>name</fieldDefinitionIdentifier>
67
      <languageCode>eng-GB</languageCode>
68
      <fieldValue>{$name}</fieldValue>
69
    </field>
70
    <field>
71
      <fieldDefinitionIdentifier>image</fieldDefinitionIdentifier>
72
      <languageCode>eng-GB</languageCode>
73
      <fieldValue>
74
        <value key="fileName">test-image.jpg</value>
75
        <value key="fileSize">{$fileSize}</value>
76
        <value key="alternativeText">Test</value>
77
        <value key="data"><![CDATA[{$imageBase64}]]></value>
78
      </fieldValue>
79
    </field>
80
  </fields>
81
</ContentCreate>
82
XML;
83
        return $this->createContent($xml);
84
    }
85
}
86