Code Duplication    Length = 15-23 lines in 4 locations

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

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

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

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