diff --git a/library/Class/Batch.php b/library/Class/Batch.php index 825726897b5d634856769f452f8eb4f533f27a44..ee0cadc207ca5050369bba2e0482cb3fc4185373 100644 --- a/library/Class/Batch.php +++ b/library/Class/Batch.php @@ -22,17 +22,22 @@ class Class_BatchLoader extends Storm_Model_Loader{ public function getKnownTypes() { + return array_merge($this->getRessourcesNumeriqueTypes(), [ + 'IMPORT_TYPO3' => new Class_Batch_Typo3(), + 'CORRECTION_PANIERS' => new Class_Batch_PanierNotice(), + 'CART_REALLOCATION' => new Class_Batch_PanierUser(), + 'COMMENT_REALLOCATION'=> new Class_Batch_AvisNotice(), + 'INDEX_RESSOURCES_NUMERIQUES' => new Class_Batch_IndexRessourcesNumeriques() + ]); + } + + public function getRessourcesNumeriqueTypes() { return ['MOISSONNAGE_VODECLIC' => new Class_Batch_Vodeclic(), 'MOISSONNAGE_ARTEVOD' => new Class_Batch_ArteVOD(), 'MOISSONNAGE_NUMERIQUEPREMIUM' => new Class_Batch_NumeriquePremium(), 'MOISSONNAGE_NUMILOG' => new Class_Batch_Numilog(), - 'MOISSONNAGE_TOUTAPPRENDRE' => new Class_Batch_ToutApprendre(), - - 'IMPORT_TYPO3' => new Class_Batch_Typo3(), - 'CORRECTION_PANIERS' => new Class_Batch_PanierNotice(), - 'CART_REALLOCATION' => new Class_Batch_PanierUser(), - 'COMMENT_REALLOCATION'=> new Class_Batch_AvisNotice() - ]; + 'MOISSONNAGE_TOUTAPPRENDRE' => new Class_Batch_ToutApprendre() + ]; } @@ -100,4 +105,4 @@ class Class_Batch extends Storm_Model_Abstract { return $this; } } -?> \ No newline at end of file +?> diff --git a/library/Class/Batch/IndexRessourcesNumeriques.php b/library/Class/Batch/IndexRessourcesNumeriques.php new file mode 100644 index 0000000000000000000000000000000000000000..489c8f510b41c6851ced249b151abdd6a5417769 --- /dev/null +++ b/library/Class/Batch/IndexRessourcesNumeriques.php @@ -0,0 +1,24 @@ +<?php + +class Class_Batch_IndexRessourcesNumeriques extends Class_Batch_Abstract { + public function getLabel() { + return $this->_("Indexer les ressources numériques"); + } + + public function run() { + $albums = Class_Album::findAll(); + foreach ($albums as $album) + $album->index(); + (new Storm_Cache())->clean(); + } + + public function isEnabled() { + $types = Class_Batch::getRessourcesNumeriqueTypes(); + foreach ($types as $instance) { + if ($instance->isEnabled()) { + return TRUE; + } + } + return FALSE; + } +} diff --git a/tests/application/modules/admin/controllers/BatchControllerTest.php b/tests/application/modules/admin/controllers/BatchControllerTest.php index d19834fe95080c8172478c73e1505300a0ec5654..169c57cebac0c5a01fd50802f10d4f9dbb3fb4a6 100644 --- a/tests/application/modules/admin/controllers/BatchControllerTest.php +++ b/tests/application/modules/admin/controllers/BatchControllerTest.php @@ -136,6 +136,11 @@ class BatchControllerAddWithNumilogAndToutApprendreTest extends BatchControllerT public function selectElementShouldContainsMoissonnageToutApprendre(){ $this->assertXPath('//select[@name="type"]/option[@value="MOISSONNAGE_TOUTAPPRENDRE"][@label="Moissonner catalogue Tout Apprendre"][not(@selected)]', $this->_response->getBody()); } + + /** @test */ + public function selectElementShouldContainsIndexerRessourcesNumeriques(){ + $this->assertXPath('//select[@name="type"]/option[@value="INDEX_RESSOURCES_NUMERIQUES"][@label="Indexer les ressources numériques"][not(@selected)]', $this->_response->getBody()); + } } @@ -193,4 +198,4 @@ class BatchControllerRunMoissonnageVodeclicTest extends BatchControllerTestCase } -?> \ No newline at end of file +?> diff --git a/tests/library/Class/BatchTest.php b/tests/library/Class/BatchTest.php index 0fac5ec698f91246fd437fd358ba3c46e6e2551f..9eac32385141e3207f29ab0cfa1a746d90aad18a 100644 --- a/tests/library/Class/BatchTest.php +++ b/tests/library/Class/BatchTest.php @@ -32,6 +32,11 @@ class BatchModelTest extends Storm_Test_ModelTestCase { ['id' => 3, 'type' => 'MOISSONNAGE_ARTEVOD', 'last_run' => '2012-05-01 10:23:00']); + + $this->batch_IndexRessourcesNumeriques = $this->fixture('Class_Batch', + ['id' => 3, + 'type' => 'INDEX_RESSOURCES_NUMERIQUES', + 'last_run' => '2014-04-02 17:11:00']); } @@ -54,6 +59,19 @@ class BatchModelTest extends Storm_Test_ModelTestCase { $this->batch_artevod->run(); $this->assertTrue($mock->methodHasBeenCalled('run')); } + + /** @test */ + public function batchIndexRessoucesNumeriquesRunShouldCallRun(){ + $mock = Storm_Test_ObjectWrapper::mock() + ->whenCalled('run')->answers(true); + + Storm_Test_ObjectWrapper::onLoaderOfModel('Class_Batch') + ->whenCalled('getKnownType')->with('INDEX_RESSOURCES_NUMERIQUES') + ->answers($mock); + + $this->batch_IndexRessourcesNumeriques->run(); + $this->assertTrue($mock->methodHasBeenCalled('run')); + } } @@ -100,8 +118,33 @@ class BatchLoaderWithRessourcesNumeriquesTest extends Storm_Test_ModelTestCase { 'MOISSONNAGE_ARTEVOD' => 'Moissonner catalogue ArteVOD', 'MOISSONNAGE_NUMERIQUEPREMIUM' => 'Moissonner catalogue Numérique Premium', 'MOISSONNAGE_NUMILOG' => 'Moissonner catalogue Numilog', - 'MOISSONNAGE_TOUTAPPRENDRE' => 'Moissonner catalogue Tout Apprendre'], + 'MOISSONNAGE_TOUTAPPRENDRE' => 'Moissonner catalogue Tout Apprendre', + 'INDEX_RESSOURCES_NUMERIQUES' => 'Indexer les ressources numériques'], Class_Batch::getAvailableType()); } } + +class BatchIndexRessourcesNumeriquesTest extends Storm_Test_ModelTestCase { + public function setUp() { + $album = $this->fixture('Class_Album', ['id' => 1, 'libelle' => 'Mon Album']); + Class_Notice::beVolatile(); + + $mock = Storm_Test_ObjectWrapper::mock(); + $this->cache = $mock->whenCalled('clean')->answers(true); + Storm_Cache::setDefaultZendCache($this->cache); + + (new Class_Batch_IndexRessourcesNumeriques())->run(); + } + + /** @test */ + public function afterRunNoticeShouldExists() { + $this->assertCount(1, Class_Notice::findAll()); + } + + /** @test */ + public function afterRunCacheShouldBeCleaned() { + $this->assertTrue($this->cache->methodHasBeenCalled('clean')); + } +} + ?>