forked from ezsystems/ezpublish-kernel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ParameterProviderTest.php
81 lines (66 loc) · 2.71 KB
/
ParameterProviderTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
<?php
namespace eZ\Publish\Core\MVC\Symfony\FieldType\Tests\RelationList;
use eZ\Publish\API\Repository\ContentService;
use eZ\Publish\API\Repository\Values\Content\ContentInfo;
use eZ\Publish\API\Repository\Values\Content\Field;
use eZ\Publish\Core\Base\Exceptions\NotFoundException;
use eZ\Publish\Core\Base\Exceptions\UnauthorizedException;
use eZ\Publish\Core\Base\Tests\PHPUnit5CompatTrait;
use eZ\Publish\Core\FieldType\Relation\Value;
use eZ\Publish\Core\MVC\Symfony\FieldType\Relation\ParameterProvider;
use PHPUnit\Framework\TestCase;
class ParameterProviderTest extends TestCase
{
use PHPUnit5CompatTrait;
public function providerForTestGetViewParameters()
{
return [
[ContentInfo::STATUS_DRAFT, ['available' => true]],
[ContentInfo::STATUS_PUBLISHED, ['available' => true]],
[ContentInfo::STATUS_TRASHED, ['available' => false]],
];
}
/**
* @dataProvider providerForTestGetViewParameters
*/
public function testGetViewParameters($status, array $expected)
{
$contentServiceMock = $this->createMock(ContentService::class);
$contentServiceMock
->method('loadContentInfo')
->will(TestCase::returnValue(
new ContentInfo(['status' => $status])
));
$parameterProvider = new ParameterProvider($contentServiceMock);
$parameters = $parameterProvider->getViewParameters(new Field([
'value' => new Value(123),
]));
TestCase::assertSame($parameters, $expected);
}
public function testNotFoundGetViewParameters()
{
$contentId = 123;
$contentServiceMock = $this->createMock(ContentService::class);
$contentServiceMock
->method('loadContentInfo')
->will(TestCase::throwException(new NotFoundException('ContentInfo', $contentId)));
$parameterProvider = new ParameterProvider($contentServiceMock);
$parameters = $parameterProvider->getViewParameters(new Field([
'value' => new Value($contentId),
]));
TestCase::assertSame($parameters, ['available' => false]);
}
public function testUnauthorizedGetViewParameters()
{
$contentId = 123;
$contentServiceMock = $this->createMock(ContentService::class);
$contentServiceMock
->method('loadContentInfo')
->will(TestCase::throwException(new UnauthorizedException('content', 'read')));
$parameterProvider = new ParameterProvider($contentServiceMock);
$parameters = $parameterProvider->getViewParameters(new Field([
'value' => new Value($contentId),
]));
TestCase::assertSame($parameters, ['available' => false]);
}
}