1<?php 2/* 3 * vim:set softtabstop=4 shiftwidth=4 expandtab: 4 * 5 * LICENSE: GNU Affero General Public License, version 3 (AGPL-3.0-or-later) 6 * Copyright 2001 - 2020 Ampache.org 7 * 8 * This program is free software: you can redistribute it and/or modify 9 * it under the terms of the GNU Affero General Public License as published by 10 * the Free Software Foundation, either version 3 of the License, or 11 * (at your option) any later version. 12 * 13 * This program is distributed in the hope that it will be useful, 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 * GNU Affero General Public License for more details. 17 * 18 * You should have received a copy of the GNU Affero General Public License 19 * along with this program. If not, see <https://www.gnu.org/licenses/>. 20 * 21 */ 22 23declare(strict_types=1); 24 25namespace Ampache\Module\Application\Video; 26 27use Ampache\Config\ConfigContainerInterface; 28use Ampache\Config\ConfigurationKeyEnum; 29use Ampache\MockeryTestCase; 30use Ampache\Module\Authorization\GuiGatekeeperInterface; 31use Ampache\Module\Util\UiInterface; 32use Mockery\MockInterface; 33use Psr\Http\Message\ServerRequestInterface; 34 35class DeleteActionTest extends MockeryTestCase 36{ 37 /** @var ConfigContainerInterface|MockInterface|null */ 38 private ?MockInterface $configContainer; 39 40 /** @var UiInterface|MockInterface|null */ 41 private ?MockInterface $ui; 42 43 private ?DeleteAction $subject; 44 45 public function setUp(): void 46 { 47 $this->configContainer = $this->mock(ConfigContainerInterface::class); 48 $this->ui = $this->mock(UiInterface::class); 49 50 $this->subject = new DeleteAction( 51 $this->configContainer, 52 $this->ui 53 ); 54 } 55 56 public function testRunReturnsNullInDemoMode(): void 57 { 58 $request = $this->mock(ServerRequestInterface::class); 59 $gatekeeper = $this->mock(GuiGatekeeperInterface::class); 60 61 $this->configContainer->shouldReceive('isFeatureEnabled') 62 ->with(ConfigurationKeyEnum::DEMO_MODE) 63 ->once() 64 ->andReturnTrue(); 65 66 $this->assertNull( 67 $this->subject->run($request, $gatekeeper) 68 ); 69 } 70 71 public function testRunDeletesAndReturnsNull(): void 72 { 73 $request = $this->mock(ServerRequestInterface::class); 74 $gatekeeper = $this->mock(GuiGatekeeperInterface::class); 75 76 $videoId = 666; 77 $webPath = 'some-path'; 78 79 $this->configContainer->shouldReceive('isFeatureEnabled') 80 ->with(ConfigurationKeyEnum::DEMO_MODE) 81 ->once() 82 ->andReturnFalse(); 83 84 $this->configContainer->shouldReceive('getWebPath') 85 ->withNoArgs() 86 ->once() 87 ->andReturn($webPath); 88 89 $request->shouldReceive('getQueryParams') 90 ->withNoArgs() 91 ->once() 92 ->andReturn(['video_id' => (string) $videoId]); 93 94 $this->ui->shouldReceive('showHeader') 95 ->withNoArgs() 96 ->once(); 97 $this->ui->shouldReceive('showFooter') 98 ->withNoArgs() 99 ->once(); 100 $this->ui->shouldReceive('showQueryStats') 101 ->withNoArgs() 102 ->once(); 103 $this->ui->shouldReceive('showConfirmation') 104 ->with( 105 'Are You Sure?', 106 'The Video will be deleted', 107 sprintf( 108 '%s/video.php?action=confirm_delete&video_id=%d', 109 $webPath, 110 $videoId 111 ), 112 1, 113 'delete_video' 114 ) 115 ->once(); 116 117 $this->assertNull( 118 $this->subject->run($request, $gatekeeper) 119 ); 120 } 121} 122