|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
/* |
|
6
|
|
|
* This file is part of the Sonata Project package. |
|
7
|
|
|
* |
|
8
|
|
|
* (c) Thomas Rabaix <[email protected]> |
|
9
|
|
|
* |
|
10
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
11
|
|
|
* file that was distributed with this source code. |
|
12
|
|
|
*/ |
|
13
|
|
|
|
|
14
|
|
|
namespace Sonata\AdminBundle\Tests\Action; |
|
15
|
|
|
|
|
16
|
|
|
use PHPUnit\Framework\TestCase; |
|
17
|
|
|
use Prophecy\Argument; |
|
18
|
|
|
use Sonata\AdminBundle\Action\GetShortObjectDescriptionAction; |
|
19
|
|
|
use Sonata\AdminBundle\Admin\AbstractAdmin; |
|
20
|
|
|
use Sonata\AdminBundle\Admin\Pool; |
|
21
|
|
|
use Symfony\Component\HttpFoundation\Request; |
|
22
|
|
|
use Symfony\Component\HttpFoundation\Response; |
|
23
|
|
|
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; |
|
24
|
|
|
use Twig\Environment; |
|
25
|
|
|
use Twig\Loader\ArrayLoader; |
|
26
|
|
|
|
|
27
|
|
|
final class GetShortObjectDescriptionActionTest extends TestCase |
|
28
|
|
|
{ |
|
29
|
|
|
/** |
|
30
|
|
|
* @var Pool |
|
31
|
|
|
*/ |
|
32
|
|
|
private $pool; |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* @var Environment |
|
36
|
|
|
*/ |
|
37
|
|
|
private $twig; |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* @var GetShortObjectDescriptionAction |
|
41
|
|
|
*/ |
|
42
|
|
|
private $action; |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* @var AbstractAdmin |
|
46
|
|
|
*/ |
|
47
|
|
|
private $admin; |
|
48
|
|
|
|
|
49
|
|
|
protected function setUp(): void |
|
50
|
|
|
{ |
|
51
|
|
|
$this->twig = new Environment(new ArrayLoader(['template' => 'renderedTemplate'])); |
|
52
|
|
|
$this->pool = $this->prophesize(Pool::class); |
|
53
|
|
|
$this->admin = $this->prophesize(AbstractAdmin::class); |
|
54
|
|
|
$this->pool->getInstance(Argument::any())->willReturn($this->admin->reveal()); |
|
55
|
|
|
$this->admin->setRequest(Argument::type(Request::class))->shouldBeCalled(); |
|
56
|
|
|
$this->action = new GetShortObjectDescriptionAction( |
|
57
|
|
|
$this->twig, |
|
58
|
|
|
$this->pool->reveal() |
|
59
|
|
|
); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
public function testGetShortObjectDescriptionActionInvalidAdmin(): void |
|
63
|
|
|
{ |
|
64
|
|
|
$this->expectException(NotFoundHttpException::class); |
|
65
|
|
|
|
|
66
|
|
|
$request = new Request([ |
|
67
|
|
|
'code' => 'sonata.post.admin', |
|
68
|
|
|
'objectId' => 42, |
|
69
|
|
|
'uniqid' => 'asdasd123', |
|
70
|
|
|
]); |
|
71
|
|
|
|
|
72
|
|
|
$this->pool->getInstance('sonata.post.admin')->willReturn(null); |
|
|
|
|
|
|
73
|
|
|
$this->admin->setRequest(Argument::type(Request::class))->shouldNotBeCalled(); |
|
|
|
|
|
|
74
|
|
|
|
|
75
|
|
|
$action = $this->action; |
|
76
|
|
|
$action($request); |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
public function testGetShortObjectDescriptionActionObjectDoesNotExist(): void |
|
80
|
|
|
{ |
|
81
|
|
|
$this->expectException(\RuntimeException::class); |
|
82
|
|
|
$this->expectExceptionMessage('Invalid format'); |
|
83
|
|
|
|
|
84
|
|
|
$request = new Request([ |
|
85
|
|
|
'code' => 'sonata.post.admin', |
|
86
|
|
|
'objectId' => 42, |
|
87
|
|
|
'uniqid' => 'asdasd123', |
|
88
|
|
|
]); |
|
89
|
|
|
|
|
90
|
|
|
$this->admin->setUniqid('asdasd123')->shouldBeCalled(); |
|
|
|
|
|
|
91
|
|
|
$this->admin->getObject(42)->willReturn(false); |
|
92
|
|
|
|
|
93
|
|
|
$action = $this->action; |
|
94
|
|
|
$action($request); |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
public function testGetShortObjectDescriptionActionEmptyObjectId(): void |
|
98
|
|
|
{ |
|
99
|
|
|
$request = new Request([ |
|
100
|
|
|
'code' => 'sonata.post.admin', |
|
101
|
|
|
'objectId' => '', |
|
102
|
|
|
'uniqid' => 'asdasd123', |
|
103
|
|
|
'_format' => 'html', |
|
104
|
|
|
]); |
|
105
|
|
|
|
|
106
|
|
|
$this->admin->setUniqid('asdasd123')->shouldBeCalled(); |
|
|
|
|
|
|
107
|
|
|
$this->admin->getObject(null)->willReturn(false); |
|
108
|
|
|
|
|
109
|
|
|
$action = $this->action; |
|
110
|
|
|
$response = $action($request); |
|
111
|
|
|
|
|
112
|
|
|
$this->assertInstanceOf(Response::class, $response); |
|
113
|
|
|
} |
|
114
|
|
|
|
|
115
|
|
|
public function testGetShortObjectDescriptionActionObject(): void |
|
116
|
|
|
{ |
|
117
|
|
|
$request = new Request([ |
|
118
|
|
|
'code' => 'sonata.post.admin', |
|
119
|
|
|
'objectId' => 42, |
|
120
|
|
|
'uniqid' => 'asdasd123', |
|
121
|
|
|
'_format' => 'html', |
|
122
|
|
|
]); |
|
123
|
|
|
$object = new \stdClass(); |
|
124
|
|
|
|
|
125
|
|
|
$this->admin->setUniqid('asdasd123')->shouldBeCalled(); |
|
|
|
|
|
|
126
|
|
|
$this->admin->getObject(42)->willReturn($object); |
|
127
|
|
|
$this->admin->getTemplate('short_object_description')->willReturn('template'); |
|
|
|
|
|
|
128
|
|
|
$this->admin->toString($object)->willReturn('bar'); |
|
|
|
|
|
|
129
|
|
|
|
|
130
|
|
|
$action = $this->action; |
|
131
|
|
|
$response = $action($request); |
|
132
|
|
|
|
|
133
|
|
|
$this->assertSame('renderedTemplate', $response->getContent()); |
|
134
|
|
|
} |
|
135
|
|
|
} |
|
136
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.