Code Duplication    Length = 34-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.
@@ 926-959 (lines=34) @@
923
     * @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException
924
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testUpdateContent
925
     */
926
    public function testUpdateContentThrowsUnauthorizedException()
927
    {
928
        $repository = $this->getRepository();
929
        $contentService = $repository->getContentService();
930
931
        $anonymousUserId = $this->generateId('user', 10);
932
        $anonymousUserId = $this->generateId('user', 10);
933
        /* BEGIN: Use Case */
934
        // $anonymousUserId is the ID of the "Anonymous User" in an eZ Publish
935
        // demo installation
936
        // $anonymousUserId is the ID of the "Anonymous User" in an eZ Publish
937
        // demo installation
938
        $draftVersion2 = $this->createContentDraftVersion2();
939
940
        // Get VersionInfo instance
941
        $versionInfo = $draftVersion2->getVersionInfo();
942
943
        // Load the user service
944
        $userService = $repository->getUserService();
945
946
        // Set anonymous user
947
        $repository->setCurrentUser($userService->loadUser($anonymousUserId));
948
949
        // Create an update struct and modify some fields
950
        $contentUpdate = $contentService->newContentUpdateStruct();
951
        $contentUpdate->setField('name', 'An awesome² story about ezp.');
952
        $contentUpdate->setField('name', 'An awesome²³ story about ezp.', 'eng-GB');
953
954
        $contentUpdate->initialLanguageCode = 'eng-US';
955
956
        // This call will fail with a "UnauthorizedException"
957
        $contentService->updateContent($versionInfo, $contentUpdate);
958
        /* END: Use Case */
959
    }
960
961
    /**
962
     * Test for the publishVersion() method.