allow to delete invoice documents (#2968)
This commit is contained in:
@@ -9,13 +9,26 @@
|
||||
|
||||
namespace App\Tests\EventSubscriber\Actions;
|
||||
|
||||
use App\EventSubscriber\Actions\AbstractActionsSubscriber;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
|
||||
use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
|
||||
|
||||
/**
|
||||
* @covers \App\EventSubscriber\Actions\AbstractActionsSubscriber
|
||||
*/
|
||||
abstract class AbstractActionsSubscriberTest extends TestCase
|
||||
{
|
||||
protected function createSubscriber(string $className, ...$grants): AbstractActionsSubscriber
|
||||
{
|
||||
$auth = $this->createMock(AuthorizationCheckerInterface::class);
|
||||
$auth->method('isGranted')->willReturnOnConsecutiveCalls(...$grants);
|
||||
$router = $this->createMock(UrlGeneratorInterface::class);
|
||||
$router->method('generate')->willReturnArgument(0);
|
||||
|
||||
return new $className($auth, $router);
|
||||
}
|
||||
|
||||
protected function assertGetSubscribedEvent(string $className, string $name)
|
||||
{
|
||||
$this->assertTrue(method_exists($className, 'getSubscribedEvents'));
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Kimai time-tracking app.
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace App\Tests\EventSubscriber\Actions;
|
||||
|
||||
use App\Entity\InvoiceDocument;
|
||||
use App\Entity\User;
|
||||
use App\Event\PageActionsEvent;
|
||||
use App\EventSubscriber\Actions\InvoiceDocumentSubscriber;
|
||||
|
||||
/**
|
||||
* @covers \App\EventSubscriber\Actions\InvoiceDocumentSubscriber
|
||||
*/
|
||||
class InvoiceDocumentSubscriberTest extends AbstractActionsSubscriberTest
|
||||
{
|
||||
public function testEventName()
|
||||
{
|
||||
$this->assertGetSubscribedEvent(InvoiceDocumentSubscriber::class, 'invoice_document');
|
||||
}
|
||||
|
||||
public function testActions()
|
||||
{
|
||||
$sut = $this->createSubscriber(InvoiceDocumentSubscriber::class, true);
|
||||
|
||||
$event = new PageActionsEvent(new User(), ['document' => new InvoiceDocument(new \SplFileInfo(__FILE__)), 'token' => uniqid()], 'invoice_document', 'index');
|
||||
$sut->onActions($event);
|
||||
|
||||
$actions = $event->getActions();
|
||||
self::assertGreaterThanOrEqual(1, \count($actions));
|
||||
self::assertArrayHasKey('trash', $actions);
|
||||
self::assertEquals('invoice_document_delete', $actions['trash']['url']);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user