Code Duplication    Length = 111-116 lines in 2 locations

eZ/Publish/Core/Repository/Tests/Values/ObjectState/ObjectStateGroupTest.php 1 location

@@ 19-129 (lines=111) @@
16
/**
17
 * Test internal integrity of @see \eZ\Publish\Core\Repository\Values\ObjectState\ObjectStateGroup ValueObject.
18
 */
19
class ObjectStateGroupTest extends PHPUnit_Framework_TestCase
20
{
21
    use ValueObjectTestTrait;
22
    use MultiLanguageTestTrait;
23
24
    /**
25
     * Test a new class and default values on properties.
26
     *
27
     * @covers \eZ\Publish\API\Repository\Values\ObjectState\ObjectStateGroup::__construct
28
     */
29
    public function testNewClass()
30
    {
31
        $objectStateGroup = new ObjectStateGroup();
32
33
        $this->assertPropertiesCorrect(
34
            [
35
                'id' => null,
36
                'identifier' => null,
37
                'mainLanguageCode' => null,
38
                'languageCodes' => null,
39
                'names' => [],
40
                'descriptions' => [],
41
            ],
42
            $objectStateGroup
43
        );
44
    }
45
46
    /**
47
     * Test a new class with unified multi language logic properties.
48
     *
49
     * @return \eZ\Publish\Core\Repository\Values\ObjectState\ObjectStateGroup
50
     */
51
    public function testNewClassWithMultiLanguageProperties()
52
    {
53
        $properties = [
54
            'names' => [
55
                'eng-US' => 'Name',
56
                'pol-PL' => 'Nazwa',
57
            ],
58
            'descriptions' => [
59
                'eng-US' => 'Description',
60
                'pol-PL' => 'Opis',
61
            ],
62
            'mainLanguageCode' => 'eng-US',
63
            'prioritizedLanguages' => ['pol-PL', 'eng-US'],
64
        ];
65
66
        $objectStateGroup = new ObjectStateGroup($properties);
67
        $this->assertPropertiesCorrect($properties, $objectStateGroup);
68
69
        // BC test:
70
        self::assertTrue(isset($objectStateGroup->defaultLanguageCode));
71
        self::assertSame('eng-US', $objectStateGroup->defaultLanguageCode);
72
73
        return $objectStateGroup;
74
    }
75
76
    /**
77
     * Test retrieving missing property.
78
     *
79
     * @covers \eZ\Publish\API\Repository\Values\ObjectState\ObjectStateGroup::__get
80
     * @expectedException \eZ\Publish\API\Repository\Exceptions\PropertyNotFoundException
81
     */
82
    public function testMissingProperty()
83
    {
84
        $objectStateGroup = new ObjectStateGroup();
85
        $value = $objectStateGroup->notDefined;
86
        $this->fail('Succeeded getting non existing property');
87
    }
88
89
    /**
90
     * Test setting read only property.
91
     *
92
     * @covers \eZ\Publish\API\Repository\Values\ObjectState\ObjectStateGroup::__set
93
     * @expectedException \eZ\Publish\API\Repository\Exceptions\PropertyReadOnlyException
94
     */
95
    public function testReadOnlyProperty()
96
    {
97
        $objectStateGroup = new ObjectStateGroup();
98
        $objectStateGroup->id = 42;
99
        $this->fail('Succeeded setting read only property');
100
    }
101
102
    /**
103
     * Test if property exists.
104
     *
105
     * @covers \eZ\Publish\API\Repository\Values\ObjectState\ObjectStateGroup::__isset
106
     */
107
    public function testIsPropertySet()
108
    {
109
        $objectStateGroup = new ObjectStateGroup();
110
        $value = isset($objectStateGroup->notDefined);
111
        $this->assertFalse($value);
112
113
        $value = isset($objectStateGroup->id);
114
        $this->assertTrue($value);
115
    }
116
117
    /**
118
     * Test unsetting a property.
119
     *
120
     * @covers \eZ\Publish\API\Repository\Values\ObjectState\ObjectStateGroup::__unset
121
     * @expectedException \eZ\Publish\API\Repository\Exceptions\PropertyReadOnlyException
122
     */
123
    public function testUnsetProperty()
124
    {
125
        $objectStateGroup = new ObjectStateGroup(['id' => 2]);
126
        unset($objectStateGroup->id);
127
        $this->fail('Unsetting read-only property succeeded');
128
    }
129
}
130

