Completed
Push — master ( aff5fa...b0939b )
by Łukasz
19:47
created

SelectionIntegrationTest::createContentType()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 58

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 58
rs 8.9163
c 0
b 0
f 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
/**
4
 * File contains: eZ\Publish\SPI\Tests\FieldType\SelectionIntegrationTest 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\SPI\Tests\FieldType;
10
11
use eZ\Publish\Core\Persistence\Legacy;
12
use eZ\Publish\Core\FieldType\FieldSettings;
13
use eZ\Publish\Core\FieldType;
14
use eZ\Publish\SPI\Persistence\Content;
15
16
/**
17
 * Integration test for legacy storage field types.
18
 *
19
 * @group integration
20
 */
21
class SelectionIntegrationTest extends BaseIntegrationTest
22
{
23
    /**
24
     * Get name of tested field type.
25
     *
26
     * @return string
27
     */
28
    public function getTypeName()
29
    {
30
        return 'ezselection';
31
    }
32
33
    /**
34
     * Get handler with required custom field types registered.
35
     *
36
     * @return Handler
37
     */
38
    public function getCustomHandler()
39
    {
40
        $fieldType = new FieldType\Selection\Type();
41
        $fieldType->setTransformationProcessor($this->getTransformationProcessor());
42
        $languageService = self::$container->get('ezpublish.api.service.language');
43
44
        return $this->getHandler(
45
            'ezselection',
46
            $fieldType,
47
            new Legacy\Content\FieldValue\Converter\SelectionConverter($languageService),
48
            new FieldType\NullStorage()
49
        );
50
    }
51
52
    /**
53
     * Returns the FieldTypeConstraints to be used to create a field definition
54
     * of the FieldType under test.
55
     *
56
     * @return \eZ\Publish\SPI\Persistence\Content\FieldTypeConstraints
57
     */
58
    public function getTypeConstraints()
59
    {
60
        return new Content\FieldTypeConstraints(
61
            array(
62
                'validators' => null,
63
                'fieldSettings' => new FieldSettings(
64
                    array(
65
                        'isMultiple' => true,
66
                        'options' => array(
67
                            1 => 'First',
68
                            2 => 'Second',
69
                            3 => 'Sindelfingen',
70
                        ),
71
                        'multilingualOptions' => array(
72
                            'ger-DE' => array(
73
                                1 => 'Zuerst',
74
                                2 => 'Zweite',
75
                            ),
76
                            'eng-US' => array(
77
                                1 => 'ML First',
78
                                2 => 'ML Second',
79
                                3 => 'ML Sindelfingen',
80
                            ),
81
                        ),
82
                    )
83
                ),
84
            )
85
        );
86
    }
87
88
    /**
89
     * Get field definition data values.
90
     *
91
     * This is a PHPUnit data provider
92
     *
93
     * @return array
94
     */
95
    public function getFieldDefinitionData()
96
    {
97
        return array(
98
            array('fieldType', 'ezselection'),
99
            array(
100
                'fieldTypeConstraints',
101
                new Content\FieldTypeConstraints(
102
                    array(
103
                        'validators' => null,
104
                        'fieldSettings' => new FieldSettings(
105
                            array(
106
                                'isMultiple' => true,
107
                                'options' => array(
108
                                    1 => 'ML First',
109
                                    2 => 'ML Second',
110
                                    3 => 'ML Sindelfingen',
111
                                ),
112
                                'multilingualOptions' => array(
113
                                    'ger-DE' => array(
114
                                        1 => 'Zuerst',
115
                                        2 => 'Zweite',
116
                                    ),
117
                                    'eng-US' => array(
118
                                        1 => 'ML First',
119
                                        2 => 'ML Second',
120
                                        3 => 'ML Sindelfingen',
121
                                    ),
122
                                ),
123
                            )
124
                        ),
125
                    )
126
                ),
127
            ),
128
        );
129
    }
130
131
    /**
132
     * Get initial field value.
133
     *
134
     * @return \eZ\Publish\SPI\Persistence\Content\FieldValue
135
     */
136 View Code Duplication
    public function getInitialValue()
137
    {
138
        return new Content\FieldValue(
139
            array(
140
                'data' => array(1, 3),
141
                'externalData' => null,
142
                'sortKey' => '1-3',
143
            )
144
        );
145
    }
146
147
    /**
148
     * Get update field value.
149
     *
150
     * Use to update the field
151
     *
152
     * @return \eZ\Publish\SPI\Persistence\Content\FieldValue
153
     */
154 View Code Duplication
    public function getUpdatedValue()
155
    {
156
        return new Content\FieldValue(
157
            array(
158
                'data' => array(2),
159
                'externalData' => null,
160
                'sortKey' => '2',
161
            )
162
        );
163
    }
164
165
    /**
166
     * Performs the creation of the content type with a field of the field type
167
     * under test.
168
     *
169
     * @return \eZ\Publish\SPI\Persistence\Content\Type
170
     */
171
    protected function createContentType()
172
    {
173
        $createStruct = new Content\Type\CreateStruct(
174
            [
175
                'name' => [
176
                    'eng-US' => 'Test',
177
                    'ger-DE' => 'Test NOR',
178
                ],
179
                'identifier' => 'test-' . $this->getTypeName(),
180
                'status' => 0,
181
                'creatorId' => 14,
182
                'created' => time(),
183
                'modifierId' => 14,
184
                'modified' => time(),
185
                'initialLanguageId' => 2,
186
                'remoteId' => 'abcdef',
187
            ]
188
        );
189
190
        $createStruct->fieldDefinitions = array(
191
            new Content\Type\FieldDefinition(
192
                [
193
                    'name' => [
194
                        'eng-US' => 'Name',
195
                        'ger-DE' => 'Name NOR',
196
                    ],
197
                    'identifier' => 'name',
198
                    'fieldGroup' => 'main',
199
                    'position' => 1,
200
                    'fieldType' => 'ezstring',
201
                    'isTranslatable' => false,
202
                    'isRequired' => true,
203
                    'mainLanguageCode' => 'eng-US',
204
                ]
205
            ),
206
            new Content\Type\FieldDefinition(
207
                [
208
                    'name' => [
209
                        'eng-US' => 'Data',
210
                        'ger-DE' => 'Data NOR',
211
                    ],
212
                    'identifier' => 'data',
213
                    'fieldGroup' => 'main',
214
                    'position' => 2,
215
                    'fieldType' => $this->getTypeName(),
216
                    'isTranslatable' => false,
217
                    'isRequired' => true,
218
                    'fieldTypeConstraints' => $this->getTypeConstraints(),
219
                    'mainLanguageCode' => 'eng-US',
220
                ]
221
            ),
222
        );
223
224
        $handler = $this->getCustomHandler();
225
        $contentTypeHandler = $handler->contentTypeHandler();
226
227
        return $contentTypeHandler->create($createStruct);
228
    }
229
}
230