Skip to content

Commit 7be4bbb

Browse files
tbialczkatarzynazawada
authored andcommitted
IBX-10221: Replaced IsContentStructureRoot with IsInContextualTreeRootIds specification and added corresponding tests
1 parent 635e40a commit 7be4bbb

File tree

5 files changed

+113
-13
lines changed

5 files changed

+113
-13
lines changed

src/lib/Menu/ContentRightSidebarBuilder.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
use Ibexa\AdminUi\Siteaccess\SiteaccessResolverInterface;
1313
use Ibexa\AdminUi\Specification\ContentType\ContentTypeIsUser;
1414
use Ibexa\AdminUi\Specification\ContentType\ContentTypeIsUserGroup;
15-
use Ibexa\AdminUi\Specification\Location\IsContentStructureRoot;
15+
use Ibexa\AdminUi\Specification\Location\IsInContextualTreeRootIds;
1616
use Ibexa\AdminUi\Specification\Location\IsRoot;
1717
use Ibexa\AdminUi\Specification\Location\IsWithinCopySubtreeLimit;
1818
use Ibexa\AdminUi\UniversalDiscovery\ConfigResolver;
@@ -295,9 +295,9 @@ public function createStructure(array $options): ItemInterface
295295
}
296296

297297
$isAtRootLevel = (new IsRoot())->isSatisfiedBy($location);
298-
$isContentStructureRoot = (new IsContentStructureRoot($this->configResolver))->isSatisfiedBy($location);
298+
$isInContextualRootIds = (new IsInContextualTreeRootIds($this->configResolver))->isSatisfiedBy($location);
299299

300-
if (!$contentIsUser && !$isAtRootLevel && !$isContentStructureRoot && $canTrashLocation) {
300+
if (!$contentIsUser && !$isAtRootLevel && !$isInContextualRootIds && $canTrashLocation) {
301301
$menu->addChild(
302302
$this->createMenuItem(
303303
self::ITEM__SEND_TO_TRASH,
@@ -309,7 +309,7 @@ public function createStructure(array $options): ItemInterface
309309
);
310310
}
311311

312-
if ($isAtRootLevel || $isContentStructureRoot) {
312+
if ($isAtRootLevel || $isInContextualRootIds) {
313313
$menu[self::ITEM__MOVE]->setAttribute('disabled', 'disabled');
314314
}
315315

src/lib/Specification/Location/IsContentStructureRoot.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,6 @@ public function __construct(ConfigResolverInterface $configResolver)
2525
*/
2626
public function isSatisfiedBy($item): bool
2727
{
28-
return $item->getDepth() === (int)$this->configResolver->getParameter('location_ids.content_structure');
28+
return $item->getId() === (int)$this->configResolver->getParameter('location_ids.content_structure');
2929
}
3030
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
3+
/**
4+
* @copyright Copyright (C) Ibexa 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 Ibexa\AdminUi\Specification\Location;
10+
11+
use Ibexa\Contracts\Core\SiteAccess\ConfigResolverInterface;
12+
use Ibexa\Contracts\Core\Specification\AbstractSpecification;
13+
14+
final class IsInContextualTreeRootIds extends AbstractSpecification
15+
{
16+
private ConfigResolverInterface $configResolver;
17+
18+
public function __construct(ConfigResolverInterface $configResolver)
19+
{
20+
$this->configResolver = $configResolver;
21+
}
22+
23+
/**
24+
* @param \Ibexa\Contracts\Core\Repository\Values\Content\Location $item
25+
*/
26+
public function isSatisfiedBy($item): bool
27+
{
28+
$contextualRootIds = $this->configResolver->getParameter(
29+
'content_tree_module.contextual_tree_root_location_ids'
30+
);
31+
32+
return in_array($item->getId(), $contextualRootIds, true);
33+
}
34+
}

tests/lib/Specification/Location/IsContentStructureRootTest.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,14 @@ final class IsContentStructureRootTest extends TestCase
2020
*/
2121
public function testReturnsTrueWhenLocationDepthMatchesRoot(): void
2222
{
23-
$depth = 1;
23+
$id = 1;
2424

2525
$specification = new IsContentStructureRoot(
26-
$this->createConfigResolverReturning($depth)
26+
$this->createConfigResolverReturning($id)
2727
);
2828

2929
self::assertTrue(
30-
$specification->isSatisfiedBy($this->createLocationWithDepth($depth))
30+
$specification->isSatisfiedBy($this->createLocationWithId($id))
3131
);
3232
}
3333

@@ -41,25 +41,25 @@ public function testReturnsFalseWhenLocationDepthDoesNotMatchRoot(): void
4141
);
4242

4343
self::assertFalse(
44-
$specification->isSatisfiedBy($this->createLocationWithDepth(3))
44+
$specification->isSatisfiedBy($this->createLocationWithId(3))
4545
);
4646
}
4747

