mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-17 15:03:25 +00:00
17
lib/Alchemy/Phrasea/Exception/Exception.php
Normal file
17
lib/Alchemy/Phrasea/Exception/Exception.php
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file is part of Phraseanet
|
||||||
|
*
|
||||||
|
* (c) 2005-2012 Alchemy
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please view the LICENSE
|
||||||
|
* file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Alchemy\Phrasea\Exception;
|
||||||
|
|
||||||
|
interface Exception
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
17
lib/Alchemy/Phrasea/Exception/InvalidArgumentException.php
Normal file
17
lib/Alchemy/Phrasea/Exception/InvalidArgumentException.php
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file is part of Phraseanet
|
||||||
|
*
|
||||||
|
* (c) 2005-2012 Alchemy
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please view the LICENSE
|
||||||
|
* file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Alchemy\Phrasea\Exception;
|
||||||
|
|
||||||
|
class InvalidArgumentException extends \InvalidArgumentException implements Exception
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
17
lib/Alchemy/Phrasea/Exception/RuntimeException.php
Normal file
17
lib/Alchemy/Phrasea/Exception/RuntimeException.php
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file is part of Phraseanet
|
||||||
|
*
|
||||||
|
* (c) 2005-2012 Alchemy
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please view the LICENSE
|
||||||
|
* file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Alchemy\Phrasea\Exception;
|
||||||
|
|
||||||
|
class RuntimeException extends \RuntimeException implements Exception
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
107
lib/Alchemy/Phrasea/Media/Subdef/OptionType/Multi.php
Normal file
107
lib/Alchemy/Phrasea/Media/Subdef/OptionType/Multi.php
Normal file
@@ -0,0 +1,107 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file is part of Phraseanet
|
||||||
|
*
|
||||||
|
* (c) 2005-2012 Alchemy
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please view the LICENSE
|
||||||
|
* file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Alchemy\Phrasea\Media\Subdef\OptionType;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Multi Subdef Option
|
||||||
|
*
|
||||||
|
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
|
||||||
|
* @link www.phraseanet.com
|
||||||
|
*/
|
||||||
|
class Multi implements OptionType
|
||||||
|
{
|
||||||
|
protected $name;
|
||||||
|
protected $displayName;
|
||||||
|
protected $defaultValue;
|
||||||
|
protected $available;
|
||||||
|
|
||||||
|
public function __construct($displayName, $name, Array $available, $defaultValue = null)
|
||||||
|
{
|
||||||
|
$this->displayName = $displayName;
|
||||||
|
$this->name = $name;
|
||||||
|
$this->available = array();
|
||||||
|
foreach ($available as $a) {
|
||||||
|
$this->available[$a] = false;
|
||||||
|
}
|
||||||
|
$this->defaultValue = $defaultValue;
|
||||||
|
|
||||||
|
if ($defaultValue) {
|
||||||
|
$this->setValue($defaultValue);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setValue($value)
|
||||||
|
{
|
||||||
|
foreach ($this->available as $k => $v) {
|
||||||
|
$this->available[$k] = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( ! $value) {
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ((array) $value as $v) {
|
||||||
|
if ( ! array_key_exists($v, $this->available)) {
|
||||||
|
throw new \Exception_InvalidArgument(
|
||||||
|
sprintf(
|
||||||
|
'The value provided `%s` for %s does not fit in range ; available are %s'
|
||||||
|
, $value
|
||||||
|
, $this->getName()
|
||||||
|
, implode(', ', $this->getAvailableValues())
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->available[$v] = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getDisplayName()
|
||||||
|
{
|
||||||
|
return $this->displayName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getType()
|
||||||
|
{
|
||||||
|
return self::TYPE_MULTI;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getAvailableValues()
|
||||||
|
{
|
||||||
|
return array_keys($this->available);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getName()
|
||||||
|
{
|
||||||
|
return $this->name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getValue($all = false)
|
||||||
|
{
|
||||||
|
if ($all) {
|
||||||
|
return $this->available;
|
||||||
|
}
|
||||||
|
|
||||||
|
$value = array();
|
||||||
|
|
||||||
|
foreach ($this->available as $a => $selected) {
|
||||||
|
if ($selected) {
|
||||||
|
$value[] = $a;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $value;
|
||||||
|
}
|
||||||
|
}
|
69
tests/Alchemy/Phrasea/Media/Subdef/OptionType/MultiTest.php
Normal file
69
tests/Alchemy/Phrasea/Media/Subdef/OptionType/MultiTest.php
Normal file
@@ -0,0 +1,69 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Alchemy\Phrasea\Media\Subdef\OptionType;
|
||||||
|
|
||||||
|
class MultiTest extends \PHPUnit_Framework_TestCase
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @var Multi
|
||||||
|
*/
|
||||||
|
protected $object;
|
||||||
|
|
||||||
|
protected function setUp()
|
||||||
|
{
|
||||||
|
$this->object = new Multi('MUMU', 'multiateur', array('un', 'dos', 'tres'), 'dos');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers Alchemy\Phrasea\Media\Subdef\OptionType\Multi::setValue
|
||||||
|
*/
|
||||||
|
public function testSetValue()
|
||||||
|
{
|
||||||
|
$this->assertEquals(array('dos'), $this->object->getValue());
|
||||||
|
$this->object->setValue('tres');
|
||||||
|
$this->assertEquals(array('tres'), $this->object->getValue());
|
||||||
|
$this->object->setValue('');
|
||||||
|
$this->assertEquals(array(), $this->object->getValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers Alchemy\Phrasea\Media\Subdef\OptionType\Multi::setValue
|
||||||
|
* @expectedException \Exception_InvalidArgument
|
||||||
|
*/
|
||||||
|
public function testSetWrongValue()
|
||||||
|
{
|
||||||
|
$this->object->setValue('deux');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers Alchemy\Phrasea\Media\Subdef\OptionType\Multi::getType
|
||||||
|
*/
|
||||||
|
public function testGetType()
|
||||||
|
{
|
||||||
|
$this->assertEquals(OptionType::TYPE_MULTI, $this->object->getType());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers Alchemy\Phrasea\Media\Subdef\OptionType\Multi::getAvailableValues
|
||||||
|
*/
|
||||||
|
public function testGetAvailableValues()
|
||||||
|
{
|
||||||
|
$this->assertEquals(array('un', 'dos', 'tres'), $this->object->getAvailableValues());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers Alchemy\Phrasea\Media\Subdef\OptionType\Multi::getName
|
||||||
|
*/
|
||||||
|
public function testGetName()
|
||||||
|
{
|
||||||
|
$this->assertEquals('multiateur', $this->object->getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers Alchemy\Phrasea\Media\Subdef\OptionType\Multi::getDisplayName
|
||||||
|
*/
|
||||||
|
public function testGetDisplayName()
|
||||||
|
{
|
||||||
|
$this->assertEquals('MUMU', $this->object->getDisplayName());
|
||||||
|
}
|
||||||
|
}
|
273
tests/media/media_subdefTest.php
Normal file
273
tests/media/media_subdefTest.php
Normal file
@@ -0,0 +1,273 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
require_once __DIR__ . '/../PhraseanetPHPUnitAbstract.class.inc';
|
||||||
|
|
||||||
|
class media_subdefTest extends \PhraseanetPHPUnitAbstract
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @var \media_subdef
|
||||||
|
*/
|
||||||
|
protected static $objectPresent;
|
||||||
|
/**
|
||||||
|
* @var \media_subdef
|
||||||
|
*/
|
||||||
|
protected static $objectNotPresent;
|
||||||
|
/**
|
||||||
|
* @var \record_adapter
|
||||||
|
*/
|
||||||
|
protected static $recordonbleu;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers media_subdef::__construct
|
||||||
|
* @covers media_subdef::create
|
||||||
|
*/
|
||||||
|
public static function setUpBeforeClass()
|
||||||
|
{
|
||||||
|
parent::setUpBeforeClass();
|
||||||
|
|
||||||
|
self::$recordonbleu = record_adapter::create(self::$collection, new system_file(__DIR__ . "/../testfiles/iphone_pic.jpg"));
|
||||||
|
self::$recordonbleu->generate_subdefs(self::$recordonbleu->get_databox());
|
||||||
|
|
||||||
|
foreach (self::$recordonbleu->get_subdefs() as $subdef) {
|
||||||
|
|
||||||
|
if ($subdef->get_name() == 'document') {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( ! self::$objectPresent) {
|
||||||
|
self::$objectPresent = $subdef;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if ( ! self::$objectNotPresent) {
|
||||||
|
self::$objectNotPresent = $subdef;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
self::$objectNotPresent->remove_file();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers media_subdef::is_physically_present
|
||||||
|
*/
|
||||||
|
public function testIs_physically_present()
|
||||||
|
{
|
||||||
|
$this->assertTrue(self::$objectPresent->is_physically_present());
|
||||||
|
$this->assertFalse(self::$objectNotPresent->is_physically_present());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers media_subdef::get_record
|
||||||
|
*/
|
||||||
|
public function testGet_record()
|
||||||
|
{
|
||||||
|
$this->assertEquals(self::$recordonbleu->get_record_id(), self::$objectNotPresent->get_record()->get_record_id());
|
||||||
|
$this->assertEquals(self::$recordonbleu->get_record_id(), self::$objectPresent->get_record()->get_record_id());
|
||||||
|
$this->assertEquals(self::$recordonbleu->get_sbas_id(), self::$objectNotPresent->get_record()->get_sbas_id());
|
||||||
|
$this->assertEquals(self::$recordonbleu->get_sbas_id(), self::$objectPresent->get_record()->get_sbas_id());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers media_subdef::get_permalink
|
||||||
|
*/
|
||||||
|
public function testGet_permalink()
|
||||||
|
{
|
||||||
|
$this->assertInstanceOf('\\media_Permalink_adapter', self::$objectNotPresent->get_permalink());
|
||||||
|
$this->assertInstanceOf('\\media_Permalink_adapter', self::$objectPresent->get_permalink());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers media_subdef::get_record_id
|
||||||
|
*/
|
||||||
|
public function testGet_record_id()
|
||||||
|
{
|
||||||
|
$this->assertEquals(self::$recordonbleu->get_record_id(), self::$objectNotPresent->get_record()->get_record_id());
|
||||||
|
$this->assertEquals(self::$recordonbleu->get_record_id(), self::$objectPresent->get_record()->get_record_id());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers media_subdef::getEtag
|
||||||
|
*/
|
||||||
|
public function testGetEtag()
|
||||||
|
{
|
||||||
|
$this->assertNull(self::$objectNotPresent->getEtag());
|
||||||
|
$this->assertInternalType('string', self::$objectPresent->getEtag());
|
||||||
|
$this->assertRegExp('/[a-zA-Z0-9]{32}/', self::$objectPresent->getEtag());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers media_subdef::setEtag
|
||||||
|
*/
|
||||||
|
public function testSetEtag()
|
||||||
|
{
|
||||||
|
$etag = md5('random');
|
||||||
|
self::$objectNotPresent->setEtag($etag);
|
||||||
|
$this->assertEquals($etag, self::$objectNotPresent->getEtag());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers media_subdef::get_sbas_id
|
||||||
|
*/
|
||||||
|
public function testGet_sbas_id()
|
||||||
|
{
|
||||||
|
$this->assertEquals(self::$recordonbleu->get_sbas_id(), self::$objectNotPresent->get_record()->get_sbas_id());
|
||||||
|
$this->assertEquals(self::$recordonbleu->get_sbas_id(), self::$objectPresent->get_record()->get_sbas_id());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers media_subdef::get_type
|
||||||
|
*/
|
||||||
|
public function testGet_type()
|
||||||
|
{
|
||||||
|
$this->assertEquals(\media_subdef::TYPE_IMAGE, self::$objectPresent->get_type());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers media_subdef::get_mime
|
||||||
|
*/
|
||||||
|
public function testGet_mime()
|
||||||
|
{
|
||||||
|
$this->assertEquals('image/jpeg', self::$objectPresent->get_mime());
|
||||||
|
$this->assertEquals('image/png', self::$objectNotPresent->get_mime());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers media_subdef::get_path
|
||||||
|
*/
|
||||||
|
public function testGet_path()
|
||||||
|
{
|
||||||
|
$this->assertEquals(dirname(self::$objectPresent->get_pathfile()) . DIRECTORY_SEPARATOR, self::$objectPresent->get_path());
|
||||||
|
$this->assertEquals(dirname(self::$objectNotPresent->get_pathfile()) . DIRECTORY_SEPARATOR, self::$objectNotPresent->get_path());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers media_subdef::get_baseurl
|
||||||
|
*/
|
||||||
|
public function testGet_baseurl()
|
||||||
|
{
|
||||||
|
$this->assertInternalType('string', self::$objectPresent->get_baseurl());
|
||||||
|
$this->assertInternalType('string', self::$objectNotPresent->get_baseurl());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers media_subdef::get_file
|
||||||
|
*/
|
||||||
|
public function testGet_file()
|
||||||
|
{
|
||||||
|
$this->assertEquals(basename(self::$objectPresent->get_pathfile()), self::$objectPresent->get_file());
|
||||||
|
$this->assertEquals(basename(self::$objectNotPresent->get_pathfile()), self::$objectNotPresent->get_file());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers media_subdef::get_size
|
||||||
|
*/
|
||||||
|
public function testGet_size()
|
||||||
|
{
|
||||||
|
$this->assertTrue(self::$objectPresent->get_size() > 0);
|
||||||
|
$this->assertTrue(self::$objectNotPresent->get_size() > 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers media_subdef::get_name
|
||||||
|
*/
|
||||||
|
public function testGet_name()
|
||||||
|
{
|
||||||
|
$this->assertTrue(in_array(self::$objectPresent->get_name(), array('thumbnail', 'preview')));
|
||||||
|
$this->assertTrue(in_array(self::$objectNotPresent->get_name(), array('thumbnail', 'preview')));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers media_subdef::get_subdef_id
|
||||||
|
*/
|
||||||
|
public function testGet_subdef_id()
|
||||||
|
{
|
||||||
|
$this->assertInternalType('int', self::$objectPresent->get_subdef_id());
|
||||||
|
$this->assertInternalType('int', self::$objectNotPresent->get_subdef_id());
|
||||||
|
$this->assertTrue(self::$objectPresent->get_size() > 0);
|
||||||
|
$this->assertTrue(self::$objectNotPresent->get_size() > 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers media_subdef::is_substituted
|
||||||
|
*/
|
||||||
|
public function testIs_substituted()
|
||||||
|
{
|
||||||
|
$this->assertFalse(self::$objectPresent->is_substituted());
|
||||||
|
$this->assertTrue(self::$objectNotPresent->is_substituted());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers media_subdef::get_pathfile
|
||||||
|
*/
|
||||||
|
public function testGet_pathfile()
|
||||||
|
{
|
||||||
|
$this->assertEquals(self::$objectPresent->get_path() . self::$objectPresent->get_file(), self::$objectPresent->get_pathfile());
|
||||||
|
$this->assertEquals(self::$objectNotPresent->get_path() . self::$objectNotPresent->get_file(), self::$objectNotPresent->get_pathfile());
|
||||||
|
$this->assertTrue(file_exists(self::$objectPresent->get_pathfile()));
|
||||||
|
$this->assertTrue(file_exists(self::$objectNotPresent->get_pathfile()));
|
||||||
|
$this->assertTrue(is_readable(self::$objectPresent->get_pathfile()));
|
||||||
|
$this->assertTrue(is_readable(self::$objectNotPresent->get_pathfile()));
|
||||||
|
$this->assertTrue(is_writable(self::$objectPresent->get_pathfile()));
|
||||||
|
$this->assertTrue(is_writable(self::$objectNotPresent->get_pathfile()));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers media_subdef::get_modification_date
|
||||||
|
*/
|
||||||
|
public function testGet_modification_date()
|
||||||
|
{
|
||||||
|
$this->assertInstanceOf('\\DateTime', self::$objectPresent->get_modification_date());
|
||||||
|
$this->assertInstanceOf('\\DateTime', self::$objectNotPresent->get_modification_date());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers media_subdef::get_creation_date
|
||||||
|
*/
|
||||||
|
public function testGet_creation_date()
|
||||||
|
{
|
||||||
|
$this->assertInstanceOf('\\DateTime', self::$objectPresent->get_creation_date());
|
||||||
|
$this->assertInstanceOf('\\DateTime', self::$objectNotPresent->get_creation_date());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers media_subdef::renew_url
|
||||||
|
*/
|
||||||
|
public function testRenew_url()
|
||||||
|
{
|
||||||
|
$this->assertInternalType('string', self::$objectPresent->renew_url());
|
||||||
|
$this->assertInternalType('string', self::$objectNotPresent->renew_url());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers media_subdef::getDataboxSubdef
|
||||||
|
*/
|
||||||
|
public function testGetDataboxSubdef()
|
||||||
|
{
|
||||||
|
$this->assertInstanceOf('\\databox_subdef', self::$objectPresent->getDataboxSubdef());
|
||||||
|
$this->assertInstanceOf('\\databox_subdef', self::$objectNotPresent->getDataboxSubdef());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers media_subdef::rotate
|
||||||
|
*/
|
||||||
|
public function testRotate()
|
||||||
|
{
|
||||||
|
$width_before = self::$objectPresent->get_width();
|
||||||
|
$height_before = self::$objectPresent->get_height();
|
||||||
|
|
||||||
|
self::$objectPresent->rotate(90);
|
||||||
|
|
||||||
|
$this->assertEquals($width_before, self::$objectPresent->get_height());
|
||||||
|
$this->assertEquals($height_before, self::$objectPresent->get_width());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers media_subdef::rotate
|
||||||
|
* @expectedException \Alchemy\Phrasea\Exception\RuntimeException
|
||||||
|
* @covers \Alchemy\Phrasea\Exception\RuntimeException
|
||||||
|
*/
|
||||||
|
public function testRotateOnSubstitution()
|
||||||
|
{
|
||||||
|
self::$objectNotPresent->rotate(90);
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user