| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  * @copyright Copyright (C) eZ Systems AS. All rights reserved. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  |  * @license For full copyright and license information view LICENSE file distributed with this source code. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | declare(strict_types=1); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  | namespace eZ\Publish\API\Repository\Tests\Limitation\PermissionResolver; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  | use eZ\Publish\API\Repository\Values\Content\VersionInfo; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  | use eZ\Publish\API\Repository\Values\User\Limitation; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |  * Test mix of chosen core Content Limitations. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  | class ContentLimitationsMixIntegrationTest extends BaseLimitationIntegrationTest | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |     const LIMITATION_VALUES = 'limitationValues'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |      * {@inheritdoc} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |      * Provides lists of: | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |      * <code>[string $module, string $function, array $limitations, bool $expectedResult]</code> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |      * This provider also checks if all registered Limitations are used. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |     public function providerForCanUser(): array | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |         $commonLimitations = $this->getCommonLimitations(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |         $contentCreateLimitations = array_merge( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |             $commonLimitations, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |             [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |                 new Limitation\ParentContentTypeLimitation([self::LIMITATION_VALUES => [1]]), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |                 new Limitation\ParentDepthLimitation([self::LIMITATION_VALUES => [2]]), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |                 new Limitation\LanguageLimitation([self::LIMITATION_VALUES => ['eng-US']]), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |             ] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |         $contentEditLimitations = array_merge( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |             $commonLimitations, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |             [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |                 new Limitation\ObjectStateLimitation( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |                     [self::LIMITATION_VALUES => [1, 2]] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |                 ), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |                 new Limitation\LanguageLimitation([self::LIMITATION_VALUES => ['eng-US']]), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |             ] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |         $contentVersionReadLimitations = array_merge( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |             $commonLimitations, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |             [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |                 new Limitation\StatusLimitation( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |                     [self::LIMITATION_VALUES => [VersionInfo::STATUS_PUBLISHED]] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |                 ), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |             ] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |         return [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |             ['content', 'create', $contentCreateLimitations, true], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |             ['content', 'edit', $contentEditLimitations, true], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |             ['content', 'publish', $contentEditLimitations, true], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |             ['content', 'versionread', $contentVersionReadLimitations, true], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |         ]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |      * @dataProvider providerForCanUser | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |      * @param string $module | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |      * @param string $function | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |      * @param array $limitations | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |      * @param bool $expectedResult | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |      * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |      * @throws \eZ\Publish\API\Repository\Exceptions\ForbiddenException | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  |      * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |      * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  |      * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  |     public function testCanUser( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  |         string $module, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  |         string $function, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  |         array $limitations, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  |         bool $expectedResult | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  |     ): void { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  |         $repository = $this->getRepository(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  |         $locationService = $repository->getLocationService(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  |         $folder = $this->createFolder(['eng-US' => 'Folder'], 2); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  |         $location = $locationService->loadLocation($folder->contentInfo->mainLocationId); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  |         $this->loginAsEditorUserWithLimitations($module, $function, $limitations); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  |         $this->assertCanUser( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  |             $expectedResult, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  |             $module, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 |  |  |             $function, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 |  |  |             $limitations, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 |  |  |             $folder, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 |  |  |             [$location] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 104 |  |  |         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 105 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 106 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 107 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 108 |  |  |      * Get a list of Limitations common to all test cases. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 109 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 110 |  |  |      * @return \eZ\Publish\API\Repository\Values\User\Limitation[] | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 111 |  |  |      */ | 
            
                                                        
            
                                    
            
            
                | 112 |  |  |     private function getCommonLimitations(): array | 
            
                                                        
            
                                    
            
            
                | 113 |  |  |     { | 
            
                                                        
            
                                    
            
            
                | 114 |  |  |         return [ | 
            
                                                        
            
                                    
            
            
                | 115 |  |  |             new Limitation\ContentTypeLimitation([self::LIMITATION_VALUES => [1]]), | 
            
                                                        
            
                                    
            
            
                | 116 |  |  |             new Limitation\SectionLimitation([self::LIMITATION_VALUES => [1]]), | 
            
                                                        
            
                                    
            
            
                | 117 |  |  |             new Limitation\SubtreeLimitation([self::LIMITATION_VALUES => ['/1/2']]), | 
            
                                                        
            
                                    
            
            
                | 118 |  |  |         ]; | 
            
                                                        
            
                                    
            
            
                | 119 |  |  |     } | 
            
                                                        
            
                                    
            
            
                | 120 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 121 |  |  |  |