mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-17 15:03:25 +00:00
Add missing applicability test in BorderManager
This commit is contained in:
@@ -19,8 +19,19 @@ use Alchemy\Phrasea\Border\File;
|
||||
*/
|
||||
abstract class AbstractChecker implements CheckerInterface
|
||||
{
|
||||
/**
|
||||
* @var Application
|
||||
*/
|
||||
protected $app;
|
||||
|
||||
/**
|
||||
* @var \databox[]
|
||||
*/
|
||||
protected $databoxes = [];
|
||||
|
||||
/**
|
||||
* @var \collection[]
|
||||
*/
|
||||
protected $collections = [];
|
||||
|
||||
public function __construct(Application $app)
|
||||
@@ -32,8 +43,8 @@ abstract class AbstractChecker implements CheckerInterface
|
||||
* Restrict the checker to a set of databoxes.
|
||||
* Warning, you can not restrict on both databoxes and collections
|
||||
*
|
||||
* @param databox|array $databoxes A databox or an array of databoxes
|
||||
* @return Boolean
|
||||
* @param \databox[] $databoxes A databox or an array of databoxes
|
||||
* @return bool
|
||||
*
|
||||
* @throws \LogicException If already restricted to collections
|
||||
* @throws \InvalidArgumentException In case invalid databoxes are provided
|
||||
@@ -60,8 +71,8 @@ abstract class AbstractChecker implements CheckerInterface
|
||||
* Restrict the checker to a set of collections.
|
||||
* Warning, you can not restrict on both databoxes and collections
|
||||
*
|
||||
* @param collection|array $collections
|
||||
* @return Boolean
|
||||
* @param \collection[] $collections
|
||||
* @return bool
|
||||
*
|
||||
* @throws \LogicException If already restricted to databoxes
|
||||
* @throws \InvalidArgumentException In case invalid collections are provided
|
||||
|
@@ -44,6 +44,9 @@ use Symfony\Component\Filesystem\Exception\IOException;
|
||||
*/
|
||||
class Manager
|
||||
{
|
||||
/**
|
||||
* @var CheckerInterface[]
|
||||
*/
|
||||
protected $checkers = [];
|
||||
protected $app;
|
||||
protected $filesystem;
|
||||
@@ -159,7 +162,9 @@ class Manager
|
||||
}
|
||||
|
||||
foreach ($this->checkers as $checker) {
|
||||
$visa->addResponse($checker->check($this->app['orm.em'], $file));
|
||||
if ($checker->isApplicable($file)) {
|
||||
$visa->addResponse($checker->check($this->app['orm.em'], $file));
|
||||
}
|
||||
}
|
||||
|
||||
return $visa;
|
||||
|
79
tests/Alchemy/Tests/Phrasea/Border/ManagerGetVisaTest.php
Normal file
79
tests/Alchemy/Tests/Phrasea/Border/ManagerGetVisaTest.php
Normal file
@@ -0,0 +1,79 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of Phraseanet
|
||||
*
|
||||
* (c) 2005-2016 Alchemy
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Alchemy\Tests\Phrasea\Border;
|
||||
|
||||
|
||||
use Alchemy\Phrasea\Application;
|
||||
use Alchemy\Phrasea\Border\Checker\CheckerInterface;
|
||||
use Alchemy\Phrasea\Border\Checker\Response;
|
||||
use Alchemy\Phrasea\Border\File;
|
||||
use Alchemy\Phrasea\Border\Manager;
|
||||
use Alchemy\Phrasea\Border\Visa;
|
||||
use Doctrine\ORM\EntityManager;
|
||||
use Prophecy\Argument;
|
||||
use Prophecy\Prophecy\ObjectProphecy;
|
||||
|
||||
class ManagerGetVisaTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @var ObjectProphecy
|
||||
*/
|
||||
private $app;
|
||||
|
||||
/**
|
||||
* @var Manager
|
||||
*/
|
||||
private $sut;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
$this->app = $this->prophesize(Application::class);
|
||||
$this->app->offsetGet('orm.em')->willReturn($this->prophesize(EntityManager::class));
|
||||
|
||||
$this->sut = new Manager($this->app->reveal());
|
||||
}
|
||||
|
||||
public function testGetVisaWithoutAnyCheckers()
|
||||
{
|
||||
$file = $this->prophesize(File::class);
|
||||
|
||||
$visa = $this->sut->getVisa($file->reveal());
|
||||
|
||||
$this->assertInstanceOf(Visa::class, $visa);
|
||||
}
|
||||
|
||||
public function testGetVisaWithOnlyOneCheckerApplicable()
|
||||
{
|
||||
$file = $this->prophesize(File::class);
|
||||
|
||||
$checker1 = $this->prophesize(CheckerInterface::class);
|
||||
$checker1->isApplicable($file->reveal())
|
||||
->willReturn(false);
|
||||
$checker1->check(Argument::any(), $file->reveal())
|
||||
->shouldNotBeCalled();
|
||||
|
||||
$checker2 = $this->prophesize(CheckerInterface::class);
|
||||
$checker2->isApplicable($file->reveal())
|
||||
->willReturn(true);
|
||||
$checker2->check(Argument::any(), $file->reveal())
|
||||
->willReturn(new Response(true, $checker2->reveal()));
|
||||
|
||||
$this->sut->registerCheckers([$checker1->reveal(), $checker2->reveal()]);
|
||||
|
||||
$visa = $this->sut->getVisa($file->reveal());
|
||||
|
||||
$this->assertInstanceOf(Visa::class, $visa);
|
||||
$responses = $visa->getResponses();
|
||||
|
||||
$this->assertCount(1, $responses);
|
||||
$this->assertSame($checker2->reveal(), $responses[0]->getChecker());
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user