Code Duplication    Length = 15-23 lines in 4 locations

eZ/Publish/Core/Repository/Tests/Service/Integration/ContentBase.php 3 locations

@@ 1056-1074 (lines=19) @@
1053
     *
1054
     * @return array
1055
     */
1056
    public function testCreateContentThrowsContentValidationExceptionFieldDefinitionUnexisting()
1057
    {
1058
        $testContentType = $this->createTestContentType();
1059
1060
        /* BEGIN: Use Case */
1061
        $contentService = $this->repository->getContentService();
1062
1063
        $contentCreate = $contentService->newContentCreateStruct($testContentType, 'eng-GB');
1064
        $contentCreate->setField('test_required_empty', 'value for field definition with empty default value');
1065
        $contentCreate->setField('humpty_dumpty', 'no such field definition');
1066
        $contentCreate->sectionId = 1;
1067
        $contentCreate->ownerId = 14;
1068
        $contentCreate->remoteId = 'abcdef0123456789abcdef0123456789';
1069
        $contentCreate->alwaysAvailable = true;
1070
1071
        // Throws an exception because field definition with identifier "humpty_dumpty" does not exist
1072
        $contentService->createContent($contentCreate);
1073
        /* END: Use Case */
1074
    }
1075
1076
    /**
1077
     * Test for the createContent() method.
@@ 1084-1103 (lines=20) @@
1081
     *
1082
     * @return array
1083
     */
1084
    public function testCreateContentThrowsContentValidationExceptionUntranslatableField()
1085
    {
1086
        $testContentType = $this->createTestContentType();
1087
1088
        /* BEGIN: Use Case */
1089
        $contentService = $this->repository->getContentService();
1090
1091
        $contentCreate = $contentService->newContentCreateStruct($testContentType, 'eng-GB');
1092
        $contentCreate->setField('test_required_empty', 'value for field definition with empty default value');
1093
        $contentCreate->setField('test_untranslatable', 'Bandersnatch', 'eng-US');
1094
        $contentCreate->sectionId = 1;
1095
        $contentCreate->ownerId = 14;
1096
        $contentCreate->remoteId = 'abcdef0123456789abcdef0123456789';
1097
        $contentCreate->alwaysAvailable = true;
1098
1099
        // Throws an exception because translation was given for a untranslatable field
1100
        // Note that it is still permissible to set untranslatable field with main language
1101
        $contentService->createContent($contentCreate);
1102
        /* END: Use Case */
1103
    }
1104
1105
    /**
1106
     * Test for the createContent() method.
@@ 1138-1160 (lines=23) @@
1135
     * @covers \eZ\Publish\Core\Repository\ContentService::createContent
1136
     * @expectedException \eZ\Publish\API\Repository\Exceptions\ContentFieldValidationException
1137
     */
1138
    public function testCreateContentThrowsContentFieldValidationException()
1139
    {
1140
        $testContentType = $this->createTestContentType();
1141
1142
        /* BEGIN: Use Case */
1143
        $contentService = $this->repository->getContentService();
1144
1145
        $contentCreate = $contentService->newContentCreateStruct($testContentType, 'eng-GB');
1146
        $contentCreate->setField(
1147
            'test_required_empty',
1148
            'a string that is too long and will not validate 12345678901234567890123456789012345678901234567890'
1149
        );
1150
        $contentCreate->setField('test_translatable', 'and thumbs opposable', 'eng-US');
1151
        $contentCreate->sectionId = 1;
1152
        $contentCreate->ownerId = 14;
1153
        $contentCreate->remoteId = 'abcdef0123456789abcdef0123456789';
1154
        $contentCreate->alwaysAvailable = true;
1155
1156
        // Throws an exception because "test_required_empty" field value is too long and fails
1157
        // field definition's string length validator
1158
        $contentService->createContent($contentCreate);
1159
        /* END: Use Case */
1160
    }
1161
1162
    /**
1163
     * Test for the newContentMetadataUpdateStruct() method.

eZ/Publish/Core/Repository/Tests/Service/Integration/UserBase.php 1 location

@@ 159-173 (lines=15) @@
156
     *
157
     * @covers \eZ\Publish\API\Repository\UserService::createUserGroup
158
     */
159
    public function testCreateUserGroup()
160
    {
161
        $userService = $this->repository->getUserService();
162
163
        $parentGroup = $userService->loadUserGroup(4);
164
        $userGroupCreateStruct = $userService->newUserGroupCreateStruct('eng-GB');
165
        $userGroupCreateStruct->ownerId = 14;
166
        $userGroupCreateStruct->sectionId = 1;
167
        $userGroupCreateStruct->setField('name', 'New group');
168
        $userGroupCreateStruct->setField('description', 'This is a new group');
169
170
        $newGroup = $userService->createUserGroup($userGroupCreateStruct, $parentGroup);
171
172
        self::assertInstanceOf('\\eZ\\Publish\\API\\Repository\\Values\\User\\UserGroup', $newGroup);
173
    }
174
175
    /**
176
     * Test creating new user group throwing ContentFieldValidationException.