diff --git a/build_other.sh b/build_other.sh index 162caec15f91bcfd9815354a862bcb5534bc8ddc..e4849f1d59e2fb27863113b21bc28fc8d7c3f267 100644 --- a/build_other.sh +++ b/build_other.sh @@ -10,8 +10,8 @@ EARLY_DESC=`php -r "echo version_compare(PHP_VERSION, '8.1', '>=') ? '--fail-err phpunit -c tests/phpunit_eco.xml --list-suites $EARLY_DESC \ && phpunit -c tests/phpunit_eco.xml $EARLY_DESC \ - && phpunit -c tests/phpunit_db.xml --list-suites $EARLY_DESC \ - && phpunit -c tests/phpunit_db.xml --exclude-group no-ci $EARLY_DESC \ + && phpunit -c tests_db/phpunit.xml --list-suites $EARLY_DESC \ + && phpunit -c tests_db/phpunit.xml --exclude-group no-ci $EARLY_DESC \ && phpunit -c tests/phpunit_js.xml --list-suites $EARLY_DESC \ && phpunit -c tests/phpunit_js.xml --exclude-group no-ci $EARLY_DESC \ && phpunit -c tests/phpunit_templates.xml --list-suites $EARLY_DESC \ diff --git a/build_other_74.sh b/build_other_74.sh index a520b00cf8f67967573281a4e957e017f6a2b010..84a71112b54dbc2e8962577e0e679be08a8d97fc 100644 --- a/build_other_74.sh +++ b/build_other_74.sh @@ -10,8 +10,8 @@ EARLY_DESC=`php -r "echo version_compare(PHP_VERSION, '8.1', '>=') ? '--fail-err phpunit -c tests/phpunit_eco.xml --list-suites $EARLY_DESC \ && phpunit -c tests/phpunit_eco.xml $EARLY_DESC \ - && phpunit -c tests/phpunit_db.xml --list-suites $EARLY_DESC \ - && phpunit -c tests/phpunit_db.xml --exclude-group no-ci $EARLY_DESC \ + && phpunit -c tests_db/phpunit.xml --list-suites $EARLY_DESC \ + && phpunit -c tests_db/phpunit.xml --exclude-group no-ci $EARLY_DESC \ && phpunit -c tests/phpunit_templates.xml --list-suites $EARLY_DESC \ && phpunit -c tests/phpunit_templates.xml --exclude-group no-ci $EARLY_DESC \ && cd cosmogramme/tests \ diff --git a/library/Class/DigitalResource.php b/library/Class/DigitalResource.php index e2b9e889043e00cbb12b5bce8b42a9eb47ad0415..6b7f65b79f570e98d6152a1c75731f2712a853f7 100644 --- a/library/Class/DigitalResource.php +++ b/library/Class/DigitalResource.php @@ -20,55 +20,110 @@ */ -class Class_DigitalResource extends Class_Entity { +class Class_DigitalResource +{ use Trait_StormFileSystem; + protected static ?Storm_Collection $_plugins = null; protected static $_instance; - protected $_plugins, $_batches; + protected ?array $_batches = null; - - public static function getInstance() { - if(!static::$_instance) - static::$_instance = new static(); + public static function getInstance(): self + { + if ( ! static::$_instance) + static::$_instance = new static; return static::$_instance; } - public static function resetInstance() { + /** @testing */ + public static function resetInstance() + { static::$_instance = null; + static::$_plugins = null; + static::setFileSystem(null); + } + + + /** @testing */ + public static function initFileSystem() + { + $file_system = (new Storm_FileSystem_Volatile) + ->mkdir(static::getInstance()->getBaseDir() . 'Arkhenum') + ->mkdir(static::getInstance()->getBaseDir() . 'ArteCampus') + ->mkdir(static::getInstance()->getBaseDir() . 'ArteVod') + ->mkdir(static::getInstance()->getBaseDir() . 'Artips') + ->mkdir(static::getInstance()->getBaseDir() . 'Assimil') + ->mkdir(static::getInstance()->getBaseDir() . 'Bacon') + ->mkdir(static::getInstance()->getBaseDir() . 'Bibliondemand') + ->mkdir(static::getInstance()->getBaseDir() . 'C3rb') + ->mkdir(static::getInstance()->getBaseDir() . 'Cafeyn') + ->mkdir(static::getInstance()->getBaseDir() . 'Capturator') + ->mkdir(static::getInstance()->getBaseDir() . 'Cvs') + ->mkdir(static::getInstance()->getBaseDir() . 'Cvs2') + ->mkdir(static::getInstance()->getBaseDir() . 'Cyberlibris') + ->mkdir(static::getInstance()->getBaseDir() . 'DiMusic') + ->mkdir(static::getInstance()->getBaseDir() . 'Kidilangues') + ->mkdir(static::getInstance()->getBaseDir() . 'LaSourisQuiRaconte') + ->mkdir(static::getInstance()->getBaseDir() . 'LesYeuxDoc') + ->mkdir(static::getInstance()->getBaseDir() . 'MaPetiteMediatheque') + ->mkdir(static::getInstance()->getBaseDir() . 'Mangasio') + ->mkdir(static::getInstance()->getBaseDir() . 'Mobidys') + ->mkdir(static::getInstance()->getBaseDir() . 'Musicme') + ->mkdir(static::getInstance()->getBaseDir() . 'Numel') + ->mkdir(static::getInstance()->getBaseDir() . 'Numilog') + ->mkdir(static::getInstance()->getBaseDir() . 'Omeka') + ->mkdir(static::getInstance()->getBaseDir() . 'OmekaS') + ->mkdir(static::getInstance()->getBaseDir() . 'Orthodidacte') + ->mkdir(static::getInstance()->getBaseDir() . 'Skilleos') + ->mkdir(static::getInstance()->getBaseDir() . 'StoryPlayR') + ->mkdir(static::getInstance()->getBaseDir() . 'Syracuse') + ->mkdir(static::getInstance()->getBaseDir() . 'ToutApprendre') + ->mkdir(static::getInstance()->getBaseDir() . 'Whisperies'); + + static::setFileSystem($file_system); + } + + + public function getDocType($plugin) + { + return $plugin; } - public function bootstrap($front_controller) { - $this->getPlugins()->eachDo( - function($config) use ($front_controller) { - $config->registerFrontController($front_controller); - }); + public function bootstrap(Zend_Controller_Front $front_controller): self + { + $this->getPlugins()->eachDo(fn($config) => $config->registerFrontController($front_controller)); + + return $this; } - public function enablePluginWith($admin_var) { - if(!$config = $this->getConfigWith($admin_var)) - return $this; + public function enablePluginWith(string $admin_var): ?Class_DigitalResource_Config + { + if ( ! $config = $this->getConfigWith($admin_var)) + return null; return $config->enablePlugin(); } - public function getConfigWith($admin_var) { + public function getConfigWith(string $admin_var): ?Class_DigitalResource_Config + { return $this->getPlugins() ->detect(function($config) use ($admin_var) - { - $name = $config->getName(); - return $admin_var == $this->withNamespace($name, $name); - } - ); + { + $name = $config->getName(); + + return $admin_var == $this->withNamespace($name, $name); + }); } - public function getHelpLink($module) { - if(!$this->isPluginModule($module)) + public function getHelpLink(?string $module): string + { + if ( ! $this->isPluginModule($module)) return ''; $config = $this->configFor($this->getPluginNameFromModule($module)); @@ -76,153 +131,146 @@ class Class_DigitalResource extends Class_Entity { } - public function addFormElementsIn($form) { + public function addFormElementsIn(ZendAfi_Form $form): ZendAfi_Form + { $this->getPlugins() - ->eachDo( - function($config) use ($form) - { - return $config->addFormElementsIn($form); - } - ); + ->eachDo(fn($config) => $config->addFormElementsIn($form)); + return $form; } - public function getPluginsSSOActions() { + public function getPluginsSSOActions(): Storm_Collection + { return $this->getPlugins() - ->collect( - function($config) - { - return $config->getSsoAction(); - } - ); + ->collect(fn($config) => $config->getSsoAction()); } - public function getPluginForServiceUrl(string $url) : ?Class_DigitalResource_Config{ + public function getPluginForServiceUrl(string $url): ?Class_DigitalResource_Config + { return $this->getPlugins() - ->detect(function($config) use ($url) - { - return ($service = $config->getServiceUrl()) - ? FALSE !== stristr(strtolower($url), $config->getServiceUrl()) - : false; - }); + ->detect(fn($config) => ($service = $config->getServiceUrl()) + ? false !== stristr(strtolower($url), $service) + : false); } - public function getSsoActionForPlugin($name) { + public function getSsoActionForPlugin(string $name): ?string + { $action_name = $this->getPlugins() - ->collect(function($config) use ($name) - { - return ($name == $config->getName()) ? $config->getSsoAction() : null; - }) + ->collect(fn($config) => ($name == $config->getName()) + ? $config->getSsoAction() + : null) ->getArrayCopy(); + $action_name = array_filter($action_name); return reset($action_name); } - public function getPluginsDescription() { - return $this->pluginsByName(function($config) - { - return $config->getDescription(); - }); + public function getPluginsDescription(): array + { + return $this->pluginsByName(fn($config) => $config->getDescription()); } - public function pluginsByName($closure) { + public function pluginsByName(Closure $closure): array + { return array_filter($this->getPlugins() ->injectInto([], function($configs, $config) use ($closure) { - $configs[$config->getName()] = $closure($config); + $configs [$config->getName()] = $closure($config); + return array_filter($configs); })); } - public function getServices() { + public function getServices(): array + { return $this->pluginsByName(function($config) { - if($service = $config->getService()) + if ($service = $config->getService()) return $this->build($config->getService(), $config); }); } - public function getImporters() { + public function getImporters(): array + { return $this->pluginsByName(function($config) { - if($importer = $config->getImporter()) + if ($importer = $config->getImporter()) return $this->build($importer, $config); }); } - public function getHarvesters() { + public function getHarvesters(): array + { return $this->pluginsByName(function($config) { - if($harvester = $config->getHarvester()) + if ($harvester = $config->getHarvester()) return $this->build($harvester, $config); }); } - public function hasRightAccessPlugin($plugin, $user) { - if (!$this->isPluginDocType($plugin)) - return false; - - if (!$this->hasPermissionOn($plugin, $user)) - return false; - - return true; + public function hasRightAccessPlugin(string $plugin, Class_Users $user): bool + { + return $this->isPluginDocType($plugin) && $this->hasPermissionOn($plugin, $user); } - public function hasPermissionOn($plugin, $user) { - if (!$config = $this->configFor($plugin)) + public function hasPermissionOn(string $plugin, Class_Users $user): bool + { + if ( ! $config = $this->configFor($plugin)) return false; - if (!$permission = $config->getPermission()) + if ( ! $permission = $config->getPermission()) return false; return $user->hasPermission($permission); } - public function getPermissionsLabel() { + public function getPermissionsLabel(): array + { return $this->pluginsByName(function($config) { - if($config->isEnabled()) + if ($config->isEnabled()) return $config->getPermissionLabel(); }); } - public function getPermissions() { + public function getPermissions(): array + { return array_filter($this->getPlugins() ->collect(function($config) { - if($config->isEnabled()) + if ($config->isEnabled()) return $config->getPermission(); - } - ) + }) ->getArrayCopy()); } - public function getThesauri() { + public function getThesauri(): array + { return array_filter($this->getPlugins() ->injectInto([], function($thesauri, $config) { - if (!$config->isEnabled()) + if ( ! $config->isEnabled()) return $thesauri; - if (!$config_thesauri = $config->getThesauri()) + if ( ! $config_thesauri = $config->getThesauri()) return $thesauri; - foreach($config_thesauri as $id => $params) + foreach ($config_thesauri as $id => $params) $thesauri [$id] = Class_CodifThesaurusFixed::newWith($params); return $thesauri; @@ -230,7 +278,8 @@ class Class_DigitalResource extends Class_Entity { } - public function renderAlbumOn(Class_Album $album, Zend_View $view) : string { + public function renderAlbumOn(Class_Album $album, Zend_View $view): string + { if ( ! $config = $this->getConfigForDocType($album->getTypeDocId())) return ''; @@ -238,83 +287,91 @@ class Class_DigitalResource extends Class_Entity { } - public function getPhoneLabelOf($record) { - if (!$config = $this->getConfigForDocType($type = $record->getTypeDoc())) + public function getPhoneLabelOf(Class_Notice $record): string + { + if ( ! $config = $this->getConfigForDocType($type = $record->getTypeDoc())) return ''; return $config->getPhoneLabel(); } - public function getExternalUris(Class_Notice $record) : array { + public function getExternalUris(Class_Notice $record): array + { return ($config = $this->getConfigForDocType($record->getTypeDoc())) ? $config->getExternalUris($record) : []; } - public function viewHelperFor($type, $helper, $view) { - if (!is_readable($this->getBaseDir() . '/' . $type . '/View/Helper/' . $helper . '.php')) + public function viewHelperFor($type, $helper, $view) + { + if ( ! is_readable($this->getBaseDir() . '/' . $type . '/View/Helper/' . $helper . '.php')) return; $class_name = $type . '_View_Helper_' . $helper; - return $this->build($class_name, $this->configFor($type)) + + return $this->build($class_name, $this->configFor($type)) ->setView($view); } - public function getDocTypes() { + public function getDocTypes(): array + { return $this->getPlugins() ->injectInto([], fn($types, $config) => $config->addDocTypeIn($types)); } - public function getModulesMenu() { + public function getModulesMenu(): array + { return $this->pluginsByName(function($config) { - if($module_menu = $config->getModuleMenu()) + if ($module_menu = $config->getModuleMenu()) return $this->build($module_menu, $config); }); } - public function getModuleMenuFor($name) { + public function getModuleMenuFor(string $name) + { $modules = $this->getModulesMenu(); - if(!isset($modules[$name])) + + if ( ! isset($modules[$name])) return null; return $modules[$name]; } - public function isPluginDocType($type) { + public function isPluginDocType(string $type): bool + { return (null !== $this->getConfigForDocType($type)); } - public function getConfigForDocType(string $type) : ?Class_DigitalResource_Config { - if(!$type) + public function getConfigForDocType(string $type): ?Class_DigitalResource_Config + { + if ( ! $type) return null; return $this->getPlugins() - ->detect( - function($config) use ($type) - { - return $config->isDocTypeHandled($type); - }); + ->detect(fn($config) => $config->isDocTypeHandled($type)); } - public function getPluginDocTypeIcon($type) { - if (!$this->isPluginDocType($type)) - return; + public function getPluginDocTypeIcon(string $type): string + { + if ( ! $this->isPluginDocType($type)) + return ''; return $this->getBaseDir() . '/' . $type . '/images/icon.png'; } - public function handlePluginModule($module, $view_renderer) { - if (!$this->isPluginModule($module)) + public function handlePluginModule(string $module, $view_renderer): bool + { + if ( ! $this->isPluginModule($module)) return false; $plugin = $this->getPluginNameFromModule($module); @@ -329,100 +386,99 @@ class Class_DigitalResource extends Class_Entity { } - public function isPluginModule($module) { - return $this->getPlugins() - ->detect( - function($config) use ($module) - { - return $module === $this->getModuleNameFor($config->getName()); - }) ; + public function isPluginModule(?string $module): bool + { + return null !== $this + ->getPlugins() + ->detect(fn($config) => $module === $this->getModuleNameFor($config->getName())); } - public function getModuleNameFor($plugin) { + public function getModuleNameFor(string $plugin): string + { return $this->withNamespace($plugin, 'Plugin'); } - public function getModuleNameForAction($action_name) { + public function getModuleNameForAction(string $action_name): string + { return $this->getModuleNameFor(Storm_Inflector::camelize($action_name)); } - public function getPluginNameFromModule($module) { + public function getPluginNameFromModule(string $module): string + { $parts = explode('_', $module); - return $parts[0]; + + return $parts[0] ?? ''; } - public function configFor($plugin) { + public function configFor(string $plugin) + { $class_name = $plugin . '_Config'; - return $this->getConfigProvider()->getConfig($this, $class_name, $plugin); - } - - protected function getConfigProvider() { - return $this->get('ConfigProvider') - ? $this->get('ConfigProvider') - : new Class_DigitalResource_ConfigProvider(); + return (new Class_DigitalResource_ConfigProvider) + ->getConfig($this, $class_name, $plugin); } - public function isAdminVarOn(string $plugin, string $name) { + public function isAdminVarOn(string $plugin, string $name): bool + { return Class_AdminVar::isModuleEnabled($this->withNamespace($plugin, $name)); } - public function getAdminVar(string $plugin, string $name) { + public function getAdminVar(string $plugin, string $name) + { return Class_AdminVar::getValueOrDefault($this->withNamespace($plugin, $name)); } - public function getAdminVarValue(string $plugin, string $name) { + public function getAdminVarValue(string $plugin, string $name) + { return Class_AdminVar::get($this->withNamespace($plugin, $name)); } - public function getAdminVarInstance(string $plugin, string $name) { + public function getAdminVarInstance(string $plugin, string $name): ?Class_AdminVar + { return Class_AdminVar::find($this->withNamespace($plugin, $name)); } - public function getDocType($plugin) { - return $plugin; - } + protected function getPlugins(): Storm_Collection + { + if (static::$_plugins) + return static::$_plugins; - - protected function getPlugins() { - if(isset($this->_plugins)) - return $this->_plugins; - - $directories = new Storm_Collection($this->getFileSystem()->directoryNamesAt($this->getBaseDir())); - return $this->_plugins = $directories - ->collect(function($dirname) { return $this->configFor($dirname); }) - ->reject(function($config) { return !$config; }); + $directories = new Storm_Collection($this->getFileSystem() + ->directoryNamesAt($this->getBaseDir())); + return static::$_plugins = $directories + ->collect(fn($dirname) => $this->configFor($dirname)) + ->reject(fn($config) => ! $config); } - public function build($class_name, $config) { - if($builder = $this->get('Builder')) - return $builder->newInstance($class_name, $config); - - if(class_exists($class_name)) + public function build(string $class_name, $config) + { + if (class_exists($class_name)) return new $class_name($config); - return (new Class_Entity()) + return (new Class_Entity) ->whenCalledDo('isVisibleForProfil', function() {}); } - public function getBaseDir() { + public function getBaseDir(): string + { return ROOT_PATH . 'library/digital_resources/'; } - public function getBatches() { - if (isset($this->_batches)) + public function getBatches(): array + { + if (null !== $this->_batches) return $this->_batches; $batches = $this->getPlugins()->injectInto([], @@ -431,7 +487,7 @@ class Class_DigitalResource extends Class_Entity { if ($batch = $config->getBatch()) $batches[$this->getBatchName($config->getName())] = $this->build($batch, $config); - foreach($config->getOtherBatches() as $name => $instance) + foreach ($config->getOtherBatches() as $name => $instance) $batches[$name] = $instance; return $batches; @@ -441,53 +497,69 @@ class Class_DigitalResource extends Class_Entity { } - public function getBatchName($name) { + public function getBatchName(string $name): string + { return $this->withNamespace($name, 'Batch'); } - public function getAdminVars() { + public function getAdminVars(): array + { return $this->getPlugins() ->injectInto([], function($admin_vars, $config) { - foreach($config->getAdminVars() as $k => $v) + foreach ($config->getAdminVars() as $k => $v) $admin_vars[$this->withNamespace($config->getName(), $k)] = $v; + return $admin_vars; }); } - public function withNamespace($name, $value) { + public function withNamespace(string $name, string $value): string + { return ucfirst($name) . '_' . $value; } } -class Class_DigitalResource_Wrapper { - public function __construct($digital_resource, $plugin) { + +class Class_DigitalResource_Wrapper +{ + + public function __construct(Class_DigitalResource $digital_resource, string $plugin) + { $this->_digital_resource = $digital_resource; $this->_plugin = $plugin; } - public function __call($name, $args) { + public function __call($name, $args) + { array_unshift($args, $this->_plugin); + return call_user_func_array([$this->_digital_resource, $name], $args); } } -class Class_DigitalResource_ConfigProvider { - protected static $_known_classes = []; - public function getConfig($digital_resource, $class_name, $plugin) { - if (!isset(static::$_known_classes[$class_name])) +class Class_DigitalResource_ConfigProvider +{ + + protected static array $_known_classes = []; + + public function getConfig(Class_DigitalResource $digital_resource, + string $class_name, + string $plugin) + { + if ( ! isset(static::$_known_classes[$class_name])) static::$_known_classes[$class_name] = @class_exists($class_name); - if (!static::$_known_classes[$class_name]) + if ( ! static::$_known_classes[$class_name]) return null; return new $class_name(new Class_DigitalResource_Wrapper($digital_resource, $plugin)); diff --git a/library/Class/TypeDoc.php b/library/Class/TypeDoc.php index 87b3a2ab5f04028aa6ba2081a28c349dd0f42803..ebe158541f22cc581215a41ad2f925dd1ff20c30 100644 --- a/library/Class/TypeDoc.php +++ b/library/Class/TypeDoc.php @@ -27,12 +27,6 @@ class TypeDocLoader extends Class_CosmoVar_ModelLoader { $_all_instances, $_used_ids_cache; - public function __construct($class) { - parent::__construct($class); - $this->findAll(); - } - - public function newInstanceWithId($id, $attributes = null) { $instance = $this->newInstance($attributes) ->setId((string)$id); diff --git a/library/digital_resources/ArteVod/tests/ArteVodTest.php b/library/digital_resources/ArteVod/tests/ArteVodTest.php index 95238735ab3659e5d33d7e4a532a43c1a48ca0bb..8e5ea2da5256915412ec18e488226b47c553883c 100644 --- a/library/digital_resources/ArteVod/tests/ArteVodTest.php +++ b/library/digital_resources/ArteVod/tests/ArteVodTest.php @@ -35,6 +35,7 @@ abstract class ArteVodHarverstingTestCase extends ModelTestCase { Class_AdminVar::set('ArteVod_LOGIN', 'user'); Class_AdminVar::set('ArteVod_SSO_KEY', 'pass'); + $codif_type_doc = $this->fixture(Class_CodifTypeDoc::class, ['id' => 'ArteVod', 'famille_id' => Class_CodifTypeDoc::INCONNU, @@ -43,7 +44,7 @@ abstract class ArteVodHarverstingTestCase extends ModelTestCase { 'sections' => '18;19']); $this->fixture(Class_TypeDoc::class, - ['id' => '11', + ['id' => 'ArteVod', 'codif_type_doc' => $codif_type_doc, 'label'=> 'Type doc']); diff --git a/library/digital_resources/Assimil/tests/AssimilTest.php b/library/digital_resources/Assimil/tests/AssimilTest.php index daa14b1c3377b84b0de0f4cf20e85ee1c3dc7d80..fcbee87b6aa0ba0892f227714a2d35479d4b8ef9 100644 --- a/library/digital_resources/Assimil/tests/AssimilTest.php +++ b/library/digital_resources/Assimil/tests/AssimilTest.php @@ -84,14 +84,11 @@ class AssimilNotActivatedAdminTest extends Admin_AbstractControllerTestCase { abstract class AssimilActivatedTestCase extends Admin_AbstractControllerTestCase { - protected - $_config, - $_storm_default_to_volatile = true; - + protected $_config; public function setUp() { parent::setUp(); - Class_DigitalResource::resetInstance(); + Class_AdminVar::set('Assimil_Assimil', '1'); $this->_config = Assimil_Config::getInstance(); } diff --git a/library/digital_resources/Cvs/tests/CvsTest.php b/library/digital_resources/Cvs/tests/CvsTest.php index 4d09083d335ae9132aa361cef3c4ae8f760a470d..6f1c6fd86595c4c9313dc4b549ae70bd5ad3ce79 100644 --- a/library/digital_resources/Cvs/tests/CvsTest.php +++ b/library/digital_resources/Cvs/tests/CvsTest.php @@ -132,11 +132,11 @@ class CvsDashboardTest extends CvsActivatedTestCase { class CvsModuleMenuTest extends CvsActivatedTestCase { + protected $_menu; /** @test */ public function cvsMenuShouldBeAvailable() { - Class_DigitalResource::resetInstance(); $menu = new Class_Systeme_ModulesMenu; $this->assertEquals('Cvs', $menu->getFonction('Cvs')->getType()); } diff --git a/library/digital_resources/Cvs2/Config.php b/library/digital_resources/Cvs2/Config.php index 7483ad52d7fda862cde1995ed6f56abeacd5847e..8c5d61fba52dcf7af05eda5ba617afb88bedc896 100644 --- a/library/digital_resources/Cvs2/Config.php +++ b/library/digital_resources/Cvs2/Config.php @@ -211,10 +211,13 @@ class Cvs2_Config extends Class_DigitalResource_Config { } - public function knownDoctypes() : array { - return Class_CodifTypeDoc::query() + public function knownDoctypes(): array + { + return $this->isEnabled() + ? Class_CodifTypeDoc::query() ->start('type_doc_id', $this->_name) - ->fetchAll(); + ->fetchAll() + : []; } diff --git a/library/digital_resources/Cvs2/tests/Cvs2Test.php b/library/digital_resources/Cvs2/tests/Cvs2Test.php index 352bc30a206cbaaa56ae12ef1b6be25dd3457914..e4ae8713616024d183dac0363c8ec067c588fc65 100644 --- a/library/digital_resources/Cvs2/tests/Cvs2Test.php +++ b/library/digital_resources/Cvs2/tests/Cvs2Test.php @@ -196,7 +196,6 @@ class Cvs2DashboardTest extends Cvs2ActivatedTestCase { ]); $this->dispatch('/Cvs2_Plugin/index'); - Class_TypeDoc::reset(); } @@ -288,11 +287,11 @@ class Cvs2NotHarvestedDashboardTest extends Cvs2ActivatedTestCase { class Cvs2ModuleMenuTest extends Cvs2ActivatedTestCase { + protected $_menu; /** @test */ public function cvsMenuShouldBeAvailable() { - Class_DigitalResource::resetInstance(); $menu = new Class_Systeme_ModulesMenu; $this->assertEquals('Cvs2', $menu->getFonction('Cvs2')->getType()); } diff --git a/library/digital_resources/Orthodidacte/tests/OrthodidacteTest.php b/library/digital_resources/Orthodidacte/tests/OrthodidacteTest.php index 6e115be729f254beb7f2eb894538c91f4b9fc218..a0699c0860e2273ce5f8138e24c4566dbc1aa470 100644 --- a/library/digital_resources/Orthodidacte/tests/OrthodidacteTest.php +++ b/library/digital_resources/Orthodidacte/tests/OrthodidacteTest.php @@ -21,13 +21,11 @@ class OrthodidacteMigrationTest extends ModelTestCase { -protected - $_storm_default_to_volatile = true, - $_migration; + + protected $_migration; public function setUp() { parent::setUp(); - Class_DigitalResource::resetInstance(); $cfg_menus = ['H' => ['libelle' => 'Menu horizontal', 'picto' => 'vide.gif', @@ -91,12 +89,6 @@ protected } - public function tearDown() { - Class_DigitalResource::resetInstance(); - parent::tearDown(); - } - - /** @test */ public function oldAdminVarShouldBeDeleted() { $this->assertNull(Class_AdminVar::get('ORTHODIDACTE')); @@ -231,7 +223,7 @@ class OrthodidacteMenuTest extends OrthodidacteActivatedTestCase { Class_Profil::setCurrentProfil($profil_adulte); Class_Profil::getCurrentProfil()->clearInstanceCache(); - Class_DigitalResource::resetInstance(); + $this->dispatch('/'); } @@ -261,4 +253,4 @@ class OrthodidacteTrySsoTest extends OrthodidacteActivatedTestCase { $this->dispatch('/Orthodidacte_Plugin/index/try-sso', true); $this->assertXPathContentContains('//script', 'document.location.href="https://orthodidacte.com/";'); } -} \ No newline at end of file +} diff --git a/library/digital_resources/StoryPlayR/tests/StoryPlayRTest.php b/library/digital_resources/StoryPlayR/tests/StoryPlayRTest.php index 1a2c4b063a8db770008bb1e96e8e93119fc6acaa..cd49aa53ddf52c64a4a6218c13c37fd9bbdd8dce 100644 --- a/library/digital_resources/StoryPlayR/tests/StoryPlayRTest.php +++ b/library/digital_resources/StoryPlayR/tests/StoryPlayRTest.php @@ -211,9 +211,9 @@ class StoryPlayRAuthValidateTest extends StoryPlayRActivatedTestCase { class StoryPlayRModuleMenuTest extends StoryPlayRActivatedTestCase { + /** @test */ public function storyPlayRMenuShouldBeAvailable() { - Class_DigitalResource::resetInstance(); Class_Systeme_ModulesMenu::reset(); $modules_menu = new Class_Systeme_ModulesMenu; $this->assertEquals('Lien vers StoryPlay*r', $modules_menu->getFonction('StoryPlayR')->getLibelle()); @@ -224,8 +224,8 @@ class StoryPlayRModuleMenuTest extends StoryPlayRActivatedTestCase { class StoryPlayRHarvestTest extends StoryPlayRActivatedTestCase { + protected - $_storm_default_to_volatile = true, $service, $_album; diff --git a/library/startup.php b/library/startup.php index 1ccb03df1e15aff8d6c2486de52b945ce9df4c76..e1480e831659057056e95db20c0e7d6961f4f628 100644 --- a/library/startup.php +++ b/library/startup.php @@ -21,45 +21,54 @@ require_once "Polyfill80.php"; -if (!function_exists('xdebug_break')) +if ( ! function_exists('xdebug_break')) { - function xdebug_break(){}; + function xdebug_break() {}; } function defineConstant($name, $value) { - if (!defined($name)) + if ( ! defined($name)) define($name, $value); } -class Bokeh_Engine { +class Bokeh_Engine +{ protected static $_zend_session_namespace, $_php_command, $_instance; - protected - $_cache_seed, - $_config, - $_front_controller; + protected ?Zend_Config_Ini $_config = null; + protected ?string $_cache_seed = null; + protected ?Zend_Controller_Front $_front_controller = null; + protected bool $_for_test = false; public static function getInstance() { - if ( static::$_instance) + if (static::$_instance) return static::$_instance; - return static::$_instance = new self(); + + return static::$_instance = new self; + } + + + public function run(): ?Zend_Controller_Front + { + return $this + ->powerOn() + ->getFrontController(); } - public function powerOn() + public function powerOn(): self { - return - $this + return $this ->warmUp() ->setupDevOptions() ->setupControllerActionHelper() @@ -74,40 +83,42 @@ class Bokeh_Engine { } - public function getFrontController() + public function getFrontController(): ?Zend_Controller_Front { return $this->_front_controller; } - public function warmUp() : self + public function warmUp(): self { return $this ->warmUpFiles() ->warmUpSession() ->warmUpDB() + ->_defaultToVolatile() ->warmUpAdminVarLanguageAndStorm(); } - public function warmUpFiles() : self + public function warmUpFiles(): self { - require_once('Class/Url.php'); + require_once 'Class/Url.php'; - defineConstant('BASE_URL', Class_Url::baseUrl()); + defineConstant('BASE_URL', Class_Url::baseUrl()); - require_once "Zend/Loader.php"; + require_once 'Zend/Loader.php'; Zend_Loader::registerAutoload(); require_once 'library/templates/autoload.php'; $this->setupConstants(); require_once('requires.php'); + return $this; } - public function warmUpDB() : self + public function warmUpDB(): self { return $this ->loadConfig() @@ -115,13 +126,13 @@ class Bokeh_Engine { } - public function warmUpSession() : self + public function warmUpSession(): self { return $this->setupSession(); } - public function warmUpAdminVarLanguageAndStorm() : self + public function warmUpAdminVarLanguageAndStorm(): self { Class_AdminVar::findAll(); @@ -133,16 +144,16 @@ class Bokeh_Engine { } - public function setupConstants() + public function setupConstants(): self { - defineConstant('BOKEH_MAJOR_VERSION','8.0'); + defineConstant('BOKEH_MAJOR_VERSION', '8.0'); defineConstant('BOKEH_RELEASE_NUMBER', BOKEH_MAJOR_VERSION . '.198'); defineConstant('BOKEH_REMOTE_FILES', 'https://git.afi-sa.net/afi/opacce/'); - defineConstant('ROOT_PATH', realpath(dirname(__FILE__).'/..').'/'); + defineConstant('ROOT_PATH', realpath(dirname(__FILE__) . '/..') . '/'); - defineConstant('ZEND_FRAMEWORK_PATH', ROOT_PATH . 'library/storm/zf/library/'); + defineConstant('ZEND_FRAMEWORK_PATH', ROOT_PATH . 'library/storm/zf/library/'); defineConstant('MODULEDIRECTORY', ROOT_PATH . 'application/modules'); defineConstant('LANG_DIR', ROOT_PATH . 'library/translation/'); @@ -155,12 +166,12 @@ class Bokeh_Engine { defineConstant('GIT_REALTIME', false); defineConstant('GIT_SKINS', 'git@git.afi-sa.net:opac-skins'); - defineConstant('PATH_TEMP', ROOT_PATH . 'temp/'); + defineConstant('PATH_TEMP', ROOT_PATH . 'temp/'); - defineConstant('CKBASEPATH', 'ckeditor/'); - defineConstant('CKBASEURL', BASE_URL . '/ckeditor/'); + defineConstant('CKBASEPATH', 'ckeditor/'); + defineConstant('CKBASEURL', BASE_URL . '/ckeditor/'); - defineConstant('AMBERURL', BASE_URL . '/amber/'); + defineConstant('AMBERURL', BASE_URL . '/amber/'); defineConstant('URL_ADMIN_SKIN', BASE_URL . '/public/admin/skins/'); defineConstant('URL_ADMIN_CSS', BASE_URL . '/public/admin/css/'); @@ -168,19 +179,19 @@ class Bokeh_Engine { defineConstant('URL_ADMIN_JS', BASE_URL . '/public/admin/js/'); defineConstant('JQUERY', URL_ADMIN_JS . 'jquery-3.6.0.min.js'); - defineConstant('JQUERYMOBILE_VERSION', '1.4.5'); + defineConstant('JQUERYMOBILE_VERSION', '1.4.5'); defineConstant('JQUERYUI', URL_ADMIN_JS . 'jquery-ui-1.12.1/jquery-ui.min.js'); - defineConstant('JQUERYUI_CSS', URL_ADMIN_JS.'jquery-ui-1.12.1/jquery-ui.min.css'); + defineConstant('JQUERYUI_CSS', URL_ADMIN_JS . 'jquery-ui-1.12.1/jquery-ui.min.css'); - defineConstant("URL_JS", BASE_URL . "/public/opac/js/"); - defineConstant("URL_EPUB", BASE_URL . "/temp/epub/"); - defineConstant("URL_SHARED_IMG", BASE_URL . "/public/opac/images/"); + defineConstant('URL_JS', BASE_URL . '/public/opac/js/'); + defineConstant('URL_EPUB', BASE_URL . '/temp/epub/'); + defineConstant('URL_SHARED_IMG', BASE_URL . '/public/opac/images/'); // il y a des autre define URL dans ZendAfi_Controller_Plugin_DefineURLs // par exemple URL_IMG, URL_CSS, URL_HTML et URL_JS va chercher dans 'URL_SKIN . 'nom de le module' . /html' etc. - defineConstant('BR','<br />'); - defineConstant('NL',"\n"); - defineConstant('CRLF', chr(13).chr(10)); + defineConstant('BR', '<br />'); + defineConstant('NL', "\n"); + defineConstant('CRLF', chr(13) . chr(10)); defineConstant('URL_JAVA', BASE_URL . '/public/opac/java/'); defineConstant('PATH_JAVA', ROOT_PATH . 'public/opac/java/'); @@ -198,18 +209,20 @@ class Bokeh_Engine { defineConstant('THUMBNAIL_FIT_WIDTH_HEIGHT', '500'); defineConstant('PATCH_PATH', ROOT_PATH . 'cosmogramme/sql/patch/'); - defineConstant('GIT_REALTIME',false); + defineConstant('GIT_REALTIME', false); + return $this; } - public function loadConfig($config_init_file_path = './config.ini', $allowModifications=false) + public function loadConfig(string $config_init_file_path = './config.ini', + bool $allowModifications = false): self { // load configuration (local ou production) - if(array_isset('REMOTE_ADDR', $_SERVER) and $_SERVER['REMOTE_ADDR'] == '127.0.0.1') - $serveur='local'; - else - $serveur='production'; + $serveur = (array_isset('REMOTE_ADDR', $_SERVER) && $_SERVER['REMOTE_ADDR'] == '127.0.0.1') + ? 'local' + : 'production'; + $this->_config = new Zend_Config_Ini($config_init_file_path, $serveur, $allowModifications); Zend_Registry::set('cfg', $this->_config); @@ -224,7 +237,7 @@ class Bokeh_Engine { } - public function setupCache() + public function setupCache(): self { $frontendOptions = ['lifetime' => CACHE_LIFETIME, // durée du cache: 1h 'automatic_serialization' => false, @@ -234,7 +247,7 @@ class Bokeh_Engine { $backendOptions = $use_memcached ? ['servers' => [ ['host' => MEMCACHED_HOST, 'port' => MEMCACHED_PORT] ]] - : ['cache_dir' => PATH_TEMP ]; + : ['cache_dir' => PATH_TEMP ]; // getting a Zend_Cache_Core object $backend = 'File'; @@ -268,49 +281,54 @@ class Bokeh_Engine { } - public function getDbName() : string + public function getDbName(): string { $this->loadConfig(); + return $this->_config->sgbd->config->dbname; } - public function getCacheSeed() + public function getCacheSeed(): ?string { - return $this->_cache_seed;; + return $this->_cache_seed; } - public function setCacheSeed($seed) + public function setCacheSeed(string $seed): self { $this->_cache_seed = $seed; + return $this; } - public function setupSession() + public function setupSession(): self { try { $session = $this->_getZendSessionNamespace()->get(md5(BASE_URL)); - } catch (Zend_Session_Exception $e) { + } catch (Zend_Session_Exception $e) + { return $this->_timeoutReload(); } - if (!isset($session->initialized)) { + if ( ! isset($session->initialized)) + { Zend_Session::regenerateId(); $session->initialized = true; } - if (!isset($session->baseUrl)) + if ( ! isset($session->baseUrl)) $session->baseUrl = BASE_URL; Zend_Registry::set('session', $session); + return $this; } - protected function _timeoutReload() + protected function _timeoutReload(): self { $this->_getPhpCommand()->header('HTTP/1.1 503 Service Unavailable'); $this->_getPhpCommand()->echoHtml('<html>' @@ -323,12 +341,14 @@ class Bokeh_Engine { . '</body>' .'</html>'); $this->_getPhpCommand()->exitDispatch(); + + return $this; } protected function _getPhpCommand() { - if ( static::$_php_command) + if (static::$_php_command) return static::$_php_command; return new Bokeh_PhpCommand; @@ -343,7 +363,7 @@ class Bokeh_Engine { protected function _getZendSessionNamespace() { - if ( static::$_zend_session_namespace ) + if (static::$_zend_session_namespace) return static::$_zend_session_namespace; return new Bokeh_Session; @@ -353,6 +373,7 @@ class Bokeh_Engine { public function setZendSessionNamespace($instance): self { static::$_zend_session_namespace = $instance; + return $this; } @@ -364,7 +385,7 @@ class Bokeh_Engine { } - public function setupLanguage() + public function setupLanguage(): self { $default = Class_AdminVar::getDefaultLanguage(); ZendAfi_Locale::setDefault($default); @@ -381,7 +402,7 @@ class Bokeh_Engine { } - protected function _setupTranslationsIn($translate, $default) + protected function _setupTranslationsIn($translate, $default): self { if ( ! $languages = Class_AdminVar::getLanguesWithoutDefault()) return $this; @@ -398,7 +419,7 @@ class Bokeh_Engine { } - function setupDatabase() + function setupDatabase(): self { // setup database $sql = Zend_Db::factory($this->_config->sgbd->adapter, @@ -406,7 +427,7 @@ class Bokeh_Engine { $sql->usePrepared(false); Zend_Db_Table::setDefaultAdapter($sql); - $afi_sql = new Class_Systeme_Sql(); + $afi_sql = new Class_Systeme_Sql; Zend_Registry::set('sql', $afi_sql); Zend_Db_Table::getDefaultAdapter()->query('set names "UTF8"'); Zend_Db_Table::getDefaultAdapter()->query('set SQL_MODE = ""'); @@ -429,26 +450,30 @@ class Bokeh_Engine { } - function setupDevOptions() + function setupDevOptions(): self { //permet d'activer les fonctions en développement if (null !== $experimental_dev = $this->_config->get('experimental_dev')) defineConstant('DEVELOPMENT', $experimental_dev); + return $this; } - function setupControllerActionHelper() { + function setupControllerActionHelper(): self + { Zend_Controller_Action_HelperBroker::resetHelpers(); Zend_Controller_Action_HelperBroker::addHelper(new ZendAfi_Controller_Action_Helper_ViewRenderer()); Zend_Controller_Action_HelperBroker::addPrefix('ZendAfi_Controller_Action_Helper'); + return $this; } - function setupHTTPClient() + function setupHTTPClient(): self { - if ( (isset ($this->_config->proxy->host) ) && ($this->_config->proxy->host != '') ){ + if ((isset($this->_config->proxy->host)) && ($this->_config->proxy->host != '')) + { //set up HTTP Client to use proxy settings $proxy_config = [ 'adapter' => 'Zend_Http_Client_Adapter_Proxy', @@ -467,64 +492,71 @@ class Bokeh_Engine { } - function setupMail() + function setupMail(): self { - if (isset($this->_config->mail->transport->file)) { + if (isset($this->_config->mail->transport->file)) + { ZendAfi_Mail::setDefaultTransport(new ZendAfi_Mail_Transport_File($this->_config->mail->transport->file)); + return $this; } - if (isset($this->_config->mail->transport->smtp)) { + if (isset($this->_config->mail->transport->smtp)) + { ZendAfi_Mail::setDefaultTransport(new Zend_Mail_Transport_Smtp($this->_config->mail->transport->smtp->host, $this->_config->mail->transport->smtp->toArray())); + return $this; } if (defined('SMTP_HOST')) ZendAfi_Mail::setDefaultTransport(new Zend_Mail_Transport_Smtp(SMTP_HOST)); + return $this; } - function newFrontController() + function newFrontController(): Zend_Controller_Front { return Zend_Controller_Front::getInstance() ->setDispatcher(new ZendAfi_Controller_Dispatcher_Standard()) ->addModuleDirectory(MODULEDIRECTORY) ->setDefaultModule('opac') - ->registerPlugin(new ZendAfi_Controller_Plugin_SetupDomain()) - ->registerPlugin(new ZendAfi_Controller_Plugin_AdminAuth()) - ->registerPlugin(new ZendAfi_Controller_Plugin_SetupLocale()) - ->registerPlugin(new ZendAfi_Controller_Plugin_DefineURLs()) - ->registerPlugin(new ZendAfi_Controller_Plugin_InitModule()) - ->registerPlugin(new ZendAfi_Controller_Plugin_System()) - ->registerPlugin(new ZendAfi_Controller_Plugin_Popup()) - ->registerPlugin(new ZendAfi_Controller_Plugin_TogetherJS()) - ->registerPlugin(new ZendAfi_Controller_Plugin_Lectura()) - ->registerPlugin(new ZendAfi_Controller_Plugin_InspectorGadget()) - ->registerPlugin(new ZendAfi_Controller_Plugin_CnilConsent()) - ->registerPlugin(new ZendAfi_Controller_Plugin_Redmine()) - ->registerPlugin(new ZendAfi_Controller_Plugin_FeaturesTracking()) - ->registerPlugin(new ZendAfi_Controller_Plugin_LastSearch()) + ->registerPlugin(new ZendAfi_Controller_Plugin_SetupDomain) + ->registerPlugin(new ZendAfi_Controller_Plugin_AdminAuth) + ->registerPlugin(new ZendAfi_Controller_Plugin_SetupLocale) + ->registerPlugin(new ZendAfi_Controller_Plugin_DefineURLs) + ->registerPlugin(new ZendAfi_Controller_Plugin_InitModule) + ->registerPlugin(new ZendAfi_Controller_Plugin_System) + ->registerPlugin(new ZendAfi_Controller_Plugin_Popup) + ->registerPlugin(new ZendAfi_Controller_Plugin_TogetherJS) + ->registerPlugin(new ZendAfi_Controller_Plugin_Lectura) + ->registerPlugin(new ZendAfi_Controller_Plugin_InspectorGadget) + ->registerPlugin(new ZendAfi_Controller_Plugin_CnilConsent) + ->registerPlugin(new ZendAfi_Controller_Plugin_Redmine) + ->registerPlugin(new ZendAfi_Controller_Plugin_FeaturesTracking) + ->registerPlugin(new ZendAfi_Controller_Plugin_LastSearch) ->registerPlugin(new ZendAfi_Controller_Plugin_XHProfile($this->_config)) ->setParam('useDefaultControllerAlways', false); } - function setupFrontController() + function setupFrontController(): self { $this->_front_controller = $this ->newFrontController() ->setBaseURL(BASE_URL); $this->setupRoutes($this->_front_controller, $this->_config); + return $this; } - function setupRoutes($front_controller, $cfg) + function setupRoutes(Zend_Controller_Front $front_controller, $cfg): self { - if ('1' == $cfg->get('enable_rewriting')) { + if ('1' == $cfg->get('enable_rewriting')) + { $front_controller ->setBaseUrl('') ->setRouter(new ZendAfi_Controller_Router_RewriteWithoutBaseUrl()); @@ -535,8 +567,7 @@ class Bokeh_Engine { $front_controller ->getRouter() ->addRoute('embed', - new Zend_Controller_Router_Route( - 'embed/:controller/:action/*', + new Zend_Controller_Router_Route('embed/:controller/:action/*', ['module' => 'telephone', 'controller' => 'index', 'action' => 'index'])) @@ -555,36 +586,54 @@ class Bokeh_Engine { new ZendAfi_Controller_Router_Route_QueryString('admin/file-manager', ['module' => 'admin', 'controller' => 'file-manager'])); + return $this; } - function setupPagination() + function setupPagination(): self { Zend_Paginator::setDefaultScrollingStyle('Sliding'); Zend_View_Helper_PaginationControl::setDefaultViewPartial('pagination.phtml'); + return $this; } - function setupSearch() + function setupSearch(): self { defineConstant('MAX_SEARCH_RESULTS', ''); Class_CriteresRecherche::setMaxSearchResults(MAX_SEARCH_RESULTS); + return $this; } - function setupDigitalResources() + function setupDigitalResources(): self { Class_DigitalResource::getInstance()->bootstrap($this->_front_controller); + return $this; } - function setupCustomFields() + function setupCustomFields(): self { Class_CustomField_Model::registerDefault(); + + return $this; + } + + + protected function _defaultToVolatile(): self + { + if ( ! $this->_for_test) + return $this; + + Storm_Model_Loader::defaultToVolatile(); + + Class_DigitalResource::initFileSystem(); + return $this; } } @@ -592,6 +641,15 @@ class Bokeh_Engine { +class Bokeh_Engine_ForTest extends Bokeh_Engine +{ + + protected bool $_for_test = true; +} + + + + class Bokeh_PhpCommand { @@ -622,8 +680,7 @@ class Bokeh_Session /* for test */ protected static $_cookie_jar; - - public function get($session_id) + public function get(string $session_id): Zend_Session_Namespace { $this->_getCookieJar()->session_set_cookie_params(['httponly' => true, 'secure' => Class_Url::isSecure()]); @@ -642,18 +699,19 @@ class Bokeh_Session /** @category testing */ protected function _getCookieJar() { - return static::$_cookie_jar ? - static::$_cookie_jar + return static::$_cookie_jar + ? static::$_cookie_jar : new Bokeh_Session_CookieJar; } - protected function _isReadAndClose() : bool + protected function _isReadAndClose(): bool { $urls_read_only = ['/newsletter/send-progress', '/noticeajax/']; - try { + try + { require_once 'Zend/Controller/Request/Http.php'; $request = new Zend_Controller_Request_Http; if ( ! ($uri = $request->getRequestUri())) @@ -664,7 +722,8 @@ class Bokeh_Session return true; return false; - } catch (Exception $e) { + } catch (Exception $e) + { return false; } @@ -677,6 +736,7 @@ class Bokeh_Session class Bokeh_Session_CookieJar { + public function session_set_cookie_params(): bool { return call_user_func_array('session_set_cookie_params', func_get_args()); @@ -689,6 +749,14 @@ class Bokeh_Session_CookieJar function setupOpac() { return Bokeh_Engine::getInstance() - ->powerOn() - ->getFrontController(); + ->run(); +} + + + + +function setupTest() +{ + return Bokeh_Engine_ForTest::getInstance() + ->run(); } diff --git a/tests/TearDown.php b/tests/TearDown.php index 4d28fa8d1943570d3b69124523c4acb2b1b9fae0..c3d3e2d7d7e57ab36d3ae7d3e502dd2d32e77afd 100644 --- a/tests/TearDown.php +++ b/tests/TearDown.php @@ -45,6 +45,7 @@ class TearDown { Class_Album::setFileSystem(null); Class_Article_Loader::reset(); + Class_TypeDoc::reset(); Class_Codification::reset(); Class_Codification::resetInstance(); Class_CommSigb::setInstance(null); diff --git a/tests/application/modules/opac/controllers/BlogControllerTest.php b/tests/application/modules/opac/controllers/BlogControllerTest.php index 1b64b77e659aba7c997af2374d580050eca12975..c43834079766cc701ebab9a43ce69e587eeb048a 100644 --- a/tests/application/modules/opac/controllers/BlogControllerTest.php +++ b/tests/application/modules/opac/controllers/BlogControllerTest.php @@ -111,7 +111,6 @@ class BlogControllerHierarchicalTest extends AbstractControllerTestCase { $this->assertSqlEquals(["SELECT `codif_thesaurus`.* FROM `codif_thesaurus` WHERE (`codif_thesaurus`.`code` = 'Catalogue' AND `codif_thesaurus`.`id_thesaurus` LIKE 'CCCC0001%') ORDER BY `codif_thesaurus`.`id_thesaurus` DESC LIMIT 1", "SELECT `codif_thesaurus`.* FROM `codif_thesaurus` WHERE (`codif_thesaurus`.`code` = 'Catalogue' AND `codif_thesaurus`.`id_thesaurus` LIKE 'CCCC00010001%') ORDER BY `codif_thesaurus`.`id_thesaurus` DESC LIMIT 1", "SELECT `codif_thesaurus`.* FROM `codif_thesaurus` WHERE (`codif_thesaurus`.`code` = 'Catalogue' AND `codif_thesaurus`.`id_thesaurus` LIKE 'CCCC00010002%') ORDER BY `codif_thesaurus`.`id_thesaurus` DESC LIMIT 1", - "SELECT `codif_type_doc`.* FROM `codif_type_doc` WHERE (`codif_type_doc`.`type_doc_id` LIKE 'Cvs2%')", "SELECT `avis_notices`.`id` FROM `notices_avis` AS `avis_notices` INNER JOIN `notices` ON `avis_notices`.`clef_oeuvre` = `notices`.`clef_oeuvre` AND MATCH(`notices`.`titres`, `notices`.`auteurs`, `notices`.`editeur`, `notices`.`collection`, `notices`.`matieres`, `notices`.`dewey`, `notices`.`other_terms`, `notices`.`facets`) AGAINST('+F_Zjeuxvideo' IN BOOLEAN MODE) AND `notices`.`type` = 1 WHERE (`avis_notices`.`flags` = 0) ORDER BY `avis_notices`.`date_avis` DESC LIMIT 2", "SELECT `notices_avis`.* FROM `notices_avis` WHERE (`notices_avis`.`id` IN (2, 1)) ORDER BY `notices_avis`.`date_avis` DESC"]); } diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 185b901602c5796de26ac2f5630bec3c354c2243..59b05a265412c0e8b8039b64ae8d068df7a6db56 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -62,7 +62,7 @@ $_SERVER['SERVER_PORT'] = '80'; $_SERVER['REMOTE_ADDR'] = '127.0.0.1'; $_SERVER['HTTP_HOST'] = 'localhost'; -setupOpac(); +setupTest(); Class_ICal_Autoloader::getInstance()->ensureAutoload(); diff --git a/tests/library/Class/Cosmogramme/Integration/PhaseDomainsTest.php b/tests/library/Class/Cosmogramme/Integration/PhaseDomainsTest.php index 5cf3d030051ccb02d662524a943d99f067f4f18d..2ecc3de4f40abd8edd4008c600803efccb9ed2d4 100644 --- a/tests/library/Class/Cosmogramme/Integration/PhaseDomainsTest.php +++ b/tests/library/Class/Cosmogramme/Integration/PhaseDomainsTest.php @@ -212,8 +212,6 @@ class PhaseDomainsCronTest extends PhaseDomainsTestCase { public function allSqlUpdatesShouldBePresent() { $this->assertSqlEquals(["UPDATE `notices` SET `facettes` = CLEAN_SPACES(REGEXP_REPLACE(`facettes`, '\\\\bHCCCC[a-zA-Z0-9]*\\\\b', '')), `facets` = CLEAN_SPACES(REGEXP_REPLACE(`facets`, '\\\\bF_HCCCC[a-zA-Z0-9]*\\\\b', '')) WHERE (`notices`.`type_doc` NOT IN (8, 9, 10) AND `notices`.`type` = 1 AND MATCH(`notices`.`titres`, `notices`.`auteurs`, `notices`.`editeur`, `notices`.`collection`, `notices`.`matieres`, `notices`.`dewey`, `notices`.`other_terms`, `notices`.`facets`) AGAINST('+F_HCCCC*' IN BOOLEAN MODE))", - "SELECT `codif_type_doc`.* FROM `codif_type_doc` WHERE (`codif_type_doc`.`type_doc_id` LIKE 'Cvs2%')", - "UPDATE `notices` SET `facettes` = CONCAT(`facettes`, ' HCCCC0001'), `facets` = CONCAT(`facets`, ' F_HCCCC0001') WHERE (MATCH(`notices`.`titres`, `notices`.`auteurs`, `notices`.`editeur`, `notices`.`collection`, `notices`.`matieres`, `notices`.`dewey`, `notices`.`other_terms`, `notices`.`facets`) AGAINST('+F_T2' IN BOOLEAN MODE) AND `notices`.`type` = 1)", "UPDATE `notices` SET `facettes` = CLEAN_SPACES(REGEXP_REPLACE(`facettes`, '\\\\bQ[a-zA-Z0-9]*\\\\b', '')), `facets` = CLEAN_SPACES(REGEXP_REPLACE(`facets`, '\\\\bF_Q[a-zA-Z0-9]*\\\\b', '')) WHERE (`notices`.`type_doc` NOT IN (8, 9, 10) AND `notices`.`type` = 1 AND MATCH(`notices`.`titres`, `notices`.`auteurs`, `notices`.`editeur`, `notices`.`collection`, `notices`.`matieres`, `notices`.`dewey`, `notices`.`other_terms`, `notices`.`facets`) AGAINST('+F_Q*' IN BOOLEAN MODE))", diff --git a/tests/library/Class/DigitalResourceTest.php b/tests/library/Class/DigitalResourceTest.php index 5bdcad8ac957241218a5c8727b546889c849ac71..9a4c1a3537178b7b71d91aed85968d7e77ac78de 100644 --- a/tests/library/Class/DigitalResourceTest.php +++ b/tests/library/Class/DigitalResourceTest.php @@ -20,114 +20,15 @@ */ -class DigitalResourceTest extends ModelTestCase { - protected - $_storm_default_to_volatile = true, - $_config_provider, - $_digital_ressource, - $_builder; - - - public function setUp() { - parent::setUp(); - Class_DigitalResource::resetInstance(); - $file_system = (new Storm_FileSystem_Volatile()) - ->mkdir(ROOT_PATH . 'library/digital_resources/PirateBayResource'); - - Class_DigitalResource::setFileSystem($file_system); - - $this->_config_provider = $this->mock(); - $this->_builder = $this->mock(); - - $this->_builder - ->whenCalled('newInstance') - ->answers(new Class_Entity()); - - - $this->_digital_resource = Class_DigitalResource::getInstance() - ->setConfigProvider($this->_config_provider) - ->setBuilder($this->_builder); - - $this->_config_provider - ->whenCalled('getName') - ->answers('PirateBayResource') - - ->whenCalled('getAdminVars') - ->answers([]) - - ->whenCalled('getConfig') - ->answers($this->_config_provider); - } - - - public function tearDown() { - Class_DigitalResource::setFileSystem(null); - Class_DigitalResource::resetInstance(); - parent::tearDown(); - } - - - /** @test */ - public function adminVarsShouldBeEmpty() { - $this->assertEmpty($this->_digital_resource->getAdminVars()); - } - - - /** @test */ - public function adminVarsShouldContainsPirateBayResource() { - $this->_config_provider - ->whenCalled('getAdminVars') - ->answers(['harvest_url' => 'une url']); - - $this->assertEquals(['PirateBayResource_harvest_url'], array_keys($this->_digital_resource->getAdminVars())); - } - - - /** @test */ - public function batchesShouldContainsPirateBayResource() { - $this->_config_provider - ->whenCalled('getBatch') - ->answers('harvest') - - ->whenCalled('getOtherBatches') - ->answers(['PirateBayResource_Rainbow' => new Class_Entity]); - - $this->assertEquals(['PirateBayResource_Batch', - 'PirateBayResource_Rainbow'], array_keys($this->_digital_resource->getBatches())); - } - - - /** @test */ - public function servicesShouldContainsPirateBayResource() { - $this->_config_provider - ->whenCalled('getService') - ->answers('service'); - - $this->assertEquals(['PirateBayResource'], array_keys($this->_digital_resource->getServices())); - } - - - /** @test */ - public function modulesMenuShouldContainsPirateBayResource() { - $this->_config_provider - ->whenCalled('getModuleMenu') - ->answers('service'); - - $this->assertEquals(['PirateBayResource'], array_keys($this->_digital_resource->getModulesMenu())); - } -} - - - - -class DigitalResourceSsoUrlTest extends ModelTestCase { +class DigitalResourceSsoUrlTest extends ModelTestCase +{ protected $_sso_url, $_config; - - public function setUp() { + public function setUp() + { parent::setUp(); $no_rights = @@ -171,19 +72,22 @@ class DigitalResourceSsoUrlTest extends ModelTestCase { /** @test */ - public function withNullUserShouldReturnEmptyString() { + public function withNullUserShouldReturnEmptyString() + { $this->assertEquals('', $this->_sso_url->urlFor(null)); } /** @test */ - public function withNoRightsUserShouldReturnEmptyString() { + public function withNoRightsUserShouldReturnEmptyString() + { $this->assertEquals('', $this->_sso_url->urlFor(Class_Users::find(4))); } /** @test */ - public function withNotEnabledConfigShouldReturnEmptyString() { + public function withNotEnabledConfigShouldReturnEmptyString() + { $this->_config ->whenCalled('isEnabled') ->answers(false); @@ -192,7 +96,8 @@ class DigitalResourceSsoUrlTest extends ModelTestCase { /** @test */ - public function withRecordParamShouldReturnEmptyString() { + public function withRecordParamShouldReturnEmptyString() + { $this->_config ->whenCalled('getRecordSsoUrl') ->with(Class_Users::find(5), Class_Notice::find(7)) @@ -203,7 +108,8 @@ class DigitalResourceSsoUrlTest extends ModelTestCase { /** @test */ - public function withAlbumParamShouldReturnEmptyString() { + public function withAlbumParamShouldReturnEmptyString() + { $this->_config ->whenCalled('getAlbumSsoUrl') ->with(Class_Users::find(5), Class_Album::find(9)) @@ -214,7 +120,8 @@ class DigitalResourceSsoUrlTest extends ModelTestCase { /** @test */ - public function withAlbumResourceParamShouldReturnEmptyString() { + public function withAlbumResourceParamShouldReturnEmptyString() + { $this->_config ->whenCalled('getAlbumResourceSsoUrl') ->with(Class_Users::find(5), Class_AlbumRessource::find(11)) @@ -225,7 +132,8 @@ class DigitalResourceSsoUrlTest extends ModelTestCase { /** @test */ - public function withNoParamsShouldReturnEmptyString() { + public function withNoParamsShouldReturnEmptyString() + { $this->_config ->whenCalled('getSsoUrl') ->with(Class_Users::find(5)) @@ -238,27 +146,39 @@ class DigitalResourceSsoUrlTest extends ModelTestCase { -class DigitalResourceConfigServiceUrlTest extends ModelTestCase { - public function setUp() { +class DigitalResourceConfigServiceUrlTest extends ModelTestCase +{ + + public function setUp() + { parent::setUp(); - Class_AdminVar::set('Mangasio_SSO_URL','https://hub.cafeyn.co/abde/mangas'); + + Class_AdminVar::set('Mangasio_SSO_URL', 'https://hub.cafeyn.co/abde/mangas'); + Class_DigitalResource::resetInstance(); + Class_DigitalResource::initFileSystem(); } - public function getUrlAndConfigName (){ + public function getUrlAndConfigName (): array + { return [['https://arte-vod/', 'ArteVod'], ['la-souris-qui-raconte', 'LaSourisQuiRaconte'], ['ma-petite-mediatheque', 'MaPetiteMediatheque'], ['skilleos', 'Skilleos'], - ['https://www.cafeyn.co/fr/externallogin/', 'Cafeyn'], - ['https://hub.cafeyn.co/abde/mangas', 'Mangasio']]; + ['https://www.cafeyn.co/fr/loginexternal', 'Cafeyn'], + ['https://hub.cafeyn.co/abde/mangas', 'Mangasio'] + ]; } - /** @test - * @dataProvider getUrlAndConfigName + /** + * @test + * @dataProvider getUrlAndConfigName */ - public function WithUrlgetServiceUrlForShouldReturnExpectedConfigName($url, $plugin_name) { - $this->assertEquals((new Class_DigitalResource)->getPluginForServiceUrl($url)->getName(),$plugin_name); + public function WithUrlgetServiceUrlForShouldReturnExpectedConfigName(string $url, + string $plugin_name) + { + $this->assertEquals((new Class_DigitalResource)->getPluginForServiceUrl($url)->getName(), + $plugin_name); } } diff --git a/tests/library/Class/Migration/DigitalResource/1DTouchTest.php b/tests/library/Class/Migration/DigitalResource/1DTouchTest.php index af3df91ae824fe6181c6181f79e5c6275999fb7f..ae73114a72f8249cd027877f25c6c244c5394571 100644 --- a/tests/library/Class/Migration/DigitalResource/1DTouchTest.php +++ b/tests/library/Class/Migration/DigitalResource/1DTouchTest.php @@ -30,8 +30,6 @@ abstract class Class_Migration_DigitialResource_1DTouchTestCase extends ModelTes // upgrade domains trigger legacy sql Zend_Registry::set('sql', $this->mock()->whenCalled('query')->answers(true)); - Class_DigitalResource::resetInstance(); - $this->fixture(Class_CosmoVar::class, ['id' => 'types_docs', 'array_as_list' => ['0' => 'non identifié', @@ -70,12 +68,6 @@ abstract class Class_Migration_DigitialResource_1DTouchTestCase extends ModelTes ['id' => '114', 'famille_id' => Class_CodifTypeDoc::SONORE]); } - - - public function tearDown() { - Class_DigitalResource::resetInstance(); - parent::tearDown(); - } } diff --git a/tests/library/Class/Migration/DigitalResource/ArteVodTest.php b/tests/library/Class/Migration/DigitalResource/ArteVodTest.php index c5aa586a6496629c0e328b61b342d233c8a8423b..400f171f52213b0429385a80c47bb4618def9637 100644 --- a/tests/library/Class/Migration/DigitalResource/ArteVodTest.php +++ b/tests/library/Class/Migration/DigitalResource/ArteVodTest.php @@ -21,13 +21,11 @@ class Class_Migration_DigitialResource_ArteVodTest extends ModelTestCase { - protected - $_storm_default_to_volatile = true, - $_migration; + + protected $_migration; public function setUp() { parent::setUp(); - Class_DigitalResource::resetInstance(); $cfg_menus = ['H' => ['libelle' => 'Menu horizontal', 'picto' => 'vide.gif', @@ -100,12 +98,6 @@ class Class_Migration_DigitialResource_ArteVodTest extends ModelTestCase { } - public function tearDown() { - Class_DigitalResource::resetInstance(); - parent::tearDown(); - } - - /** @test */ public function adminVarArtevodLoginShoudBeUpdated() { $this->assertNotNull(Class_AdminVar::findFirstBy(['clef' => 'ArteVod_LOGIN', diff --git a/tests/library/Class/Migration/DigitalResource/CVSTest.php b/tests/library/Class/Migration/DigitalResource/CVSTest.php index 0d0e8ac746a308cd4a92affe59a9d57e0aa252a5..d6e9b4be54b33554762f8a55e99bc664f5530078 100644 --- a/tests/library/Class/Migration/DigitalResource/CVSTest.php +++ b/tests/library/Class/Migration/DigitalResource/CVSTest.php @@ -21,13 +21,11 @@ class Class_Migration_DigitialResource_CVSTest extends ModelTestCase { - protected - $_storm_default_to_volatile = true, - $_migration; + + protected $_migration; public function setUp() { parent::setUp(); - Class_DigitalResource::resetInstance(); $cfg_menus = ['H' => ['libelle' => 'Menu horizontal', 'picto' => 'vide.gif', @@ -93,12 +91,6 @@ class Class_Migration_DigitialResource_CVSTest extends ModelTestCase { } - public function tearDown() { - Class_DigitalResource::resetInstance(); - parent::tearDown(); - } - - /** @test */ public function oldLoginTestAdminVarShouldBeDeleted() { $this->assertNull(Class_AdminVar::get('CVS_LOGINTEST')); diff --git a/tests/library/Class/Migration/DigitalResource/CafeynTest.php b/tests/library/Class/Migration/DigitalResource/CafeynTest.php index ee307f85e0cbfe6a45ef5a846cd7c79370131087..5f060a6195d249ef7029f15e3035723ba706fec4 100644 --- a/tests/library/Class/Migration/DigitalResource/CafeynTest.php +++ b/tests/library/Class/Migration/DigitalResource/CafeynTest.php @@ -21,13 +21,11 @@ class Class_Migration_DigitialResource_CafeynTest extends ModelTestCase { - protected - $_storm_default_to_volatile = true, - $_migration; + + protected $_migration; public function setUp() { parent::setUp(); - Class_DigitalResource::resetInstance(); $cfg_menus = ['H' => ['libelle' => 'Menu horizontal', 'picto' => 'vide.gif', @@ -107,12 +105,6 @@ class Class_Migration_DigitialResource_CafeynTest extends ModelTestCase { } - public function tearDown() { - Class_DigitalResource::resetInstance(); - parent::tearDown(); - } - - /** @test */ public function albumLeKioskShouldBeDeleted() { $this->assertNull(Class_Album::find(10)); diff --git a/tests/library/Class/Migration/DigitalResource/CyberlibrisTest.php b/tests/library/Class/Migration/DigitalResource/CyberlibrisTest.php index 8ecceeef7be70678e07afbbb754481d74c7a3a2e..cf1f48f11287b073744c0785fe001845f9d8343f 100644 --- a/tests/library/Class/Migration/DigitalResource/CyberlibrisTest.php +++ b/tests/library/Class/Migration/DigitalResource/CyberlibrisTest.php @@ -21,9 +21,10 @@ class Class_Migration_DigitalResource_CyberlibrisTest extends ModelTestCase { + public function setUp() { parent::setUp(); - Class_DigitalResource::resetInstance(); + Class_AdminVar::set('CYBERLIBRIS_URL', 'http://bibliovox.com'); Class_AdminVar::set('CYBERLIBRIS_ID', 'myuser'); @@ -48,12 +49,6 @@ class Class_Migration_DigitalResource_CyberlibrisTest extends ModelTestCase { } - public function tearDown() { - Class_DigitalResource::resetInstance(); - parent::tearDown(); - } - - /** @test */ public function updateDocTypeIdShouldBeNumilog() { $this->assertEquals('Cyberlibris', Class_Album::find(456)->getTypeDocId()); diff --git a/tests/library/Class/Migration/DigitalResource/DropCafeynTest.php b/tests/library/Class/Migration/DigitalResource/DropCafeynTest.php index 77d86268eafed32cb76c9beb4e651f5c039d11fb..93fc3e77547c77d5e92065822b9ce243082ded04 100644 --- a/tests/library/Class/Migration/DigitalResource/DropCafeynTest.php +++ b/tests/library/Class/Migration/DigitalResource/DropCafeynTest.php @@ -21,9 +21,9 @@ class DropCafeyn_NotEnabledTest extends ModelTestCase { + public function setUp() { parent::setUp(); - Class_DigitalResource::resetInstance(); $this->fixture(Class_Album::class, ['id' => 12, @@ -47,9 +47,9 @@ class DropCafeyn_NotEnabledTest extends ModelTestCase { class DropCafeyn_EnabledTest extends ModelTestCase { + public function setUp() { parent::setUp(); - Class_DigitalResource::resetInstance(); $album = $this ->fixture(Class_Album::class, diff --git a/tests/library/Class/Migration/DigitalResource/LeKioskTest.php b/tests/library/Class/Migration/DigitalResource/LeKioskTest.php index 15282cb5e2bca482d79102c6375a97ad7a61a57d..8bf8a7dff50aa772a26786d9b2508f38e7aa0893 100644 --- a/tests/library/Class/Migration/DigitalResource/LeKioskTest.php +++ b/tests/library/Class/Migration/DigitalResource/LeKioskTest.php @@ -21,13 +21,11 @@ class Class_Migration_DigitialResource_LeKioskTest extends ModelTestCase { - protected - $_storm_default_to_volatile = true, - $_migration; + + protected $_migration; public function setUp() { parent::setUp(); - Class_DigitalResource::resetInstance(); $cfg_menus = ['H' => ['libelle' => 'Menu horizontal', 'picto' => 'vide.gif', @@ -99,12 +97,6 @@ class Class_Migration_DigitialResource_LeKioskTest extends ModelTestCase { } - public function tearDown() { - Class_DigitalResource::resetInstance(); - parent::tearDown(); - } - - /** @test */ public function adminVarLeKioskIdShoudBeUpdated() { $this->assertNotNull(Class_AdminVar::findFirstBy(['clef' => 'Cafeyn_ID', diff --git a/tests/library/Class/Migration/DigitalResource/MusicMeTest.php b/tests/library/Class/Migration/DigitalResource/MusicMeTest.php index 8871a267c94f94c3315e57eb17c2947f555f80cd..33f4d3a280e1564ef6f708b690aa580808052725 100644 --- a/tests/library/Class/Migration/DigitalResource/MusicMeTest.php +++ b/tests/library/Class/Migration/DigitalResource/MusicMeTest.php @@ -21,13 +21,11 @@ class Class_Migration_DigitialResource_MusicmeTest extends ModelTestCase { - protected - $_storm_default_to_volatile = true, - $_migration; + + protected $_migration; public function setUp() { parent::setUp(); - Class_DigitalResource::resetInstance(); $cfg_menus = ['H' => ['libelle' => 'Menu horizontal', 'picto' => 'vide.gif', @@ -99,12 +97,6 @@ class Class_Migration_DigitialResource_MusicmeTest extends ModelTestCase { } - public function tearDown() { - Class_DigitalResource::resetInstance(); - parent::tearDown(); - } - - /** @test */ public function adminVarMusicmeUrlShoudBeUpdated() { $this->assertNotNull(Class_AdminVar::findFirstBy(['clef' => 'Musicme_URL', diff --git a/tests/library/Class/Migration/DigitalResource/NumilogTest.php b/tests/library/Class/Migration/DigitalResource/NumilogTest.php index de5fa0b645dd1157303807fba7b343427319edc9..80232d1699127f59d4074538dea0165e020f18af 100644 --- a/tests/library/Class/Migration/DigitalResource/NumilogTest.php +++ b/tests/library/Class/Migration/DigitalResource/NumilogTest.php @@ -25,8 +25,6 @@ class Class_Migration_DigitialResource_NumilogTest extends ModelTestCase { public function setUp() { parent::setUp(); - Class_DigitalResource::resetInstance(); - $cfg_menus = ['H' => ['libelle' => 'Menu horizontal', 'picto' => 'vide.gif', @@ -121,12 +119,6 @@ class Class_Migration_DigitialResource_NumilogTest extends ModelTestCase { } - public function tearDown() { - Class_DigitalResource::resetInstance(); - parent::tearDown(); - } - - /** @test */ public function updateDocTypeIdShouldBeNumilog() { $this->assertEquals('Numilog', Class_Album::find(456)->getTypeDocId()); diff --git a/tests/library/Class/Migration/DigitalResource/ToutApprendreTest.php b/tests/library/Class/Migration/DigitalResource/ToutApprendreTest.php index 28b077cfae71c0b762f5b14f5cc91b1043d065fb..ce03dbca2d1e99597bc8a2b76a168080eacd6575 100644 --- a/tests/library/Class/Migration/DigitalResource/ToutApprendreTest.php +++ b/tests/library/Class/Migration/DigitalResource/ToutApprendreTest.php @@ -21,15 +21,12 @@ class Class_Migration_DigitialResource_ToutApprendreTest extends ModelTestCase { - protected - $_storm_default_to_volatile = true, - $_migration; + + protected $_migration; public function setUp() { parent::setUp(); - Class_DigitalResource::resetInstance(); - $cfg_menus = ['H' => ['libelle' => 'Menu horizontal', 'picto' => 'vide.gif', 'menus' => [ @@ -130,12 +127,6 @@ class Class_Migration_DigitialResource_ToutApprendreTest extends ModelTestCase { } - public function tearDown() { - Class_DigitalResource::resetInstance(); - parent::tearDown(); - } - - /** @test */ public function updateMeDocTypeIdShouldBeToutApprendre() { $this->assertEquals('ToutApprendre', Class_Album::find(456)->getTypeDocId()); diff --git a/tests/phpunit.xml b/tests/phpunit.xml index 2a3703effdae3174b80e12548a7fcf3e94384530..11cee001ee38dbfe9a7c6fd6e9caf20a82e71c78 100644 --- a/tests/phpunit.xml +++ b/tests/phpunit.xml @@ -13,7 +13,6 @@ <directory>./application/</directory> <directory>./library/</directory> <directory>../library/digital_resources/</directory> - <directory>./db/</directory> <directory>./eco/</directory> <directory>./scenarios/</directory> <directory>../library/storm/tests/Storm/</directory> diff --git a/tests/scenarios/AlbumAudioRecord/AlbumAudioRecordTest.php b/tests/scenarios/AlbumAudioRecord/AlbumAudioRecordTest.php index 01966e9164d0040f45c5e7024d5563fd3b7dfce2..c73b01dc54773751852b0c2aed3c7d5898096483 100644 --- a/tests/scenarios/AlbumAudioRecord/AlbumAudioRecordTest.php +++ b/tests/scenarios/AlbumAudioRecord/AlbumAudioRecordTest.php @@ -21,11 +21,12 @@ abstract class AlbumAudioRecordTestCase extends AbstractControllerTestCase { + + protected bool $_storm_mock_zend_adapter = true; protected $_notice, $_tracks; - public function setUp() { parent::setUp(); @@ -109,6 +110,7 @@ abstract class AlbumAudioRecordTestCase extends AbstractControllerTestCase { class AlbumAudioRecordViewNoticeTest extends AlbumAudioRecordTestCase { + public function setUp() { parent::setUp(); @@ -168,8 +170,7 @@ class AlbumAudioRecordViewNoticeTest extends AlbumAudioRecordTestCase { /** @test */ public function titrePrincipalShouldBeSeventhSonOfASeventhSon() { $this->assertXPathContentContains('//h1', - 'Seventh Son of a Seventh Son', - $this->_response->getBody()); + 'Seventh Son of a Seventh Son'); } @@ -257,8 +258,10 @@ class AlbumAudioRecordViewNoticeTest extends AlbumAudioRecordTestCase { class AlbumAudioRecordViewMorceauxTest extends AlbumAudioRecordTestCase { + public function setUp() { parent::setUp(); + $this->dispatch('/opac/noticeajax/morceaux/id_notice/' . $this->_notice->getId()); } @@ -294,34 +297,39 @@ class AlbumAudioRecordViewMorceauxTest extends AlbumAudioRecordTestCase { class AlbumAudioRecordViewDetailsTest extends AlbumAudioRecordTestCase { + public function setUp() { parent::setUp(); + Class_AdminVar::set('AUTHOR_PAGE', 0); - $this->dispatch('/opac/noticeajax/detail/id_notice/'.$this->_notice->getId(), true); + + $this->dispatch('/opac/noticeajax/detail/id_notice/' . $this->_notice->getId()); } + /** @test */ public function titresShouldContainsMoonchild() { $this->assertXPathContentContains('//dd[@class="first"]//div', 'Moonchild'); } + /** @test */ public function titresShouldContainsIronMaidenAsCodeRebond() { $this->assertXPathContentContains('//dd//a[contains(@href, "code_rebond/A1")]', 'Iron Maiden'); } + /** @test */ public function noUrlShouldBePresent() { - $this->assertNotXPath('//dt[contains(@class, "internet")]', $this->_response->getBody()); + $this->assertNotXPath('//dt[contains(@class, "internet")]'); } /** @test */ public function distributorShouldBeGeffenRecords() { $this->assertXPathContentContains('//dl//dd', - 'Geffen Records', - $this->_response->getBody()); + 'Geffen Records'); } @@ -334,8 +342,7 @@ class AlbumAudioRecordViewDetailsTest extends AlbumAudioRecordTestCase { /** @test */ public function aDDForAuthorsShouldContainsBruceDickinsonAsChanteur() { $this->assertXPathContentContains('//dl//dd//a', - 'Bruce Dickinson (Chanteur)', - $this->_response->getBody()); + 'Bruce Dickinson (Chanteur)'); } } @@ -345,7 +352,7 @@ class AlbumAudioRecordViewDetailsTest extends AlbumAudioRecordTestCase { class AlbumAudioRecordViewRessourcesNumeriquesTest extends AlbumAudioRecordTestCase { public function setUp() { parent::setUp(); - $this->dispatch('/opac/noticeajax/resnumeriques/id_notice/'.$this->_notice->getId(), true); + $this->dispatch('/opac/noticeajax/resnumeriques/id_notice/'.$this->_notice->getId()); } @@ -369,7 +376,7 @@ class AlbumAudioRecordViewRessourcesNumeriquesTest extends AlbumAudioRecordTestC /** @test */ public function moonchildTrackShouldBePresent() { - $this->assertXPath('//ol//li//a[contains(@data-src, "/bib-numerique/play-ressource/id/1.mp3")]', $this->_response->getBody()); + $this->assertXPath('//ol//li//a[contains(@data-src, "/bib-numerique/play-ressource/id/1.mp3")]'); } @@ -411,13 +418,13 @@ class AlbumAudioRecordViewRessourceInTelephoneModeTest extends AlbumAudioRecordT public function setup() { parent::setup(); Class_Profil::getCurrentProfil()->beTelephone(); - $this->dispatch('/opac/recherche/viewnotice/id/1', true); + $this->dispatch('/opac/recherche/viewnotice/id/1'); } /** @test */ public function pageShouldContainsLinkToOpenRessourcesNumeriques() { - $this->assertXPathContentContains('//a[contains(@href,"recherche/ressourcesnumeriques/id/1")]', 'Accéder à l\'album',$this->_response->getBody()); + $this->assertXPathContentContains('//a[contains(@href,"recherche/ressourcesnumeriques/id/1")]', 'Accéder à l\'album'); } } @@ -427,13 +434,13 @@ class AlbumAudioRecordAsTelephoneViewRessourcesNumeriquesTest extends AlbumAudio public function setUp() { parent::setUp(); Class_Profil::getCurrentProfil()->beTelephone(); - $this->dispatch('/recherche/ressourcesnumeriques/id/1', true); + $this->dispatch('/recherche/ressourcesnumeriques/id/1'); } /** @test */ public function moonchildPlayerShouldBePresent() { - $this->assertXPath('//ol//li//a[contains(@data-src, "/bib-numerique/play-ressource/id/1.mp3")]', $this->_response->getBody()); + $this->assertXPath('//ol//li//a[contains(@data-src, "/bib-numerique/play-ressource/id/1.mp3")]'); } @@ -467,5 +474,3 @@ class AlbumAudioRecordNotVisibleTest extends AlbumAudioRecordTestCase { $this->assertEmpty(Class_Notice::findAll()); } } - -?> diff --git a/tests/scenarios/ArticlesMultipleTimings/ArticlesMultipleTimingsAdminTest.php b/tests/scenarios/ArticlesMultipleTimings/ArticlesMultipleTimingsAdminTest.php index 80bb7be2f089377587c74b5e15d3ef0b861e2c9e..82831516a57ab3551434759642862d64e28ce7fa 100644 --- a/tests/scenarios/ArticlesMultipleTimings/ArticlesMultipleTimingsAdminTest.php +++ b/tests/scenarios/ArticlesMultipleTimings/ArticlesMultipleTimingsAdminTest.php @@ -22,8 +22,11 @@ class ArticlesMultipleTimingsAdminVarTest extends Admin_AbstractControllerTestCase { + protected bool $_storm_mock_zend_adapter = true; + public function setUp() { parent::setUp(); + $this->dispatch('/admin/index/adminvar'); } @@ -41,8 +44,11 @@ class ArticlesMultipleTimingsAdminVarTest extends Admin_AbstractControllerTestCa class ArticlesMultipleTimingsAdminActivationCmsControllerTest extends Admin_AbstractControllerTestCase { + protected bool $_storm_mock_zend_adapter = true; + public function setUp() { parent::setUp(); + $this->fixture(Class_Article::class, ['id' => 2, 'titre' => 'Heure du conte', @@ -73,8 +79,11 @@ class ArticlesMultipleTimingsAdminActivationCmsControllerTest abstract class ArticlesMultipleTimingsAdminTestCase extends Admin_AbstractControllerTestCase { + protected bool $_storm_mock_zend_adapter = true; + public function setUp() { parent::setUp(); + $this->fixture(Class_Article::class, ['id' => 2, 'titre' => 'Heure du conte', @@ -102,6 +111,7 @@ class ArticlesMultipleTimingsAdminCmsControllerEventTimingIndexArticleNotFoundTe public function setUp() { parent::setUp(); + $this->dispatch('/admin/cms/event-timings/article_id/666'); } @@ -120,6 +130,7 @@ class ArticlesMultipleTimingsAdminCmsControllerEventTimingIndexTest public function setUp() { parent::setUp(); + $this->dispatch('/admin/cms/event-timings/article_id/2'); } @@ -190,6 +201,7 @@ class ArticlesMultipleTimingsAdminDeleteTest extends ArticlesMultipleTimingsAdmi public function setUp() { parent::setUp(); + $this->dispatch('/admin/cms/event-timing-delete/id/1'); } @@ -220,6 +232,7 @@ class ArticlesMultipleTimingsAdminCmsDeleteArticleTest public function setUp() { parent::setUp(); + $this->dispatch('/admin/cms/force-delete/id/2'); } @@ -230,7 +243,7 @@ class ArticlesMultipleTimingsAdminCmsDeleteArticleTest } - /** @test */ + /** @test */ public function articleTwoShouldBeDeleted() { $this->assertEmpty(Class_Article::find(2)); } @@ -244,6 +257,7 @@ class ArticlesMultipleTimingsAdminEditTest extends ArticlesMultipleTimingsAdminT public function setUp() { parent::setUp(); + $this->dispatch('/admin/cms/event-timing-edit/id/1'); } @@ -268,7 +282,7 @@ class ArticlesMultipleTimingsAdminEditTest extends ArticlesMultipleTimingsAdminT /** @test */ public function editFormShouldContainsActionToEventTimingEdit() { - $this->assertXPath('//form[contains(@action,"event-timing-edit")]',$this->_response->getBody()); + $this->assertXPath('//form[contains(@action,"event-timing-edit")]'); } } @@ -280,6 +294,7 @@ class ArticlesMultipleTimingsAdminEditWithWrongIdTest public function setUp() { parent::setup(); + $this->dispatch('/admin/cms/event-timing-edit/id/42'); } @@ -299,6 +314,7 @@ class ArticlesMultipleTimingsAdminEditWithParamsTest extends ArticlesMultipleTim public function setUp() { parent::setup(); + $this->postDispatch('/admin/cms/event-timing-edit/id/1', ['start' => '07/07/2021 11:00', 'end' => '07/07/2021 12:00']); @@ -345,6 +361,7 @@ class ArticlesMultipleTimingsAdminAddDispatchTest public function setUp() { parent::setup(); + $this->dispatch('/admin/cms/event-timing-add/article_id/2'); } @@ -378,9 +395,11 @@ class ArticlesMultipleTimingsAdminAddPostDispatchTest public function setUp() { parent::setup(); + $this->postDispatch('/admin/cms/event-timing-add/article_id/2', ['start' => '21/07/2021 10:00', 'end' => '21/07/2021 11:00']); + $this->_event_time = Class_Article_EventTiming::find(3); } @@ -424,6 +443,7 @@ class ArticlesMultipleTimingsAdminAddPostDispatchWithEndBeforeStartTest public function setUp() { parent::setup(); + $this->postDispatch('/admin/cms/event-timing-add/article_id/2', ['start' => '22/07/2021 10:00', 'end' => '21/07/2021 11:00']); @@ -432,7 +452,7 @@ class ArticlesMultipleTimingsAdminAddPostDispatchWithEndBeforeStartTest /** @test */ public function contextShouldExpectation() { - $this->assertXPathContentContains('//ul[@class="errors"]/li','La date de début doit être antérieure à la date de fin',$this->_response->getBody()); + $this->assertXPathContentContains('//ul[@class="errors"]/li','La date de début doit être antérieure à la date de fin'); } } @@ -444,6 +464,7 @@ class ArticlesMultipleTimingsAdminAddPostDispatchWithSingleDateTest public function setUp() { parent::setup(); + $this->postDispatch('/admin/cms/event-timing-add/article_id/2', ['start' => '22/07/2021 10:00']); } @@ -463,6 +484,7 @@ class ArticlesEventTimingAddPostDispatchWithWrongFormatDateTest public function setUp() { parent::setup(); + $this->postDispatch('/admin/cms/event-timing-add/article_id/2', ['start' => 'test']); } @@ -482,6 +504,7 @@ class ArticlesMultipleTimingsAdminCmsEditEventTimingAsRedacteurTest public function setUp() { parent::setUp(); + $this->fixture(Class_Bib::class, ['id' => 1, 'libelle' => 'Spirou' ]); @@ -512,9 +535,9 @@ class ArticlesMultipleTimingsAdminCmsEditEventTimingAsRedacteurTest 'id_site' => 1]); $this->fixture(Class_Permission::class, - ['id' => 666, - 'code' => 'ARTICLE', - 'module' => 'ARTICLE']); + ['id' => 666, + 'code' => 'ARTICLE', + 'module' => 'ARTICLE']); Class_Permission::createArticle()->permitTo($redacteur_group, $article_categorie); ZendAfi_Auth::getInstance()->logUser($redacteur); diff --git a/tests/scenarios/DynamicFacetOnDomains/DynamicFacetOnDomainsPhaseTest.php b/tests/scenarios/DynamicFacetOnDomains/DynamicFacetOnDomainsPhaseTest.php index ad93a777f7d7f23064414c904cdd5f5ac10b2204..02a5b3878677ad8c3c957a6b328a0cfa1df2fe13 100644 --- a/tests/scenarios/DynamicFacetOnDomains/DynamicFacetOnDomainsPhaseTest.php +++ b/tests/scenarios/DynamicFacetOnDomains/DynamicFacetOnDomainsPhaseTest.php @@ -176,8 +176,6 @@ class DynamicFacetOnDomainsPhaseEnabledTest extends DynamicFacetOnDomainsPhaseTe "SELECT `codif_matiere`.* FROM `codif_matiere` WHERE (`codif_matiere`.`libelle` LIKE 'Animaux de la ferme : %')", - "SELECT `codif_type_doc`.* FROM `codif_type_doc` WHERE (`codif_type_doc`.`type_doc_id` LIKE 'Cvs2%')", - "UPDATE `notices` SET `facettes` = CONCAT(`facettes`, ' HANIM0001'), `facets` = CONCAT(`facets`, ' F_HANIM0001') WHERE (MATCH(`notices`.`titres`, `notices`.`auteurs`, `notices`.`editeur`, `notices`.`collection`, `notices`.`matieres`, `notices`.`dewey`, `notices`.`other_terms`, `notices`.`facets`) AGAINST('+F_M1' IN BOOLEAN MODE) AND `notices`.`type` = 1)", "SELECT `codif_matiere`.* FROM `codif_matiere` WHERE (`codif_matiere`.`libelle` LIKE 'Animaux de compagnie : %')", diff --git a/tests/scenarios/Templates/MyBibAppTemplateTest.php b/tests/scenarios/Templates/MyBibAppTemplateTest.php index f7a7a6db58f013289ca1fecfb68a17a97de02af3..ef917c6a1726ce04fb8d8e869293a98369a0f786 100644 --- a/tests/scenarios/Templates/MyBibAppTemplateTest.php +++ b/tests/scenarios/Templates/MyBibAppTemplateTest.php @@ -567,8 +567,7 @@ class MyBibAppTemplateNoveltyDomainTest extends MyBibAppTemplateTestCase { Class_Catalogue::getRequetes(['id_catalogue' => $domain->getId()])['req_liste']() ->fetchAll(); - $this->assertSqlEquals(["SELECT `codif_type_doc`.* FROM `codif_type_doc` WHERE (`codif_type_doc`.`type_doc_id` LIKE 'Cvs2%')", - "SELECT DISTINCT `notices`.`type_doc` FROM `notices`", + $this->assertSqlEquals(["SELECT DISTINCT `notices`.`type_doc` FROM `notices`", "SELECT `notices`.* FROM `notices` WHERE (`notices`.`date_creation` >= '2023-04-24' AND `notices`.`type` = 1) ORDER BY `notices`.`alpha_titre` ASC LIMIT 5000"]); } diff --git a/tests/scenarios/Templates/TemplatesAvailabilityTest.php b/tests/scenarios/Templates/TemplatesAvailabilityTest.php index 407da88f276820aa9ccace0546269f079ec7d145..f33d9ea69da1983e0ac75f80d7f4be043bfd9b09 100644 --- a/tests/scenarios/Templates/TemplatesAvailabilityTest.php +++ b/tests/scenarios/Templates/TemplatesAvailabilityTest.php @@ -47,6 +47,14 @@ abstract class TemplatesAvailabilityTestCase extends AbstractControllerTestCase ['id' => 0, 'label' => 'Non identifié']); + $this->fixture(Class_TypeDoc::class, + ['id' => 1, + 'label' => 'Livre']); + + $this->fixture(Class_TypeDoc::class, + ['id' => 101, + 'label' => 'Numérique']); + $this->fixture(Class_Notice::class, ['id' => 3, 'type_doc' => 0]); @@ -184,7 +192,7 @@ class TemplatesAvailabilityWithRelevanceTest extends TemplatesAvailabilityTestCa public function withRecordIdTenAndBookmarkedLibrariesReadyShouldRenderAvailableInMyLibraryBadge() { Class_AdminVar::set('ENABLE_BOOKMARKABLE_LIBRARIES', 1); $this->dispatch('noticeajax/availability/id/10'); - $this->assertXPathContentContains('//span[@class="badge_tag badge_record_availability record_id_10 doctype_id_1 record_available text-left badge badge-success"]', utf8_encode('Disponible à Gland')); + $this->assertXPathContentContains('//span[@class="badge_tag badge_record_availability record_id_10 doctype_id_1 record_available text-left badge badge-success"]', Class_CharSet::fromISOtoUTF8('Disponible à Gland')); } diff --git a/tests/scenarios/Templates/TemplatesMediaTest.php b/tests/scenarios/Templates/TemplatesMediaTest.php index d68e79efdc575282dd3e0c1e19e5d14436931cb6..fa4013389f0020ffc66147fc698dee75ffd87810 100644 --- a/tests/scenarios/Templates/TemplatesMediaTest.php +++ b/tests/scenarios/Templates/TemplatesMediaTest.php @@ -266,10 +266,21 @@ class TemplatesMediaRecordWithCVSTracksTest extends TemplatesMediaTestCase { -class TemplatesMediaChiliNoticeajaxRecordWithBaseTracksTest extends TemplatesMediaTestCase { - public function setUp() { +class TemplatesMediaChiliNoticeajaxRecordWithBaseTracksTest extends TemplatesMediaTestCase +{ + + public function setUp() + { parent::setUp(); + $this->fixture(Class_TypeDoc::class, + ['id' => 3, + 'label' => 'Sonore']); + + $this->fixture(Class_CodifTypeDoc::class, + ['id' => 3, + 'famille_id' => Class_CodifTypeDoc::SONORE]); + $unimarc = (new Class_NoticeUnimarc_Fluent) ->zoneWithContent('001', '12345') ->zoneWithChildren('200', ['f' => 'Loow']) diff --git a/tests/scenarios/Templates/TemplatesWidgetTest.php b/tests/scenarios/Templates/TemplatesWidgetTest.php index 4ab474b4a4cd044698bab5410214e38a0a9f16ac..77a92d164f530d4edd6c8da89ecc692eef955795 100644 --- a/tests/scenarios/Templates/TemplatesWidgetTest.php +++ b/tests/scenarios/Templates/TemplatesWidgetTest.php @@ -664,12 +664,6 @@ class TemplatesWidgetSearchDefaultStyleTest extends TemplatesIntonationTestCase } - public function tearDown() { - Class_TypeDoc::reset(); - parent::tearDown(); - } - - /** @test */ public function searchWidgetShouldBeDefaultForm() { $this->assertXPath('//div[contains(@class,"boite rech_simple")]//form'); diff --git a/tests/db/UpgradeDBTest.php b/tests_db/UpgradeDBTest.php similarity index 98% rename from tests/db/UpgradeDBTest.php rename to tests_db/UpgradeDBTest.php index 054eec723a46831474a5c1b766cfd4e80b9f640c..38c105e3d56d3f3d4d2c0a255f4fcdcd459598c1 100644 --- a/tests/db/UpgradeDBTest.php +++ b/tests_db/UpgradeDBTest.php @@ -19,76 +19,94 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ -abstract class UpgradeDBTestCase extends PHPUnit_Framework_TestCase { + +abstract class UpgradeDBTestCase extends PHPUnit_Framework_TestCase +{ + abstract public function prepare(); - public function setUp() { + public function setUp() + { $patch_level = Class_CosmoVar::getValueOf('patch_level'); $this->_movePatchLevelTo(min($patch_level, $this->_getPatchLevel() - 1)); $this->prepare(); - $migrator = (new Class_Migration_ScriptPatchs()); + $migrator = (new Class_Migration_ScriptPatchs); $migrator->setEchoFunction(fn() => null); $migrator->runTo($this->_getPatchLevel()); } - public function query($query, $bind=[]) { + public function query($query, $bind = []) + { return Zend_Db_Table::getDefaultAdapter()->query($query, $bind); } - public function silentQuery($query, $bind=[]) { - try { + public function silentQuery($query, $bind = []) + { + try + { $this->query($query, $bind); - } catch(Exception $e) {} + } catch(Exception $e) + {} return $this; } - public function lastInsertId() { + public function lastInsertId() + { return Zend_Db_Table::getDefaultAdapter()->lastInsertId(); } - public function _movePatchLevelTo($patch_level) { + public function _movePatchLevelTo($patch_level) + { Class_CosmoVar::setValueOf('patch_level', $patch_level); $this->query('delete from patch_hash'); } - public function _runAllPrepares() { - foreach($this->_getSubclasses() as $subclass) { - $test_object = new $subclass(); + public function _runAllPrepares() + { + foreach($this->_getSubclasses() as $subclass) + { + $test_object = new $subclass; if ($test_object->getPatchLevel() >= $this->getPatchLevel()) $test_object->prepare(); } } - protected function _getPatchLevel() { + protected function _getPatchLevel() + { preg_match('/UpgradeDB_([0-9]+)_Test/', get_class($this), $matches); + return $matches[1]; } - protected function _getSubclasses() { - $result = array(); - foreach (get_declared_classes() as $class) { + protected function _getSubclasses() + { + $result = []; + + foreach (get_declared_classes() as $class) if (is_subclass_of($class, __CLASS__)) $result[] = $class; - } return $result; } - protected function assertTable($table, $message='') { - try { + protected function assertTable($table, $message = '') + { + try + { $this->query('show create table ' . $table); - } catch(Exception $e) { + } catch(Exception $e) + { $message = $message ? $message : sprintf('Failed asserting that "%s" table EXISTS', @@ -99,11 +117,14 @@ abstract class UpgradeDBTestCase extends PHPUnit_Framework_TestCase { } - protected function assertColumn($table, $column, $message='') { - try { + protected function assertColumn($table, $column, $message = '') + { + try + { $this->query(sprintf('select `%s` from `%s` limit 1', $column, $table)); - } catch (Exception $e) { + } catch (Exception $e) + { $message = $message ? $message : sprintf('Failed asserting that "%s" table CONTAINS a "%s" column.', @@ -114,15 +135,17 @@ abstract class UpgradeDBTestCase extends PHPUnit_Framework_TestCase { } - protected function assertNotColumn($table, $column, $message='') { - try { + protected function assertNotColumn($table, $column, $message='') + { + try + { $this->query(sprintf('select `%s` from `%s` limit 1', $column, $table)); - } catch (Exception $e) { + } catch (Exception $e) + { return true; } - $message = $message ? $message : sprintf('Failed asserting that "%s" table does NOT contains column "%s".', @@ -132,16 +155,21 @@ abstract class UpgradeDBTestCase extends PHPUnit_Framework_TestCase { } - protected function assertIndex($table, $name, $type='BTREE', $message='') { + protected function assertIndex($table, $name, $type = 'BTREE', $message = '') + { $keys = []; - try { - foreach($this->query(sprintf('show keys in `%s`', $table))->fetchAll() as $row) { + + try + { + foreach ($this->query(sprintf('show keys in `%s`', $table))->fetchAll() as $row) + { if ($name == $row['Key_name'] && $type == $row['Index_type']) return true; $keys[] = $row; } - } catch (Exception $e) {} + } catch (Exception $e) + {} $message = $message ? $message @@ -153,16 +181,20 @@ abstract class UpgradeDBTestCase extends PHPUnit_Framework_TestCase { } - protected function assertPrimary($table, $name) { + protected function assertPrimary($table, $name) + { $keys = []; - try { - foreach($this->query(sprintf('show keys in `%s` where Key_name="PRIMARY"', $table))->fetchAll() as $row) { + + try + { + foreach ($this->query(sprintf('show keys in `%s` where Key_name="PRIMARY"', $table))->fetchAll() as $row) { if ($name == $row['Column_name']) return true; $keys[] = $row; } - } catch (Exception $e) {} + } catch (Exception $e) + {} $message = sprintf('Failed asserting that "%s" table CONTAINS a PRIMARY on column "%s".', $table, $name) @@ -172,18 +204,20 @@ abstract class UpgradeDBTestCase extends PHPUnit_Framework_TestCase { } - protected function assertNotIndex($table, $name, $message = '') { + protected function assertNotIndex($table, $name, $message = '') + { $message = $message ? $message : sprintf('Failed asserting that "%s" table NOT CONTAINS index "%s" .', $table, $name); - try { - foreach($this->query(sprintf('show keys in `%s`', $table))->fetchAll() as $row) { + try + { + foreach($this->query(sprintf('show keys in `%s`', $table))->fetchAll() as $row) if ($name == $row['Key_name']) - throw new Exception(); - } - } catch (Exception $e) { + throw new Exception; + } catch (Exception $e) + { $this->fail($message); } @@ -191,42 +225,49 @@ abstract class UpgradeDBTestCase extends PHPUnit_Framework_TestCase { } - protected function assertFieldType($table, $name, $type, $message='') { + protected function assertFieldType($table, $name, $type, $message = '') + { return $this->assertField($table, $name, $type, 'Type', $message); } - protected function assertFieldNullable($table, $column, $message='') { + protected function assertFieldNullable($table, $column, $message = '') + { return $this->assertField($table, $column, 'YES', 'Null', $message); } - protected function assertFieldNotNullable($table, $column, $message='') { + protected function assertFieldNotNullable($table, $column, $message = '') + { return $this->assertField($table, $column, 'NO', 'Null', $message); } - protected function assertFieldDefault($table, $column, $default, $message='') { + protected function assertFieldDefault($table, $column, $default, $message = '') + { return $this->assertField($table, $column, $default, 'Default', $message); } - - protected function assertField($table, $column, $expected, $field, $message = '') { + protected function assertField($table, $column, $expected, $field, $message = '') + { $fields = []; - try { + + try + { foreach($this->query(sprintf('show fields from `%s` where field=\'%s\'', - $table, $column))->fetchAll() as $row - ) { + $table, $column))->fetchAll() as $row) + { $fields[] = $row; if ($expected == $row[$field]) return true; } - } catch (Exception $e) { + } catch (Exception $e) + { echo $e; } - if (!$message) + if ( ! $message) $message = sprintf("Failed asserting that TABLE %s contains COLUMN %s with field %s = %s\n\n%s", $table, $column, $field, $expected, json_encode($fields, JSON_PRETTY_PRINT)); @@ -234,38 +275,44 @@ abstract class UpgradeDBTestCase extends PHPUnit_Framework_TestCase { } - protected function dropTable($name) { + protected function dropTable($name) + { return $this->silentQuery('DROP TABLE `' . $name . '`'); } - protected function dropFieldFrom($table, $field) { + protected function dropFieldFrom($table, $field) + { return $this->silentQuery(sprintf('alter table %s drop column %s', $table, $field)); } - protected function dropFieldsFrom($table, $fields) { - foreach($fields as $field) + protected function dropFieldsFrom($table, $fields) + { + foreach ($fields as $field) $this->dropFieldFrom($table, $field); return $this; } - protected function dropIndexedFieldFrom($table, $field) { + protected function dropIndexedFieldFrom($table, $field) + { return $this->silentQuery('ALTER TABLE ' . $table . ' ' . 'DROP KEY ' . $field . ', ' . 'DROP COLUMN ' . $field); } - protected function dropIndexFrom($table, $field) { + protected function dropIndexFrom($table, $field) + { return $this->silentQuery('ALTER TABLE ' . $table . ' DROP KEY ' . $field); } - protected function getCharacterSet($table, $field) { + protected function getCharacterSet($table, $field) + { $schemaname = Zend_Db_Table::getDefaultAdapter()->getConfig()['dbname']; return $this->query("SELECT character_set_name FROM information_schema.`COLUMNS` @@ -1741,7 +1788,7 @@ class UpgradeDB_335_Test extends UpgradeDBTestCase { } catch(Exception $e) {} foreach([ 'MOISSONAGE_JAMENDO', - Class_Batch_PanierUser::TYPE] + Class_Batch_PanierUser::TYPE] as $type) if (!$this->fetchBatchByType($type)) $this->query('insert into batchs (type, last_run) values("' . $type . '", "")'); @@ -3812,7 +3859,7 @@ class UpgradeDB_408_Test extends UpgradeDBTestCase { /** @test */ public function tableVariablesShouldHaveFlushBeforeFullVariableInGroupe4() { $this->assertEquals(4, - $this->query("select * from variables where clef='flush_before_full'")->fetch()['groupe']); + $this->query("select * from variables where clef='flush_before_full'")->fetch()['groupe']); } } @@ -4158,7 +4205,7 @@ class UpgradeDB_423_Test extends UpgradeDBTestCase { 'role_level' => $role, 'id_cat' => $parent_group->getId(), 'filters' => json_encode( - ['search_role_level' => $role]) + ['search_role_level' => $role]) ]); $this->assertTrue($group->hasRight(Class_UserGroup::RIGHT_GERER_LETTRESINFO)); } @@ -4169,7 +4216,7 @@ class UpgradeDB_423_Test extends UpgradeDBTestCase { ['Administrateurs Bibliothèque' , ZendAfi_Acl_AdminControllerRoles::ADMIN_BIB], ['Rédacteurs Portail' , ZendAfi_Acl_AdminControllerRoles::MODO_PORTAIL], ['Administrateurs Portail' , ZendAfi_Acl_AdminControllerRoles::ADMIN_PORTAIL] - ]; + ]; } } @@ -4340,7 +4387,7 @@ class UpgradeDB_426_Test extends UpgradeDBTestCase { } } - /** @test */ + /** @test */ public function zorroShouldHaveRightToAccessSito() { $this->assertTrue((new ZendAfi_Acl_AdminControllerGroup()) ->isAllowed(Class_Users::findFirstBy(['login' => 'test426_Zorro']),'sito','')); @@ -4357,7 +4404,7 @@ class UpgradeDB_426_Test extends UpgradeDBTestCase { /** @test */ public function ricardoShouldNotHaveRightToAccessSito() { $this->assertFalse((new ZendAfi_Acl_AdminControllerGroup()) - ->isAllowed(Class_Users::findFirstBy(['login' => 'test426_Ricardo']),'sito','')); + ->isAllowed(Class_Users::findFirstBy(['login' => 'test426_Ricardo']),'sito','')); } } @@ -4871,7 +4918,7 @@ class UpgradeDB_439_Test extends UpgradeDBTestCase { } /** @test - PlaceHolder for patch438 which is a Cyberlibris migration to digitalresource + PlaceHolder for patch438 which is a Cyberlibris migration to digitalresource */ public function placeholderForPatch438() { $this->assertTrue(true); @@ -4930,9 +4977,9 @@ class UpgradeDB_440_Test extends UpgradeDBTestCase { /** @test */ public function loanLinkShouldHaveRemovedUserAgentId() { - $row = $this->query('select loan_link from loan_pnb where record_origin_id="TestDilicom"') - ->fetch(); - $this->assertTrue("https://pnb-dilicom.centprod.com/v2//link/3056000551506/LOAN/4/9782404003566-P4BRGR1CXJI4FZBRYLO64KEJZT7F02JZ.do" === $row['loan_link']); + $row = $this->query('select loan_link from loan_pnb where record_origin_id="TestDilicom"') + ->fetch(); + $this->assertTrue("https://pnb-dilicom.centprod.com/v2//link/3056000551506/LOAN/4/9782404003566-P4BRGR1CXJI4FZBRYLO64KEJZT7F02JZ.do" === $row['loan_link']); } @@ -5110,7 +5157,7 @@ class UpgradeDB_446_Test extends UpgradeDBTestCase { /** @test */ public function tableVariablesShouldHaveMaxItemsVariableInGroupe4() { $this->assertEquals(4, - $this->query("select * from variables where clef='max_items'")->fetch()['groupe']); + $this->query("select * from variables where clef='max_items'")->fetch()['groupe']); } diff --git a/tests_db/bootstrap_db.php b/tests_db/bootstrap_db.php new file mode 100644 index 0000000000000000000000000000000000000000..5df6e947701e3acbf16c780f3504e6b8902aa9f2 --- /dev/null +++ b/tests_db/bootstrap_db.php @@ -0,0 +1,90 @@ +<?php +/** + * Copyright (c) 2012, Agence Française Informatique (AFI). All rights reserved. + * + * BOKEH is free software; you can redistribute it and/or modify + * it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE as published by + * the Free Software Foundation. + * + * There are special exceptions to the terms and conditions of the AGPL as it + * is applied to this software (see README file). + * + * BOKEH is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU AFFERO GENERAL PUBLIC LICENSE for more details. + * + * You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE + * along with BOKEH; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +chdir(realpath(dirname(__FILE__)) . '/../'); + +error_reporting(E_ALL^E_DEPRECATED); +ini_set('display_startup_errors', 1); +ini_set('display_errors', 1); +ini_set('memory_limit', '3072M'); +date_default_timezone_set('Europe/Paris'); + +set_include_path(getcwd() . '/library' + . PATH_SEPARATOR . getcwd() . '/library/digital_resources' + . PATH_SEPARATOR . getcwd() . '/library/templates' + . PATH_SEPARATOR . getcwd() . '/library/Class' + . PATH_SEPARATOR . getcwd() . '/library/ZendAfi' + . PATH_SEPARATOR . getcwd() . '/library/storm/src' + . PATH_SEPARATOR . getcwd() . '/library/storm/tests' + . PATH_SEPARATOR . getcwd() . '/library/storm/zf/library' + . PATH_SEPARATOR . getcwd() . '/application/modules' + . PATH_SEPARATOR . getcwd() . '/tests' + . PATH_SEPARATOR . getcwd() + . PATH_SEPARATOR . get_include_path()); + +//echo 'PATHS = ' . get_include_path() . "\n"; +// Includes de base +include_once 'local.php'; +include_once 'fonctions/fonctions.php'; +require_once 'Zend/Loader.php'; +require_once 'library/startup.php'; + +$path = dirname(__FILE__); +$parts = explode(DIRECTORY_SEPARATOR, $path); +$parts = array_reverse($parts); + +defineConstant('BASE_URL', '/' . $parts[1]); +defineConstant('URL_IMG', BASE_URL . '/public/opac/skins/original/images/'); +defineConstant('URL_SHARED_IMG', BASE_URL . '/public/opac/images/'); + +$_SERVER['SERVER_NAME'] = 'localhost'; +$_SERVER['SERVER_PORT'] = '80'; +$_SERVER['REMOTE_ADDR'] = '127.0.0.1'; +$_SERVER['HTTP_HOST'] = 'localhost'; + +setupOpac(); + +Class_ICal_Autoloader::getInstance()->ensureAutoload(); + +(new Storm_Cache)->getCache()->setOption('caching', true); + +$db_cache = Zend_Cache::factory('Core', + 'File', + ['lifetime' => 300 , + 'automatic_serialization' => true], + ['cache_dir' => PATH_TEMP]); + +Zend_Db_Table_Abstract::setDefaultMetadataCache($db_cache); + +Storm_Cache::setSeed('local'); + +$cfg = new Zend_Config(Zend_Registry::get('cfg')->toArray(), true); +$cfg->amber = new Zend_Config(['deploy' => false]); + +Zend_Registry::set('cfg', $cfg); +$translate = Zend_Registry::get('translate'); +$translate->addTranslation(LANG_DIR . 'ro.mo', 'ro'); +$translate->addTranslation(LANG_DIR . 'en.mo', 'en'); +$translate->addTranslation(LANG_DIR . 'es.mo', 'es'); +$translate->addTranslation(LANG_DIR . 'fr.mo', 'fr'); +$translate->setLocale('fr'); + +register_shutdown_function(fn() => TestSpeedTrap::printSpeedTrappedTests()); diff --git a/tests/phpunit_db.xml b/tests_db/phpunit.xml similarity index 70% rename from tests/phpunit_db.xml rename to tests_db/phpunit.xml index d304e16455683964ded110128608831163053302..7daf20929f031ff9be915ce6ab9edc48d1cf1154 100644 --- a/tests/phpunit_db.xml +++ b/tests_db/phpunit.xml @@ -1,14 +1,13 @@ <?xml version="1.0" encoding="UTF-8"?> <phpunit - bootstrap="./bootstrap.php" + bootstrap="./bootstrap_db.php" colors="false" backupGlobals="false" stopOnFailure="false" - stopOnError="false" - > + stopOnError="false"> <testsuites> <testsuite name="Bokeh database migrations"> - <directory>./db/</directory> + <directory>./</directory> </testsuite> </testsuites> </phpunit>