Code Duplication    Length = 26-27 lines in 2 locations

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

@@ 947-972 (lines=26) @@
944
     * @see \eZ\Publish\API\Repository\ContentTypeService::createContentType()
945
     * @depends eZ\Publish\API\Repository\Tests\ContentTypeServiceTest::testCreateContentType
946
     */
947
    public function testCreateContentTypeThrowsInvalidArgumentExceptionDuplicateIdentifier()
948
    {
949
        $this->expectException(\eZ\Publish\API\Repository\Exceptions\InvalidArgumentException::class);
950
        $this->expectExceptionMessage('Argument \'$contentTypeCreateStruct\' is invalid: Another Content Type with identifier \'folder\' exists');
951
952
        $repository = $this->getRepository();
953
954
        /* BEGIN: Use Case */
955
        $contentTypeService = $repository->getContentTypeService();
956
957
        $typeCreate = $contentTypeService->newContentTypeCreateStruct('folder');
958
        $typeCreate->mainLanguageCode = 'eng-GB';
959
        $typeCreate->names = ['eng-GB' => 'Article'];
960
961
        $firstFieldCreate = $contentTypeService->newFieldDefinitionCreateStruct('title', 'ezstring');
962
        $typeCreate->addFieldDefinition($firstFieldCreate);
963
964
        $groups = [
965
            $contentTypeService->loadContentTypeGroupByIdentifier('Media'),
966
            $contentTypeService->loadContentTypeGroupByIdentifier('Setup'),
967
        ];
968
969
        // Throws exception, since type "folder" exists
970
        $contentTypeService->createContentType($typeCreate, $groups);
971
        /* END: Use Case */
972
    }
973
974
    /**
975
     * Test for the createContentType() method trying to create Content Type with already existing
@@ 981-1007 (lines=27) @@
978
     * @covers \eZ\Publish\API\Repository\ContentTypeService::createContentType()
979
     * @depends eZ\Publish\API\Repository\Tests\ContentTypeServiceTest::testCreateContentType
980
     */
981
    public function testCreateContentTypeThrowsInvalidArgumentExceptionDuplicateRemoteId()
982
    {
983
        $this->expectException(\eZ\Publish\API\Repository\Exceptions\InvalidArgumentException::class);
984
        $this->expectExceptionMessage('Another Content Type with remoteId \'a3d405b81be900468eb153d774f4f0d2\' exists');
985
986
        $repository = $this->getRepository();
987
988
        /* BEGIN: Use Case */
989
        $contentTypeService = $repository->getContentTypeService();
990
991
        $typeCreate = $contentTypeService->newContentTypeCreateStruct('news-article');
992
        $typeCreate->remoteId = 'a3d405b81be900468eb153d774f4f0d2';
993
        $typeCreate->mainLanguageCode = 'eng-GB';
994
        $typeCreate->names = ['eng-GB' => 'Article'];
995
996
        $firstFieldCreate = $contentTypeService->newFieldDefinitionCreateStruct('title', 'ezstring');
997
        $typeCreate->addFieldDefinition($firstFieldCreate);
998
999
        $groups = [
1000
            $contentTypeService->loadContentTypeGroupByIdentifier('Media'),
1001
            $contentTypeService->loadContentTypeGroupByIdentifier('Setup'),
1002
        ];
1003
1004
        // Throws exception, since "folder" type has this remote ID
1005
        $contentTypeService->createContentType($typeCreate, $groups);
1006
        /* END: Use Case */
1007
    }
1008
1009
    /**
1010
     * Test for the createContentType() method creating content with duplicate field identifiers.