48-
private function createLocationWithDepth(int $depth): Location
48+
private function createLocationWithId(int $id): Location
4949
{
5050
$location = $this->createMock(Location::class);
51-
$location->method('getDepth')->willReturn($depth);
51+
$location->method('getId')->willReturn($id);
5252

5353
return $location;
5454
}
5555

56-
private function createConfigResolverReturning(int $depth): ConfigResolverInterface
56+
private function createConfigResolverReturning(int $id): ConfigResolverInterface
5757
{
5858
$configResolver = $this->createMock(ConfigResolverInterface::class);
5959
$configResolver
6060
->method('getParameter')
6161
->with('location_ids.content_structure')
62-
->willReturn($depth);
62+
->willReturn($id);
6363

6464
return $configResolver;
6565
}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
<?php
2+
3+
/**
4+
* @copyright Copyright (C) Ibexa 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 Ibexa\Tests\AdminUi\Specification\Location;
10+
11+
use Ibexa\AdminUi\Specification\Location\IsInContextualTreeRootIds;
12+
use Ibexa\Contracts\Core\Repository\Values\Content\Location;
13+
use Ibexa\Contracts\Core\SiteAccess\ConfigResolverInterface;
14+
use PHPUnit\Framework\TestCase;
15+
16+
final class IsInContextualTreeRootIdsTest extends TestCase
17+
{
18+
private const CONTEXTUAL_ROOT_IDS = [2, 5, 43, 55, 56, 67];
19+
20+
/**
21+
* @covers \Ibexa\AdminUi\Specification\Location\IsInContextualTreeRootIds::isSatisfiedBy
22+
*/
23+
public function testReturnsTrueWhenLocationIdIsInContextualRootList(): void
24+
{
25+
$specification = new IsInContextualTreeRootIds(
26+
$this->createConfigResolverReturning()
27+
);
28+
29+
self::assertTrue(
30+
$specification->isSatisfiedBy($this->createLocationWithId(43))
31+
);
32+
}
33+
34+
/**
35+
* @covers \Ibexa\AdminUi\Specification\Location\IsInContextualTreeRootIds::isSatisfiedBy
36+
*/
37+
public function testReturnsFalseWhenLocationIdIsNotInContextualRootList(): void
38+
{
39+
$specification = new IsInContextualTreeRootIds(
40+
$this->createConfigResolverReturning()
41+
);
42+
43+
self::assertFalse(
44+
$specification->isSatisfiedBy($this->createLocationWithId(999))
45+
);
46+
}
47+
48+
private function createLocationWithId(int $id): Location
49+
{
50+
$location = $this->createMock(Location::class);
51+
$location->method('getId')->willReturn($id);
52+
53+
return $location;
54+
}
55+
56+
private function createConfigResolverReturning(): ConfigResolverInterface
57+
{
58+
$configResolver = $this->createMock(ConfigResolverInterface::class);
59+
$configResolver
60+
->method('getParameter')
61+
->with('content_tree_module.contextual_tree_root_location_ids')
62+
->willReturn(self::CONTEXTUAL_ROOT_IDS);
63+
64+
return $configResolver;
65+
}
66+
}

0 commit comments

Comments
 (0)