Fix failing enable/disable collection tests

This commit is contained in:
Vagrant User
2016-01-07 17:02:20 +01:00
parent 921a32034a
commit bf524dac0c
3 changed files with 72 additions and 48 deletions

View File

@@ -45,9 +45,6 @@ class collection implements ThumbnailedElement, cache_cacheableInterface
private static $_stamps = [];
private static $_watermarks = [];
private static $_presentations = [];
private static $_collections = [];
/**
* @param Application $app
@@ -110,6 +107,7 @@ class collection implements ThumbnailedElement, cache_cacheableInterface
$collection
)
);
return $reference->getBaseId();
}
@@ -169,7 +167,7 @@ class collection implements ThumbnailedElement, cache_cacheableInterface
public static function purge()
{
self::$_collections = [];
// BC only
}
/**
@@ -260,6 +258,11 @@ class collection implements ThumbnailedElement, cache_cacheableInterface
*/
protected $collectionVO;
/**
* @var CollectionRepositoryRegistry
*/
protected $collectionRepositoryRegistry;
/**
* @var CollectionReference
*/
@@ -278,6 +281,7 @@ class collection implements ThumbnailedElement, cache_cacheableInterface
$this->app = $app;
$this->databox = $app->getApplicationBox()->get_databox($reference->getDataboxId());
$this->collectionService = $app->getApplicationBox()->getCollectionService();
$this->collectionRepositoryRegistry = $app['repo.collections-registry'];
$this->collectionVO = $collection;
$this->reference = $reference;
@@ -317,10 +321,19 @@ class collection implements ThumbnailedElement, cache_cacheableInterface
public function __sleep()
{
return array(
return [
'collectionVO',
'reference'
);
];
}
public function __debugInfo()
{
return [
'reference' => $this->reference,
'databox' => $this->databox,
'collectionVO' => $this->collectionVO
];
}
/**
@@ -472,7 +485,7 @@ class collection implements ThumbnailedElement, cache_cacheableInterface
*/
public function get_base_id()
{
return $this->reference->getBaseId();
return (int) $this->reference->getBaseId();
}
/**
@@ -480,7 +493,7 @@ class collection implements ThumbnailedElement, cache_cacheableInterface
*/
public function get_sbas_id()
{
return $this->reference->getDataboxId();
return (int) $this->reference->getDataboxId();
}
/**
@@ -488,7 +501,7 @@ class collection implements ThumbnailedElement, cache_cacheableInterface
*/
public function get_coll_id()
{
return $this->reference->getCollectionId();
return (int) $this->reference->getCollectionId();
}
/**
@@ -565,7 +578,7 @@ class collection implements ThumbnailedElement, cache_cacheableInterface
$this->reference->disable();
$this->getReferenceRepository()->save($this->reference);
$this->app['repo.collections-registry']->purgeRegistry();
$this->collectionRepositoryRegistry->purgeRegistry();
cache_databox::update($this->app, $this->databox->get_sbas_id(), 'structure');
@@ -582,7 +595,7 @@ class collection implements ThumbnailedElement, cache_cacheableInterface
$this->reference->enable();
$this->getReferenceRepository()->save($this->reference);
$this->app['repo.collections-registry']->purgeRegistry();
$this->collectionRepositoryRegistry->purgeRegistry();
cache_databox::update($this->app, $this->databox->get_sbas_id(), 'structure');
@@ -659,7 +672,7 @@ class collection implements ThumbnailedElement, cache_cacheableInterface
$this->collectionVO->setLogo($fileContents);
$this->getCollectionRepository()->save($this->collectionVO);
$this->app['repo.collections-registry']->purgeRegistry();
$this->collectionRepositoryRegistry->purgeRegistry();
return $this;
}
@@ -673,7 +686,7 @@ class collection implements ThumbnailedElement, cache_cacheableInterface
$this->collectionService->resetWatermark($this->collectionVO);
$this->getCollectionRepository()->save($this->collectionVO);
$this->app['repo.collections-registry']->purgeRegistry();
$this->collectionRepositoryRegistry->purgeRegistry();
return $this;
}
@@ -688,7 +701,7 @@ class collection implements ThumbnailedElement, cache_cacheableInterface
$this->collectionService->resetStamp($this->collectionVO, $record_id);
$this->getCollectionRepository()->save($this->collectionVO);
$this->app['repo.collections-registry']->purgeRegistry();
$this->collectionRepositoryRegistry->purgeRegistry();
return $this;
}
@@ -703,7 +716,7 @@ class collection implements ThumbnailedElement, cache_cacheableInterface
$this->getCollectionRepository()->delete($this->collectionVO);
$this->app['manipulator.registration']->deleteRegistrationsOnCollection($this);
$this->app['repo.collections-registry']->purgeRegistry();
$this->collectionRepositoryRegistry->purgeRegistry();
}
/**
@@ -720,7 +733,7 @@ class collection implements ThumbnailedElement, cache_cacheableInterface
$this->getReferenceRepository()->delete($this->reference);
$this->app['manipulator.registration']->deleteRegistrationsOnCollection($this);
$this->app['repo.collections-registry']->purgeRegistry();
$this->collectionRepositoryRegistry->purgeRegistry();
$this->dispatch(
CollectionEvents::UNMOUNTED,

View File

@@ -178,17 +178,13 @@ class databox extends base implements ThumbnailedElement
*/
public function get_collections()
{
static $collections;
if ($collections === null) {
/** @var CollectionRepositoryRegistry $repositoryRegistry */
$repositoryRegistry = $this->app['repo.collections-registry'];
$repository = $repositoryRegistry->getRepositoryByDatabox($this->get_sbas_id());
$collections = $repository->findAll();
}
return $collections;
return array_filter($repository->findAll(), function (collection $collection) {
return $collection->is_active();
});
}
/**

View File

@@ -23,29 +23,29 @@ class collectionTest extends \PhraseanetTestCase
parent::setup();
if (!self::$object) {
if (0 === count($databoxes = self::$DI['app']->getDataboxes())) {
if (0 === count($databoxes = $this->getApplication()->getDataboxes())) {
$this->fail('No databox found for collection test');
}
$databox = array_shift($databoxes);
self::$object = collection::create(
self::$DI['app'],
$this->getApplication(),
$databox,
self::$DI['app']['phraseanet.appbox'],
$this->getApplication()['phraseanet.appbox'],
'test_collection',
self::$DI['user']
);
self::$objectDisable = collection::create(
self::$DI['app'],
$this->getApplication(),
$databox,
self::$DI['app']['phraseanet.appbox'],
$this->getApplication()['phraseanet.appbox'],
'test_collection',
self::$DI['user']
);
self::$objectDisable->disable(self::$DI['app']['phraseanet.appbox']);
self::$objectDisable->disable();
}
}
@@ -62,34 +62,42 @@ class collectionTest extends \PhraseanetTestCase
{
$base_id = self::$object->get_base_id();
$coll_id = self::$object->get_coll_id();
self::$object->disable(self::$DI['app']['phraseanet.appbox']);
self::$object->disable();
$this->assertTrue(is_int(self::$object->get_base_id()));
$this->assertTrue(is_int(self::$object->get_coll_id()));
$this->assertFalse(self::$object->is_active());
$sbas_id = self::$object->get_databox()->get_sbas_id();
$databox = self::$DI['app']->findDataboxById($sbas_id);
$databox = $this->getApplication()->findDataboxById($sbas_id);
foreach ($databox->get_collections() as $collection) {
$this->assertTrue($collection->get_base_id() !== $base_id);
$this->assertTrue($collection->get_coll_id() !== $coll_id);
$this->assertNotEquals($collection->get_base_id(), $base_id);
$this->assertNotEquals($collection->get_coll_id(), $coll_id);
}
}
public function testEnable()
{
self::$objectDisable->enable(self::$DI['app']['phraseanet.appbox']);
self::$objectDisable->enable();
$this->assertTrue(is_int(self::$objectDisable->get_base_id()));
$this->assertTrue(is_int(self::$objectDisable->get_coll_id()));
$this->assertTrue(self::$objectDisable->is_active());
$n = $m = 0;
foreach (self::$objectDisable->get_databox()->get_collections() as $collection) {
if ($collection->get_base_id() === self::$objectDisable->get_base_id())
$n ++;
if ($collection->get_coll_id() === self::$objectDisable->get_coll_id())
$m ++;
if ($collection->get_base_id() === self::$objectDisable->get_base_id()) {
$n++;
}
if ($collection->get_coll_id() === self::$objectDisable->get_coll_id()) {
$m++;
}
}
$this->assertEquals(1, $n);
$this->assertEquals(1, $m);
}
@@ -97,9 +105,16 @@ class collectionTest extends \PhraseanetTestCase
public function testGet_record_amount()
{
self::$object->empty_collection();
$file = new File(self::$DI['app'], self::$DI['app']['mediavorus']->guess(__DIR__ . '/../files/cestlafete.jpg'), self::$object);
record_adapter::createFromFile($file, self::$DI['app']);
$file = new File(
$this->getApplication(),
$this->getApplication()['mediavorus']->guess(__DIR__ . '/../files/cestlafete.jpg'),
self::$object
);
record_adapter::createFromFile($file, $this->getApplication());
$this->assertTrue(self::$object->get_record_amount() === 1);
self::$object->empty_collection();
$this->assertTrue(self::$object->get_record_amount() === 0);
}
@@ -148,8 +163,8 @@ class collectionTest extends \PhraseanetTestCase
public function testGet_record_details()
{
$file = new File(self::$DI['app'], self::$DI['app']['mediavorus']->guess(__DIR__ . '/../files/cestlafete.jpg'), self::$object);
$record = record_adapter::createFromFile($file, self::$DI['app']);
$file = new File($this->getApplication(), $this->getApplication()['mediavorus']->guess(__DIR__ . '/../files/cestlafete.jpg'), self::$object);
$record = record_adapter::createFromFile($file, $this->getApplication());
$details = self::$object->get_record_details();
$this->assertTrue(is_array($details));
@@ -175,7 +190,7 @@ class collectionTest extends \PhraseanetTestCase
public function testGet_from_coll_id()
{
$temp_coll = collection::getByCollectionId(self::$DI['app'], self::$object->get_databox(), self::$object->get_coll_id());
$temp_coll = collection::getByCollectionId($this->getApplication(), self::$object->get_databox(), self::$object->get_coll_id());
$this->assertEquals(self::$object->get_coll_id(), $temp_coll->get_coll_id());
$this->assertEquals(self::$object->get_base_id(), $temp_coll->get_base_id());
}