Completed
Push — ezp-30971-remove-deprecated-ro... ( 445d16...da413e )
by
unknown
41:11 queued 26:46
created

BaseLimitationTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 81
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 9

Importance

Changes 0
Metric Value
dl 0
loc 81
rs 10
c 0
b 0
f 0
wmc 3
lcom 1
cbo 9

3 Methods

Rating   Name   Duplication   Size   Complexity  
A createWikiPage() 0 13 1
A createWikiPageDraft() 0 42 1
A addPolicyToRole() 0 11 1
1
<?php
2
3
/**
4
 * File containing the BaseLimitationTest class.
5
 *
6
 * @copyright Copyright (C) eZ Systems AS. All rights reserved.
7
 * @license For full copyright and license information view LICENSE file distributed with this source code.
8
 */
9
namespace eZ\Publish\API\Repository\Tests\Values\User\Limitation;
10
11
use eZ\Publish\API\Repository\Tests\BaseTest;
12
use eZ\Publish\API\Repository\Values\Content\Location;
13
use eZ\Publish\API\Repository\Values\User\PolicyCreateStruct;
14
use eZ\Publish\API\Repository\Values\User\Role;
15
16
/**
17
 * Abstract base class for limitation tests.
18
 *
19
 * @group integration
20
 * @group limitation
21
 */
22
abstract class BaseLimitationTest extends BaseTest
23
{
24
    /**
25
     * Creates a published wiki page.
26
     *
27
     * @return \eZ\Publish\API\Repository\Values\Content\Content
28
     */
29
    protected function createWikiPage()
30
    {
31
        $repository = $this->getRepository();
32
33
        $contentService = $repository->getContentService();
34
        /* BEGIN: Inline */
35
        $draft = $this->createWikiPageDraft();
36
37
        $content = $contentService->publishVersion($draft->versionInfo);
38
        /* END: Inline */
39
40
        return $content;
41
    }
42
43
    /**
44
     * Creates a fresh clean content draft.
45
     *
46
     * @return \eZ\Publish\API\Repository\Values\Content\Content
47
     */
48
    protected function createWikiPageDraft()
49
    {
50
        $repository = $this->getRepository();
51
52
        $parentLocationId = $this->generateId('location', 60);
53
        $sectionId = $this->generateId('section', 1);
54
        /* BEGIN: Inline */
55
        $contentTypeService = $repository->getContentTypeService();
56
        $locationService = $repository->getLocationService();
57
        $contentService = $repository->getContentService();
58
59
        // Configure new location
60
        // $parentLocationId is the id of the /Home/Contact-Us node
61
        $locationCreate = $locationService->newLocationCreateStruct($parentLocationId);
62
63
        $locationCreate->priority = 23;
64
        $locationCreate->hidden = true;
65
        $locationCreate->remoteId = '0123456789abcdef0123456789abcdef';
66
        $locationCreate->sortField = Location::SORT_FIELD_NODE_ID;
67
        $locationCreate->sortOrder = Location::SORT_ORDER_DESC;
68
69
        // Load content type
70
        $wikiPageType = $contentTypeService->loadContentTypeByIdentifier('wiki_page');
71
72
        // Configure new content object
73
        $wikiPageCreate = $contentService->newContentCreateStruct($wikiPageType, 'eng-US');
74
75
        $wikiPageCreate->setField('title', 'An awesome wiki page');
76
        $wikiPageCreate->remoteId = 'abcdef0123456789abcdef0123456789';
77
        // $sectionId is the ID of section 1
78
        $wikiPageCreate->sectionId = $sectionId;
79
        $wikiPageCreate->alwaysAvailable = true;
80
81
        // Create a draft
82
        $draft = $contentService->createContent(
83
            $wikiPageCreate,
84
            [$locationCreate]
85
        );
86
        /* END: Inline */
87
88
        return $draft;
89
    }
90
91
    protected function addPolicyToRole(string $roleIdentifier, PolicyCreateStruct $policyCreateStruct): Role
92
    {
93
        $roleService = $this->getRepository()->getRoleService();
94
95
        $role = $roleService->loadRoleByIdentifier($roleIdentifier);
96
        $roleDraft = $roleService->createRoleDraft($role);
97
        $roleService->addPolicyByRoleDraft($roleDraft, $policyCreateStruct);
98
        $roleService->publishRoleDraft($roleDraft);
99
100
        return $roleService->loadRoleByIdentifier($roleIdentifier);
101
    }
102
}
103