eZ/Publish/Core/Repository/Tests/Values/ObjectState/ObjectStateTest.php 1 location

@@ 19-134 (lines=116) @@
16
/**
17
 * Test internal integrity of @see \eZ\Publish\Core\Repository\Values\ObjectState\ObjectState ValueObject.
18
 */
19
class ObjectStateTest extends PHPUnit_Framework_TestCase
20
{
21
    use ValueObjectTestTrait;
22
    use MultiLanguageTestTrait;
23
24
    /**
25
     * Test a new class and default values on properties.
26
     *
27
     * @covers \eZ\Publish\API\Repository\Values\ObjectState\ObjectState::__construct
28
     */
29
    public function testNewClass()
30
    {
31
        $objectState = new ObjectState();
32
33
        $this->assertPropertiesCorrect(
34
            [
35
                'id' => null,
36
                'identifier' => null,
37
                'priority' => null,
38
                'mainLanguageCode' => null,
39
                'languageCodes' => null,
40
                'names' => [],
41
                'descriptions' => [],
42
            ],
43
            $objectState
44
        );
45
    }
46
47
    /**
48
     * Test a new class with unified multi language logic properties.
49
     *
50
     * @return \eZ\Publish\Core\Repository\Values\ObjectState\ObjectState
51
     */
52
    public function testNewClassWithMultiLanguageProperties()
53
    {
54
        $properties = [
55
            'names' => [
56
                'eng-US' => 'Name',
57
                'pol-PL' => 'Nazwa',
58
            ],
59
            'descriptions' => [
60
                'eng-US' => 'Description',
61
                'pol-PL' => 'Opis',
62
            ],
63
            'mainLanguageCode' => 'eng-US',
64
            'prioritizedLanguages' => ['pol-PL', 'eng-US'],
65
        ];
66
67
        $objectState = new ObjectState($properties);
68
        $this->assertPropertiesCorrect($properties, $objectState);
69
70
        // BC test:
71
        self::assertTrue(isset($objectState->defaultLanguageCode));
72
        self::assertSame('eng-US', $objectState->defaultLanguageCode);
73
74
        return $objectState;
75
    }
76
77
    /**
78
     * Test retrieving missing property.
79
     *
80
     * @covers \eZ\Publish\API\Repository\Values\ObjectState\ObjectState::__get
81
     * @covers \eZ\Publish\API\Repository\Values\ObjectState\ObjectStateGroup::__get
82
     * @expectedException \eZ\Publish\API\Repository\Exceptions\PropertyNotFoundException
83
     */
84
    public function testMissingProperty()
85
    {
86
        $objectState = new ObjectState();
87
        $value = $objectState->notDefined;
88
        $this->fail('Succeeded getting non existing property');
89
    }
90
91
    /**
92
     * Test setting read only property.
93
     *
94
     * @covers \eZ\Publish\API\Repository\Values\ObjectState\ObjectState::__set
95
     * @covers \eZ\Publish\API\Repository\Values\ObjectState\ObjectStateGroup::__set
96
     * @expectedException \eZ\Publish\API\Repository\Exceptions\PropertyReadOnlyException
97
     */
98
    public function testReadOnlyProperty()
99
    {
100
        $objectState = new ObjectState();
101
        $objectState->id = 42;
102
        $this->fail('Succeeded setting read only property');
103
    }
104
105
    /**
106
     * Test if property exists.
107
     *
108
     * @covers \eZ\Publish\API\Repository\Values\ObjectState\ObjectState::__isset
109
     * @covers \eZ\Publish\API\Repository\Values\ObjectState\ObjectStateGroup::__isset
110
     */
111
    public function testIsPropertySet()
112
    {
113
        $objectState = new ObjectState();
114
        $value = isset($objectState->notDefined);
115
        $this->assertFalse($value);
116
117
        $value = isset($objectState->id);
118
        $this->assertTrue($value);
119
    }
120
121
    /**
122
     * Test unsetting a property.
123
     *
124
     * @covers \eZ\Publish\API\Repository\Values\ObjectState\ObjectState::__unset
125
     * @covers \eZ\Publish\API\Repository\Values\ObjectState\ObjectStateGroup::__unset
126
     * @expectedException \eZ\Publish\API\Repository\Exceptions\PropertyReadOnlyException
127
     */
128
    public function testUnsetProperty()
129
    {
130
        $objectState = new ObjectState(array('id' => 2));
131
        unset($objectState->id);
132
        $this->fail('Unsetting read-only property succeeded');
133
    }
134
}
135