Code Duplication    Length = 39-39 lines in 2 locations

eZ/Publish/API/Repository/Tests/ContentTypeServiceTest.php 2 locations

@@ 4105-4143 (lines=39) @@
4102
     * @see \eZ\Publish\API\Repository\ContentTypeService::assignContentTypeGroup()
4103
     * @depends eZ\Publish\API\Repository\Tests\ContentTypeServiceTest::testAssignContentTypeGroup
4104
     */
4105
    public function testAssignContentTypeGroupInTransactionWithRollback()
4106
    {
4107
        $repository = $this->getRepository();
4108
4109
        /* BEGIN: Use Case */
4110
        $contentTypeService = $repository->getContentTypeService();
4111
4112
        $mediaGroup = $contentTypeService->loadContentTypeGroupByIdentifier('Media');
4113
        $folderType = $contentTypeService->loadContentTypeByIdentifier('folder');
4114
4115
        // Start a new transaction
4116
        $repository->beginTransaction();
4117
4118
        try {
4119
            // Assign group to content type
4120
            $contentTypeService->assignContentTypeGroup($folderType, $mediaGroup);
4121
        } catch (Exception $e) {
4122
            // Cleanup hanging transaction on error
4123
            $repository->rollback();
4124
            throw $e;
4125
        }
4126
4127
        // Rollback all changes
4128
        $repository->rollback();
4129
4130
        // Load all content types assigned to media group
4131
        $contentTypes = $contentTypeService->loadContentTypes($mediaGroup);
4132
4133
        $contentTypeIds = [];
4134
        foreach ($contentTypes as $contentType) {
4135
            $contentTypeIds[] = $contentType->id;
4136
        }
4137
        /* END: Use Case */
4138
4139
        $this->assertFalse(
4140
            in_array($folderType->id, $contentTypeIds),
4141
            'Folder content type is still in media group after rollback.'
4142
        );
4143
    }
4144
4145
    /**
4146
     * Test for the assignContentTypeGroup() method.
@@ 4151-4189 (lines=39) @@
4148
     * @see \eZ\Publish\API\Repository\ContentTypeService::assignContentTypeGroup()
4149
     * @depends eZ\Publish\API\Repository\Tests\ContentTypeServiceTest::testAssignContentTypeGroup
4150
     */
4151
    public function testAssignContentTypeGroupInTransactionWithCommit()
4152
    {
4153
        $repository = $this->getRepository();
4154
4155
        /* BEGIN: Use Case */
4156
        $contentTypeService = $repository->getContentTypeService();
4157
4158
        $mediaGroup = $contentTypeService->loadContentTypeGroupByIdentifier('Media');
4159
        $folderType = $contentTypeService->loadContentTypeByIdentifier('folder');
4160
4161
        // Start a new transaction
4162
        $repository->beginTransaction();
4163
4164
        try {
4165
            // Assign group to content type
4166
            $contentTypeService->assignContentTypeGroup($folderType, $mediaGroup);
4167
4168
            // Commit all changes
4169
            $repository->commit();
4170
        } catch (Exception $e) {
4171
            // Cleanup hanging transaction on error
4172
            $repository->rollback();
4173
            throw $e;
4174
        }
4175
4176
        // Load all content types assigned to media group
4177
        $contentTypes = $contentTypeService->loadContentTypes($mediaGroup);
4178
4179
        $contentTypeIds = [];
4180
        foreach ($contentTypes as $contentType) {
4181
            $contentTypeIds[] = $contentType->id;
4182
        }
4183
        /* END: Use Case */
4184
4185
        $this->assertTrue(
4186
            in_array($folderType->id, $contentTypeIds),
4187
            'Folder content type not in media group after commit.'
4188
        );
4189
    }
4190
4191
    /**
4192
     * Test for the isContentTypeUsed() method.