Add databox_subdef tests

This commit is contained in:
Romain Neutron
2012-04-25 12:31:34 +02:00
parent 79c1d831c1
commit 9111594802
3 changed files with 787 additions and 513 deletions

View File

@@ -9,317 +9,312 @@
* file that was distributed with this source code. * 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 * @package
* @license http://opensource.org/licenses/gpl-3.0 GPLv3 * @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link www.phraseanet.com * @link www.phraseanet.com
*/ */
abstract class databox_subdefAbstract class databox_subdef
{ {
/** /**
* * The class type of the subdef
* @var boolean * Is null or one of the CLASS_* constants
*/ *
protected $debug = false; * @var string
/** */
* protected $class;
* @var string protected $name;
*/ protected $path;
protected $class; protected $subdef_group;
/** protected $baseurl;
* protected $labels = array();
* @var string protected $write_meta;
*/ protected $downloadable;
protected $name; protected static $mediaTypeToSubdefTypes = array(
/** SubdefType::TYPE_AUDIO => array(SubdefSpecs::TYPE_IMAGE, SubdefSpecs::TYPE_AUDIO),
* SubdefType::TYPE_DOCUMENT => array(SubdefSpecs::TYPE_IMAGE, SubdefSpecs::TYPE_FLEXPAPER),
* @var string SubdefType::TYPE_FLASH => array(SubdefSpecs::TYPE_IMAGE),
*/ SubdefType::TYPE_IMAGE => array(SubdefSpecs::TYPE_IMAGE),
protected $path; SubdefType::TYPE_VIDEO => array(SubdefSpecs::TYPE_IMAGE, SubdefSpecs::TYPE_VIDEO, SubdefSpecs::TYPE_ANIMATION),
/** );
*
* @var string
*/
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;
const CLASS_THUMBNAIL = 'thumbnail'; const CLASS_THUMBNAIL = 'thumbnail';
const CLASS_PREVIEW = 'preview';
const CLASS_DOCUMENT = 'document';
const CLASS_PREVIEW = 'preview'; /**
*
const CLASS_DOCUMENT = 'document'; * @param SimpleXMLElement $sd
* @return databox_subdef
/** */
* public function __construct(SubdefType $type, SimpleXMLElement $sd)
* @return string
*/
public function get_class()
{
return $this->class;
}
/**
*
* @return string
*/
public function get_path()
{
return $this->path;
}
/**
*
* @return string
*/
public function get_baseurl()
{
return $this->baseurl;
}
/**
*
* @return string
*/
public function get_mediatype()
{
return $this->current_mediatype;
}
/**
*
* @return Array
*/
public function get_labels()
{
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': $this->subdef_group = $type;
default: $this->class = (string) $sd->attributes()->class;
$size = (int) $sd->size; $this->name = strtolower($sd->attributes()->name);
$resolution = trim($sd->dpi); $this->downloadable = p4field::isyes($sd->attributes()->downloadable);
$strip = p4field::isyes((string) $sd->strip); $this->path = trim($sd->path) !== '' ? p4string::addEndSlash(trim($sd->path)) : '';
$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); $this->baseurl = trim($sd->baseurl) !== '' ? p4string::addEndSlash(trim($sd->baseurl)) : false;
foreach ($sd->label as $label) $this->write_meta = p4field::isyes((string) $sd->meta);
{
$lang = trim((string) $label->attributes()->lang);
if ($lang)
$this->labels[$lang] = (string) $label;
}
return $this; foreach ($sd->label as $label)
}
public function is_downloadable()
{
return $this->downloadable;
}
/**
*
* @return Array
*/
public function get_mediatype_options()
{
$options = array();
foreach ($this->available_mediatypes as $mediatype)
{
if ($mediatype == $this->current_mediatype)
{
$mediatype_obj = $this->mediatype;
}
else
{
try
{ {
$mediatype_class = 'databox_subdef_mediatype_' . $mediatype; $lang = trim((string) $label->attributes()->lang);
$mediatype_obj = new $mediatype_class();
if ($lang)
{
$this->labels[$lang] = (string) $label;
}
} }
catch (Exception $e)
switch ((string) $sd->mediatype)
{ {
continue; 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;
} }
}
$media_opt = $mediatype_obj->get_available_options($this);
foreach ($media_opt as $opt_name => $values) return $this;
{ }
if (is_null($values['value']) || $values['value'] == '')
protected function buildImageSubdef(SimpleXMLElement $sd)
{
$image = new Image();
if ($sd->size)
{ {
$values['value'] = $values['default']; $image->setOptionValue(Image::OPTION_SIZE, (int) $sd->size);
$media_opt[$opt_name] = $values;
} }
} if ($sd->quality)
$options[$mediatype] = $media_opt; {
$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;
} }
return $options; protected function buildAudioSubdef(SimpleXMLElement $sd)
}
/**
* Tells us if we have to write meta datas in the subdef
*
* @return boolean
*/
public function meta_writeable()
{
return $this->write_meta;
}
/**
* logs
*
* @param <type> $message
* @return databox_subdefAbstract
*/
public function log($message)
{
if ($this->debug)
{ {
echo "\t --> \t" . $message . "\n"; return new Audio();
} }
return $this; protected function buildFlexPaperSubdef(SimpleXMLElement $sd)
}
/**
*
* @return string
*/
public function get_name()
{
return $this->name;
}
/**
*
* @param record $record
* @param string $pathdest
* @param registry $registry
* @return media_subdef
*/
public function generate(record_adapter &$record, $pathdest, registry &$registry)
{
$dest_dir = p4string::addEndSlash(dirname($pathdest));
if (!$pathdest)
{ {
$dest_dir = databox::dispatch($this->path); return new FlexPaper();
} }
$baseurl = $this->baseurl ? protected function buildGifSubdef(SimpleXMLElement $sd)
$this->baseurl . substr($dest_dir, strlen($this->path)) : '';
try
{ {
$generated = $this->generator_switcher($record, $dest_dir, $registry); $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;
} }
catch (Exception $e)
protected function buildVideoSubdef(SimpleXMLElement $sd)
{ {
throw $e; $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 media_subdef::create($record, $this->get_name(), $generated, $baseurl); /**
} *
* @return string
*/
public function get_class()
{
return $this->class;
}
/** /**
* *
* @param record $record * @return string
* @param string $dest_dir */
* @param string $extension public function get_path()
* @return string {
*/ return $this->path;
protected function get_newpathfile_name(record_adapter &$record, $dest_dir, $extension) }
{
return $dest_dir . $record->get_record_id() . '_'
. $this->name . '.' . $extension;
}
/** /**
* *
* @return <type> * @return string
*/ */
public function get_options() public function get_baseurl()
{ {
return $this->mediatype->get_options($this); return $this->baseurl;
} }
/**
*
* @return type
*/
public function getSubdefType()
{
return $this->subdef_type;
}
/**
*
* @return type
*/
public function getSubdefGroup()
{
return $this->subdef_group;
}
/**
*
* @return Array
*/
public function get_labels()
{
return $this->labels;
}
public function is_downloadable()
{
return $this->downloadable;
}
public function getAvailableSubdefTypes()
{
$subdefTypes = array();
if (isset(self::$mediaTypeToSubdefTypes[$this->subdef_group->getType()]))
{
foreach (self::$mediaTypeToSubdefTypes[$this->subdef_group->getType()] as $subdefType)
{
if ($subdefType == $this->subdef_type->getType())
{
$mediatype_obj = $this->subdef_type;
}
else
{
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;
}
}
$subdefTypes[] = $mediatype_obj;
}
}
return $subdefTypes;
}
/**
* Tells us if we have to write meta datas in the subdef
*
* @return boolean
*/
public function meta_writeable()
{
return $this->write_meta;
}
/**
*
* @return string
*/
public function get_name()
{
return $this->name;
}
public function getSpecs()
{
return $this->subdef_type->getMediaAlchemystSpec();
}
/**
*
* @return <type>
*/
public function getOptions()
{
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);
} }

View File

@@ -18,264 +18,273 @@
class databox_subdefsStructure implements IteratorAggregate class databox_subdefsStructure implements IteratorAggregate
{ {
/** /**
* *
* @var Array * @var Array
*/ */
protected $AvSubdefs = array(); protected $AvSubdefs = array();
/** /**
* *
* @return ArrayIterator * @return ArrayIterator
*/ */
public function getIterator() public function getIterator()
{
return new ArrayIterator($this->AvSubdefs);
}
/**
*
* @param databox $databox
* @return Array
*/
public function __construct(databox &$databox)
{
$this->databox = $databox;
$this->load_subdefs();
return $this->AvSubdefs;
}
/**
*
* @return databox_subdefsStructure
*/
protected function load_subdefs()
{
$sx_struct = $this->databox->get_sxml_structure();
$this->AvSubdefs = array(
'image' => array(),
'video' => array(),
'audio' => array(),
'document' => array(),
'flash' => array()
);
if (!$sx_struct)
return $this;
$subdefgroup = $sx_struct->subdefs[0];
foreach ($subdefgroup as $k => $subdefs)
{ {
$subdefgroup_name = (string) $subdefs->attributes()->name; return new ArrayIterator($this->AvSubdefs);
}
if (!isset($AvSubdefs[$subdefgroup_name])) /**
$AvSubdefs[$subdefgroup_name] = array(); *
* @param databox $databox
* @return Array
*/
public function __construct(databox &$databox)
{
$this->databox = $databox;
foreach ($subdefs as $sd) $this->load_subdefs();
{
$subdef_name = mb_strtolower((string) $sd->attributes()->name); return $this->AvSubdefs;
switch ($subdefgroup_name) }
public function getSubdefGroup($searchGroup)
{
$searchGroup = strtolower($searchGroup);
foreach ($this->AvSubdefs as $groupname => $subdefgroup)
{ {
case 'audio': if ($searchGroup == $groupname)
$AvSubdefs[$subdefgroup_name][$subdef_name] = {
new databox_subdef_audio($sd); return $subdefgroup;
break; }
case 'image':
$AvSubdefs[$subdefgroup_name][$subdef_name] =
new databox_subdef_image($sd);
break;
case 'video':
$AvSubdefs[$subdefgroup_name][$subdef_name] =
new databox_subdef_video($sd);
break;
case 'document':
$AvSubdefs[$subdefgroup_name][$subdef_name] =
new databox_subdef_document($sd);
break;
case 'flash':
$AvSubdefs[$subdefgroup_name][$subdef_name] =
new databox_subdef_flash($sd);
break;
default:
continue;
break;
} }
}
return null;
} }
$this->AvSubdefs = $AvSubdefs;
return $this; /**
} *
* @return databox_subdefsStructure
/** */
* protected function load_subdefs()
* @param type $subdef_type
* @param type $subdef_name
* @return databox_subdefAbstract
*/
public function get_subdef($subdef_type, $subdef_name)
{
if (isset($this->AvSubdefs[$subdef_type]) && isset($this->AvSubdefs[$subdef_type][$subdef_name]))
{ {
return $this->AvSubdefs[$subdef_type][$subdef_name]; $sx_struct = $this->databox->get_sxml_structure();
$this->AvSubdefs = array(
'image' => array(),
'video' => array(),
'audio' => array(),
'document' => array(),
'flash' => array()
);
if ( ! $sx_struct)
{
return $this;
}
$subdefgroup = $sx_struct->subdefs[0];
foreach ($subdefgroup as $k => $subdefs)
{
$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);
switch ($subdefgroup_name)
{
case 'audio':
$type = new \Alchemy\Phrasea\Media\Type\Audio();
break;
case 'image':
$type = new \Alchemy\Phrasea\Media\Type\Image();
break;
case 'video':
$type = new \Alchemy\Phrasea\Media\Type\Video();
break;
case 'document':
$type = new \Alchemy\Phrasea\Media\Type\Document();
break;
case 'flash':
$type = new \Alchemy\Phrasea\Media\Type\Flash();
break;
default:
continue;
break;
}
$AvSubdefs[$subdefgroup_name][$subdef_name] = new databox_subdef($type, $sd);
}
}
$this->AvSubdefs = $AvSubdefs;
return $this;
} }
throw new Exception_Databox_SubdefNotFound();
}
/** /**
* *
* @param string $group * @param type $subdef_type
* @param string $name * @param type $subdef_name
* @return databox_subdefsStructure * @return databox_subdef
*/ */
public function delete_subdef($group, $name) public function get_subdef($subdef_type, $subdef_name)
{
$dom_struct = $this->databox->get_dom_structure();
$dom_xp = $this->databox->get_xpath_structure();
$nodes = $dom_xp->query(
'//record/subdefs/'
. 'subdefgroup[@name="' . $group . '"]/'
. 'subdef[@name="' . $name . '"]'
);
if ($nodes->length > 0)
{ {
$node = $nodes->item(0); if (isset($this->AvSubdefs[$subdef_type]) && isset($this->AvSubdefs[$subdef_type][$subdef_name]))
$parent = $node->parentNode; {
$parent->removeChild($node); return $this->AvSubdefs[$subdef_type][$subdef_name];
}
throw new Exception_Databox_SubdefNotFound();
} }
if (isset($AvSubdefs[$group]) && isset($AvSubdefs[$group][$name])) /**
unset($AvSubdefs[$group][$name]); *
* @param string $group
$this->databox->saveStructure($dom_struct); * @param string $name
* @return databox_subdefsStructure
return $this; */
} public function delete_subdef($group, $name)
/**
*
* @param string $group
* @param string $name
* @param string $class
* @return databox_subdefsStructure
*/
public function add_subdef($groupname, $name, $class)
{
$dom_struct = $this->databox->get_dom_structure();
$subdef = $dom_struct->createElement('subdef');
$subdef->setAttribute('class', $class);
$subdef->setAttribute('name', mb_strtolower($name));
$dom_xp = $this->databox->get_xpath_structure();
$query = '//record/subdefs/subdefgroup[@name="' . $groupname . '"]';
$groups = $dom_xp->query($query);
if ($groups->length == 0)
{ {
$group = $dom_struct->createElement('subdefgroup');
$group->setAttribute('name', $groupname); $dom_struct = $this->databox->get_dom_structure();
$dom_xp->query('/record/subdefs')->item(0)->appendChild($group); $dom_xp = $this->databox->get_xpath_structure();
$nodes = $dom_xp->query(
'//record/subdefs/'
. 'subdefgroup[@name="' . $group . '"]/'
. 'subdef[@name="' . $name . '"]'
);
if ($nodes->length > 0)
{
$node = $nodes->item(0);
$parent = $node->parentNode;
$parent->removeChild($node);
}
if (isset($AvSubdefs[$group]) && isset($AvSubdefs[$group][$name]))
unset($AvSubdefs[$group][$name]);
$this->databox->saveStructure($dom_struct);
return $this;
} }
else
/**
*
* @param string $group
* @param string $name
* @param string $class
* @return databox_subdefsStructure
*/
public function add_subdef($groupname, $name, $class)
{ {
$group = $groups->item(0); $dom_struct = $this->databox->get_dom_structure();
$subdef = $dom_struct->createElement('subdef');
$subdef->setAttribute('class', $class);
$subdef->setAttribute('name', mb_strtolower($name));
$dom_xp = $this->databox->get_xpath_structure();
$query = '//record/subdefs/subdefgroup[@name="' . $groupname . '"]';
$groups = $dom_xp->query($query);
if ($groups->length == 0)
{
$group = $dom_struct->createElement('subdefgroup');
$group->setAttribute('name', $groupname);
$dom_xp->query('/record/subdefs')->item(0)->appendChild($group);
}
else
{
$group = $groups->item(0);
}
$group->appendChild($subdef);
$this->databox->saveStructure($dom_struct);
$this->load_subdefs();
return $this;
} }
$group->appendChild($subdef); /**
*
$this->databox->saveStructure($dom_struct); * @param string $group
* @param string $name
$this->load_subdefs(); * @param string $class
* @param boolean $downloadable
return $this; * @param Array $options
} * @return databox_subdefsStructure
*/
/** public function set_subdef($group, $name, $class, $downloadable, $options)
*
* @param string $group
* @param string $name
* @param string $class
* @param boolean $downloadable
* @param Array $options
* @return databox_subdefsStructure
*/
public function set_subdef($group, $name, $class, $downloadable, $options)
{
$dom_struct = $this->databox->get_dom_structure();
$subdef = $dom_struct->createElement('subdef');
$subdef->setAttribute('class', $class);
$subdef->setAttribute('name', mb_strtolower($name));
$subdef->setAttribute('downloadable', ($downloadable ? 'true' : 'false'));
foreach ($options as $option => $value)
{ {
$child = $dom_struct->createElement($option); $dom_struct = $this->databox->get_dom_structure();
$child->appendChild($dom_struct->createTextNode($value));
$subdef->appendChild($child); $subdef = $dom_struct->createElement('subdef');
$subdef->setAttribute('class', $class);
$subdef->setAttribute('name', mb_strtolower($name));
$subdef->setAttribute('downloadable', ($downloadable ? 'true' : 'false'));
foreach ($options as $option => $value)
{
$child = $dom_struct->createElement($option);
$child->appendChild($dom_struct->createTextNode($value));
$subdef->appendChild($child);
}
$dom_xp = $this->databox->get_xpath_structure();
$nodes = $dom_xp->query('//record/subdefs/'
. 'subdefgroup[@name="' . $group . '"]');
if ($nodes->length > 0)
{
$dom_group = $nodes->item(0);
}
else
{
$dom_group = $dom_struct->createElement('subdefgroup');
$dom_group->setAttribute('name', $group);
$nodes = $dom_xp->query('//record/subdefs');
if ($nodes->length > 0)
{
$nodes->item(0)->appendChild($dom_group);
}
else
{
throw new Exception('Unable to find /record/subdefs xquery');
}
}
$nodes = $dom_xp->query(
'//record/subdefs/'
. 'subdefgroup[@name="' . $group . '"]/'
. 'subdef[@name="' . $name . '"]'
);
if ($nodes->length > 0)
{
for ($i = 0; $i < $nodes->length; $i ++ )
{
$dom_group->removeChild($nodes->item($i));
}
}
$dom_group->appendChild($subdef);
$this->databox->saveStructure($dom_struct);
$this->load_subdefs();
return $this;
} }
$dom_xp = $this->databox->get_xpath_structure();
$nodes = $dom_xp->query('//record/subdefs/'
. 'subdefgroup[@name="' . $group . '"]');
if ($nodes->length > 0)
{
$dom_group = $nodes->item(0);
}
else
{
$dom_group = $dom_struct->createElement('subdefgroup');
$dom_group->setAttribute('name', $group);
$nodes = $dom_xp->query('//record/subdefs');
if ($nodes->length > 0)
{
$nodes->item(0)->appendChild($dom_group);
}
else
{
throw new Exception('Unable to find /record/subdefs xquery');
}
}
$nodes = $dom_xp->query(
'//record/subdefs/'
. 'subdefgroup[@name="' . $group . '"]/'
. 'subdef[@name="' . $name . '"]'
);
if ($nodes->length > 0)
{
for ($i = 0; $i < $nodes->length; $i++)
{
$dom_group->removeChild($nodes->item($i));
}
}
$dom_group->appendChild($subdef);
$this->databox->saveStructure($dom_struct);
$this->load_subdefs();
return $this;
}
} }

View 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))),
);
}
}