Code Duplication    Length = 24-34 lines in 3 locations

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

@@ 33-66 (lines=34) @@
30
     * @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException
31
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testCreateContent
32
     */
33
    public function testCreateContentThrowsUnauthorizedException()
34
    {
35
        if ($this->isVersion4()) {
36
            $this->markTestSkipped('This test requires eZ Publish 5');
37
        }
38
39
        $repository = $this->getRepository();
40
41
        $anonymousUserId = $this->generateId('user', 10);
42
        /* BEGIN: Use Case */
43
        // $anonymousUserId is the ID of the "Anonymous User" in an eZ Publish
44
        // demo installation
45
        // Load the user service
46
        $userService = $repository->getUserService();
47
48
        // Set anonymous user
49
        $repository->setCurrentUser($userService->loadUser($anonymousUserId));
50
51
        $contentTypeService = $repository->getContentTypeService();
52
53
        $contentType = $contentTypeService->loadContentTypeByIdentifier('forum');
54
55
        $contentService = $repository->getContentService();
56
57
        $contentCreate = $contentService->newContentCreateStruct($contentType, 'eng-US');
58
        $contentCreate->setField('name', 'Awesome Sindelfingen forum');
59
60
        $contentCreate->remoteId = 'abcdef0123456789abcdef0123456789';
61
        $contentCreate->alwaysAvailable = true;
62
63
        // This call will fail with a "UnauthorizedException"
64
        $contentService->createContent($contentCreate);
65
        /* END: Use Case */
66
    }
67
68
    /**
69
     * Test for the createContent() method.
@@ 969-1001 (lines=33) @@
966
     * @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException
967
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testUpdateContent
968
     */
969
    public function testUpdateContentThrowsUnauthorizedException()
970
    {
971
        $repository = $this->getRepository();
972
        $contentService = $repository->getContentService();
973
974
        $anonymousUserId = $this->generateId('user', 10);
975
        /* BEGIN: Use Case */
976
        // $anonymousUserId is the ID of the "Anonymous User" in an eZ Publish
977
        // demo installation
978
        // $anonymousUserId is the ID of the "Anonymous User" in an eZ Publish
979
        // demo installation
980
        $draftVersion2 = $this->createContentDraftVersion2();
981
982
        // Get VersionInfo instance
983
        $versionInfo = $draftVersion2->getVersionInfo();
984
985
        // Load the user service
986
        $userService = $repository->getUserService();
987
988
        // Set anonymous user
989
        $repository->setCurrentUser($userService->loadUser($anonymousUserId));
990
991
        // Create an update struct and modify some fields
992
        $contentUpdate = $contentService->newContentUpdateStruct();
993
        $contentUpdate->setField('name', 'An awesome² story about ezp.');
994
        $contentUpdate->setField('name', 'An awesome²³ story about ezp.', 'eng-GB');
995
996
        $contentUpdate->initialLanguageCode = 'eng-US';
997
998
        // This call will fail with a "UnauthorizedException"
999
        $contentService->updateContent($versionInfo, $contentUpdate);
1000
        /* END: Use Case */
1001
    }
1002
1003
    /**
1004
     * Test for the publishVersion() method.

eZ/Publish/API/Repository/Tests/ContentServiceTest.php 1 location

@@ 1732-1755 (lines=24) @@
1729
     * @expectedException \eZ\Publish\API\Repository\Exceptions\ContentFieldValidationException
1730
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testUpdateContent
1731
     */
1732
    public function testUpdateContentThrowsContentFieldValidationException()
1733
    {
1734
        $repository = $this->getRepository();
1735
1736
        /* BEGIN: Use Case */
1737
        $contentTypeService = $repository->getContentTypeService();
1738
        $contentService = $repository->getContentService();
1739
1740
        $contentType = $contentTypeService->loadContentTypeByIdentifier('folder');
1741
1742
        $contentCreate = $contentService->newContentCreateStruct($contentType, 'eng-US');
1743
        $contentCreate->setField('name', 'An awesome Sidelfingen folder');
1744
1745
        $draft = $contentService->createContent($contentCreate);
1746
1747
        $contentUpdate = $contentService->newContentUpdateStruct();
1748
        // Violates string length constraint
1749
        $contentUpdate->setField('short_name', str_repeat('a', 200), 'eng-US');
1750
1751
        // Throws ContentFieldValidationException because the string length
1752
        // validation of the field "short_name" fails
1753
        $contentService->updateContent($draft->getVersionInfo(), $contentUpdate);
1754
        /* END: Use Case */
1755
    }
1756
1757
    /**
1758
     * Test for the updateContent() method.