Merge pull request #1675 from bburnichon/feature/add-orderable-flag-PHRAS-954

Add orderable flag
This commit is contained in:
Thibaud Fabre
2016-02-11 14:06:45 +01:00
8 changed files with 274 additions and 260 deletions

View File

@@ -80,6 +80,7 @@ class SubdefsController extends Controller
$class = $request->request->get($post_sub . '_class'); $class = $request->request->get($post_sub . '_class');
$downloadable = $request->request->get($post_sub . '_downloadable'); $downloadable = $request->request->get($post_sub . '_downloadable');
$orderable = $request->request->get($post_sub . '_orderable');
$defaults = ['path', 'meta', 'mediatype']; $defaults = ['path', 'meta', 'mediatype'];
@@ -107,7 +108,7 @@ class SubdefsController extends Controller
$labels = $request->request->get($post_sub . '_label', []); $labels = $request->request->get($post_sub . '_label', []);
$subdefs->set_subdef($group, $name, $class, $downloadable, $options, $labels); $subdefs->set_subdef($group, $name, $class, $downloadable, $options, $labels, $orderable);
} }
} }

View File

@@ -1,5 +1,4 @@
<?php <?php
/* /*
* This file is part of Phraseanet * This file is part of Phraseanet
* *
@@ -9,18 +8,37 @@
* file that was distributed with this source code. * file that was distributed with this source code.
*/ */
use Alchemy\Phrasea\Media\Subdef\Image;
use Alchemy\Phrasea\Media\Subdef\Audio; use Alchemy\Phrasea\Media\Subdef\Audio;
use Alchemy\Phrasea\Media\Subdef\Video;
use Alchemy\Phrasea\Media\Subdef\FlexPaper; use Alchemy\Phrasea\Media\Subdef\FlexPaper;
use Alchemy\Phrasea\Media\Subdef\Gif; use Alchemy\Phrasea\Media\Subdef\Gif;
use Alchemy\Phrasea\Media\Subdef\Image;
use Alchemy\Phrasea\Media\Subdef\Subdef as SubdefSpecs; use Alchemy\Phrasea\Media\Subdef\Subdef as SubdefSpecs;
use Alchemy\Phrasea\Media\Subdef\Video;
use Alchemy\Phrasea\Media\Type\Type as SubdefType; use Alchemy\Phrasea\Media\Type\Type as SubdefType;
use MediaAlchemyst\Specification\SpecificationInterface; use MediaAlchemyst\Specification\SpecificationInterface;
use Symfony\Component\Translation\TranslatorInterface; use Symfony\Component\Translation\TranslatorInterface;
class databox_subdef class databox_subdef
{ {
const CLASS_THUMBNAIL = 'thumbnail';
const CLASS_PREVIEW = 'preview';
const CLASS_DOCUMENT = 'document';
const DEVICE_ALL = 'all';
const DEVICE_HANDHELD = 'handheld';
const DEVICE_PRINT = 'print';
const DEVICE_PROJECTION = 'projection';
const DEVICE_SCREEN = 'screen';
const DEVICE_TV = 'tv';
protected static $mediaTypeToSubdefTypes = [
SubdefType::TYPE_AUDIO => [SubdefSpecs::TYPE_IMAGE, SubdefSpecs::TYPE_AUDIO],
SubdefType::TYPE_DOCUMENT => [SubdefSpecs::TYPE_IMAGE, SubdefSpecs::TYPE_FLEXPAPER],
SubdefType::TYPE_FLASH => [SubdefSpecs::TYPE_IMAGE],
SubdefType::TYPE_IMAGE => [SubdefSpecs::TYPE_IMAGE],
SubdefType::TYPE_VIDEO => [SubdefSpecs::TYPE_IMAGE, SubdefSpecs::TYPE_VIDEO, SubdefSpecs::TYPE_ANIMATION],
];
/** /**
* The class type of the subdef * The class type of the subdef
* Is null or one of the CLASS_* constants * Is null or one of the CLASS_* constants
@@ -33,37 +51,23 @@ class databox_subdef
protected $path; protected $path;
protected $subdef_group; protected $subdef_group;
protected $labels = []; protected $labels = [];
protected $downloadable;
protected $translator;
/** /**
* @var bool * @var bool
*/ */
private $requiresMetadataUpdate; private $requiresMetadataUpdate;
protected $downloadable;
protected $translator;
protected static $mediaTypeToSubdefTypes = [
SubdefType::TYPE_AUDIO => [SubdefSpecs::TYPE_IMAGE, SubdefSpecs::TYPE_AUDIO],
SubdefType::TYPE_DOCUMENT => [SubdefSpecs::TYPE_IMAGE, SubdefSpecs::TYPE_FLEXPAPER],
SubdefType::TYPE_FLASH => [SubdefSpecs::TYPE_IMAGE],
SubdefType::TYPE_IMAGE => [SubdefSpecs::TYPE_IMAGE],
SubdefType::TYPE_VIDEO => [SubdefSpecs::TYPE_IMAGE, SubdefSpecs::TYPE_VIDEO, SubdefSpecs::TYPE_ANIMATION],
];
const CLASS_THUMBNAIL = 'thumbnail';
const CLASS_PREVIEW = 'preview';
const CLASS_DOCUMENT = 'document';
const DEVICE_ALL = 'all';
const DEVICE_HANDHELD = 'handheld';
const DEVICE_PRINT = 'print';
const DEVICE_PROJECTION = 'projection';
const DEVICE_SCREEN = 'screen';
const DEVICE_TV = 'tv';
/** /**
* * @var bool
* @param SubdefType $type */
private $orderable;
/**
* @param SubdefType $type
* @param SimpleXMLElement $sd * @param SimpleXMLElement $sd
* * @param TranslatorInterface $translator
* @return databox_subdef
*/ */
public function __construct(SubdefType $type, SimpleXMLElement $sd, TranslatorInterface $translator) public function __construct(SubdefType $type, SimpleXMLElement $sd, TranslatorInterface $translator)
{ {
@@ -77,6 +81,7 @@ class databox_subdef
$this->name = strtolower($sd->attributes()->name); $this->name = strtolower($sd->attributes()->name);
$this->downloadable = p4field::isyes($sd->attributes()->downloadable); $this->downloadable = p4field::isyes($sd->attributes()->downloadable);
$this->orderable = isset($sd->attributes()->orderable) ? p4field::isyes($sd->attributes()->orderable) : true;
$this->path = trim($sd->path) !== '' ? p4string::addEndSlash(trim($sd->path)) : ''; $this->path = trim($sd->path) !== '' ? p4string::addEndSlash(trim($sd->path)) : '';
$this->requiresMetadataUpdate = p4field::isyes((string) $sd->meta); $this->requiresMetadataUpdate = p4field::isyes((string) $sd->meta);
@@ -107,12 +112,130 @@ class databox_subdef
$this->subdef_type = $this->buildFlexPaperSubdef($sd); $this->subdef_type = $this->buildFlexPaperSubdef($sd);
break; break;
} }
return $this;
} }
/** /**
* Build Image Subdef object depending the SimpleXMLElement
* *
* @param SimpleXMLElement $sd
* @return Image
*/
protected function buildImageSubdef(SimpleXMLElement $sd)
{
$image = new Image($this->translator);
if ($sd->size) {
$image->setOptionValue(Image::OPTION_SIZE, (int) $sd->size);
}
if ($sd->quality) {
$image->setOptionValue(Image::OPTION_QUALITY, (int) $sd->quality);
}
if ($sd->strip) {
$image->setOptionValue(Image::OPTION_STRIP, p4field::isyes($sd->strip));
}
if ($sd->dpi) {
$image->setOptionValue(Image::OPTION_RESOLUTION, (int) $sd->dpi);
}
if ($sd->flatten) {
$image->setOptionValue(Image::OPTION_FLATTEN, p4field::isyes($sd->flatten));
}
return $image;
}
/**
* Build Audio Subdef object depending the SimpleXMLElement
*
* @param SimpleXMLElement $sd
* @return Audio
*/
protected function buildAudioSubdef(SimpleXMLElement $sd)
{
$audio = new Audio($this->translator);
if ($sd->acodec) {
$audio->setOptionValue(Audio::OPTION_ACODEC, (string) $sd->acodec);
}
if ($sd->audiobitrate) {
$audio->setOptionValue(Audio::OPTION_AUDIOBITRATE, (int) $sd->audiobitrate);
}
if ($sd->audiosamplerate) {
$audio->setOptionValue(Audio::OPTION_AUDIOSAMPLERATE, (int) $sd->audiosamplerate);
}
return $audio;
}
/**
* Build Video Subdef object depending the SimpleXMLElement
*
* @param SimpleXMLElement $sd
* @return Video
*/
protected function buildVideoSubdef(SimpleXMLElement $sd)
{
$video = new Video($this->translator);
if ($sd->size) {
$video->setOptionValue(Video::OPTION_SIZE, (int) $sd->size);
}
if ($sd->acodec) {
$video->setOptionValue(Video::OPTION_ACODEC, (string) $sd->acodec);
}
if ($sd->vcodec) {
$video->setOptionValue(Video::OPTION_VCODEC, (string) $sd->vcodec);
}
if ($sd->fps) {
$video->setOptionValue(Video::OPTION_FRAMERATE, (int) $sd->fps);
}
if ($sd->bitrate) {
$video->setOptionValue(Video::OPTION_BITRATE, (int) $sd->bitrate);
}
if ($sd->audiobitrate) {
$video->setOptionValue(Video::OPTION_AUDIOBITRATE, (int) $sd->audiobitrate);
}
if ($sd->audiosamplerate) {
$video->setOptionValue(Video::OPTION_AUDIOSAMPLERATE, (int) $sd->audiosamplerate);
}
if ($sd->GOPsize) {
$video->setOptionValue(Video::OPTION_GOPSIZE, (int) $sd->GOPsize);
}
return $video;
}
/**
* Build GIF Subdef object depending the SimpleXMLElement
*
* @param SimpleXMLElement $sd
* @return Gif
*/
protected function buildGifSubdef(SimpleXMLElement $sd)
{
$gif = new Gif($this->translator);
if ($sd->size) {
$gif->setOptionValue(Gif::OPTION_SIZE, (int) $sd->size);
}
if ($sd->delay) {
$gif->setOptionValue(Gif::OPTION_DELAY, (int) $sd->delay);
}
return $gif;
}
/**
* Build Flexpaper Subdef object depending the SimpleXMLElement
*
* @param SimpleXMLElement $sd
* @return FlexPaper
*/
protected function buildFlexPaperSubdef(SimpleXMLElement $sd)
{
return new FlexPaper($this->translator);
}
/**
* @return string * @return string
*/ */
public function get_class() public function get_class()
@@ -121,7 +244,6 @@ class databox_subdef
} }
/** /**
*
* @return string * @return string
*/ */
public function get_path() public function get_path()
@@ -132,7 +254,7 @@ class databox_subdef
/** /**
* The devices matching this subdefinition * The devices matching this subdefinition
* *
* @return Array * @return array
*/ */
public function getDevices() public function getDevices()
{ {
@@ -142,7 +264,7 @@ class databox_subdef
/** /**
* The current SubdefType the subdef converts documents * The current SubdefType the subdef converts documents
* *
* @return Alchemy\Phrasea\Media\Subdef\Subdef * @return \Alchemy\Phrasea\Media\Subdef\Subdef
*/ */
public function getSubdefType() public function getSubdefType()
{ {
@@ -162,7 +284,7 @@ class databox_subdef
/** /**
* An associative label ; keys are i18n languages * An associative label ; keys are i18n languages
* *
* @return Array * @return array
*/ */
public function get_labels() public function get_labels()
{ {
@@ -181,15 +303,31 @@ class databox_subdef
} }
/** /**
* boolean * The name of the subdef
* *
* @return type * @return string
*/ */
public function is_downloadable() public function get_name()
{
return $this->name;
}
/**
* @return bool
*/
public function isDownloadable()
{ {
return $this->downloadable; return $this->downloadable;
} }
/**
* @return bool
*/
public function isOrderable()
{
return $this->orderable;
}
/** /**
* Get an array of Alchemy\Phrasea\Media\Subdef\Subdef available for the current Media Type * Get an array of Alchemy\Phrasea\Media\Subdef\Subdef available for the current Media Type
* *
@@ -256,16 +394,6 @@ class databox_subdef
return $this->requiresMetadataUpdate; return $this->requiresMetadataUpdate;
} }
/**
* The name of the subdef
*
* @return string
*/
public function get_name()
{
return $this->name;
}
/** /**
* Get the MediaAlchemyst specs for the current subdef * Get the MediaAlchemyst specs for the current subdef
* *
@@ -285,125 +413,4 @@ class databox_subdef
{ {
return $this->subdef_type->getOptions(); return $this->subdef_type->getOptions();
} }
/**
* Build Image Subdef object depending the SimpleXMLElement
*
* @param SimpleXMLElement $sd
* @return \Alchemy\Phrasea\Media\Subdef\Video
*/
protected function buildImageSubdef(SimpleXMLElement $sd)
{
$image = new Image($this->translator);
if ($sd->size) {
$image->setOptionValue(Image::OPTION_SIZE, (int) $sd->size);
}
if ($sd->quality) {
$image->setOptionValue(Image::OPTION_QUALITY, (int) $sd->quality);
}
if ($sd->strip) {
$image->setOptionValue(Image::OPTION_STRIP, p4field::isyes($sd->strip));
}
if ($sd->dpi) {
$image->setOptionValue(Image::OPTION_RESOLUTION, (int) $sd->dpi);
}
if ($sd->flatten) {
$image->setOptionValue(Image::OPTION_FLATTEN, p4field::isyes($sd->flatten));
}
return $image;
}
/**
* Build Audio Subdef object depending the SimpleXMLElement
*
* @param SimpleXMLElement $sd
* @return \Alchemy\Phrasea\Media\Subdef\Video
*/
protected function buildAudioSubdef(SimpleXMLElement $sd)
{
$audio = new Audio($this->translator);
if ($sd->acodec) {
$audio->setOptionValue(Audio::OPTION_ACODEC, (string) $sd->acodec);
}
if ($sd->audiobitrate) {
$audio->setOptionValue(Audio::OPTION_AUDIOBITRATE, (int) $sd->audiobitrate);
}
if ($sd->audiosamplerate) {
$audio->setOptionValue(Audio::OPTION_AUDIOSAMPLERATE, (int) $sd->audiosamplerate);
}
return $audio;
}
/**
* Build Flexpaper Subdef object depending the SimpleXMLElement
*
* @param SimpleXMLElement $sd
* @return \Alchemy\Phrasea\Media\Subdef\Video
*/
protected function buildFlexPaperSubdef(SimpleXMLElement $sd)
{
return new FlexPaper($this->translator);
}
/**
* Build GIF Subdef object depending the SimpleXMLElement
*
* @param SimpleXMLElement $sd
* @return \Alchemy\Phrasea\Media\Subdef\Video
*/
protected function buildGifSubdef(SimpleXMLElement $sd)
{
$gif = new Gif($this->translator);
if ($sd->size) {
$gif->setOptionValue(Gif::OPTION_SIZE, (int) $sd->size);
}
if ($sd->delay) {
$gif->setOptionValue(Gif::OPTION_DELAY, (int) $sd->delay);
}
return $gif;
}
/**
* Build Video Subdef object depending the SimpleXMLElement
*
* @param SimpleXMLElement $sd
* @return \Alchemy\Phrasea\Media\Subdef\Video
*/
protected function buildVideoSubdef(SimpleXMLElement $sd)
{
$video = new Video($this->translator);
if ($sd->size) {
$video->setOptionValue(Video::OPTION_SIZE, (int) $sd->size);
}
if ($sd->acodec) {
$video->setOptionValue(Video::OPTION_ACODEC, (string) $sd->acodec);
}
if ($sd->vcodec) {
$video->setOptionValue(Video::OPTION_VCODEC, (string) $sd->vcodec);
}
if ($sd->fps) {
$video->setOptionValue(Video::OPTION_FRAMERATE, (int) $sd->fps);
}
if ($sd->bitrate) {
$video->setOptionValue(Video::OPTION_BITRATE, (int) $sd->bitrate);
}
if ($sd->audiobitrate) {
$video->setOptionValue(Video::OPTION_AUDIOBITRATE, (int) $sd->audiobitrate);
}
if ($sd->audiosamplerate) {
$video->setOptionValue(Video::OPTION_AUDIOSAMPLERATE, (int) $sd->audiosamplerate);
}
if ($sd->GOPsize) {
$video->setOptionValue(Video::OPTION_GOPSIZE, (int) $sd->GOPsize);
}
return $video;
}
} }

View File

@@ -223,10 +223,11 @@ class databox_subdefsStructure implements IteratorAggregate, Countable
* @param boolean $downloadable * @param boolean $downloadable
* @param array $options * @param array $options
* @param array $labels * @param array $labels
* @param bool $orderable
* @return databox_subdefsStructure * @return databox_subdefsStructure
* @throws Exception * @throws Exception
*/ */
public function set_subdef($group, $name, $class, $downloadable, $options, $labels) public function set_subdef($group, $name, $class, $downloadable, $options, $labels, $orderable = true)
{ {
$dom_struct = $this->databox->get_dom_structure(); $dom_struct = $this->databox->get_dom_structure();
@@ -234,6 +235,7 @@ class databox_subdefsStructure implements IteratorAggregate, Countable
$subdef->setAttribute('class', $class); $subdef->setAttribute('class', $class);
$subdef->setAttribute('name', mb_strtolower($name)); $subdef->setAttribute('name', mb_strtolower($name));
$subdef->setAttribute('downloadable', ($downloadable ? 'true' : 'false')); $subdef->setAttribute('downloadable', ($downloadable ? 'true' : 'false'));
$subdef->setAttribute('orderable', ($orderable ? 'true' : 'false'));
foreach ($labels as $code => $label) { foreach ($labels as $code => $label) {
$child = $dom_struct->createElement('label'); $child = $dom_struct->createElement('label');

View File

@@ -108,7 +108,7 @@ class patch_370alpha6a extends patchAbstract
$options['meta'] = $subdef->isMetadataUpdateRequired() ? 'yes' : 'no'; $options['meta'] = $subdef->isMetadataUpdateRequired() ? 'yes' : 'no';
$options['devices'] = [databox_subdef::DEVICE_SCREEN]; $options['devices'] = [databox_subdef::DEVICE_SCREEN];
$root->set_subdef($groupname, $subdef->get_name(), $subdef->get_class(), $subdef->is_downloadable(), $options, []); $root->set_subdef($groupname, $subdef->get_name(), $subdef->get_class(), $subdef->isDownloadable(), $options, []);
} }
protected function addMobileSubdefVideo($root, $baseSubdef, $groupname) protected function addMobileSubdefVideo($root, $baseSubdef, $groupname)

View File

@@ -85,11 +85,10 @@ class record_exportElement extends record_adapter
$sbas_id = phrasea::sbasFromBas($this->app, $this->get_base_id()); $sbas_id = phrasea::sbasFromBas($this->app, $this->get_base_id());
$subdefgroups = $this->app->findDataboxById($sbas_id)->get_subdef_structure(); /** @var databox_subdef[] $subdefs */
$subdefs = []; $subdefs = [];
foreach ($subdefgroups as $subdef_type => $subdefs_obj) { foreach ($this->app->findDataboxById($sbas_id)->get_subdef_structure() as $subdef_type => $subdefs_obj) {
if ($subdef_type == $this->get_type()) { if ($subdef_type == $this->get_type()) {
$subdefs = $subdefs_obj; $subdefs = $subdefs_obj;
break; break;
@@ -173,7 +172,7 @@ class record_exportElement extends record_adapter
$downloadable[$name] = false; $downloadable[$name] = false;
$downloadable_settings = $subdef->is_downloadable(); $downloadable_settings = $subdef->isDownloadable();
if (! $downloadable_settings || $go_dl[$class] === false) { if (! $downloadable_settings || $go_dl[$class] === false) {
continue; continue;

View File

@@ -227,7 +227,12 @@
{% endfor %} {% endfor %}
<tr> <tr>
<td>{{ 'Telechargeable' | trans }}</td> <td>{{ 'Telechargeable' | trans }}</td>
<td><input type="checkbox" name="{{subdefgroup}}_{{subdefname}}_downloadable" {% if subdef.is_downloadable() %}checked="checked"{% endif %} value="1" /></td> <td><input type="checkbox" name="{{subdefgroup}}_{{subdefname}}_downloadable" {% if subdef.isDownloadable() %}checked="checked"{% endif %} value="1" /></td>
<td></td>
</tr>
<tr>
<td>{{ 'subdef.orderable' | trans }}</td>
<td><input type="checkbox" name="{{subdefgroup}}_{{subdefname}}_orderable" {% if subdef.isOrderable() %}checked="checked"{% endif %} value="1" /></td>
<td></td> <td></td>
</tr> </tr>
<tr> <tr>

View File

@@ -94,8 +94,7 @@ class SubdefsTest extends \PhraseanetAuthenticatedWebTestCase
$subdefs = new \databox_subdefsStructure($app->findDataboxById($this->databox_id), $app['translator']); $subdefs = new \databox_subdefsStructure($app->findDataboxById($this->databox_id), $app['translator']);
$subdef = $subdefs->get_subdef("image", $name); $subdef = $subdefs->get_subdef("image", $name);
/* @var $subdef \databox_subdef */ $this->assertFalse($subdef->isDownloadable());
$this->assertFalse($subdef->is_downloadable());
$options = $subdef->getOptions(); $options = $subdef->getOptions();

View File

@@ -1,27 +1,23 @@
<?php <?php
/** use Alchemy\Phrasea\Media\Subdef\OptionType\OptionType;
* @group functional use Alchemy\Phrasea\Media\Subdef;
* @group legacy use Alchemy\Phrasea\Media\Type;
*/ use MediaAlchemyst\Specification;
class databox_subdefTest extends \PhraseanetTestCase use Symfony\Component\Translation\TranslatorInterface;
{
class databox_subdefTest extends \PHPUnit_Framework_TestCase
{
/** /**
* @covers databox_subdef::__construct * @var TranslatorInterface
* @covers databox_subdef::get_class
* @covers databox_subdef::get_name
* @covers databox_subdef::isMetadataUpdateRequired
* @covers databox_subdef::getAvailableSubdefTypes
* @covers databox_subdef::is_downloadable
* @covers databox_subdef::get_labels
* @covers databox_subdef::getSubdefGroup
* @covers databox_subdef::getSubdefType
* @covers databox_subdef::get_path
* @covers databox_subdef::getSpecs
* @covers databox_subdef::getOptions
* @covers databox_subdef::buildImageSubdef
*/ */
private $translator;
protected function setUp()
{
$this->translator = $this->getTranslatorMock();
}
public function testImage() public function testImage()
{ {
$xml = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?> $xml = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
@@ -37,12 +33,12 @@ class databox_subdefTest extends \PhraseanetTestCase
<quality>75</quality> <quality>75</quality>
</subdef>'; </subdef>';
$type = new \Alchemy\Phrasea\Media\Type\Image(); $type = new Type\Image();
$object = new databox_subdef($type, simplexml_load_string($xml), $this->getMock('Symfony\Component\Translation\TranslatorInterface')); $object = new databox_subdef($type, simplexml_load_string($xml), $this->translator);
$this->assertEquals(databox_subdef::CLASS_PREVIEW, $object->get_class()); $this->assertEquals(databox_subdef::CLASS_PREVIEW, $object->get_class());
$this->assertEquals('/home/datas/noweb/db_alch_phrasea/subdefs/', $object->get_path()); $this->assertEquals('/home/datas/noweb/db_alch_phrasea/subdefs/', $object->get_path());
$this->assertInstanceOf('\\Alchemy\\Phrasea\\Media\Subdef\\Subdef', $object->getSubdefType()); $this->assertInstanceOf(Subdef\Subdef::class, $object->getSubdefType());
$this->assertEquals($type, $object->getSubdefGroup()); $this->assertEquals($type, $object->getSubdefGroup());
$labels = $object->get_labels(); $labels = $object->get_labels();
@@ -52,42 +48,27 @@ class databox_subdefTest extends \PhraseanetTestCase
$this->assertArrayHasKey('en', $labels); $this->assertArrayHasKey('en', $labels);
$this->assertEquals('Preview', $labels['en']); $this->assertEquals('Preview', $labels['en']);
$this->assertTrue($object->is_downloadable()); $this->assertTrue($object->isDownloadable());
$this->assertTrue(is_array($object->getAvailableSubdefTypes())); $this->assertTrue(is_array($object->getAvailableSubdefTypes()));
$this->assertTrue(count($object->getAvailableSubdefTypes()) > 0); $this->assertTrue(count($object->getAvailableSubdefTypes()) > 0);
foreach ($object->getAvailableSubdefTypes() as $type) { foreach ($object->getAvailableSubdefTypes() as $type) {
$this->assertInstanceOf('\\Alchemy\\Phrasea\\Media\\Subdef\\Image', $type); $this->assertInstanceOf(Subdef\Image::class, $type);
} }
$this->assertTrue($object->isMetadataUpdateRequired()); $this->assertTrue($object->isMetadataUpdateRequired());
$this->assertEquals('preview_api', $object->get_name()); $this->assertEquals('preview_api', $object->get_name());
$this->assertInstanceOf('\\MediaAlchemyst\\Specification\\Image', $object->getSpecs()); $this->assertInstanceOf(Specification\Image::class, $object->getSpecs());
$options = $object->getOptions(); $options = $object->getOptions();
$this->assertTrue(is_array($options)); $this->assertTrue(is_array($options));
foreach ($options as $option) { foreach ($options as $option) {
$this->assertInstanceOf('\\Alchemy\\Phrasea\\Media\\Subdef\\OptionType\\OptionType', $option); $this->assertInstanceOf(OptionType::class, $option);
} }
} }
/**
* @covers databox_subdef::__construct
* @covers databox_subdef::get_class
* @covers databox_subdef::get_name
* @covers databox_subdef::isMetadataUpdateRequired
* @covers databox_subdef::getAvailableSubdefTypes
* @covers databox_subdef::is_downloadable
* @covers databox_subdef::get_labels
* @covers databox_subdef::getSubdefGroup
* @covers databox_subdef::getSubdefType
* @covers databox_subdef::get_path
* @covers databox_subdef::getSpecs
* @covers databox_subdef::getOptions
* @covers databox_subdef::buildVideoSubdef
*/
public function testVideo() public function testVideo()
{ {
$xml = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?> $xml = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
@@ -107,44 +88,38 @@ class databox_subdefTest extends \PhraseanetTestCase
</subdef>'; </subdef>';
$type = new \Alchemy\Phrasea\Media\Type\Video(); $type = new \Alchemy\Phrasea\Media\Type\Video();
$object = new databox_subdef($type, simplexml_load_string($xml), $this->getMock('Symfony\Component\Translation\TranslatorInterface')); $object = new databox_subdef($type, simplexml_load_string($xml), $this->translator);
$this->assertEquals(databox_subdef::CLASS_THUMBNAIL, $object->get_class()); $this->assertEquals(databox_subdef::CLASS_THUMBNAIL, $object->get_class());
$this->assertEquals('/home/datas/noweb/db_alch_phrasea/video/', $object->get_path()); $this->assertEquals('/home/datas/noweb/db_alch_phrasea/video/', $object->get_path());
$this->assertInstanceOf('\\Alchemy\\Phrasea\\Media\Subdef\\Subdef', $object->getSubdefType()); $this->assertInstanceOf(Subdef\Subdef::class, $object->getSubdefType());
$this->assertEquals($type, $object->getSubdefGroup()); $this->assertEquals($type, $object->getSubdefGroup());
$labels = $object->get_labels(); $labels = $object->get_labels();
$this->assertTrue(is_array($labels)); $this->assertTrue(is_array($labels));
$this->assertEquals(0, count($labels)); $this->assertEquals(0, count($labels));
$this->assertFalse($object->is_downloadable()); $this->assertFalse($object->isDownloadable());
$this->assertTrue(is_array($object->getAvailableSubdefTypes())); $this->assertTrue(is_array($object->getAvailableSubdefTypes()));
$this->assertTrue(count($object->getAvailableSubdefTypes()) > 0); $this->assertTrue(count($object->getAvailableSubdefTypes()) > 0);
foreach ($object->getAvailableSubdefTypes() as $type) { foreach ($object->getAvailableSubdefTypes() as $type) {
$this->assertInstanceOf('\\Alchemy\\Phrasea\\Media\\Subdef\\Subdef', $type); $this->assertInstanceOf(Subdef\Subdef::class, $type);
} }
$this->assertFalse($object->isMetadataUpdateRequired()); $this->assertFalse($object->isMetadataUpdateRequired());
$this->assertEquals('video_api', $object->get_name()); $this->assertEquals('video_api', $object->get_name());
$this->assertInstanceOf('\\MediaAlchemyst\\Specification\\Video', $object->getSpecs()); $this->assertInstanceOf(Specification\Video::class, $object->getSpecs());
$options = $object->getOptions(); $options = $object->getOptions();
$this->assertTrue(is_array($options)); $this->assertTrue(is_array($options));
foreach ($options as $option) { foreach ($options as $option) {
$this->assertInstanceOf('\\Alchemy\\Phrasea\\Media\\Subdef\\OptionType\\OptionType', $option); $this->assertInstanceOf(OptionType::class, $option);
} }
} }
/**
* @covers databox_subdef::__construct
* @covers databox_subdef::getSpecs
* @covers databox_subdef::getOptions
* @covers databox_subdef::buildGifSubdef
*/
public function testGif() public function testGif()
{ {
$xml = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?> $xml = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
@@ -158,24 +133,18 @@ class databox_subdefTest extends \PhraseanetTestCase
</subdef>'; </subdef>';
$type = new \Alchemy\Phrasea\Media\Type\Video(); $type = new \Alchemy\Phrasea\Media\Type\Video();
$object = new databox_subdef($type, simplexml_load_string($xml), $this->getMock('Symfony\Component\Translation\TranslatorInterface')); $object = new databox_subdef($type, simplexml_load_string($xml), $this->translator);
$this->assertInstanceOf('\\MediaAlchemyst\\Specification\\Animation', $object->getSpecs()); $this->assertInstanceOf(Specification\Animation::class, $object->getSpecs());
$options = $object->getOptions(); $options = $object->getOptions();
$this->assertTrue(is_array($options)); $this->assertTrue(is_array($options));
foreach ($options as $option) { foreach ($options as $option) {
$this->assertInstanceOf('\\Alchemy\\Phrasea\\Media\\Subdef\\OptionType\\OptionType', $option); $this->assertInstanceOf(OptionType::class, $option);
} }
} }
/**
* @covers databox_subdef::__construct
* @covers databox_subdef::getSpecs
* @covers databox_subdef::getOptions
* @covers databox_subdef::buildAudioSubdef
*/
public function testAudio() public function testAudio()
{ {
$xml = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?> $xml = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
@@ -185,24 +154,18 @@ class databox_subdefTest extends \PhraseanetTestCase
</subdef>'; </subdef>';
$type = new \Alchemy\Phrasea\Media\Type\Audio(); $type = new \Alchemy\Phrasea\Media\Type\Audio();
$object = new databox_subdef($type, simplexml_load_string($xml), $this->getMock('Symfony\Component\Translation\TranslatorInterface')); $object = new databox_subdef($type, simplexml_load_string($xml), $this->translator);
$this->assertInstanceOf('\\MediaAlchemyst\\Specification\\Audio', $object->getSpecs()); $this->assertInstanceOf(Specification\Audio::class, $object->getSpecs());
$options = $object->getOptions(); $options = $object->getOptions();
$this->assertTrue(is_array($options)); $this->assertTrue(is_array($options));
foreach ($options as $option) { foreach ($options as $option) {
$this->assertInstanceOf('\\Alchemy\\Phrasea\\Media\\Subdef\\OptionType\\OptionType', $option); $this->assertInstanceOf(OptionType::class, $option);
} }
} }
/**
* @covers databox_subdef::__construct
* @covers databox_subdef::getSpecs
* @covers databox_subdef::getOptions
* @covers databox_subdef::buildFlexPaperSubdef
*/
public function testFlexPaper() public function testFlexPaper()
{ {
$xml = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?> $xml = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
@@ -212,47 +175,85 @@ class databox_subdefTest extends \PhraseanetTestCase
</subdef>'; </subdef>';
$type = new \Alchemy\Phrasea\Media\Type\Flash(); $type = new \Alchemy\Phrasea\Media\Type\Flash();
$object = new databox_subdef($type, simplexml_load_string($xml), $this->getMock('Symfony\Component\Translation\TranslatorInterface')); $object = new databox_subdef($type, simplexml_load_string($xml), $this->translator);
$this->assertInstanceOf('\\MediaAlchemyst\\Specification\\Flash', $object->getSpecs()); $this->assertInstanceOf(Specification\Flash::class, $object->getSpecs());
$options = $object->getOptions(); $options = $object->getOptions();
$this->assertTrue(is_array($options)); $this->assertTrue(is_array($options));
foreach ($options as $option) { foreach ($options as $option) {
$this->assertInstanceOf('\\Alchemy\\Phrasea\\Media\\Subdef\\OptionType\\OptionType', $option); $this->assertInstanceOf(OptionType::class, $option);
} }
} }
/** /**
* @dataProvider getVariouasTypeAndSubdefs * @dataProvider getVariouasTypeAndSubdefs
* @covers databox_subdef::getAvailableSubdefTypes
*/ */
public function testGetAvailableSubdefTypes($object) public function testGetAvailableSubdefTypes($object)
{ {
foreach ($object->getAvailableSubdefTypes() as $type) { foreach ($object->getAvailableSubdefTypes() as $type) {
$this->assertInstanceOf('\\Alchemy\\Phrasea\\Media\\Subdef\\Subdef', $type); $this->assertInstanceOf(Subdef\Subdef::class, $type);
} }
} }
public function getVariouasTypeAndSubdefs() public function getVariouasTypeAndSubdefs()
{ {
$xmlImage = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?> $xmlImage = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<subdef class="thumbnail" name="gifou" downloadable="false"> <subdef class="thumbnail" name="gifou" downloadable="false">
<path>/home/datas/noweb/db_alch_phrasea/video/</path> <path>/home/datas/noweb/db_alch_phrasea/video/</path>
<mediatype>image</mediatype> <mediatype>image</mediatype>
</subdef>'; </subdef>';
$typeAudio = new \Alchemy\Phrasea\Media\Type\Audio(); $translator = $this->getTranslatorMock();
$typeDocument = new \Alchemy\Phrasea\Media\Type\Document();
$typeVideo = new \Alchemy\Phrasea\Media\Type\Video();
return [ return [
[new databox_subdef($typeAudio, simplexml_load_string($xmlImage), $this->getMock('Symfony\Component\Translation\TranslatorInterface'))], [new databox_subdef(new Type\Audio(), simplexml_load_string($xmlImage), $translator)],
[new databox_subdef($typeDocument, simplexml_load_string($xmlImage), $this->getMock('Symfony\Component\Translation\TranslatorInterface'))], [new databox_subdef(new Type\Document(), simplexml_load_string($xmlImage), $translator)],
[new databox_subdef($typeVideo, simplexml_load_string($xmlImage), $this->getMock('Symfony\Component\Translation\TranslatorInterface'))], [new databox_subdef(new Type\Video(), simplexml_load_string($xmlImage), $translator)],
]; ];
} }
/**
* @param bool $expected
* @param null|string $configValue
* @dataProvider providesOrderableStatuses
*/
public function testOrderableStatus($expected, $configValue, $message)
{
$xmlTemplate = <<<'EOF'
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<subdef class="thumbnail" name="gifou" downloadable="false"%s>
<path>/home/datas/noweb/db_alch_phrasea/video/</path>
<mediatype>image</mediatype>
</subdef>
EOF;
if (null !== $configValue) {
$configValue = ' orderable="' . $configValue . '"';
}
$xml = sprintf($xmlTemplate, $configValue ?: '');
$sut = new databox_subdef(new Type\Image(), simplexml_load_string($xml), $this->translator);
$this->assertSame($expected, $sut->isOrderable(), $message);
}
public function providesOrderableStatuses()
{
return [
[true, null, 'No Orderable Status set should defaults to true'],
[false, 'false', 'Orderable should be false'],
[true, 'true', 'Orderable should be true'],
];
}
/**
* @return PHPUnit_Framework_MockObject_MockObject|TranslatorInterface
*/
private function getTranslatorMock()
{
return $this->getMock(TranslatorInterface::class);
}
} }