/
EditShoutActionTest.php
134 lines (112 loc) · 4.33 KB
/
EditShoutActionTest.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
<?php
/*
* vim:set softtabstop=4 shiftwidth=4 expandtab:
*
* LICENSE: GNU Affero General Public License, version 3 (AGPL-3.0-or-later)
* Copyright 2001 - 2020 Ampache.org
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace Ampache\Module\Application\Admin\Shout;
use Ampache\Config\ConfigContainerInterface;
use Ampache\MockeryTestCase;
use Ampache\Repository\Model\ModelFactoryInterface;
use Ampache\Repository\Model\Shoutbox;
use Ampache\Module\Application\Exception\AccessDeniedException;
use Ampache\Module\Authorization\AccessLevelEnum;
use Ampache\Module\Authorization\GuiGatekeeperInterface;
use Ampache\Module\Util\UiInterface;
use Mockery\MockInterface;
use Psr\Http\Message\ServerRequestInterface;
class EditShoutActionTest extends MockeryTestCase
{
/** @var MockInterface|UiInterface|null */
private MockInterface $ui;
/** @var MockInterface|ConfigContainerInterface|null */
private MockInterface $configContainer;
/** @var MockInterface|ModelFactoryInterface|null */
private MockInterface $modelFactory;
private ?EditShoutAction $subject;
public function setUp(): void
{
$this->ui = $this->mock(UiInterface::class);
$this->configContainer = $this->mock(ConfigContainerInterface::class);
$this->modelFactory = $this->mock(ModelFactoryInterface::class);
$this->subject = new EditShoutAction(
$this->ui,
$this->configContainer,
$this->modelFactory
);
}
public function testRunThrowExceptionIfAccessIsDenied(): void
{
$this->expectException(AccessDeniedException::class);
$request = $this->mock(ServerRequestInterface::class);
$gatekeeper = $this->mock(GuiGatekeeperInterface::class);
$gatekeeper->shouldReceive('mayAccess')
->with(AccessLevelEnum::TYPE_INTERFACE, AccessLevelEnum::LEVEL_ADMIN)
->once()
->andReturnFalse();
$this->subject->run($request, $gatekeeper);
}
public function testRunUpdatesEntry(): void
{
$request = $this->mock(ServerRequestInterface::class);
$gatekeeper = $this->mock(GuiGatekeeperInterface::class);
$shoutbox = $this->mock(Shoutbox::class);
$shout_id = 666;
$data = ['shout_id' => $shout_id, 'comment' => '', 'sticky' => ''];
$webPath = 'some-path';
$shoutbox->id = $shout_id;
$this->configContainer->shouldReceive('getWebPath')
->withNoArgs()
->once()
->andReturn($webPath);
$gatekeeper->shouldReceive('mayAccess')
->with(AccessLevelEnum::TYPE_INTERFACE, AccessLevelEnum::LEVEL_ADMIN)
->once()
->andReturnTrue();
$this->modelFactory->shouldReceive('createShoutbox')
->with($shout_id)
->once()
->andReturn($shoutbox);
$shoutbox->shouldReceive('update')
->with($data)
->once();
$request->shouldReceive('getParsedBody')
->withNoArgs()
->once()
->andReturn($data);
$this->ui->shouldReceive('showHeader')
->withNoArgs()
->once();
$this->ui->shouldReceive('showConfirmation')
->with(
'No Problem',
'Shoutbox post has been updated',
sprintf('%s/admin/shout.php', $webPath)
)
->once();
$this->ui->shouldReceive('showQueryStats')
->withNoArgs()
->once();
$this->ui->shouldReceive('showFooter')
->withNoArgs()
->once();
$this->assertNull(
$this->subject->run($request, $gatekeeper)
);
}
}