Completed
Push — master ( 745b87...dded74 )
by André
13:55
created

RelationTest::testToStorageFieldDefinition()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 32
Code Lines 16

Duplication

Lines 32
Ratio 100 %

Importance

Changes 0
Metric Value
cc 1
eloc 16
nc 1
nop 0
dl 32
loc 32
rs 8.8571
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * File containing the RelationTest 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\Publish\Core\Persistence\Legacy\Tests\Content\FieldValue\Converter;
10
11
use eZ\Publish\Core\FieldType\RelationList\Type;
12
use eZ\Publish\Core\Persistence\Legacy\Content\FieldValue\Converter\RelationConverter;
13
use eZ\Publish\Core\Persistence\Legacy\Content\StorageFieldDefinition;
14
use eZ\Publish\SPI\Persistence\Content\Type\FieldDefinition as PersistenceFieldDefinition;
15
use eZ\Publish\SPI\Persistence\Content\FieldTypeConstraints;
16
use PHPUnit_Framework_TestCase;
17
18
/**
19
 * Test case for Relation converter in Legacy storage.
20
 */
21
class RelationTest extends PHPUnit_Framework_TestCase
22
{
23
    /**
24
     * @var \PHPUnit_Framework_MockObject_MockObject|\eZ\Publish\Core\Persistence\Legacy\Content\FieldValue\Converter\RelationConverter
25
     */
26
    protected $converter;
27
28
    protected function setUp()
29
    {
30
        parent::setUp();
31
        $this->converter = new RelationConverter();
32
    }
33
34
    /**
35
     * @group fieldType
36
     * @group relationlist
37
     */
38 View Code Duplication
    public function testToStorageFieldDefinition()
39
    {
40
        $fieldDefinition = new PersistenceFieldDefinition(
41
            [
42
                'fieldTypeConstraints' => new FieldTypeConstraints(
43
                    [
44
                        'fieldSettings' => [
45
                            'selectionMethod' => Type::SELECTION_BROWSE,
46
                            'selectionRoot' => 12345,
47
                            'selectionContentTypes' => ['article', 'blog_post'],
48
                        ],
49
                    ]
50
                ),
51
            ]
52
        );
53
54
        $expectedStorageFieldDefinition = new StorageFieldDefinition();
55
        $expectedStorageFieldDefinition->dataText5 = <<<EOT
56
<?xml version="1.0" encoding="utf-8"?>
57
<related-objects><constraints><allowed-class contentclass-identifier="article"/><allowed-class contentclass-identifier="blog_post"/></constraints><selection_type value="0"/><contentobject-placement node-id="12345"/></related-objects>
58
59
EOT;
60
61
        $actualStorageFieldDefinition = new StorageFieldDefinition();
62
63
        $this->converter->toStorageFieldDefinition($fieldDefinition, $actualStorageFieldDefinition);
64
65
        $this->assertEquals(
66
            $expectedStorageFieldDefinition,
67
            $actualStorageFieldDefinition
68
        );
69
    }
70
}
71