mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-23 18:03:17 +00:00
PHRAS-1819: add quarantine rule based on media type
This commit is contained in:
@@ -102,6 +102,7 @@ border-manager:
|
|||||||
enabled: false
|
enabled: false
|
||||||
options:
|
options:
|
||||||
colorspaces: [cmyk, grayscale, rgb]
|
colorspaces: [cmyk, grayscale, rgb]
|
||||||
|
media_types: [Image]
|
||||||
-
|
-
|
||||||
type: Checker\Dimension
|
type: Checker\Dimension
|
||||||
enabled: false
|
enabled: false
|
||||||
|
@@ -20,6 +20,7 @@ use Symfony\Component\Translation\TranslatorInterface;
|
|||||||
class Colorspace extends AbstractChecker
|
class Colorspace extends AbstractChecker
|
||||||
{
|
{
|
||||||
protected $colorspaces;
|
protected $colorspaces;
|
||||||
|
protected $mediatypes;
|
||||||
|
|
||||||
const COLORSPACE_RGB = 'rgb';
|
const COLORSPACE_RGB = 'rgb';
|
||||||
const COLORSPACE_CMYK = 'cmyk';
|
const COLORSPACE_CMYK = 'cmyk';
|
||||||
@@ -32,7 +33,12 @@ class Colorspace extends AbstractChecker
|
|||||||
throw new \InvalidArgumentException('Missing "colorspaces" options');
|
throw new \InvalidArgumentException('Missing "colorspaces" options');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!isset($options['media_types'])) {
|
||||||
|
throw new \InvalidArgumentException('Missing "media_types" options');
|
||||||
|
}
|
||||||
|
|
||||||
$this->colorspaces = array_map('strtolower', (array) $options['colorspaces']);
|
$this->colorspaces = array_map('strtolower', (array) $options['colorspaces']);
|
||||||
|
$this->mediatypes = $options['media_types'];
|
||||||
parent::__construct($app);
|
parent::__construct($app);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -42,8 +48,8 @@ class Colorspace extends AbstractChecker
|
|||||||
|
|
||||||
if (0 === count($this->colorspaces)) {
|
if (0 === count($this->colorspaces)) {
|
||||||
$boolean = true; //bypass color if empty array
|
$boolean = true; //bypass color if empty array
|
||||||
} elseif ($file->getMedia()->getType() === Document::TYPE_DOCUMENT) {
|
} elseif (0 !== count($this->mediatypes) && $file->getMedia()->getType() !== NULL && !in_array($file->getMedia()->getType(), $this->mediatypes)) {
|
||||||
$boolean = true; //bypass color checker if file is of type document
|
$boolean = true; //bypass color checker if media type is not in the config
|
||||||
} elseif (method_exists($file->getMedia(), 'getColorSpace')) {
|
} elseif (method_exists($file->getMedia(), 'getColorSpace')) {
|
||||||
$colorspace = null;
|
$colorspace = null;
|
||||||
switch ($file->getMedia()->getColorSpace())
|
switch ($file->getMedia()->getColorSpace())
|
||||||
|
@@ -23,18 +23,21 @@ class ColorspaceTest extends \PhraseanetTestCase
|
|||||||
public function setUp()
|
public function setUp()
|
||||||
{
|
{
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
$this->object = new Colorspace(self::$DI['app'], ['colorspaces' => ['RGB', 'cmyk']]);
|
$this->object = new Colorspace(self::$DI['app'], ['colorspaces' => ['RGB', 'cmyk'], 'media_types' => ['Image', 'Document']]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @covers Alchemy\Phrasea\Border\Checker\Colorspace::check
|
* @covers Alchemy\Phrasea\Border\Checker\Colorspace::check
|
||||||
*/
|
*/
|
||||||
public function testCheck()
|
public function testCheckImage()
|
||||||
{
|
{
|
||||||
$media = $this
|
$media = $this
|
||||||
->getMockBuilder('\\MediaVorus\\Media\\Image')
|
->getMockBuilder('\\MediaVorus\\Media\\Image')
|
||||||
->disableOriginalConstructor()
|
->disableOriginalConstructor()
|
||||||
->getMock();
|
->getMock();
|
||||||
|
$media->expects($this->any())
|
||||||
|
->method('getType')
|
||||||
|
->will($this->returnValue('Image'));
|
||||||
$media->expects($this->once())
|
$media->expects($this->once())
|
||||||
->method('getColorSpace')
|
->method('getColorSpace')
|
||||||
->will($this->returnValue('RGB'));
|
->will($this->returnValue('RGB'));
|
||||||
@@ -50,6 +53,58 @@ class ColorspaceTest extends \PhraseanetTestCase
|
|||||||
$this->assertTrue($response->isOk());
|
$this->assertTrue($response->isOk());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers Alchemy\Phrasea\Border\Checker\Colorspace::check
|
||||||
|
*/
|
||||||
|
public function testCheckVideo()
|
||||||
|
{
|
||||||
|
$media = $this
|
||||||
|
->getMockBuilder('\\MediaVorus\\Media\\Video')
|
||||||
|
->disableOriginalConstructor()
|
||||||
|
->getMock();
|
||||||
|
$media->expects($this->any())
|
||||||
|
->method('getType')
|
||||||
|
->will($this->returnValue('Video'));
|
||||||
|
$media->expects($this->any())
|
||||||
|
->method('getFile')
|
||||||
|
->will($this->returnValue(new \SplFileInfo(__FILE__)));
|
||||||
|
|
||||||
|
$File = new File(self::$DI['app'], $media, self::$DI['collection']);
|
||||||
|
|
||||||
|
$response = $this->object->check(self::$DI['app']['orm.em'], $File);
|
||||||
|
|
||||||
|
$this->assertInstanceOf('\\Alchemy\\Phrasea\\Border\\Checker\\Response', $response);
|
||||||
|
$this->assertTrue($response->isOk());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers Alchemy\Phrasea\Border\Checker\Colorspace::check
|
||||||
|
*/
|
||||||
|
public function testCheckFailDocument()
|
||||||
|
{
|
||||||
|
$media = $this
|
||||||
|
->getMockBuilder('\\MediaVorus\\Media\\Document')
|
||||||
|
->disableOriginalConstructor()
|
||||||
|
->getMock();
|
||||||
|
$media->expects($this->once())
|
||||||
|
->method('getColorSpace')
|
||||||
|
->will($this->returnValue(''));
|
||||||
|
$media->expects($this->any())
|
||||||
|
->method('getType')
|
||||||
|
->will($this->returnValue('Document'));
|
||||||
|
$media->expects($this->any())
|
||||||
|
->method('getFile')
|
||||||
|
->will($this->returnValue(new \SplFileInfo(__FILE__)));
|
||||||
|
|
||||||
|
$File = new File(self::$DI['app'], $media, self::$DI['collection']);
|
||||||
|
|
||||||
|
$response = $this->object->check(self::$DI['app']['orm.em'], $File);
|
||||||
|
|
||||||
|
$this->assertInstanceOf('\\Alchemy\\Phrasea\\Border\\Checker\\Response', $response);
|
||||||
|
|
||||||
|
$this->assertEquals($this->createTranslatorMock()->trans('The file does not match available color'), $response->getMessage($this->createTranslatorMock()));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @covers Alchemy\Phrasea\Border\Checker\Colorspace::getMessage
|
* @covers Alchemy\Phrasea\Border\Checker\Colorspace::getMessage
|
||||||
*/
|
*/
|
||||||
|
Reference in New Issue
Block a user