mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-18 15:33:15 +00:00
Add databox_subdef tests
This commit is contained in:
@@ -9,72 +9,178 @@
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
use MediaAlchemyst\Specification\Specification;
|
||||
use Alchemy\Phrasea\Media\Subdef\Image;
|
||||
use Alchemy\Phrasea\Media\Subdef\Audio;
|
||||
use Alchemy\Phrasea\Media\Subdef\Video;
|
||||
use Alchemy\Phrasea\Media\Subdef\FlexPaper;
|
||||
use Alchemy\Phrasea\Media\Subdef\Gif;
|
||||
use Alchemy\Phrasea\Media\Subdef\Subdef as SubdefSpecs;
|
||||
use Alchemy\Phrasea\Media\Type\Type as SubdefType;
|
||||
|
||||
/**
|
||||
*
|
||||
* @package
|
||||
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
|
||||
* @link www.phraseanet.com
|
||||
*/
|
||||
abstract class databox_subdefAbstract
|
||||
class databox_subdef
|
||||
{
|
||||
|
||||
/**
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
protected $debug = false;
|
||||
/**
|
||||
* The class type of the subdef
|
||||
* Is null or one of the CLASS_* constants
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $class;
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $name;
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $path;
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $subdef_group;
|
||||
protected $baseurl;
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $mediatype;
|
||||
/**
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $labels = array();
|
||||
/**
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
protected $write_meta;
|
||||
/**
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected $current_mediatype;
|
||||
/**
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
protected $downloadable;
|
||||
protected static $mediaTypeToSubdefTypes = array(
|
||||
SubdefType::TYPE_AUDIO => array(SubdefSpecs::TYPE_IMAGE, SubdefSpecs::TYPE_AUDIO),
|
||||
SubdefType::TYPE_DOCUMENT => array(SubdefSpecs::TYPE_IMAGE, SubdefSpecs::TYPE_FLEXPAPER),
|
||||
SubdefType::TYPE_FLASH => array(SubdefSpecs::TYPE_IMAGE),
|
||||
SubdefType::TYPE_IMAGE => array(SubdefSpecs::TYPE_IMAGE),
|
||||
SubdefType::TYPE_VIDEO => array(SubdefSpecs::TYPE_IMAGE, SubdefSpecs::TYPE_VIDEO, SubdefSpecs::TYPE_ANIMATION),
|
||||
);
|
||||
|
||||
const CLASS_THUMBNAIL = 'thumbnail';
|
||||
|
||||
const CLASS_PREVIEW = 'preview';
|
||||
|
||||
const CLASS_DOCUMENT = 'document';
|
||||
|
||||
/**
|
||||
*
|
||||
* @param SimpleXMLElement $sd
|
||||
* @return databox_subdef
|
||||
*/
|
||||
public function __construct(SubdefType $type, SimpleXMLElement $sd)
|
||||
{
|
||||
$this->subdef_group = $type;
|
||||
$this->class = (string) $sd->attributes()->class;
|
||||
$this->name = strtolower($sd->attributes()->name);
|
||||
$this->downloadable = p4field::isyes($sd->attributes()->downloadable);
|
||||
$this->path = trim($sd->path) !== '' ? p4string::addEndSlash(trim($sd->path)) : '';
|
||||
|
||||
$this->baseurl = trim($sd->baseurl) !== '' ? p4string::addEndSlash(trim($sd->baseurl)) : false;
|
||||
|
||||
$this->write_meta = p4field::isyes((string) $sd->meta);
|
||||
|
||||
foreach ($sd->label as $label)
|
||||
{
|
||||
$lang = trim((string) $label->attributes()->lang);
|
||||
|
||||
if ($lang)
|
||||
{
|
||||
$this->labels[$lang] = (string) $label;
|
||||
}
|
||||
}
|
||||
|
||||
switch ((string) $sd->mediatype)
|
||||
{
|
||||
default:
|
||||
case SubdefSpecs::TYPE_IMAGE:
|
||||
$this->subdef_type = $this->buildImageSubdef($sd);
|
||||
break;
|
||||
case SubdefSpecs::TYPE_AUDIO:
|
||||
$this->subdef_type = $this->buildAudioSubdef($sd);
|
||||
break;
|
||||
case SubdefSpecs::TYPE_VIDEO:
|
||||
$this->subdef_type = $this->buildVideoSubdef($sd);
|
||||
break;
|
||||
case SubdefSpecs::TYPE_ANIMATION:
|
||||
$this->subdef_type = $this->buildGifSubdef($sd);
|
||||
break;
|
||||
case SubdefSpecs::TYPE_FLEXPAPER:
|
||||
$this->subdef_type = $this->buildFlexPaperSubdef($sd);
|
||||
break;
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
protected function buildImageSubdef(SimpleXMLElement $sd)
|
||||
{
|
||||
$image = new Image();
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
return $image;
|
||||
}
|
||||
|
||||
protected function buildAudioSubdef(SimpleXMLElement $sd)
|
||||
{
|
||||
return new Audio();
|
||||
}
|
||||
|
||||
protected function buildFlexPaperSubdef(SimpleXMLElement $sd)
|
||||
{
|
||||
return new FlexPaper();
|
||||
}
|
||||
|
||||
protected function buildGifSubdef(SimpleXMLElement $sd)
|
||||
{
|
||||
$gif = new Gif();
|
||||
|
||||
if ($sd->size)
|
||||
{
|
||||
$gif->setOptionValue(Gif::OPTION_SIZE, (int) $sd->size);
|
||||
}
|
||||
if ($sd->delay)
|
||||
{
|
||||
$gif->setOptionValue(Gif::OPTION_DELAY, (int) $sd->delay);
|
||||
}
|
||||
|
||||
return $gif;
|
||||
}
|
||||
|
||||
protected function buildVideoSubdef(SimpleXMLElement $sd)
|
||||
{
|
||||
$video = new Video();
|
||||
|
||||
if ($sd->size)
|
||||
{
|
||||
$video->setOptionValue(Video::OPTION_SIZE, (int) $sd->size);
|
||||
}
|
||||
if ($sd->a_codec)
|
||||
{
|
||||
$video->setOptionValue(Video::OPTION_ACODEC, (string) $sd->a_codec);
|
||||
}
|
||||
if ($sd->v_codec)
|
||||
{
|
||||
$video->setOptionValue(Video::OPTION_VCODEC, (string) $sd->v_codec);
|
||||
}
|
||||
if ($sd->fps)
|
||||
{
|
||||
$video->setOptionValue(Video::OPTION_FRAMERATE, (int) $sd->fps);
|
||||
}
|
||||
if ($sd->bitrate)
|
||||
{
|
||||
$video->setOptionValue(Video::OPTION_BITRATE, (int) $sd->bitrate);
|
||||
}
|
||||
|
||||
return $video;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return string
|
||||
@@ -104,11 +210,20 @@ abstract class databox_subdefAbstract
|
||||
|
||||
/**
|
||||
*
|
||||
* @return string
|
||||
* @return type
|
||||
*/
|
||||
public function get_mediatype()
|
||||
public function getSubdefType()
|
||||
{
|
||||
return $this->current_mediatype;
|
||||
return $this->subdef_type;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return type
|
||||
*/
|
||||
public function getSubdefGroup()
|
||||
{
|
||||
return $this->subdef_group;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -120,110 +235,53 @@ abstract class databox_subdefAbstract
|
||||
return $this->labels;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param SimpleXMLElement $sd
|
||||
* @return databox_subdefAbstract
|
||||
*/
|
||||
public function __construct(SimpleXMLElement $sd)
|
||||
{
|
||||
|
||||
$this->class = (string) $sd->attributes()->class;
|
||||
$this->name = (string) strtolower($sd->attributes()->name);
|
||||
$this->downloadable = p4field::isyes((string) $sd->attributes()->downloadable);
|
||||
$this->path = trim($sd->path) !== '' ? p4string::addEndSlash(trim($sd->path)) : '';
|
||||
|
||||
$this->baseurl = trim($sd->baseurl) !== '' ?
|
||||
p4string::addEndSlash(trim($sd->baseurl)) : false;
|
||||
$this->current_mediatype = (string) $sd->mediatype;
|
||||
switch ($this->current_mediatype)
|
||||
{
|
||||
case 'image':
|
||||
default:
|
||||
$size = (int) $sd->size;
|
||||
$resolution = trim($sd->dpi);
|
||||
$strip = p4field::isyes((string) $sd->strip);
|
||||
$quality = trim($sd->quality);
|
||||
$this->mediatype = new databox_subdef_mediatype_image($size, $resolution, $strip, $quality);
|
||||
break;
|
||||
case 'audio':
|
||||
$this->mediatype = new databox_subdef_mediatype_audio();
|
||||
break;
|
||||
case 'video':
|
||||
$fps = (int) $sd->fps;
|
||||
$threads = (int) $sd->threads;
|
||||
$bitrate = (int) $sd->bitrate;
|
||||
$vcodec = trim($sd->vcodec);
|
||||
$acodec = trim($sd->acodec);
|
||||
$size = (int) $sd->size;
|
||||
$this->mediatype = new databox_subdef_mediatype_video($size, $fps, $threads, $bitrate, $acodec, $vcodec);
|
||||
break;
|
||||
case 'gif':
|
||||
$delay = (int) $sd->delay;
|
||||
$size = (int) $sd->size;
|
||||
$this->mediatype = new databox_subdef_mediatype_gif($size, $delay);
|
||||
break;
|
||||
case 'flexpaper':
|
||||
$this->mediatype = new databox_subdef_mediatype_flexpaper();
|
||||
break;
|
||||
}
|
||||
|
||||
$this->write_meta = p4field::isyes((string) $sd->meta);
|
||||
|
||||
foreach ($sd->label as $label)
|
||||
{
|
||||
$lang = trim((string) $label->attributes()->lang);
|
||||
if ($lang)
|
||||
$this->labels[$lang] = (string) $label;
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function is_downloadable()
|
||||
{
|
||||
return $this->downloadable;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return Array
|
||||
*/
|
||||
public function get_mediatype_options()
|
||||
public function getAvailableSubdefTypes()
|
||||
{
|
||||
$options = array();
|
||||
foreach ($this->available_mediatypes as $mediatype)
|
||||
$subdefTypes = array();
|
||||
|
||||
if (isset(self::$mediaTypeToSubdefTypes[$this->subdef_group->getType()]))
|
||||
{
|
||||
if ($mediatype == $this->current_mediatype)
|
||||
foreach (self::$mediaTypeToSubdefTypes[$this->subdef_group->getType()] as $subdefType)
|
||||
{
|
||||
$mediatype_obj = $this->mediatype;
|
||||
if ($subdefType == $this->subdef_type->getType())
|
||||
{
|
||||
$mediatype_obj = $this->subdef_type;
|
||||
}
|
||||
else
|
||||
{
|
||||
try
|
||||
{
|
||||
$mediatype_class = 'databox_subdef_mediatype_' . $mediatype;
|
||||
$mediatype_obj = new $mediatype_class();
|
||||
}
|
||||
catch (Exception $e)
|
||||
switch ($subdefType)
|
||||
{
|
||||
case SubdefSpecs::TYPE_ANIMATION:
|
||||
$mediatype_obj = new Gif();
|
||||
break;
|
||||
case SubdefSpecs::TYPE_AUDIO:
|
||||
$mediatype_obj = new Audio();
|
||||
break;
|
||||
case SubdefSpecs::TYPE_FLEXPAPER:
|
||||
$mediatype_obj = new FlexPaper();
|
||||
break;
|
||||
case SubdefSpecs::TYPE_IMAGE:
|
||||
$mediatype_obj = new Image();
|
||||
break;
|
||||
case SubdefSpecs::TYPE_VIDEO:
|
||||
$mediatype_obj = new Video();
|
||||
break;
|
||||
default:
|
||||
continue;
|
||||
break;
|
||||
}
|
||||
}
|
||||
$media_opt = $mediatype_obj->get_available_options($this);
|
||||
|
||||
foreach ($media_opt as $opt_name => $values)
|
||||
{
|
||||
if (is_null($values['value']) || $values['value'] == '')
|
||||
{
|
||||
$values['value'] = $values['default'];
|
||||
$media_opt[$opt_name] = $values;
|
||||
}
|
||||
}
|
||||
$options[$mediatype] = $media_opt;
|
||||
}
|
||||
|
||||
return $options;
|
||||
$subdefTypes[] = $mediatype_obj;
|
||||
}
|
||||
}
|
||||
|
||||
return $subdefTypes;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -236,22 +294,6 @@ abstract class databox_subdefAbstract
|
||||
return $this->write_meta;
|
||||
}
|
||||
|
||||
/**
|
||||
* logs
|
||||
*
|
||||
* @param <type> $message
|
||||
* @return databox_subdefAbstract
|
||||
*/
|
||||
public function log($message)
|
||||
{
|
||||
if ($this->debug)
|
||||
{
|
||||
echo "\t --> \t" . $message . "\n";
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return string
|
||||
@@ -261,65 +303,18 @@ abstract class databox_subdefAbstract
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param record $record
|
||||
* @param string $pathdest
|
||||
* @param registry $registry
|
||||
* @return media_subdef
|
||||
*/
|
||||
public function generate(record_adapter &$record, $pathdest, registry &$registry)
|
||||
public function getSpecs()
|
||||
{
|
||||
$dest_dir = p4string::addEndSlash(dirname($pathdest));
|
||||
if (!$pathdest)
|
||||
{
|
||||
$dest_dir = databox::dispatch($this->path);
|
||||
}
|
||||
|
||||
$baseurl = $this->baseurl ?
|
||||
$this->baseurl . substr($dest_dir, strlen($this->path)) : '';
|
||||
|
||||
try
|
||||
{
|
||||
$generated = $this->generator_switcher($record, $dest_dir, $registry);
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
throw $e;
|
||||
}
|
||||
|
||||
return media_subdef::create($record, $this->get_name(), $generated, $baseurl);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param record $record
|
||||
* @param string $dest_dir
|
||||
* @param string $extension
|
||||
* @return string
|
||||
*/
|
||||
protected function get_newpathfile_name(record_adapter &$record, $dest_dir, $extension)
|
||||
{
|
||||
return $dest_dir . $record->get_record_id() . '_'
|
||||
. $this->name . '.' . $extension;
|
||||
return $this->subdef_type->getMediaAlchemystSpec();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return <type>
|
||||
*/
|
||||
public function get_options()
|
||||
public function getOptions()
|
||||
{
|
||||
return $this->mediatype->get_options($this);
|
||||
return $this->subdef_type->getOptions();
|
||||
}
|
||||
|
||||
/**
|
||||
* Abstract generator switcher
|
||||
*
|
||||
* @param record_Interface $record
|
||||
* @param string $dest_dir
|
||||
* @param registry $registry
|
||||
* @return system_file
|
||||
*/
|
||||
abstract protected function generator_switcher(record_Interface &$record, $dest_dir, registry &$registry);
|
||||
}
|
||||
|
@@ -47,13 +47,27 @@ class databox_subdefsStructure implements IteratorAggregate
|
||||
return $this->AvSubdefs;
|
||||
}
|
||||
|
||||
public function getSubdefGroup($searchGroup)
|
||||
{
|
||||
$searchGroup = strtolower($searchGroup);
|
||||
|
||||
foreach ($this->AvSubdefs as $groupname => $subdefgroup)
|
||||
{
|
||||
if ($searchGroup == $groupname)
|
||||
{
|
||||
return $subdefgroup;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return databox_subdefsStructure
|
||||
*/
|
||||
protected function load_subdefs()
|
||||
{
|
||||
|
||||
$sx_struct = $this->databox->get_sxml_structure();
|
||||
|
||||
$this->AvSubdefs = array(
|
||||
@@ -65,54 +79,49 @@ class databox_subdefsStructure implements IteratorAggregate
|
||||
);
|
||||
|
||||
if ( ! $sx_struct)
|
||||
|
||||
{
|
||||
return $this;
|
||||
}
|
||||
|
||||
$subdefgroup = $sx_struct->subdefs[0];
|
||||
|
||||
|
||||
foreach ($subdefgroup as $k => $subdefs)
|
||||
{
|
||||
$subdefgroup_name = (string) $subdefs->attributes()->name;
|
||||
$subdefgroup_name = strtolower($subdefs->attributes()->name);
|
||||
|
||||
if ( ! isset($AvSubdefs[$subdefgroup_name]))
|
||||
{
|
||||
$AvSubdefs[$subdefgroup_name] = array();
|
||||
}
|
||||
|
||||
foreach ($subdefs as $sd)
|
||||
{
|
||||
$subdef_name = strtolower($sd->attributes()->name);
|
||||
|
||||
$subdef_name = mb_strtolower((string) $sd->attributes()->name);
|
||||
switch ($subdefgroup_name)
|
||||
{
|
||||
case 'audio':
|
||||
$AvSubdefs[$subdefgroup_name][$subdef_name] =
|
||||
new databox_subdef_audio($sd);
|
||||
$type = new \Alchemy\Phrasea\Media\Type\Audio();
|
||||
break;
|
||||
|
||||
case 'image':
|
||||
$AvSubdefs[$subdefgroup_name][$subdef_name] =
|
||||
new databox_subdef_image($sd);
|
||||
$type = new \Alchemy\Phrasea\Media\Type\Image();
|
||||
break;
|
||||
|
||||
case 'video':
|
||||
$AvSubdefs[$subdefgroup_name][$subdef_name] =
|
||||
new databox_subdef_video($sd);
|
||||
$type = new \Alchemy\Phrasea\Media\Type\Video();
|
||||
break;
|
||||
|
||||
case 'document':
|
||||
$AvSubdefs[$subdefgroup_name][$subdef_name] =
|
||||
new databox_subdef_document($sd);
|
||||
$type = new \Alchemy\Phrasea\Media\Type\Document();
|
||||
break;
|
||||
|
||||
case 'flash':
|
||||
$AvSubdefs[$subdefgroup_name][$subdef_name] =
|
||||
new databox_subdef_flash($sd);
|
||||
$type = new \Alchemy\Phrasea\Media\Type\Flash();
|
||||
break;
|
||||
|
||||
default:
|
||||
continue;
|
||||
break;
|
||||
}
|
||||
|
||||
$AvSubdefs[$subdefgroup_name][$subdef_name] = new databox_subdef($type, $sd);
|
||||
}
|
||||
}
|
||||
$this->AvSubdefs = $AvSubdefs;
|
||||
@@ -124,7 +133,7 @@ class databox_subdefsStructure implements IteratorAggregate
|
||||
*
|
||||
* @param type $subdef_type
|
||||
* @param type $subdef_name
|
||||
* @return databox_subdefAbstract
|
||||
* @return databox_subdef
|
||||
*/
|
||||
public function get_subdef($subdef_type, $subdef_name)
|
||||
{
|
||||
|
270
tests/databox/databox_subdefTest.php
Normal file
270
tests/databox/databox_subdefTest.php
Normal file
@@ -0,0 +1,270 @@
|
||||
<?php
|
||||
|
||||
class databox_subdefTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
|
||||
/**
|
||||
* @covers databox_subdef::__construct
|
||||
* @covers databox_subdef::get_class
|
||||
* @covers databox_subdef::get_name
|
||||
* @covers databox_subdef::meta_writeable
|
||||
* @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_baseurl
|
||||
* @covers databox_subdef::get_path
|
||||
* @covers databox_subdef::getSpecs
|
||||
* @covers databox_subdef::getOptions
|
||||
* @covers databox_subdef::buildImageSubdef
|
||||
*/
|
||||
public function testImage()
|
||||
{
|
||||
$xml = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
||||
<subdef class="preview" name="preview_api" downloadable="true">
|
||||
<path>/home/datas/noweb/db_alch_phrasea/subdefs/</path>
|
||||
<baseurl/>
|
||||
<meta>yes</meta>
|
||||
<mediatype>image</mediatype>
|
||||
<label lang="fr">Prévisualisation</label>
|
||||
<label lang="en">Preview</label>
|
||||
<size>1000</size>
|
||||
<dpi>150</dpi>
|
||||
<strip>no</strip>
|
||||
<quality>75</quality>
|
||||
</subdef>';
|
||||
|
||||
$type = new \Alchemy\Phrasea\Media\Type\Image();
|
||||
$object = new databox_subdef($type, simplexml_load_string($xml));
|
||||
|
||||
$this->assertEquals(databox_subdef::CLASS_PREVIEW, $object->get_class());
|
||||
$this->assertEquals('/home/datas/noweb/db_alch_phrasea/subdefs/', $object->get_path());
|
||||
$this->assertEquals('', $object->get_baseurl());
|
||||
$this->assertInstanceOf('\\Alchemy\\Phrasea\\Media\Subdef\\Subdef', $object->getSubdefType());
|
||||
$this->assertEquals($type, $object->getSubdefGroup());
|
||||
|
||||
$labels = $object->get_labels();
|
||||
$this->assertTrue(is_array($labels));
|
||||
$this->assertArrayHasKey('fr', $labels);
|
||||
$this->assertEquals('Prévisualisation', $labels['fr']);
|
||||
$this->assertArrayHasKey('en', $labels);
|
||||
$this->assertEquals('Preview', $labels['en']);
|
||||
|
||||
$this->assertTrue($object->is_downloadable());
|
||||
$this->assertTrue(is_array($object->getAvailableSubdefTypes()));
|
||||
$this->assertTrue(count($object->getAvailableSubdefTypes()) > 0);
|
||||
|
||||
foreach ($object->getAvailableSubdefTypes() as $type)
|
||||
{
|
||||
$this->assertInstanceOf('\\Alchemy\\Phrasea\\Media\\Subdef\\Image', $type);
|
||||
}
|
||||
|
||||
$this->assertTrue($object->meta_writeable());
|
||||
|
||||
$this->assertEquals('preview_api', $object->get_name());
|
||||
$this->assertInstanceOf('\\MediaAlchemyst\\Specification\\Image', $object->getSpecs());
|
||||
|
||||
$options = $object->getOptions();
|
||||
$this->assertTrue(is_array($options));
|
||||
|
||||
foreach ($options as $option)
|
||||
{
|
||||
$this->assertInstanceOf('\\Alchemy\\Phrasea\\Media\\Subdef\\OptionType\\OptionType', $option);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers databox_subdef::__construct
|
||||
* @covers databox_subdef::get_class
|
||||
* @covers databox_subdef::get_name
|
||||
* @covers databox_subdef::meta_writeable
|
||||
* @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_baseurl
|
||||
* @covers databox_subdef::get_path
|
||||
* @covers databox_subdef::getSpecs
|
||||
* @covers databox_subdef::getOptions
|
||||
* @covers databox_subdef::buildVideoSubdef
|
||||
*/
|
||||
public function testVideo()
|
||||
{
|
||||
$xml = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
||||
<subdef class="thumbnail" name="video_api" downloadable="false">
|
||||
<path>/home/datas/noweb/db_alch_phrasea/video/</path>
|
||||
<baseurl>/video/</baseurl>
|
||||
<meta>no</meta>
|
||||
<mediatype>video</mediatype>
|
||||
<size>196</size>
|
||||
<dpi>72</dpi>
|
||||
<strip>yes</strip>
|
||||
<quality>75</quality>
|
||||
<fps>10</fps>
|
||||
<threads>1</threads>
|
||||
<bitrate>192</bitrate>
|
||||
<a_codec>faac</a_codec>
|
||||
<v_codec>libx264</v_codec>
|
||||
</subdef>';
|
||||
|
||||
$type = new \Alchemy\Phrasea\Media\Type\Video();
|
||||
$object = new databox_subdef($type, simplexml_load_string($xml));
|
||||
|
||||
$this->assertEquals(databox_subdef::CLASS_THUMBNAIL, $object->get_class());
|
||||
$this->assertEquals('/home/datas/noweb/db_alch_phrasea/video/', $object->get_path());
|
||||
$this->assertEquals('/video/', $object->get_baseurl());
|
||||
$this->assertInstanceOf('\\Alchemy\\Phrasea\\Media\Subdef\\Subdef', $object->getSubdefType());
|
||||
$this->assertEquals($type, $object->getSubdefGroup());
|
||||
|
||||
$labels = $object->get_labels();
|
||||
$this->assertTrue(is_array($labels));
|
||||
$this->assertEquals(0, count($labels));
|
||||
|
||||
$this->assertFalse($object->is_downloadable());
|
||||
$this->assertTrue(is_array($object->getAvailableSubdefTypes()));
|
||||
$this->assertTrue(count($object->getAvailableSubdefTypes()) > 0);
|
||||
|
||||
foreach ($object->getAvailableSubdefTypes() as $type)
|
||||
{
|
||||
$this->assertInstanceOf('\\Alchemy\\Phrasea\\Media\\Subdef\\Subdef', $type);
|
||||
}
|
||||
|
||||
$this->assertFalse($object->meta_writeable());
|
||||
|
||||
$this->assertEquals('video_api', $object->get_name());
|
||||
$this->assertInstanceOf('\\MediaAlchemyst\\Specification\\Video', $object->getSpecs());
|
||||
|
||||
$options = $object->getOptions();
|
||||
$this->assertTrue(is_array($options));
|
||||
|
||||
foreach ($options as $option)
|
||||
{
|
||||
$this->assertInstanceOf('\\Alchemy\\Phrasea\\Media\\Subdef\\OptionType\\OptionType', $option);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers databox_subdef::__construct
|
||||
* @covers databox_subdef::getSpecs
|
||||
* @covers databox_subdef::getOptions
|
||||
* @covers databox_subdef::buildGifSubdef
|
||||
*/
|
||||
public function testGif()
|
||||
{
|
||||
$xml = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
||||
<subdef class="thumbnail" name="gifou" downloadable="false">
|
||||
<path>/home/datas/noweb/db_alch_phrasea/video/</path>
|
||||
<baseurl>web//db_alch_beta/subdefs/</baseurl>
|
||||
<meta>no</meta>
|
||||
<mediatype>gif</mediatype>
|
||||
<size>200</size>
|
||||
<strip>yes</strip>
|
||||
<delay>100</delay>
|
||||
</subdef>';
|
||||
|
||||
$type = new \Alchemy\Phrasea\Media\Type\Video();
|
||||
$object = new databox_subdef($type, simplexml_load_string($xml));
|
||||
|
||||
$this->assertInstanceOf('\\MediaAlchemyst\\Specification\\Animation', $object->getSpecs());
|
||||
|
||||
$options = $object->getOptions();
|
||||
$this->assertTrue(is_array($options));
|
||||
|
||||
foreach ($options as $option)
|
||||
{
|
||||
$this->assertInstanceOf('\\Alchemy\\Phrasea\\Media\\Subdef\\OptionType\\OptionType', $option);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers databox_subdef::__construct
|
||||
* @covers databox_subdef::getSpecs
|
||||
* @covers databox_subdef::getOptions
|
||||
* @covers databox_subdef::buildAudioSubdef
|
||||
*/
|
||||
public function testAudio()
|
||||
{
|
||||
$xml = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
||||
<subdef class="thumbnail" name="gifou" downloadable="false">
|
||||
<path>/home/datas/noweb/db_alch_phrasea/video/</path>
|
||||
<mediatype>audio</mediatype>
|
||||
</subdef>';
|
||||
|
||||
$type = new \Alchemy\Phrasea\Media\Type\Audio();
|
||||
$object = new databox_subdef($type, simplexml_load_string($xml));
|
||||
|
||||
$this->assertInstanceOf('\\MediaAlchemyst\\Specification\\Audio', $object->getSpecs());
|
||||
|
||||
$options = $object->getOptions();
|
||||
$this->assertTrue(is_array($options));
|
||||
|
||||
foreach ($options as $option)
|
||||
{
|
||||
$this->assertInstanceOf('\\Alchemy\\Phrasea\\Media\\Subdef\\OptionType\\OptionType', $option);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers databox_subdef::__construct
|
||||
* @covers databox_subdef::getSpecs
|
||||
* @covers databox_subdef::getOptions
|
||||
* @covers databox_subdef::buildFlexPaperSubdef
|
||||
*/
|
||||
public function testFlexPaper()
|
||||
{
|
||||
$xml = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
||||
<subdef class="thumbnail" name="gifou" downloadable="false">
|
||||
<path>/home/datas/noweb/db_alch_phrasea/video/</path>
|
||||
<mediatype>flexpaper</mediatype>
|
||||
</subdef>';
|
||||
|
||||
$type = new \Alchemy\Phrasea\Media\Type\Flash();
|
||||
$object = new databox_subdef($type, simplexml_load_string($xml));
|
||||
|
||||
$this->assertInstanceOf('\\MediaAlchemyst\\Specification\\Flash', $object->getSpecs());
|
||||
|
||||
$options = $object->getOptions();
|
||||
$this->assertTrue(is_array($options));
|
||||
|
||||
foreach ($options as $option)
|
||||
{
|
||||
$this->assertInstanceOf('\\Alchemy\\Phrasea\\Media\\Subdef\\OptionType\\OptionType', $option);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getVariouasTypeAndSubdefs
|
||||
* @covers databox_subdef::getAvailableSubdefTypes
|
||||
*/
|
||||
public function testGetAvailableSubdefTypes($object)
|
||||
{
|
||||
|
||||
foreach ($object->getAvailableSubdefTypes() as $type)
|
||||
{
|
||||
$this->assertInstanceOf('\\Alchemy\\Phrasea\\Media\\Subdef\\Subdef', $type);
|
||||
}
|
||||
}
|
||||
|
||||
public function getVariouasTypeAndSubdefs()
|
||||
{
|
||||
|
||||
$xmlImage = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
||||
<subdef class="thumbnail" name="gifou" downloadable="false">
|
||||
<path>/home/datas/noweb/db_alch_phrasea/video/</path>
|
||||
<mediatype>image</mediatype>
|
||||
</subdef>';
|
||||
|
||||
$typeAudio = new \Alchemy\Phrasea\Media\Type\Audio();
|
||||
$typeDocument = new \Alchemy\Phrasea\Media\Type\Document();
|
||||
$typeVideo = new \Alchemy\Phrasea\Media\Type\Video();
|
||||
|
||||
return array(
|
||||
array(new databox_subdef($typeAudio, simplexml_load_string($xmlImage))),
|
||||
array(new databox_subdef($typeDocument, simplexml_load_string($xmlImage))),
|
||||
array(new databox_subdef($typeVideo, simplexml_load_string($xmlImage))),
|
||||
);
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user