Code Duplication    Length = 33-34 lines in 2 locations

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

@@ 31-64 (lines=34) @@
28
     * @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException
29
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testCreateContent
30
     */
31
    public function testCreateContentThrowsUnauthorizedException()
32
    {
33
        if ($this->isVersion4()) {
34
            $this->markTestSkipped('This test requires eZ Publish 5');
35
        }
36
37
        $repository = $this->getRepository();
38
39
        $anonymousUserId = $this->generateId('user', 10);
40
        /* BEGIN: Use Case */
41
        // $anonymousUserId is the ID of the "Anonymous User" in an eZ Publish
42
        // demo installation
43
        // Load the user service
44
        $userService = $repository->getUserService();
45
46
        // Set anonymous user
47
        $repository->setCurrentUser($userService->loadUser($anonymousUserId));
48
49
        $contentTypeService = $repository->getContentTypeService();
50
51
        $contentType = $contentTypeService->loadContentTypeByIdentifier('forum');
52
53
        $contentService = $repository->getContentService();
54
55
        $contentCreate = $contentService->newContentCreateStruct($contentType, 'eng-US');
56
        $contentCreate->setField('name', 'Awesome Sindelfingen forum');
57
58
        $contentCreate->remoteId = 'abcdef0123456789abcdef0123456789';
59
        $contentCreate->alwaysAvailable = true;
60
61
        // This call will fail with a "UnauthorizedException"
62
        $contentService->createContent($contentCreate);
63
        /* END: Use Case */
64
    }
65
66
    /**
67
     * Test for the createContent() method.
@@ 944-976 (lines=33) @@
941
     * @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException
942
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testUpdateContent
943
     */
944
    public function testUpdateContentThrowsUnauthorizedException()
945
    {
946
        $repository = $this->getRepository();
947
        $contentService = $repository->getContentService();
948
949
        $anonymousUserId = $this->generateId('user', 10);
950
        /* BEGIN: Use Case */
951
        // $anonymousUserId is the ID of the "Anonymous User" in an eZ Publish
952
        // demo installation
953
        // $anonymousUserId is the ID of the "Anonymous User" in an eZ Publish
954
        // demo installation
955
        $draftVersion2 = $this->createContentDraftVersion2();
956
957
        // Get VersionInfo instance
958
        $versionInfo = $draftVersion2->getVersionInfo();
959
960
        // Load the user service
961
        $userService = $repository->getUserService();
962
963
        // Set anonymous user
964
        $repository->setCurrentUser($userService->loadUser($anonymousUserId));
965
966
        // Create an update struct and modify some fields
967
        $contentUpdate = $contentService->newContentUpdateStruct();
968
        $contentUpdate->setField('name', 'An awesome² story about ezp.');
969
        $contentUpdate->setField('name', 'An awesome²³ story about ezp.', 'eng-GB');
970
971
        $contentUpdate->initialLanguageCode = 'eng-US';
972
973
        // This call will fail with a "UnauthorizedException"
974
        $contentService->updateContent($versionInfo, $contentUpdate);
975
        /* END: Use Case */
976
    }
977
978
    /**
979
     * Test for the publishVersion() method.