diff --git a/VERSIONS_HOTLINE/86175 b/VERSIONS_HOTLINE/86175 new file mode 100644 index 0000000000000000000000000000000000000000..8a9c1a6a232601ded34232ef3f8f5971e9d8fc1a --- /dev/null +++ b/VERSIONS_HOTLINE/86175 @@ -0,0 +1,2 @@ + - ticket #86175 : Intégration Cosmogramme : correction de l'import des genres. + \ No newline at end of file diff --git a/cosmogramme/cosmozend/tests/CosmoControllerTestCase.php b/cosmogramme/cosmozend/tests/CosmoControllerTestCase.php index d9331fa8a8dbcabdb22e46772fbe58b11e815353..c8e88a8fc2350894745d08fee232eba1cbc27650 100644 --- a/cosmogramme/cosmozend/tests/CosmoControllerTestCase.php +++ b/cosmogramme/cosmozend/tests/CosmoControllerTestCase.php @@ -46,6 +46,7 @@ abstract class CosmoControllerTestCase extends Zend_Test_PHPUnit_ControllerTestC Storm_Model_Abstract::unsetLoaders(); Class_FileManager::reset(); Class_FileManager_FileSystem::reset(); + Class_Cosmogramme_LandingDirectory::reset(); } diff --git a/cosmogramme/cosmozend/tests/application/modules/cosmo/controllers/IntegrationControllerTest.php b/cosmogramme/cosmozend/tests/application/modules/cosmo/controllers/IntegrationControllerTest.php index eb6fde315fd409ff3a028d80b212280b4657bd75..7481b7081e811064c931f819a4d979ad68f8d5a8 100644 --- a/cosmogramme/cosmozend/tests/application/modules/cosmo/controllers/IntegrationControllerTest.php +++ b/cosmogramme/cosmozend/tests/application/modules/cosmo/controllers/IntegrationControllerTest.php @@ -619,45 +619,90 @@ abstract class Cosmo_IntegrationControllerWaitingFilesTestCase extends CosmoCont 'nom_fichier' => 'lunel/[DATE]_records_tot.mrc', 'taille_min_import_total' => 0]); - $lunel = $this->mock()->whenCalled('getPath') - ->answers('/ccpl34/lunel') - ->whenCalled('getName')->answers('lunel'); - - $this->_tot = $this->mock() - ->whenCalled('getParent')->answers($lunel) - ->whenCalled('isWritable')->answers(true) - ->whenCalled('getName')->answers('20190116220001_records_tot.mrc') - ->whenCalled('getMTime')->answers('2019-01-13 22:88:77') - ->whenCalled('getSize')->answers('42 Ko') - ->whenCalled('getFileSize')->answers(43986) - ->whenCalled('getId')->answers('/ccpl34/lunel/20190116220001_records_tot.mrc') - ->whenCalled('getModels')->answers([]) - ->whenCalled('isDir')->answers(false) - ->whenCalled('getPath')->answers('/ccpl34/lunel/') - ->whenCalled('readfile')->answers(true) - ->whenCalled('getProgrammed')->answers(Class_IntMajAuto::find(43)) - ; + $ccpl34 = $this + ->mock() + ->whenCalled('isDir')->answers(true) + ->whenCalled('getPath')->answers('/ccpl34') + ->whenCalled('getName')->answers('ccpl34'); + + $lunel = $this + ->mock() + ->whenCalled('isDir')->answers(true) + ->whenCalled('getPath')->answers('/ccpl34/lunel') + ->whenCalled('getName')->answers('lunel') + ->whenCalled('getParent')->answers($ccpl34); + + $etalon = $this + ->mock() + ->whenCalled('isDir')->answers(true) + ->whenCalled('getPath')->answers('/ccpl34/etalon') + ->whenCalled('getName')->answers('etalon') + ->whenCalled('getParent')->answers($ccpl34); + + $kinds = $this + ->mock() + ->whenCalled('getName')->answers('genres.txt') + ->whenCalled('getMTime')->answers('2019-01-13 22:88:77') + ->whenCalled('getFileSize')->answers(43986) + ->whenCalled('getParent')->answers($etalon) + ->whenCalled('getPath')->answers('/ccpl34/etalon/genres.txt') + ->whenCalled('getFileMTime')->answers('12345678') + ->whenCalled('getProgrammed')->answers(null) + ->whenCalled('isWritable')->answers(true) + ->whenCalled('getId')->answers('/ccpl34/etalon/genres.txt') + ->whenCalled('getParentPath')->answers('/ccpl34/etalon') + ->whenCalled('isFile')->answers(true); + + $this->_tot = $this + ->mock() + ->whenCalled('getParent')->answers($lunel) + ->whenCalled('isWritable')->answers(true) + ->whenCalled('getName')->answers('20190116220001_records_tot.mrc') + ->whenCalled('getMTime')->answers('2019-01-13 22:88:77') + ->whenCalled('getFileMTime')->answers('1234567') + ->whenCalled('getSize')->answers('42 Ko') + ->whenCalled('getFileSize')->answers(43986) + ->whenCalled('getId')->answers('/ccpl34/lunel/20190116220001_records_tot.mrc') + ->whenCalled('getModels')->answers([]) + ->whenCalled('isDir')->answers(false) + ->whenCalled('getPath')->answers('/ccpl34/lunel/20190116220001_records_tot.mrc') + ->whenCalled('getParentPath')->answers('/ccpl34/lunel') + ->whenCalled('readfile')->answers(true) + ->whenCalled('getProgrammed')->answers(Class_IntMajAuto::find(43)) + ->whenCalled('isFile')->answers(true); $this->_tot->whenCalled('setProgrammed')->answers($this->_tot); $file_system = $this ->mock() - ->whenCalled('directoriesAt')->with('/ccpl34')->answers([$lunel]) + ->whenCalled('search')->with('*', '/ccpl34/lunel')->answers([$this->_tot]) + + ->whenCalled('search')->with('*', '/ccpl34/etalon')->answers([$kinds]) + + ->whenCalled('directoriesAt')->with('/ccpl34')->answers([$lunel, $etalon]) + + ->whenCalled('directoryAt')->with('ccpl34/lunel')->answers($lunel) + + ->whenCalled('directoryAt')->with('ccpl34/etalon')->answers($etalon) - ->whenCalled('filesAt')->with('/ccpl34/lunel')->answers([$this->_tot]) + ->whenCalled('fileAt')->with('ccpl34/lunel')->answers(null) + + ->whenCalled('fileAt')->with('ccpl34/etalon')->answers(null) + + ->whenCalled('delete')->with('/ccpl34/lunel/20190116220001_records_tot.mrc') + ->answers(true) ->whenCalled('directoryAt')->with('ccpl34/lunel/20190116220001_records_tot.mrc') ->answers(null) ->whenCalled('fileAt')->with('ccpl34/lunel/20190116220001_records_tot.mrc') - ->answers($this->_tot) + ->answers($this->_tot); - ->whenCalled('delete')->with('/ccpl34/lunel/20190116220001_records_tot.mrc') - ->answers(true) - ; Class_FileManager::setFileSystem($file_system); + Class_Cosmogramme_LandingDirectory::setSubdirCache($etalon); + Class_AdminVar::set('NOM_DOMAINE', 'http://localhost'); } } @@ -700,6 +745,12 @@ class Cosmo_IntegrationControllerWaitingFilesActionTest public function linkToDownloadRecordTotShouldBePresent() { $this->assertXPath('//a[@href = "/cosmo/integration/waiting-files-download?id=%2Fccpl34%2Flunel%2F20190116220001_records_tot.mrc"]'); } + + + /** @test */ + public function kindsShouldBeProgrammed() { + $this->assertXPathContentContains('//tr[@data-path="/ccpl34/etalon/genres.txt"]//td', 'Programmé'); + } } diff --git a/cosmogramme/tests/php/classes/ModelTestCase.php b/cosmogramme/tests/php/classes/ModelTestCase.php index 92cf19ee005944c585c3417e29a30295cb0536b1..c34a5d3642afb526c850930122a4ebab9babe1a9 100644 --- a/cosmogramme/tests/php/classes/ModelTestCase.php +++ b/cosmogramme/tests/php/classes/ModelTestCase.php @@ -85,6 +85,8 @@ abstract class ModelTestCase extends PHPUnit_Framework_TestCase { Storm_Model_Loader::defaultToDb(); Storm_Model_Abstract::unsetLoaders(); Class_Crypt::setPhpCommand(null); + Class_Cosmogramme_LandingDirectory::reset(); + Class_Cosmogramme_Generator_KindsTask::setDbAdapter(null); } diff --git a/library/Class/CodifGenre.php b/library/Class/CodifGenre.php index 60d5274529484bcf37c5da39155cc6af885c8fe7..7c97109ff916365a6b988fe9c34f76c8d0f6f160 100644 --- a/library/Class/CodifGenre.php +++ b/library/Class/CodifGenre.php @@ -47,6 +47,8 @@ class Class_CodifGenre extends Storm_Model_Abstract { $_loader_class = 'Class_CodifGenreLoader', $_table_name = 'codif_genre', $_table_primary = 'id_genre', - $_default_attribute_values = ['picto' => '']; + $_default_attribute_values = ['picto' => '', + 'libelle' => '', + 'regles' => '', + 'date_maj' => '']; } -?> diff --git a/library/Class/Cosmogramme/Generator.php b/library/Class/Cosmogramme/Generator.php index 39e8774e8eafe695c1428c6e838758db61a92a26..52aa6f6875352726ce62c2756f5474707b1f10a4 100644 --- a/library/Class/Cosmogramme/Generator.php +++ b/library/Class/Cosmogramme/Generator.php @@ -66,11 +66,21 @@ class Class_Cosmogramme_Generator { public function getUpdatableStandard() { - if (null === Class_IntMajAuto::findFirstBy([]) - || !Class_IntBib::isSingleNanook()) + if (null === Class_IntMajAuto::findFirstBy([])) { + $this->logError($this->_('Aucune intégration programmée.')); return null; + } + + if (!Class_IntBib::isSingleNanook()) { + $this->logError($this->_('Le mode Nanook unique n\'est pas activé.')); + return null; + } + + $landing_directory = $this->getLandingDirectory(); + if (!$result = $landing_directory->getUpdatableStandard()) + $this->logError($landing_directory->getLog()->getLastMessage()); - return $this->getLandingDirectory()->getUpdatableStandard(); + return $result; } diff --git a/library/Class/Cosmogramme/Generator/AbstractTask.php b/library/Class/Cosmogramme/Generator/AbstractTask.php index 168006e6c31fe43e3b85261e9eabfc7bc5389aca..ca88a3596497dc07ab3117a36e36018e61e35782 100644 --- a/library/Class/Cosmogramme/Generator/AbstractTask.php +++ b/library/Class/Cosmogramme/Generator/AbstractTask.php @@ -98,8 +98,9 @@ abstract class Class_Cosmogramme_Generator_AbstractTask { $model = $model_class::newInstance(['libelle' => $label]); return - $model->setDateMaj($this->_date) - ->setRegles($this->_createOrConcatRules($code, $model)); + $model + ->setRegles($this->_createOrConcatRules($code, $model)) + ->setDateMaj($this->_date); } diff --git a/library/Class/Cosmogramme/Generator/KindsTask.php b/library/Class/Cosmogramme/Generator/KindsTask.php index 955b3e7e5caaef8db161edd188202ebe942d0b5f..7a8a7ae78a17a41fa67bc72f358ee0b7afd15d75 100644 --- a/library/Class/Cosmogramme/Generator/KindsTask.php +++ b/library/Class/Cosmogramme/Generator/KindsTask.php @@ -57,4 +57,18 @@ class Class_Cosmogramme_Generator_KindsTask extends Class_Cosmogramme_Generator_ protected function getItemField() { return 'genre'; } + + + protected function _findExistingBy($code, $label) { + return ($model = Class_CodifGenre::findFirstBy(['libelle' => $label])) + ? $model + : Class_CodifGenre::newInstance(['libelle' => $label]); + } + + + protected function _createOrConcatRules($code, $model) { + return $this->_date != $model->getDateMaj() + ? $this->_getRuleFor($code) + : $this->_concatRulesTo($code, $model); + } } diff --git a/library/Class/Cosmogramme/Integration/PhasePrepareIntegrations.php b/library/Class/Cosmogramme/Integration/PhasePrepareIntegrations.php index 2836fe1805b724936f63e1212e564cfc2a7bc999..8e2aca10addc9572f7d22274d0973bf70673513f 100644 --- a/library/Class/Cosmogramme/Integration/PhasePrepareIntegrations.php +++ b/library/Class/Cosmogramme/Integration/PhasePrepareIntegrations.php @@ -70,10 +70,13 @@ class Class_Cosmogramme_Integration_PhasePrepareIntegrations extends Class_Cosmo protected function _updateStandard() { $generator = (new Class_Cosmogramme_Generator())->beUpdate(); - if (!$standard_dir = $generator->getUpdatableStandard()) + $this->_log->log('<h4>' . $this->_('Mise à jour de l\'étalon') . '</h4>'); + + if (!$standard_dir = $generator->getUpdatableStandard()) { + $this->_log->info($this->_('État de la Configuration : %s', $generator->getLastError())); return $this; + } - $this->_log->log('<h4>' . $this->_('Mise à jour de l\'étalon') . '</h4>'); $generator->update($standard_dir) ? $this->_log->success($this->_('OK')) : $this->_log->error($this->_('Erreur : %s', diff --git a/library/Class/Cosmogramme/Integration/WaitingFiles.php b/library/Class/Cosmogramme/Integration/WaitingFiles.php index fd921d81b982ce85a140b31c82c4bd917f15744a..cd5bf8a667ce7a9bcf22b014c7874b76cbf50fb3 100644 --- a/library/Class/Cosmogramme/Integration/WaitingFiles.php +++ b/library/Class/Cosmogramme/Integration/WaitingFiles.php @@ -26,9 +26,11 @@ class Class_Cosmogramme_Integration_WaitingFiles { Class_FileManager_FileSystem::beUnlimited(); $files = []; + foreach(Class_FileManager::directories(Class_CosmoVar::get('ftp_path')) as $directory) - foreach(Class_FileManager::files($directory->getPath()) as $file) - $files[] = $file; + foreach(Class_FileManager::search('*', $directory->getPath()) as $file) + if ($file->isFile()) + $files[] = $file; usort($files, function($a, $b) diff --git a/library/Class/Cosmogramme/LandingDirectory.php b/library/Class/Cosmogramme/LandingDirectory.php index 50c51c2a19ca717583aa9b9f492b2b37cc45d146..bdc24c20eed4e8b37b092e0a6387f8d97d89052a 100644 --- a/library/Class/Cosmogramme/LandingDirectory.php +++ b/library/Class/Cosmogramme/LandingDirectory.php @@ -26,6 +26,8 @@ class Class_Cosmogramme_LandingDirectory { const VAR_NAME = 'ftp_path'; const STANDARD_NAME = 'etalon'; + protected static $_subdir_cache; + protected $_path, $_required_files = ['libraries' => 'annexes.txt', @@ -39,6 +41,22 @@ class Class_Cosmogramme_LandingDirectory { } + public static function reset() { + static::$_subdir_cache = null; + static::setInstance(null); + } + + + public static function setSubdirCache($subdir) { + static::$_subdir_cache = $subdir; + } + + + public function getRequiredFiles() { + return $this->_required_files; + } + + public function isValid() { if ($this->_path && $this->getFileSystem()->file_exists($this->_path)) return true; @@ -78,9 +96,12 @@ class Class_Cosmogramme_LandingDirectory { public function getUpdatableStandard() { + if (static::$_subdir_cache) + return static::$_subdir_cache; + if (($subdir = $this->getSingleSubdirectory()) && $this->couldGenerateFrom($subdir)) - return $subdir; + return static::$_subdir_cache = $subdir; } @@ -151,9 +172,18 @@ class Class_Cosmogramme_LandingDirectory { public function getSingleSubdirectory() { - if (!$subdirs = $this->getSubdirectories()) + if (!$subdirs = $this->getSubdirectories()) { + $this->log($this->_('Pas de sous-répertoire dans : %s', + $this->_path)); return null; + } + + if ( 1 < count($subdirs)) { + $this->log($this->_('Trop de sous-répertoires dans : %s', + $this->_path)); + return null; + } - return 1 == count($subdirs) ? current($subdirs) : null; + return current($subdirs); } } \ No newline at end of file diff --git a/library/Class/FileManager/FileSystem.php b/library/Class/FileManager/FileSystem.php index 120d2a4d19418f350371ff1c2d7b6e78d2ae2b2d..54ab9c32be33c73bee4fc4b4c941cc18381c30b8 100644 --- a/library/Class/FileManager/FileSystem.php +++ b/library/Class/FileManager/FileSystem.php @@ -367,7 +367,7 @@ class Class_FileManager_FileSystem { sort($found, SORT_NATURAL); - if(Class_FileManager_FileSystem::LISTING_LIMIT < count($found)) { + if(static::$_limited && Class_FileManager_FileSystem::LISTING_LIMIT < count($found)) { $this->_oversized[] = $path; $found = array_slice($found, 0, Class_FileManager_FileSystem::LISTING_LIMIT); } diff --git a/library/Class/TableDescription/CosmoWaitingFiles.php b/library/Class/TableDescription/CosmoWaitingFiles.php index c17e34f3461dbe33303704920d2986ced041de54..c27b6bcf675891ed18d1ba790831f09e0793411b 100644 --- a/library/Class/TableDescription/CosmoWaitingFiles.php +++ b/library/Class/TableDescription/CosmoWaitingFiles.php @@ -33,10 +33,33 @@ class Class_TableDescription_CosmoWaitingFiles extends Class_TableDescription { public function read() { - $statut = function($item) { + $landing_directory = new Class_Cosmogramme_LandingDirectory; + + $standard_status = function($item) use ($landing_directory) { + if (!$landing_directory->getUpdatableStandard()) + return $this->_view->tagWarning($this->_('Non programmé')); + + return in_array($item->getName(), $landing_directory->getRequiredFiles()) + ? $this->_view->tagNotice($this->_('Programmé')) + : $this->_view->tagWarning($this->_('Non programmé')); + }; + + $statut = function($item) use ($standard_status) { $folder = ($parent = $item->getParent()) ? $parent->getName() : ''; + $path = $folder . '/' . $item->getName(); + + if ($folder == Class_Cosmogramme_LandingDirectory::STANDARD_NAME) + return $standard_status($item); + + $higher_folder = ($higher_parent = $parent->getParent()) ? $higher_parent->getName() : ''; + $higher_path = $higher_folder ? $higher_folder . '/' . $path : ''; + + if ($prog = Class_IntMajAuto::findFirstby(['nom_fichier' => $path])) { + $item->setProgrammed($prog); + return $this->_view->tagNotice($this->_('Programmé')); + } - if ($prog = Class_IntMajAuto::findFirstby(['nom_fichier' => $folder . '/' . $item->getName()])) { + if ($higher_path && $prog = Class_IntMajAuto::findFirstby(['nom_fichier' => $higher_path])) { $item->setProgrammed($prog); return $this->_view->tagNotice($this->_('Programmé')); } @@ -93,7 +116,15 @@ class Class_TableDescription_CosmoWaitingFiles extends Class_TableDescription { $this ->addColumn($this->_('Dossier'), - function($item) { return ($parent = $item->getParent()) ? $parent->getName() : ''; }) + ['callback' => function($item) + { + return ($parent = $item->getParent()) ? $item->getParentPath() : ''; + }, + 'options' => ['row_params' => function($item) + { + return ['data-path' => $item->getPath()]; + } + ]]) ->addColumn($this->_('Fichier'), function($item) { return $item->getName(); }) @@ -136,8 +167,7 @@ class Class_TableDescription_CosmoWaitingFiles extends Class_TableDescription { ->addRowAction($delete) - ->addRowAction($download) - ; + ->addRowAction($download); return $this; } diff --git a/tests/library/Class/Cosmogramme/Integration/PhasePrepareIntegrationsTest.php b/tests/library/Class/Cosmogramme/Integration/PhasePrepareIntegrationsTest.php index a3c3f28f6720444fb5289c45b7a0ce7ddd73708b..1c4682b391f31b93828416d8fd2b16380765df5c 100644 --- a/tests/library/Class/Cosmogramme/Integration/PhasePrepareIntegrationsTest.php +++ b/tests/library/Class/Cosmogramme/Integration/PhasePrepareIntegrationsTest.php @@ -30,11 +30,13 @@ abstract class PhasePrepareIntegrationsWithOAITestCase $foo = $this->mock() ->whenCalled('getName')->answers('foo') + ->whenCalled('isDir')->answers(true) ->whenCalled('getPath')->answers('ftp/my-library.net/transferts/foo'); $file_with_date = $this->mock() ->whenCalled('getName')->answers('20180517mylibraryincr.txt') + ->whenCalled('isFile')->answers(true) ->whenCalled('getId')->answers('ftp/my-library.net/transferts/foo/20180517mylibraryincr.txt') ->whenCalled('getFileMTime')->answers(strtotime('2018-05-17')) ->whenCalled('getParent')->answers($foo); @@ -42,6 +44,7 @@ abstract class PhasePrepareIntegrationsWithOAITestCase $other_with_date = $this->mock() ->whenCalled('getName')->answers('20190118mylibraryincr.txt') + ->whenCalled('isFile')->answers(true) ->whenCalled('getId')->answers('ftp/my-library.net/transferts/foo/20190118mylibraryincr.txt') ->whenCalled('getFileMTime')->answers(strtotime('2019-01-18')) ->whenCalled('getParent')->answers($foo); @@ -53,7 +56,10 @@ abstract class PhasePrepareIntegrationsWithOAITestCase ->whenCalled('directoriesAt')->with('ftp/my-library.net/transferts/') ->answers([$foo]) - ->whenCalled('filesAt')->with('ftp/my-library.net/transferts/foo') + ->whenCalled('directoryAt')->with('ftp/my-library.net/transferts/foo') + ->answers($foo) + + ->whenCalled('search')->with('*', 'ftp/my-library.net/transferts/foo') ->answers([$file_with_date, $other_with_date]); @@ -123,7 +129,6 @@ abstract class PhasePrepareIntegrationsWithOAITestCase Class_Cosmogramme_Integration_PhasePrepareIntegrations::setFileSystem($file_system); Class_Cosmogramme_Integration_PhasePrepareIntegrations::setTimeSource(new TimeSourceForTest('2015-03-26 14:00:00')); - $this->_phase = $this->_buildPhase('PrepareIntegrations')->run(); } @@ -457,7 +462,6 @@ class PhasePrepareIntegrationsNanookStandardTest Class_Cosmogramme_LandingDirectory::setInstance($landing_directory); - $this->fixture('Class_CodifSection', ['id' => 34, 'libelle' => 'Game', @@ -600,9 +604,7 @@ class PhasePrepareIntegrationsNanookStandardTest 'id_article_periodique' => Class_IntProfilDonnees::SERIAL_FORMAT_PERGAME, 'type_fichier' => Class_IntProfilDonnees::FT_RECORDS, 'format' => Class_IntProfilDonnees::FORMAT_UNIMARC, - 'attributs' => [] - ] - ); + 'attributs' => []]); $this->fixture('Class_IntProfilDonnees', ['id' => 103, @@ -800,4 +802,157 @@ class PhasePrepareIntegrationsNanookStandardTest public function renamedSectionShouldBeUpdated() { $this->assertEquals('Jeunes', Class_CodifSection::find(38)->getLibelle()); } +} + + + +class PhasePrepareIntegrationsKindTest extends Class_Cosmogramme_Integration_PhaseTestCase { + protected $_http_client; + + public function setUp() { + parent::setUp(); + + Class_Cosmogramme_Generator_KindsTask::setTimeSource(new TimeSourceForTest('2019-02-12 14:00:00')); + + $sql = $this + ->mock() + ->beStrict() + + ->whenCalled('query') + ->with('update exemplaires set genre="" where genre="5"') + ->answers('') + + ->whenCalled('query') + ->with('update exemplaires set genre="" where genre="4"') + ->answers('') + + ->whenCalled('query') + ->with('update notices set date_maj="2019-02-12 14:00:00" where match(facettes) against("G4 G5" in BOOLEAN MODE)') + ->answers('') + + ->whenCalled('query') + ->with('delete from codif_genre where date_maj != "2019-02-12"') + ->willDo(function() + { + (new Storm_Model_Collection(Class_CodifGenre::findAllBy(['date_maj not' => '2019-02-12']))) + ->eachDo('delete'); + }) + + ->whenCalled('query') + ->with('update codif_genre set date_maj=""') + ->willDo(function() + { + (new Storm_Model_Collection(Class_CodifGenre::findAll())) + ->eachDo(function($model) + { + $model->setDateMaj(''); + }); + }); + + Class_Cosmogramme_Generator_KindsTask::setDbAdapter($sql); + + $generator = $this + ->mock() + + ->whenCalled('logTitle') + ->answers('') + + ->whenCalled('log') + ->answers('') + + ->whenCalled('isNanook') + ->answers(true) + + ->whenCalled('isPergame') + ->answers(false); + + $this->fixture('Class_CodifGenre', + ['id' => 4, + 'libelle' => 'ALBUM', + 'regles' => '995$7=1']); + + $this->fixture('Class_CodifGenre', + ['id' => 5, + 'libelle' => 'Fiction', + 'regles' => '995$7=3']); + + $this->fixture('Class_CodifGenre', + ['id' => 6, + 'libelle' => 'SYNTHETISEUR, flûte de PAN', + 'regles' => '995$7=51;2;3']); + + $datas = ['BIB_GENRES|SUPPORT|CODE|LIBELLE|DOC', + '0|1|Music|f', + '0|2|Bande dessinée|f', + '0|3|Bande dessinée|f', + '0|51|SYNTHETISEUR, flûte de PAN|f', + '0|94|SYNTHETISEUR|f']; + + (new Class_Cosmogramme_Generator_KindsTask($generator, []))->run($datas); + } + + + /** @test */ + public function fictionShouldHaveBeenDeleted() { + $this->assertNull(Class_CodifGenre::find(34)); + } + + + /** @test */ + public function albumShouldBeDeleted() { + $this->assertNull(Class_CodifGenre::find(4)); + } + + + /** @test */ + public function fourKindsShouldRemains() { + $this->assertEquals(4, Class_CodifGenre::count()); + } + + + public function getAttribs() { + return [ + ['Music', + ['picto' => '', + 'libelle' => 'Music', + 'regles' => '995$7=1', + 'date_maj' => '', + 'id' => 7, + 'id_genre' => 7]], + + ['Bande dessinée', + ['picto' => '', + 'libelle' => 'Bande dessinée', + 'regles' => '995$7=2;3', + 'date_maj' => '', + 'id' => 8, + 'id_genre' => 8]], + + ['SYNTHETISEUR, flûte de PAN', + ['picto' => '', + 'libelle' => 'SYNTHETISEUR, flûte de PAN', + 'regles' => '995$7=51', + 'date_maj' => '', + 'id' => 6, + 'id_genre' => 6]], + + ['SYNTHETISEUR', + ['picto' => '', + 'libelle' => 'SYNTHETISEUR', + 'regles' => '995$7=94', + 'date_maj' => '', + 'id' => 9, + 'id_genre' => 9]] + ]; + } + + + /** + * @dataProvider getAttribs + * @test + */ + public function codifAttribsShouldBeAsExpected($label, $attribs) { + $this->assertNotNull($kind = Class_CodifGenre::findFirstBy(['libelle' => $label])); + $this->assertEquals($attribs, $kind->toArray()); + } } \ No newline at end of file diff --git a/tests/library/Class/Migration/SigbStandardCodificationsTest.php b/tests/library/Class/Migration/SigbStandardCodificationsTest.php index 536e9aa38d062cca2b8c40688311abb4b23f52ef..be940be2ad16039fe7a77af49b31a845282b253f 100644 --- a/tests/library/Class/Migration/SigbStandardCodificationsTest.php +++ b/tests/library/Class/Migration/SigbStandardCodificationsTest.php @@ -100,7 +100,7 @@ class Class_Migration_SigbStandardCodificationsTest extends ModelTestCase { /** @test */ public function withSingleNanookShouldCleanLocations() { (new Class_Migration_SigbStandardCodifications())->run(); - $this->assertEquals('995$6=108;9', Class_CodifEmplacement::find(33)->getRegles()); + $this->assertEquals('995$6=9', Class_CodifEmplacement::find(33)->getRegles()); } diff --git a/tests/library/Class/ModelTestCase.php b/tests/library/Class/ModelTestCase.php index e95f85b7703f0a2ab3b7cdc576ac10071dec57aa..fc600cf475eca4634fd97c2129a68840a607f072 100644 --- a/tests/library/Class/ModelTestCase.php +++ b/tests/library/Class/ModelTestCase.php @@ -99,6 +99,8 @@ abstract class ModelTestCase extends Storm_Test_ModelTestCase { Class_FileManager::reset(); Class_MoteurRecherche::resetInstance(); Class_Crypt::setPhpCommand(null); + Class_Cosmogramme_LandingDirectory::reset(); + Class_Cosmogramme_Generator_KindsTask::setDbAdapter(null); if($this->_storm_default_to_volatile) { Storm_Model_Loader::defaultToDb();