From ef81ffb4afe1bcf3f591fff598e5d24bfa6bfffb Mon Sep 17 00:00:00 2001 From: j3nsch Date: Wed, 4 Dec 2024 09:10:27 +0100 Subject: [PATCH] #1253 Added enrichment commands --- composer.json | 1 + .../EnrichmentConfigImporter.php | 104 ++++++-- library/Application/Console/App.php | 6 +- .../Console/Model/EnrichmentDeleteCommand.php | 112 +++++++++ .../Console/Model/EnrichmentExportCommand.php | 128 ++++++++++ .../EnrichmentImportCommand.php | 12 +- .../Console/Model/EnrichmentListCommand.php | 5 +- .../Console/Model/EnrichmentRenameCommand.php | 110 +++++++++ modules/admin/forms/EnrichmentKey.php | 2 + modules/admin/models/EnrichmentKeys.php | 118 ++++++++- .../EnrichmentConfigImporterTest.php | 213 +++++++++++++++- .../Model/EnrichmentDeleteCommandTest.php | 168 +++++++++++++ .../Model/EnrichmentExportCommandTest.php | 224 +++++++++++++++++ .../Model/EnrichmentImportCommandTest.php | 228 ++++++++++++++++++ .../Model/EnrichmentRenameCommandTest.php | 166 +++++++++++++ .../Tool/EnrichmentImportCommandTest.php | 52 ---- .../admin/models/EnrichmentKeysTest.php | 62 +++++ .../resources/enrichments/conferenceType.yml | 24 +- tests/resources/enrichments/doi-import.yml | 10 + tests/resources/enrichments/multipleKeys.yml | 6 + tests/resources/enrichments/simpleOption.yml | 17 ++ tests/resources/enrichments/singleKey.yml | 1 + 22 files changed, 1663 insertions(+), 106 deletions(-) create mode 100644 library/Application/Console/Model/EnrichmentDeleteCommand.php create mode 100644 library/Application/Console/Model/EnrichmentExportCommand.php rename library/Application/Console/{Tool => Model}/EnrichmentImportCommand.php (92%) create mode 100644 library/Application/Console/Model/EnrichmentRenameCommand.php create mode 100644 tests/library/Application/Console/Model/EnrichmentDeleteCommandTest.php create mode 100644 tests/library/Application/Console/Model/EnrichmentExportCommandTest.php create mode 100644 tests/library/Application/Console/Model/EnrichmentImportCommandTest.php create mode 100644 tests/library/Application/Console/Model/EnrichmentRenameCommandTest.php delete mode 100644 tests/library/Application/Console/Tool/EnrichmentImportCommandTest.php create mode 100644 tests/resources/enrichments/doi-import.yml create mode 100644 tests/resources/enrichments/multipleKeys.yml create mode 100644 tests/resources/enrichments/simpleOption.yml create mode 100644 tests/resources/enrichments/singleKey.yml diff --git a/composer.json b/composer.json index f18e79fe2..95e9c3690 100644 --- a/composer.json +++ b/composer.json @@ -35,6 +35,7 @@ "components/jqueryui": "1.12.*", "oomphinc/composer-installers-extender": "^2.0", "symfony/console": "*", + "symfony/yaml": "*", "pear/log": "*" }, "require-dev": { diff --git a/library/Application/Configuration/EnrichmentConfigImporter.php b/library/Application/Configuration/EnrichmentConfigImporter.php index c267f48f3..dce9b1fe8 100644 --- a/library/Application/Configuration/EnrichmentConfigImporter.php +++ b/library/Application/Configuration/EnrichmentConfigImporter.php @@ -30,6 +30,7 @@ */ use Opus\Common\EnrichmentKey; +use Opus\Common\EnrichmentKeyInterface; use Symfony\Component\Console\Output\NullOutput; use Symfony\Component\Console\Output\OutputInterface; @@ -44,27 +45,61 @@ class Application_Configuration_EnrichmentConfigImporter private $output; /** - * @param string $filePath + * @param string $filePath + * @param string|null $keyName */ - public function import($filePath) + public function import($filePath, $keyName = null) { $config = yaml_parse_file($filePath); + $this->processConfig($config, $keyName); + } + + /** + * @param string $yaml + * @param string|null $keyName + */ + public function importYaml($yaml, $keyName = null) + { + $config = yaml_parse($yaml); + + $this->processConfig($config, $keyName); + } + + /** + * @param array $config + * @param string|null $keyName + */ + protected function processConfig($config, $keyName = null) + { if (! $config || ! is_array($config)) { - // TODO throw exception + throw new InvalidArgumentException('First parameter should be an array'); } + $config = $this->changeKeysTolowerCase($config); + if (isset($config['enrichments'])) { $enrichmentConfigs = $config['enrichments']; } else { + if ($keyName !== null) { + $config['name'] = $keyName; + } $enrichmentConfigs = [$config]; } foreach ($enrichmentConfigs as $enrichment) { - $this->createEnrichment($enrichment); + $enrichmentKey = $this->createEnrichment($enrichment); + if ($enrichmentKey !== null) { + $name = $enrichmentKey->getName(); + $this->getOutput()->writeln("Created enrichment key '{$name}'"); + } } } + /** + * @param array $config + * @return EnrichmentKeyInterface|null + */ public function createEnrichment($config) { $name = $config['name']; @@ -73,37 +108,60 @@ public function createEnrichment($config) if ($enrichmentKey !== null) { $this->getOutput()->writeln("Enrichment '{$enrichmentKey}' already exists"); - return; + return null; } $enrichmentKey = EnrichmentKey::new(); $enrichmentKey->setName($name); + $type = null; + if (isset($config['type'])) { - $type = $config['type']; - $enrichmentKey->setType($type); + $type = ucfirst($config['type'] . 'Type'); + $enrichmentKey->setType($type); // TODO make 'Type' suffix unnecessary } - if (isset($config['options'])) { - $options = $config['config']; - $enrichmentKey->setOptions($options); + if (isset($config['options']) && $type !== null) { + $typeClass = 'Opus\\Enrichment\\' . $type; + $enrichmentType = new $typeClass(); + $options = $config['options']; + if (is_array($options)) { + $enrichmentType->setOptions($options); + $enrichmentKey->setOptions($enrichmentType->getOptions()); + } else { + $enrichmentType->setOptionsFromString($options); + $enrichmentKey->setOptions($enrichmentType->getOptions()); + } } - // TODO strict validation - $enrichmentKey->store(); - if (isset($config['label'])) { - $this->createTranslations($config['label']); + if (isset($config['translations'])) { + $this->createTranslations($name, $config['translations']); } - // TODO set translations + return $enrichmentKey; } - public function createTranslations($translations) + /** + * @param string $name + * @param array $translations + */ + public function createTranslations($name, $translations) { + $helper = new Admin_Model_EnrichmentKeys(); + $keys = array_keys($translations); + $supportedKeys = $helper->getSupportedKeys(); + $unsupportedKeys = array_diff($keys, $supportedKeys); + + if (count($unsupportedKeys) > 0) { + foreach ($unsupportedKeys as $key) { + $this->getOutput()->writeln("Unsupported translation key: {$key}"); + } + } + $helper->createTranslations($name, null, $translations); } /** @@ -126,4 +184,18 @@ public function getOutput() } return $this->output; } + + /** + * @param array $config + * @return array + */ + protected function changeKeysTolowerCase($config) + { + return array_map(function ($item) { + if (is_array($item)) { + $item = $this->changeKeysToLowerCase($item); + } + return $item; + }, array_change_key_case($config, CASE_LOWER)); + } } diff --git a/library/Application/Console/App.php b/library/Application/Console/App.php index 14a6a1dc5..1788dde04 100644 --- a/library/Application/Console/App.php +++ b/library/Application/Console/App.php @@ -65,8 +65,12 @@ public function __construct() $this->add(new Application_Console_Debug_DocumentXmlCommand()); $this->add(new CoverGenerateCommand()); - $this->add(new Application_Console_Tool_EnrichmentImportCommand()); + // TODO use ModelCommandProvider (with OPUS 4.8.1) + $this->add(new Application_Console_Model_EnrichmentImportCommand()); $this->add(new Application_Console_Model_EnrichmentListCommand()); + $this->add(new Application_Console_Model_EnrichmentExportCommand()); + $this->add(new Application_Console_Model_EnrichmentRenameCommand()); + $this->add(new Application_Console_Model_EnrichmentDeleteCommand()); $this->setDefaultCommand('list'); } diff --git a/library/Application/Console/Model/EnrichmentDeleteCommand.php b/library/Application/Console/Model/EnrichmentDeleteCommand.php new file mode 100644 index 000000000..21cebb014 --- /dev/null +++ b/library/Application/Console/Model/EnrichmentDeleteCommand.php @@ -0,0 +1,112 @@ +enrichment:delete command can be used to delete enrichments. The command +also removes the translations associated with the enrichment. +EOT; + + $this->setName('enrichment:delete') + ->setDescription('Rename enrichment') + ->setHelp($help) + ->addArgument( + self::ARGUMENT_KEY, + InputArgument::OPTIONAL, + 'Enrichment key' + )->addOption( + self::OPTION_FORCE, + 'f', + InputOption::VALUE_NONE, + 'Do not prompt for confirmation.' + ); + } + + protected function execute(InputInterface $input, OutputInterface $output): int + { + $key = $input->getArgument(self::ARGUMENT_KEY); + + if ($key === null) { + $output->writeln('Enrichment key is required'); + return self::FAILURE; + } + + $enrichment = EnrichmentKey::fetchByName($key); + + if ($enrichment === null) { + $output->writeln("Enrichment key \"{$key}\" not found"); + return self::FAILURE; + } + + if (! $input->getOption(self::OPTION_FORCE)) { + $questionText = "Do you want to remove enrichment key \"{$key}\" (Y/n)?"; + $confirmation = new ConfirmationQuestion($questionText, true); + $question = $this->getHelper('question'); + + if (! $question->ask($input, $output, $confirmation)) { + $output->writeln("Not removing enrichment key \"{$key}\"."); + return self::SUCCESS; + } + } + + $output->writeln("Removing enrichment key \"{$key}\"."); + $enrichment->delete(); + + $output->writeln("Removing translations for enrichment key \"{$key}\"."); + $helper = new Admin_Model_EnrichmentKeys(); + $helper->removeTranslations($key); + + return self::SUCCESS; + } +} diff --git a/library/Application/Console/Model/EnrichmentExportCommand.php b/library/Application/Console/Model/EnrichmentExportCommand.php new file mode 100644 index 000000000..9c0f85b04 --- /dev/null +++ b/library/Application/Console/Model/EnrichmentExportCommand.php @@ -0,0 +1,128 @@ +enrichment:export command allows exporting the configuration of +one or all enrichment keys. +EOT; + + $this->setName('enrichment:export') + ->setDescription('Export enrichment configurations') + ->setHelp($help) + ->addArgument( + self::ARGUMENT_KEYS, + InputArgument::OPTIONAL | InputArgument::IS_ARRAY, + 'Enrichment key(s)' + )->addOption( + self::OPTION_OUTPUT_FILE, + 'o', + InputOption::VALUE_REQUIRED, + 'Name of output file' + ); + } + + protected function execute(InputInterface $input, OutputInterface $output): int + { + $keys = $input->getArgument(self::ARGUMENT_KEYS); + + if (count($keys) === 0) { + $keys = EnrichmentKey::getAll(); + } else { + foreach ($keys as $key) { + $enrichment = EnrichmentKey::fetchByName($key); + + if ($enrichment === null) { + $output->writeln("Enrichment key \"{$key}\" not found"); + return self::FAILURE; + } + } + } + + if (count($keys) === 0) { + $output->writeln("No enrichment keys found"); + return self::SUCCESS; + } + + $helper = new Admin_Model_EnrichmentKeys(); + + if (count($keys) === 1) { + $data = $helper->getEnrichmentConfig($keys[0]); + } else { + $enrichments = []; + foreach ($keys as $key) { + $enrichments[] = $helper->getEnrichmentConfig($key); + } + $data['enrichments'] = $enrichments; + } + + // Export lowercase keys + $data = array_change_key_case($data, CASE_LOWER); + $yaml = Yaml::dump($data, 6, 2, Yaml::DUMP_MULTI_LINE_LITERAL_BLOCK); + + // WORKAROUND: put first line of collection item behind dash + $yaml = preg_replace('/\-\n\s+/', '- ', $yaml); + + $outputFile = $input->getOption(self::OPTION_OUTPUT_FILE); + + if ($outputFile === null) { + $output->writeln($yaml); + } else { + file_put_contents($outputFile, $yaml); + } + + return self::SUCCESS; + } +} diff --git a/library/Application/Console/Tool/EnrichmentImportCommand.php b/library/Application/Console/Model/EnrichmentImportCommand.php similarity index 92% rename from library/Application/Console/Tool/EnrichmentImportCommand.php rename to library/Application/Console/Model/EnrichmentImportCommand.php index cdb135323..f3a7984ab 100644 --- a/library/Application/Console/Tool/EnrichmentImportCommand.php +++ b/library/Application/Console/Model/EnrichmentImportCommand.php @@ -37,7 +37,7 @@ /** * Command for importing Enrichment configurations. */ -class Application_Console_Tool_EnrichmentImportCommand extends Command +class Application_Console_Model_EnrichmentImportCommand extends Command { public const ARGUMENT_FILE = 'config_file'; @@ -51,7 +51,7 @@ protected function configure() EOT; $this->setName('enrichment:import') - ->setDescription('Imports an Enrichment configuration') + ->setDescription('Import Enrichment configuration') ->setHelp($help) ->addArgument( self::ARGUMENT_FILE, @@ -60,24 +60,22 @@ protected function configure() ); } - /** - * @return int - */ - protected function execute(InputInterface $input, OutputInterface $output) + protected function execute(InputInterface $input, OutputInterface $output): int { $file = $input->getArgument(self::ARGUMENT_FILE); if (! file_exists($file)) { $output->writeln('Input file not found'); + return self::FAILURE; } - if (! is_readable($file)) { $output->writeln('Input file not readable'); return self::FAILURE; } $importer = new Application_Configuration_EnrichmentConfigImporter(); + $importer->setOutput($output); $importer->import($file); diff --git a/library/Application/Console/Model/EnrichmentListCommand.php b/library/Application/Console/Model/EnrichmentListCommand.php index cdd7a8500..7ae9ef715 100644 --- a/library/Application/Console/Model/EnrichmentListCommand.php +++ b/library/Application/Console/Model/EnrichmentListCommand.php @@ -57,10 +57,7 @@ protected function configure() ->setHelp($help); } - /** - * @return int - */ - protected function execute(InputInterface $input, OutputInterface $output) + protected function execute(InputInterface $input, OutputInterface $output): int { $allKeys = EnrichmentKey::getAll(); $referencedKeys = EnrichmentKey::getAllReferenced(); diff --git a/library/Application/Console/Model/EnrichmentRenameCommand.php b/library/Application/Console/Model/EnrichmentRenameCommand.php new file mode 100644 index 000000000..a38734beb --- /dev/null +++ b/library/Application/Console/Model/EnrichmentRenameCommand.php @@ -0,0 +1,110 @@ +enrichment:rename command can be used to rename enrichments. +EOT; + + $this->setName('enrichment:rename') + ->setDescription('Rename enrichment') + ->setHelp($help) + ->addArgument( + self::ARGUMENT_KEY, + InputArgument::REQUIRED, + 'Enrichment key' + )->addArgument( + self::ARGUMENT_NEW_KEY, + InputArgument::REQUIRED, + 'New Enrichment key' + ); + } + + protected function execute(InputInterface $input, OutputInterface $output): int + { + $key = $input->getArgument(self::ARGUMENT_KEY); + + if ($key === null) { + $output->writeln('Enrichment key is required.'); + return self::FAILURE; + } + + $newKey = $input->getArgument(self::ARGUMENT_NEW_KEY); + + if ($newKey === null) { + $output->writeln('New enrichment key name is required.'); + return self::FAILURE; + } + + $enrichment = EnrichmentKey::fetchByName($key); + + if ($enrichment === null) { + $output->writeln("Enrichment key \"{$key}\" not found."); + return self::FAILURE; + } + + $newEnrichment = EnrichmentKey::fetchByName($newKey); + + if ($newEnrichment !== null) { + $output->writeln("Enrichment key \"{$newKey}\" already exists."); + return self::FAILURE; + } + + $output->writeln("Renaming key \"{$key}\" to \"{$newKey}\"."); + $enrichment->rename($newKey); + $enrichment->setName($newKey); + $enrichment->store(); + + $output->writeln("Renaming translations for enrichment key \"{$newKey}\""); + $helper = new Admin_Model_EnrichmentKeys(); + $helper->createTranslations($newKey, $key); + + return self::SUCCESS; + } +} diff --git a/modules/admin/forms/EnrichmentKey.php b/modules/admin/forms/EnrichmentKey.php index eb4a73c85..ddc462dcd 100644 --- a/modules/admin/forms/EnrichmentKey.php +++ b/modules/admin/forms/EnrichmentKey.php @@ -175,6 +175,8 @@ public function populateFromModel($enrichmentKey) $enrichmentType = $this->initEnrichmentType($enrichmentKey->getType()); if ($enrichmentType !== null) { + // TODO this should not be necessary - The EnrichmentType defines the options, but the options are not for + // the type, but for the EnrichmentKey. $enrichmentType->setOptions($enrichmentKey->getOptions()); $optionsElement = $this->getElement(self::ELEMENT_OPTIONS); diff --git a/modules/admin/models/EnrichmentKeys.php b/modules/admin/models/EnrichmentKeys.php index 9200d7421..07770a189 100644 --- a/modules/admin/models/EnrichmentKeys.php +++ b/modules/admin/models/EnrichmentKeys.php @@ -29,6 +29,7 @@ * @license http://www.gnu.org/licenses/gpl.html General Public License */ +use Opus\Common\EnrichmentKey; use Opus\Translate\Dao; /** @@ -41,12 +42,12 @@ class Admin_Model_EnrichmentKeys extends Application_Model_Abstract { /** @var string[] */ private $translationKeyPatterns = [ - 'hint_Enrichment%s', - 'header_Enrichment%s', - 'group%s', - 'hint_group%s', - 'button_label_add_one_moreEnrichment%s', - 'button_label_deleteEnrichment%s', + 'hint' => 'hint_Enrichment%s', + 'header' => 'header_Enrichment%s', + 'group' => 'group%s', + 'groupHint' => 'hint_group%s', + 'buttonAdd' => 'button_label_add_one_moreEnrichment%s', + 'buttonDelete' => 'button_label_deleteEnrichment%s', ]; /** @@ -110,36 +111,85 @@ public function setProtectedEnrichmentKeys($keys) * * @param string $name Name of enrichment * @param string|null $oldName Optionally old name if it has been changed + * @param array|null $translations * * TODO create keys if they don't exist * TODO what happens if renameKey into keys that already exist? + * TODO support more languages */ - public function createTranslations($name, $oldName = null) + public function createTranslations($name, $oldName = null, $translations = null) { $patterns = $this->translationKeyPatterns; $database = new Dao(); $manager = new Application_Translate_TranslationManager(); + if ($translations === null) { + $translations = []; + } + if ($oldName !== null && $name !== $oldName) { + $patterns['label'] = 'Enrichment%s'; // TODO avoid custom handling for 'label' + foreach ($patterns as $pattern) { $key = sprintf($pattern, $name); $oldKey = sprintf($pattern, $oldName); $database->renameKey($oldKey, $key, 'default'); } } else { - foreach ($patterns as $pattern) { + if (isset($translations['label'])) { + $patterns['label'] = 'Enrichment%s'; // TODO avoid custom handling for 'label' + } + foreach ($patterns as $patternName => $pattern) { $key = sprintf($pattern, $name); if (! $manager->keyExists($key)) { + $enValue = $name; + if (isset($translations[$patternName]['en'])) { + $enValue = $translations[$patternName]['en']; + } + + $deValue = $name; + if (isset($translations[$patternName]['de'])) { + $deValue = $translations[$patternName]['de']; + } + $database->setTranslation($key, [ - 'en' => $name, - 'de' => $name, + 'en' => $enValue, + 'de' => $deValue, ], 'default'); } } } } + /** + * @param string $name Name of enrichment key + * @return string[] + * + * TODO 'label' translation handled separately (here and in admin form) - unify handling? + */ + public function getTranslations($name) + { + $patterns = $this->translationKeyPatterns; + + $patterns['label'] = 'Enrichment%s'; + + $manager = new Application_Translate_TranslationManager(); + + $translations = []; + + $allTranslations = $manager->getMergedTranslations(); + + foreach ($patterns as $patternName => $pattern) { + $key = sprintf($pattern, $name); + if (isset($allTranslations[$key]['translations'])) { + $translations[$patternName] = $allTranslations[$key]['translations']; + } + } + + return $translations; + } + /** * Remove translation keys if enrichment is deleted. * @@ -151,6 +201,8 @@ public function removeTranslations($name) $database = new Dao(); + $patterns['label'] = 'Enrichment%s'; // TODO avoid custom handling for 'label' + foreach ($patterns as $pattern) { $key = sprintf($pattern, $name); $database->remove($key, 'default'); @@ -164,4 +216,50 @@ public function getKeyPatterns() { return $this->translationKeyPatterns; } + + /** + * @param string $name + * @return string[] + */ + public function getEnrichmentConfig($name) + { + $enrichment = EnrichmentKey::fetchByName($name); + $enrichmentConfig = $enrichment->toArray(); + + // remove NULL values + $enrichmentConfig = array_filter($enrichmentConfig, function ($value) { + return $value !== null; + }); + + // remove 'Type' from type name (TODO this should not be necessary later) + if (isset($enrichmentConfig['Type'])) { + $type = preg_replace('/Type$/', '', $enrichmentConfig['Type']); + $enrichmentConfig['Type'] = $type; + } + + // add translations to configuration + $translations = $this->getTranslations($name); + if (count($translations) > 0) { + $enrichmentConfig['translations'] = $translations; + } + + // handle options + if (isset($enrichmentConfig['Options'])) { + $options = json_decode($enrichmentConfig['Options'], true); + $enrichmentConfig['Options'] = $options; + } + + // use lowercase keys in yaml + $enrichmentConfig = array_change_key_case($enrichmentConfig, CASE_LOWER); + + return $enrichmentConfig; + } + + /** + * @return string[] + */ + public function getSupportedKeys() + { + return array_keys($this->getKeyPatterns()); + } } diff --git a/tests/library/Application/Configuration/EnrichmentConfigImporterTest.php b/tests/library/Application/Configuration/EnrichmentConfigImporterTest.php index d261c50e9..7b1ed2a5e 100644 --- a/tests/library/Application/Configuration/EnrichmentConfigImporterTest.php +++ b/tests/library/Application/Configuration/EnrichmentConfigImporterTest.php @@ -29,6 +29,10 @@ * @license http://www.gnu.org/licenses/gpl.html General Public License */ +use Opus\Common\EnrichmentKey; +use Opus\Enrichment\SelectType; +use Symfony\Component\Console\Output\BufferedOutput; + class Application_Configuration_EnrichmentConfigImporterTest extends ControllerTestCase { /** @var string */ @@ -37,24 +41,227 @@ class Application_Configuration_EnrichmentConfigImporterTest extends ControllerT /** @var Application_Configuration_EnrichmentConfigImporter */ private $importer; - public function setUp() : void + public function setUp(): void { parent::setUp(); $this->importer = new Application_Configuration_EnrichmentConfigImporter(); } - public function testImportSingleEnrichmentConfig() + public function testImportSingleEnrichmentFromString() + { + $yaml = <<importer->importYaml($yaml); + + $enrichment = EnrichmentKey::fetchByName('testKey1'); + + $this->assertNotNull($enrichment); + $this->addModelToCleanup($enrichment); + } + + public function testImportSelectEnrichmentConfig() { + $keyName = 'conferenceType'; + $yamlFile = APPLICATION_PATH . '/tests/resources/enrichments/conferenceType.yml'; $this->importer->import($yamlFile); + + $enrichmentKey = EnrichmentKey::fetchByName($keyName); + + $this->assertNotNull($enrichmentKey); + + $this->addModelToCleanup($enrichmentKey); + + $this->assertEquals($keyName, $enrichmentKey->getName()); + $this->assertEquals('SelectType', $enrichmentKey->getType()); + + $options = $enrichmentKey->getOptions(); + + $enrichmentType = new SelectType(); + $enrichmentType->setOptions($options); + + $this->assertEquals('strict', $enrichmentType->getValidation()); + $this->assertEquals([ + 'Konferenzband', + 'Konferenzartikel', + 'Konferenz-Poster', + 'Konferenz-Abstract', + 'Sonstiges', + ], $enrichmentType->getValues()); + + $helper = new Admin_Model_EnrichmentKeys(); + $translations = $helper->getTranslations($keyName); + $helper->removeTranslations($keyName); + + $this->assertCount(7, $translations); + $this->assertEquals([ + 'de' => 'Art der Konferenzveröffentlichung', + 'en' => 'Conference Type', + ], $translations['label']); + $this->assertEquals([ + 'de' => 'conferenceType', + 'en' => 'conferenceType', + ], $translations['hint']); } public function testImportMultipleEnrichmentConfigs() { - $yamlFile = APPLICATION_PATH . '/tests/resources/enrichments/import.yml'; + $yamlFile = APPLICATION_PATH . '/tests/resources/enrichments/multipleKeys.yml'; $this->importer->import($yamlFile); + + $keys = [ + 'testKey1', + 'testKey2', + 'testKey3', + 'testKey4', + ]; + + foreach ($keys as $key) { + $enrichment = EnrichmentKey::fetchByName($key); + $this->assertNotNull($enrichment); + $this->addModelToCleanup($enrichment); + } + } + + public function testKeysAreHandledCaseInsensitive() + { + $yaml = <<importer->importYaml($yaml); + + $enrichment = EnrichmentKey::fetchByName('enrichmentKey1'); + $this->assertNotNull($enrichment); + $this->addModelToCleanup($enrichment); + + $helper = new Admin_Model_EnrichmentKeys(); + $translations = $helper->getTranslations('enrichmentKey1'); + $helper->removeTranslations('enrichmentKey1'); + + $this->assertCount(7, $translations); + $this->assertEquals([ + 'de' => 'EnrichmentKey1de', + 'en' => 'EnrichmentKey1en', + ], $translations['label']); + } + + public function testEnrichmentAlreadyExists() + { + $this->assertNotNull(EnrichmentKey::fetchByName('Country')); + + $yaml = <<importer->importYaml($yaml); + + $enrichment = EnrichmentKey::fetchByName('Country'); + + $this->assertNotNull($enrichment); + } + + public function testUseDifferentEnrichmentKeyName() + { + $yaml = <<importer->importYaml($yaml, 'enrichmentKey2'); + + $enrichment = EnrichmentKey::fetchByName('enrichmentKey1'); + $this->assertNull($enrichment); + + $enrichment = EnrichmentKey::fetchByName('enrichmentKey2'); + $this->assertNotNull($enrichment); + $this->addModelToCleanup($enrichment); + } + + public function testUseKeyNameWhenImportingMultipleKeys() + { + $yaml = <<importer->importYaml($yaml, 'enrichmentKey3'); + + $enrichment = EnrichmentKey::fetchByName('enrichmentKey1'); + $this->assertNotNull($enrichment); + $this->addModelToCleanup($enrichment); + + $enrichment = EnrichmentKey::fetchByName('enrichmentKey2'); + $this->assertNotNull($enrichment); + $this->addModelToCleanup($enrichment); + + $enrichment = EnrichmentKey::fetchByName('enrichmentKey3'); + $this->assertNull($enrichment); + } + + public function testImportSelectEnrichmentWithSimpleOptions() + { + $yaml = <<importer->importYaml($yaml); + + $enrichment = EnrichmentKey::fetchByName('color'); + $this->assertNotNull($enrichment); + $this->addModelToCleanup($enrichment); + + $enrichmentType = new SelectType(); + $enrichmentType->setOptions($enrichment->getOptions()); + + $this->assertEquals('none', $enrichmentType->getValidation()); + $this->assertEquals([ + 'red', + 'green', + 'blue', + 'yellow', + ], $enrichmentType->getValues()); + } + + public function testTranslationWithUnknownKey() + { + $yaml = <<importer->setOutput($output); + $this->importer->importYaml($yaml); + + $enrichment = EnrichmentKey::fetchByName('color'); + $this->assertNotNull($enrichment); + $this->addModelToCleanup($enrichment); + + $helper = new Admin_Model_EnrichmentKeys(); + $translations = $helper->getTranslations('color'); + + $this->assertCount(6, $translations); // TODO label should be added automatically + + $this->assertStringContainsString('Unsupported translation key: category', $output->fetch()); } } diff --git a/tests/library/Application/Console/Model/EnrichmentDeleteCommandTest.php b/tests/library/Application/Console/Model/EnrichmentDeleteCommandTest.php new file mode 100644 index 000000000..dd6159931 --- /dev/null +++ b/tests/library/Application/Console/Model/EnrichmentDeleteCommandTest.php @@ -0,0 +1,168 @@ +setApplication($app); + + $this->tester = new CommandTester($command); + + $enrichment = EnrichmentKey::new(); + $enrichment->setName(self::TEST_ENRICHMENT_KEY); + $enrichment->store(); + } + + public function tearDown(): void + { + $enrichment = EnrichmentKey::fetchByName(self::TEST_ENRICHMENT_KEY); + if ($enrichment !== null) { + $enrichment->delete(); + } + + parent::tearDown(); + } + + public function testDeleteWithoutEnrichmentKey() + { + $this->tester->execute([]); + + $output = $this->tester->getDisplay(); + + $this->assertStringContainsString('Enrichment key is required', $output); + } + + public function testDeleteEnrichmentWithoutConfirmation() + { + $this->tester->execute([ + Application_Console_Model_EnrichmentDeleteCommand::ARGUMENT_KEY => self::TEST_ENRICHMENT_KEY, + '-f' => true, + ]); + + $this->assertNull(EnrichmentKey::fetchByName(self::TEST_ENRICHMENT_KEY)); + } + + public function testDeleteEnrichmentWithoutConfirmationUsingLongOption() + { + $this->tester->execute([ + Application_Console_Model_EnrichmentDeleteCommand::ARGUMENT_KEY => self::TEST_ENRICHMENT_KEY, + '--force' => true, + ]); + + $this->assertNull(EnrichmentKey::fetchByName(self::TEST_ENRICHMENT_KEY)); + } + + public function testDeleteEnrichmentWithConfirmation() + { + $this->tester->setInputs(['y']); + + $this->tester->execute([ + Application_Console_Model_EnrichmentDeleteCommand::ARGUMENT_KEY => self::TEST_ENRICHMENT_KEY, + ]); + + $this->assertNull(EnrichmentKey::fetchByName(self::TEST_ENRICHMENT_KEY)); + } + + public function testDeleteEnrichmentWithConfirmationYesIsDefault() + { + $this->tester->setInputs([]); // pressing enter at confirmation step + + $this->tester->execute([ + Application_Console_Model_EnrichmentDeleteCommand::ARGUMENT_KEY => self::TEST_ENRICHMENT_KEY, + ]); + + $this->assertNull(EnrichmentKey::fetchByName(self::TEST_ENRICHMENT_KEY)); + } + + public function testCancelDeletionAtConfirmation() + { + $this->tester->setInputs(['n']); // pressing enter at confirmation step + + $this->tester->execute([ + Application_Console_Model_EnrichmentDeleteCommand::ARGUMENT_KEY => self::TEST_ENRICHMENT_KEY, + ]); + + $this->assertNotNull(EnrichmentKey::fetchByName(self::TEST_ENRICHMENT_KEY)); + } + + public function testDeleteUnknownEnrichment() + { + $this->tester->execute([ + Application_Console_Model_EnrichmentDeleteCommand::ARGUMENT_KEY => 'unknownEnrichmentKey', + '-f' => true, + ]); + + $output = $this->tester->getDisplay(); + + $this->assertStringContainsString('Enrichment key "unknownEnrichmentKey" not found', $output); + $this->assertNotNull(EnrichmentKey::fetchByName(self::TEST_ENRICHMENT_KEY)); // no side effects + } + + public function testDeletionRemovesTranslations() + { + $helper = new Admin_Model_EnrichmentKeys(); + + $helper->createTranslations(self::TEST_ENRICHMENT_KEY); + + $translations = $helper->getTranslations(self::TEST_ENRICHMENT_KEY); + + $this->assertGreaterThan(1, count($translations)); + + $this->tester->execute([ + Application_Console_Model_EnrichmentDeleteCommand::ARGUMENT_KEY => self::TEST_ENRICHMENT_KEY, + '-f' => true, + ]); + + $this->assertNull(EnrichmentKey::fetchByName(self::TEST_ENRICHMENT_KEY)); // no side effects + + $translations = $helper->getTranslations(self::TEST_ENRICHMENT_KEY); + + $this->assertCount(0, $translations); + } +} diff --git a/tests/library/Application/Console/Model/EnrichmentExportCommandTest.php b/tests/library/Application/Console/Model/EnrichmentExportCommandTest.php new file mode 100644 index 000000000..c35fee052 --- /dev/null +++ b/tests/library/Application/Console/Model/EnrichmentExportCommandTest.php @@ -0,0 +1,224 @@ +setApplication($app); + + $this->tester = new CommandTester($command); + } + + public function testExportEnrichment() + { + $this->tester->execute([ + Application_Console_Model_EnrichmentExportCommand::ARGUMENT_KEYS => ['opus.import.checksum'], + ]); + + $output = $this->tester->getDisplay(); + + $expected = <<assertEquals($expected, trim($output)); // trim additional line breaks at end of output + } + + public function testExportEnrichmentWithTranslations() + { + $this->tester->execute([ + Application_Console_Model_EnrichmentExportCommand::ARGUMENT_KEYS => ['Country'], + ]); + + $output = $this->tester->getDisplay(); + + $expected = <<assertEquals($expected, trim($output)); // trim additional line breaks at end of output + } + + public function testExportMultipleEnrichmentKeys() + { + $this->tester->execute([ + Application_Console_Model_EnrichmentExportCommand::ARGUMENT_KEYS => [ + 'opus.import.date', + 'opus.import.file', + ], + ]); + + $output = $this->tester->getDisplay(); + + $this->assertStringContainsString('enrichments:', $output); + $this->assertStringContainsString(' - name: opus.import.date', $output); + $this->assertStringContainsString(' - name: opus.import.file', $output); + } + + public function testExportAllEnrichments() + { + $this->tester->execute([]); + + $output = $this->tester->getDisplay(); + + $this->assertStringContainsString('enrichments:', $output); + + $exportCount = substr_count($output, '- name:'); + + $allKeys = EnrichmentKey::getKeys(); + + $this->assertEquals(count($allKeys), $exportCount); + } + + public function testUnknownEnrichmentKey() + { + $this->tester->execute([ + Application_Console_Model_EnrichmentExportCommand::ARGUMENT_KEYS => [ + 'UnknownKey', + ], + ]); + + $output = $this->tester->getDisplay(); + + $this->assertStringContainsString('Enrichment key "UnknownKey" not found', $output); + } + + public function testExportMultipleEnrichmentKeysWithUnknownKeys() + { + $this->tester->execute([ + Application_Console_Model_EnrichmentExportCommand::ARGUMENT_KEYS => [ + 'Country', + 'UnknownKey1', + 'UnknownKey2', + ], + ]); + + $output = $this->tester->getDisplay(); + + $this->assertStringContainsString('Enrichment key "UnknownKey1" not found', $output); + $this->assertStringNotContainsString('Enrichment key "UnknownKey2" not found', $output); + } + + public function testExportSelectEnrichment() + { + $enrichmentKey = EnrichmentKey::new(); + $enrichmentKey->setName('testSelect'); + $enrichmentKey->setType('SelectType'); + + $selectType = new SelectType(); + $selectType->setOptions([ + 'validation' => 'strict', + 'values' => [ + 'Item1', + 'Item2', + 'Item3', + ], + ]); + + $enrichmentKey->setOptions($selectType->getOptions()); + $enrichmentKey->store(); + + $this->tester->execute([ + Application_Console_Model_EnrichmentExportCommand::ARGUMENT_KEYS => ['testSelect'], + ]); + + // cleanup before checks + $enrichmentKey->delete(); + + $output = $this->tester->getDisplay(); + + $expected = <<assertEquals($expected, trim($output)); + } + + public function testExportEnrichmentToOutputFile() + { + $tempFile = $this->getTempFile(); + + $this->tester->execute([ + Application_Console_Model_EnrichmentExportCommand::ARGUMENT_KEYS => ['Country'], + '--outputFile' => $tempFile, + ]); + + $output = $this->tester->getDisplay(); + + $this->assertEmpty($output); + + $yaml = file_get_contents($tempFile); + + $expected = <<assertEquals($expected, trim($yaml)); + } +} diff --git a/tests/library/Application/Console/Model/EnrichmentImportCommandTest.php b/tests/library/Application/Console/Model/EnrichmentImportCommandTest.php new file mode 100644 index 000000000..9da69fb66 --- /dev/null +++ b/tests/library/Application/Console/Model/EnrichmentImportCommandTest.php @@ -0,0 +1,228 @@ +setApplication($app); + + $this->tester = new CommandTester($command); + } + + public function testImportSingleEnrichment() + { + $yamlFile = APPLICATION_PATH . '/tests/resources/enrichments/singleKey.yml'; + + $this->tester->execute([ + Application_Console_Model_EnrichmentImportCommand::ARGUMENT_FILE => $yamlFile, + ]); + + $output = $this->tester->getDisplay(); + + $enrichment = EnrichmentKey::fetchByName('singleEnrichmentKey'); + $this->assertNotNull($enrichment); + $this->addModelToCleanup($enrichment); + + $this->assertStringContainsString('Created enrichment key \'singleEnrichmentKey\'', $output); + } + + public function testImportEnrichmentAlreadyExists() + { + $enrichment = EnrichmentKey::new(); + $enrichment->setName('singleEnrichmentKey'); + $enrichment->store(); + + $yamlFile = APPLICATION_PATH . '/tests/resources/enrichments/singleKey.yml'; + + $this->tester->execute([ + Application_Console_Model_EnrichmentImportCommand::ARGUMENT_FILE => $yamlFile, + ]); + + $output = $this->tester->getDisplay(); + + $enrichment = EnrichmentKey::fetchByName('singleEnrichmentKey'); + $this->assertNotNull($enrichment); + $this->addModelToCleanup($enrichment); + + $this->assertStringContainsString('Enrichment \'singleEnrichmentKey\' already exists', $output); + } + + public function testImportMultipleEnrichments() + { + $yamlFile = APPLICATION_PATH . '/tests/resources/enrichments/multipleKeys.yml'; + + $this->tester->execute([ + Application_Console_Model_EnrichmentImportCommand::ARGUMENT_FILE => $yamlFile, + ]); + + $keys = [ + 'testKey1', + 'testKey2', + 'testKey3', + 'testKey4', + ]; + + $output = $this->tester->getDisplay(); + + foreach ($keys as $key) { + $enrichment = EnrichmentKey::fetchByName($key); + $this->assertNotNull($enrichment); + $this->addModelToCleanup($enrichment); + } + + foreach ($keys as $key) { + $this->assertStringContainsString("Created enrichment key '{$key}'", $output); + } + } + + public function testImportMultipleEnrichmentsOneAlreadyExists() + { + $enrichment = EnrichmentKey::new(); + $enrichment->setName('testKey4'); + $enrichment->store(); + + $yamlFile = APPLICATION_PATH . '/tests/resources/enrichments/multipleKeys.yml'; + + $this->tester->execute([ + Application_Console_Model_EnrichmentImportCommand::ARGUMENT_FILE => $yamlFile, + ]); + + $keys = [ + 'testKey1', + 'testKey2', + 'testKey3', + 'testKey4', + ]; + + $output = $this->tester->getDisplay(); + + foreach ($keys as $key) { + $enrichment = EnrichmentKey::fetchByName($key); + $this->assertNotNull($enrichment); + $this->addModelToCleanup($enrichment); + } + + array_pop($keys); + + foreach ($keys as $key) { + $this->assertStringContainsString("Created enrichment key '{$key}'", $output); + } + + $this->assertStringContainsString('Enrichment \'testKey4\' already exists', $output); + } + + public function testImportFileNotFound() + { + $yamlFile = APPLICATION_PATH . '/tests/resources/enrichments/unknownFile.yml'; + + $this->tester->execute([ + Application_Console_Model_EnrichmentImportCommand::ARGUMENT_FILE => $yamlFile, + ]); + + $output = $this->tester->getDisplay(); + + $this->assertStringContainsString('Input file not found', $output); + } + + public function testImportEnrichmentWithOptions() + { + $yamlFile = APPLICATION_PATH . '/tests/resources/enrichments/simpleOption.yml'; + + $this->tester->execute([ + Application_Console_Model_EnrichmentImportCommand::ARGUMENT_FILE => $yamlFile, + ]); + + $enrichment = EnrichmentKey::fetchByName('conferenceType'); + $this->assertNotNull($enrichment); + $this->addModelToCleanup($enrichment); + + $selectType = new SelectType(); + + $selectType->setOptions($enrichment->getOptions()); + + $this->assertEquals('none', $selectType->getValidation()); + $this->assertEquals([ + 'Konferenzband', + 'Konferenzartikel', + 'Konferenz-Poster', + 'Konferenz-Abstract', + 'Sonstiges', + ], $selectType->getValues()); + + $output = $this->tester->getDisplay(); + + $this->assertStringContainsString("Created enrichment key 'conferenceType'", $output); + } + + public function testImportEnrichmentWithTranslations() + { + $yamlFile = APPLICATION_PATH . '/tests/resources/enrichments/simpleOption.yml'; + + $this->tester->execute([ + Application_Console_Model_EnrichmentImportCommand::ARGUMENT_FILE => $yamlFile, + ]); + + $enrichment = EnrichmentKey::fetchByName('conferenceType'); + $this->assertNotNull($enrichment); + $this->addModelToCleanup($enrichment); + + $output = $this->tester->getDisplay(); + + $this->assertStringContainsString("Created enrichment key 'conferenceType'", $output); + + $helper = new Admin_Model_EnrichmentKeys(); + + $translations = $helper->getTranslations('conferenceType'); + + $this->assertNotEmpty($translations); + $this->assertEquals([ + 'de' => 'Art der Konferenzveröffentlichung', + 'en' => 'Conference Type', + ], $translations['label']); + } +} diff --git a/tests/library/Application/Console/Model/EnrichmentRenameCommandTest.php b/tests/library/Application/Console/Model/EnrichmentRenameCommandTest.php new file mode 100644 index 000000000..90a6fe0b5 --- /dev/null +++ b/tests/library/Application/Console/Model/EnrichmentRenameCommandTest.php @@ -0,0 +1,166 @@ +setApplication($app); + + $this->tester = new CommandTester($command); + + $enrichmentKey = EnrichmentKey::new(); + $enrichmentKey->setName(self::TEST_ENRICHMENT_KEY); + $enrichmentKey->store(); + } + + public function tearDown(): void + { + $enrichmentKey = EnrichmentKey::fetchByName(self::TEST_ENRICHMENT_KEY); + if ($enrichmentKey !== null) { + $enrichmentKey->delete(); + } + + parent::tearDown(); + } + + public function testRenameEnrichment() + { + $newKey = 'newEnrichmentKey'; + + $this->assertNull(EnrichmentKey::fetchByName($newKey)); + + $this->tester->execute([ + Application_Console_Model_EnrichmentRenameCommand::ARGUMENT_KEY => self::TEST_ENRICHMENT_KEY, + Application_Console_Model_EnrichmentRenameCommand::ARGUMENT_NEW_KEY => $newKey, + ]); + + $this->assertNull(EnrichmentKey::fetchByName(self::TEST_ENRICHMENT_KEY)); + + $enrichmentKey = EnrichmentKey::fetchByName($newKey); + $this->assertNotNull($enrichmentKey); + $enrichmentKey->delete(); + + $output = $this->tester->getDisplay(); + + $oldKey = self::TEST_ENRICHMENT_KEY; + + $this->assertStringContainsString("Renaming key \"$oldKey\" to \"{$newKey}\"", $output); + $this->assertStringContainsString("Renaming translations for enrichment key \"{$newKey}\"", $output); + } + + public function testMissingArguments() + { + $this->expectException(RuntimeException::class); + $this->expectExceptionMessage('Not enough arguments (missing: "key, newKey")'); + + $this->tester->execute([]); + } + + public function testArgumentKeyIsUnknown() + { + $this->tester->execute([ + Application_Console_Model_EnrichmentRenameCommand::ARGUMENT_KEY => 'unknownEnrichmentKey', + Application_Console_Model_EnrichmentRenameCommand::ARGUMENT_NEW_KEY => 'newEnrichmentKey', + ]); + + $output = $this->tester->getDisplay(); + + $this->assertStringContainsString('Enrichment key "unknownEnrichmentKey" not found', $output); + } + + public function testArgumentNewKeyMissing() + { + $this->expectException(RuntimeException::class); + $this->expectExceptionMessage('Not enough arguments (missing: "newKey")'); + + $this->tester->execute([ + Application_Console_Model_EnrichmentRenameCommand::ARGUMENT_KEY => self::TEST_ENRICHMENT_KEY, + ]); + } + + public function testNewKeyAlreadyExists() + { + $this->tester->execute([ + Application_Console_Model_EnrichmentRenameCommand::ARGUMENT_KEY => self::TEST_ENRICHMENT_KEY, + Application_Console_Model_EnrichmentRenameCommand::ARGUMENT_NEW_KEY => 'Country', + ]); + + $output = $this->tester->getDisplay(); + + $this->assertStringContainsString('Enrichment key "Country" already exists', $output); + } + + public function testTranslationsAreRenamed() + { + $newKey = 'newEnrichmentKey'; + + $this->assertNull(EnrichmentKey::fetchByName($newKey)); + + $helper = new Admin_Model_EnrichmentKeys(); + $helper->createTranslations(self::TEST_ENRICHMENT_KEY); + + $helper->removeTranslations($newKey); // just in case + $this->assertCount(0, $helper->getTranslations($newKey)); + + $this->tester->execute([ + Application_Console_Model_EnrichmentRenameCommand::ARGUMENT_KEY => self::TEST_ENRICHMENT_KEY, + Application_Console_Model_EnrichmentRenameCommand::ARGUMENT_NEW_KEY => $newKey, + ]); + + $this->assertNull(EnrichmentKey::fetchByName(self::TEST_ENRICHMENT_KEY)); + + $enrichmentKey = EnrichmentKey::fetchByName($newKey); + $this->assertNotNull($enrichmentKey); + $enrichmentKey->delete(); + + $this->assertGreaterThan(1, count($helper->getTranslations($newKey))); + $this->assertCount(0, $helper->getTranslations(self::TEST_ENRICHMENT_KEY)); + } +} diff --git a/tests/library/Application/Console/Tool/EnrichmentImportCommandTest.php b/tests/library/Application/Console/Tool/EnrichmentImportCommandTest.php deleted file mode 100644 index 15c9ed343..000000000 --- a/tests/library/Application/Console/Tool/EnrichmentImportCommandTest.php +++ /dev/null @@ -1,52 +0,0 @@ -markTestIncomplete('not implemented yet'); - } - - public function testImportFileNotFound() - { - - } -} diff --git a/tests/modules/admin/models/EnrichmentKeysTest.php b/tests/modules/admin/models/EnrichmentKeysTest.php index 1e9692fae..ebc819e2e 100644 --- a/tests/modules/admin/models/EnrichmentKeysTest.php +++ b/tests/modules/admin/models/EnrichmentKeysTest.php @@ -29,6 +29,8 @@ * @license http://www.gnu.org/licenses/gpl.html General Public License */ +use Opus\Common\EnrichmentKey; +use Opus\Enrichment\RegexType; use Opus\Translate\Dao; class Admin_Model_EnrichmentKeysTest extends ControllerTestCase @@ -226,4 +228,64 @@ public function testRemoveTranslations() $translations = $database->getTranslations('default'); $this->assertCount(0, $translations); } + + public function testGetTranslation() + { + $model = new Admin_Model_EnrichmentKeys(); + + $key = 'MyTestEnrichment'; + + $model->createTranslations($key); + + $translations = $model->getTranslations($key); + + $model->removeTranslations($key); + + $this->assertCount(6, $translations); + + $translationKeys = $model->getSupportedKeys(); + + foreach ($translationKeys as $translationKey) { + $this->assertArrayHasKey($translationKey, $translations); + $this->assertEquals('MyTestEnrichment', $translations[$translationKey]['de']); + $this->assertEquals('MyTestEnrichment', $translations[$translationKey]['en']); + } + } + + public function testGetEnrichmentConfig() + { + $model = new Admin_Model_EnrichmentKeys(); + + $key = 'MyTestEnrichment'; + + $enrichment = EnrichmentKey::fetchByName($key); + + if ($enrichment === null) { + $enrichment = EnrichmentKey::new(); + $enrichment->setName($key); + $enrichment->setType('RegexType'); + $enrichmentType = new RegexType(); + $enrichmentType->setRegex('/[a-z]+/'); + $enrichment->setOptions($enrichmentType->getOptions()); + $enrichment->store(); + } + + $this->addModelToCleanup($enrichment); + + $model->createTranslations($key); + + $config = $model->getEnrichmentConfig($key); + + // cleanup + $model->removeTranslations($key); + + $this->assertArrayHasKey('name', $config); + $this->assertEquals($key, $config['name']); + $this->assertArrayHasKey('translations', $config); + $this->assertCount(6, $config['translations']); + + $this->assertArrayHasKey('options', $config); + $this->assertEquals('none', $config['options']['validation']); + $this->assertEquals('/[a-z]+/', $config['options']['regex']); + } } diff --git a/tests/resources/enrichments/conferenceType.yml b/tests/resources/enrichments/conferenceType.yml index df0698db3..d519d7f93 100644 --- a/tests/resources/enrichments/conferenceType.yml +++ b/tests/resources/enrichments/conferenceType.yml @@ -1,20 +1,18 @@ # Enrichment configuration for conference types name: conferenceType -type: SelectType +type: Select -label: +translations: + label: de: Art der Konferenzveröffentlichung en: Conference Type -# TODO support additional translation keys (like hint) -# TODO support strict validation settign - -options: | - Konferenzband - Konferenzartikel - Konferenz-Poster - Konferenz-Abstract - Sonstiges - -# TODO support multiple option keys \ No newline at end of file +options: + validation: strict + values: + - Konferenzband + - Konferenzartikel + - Konferenz-Poster + - Konferenz-Abstract + - Sonstiges diff --git a/tests/resources/enrichments/doi-import.yml b/tests/resources/enrichments/doi-import.yml new file mode 100644 index 000000000..4a2eb6eff --- /dev/null +++ b/tests/resources/enrichments/doi-import.yml @@ -0,0 +1,10 @@ +# Enrichment keys for Publish module DOI import (for OPUS 4.8.0) +enrichments: + - name: opus_import_data + - name: local_crossrefDocumentType + - name: local_crossrefLicence + - name: local_doiImportPopulated + - name: local_import_origin + - name: opus_doi_flag + - name: conference_place + - name: conference_title \ No newline at end of file diff --git a/tests/resources/enrichments/multipleKeys.yml b/tests/resources/enrichments/multipleKeys.yml new file mode 100644 index 000000000..172e64ed9 --- /dev/null +++ b/tests/resources/enrichments/multipleKeys.yml @@ -0,0 +1,6 @@ +# Example of configuration for multiple enrichments +enrichments: + - name: testKey1 + - name: testKey2 + - name: testKey3 + - name: testKey4 diff --git a/tests/resources/enrichments/simpleOption.yml b/tests/resources/enrichments/simpleOption.yml new file mode 100644 index 000000000..be975bb76 --- /dev/null +++ b/tests/resources/enrichments/simpleOption.yml @@ -0,0 +1,17 @@ +# Example of SELECT enrichment with simple options +# with 'validation: none' - 'none' meaning invalid stored values are allowed to remain +name: conferenceType + +type: Select + +translations: + label: + de: Art der Konferenzveröffentlichung + en: Conference Type + +options: | + Konferenzband + Konferenzartikel + Konferenz-Poster + Konferenz-Abstract + Sonstiges diff --git a/tests/resources/enrichments/singleKey.yml b/tests/resources/enrichments/singleKey.yml new file mode 100644 index 000000000..9195cf5a7 --- /dev/null +++ b/tests/resources/enrichments/singleKey.yml @@ -0,0 +1 @@ +name: singleEnrichmentKey \ No newline at end of file