diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 4079db4..243164c 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -6,13 +6,21 @@ include: ref: main file: - 'templates/groups/pkp_plugin.yml' - - 'templates/groups/ops_plugins_unit_tests_model.yml' + - 'templates/groups/ops_3_4_plugins_unit_tests_model.yml' + - 'templates/groups/ops_3_4_plugins_cypress_tests_model.yml' .unit_test_template: before_script: - - apt update && apt install poppler-utils imagemagick php{8.1,7.4,7.3}-imagick xmlstarlet -yqq + - apt update && apt install poppler-utils imagemagick php8.2-imagick xmlstarlet -yqq - composer install - sed -i 's/stealth="true"\/>/stealth="true"\/> -->/' /etc/ImageMagick-6/policy.xml - xmlstarlet edit --inplace -u "policymap/policy[@pattern='PDF']/@rights" -v 'read|write' /etc/ImageMagick-6/policy.xml - wget https://github.com/coherentgraphics/cpdf-binaries/blob/master/Linux-Intel-64bit/cpdf?raw=true -O /usr/local/bin/cpdf + - chmod +x /usr/local/bin/cpdf + +.integration_tests_template: + before_script: + - apt update && apt install poppler-utils -yqq + - composer install + - wget https://github.com/coherentgraphics/cpdf-binaries/blob/master/Linux-Intel-64bit/cpdf?raw=true -O /usr/local/bin/cpdf - chmod +x /usr/local/bin/cpdf \ No newline at end of file diff --git a/.vscode/extensions.json b/.vscode/extensions.json deleted file mode 100644 index 52a6eeb..0000000 --- a/.vscode/extensions.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "recommendations": [ - "mhutchie.git-graph", - "GitLab.gitlab-workflow", - "ms-azuretools.vscode-docker", - "streetsidesoftware.code-spell-checker", - "eamodio.gitlens", - "coenraads.bracket-pair-colorizer-2", - "oderwat.indent-rainbow", - "ms-vsliveshare.vsliveshare", - "mrorz.language-gettext", - "aswinkumar863.smarty-template-support", - "neilbrayfield.php-docblocker" - ] -} \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json deleted file mode 100644 index 3dc8b9f..0000000 --- a/.vscode/settings.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "editor.fontSize": 14, - "editor.formatOnSave": false -} \ No newline at end of file diff --git a/README.md b/README.md index 7d2f569..3d9894a 100644 --- a/README.md +++ b/README.md @@ -1,23 +1,26 @@ # Title Page Plugin -This plugin creates a title page on PDF files submitted to preprint servers. The title page is a page added to the beginning of the PDF file, containing a series of information about the preprint when it is posted. After the preprint is posted, the title page is also updated if the preprint relations are changed. +This plugin creates a title page on PDF files submitted to preprint servers. The title page is a page added to the beginning of the PDF file, containing a series of information about the preprint when it is posted. -The common information obtained for PDF title page are: +After the preprint is posted, the title page is updated if the preprint relations are changed. The updating also takes place when the preprint is unposted and posted back again. + +The common information obtained for the PDF title page are: - Relation status -- Publication DOI (if it was published in a journal) +- Publication DOI (if the preprint has been published elsewhere) - Preprint title - Preprint authors - Preprint DOI in current server -- Submission preparation checklist - Submitted date - Posted date +The plugin also adds a new page at the end of the PDF file, containing the server's submission checklist at the moment the preprint is posted first time. + ## Compatibility The latest release of this plugin is compatible with the following PKP applications: -* OPS 3.3.0 +* OPS 3.4.0 ## Plugin Download @@ -26,7 +29,7 @@ To download the plugin, go to the [Releases page](https://github.com/lepidus/tit ## Installation dependencies * [poppler-utils](https://poppler.freedesktop.org/) -This plugin requires the installation of the CPDF binary in your system. You can download it at the [GitHub repository](https://github.com/coherentgraphics/cpdf-binaries). After that, you should make it executable from the command line. In linux systems it can be done by placing the binary in the `/usr/local/bin` directory and running `chmod +x /usr/local/bin/cpdf`. +This plugin requires the installation of the CPDF binary in your system. You can download it at the [GitHub repository](https://github.com/coherentgraphics/cpdf-binaries). After that, you should make it executable from the command line. In Linux systems it can be done by placing the binary in the `/usr/local/bin` directory and running `chmod +x /usr/local/bin/cpdf`. This plugin also requires a logo on your OPS, defined on `Website Settings` > `Appearance` > `Logo`, so you need to upload an image. Images with any kind of transparency (alpha channel) are not supported and **should not** be used. @@ -57,6 +60,6 @@ Since this plugin uses the CPDF library, make sure to check [its license](https: __This plugin is licensed under the GNU General Public License v3.0__ -__Copyright (c) 2020-2021 Lepidus Tecnologia__ +__Copyright (c) 2020-2024 Lepidus Tecnologia__ -__Copyright (c) 2020-2021 SciELO__ +__Copyright (c) 2020-2024 SciELO__ \ No newline at end of file diff --git a/TitlePagePlugin.inc.php b/TitlePageForPreprintPlugin.php similarity index 63% rename from TitlePagePlugin.inc.php rename to TitlePageForPreprintPlugin.php index 27bd21e..4d0209f 100644 --- a/TitlePagePlugin.inc.php +++ b/TitlePageForPreprintPlugin.php @@ -1,33 +1,44 @@ getEnabled()) { - HookRegistry::register('Publication::publish::before', [$this, 'insertTitlePageWhenPublishing']); - HookRegistry::register('Publication::edit', [$this, 'insertTitlePageWhenChangeRelation']); - HookRegistry::register('Schema::get::submissionFile', array($this, 'modifySubmissionFileSchema')); + if ($success && $this->getEnabled($mainContextId)) { + Hook::add('Publication::publish::before', [$this, 'insertTitlePageOnPosting']); + Hook::add('Publication::edit', [$this, 'insertTitlePageWhenChangeRelation']); + Hook::add('Schema::get::submissionFile', array($this, 'modifySubmissionFileSchema')); } - return $registeredPlugin; + + return $success; } public function setEnabled($enabled) @@ -67,12 +78,12 @@ public function modifySubmissionFileSchema($hookName, $params) return false; } - public function insertTitlePageWhenPublishing($hookName, $arguments) + public function insertTitlePageOnPosting($hookName, $params) { $titlePageRequirements = new TitlePageRequirements(); if ($titlePageRequirements->checkRequirements()) { - $publication = $arguments[0]; + $publication = $params[0]; $this->insertTitlePageInPreprint($publication); } } @@ -93,11 +104,11 @@ public function insertTitlePageWhenChangeRelation($hookName, $arguments) public function insertTitlePageInPreprint($publication) { - $submission = Services::get('submission')->get($publication->getData('submissionId')); + $submission = Repo::submission()->get($publication->getData('submissionId')); $context = Application::getContextDAO()->getById($submission->getContextId()); $this->addLocaleData("pt_BR"); - $this->addLocaleData("en_US"); - $this->addLocaleData("es_ES"); + $this->addLocaleData("en"); + $this->addLocaleData("es"); $submissionPressFactory = new SubmissionPressFactory(); $submissionFileUpdater = new SubmissionFileUpdater(); $press = $submissionPressFactory->createSubmissionPress($submission, $publication, $context); diff --git a/classes/GalleyAdapter.inc.php b/classes/GalleyAdapter.php similarity index 86% rename from classes/GalleyAdapter.inc.php rename to classes/GalleyAdapter.php index f41e0e0..4d2980f 100644 --- a/classes/GalleyAdapter.inc.php +++ b/classes/GalleyAdapter.php @@ -1,5 +1,9 @@ submissionFileDao = $submissionFileDao; + $this->submissionFileRepo = $submissionFileRepo; } public function createGalleyAdapter($submission, $galley): GalleyAdapter @@ -18,9 +21,9 @@ public function createGalleyAdapter($submission, $galley): GalleyAdapter list($lastRevisionId, $lastRevisionPath) = $this->getLatestRevision($submissionFile->getId()); if ($this->submissionFileHasNewRevisionWithoutTitlePage($submissionFile, $lastRevisionId)) { - Services::get('submissionFile')->edit($submissionFile, [ + Repo::submissionFile()->edit($submissionFile, [ 'folhaDeRosto' => 'nao', - ], Application::get()->getRequest()); + ]); } return new GalleyAdapter($lastRevisionPath, $galley->getLocale(), $submissionFile->getId(), $lastRevisionId); @@ -28,7 +31,7 @@ public function createGalleyAdapter($submission, $galley): GalleyAdapter public function getLatestRevision($submissionFileId) { - $revisions = $this->submissionFileDao->getRevisions($submissionFileId)->toArray(); + $revisions = $this->submissionFileRepo->getRevisions($submissionFileId)->toArray(); $lastRevision = get_object_vars($revisions[0]); foreach ($revisions as $revision) { diff --git a/classes/Pdf.inc.php b/classes/Pdf.php similarity index 86% rename from classes/Pdf.inc.php rename to classes/Pdf.php index 6b1e79b..ae46682 100644 --- a/classes/Pdf.inc.php +++ b/classes/Pdf.php @@ -1,5 +1,9 @@ getById($submissionFileId); + $submissionFile = Repo::submissionFile()->get($submissionFileId); $revisions = !is_null($submissionFile->getData('revisoes')) ? json_decode($submissionFile->getData('revisoes')) : array(); if (!$hasTitlePage) { array_push($revisions, $newRevisionId); } - Services::get('submissionFile')->edit($submissionFile, [ + Repo::submissionFile()->edit($submissionFile, [ 'folhaDeRosto' => 'sim', 'revisoes' => json_encode($revisions) - ], Application::get()->getRequest()); + ]); } } diff --git a/classes/SubmissionModel.inc.php b/classes/SubmissionModel.php similarity index 78% rename from classes/SubmissionModel.inc.php rename to classes/SubmissionModel.php index 79b1d9b..32fce94 100644 --- a/classes/SubmissionModel.inc.php +++ b/classes/SubmissionModel.php @@ -1,5 +1,7 @@ title = $title; $this->status = $status; $this->doi = ((empty($doi)) ? ("Not informed") : ($doi)); $this->doiJournal = ((empty($doiJournal)) ? ("Not informed") : ($doiJournal)); @@ -29,6 +32,15 @@ public function __construct(string $status, $doi, $doiJournal, string $authors, $this->versionJustification = $versionJustification; } + public function getTitle(string $locale): string + { + if (isset($this->title[$locale])) { + return $this->title[$locale]; + } + + return ''; + } + public function getStatus(): string { return $this->status; diff --git a/classes/SubmissionPress.inc.php b/classes/SubmissionPress.php similarity index 64% rename from classes/SubmissionPress.inc.php rename to classes/SubmissionPress.php index 64ee191..c8b2a1f 100644 --- a/classes/SubmissionPress.inc.php +++ b/classes/SubmissionPress.php @@ -1,27 +1,28 @@ logoForTitlePage = $logoForTitlePage; $this->submission = $submission; - $this->translator = $translator; + $this->checklist = $checklist; + $this->logoForTitlePage = $logoForTitlePage; } private function galleyHasTitlePage($galley) { - $submissionFileDao = DAORegistry::getDAO('SubmissionFileDAO'); - $submissionFile = $submissionFileDao->getById($galley->submissionFileId); + $submissionFile = Repo::submissionFile()->get($galley->submissionFileId); $hasTitlePage = $submissionFile->getData('folhaDeRosto'); return $hasTitlePage == 'sim'; @@ -30,7 +31,7 @@ private function galleyHasTitlePage($galley) public function insertTitlePage($submissionFileUpdater): void { foreach ($this->submission->getGalleys() as $galley) { - $titlePage = new TitlePage($this->submission, $this->logoForTitlePage, $galley->locale, $this->translator); + $titlePage = new TitlePage($this->submission, $this->checklist, $this->logoForTitlePage, $galley->locale); $pdfPath = $galley->getFullFilePath(); if (Pdf::isPdf($pdfPath)) { @@ -42,7 +43,7 @@ public function insertTitlePage($submissionFileUpdater): void try { $hasTitlePage ? $titlePage->updateTitlePage($pdf) : $titlePage->insertTitlePageFirstTime($pdf); $submissionFileUpdater->updateRevisions($submissionFileId, $galley->revisionId, $hasTitlePage); - } catch(Exception $e) { + } catch (\Exception $e) { error_log('Caught exception: ' . $e->getMessage()); } } diff --git a/classes/SubmissionPressFactory.inc.php b/classes/SubmissionPressFactory.inc.php deleted file mode 100644 index 4b637fb..0000000 --- a/classes/SubmissionPressFactory.inc.php +++ /dev/null @@ -1,75 +0,0 @@ -getLogoPath($context); - $dataPress = $this->getDataForPress($submission, $publication); - $galleys = $publication->getData('galleys'); - - foreach ($galleys as $galley) { - $submissionFileDao = DAORegistry::getDAO('SubmissionFileDAO'); - $galleyAdapterFactory = new GalleyAdapterFactory($submissionFileDao); - $submissionGalleys[] = $galleyAdapterFactory->createGalleyAdapter($submission, $galley); - } - - return new SubmissionPress( - $logoPath, - new SubmissionModel($dataPress['status'], $dataPress['doi'], $dataPress['doiJournal'], $dataPress['authors'], $dataPress['submissionDate'], $dataPress['publicationDate'], $dataPress['endorserName'], $dataPress['endorserOrcid'], $dataPress['version'], $dataPress['versionJustification'], $submissionGalleys), - new Translator($context, $submission, $publication) - ); - } - - public function getLogoPath($context) - { - $publicFileManager = new PublicFileManager(); - $filesPath = $publicFileManager->getContextFilesPath($context->getId()); - $logoFilePath = $context->getLocalizedPageHeaderLogo()['uploadName']; - - return $filesPath . DIRECTORY_SEPARATOR . $logoFilePath; - } - - private function getAuthors($publication) - { - $userGroupIds = array_map(function ($author) { - return $author->getData('userGroupId'); - }, $publication->getData('authors')); - $userGroups = array_map(function ($userGroupId) { - $userGroupDao = DAORegistry::getDAO('UserGroupDAO'); - return $userGroupDao->getbyId($userGroupId); - }, array_unique($userGroupIds)); - - return $publication->getAuthorString($userGroups); - } - - private function getDataForPress($submission, $publication) - { - $data = array(); - - $data['doi'] = $publication->getStoredPubId('doi'); - $data['doiJournal'] = $publication->getData('vorDoi'); - $data['authors'] = $this->getAuthors($publication); - $data['version'] = $publication->getData('version'); - $data['versionJustification'] = $publication->getData('versionJustification'); - - $dateSubmitted = strtotime($submission->getData('dateSubmitted')); - $data['submissionDate'] = date('Y-m-d', $dateSubmitted); - $datePublished = strtotime($publication->getData('datePublished')); - $data['publicationDate'] = date('Y-m-d', $datePublished); - - $data['endorserName'] = $publication->getData('endorserName'); - $data['endorserOrcid'] = $publication->getData('endorserOrcid'); - - $status = $publication->getData('relationStatus'); - $relation = array(PUBLICATION_RELATION_NONE => 'publication.relation.none', PUBLICATION_RELATION_SUBMITTED => 'publication.relation.submitted', PUBLICATION_RELATION_PUBLISHED => 'publication.relation.published'); - $data['status'] = ($status) ? ($relation[$status]) : (""); - - return $data; - } -} diff --git a/classes/SubmissionPressFactory.php b/classes/SubmissionPressFactory.php new file mode 100644 index 0000000..ee578a5 --- /dev/null +++ b/classes/SubmissionPressFactory.php @@ -0,0 +1,111 @@ +getContextChecklist($context); + $logoPath = $this->getLogoPath($context); + $dataPress = $this->getDataForPress($submission, $publication); + $galleys = $publication->getData('galleys'); + + foreach ($galleys as $galley) { + $submissionFileRepo = Repo::submissionFile(); + $galleyAdapterFactory = new GalleyAdapterFactory($submissionFileRepo); + $submissionGalleys[] = $galleyAdapterFactory->createGalleyAdapter($submission, $galley); + } + + return new SubmissionPress( + new SubmissionModel( + $dataPress['title'], + $dataPress['status'], + $dataPress['doi'], + $dataPress['doiJournal'], + $dataPress['authors'], + $dataPress['submissionDate'], + $dataPress['publicationDate'], + $dataPress['endorserName'], + $dataPress['endorserOrcid'], + $dataPress['version'], + $dataPress['versionJustification'], + $submissionGalleys + ), + $checklist, + $logoPath + ); + } + + private function getContextChecklist($context): array + { + $checklist = $context->getData('submissionChecklist'); + + foreach ($checklist as $locale => $checklistText) { + preg_match_all('/
  • (.*?)<\/li>/', $checklistText, $matches); + + $checklist[$locale] = $matches[1]; + } + + return $checklist; + } + + + private function getLogoPath($context): string + { + $publicFileManager = new PublicFileManager(); + $filesPath = $publicFileManager->getContextFilesPath($context->getId()); + $logoFilePath = $context->getLocalizedData('pageHeaderLogoImage')['uploadName']; + + return $filesPath . DIRECTORY_SEPARATOR . $logoFilePath; + } + + private function getAuthors($publication) + { + $userGroups = []; + foreach ($publication->getData('authors') as $author) { + $userGroupId = $author->getData('userGroupId'); + + if (!isset($userGroups[$userGroupId])) { + $userGroups[$userGroupId] = Repo::userGroup()->get($userGroupId); + } + } + + $traversableArray = new \ArrayObject($userGroups); + + return $publication->getAuthorString($traversableArray); + } + + private function getDataForPress($submission, $publication) + { + $data = array(); + + $data['title'] = $publication->getTitles(); + $data['doi'] = $publication->getStoredPubId('doi'); + $data['doiJournal'] = $publication->getData('vorDoi'); + $data['authors'] = $this->getAuthors($publication); + $data['version'] = $publication->getData('version'); + $data['versionJustification'] = $publication->getData('versionJustification'); + + $dateSubmitted = strtotime($submission->getData('dateSubmitted')); + $data['submissionDate'] = date('Y-m-d', $dateSubmitted); + $datePublished = strtotime($publication->getData('datePublished')); + $data['publicationDate'] = date('Y-m-d', $datePublished); + + $data['endorserName'] = $publication->getData('endorserName'); + $data['endorserOrcid'] = $publication->getData('endorserOrcid'); + + $status = $publication->getData('relationStatus'); + $relation = array(Publication::PUBLICATION_RELATION_NONE => 'publication.relation.none', Publication::PUBLICATION_RELATION_PUBLISHED => 'publication.relation.published'); + $data['status'] = ($status) ? ($relation[$status]) : (""); + + return $data; + } +} diff --git a/classes/TitlePage.inc.php b/classes/TitlePage.php similarity index 66% rename from classes/TitlePage.inc.php rename to classes/TitlePage.php index 713d621..5f9c50f 100644 --- a/classes/TitlePage.inc.php +++ b/classes/TitlePage.php @@ -1,46 +1,43 @@ submission = $submission; + $this->checklist = $checklist; $this->logo = $logo; $this->locale = $locale; - $this->translator = $translator; - $this->fontName = TCPDF_FONTS::addTTFfont(__DIR__.'/../resources/opensans.ttf', 'TrueTypeUnicode', '', 32); + $this->fontName = TCPDF_FONTS::addTTFfont(__DIR__ . '/../resources/opensans.ttf', 'TrueTypeUnicode', '', 32); $this->titlePageRequirements = new TitlePageRequirements(); } - private function commandSuccessful(int $resultCode): bool - { - if ($resultCode != 0) { - return false; - } - return true; - } - public function removeTitlePage($pdf): void { $separateCommand = "cpdf {$pdf} 2-end -o {$pdf}"; exec($separateCommand, $output, $resultCode); - if (!$this->commandSuccessful($resultCode)) { + if ($resultCode != 0) { $this->titlePageRequirements->showMissingRequirementNotification('plugins.generic.titlePageForPreprint.requirements.removeTitlePageMissing'); - throw new Exception('Title Page Remove Failure'); + throw new \Exception('Title Page Remove Failure'); } } @@ -55,14 +52,14 @@ private function writePublicationStatusOnTitlePage($titlePage) $titlePage->SetFont($this->fontName, '', 10, '', false); if (!empty($this->submission->getStatus())) { - $titlePage->Write(0, $this->translator->translate('plugins.generic.titlePageForPreprint.publicationStatus', $this->locale) . ": " . $this->translator->translate($this->submission->getStatus(), $this->locale), '', 0, 'JUSTIFY', true, 0, false, false, 0); + $titlePage->Write(0, __('plugins.generic.titlePageForPreprint.publicationStatus', [], $this->locale) . ": " . __($this->submission->getStatus(), [], $this->locale), '', 0, 'JUSTIFY', true, 0, false, false, 0); if ($this->submission->getStatus() == 'publication.relation.published') { - $titlePage->Write(0, $this->translator->translate('publication.relation.vorDoi', $this->locale) . ": ", '', 0, 'JUSTIFY', false, 0, false, false, 0); + $titlePage->Write(0, __('publication.relation.vorDoi', [], $this->locale) . ": ", '', 0, 'JUSTIFY', false, 0, false, false, 0); $titlePage->write(0, $this->submission->getJournalDOI(), $this->submission->getJournalDOI(), 0, 'JUSTIFY', true, 0, false, false, 0); } } else { - $titlePage->Write(0, $this->translator->translate('plugins.generic.titlePageForPreprint.publicationStatus', $this->locale) . ": " . $this->translator->translate('plugins.generic.titlePageForPreprint.emptyPublicationStatus', $this->locale), '', 0, 'JUSTIFY', true, 0, false, false, 0); + $titlePage->Write(0, __('plugins.generic.titlePageForPreprint.publicationStatus', [], $this->locale) . ": " . __('plugins.generic.titlePageForPreprint.emptyPublicationStatus', [], $this->locale), '', 0, 'JUSTIFY', true, 0, false, false, 0); } $titlePage->Ln(5); @@ -88,7 +85,7 @@ private function generateTitlePage(): string $this->writePublicationStatusOnTitlePage($titlePage); $titlePage->SetFont($this->fontName, '', 18, '', false); - $normalizedTitle = Normalizer::normalize($this->translator->getTranslatedTitle($this->locale)); + $normalizedTitle = Normalizer::normalize($this->submission->getTitle($this->locale)); $titlePage->Write(0, $normalizedTitle, '', 0, 'C', true, 0, false, false, 0); $titlePage->SetFont($this->fontName, '', 12, '', false); @@ -98,27 +95,27 @@ private function generateTitlePage(): string $titlePage->Write(0, $doiLink, $doiLink, 0, 'C', true, 0, false, false, 0); $titlePage->Ln(10); - $titlePage->Write(0, $this->translator->translate('plugins.generic.titlePageForPreprint.submissionDate', $this->locale, ['subDate' => $this->submission->getSubmissionDate()]), '', 0, 'JUSTIFY', true, 0, false, false, 0); - $titlePage->Write(0, $this->translator->translate('plugins.generic.titlePageForPreprint.publicationDate', $this->locale, ['postDate' => $this->submission->getPublicationDate(), 'version' => $this->submission->getVersion()]), '', 0, 'JUSTIFY', true, 0, false, false, 0); - $titlePage->Write(0, $this->translator->translate('plugins.generic.titlePageForPreprint.dateFormat', $this->locale), '', 0, 'JUSTIFY', true, 0, false, false, 0); + $titlePage->Write(0, __('plugins.generic.titlePageForPreprint.submissionDate', ['subDate' => $this->submission->getSubmissionDate()], $this->locale), '', 0, 'JUSTIFY', true, 0, false, false, 0); + $titlePage->Write(0, __('plugins.generic.titlePageForPreprint.publicationDate', ['postDate' => $this->submission->getPublicationDate(), 'version' => $this->submission->getVersion()], $this->locale), '', 0, 'JUSTIFY', true, 0, false, false, 0); + $titlePage->Write(0, __('plugins.generic.titlePageForPreprint.dateFormat', [], $this->locale), '', 0, 'JUSTIFY', true, 0, false, false, 0); $endorserName = $this->submission->getEndorserName(); $endorserOrcid = $this->submission->getEndorserOrcid(); if(!is_null($endorserOrcid) && !is_null($endorserName)) { $titlePage->Ln(5); - $titlePage->writeHTML($this->translator->translate('plugins.generic.titlePageForPreprint.endorsement', $this->locale, ['endorserName' => $endorserName, 'endorserOrcid' => $endorserOrcid])); + $titlePage->writeHTML(__('plugins.generic.titlePageForPreprint.endorsement', ['endorserName' => $endorserName, 'endorserOrcid' => $endorserOrcid], $this->locale)); } $versionJustification = $this->submission->getVersionJustification(); if($this->submission->getVersion() > 1 && !is_null($versionJustification)) { - $versionJustification = $this->translator->translate('plugins.generic.titlePageForPreprint.versionJustification', $this->locale) . ": " . $versionJustification; + $versionJustification = __('plugins.generic.titlePageForPreprint.versionJustification', [], $this->locale) . ": " . $versionJustification; $titlePage->Ln(5); $titlePage->Write(0, $versionJustification, '', 0, 'JUSTIFY', true, 0, false, false, 0); } $TitlePageFile = self::OUTPUT_DIRECTORY . 'titlePage.pdf'; $titlePage->Output($TitlePageFile, 'F'); - } catch(Exception $e) { + } catch (Exception $e) { $this->titlePageRequirements->showMissingRequirementNotification($errorMessage); throw new Exception('Title Page Generation Failure'); } @@ -134,13 +131,13 @@ public function generateChecklistPage(): string $checklistPage->setPrintFooter(false); $checklistPage->AddPage(); - $checklistPage->Write(0, $this->translator->translate('plugins.generic.titlePageForPreprint.checklistLabel', $this->locale) . ": ", '', 0, 'JUSTIFY', true, 0, false, false, 0); + $checklistPage->Write(0, __('plugins.generic.titlePageForPreprint.checklistLabel', [], $this->locale) . ": ", '', 0, 'JUSTIFY', true, 0, false, false, 0); $checklistPage->SetFont($this->fontName, '', 10, '', false); $checklistPage->Ln(5); $checklistText = ''; - foreach ($this->translator->getTranslatedChecklist($this->locale) as $item) { - $checklistText = $checklistText. ""; + foreach ($this->checklist[$this->locale] as $item) { + $checklistText = $checklistText . ""; } $checklistPage->writeHTMLCell(0, 0, '', '', $checklistText, 1, 1, false, true, 'JUSTIFY', false); $checklistPage->SetFont($this->fontName, '', 11, '', false); @@ -148,7 +145,7 @@ public function generateChecklistPage(): string $checklistPageFile = self::OUTPUT_DIRECTORY . 'checklistPage.pdf'; $checklistPage->Output($checklistPageFile, 'F'); - } catch(Exception $e) { + } catch (Exception $e) { $this->titlePageRequirements->showMissingRequirementNotification('plugins.generic.titlePageForPreprint.requirements.generateChecklistPageMissing'); throw new Exception('Checklist Page Generation Failure'); } @@ -158,12 +155,12 @@ public function generateChecklistPage(): string public function addDocumentHeader($pdf): void { - $linkDOI = "https://doi.org/".$this->submission->getDOI(); - $headerText = $this->translator->translate('plugins.generic.titlePageForPreprint.headerText', $this->locale, ['doiPreprint' => $linkDOI]); + $linkDOI = "https://doi.org/" . $this->submission->getDOI(); + $headerText = __('plugins.generic.titlePageForPreprint.headerText', ['doiPreprint' => $linkDOI], $this->locale); $addHeaderCommand = "cpdf -add-text \"{$headerText}\" -top 15pt -font \"Helvetica\" -font-size 8 {$pdf} -o {$pdf}"; exec($addHeaderCommand, $output, $resultCode); - if (!$this->commandSuccessful($resultCode)) { + if ($resultCode != 0) { $this->titlePageRequirements->showMissingRequirementNotification('plugins.generic.titlePageForPreprint.requirements.addDocumentHeaderMissing'); throw new Exception('Headers Stamping Failure'); } @@ -174,7 +171,7 @@ private function concatenateTitlePage($pdf, $titlePage): void $uniteCommand = "cpdf -merge {$titlePage} {$pdf} -o {$pdf}"; exec($uniteCommand, $output, $resultCode); - if (!$this->commandSuccessful($resultCode)) { + if ($resultCode != 0) { $this->titlePageRequirements->showMissingRequirementNotification('plugins.generic.titlePageForPreprint.requirements.concatenateTitlePageMissing'); throw new Exception('Title Page Concatenation Failure'); } @@ -185,7 +182,7 @@ public function concatenateChecklistPage($pdf, $checklistPage): void $uniteCommand = "cpdf -merge {$pdf} {$checklistPage} -o {$pdf}"; exec($uniteCommand, $output, $resultCode); - if (!$this->commandSuccessful($resultCode)) { + if ($resultCode != 0) { $this->titlePageRequirements->showMissingRequirementNotification('plugins.generic.titlePageForPreprint.requirements.concatenateChecklistPageMissing'); throw new Exception('Checklist Page Concatenation Failure'); } diff --git a/classes/TitlePageDAO.inc.php b/classes/TitlePageDAO.php similarity index 58% rename from classes/TitlePageDAO.inc.php rename to classes/TitlePageDAO.php index 99dfd37..e16909c 100644 --- a/classes/TitlePageDAO.inc.php +++ b/classes/TitlePageDAO.php @@ -9,18 +9,18 @@ * Operations for retrieving data for the title page */ -import('lib.pkp.classes.db.DAO'); +namespace APP\plugins\generic\titlePageForPreprint\classes; -use Illuminate\Database\Capsule\Manager as Capsule; -use Illuminate\Support\Collection; +use PKP\db\DAO; +use Illuminate\Support\Facades\DB; class TitlePageDAO extends DAO { public function getNumberOfRevisions(int $submissionFileId): int { - $numberOfRevisions = Capsule::table('submission_file_revisions') - ->where('submission_file_id', $submissionFileId) - ->count(); + $numberOfRevisions = DB::table('submission_file_revisions') + ->where('submission_file_id', $submissionFileId) + ->count(); return $numberOfRevisions; } diff --git a/classes/TitlePageRequirements.inc.php b/classes/TitlePageRequirements.php similarity index 89% rename from classes/TitlePageRequirements.inc.php rename to classes/TitlePageRequirements.php index cc349f9..234f734 100644 --- a/classes/TitlePageRequirements.inc.php +++ b/classes/TitlePageRequirements.php @@ -1,5 +1,10 @@ context = $context; - $this->publication = $publication; - } - - public function translate($key, $locale, $params = null) - { - AppLocale::requireComponents(LOCALE_COMPONENT_PKP_COMMON, $locale); - AppLocale::requireComponents(LOCALE_COMPONENT_PKP_SUBMISSION, $locale); - AppLocale::requireComponents(LOCALE_COMPONENT_APP_SUBMISSION, $locale); - - return __($key, $params, $locale); - } - - public function getTranslatedChecklist($locale) - { - $rawChecklist = $this->context->getData('submissionChecklist')[$locale]; - foreach ($rawChecklist as $checklistItem) { - $checklist[] = $checklistItem['content']; - } - return $checklist; - } - - public function getTranslatedTitle($locale) - { - return $this->publication->getLocalizedTitle($locale); - } -} diff --git a/composer.json b/composer.json index a66ef64..4c13bca 100644 --- a/composer.json +++ b/composer.json @@ -1,6 +1,5 @@ { "require" : { - "tecnickcom/tcpdf": "6.3.5", "propa/tcpdi": "^1.3" } } diff --git a/cypress/support/commands.js b/cypress/support/commands.js new file mode 100644 index 0000000..28e7cc1 --- /dev/null +++ b/cypress/support/commands.js @@ -0,0 +1,56 @@ +function downloadPdfFile(pdfUrl, directory, pdfFile, txtFile) { + cy.exec('mkdir ' + directory).its('code').should('eq', 0); + cy.exec('curl -o ' + pdfFile + ' ' + pdfUrl).its('code').should('eq', 0); + cy.exec('pdftotext ' + pdfFile + ' ' + txtFile).its('code').should('eq', 0); +} + +function assertNumberPdfPages(pdfFile, expectedNumberOfPages) { + cy.exec('cpdf -pages ' + pdfFile).its('stdout').should('contain', expectedNumberOfPages); +} + +function checkTitlePage(txtFile, submissionData) { + cy.exec("grep '" + submissionData.title + "' " + txtFile).its('code').should('eq', 0); + + if(submissionData.relations == 1) { + cy.exec("grep 'Publication status: This preprint has not been published elsewhere.' " + txtFile).its('code').should('eq', 0); + } else if (submissionData.relations == 3) { + cy.exec("grep 'Publication status: This preprint has been published elsewhere.' " + txtFile).its('code').should('eq', 0); + + if('vorDoi' in submissionData) { + cy.exec("grep 'DOI of the published preprint: " + submissionData.vorDoi + "' " + txtFile).its('code').should('eq', 0); + } + } + + let authorFullName = submissionData.contributors[0]['given'] + ' ' + submissionData.contributors[0]['family']; + cy.exec("grep '" + authorFullName + "' " + txtFile).its('code').should('eq', 0); + + let today = (new Date()).toISOString().split('T')[0]; + cy.exec("grep 'Submitted on: " + today + "' " + txtFile).its('code').should('eq', 0); + cy.exec("grep 'Posted on: " + today + "' " + txtFile).its('code').should('eq', 0); + + cy.exec("grep 'This document is a preprint and its current status is available at:' " + txtFile).its('code').should('eq', 0); +} + +function checkChecklistPage(txtFile) { + cy.exec("grep 'This preprint was submitted under the following conditions:' " + txtFile).its('code').should('eq', 0); + + cy.exec("grep 'This submission meets the requirements outlined in the Author Guidelines.' " + txtFile).its('code').should('eq', 0); + cy.exec("grep 'This submission has not been previously posted.' " + txtFile).its('code').should('eq', 0); + cy.exec("grep 'All references have been checked for accuracy and completeness.' " + txtFile).its('code').should('eq', 0); + cy.exec("grep 'All tables and figures have been numbered and labeled.' " + txtFile).its('code').should('eq', 0); +} + +Cypress.Commands.add('performTitlePageCheckings', function (submissionData, pdfUrl) { + const directory = './plugins/generic/titlePageForPreprint/cypress/tests/result/'; + const pdfFile = directory + 'document.pdf'; + const txtFile = directory + 'document.txt'; + const expectedNumberOfPages = 3; + + downloadPdfFile(pdfUrl, directory, pdfFile, txtFile); + + assertNumberPdfPages(pdfFile, expectedNumberOfPages); + checkTitlePage(txtFile, submissionData); + checkChecklistPage(txtFile); + + cy.exec('rm -r ' + directory).its('code').should('eq', 0); +}); \ No newline at end of file diff --git a/cypress/tests/Test0_pluginSetup.cy.js b/cypress/tests/Test0_pluginSetup.cy.js new file mode 100644 index 0000000..8d55446 --- /dev/null +++ b/cypress/tests/Test0_pluginSetup.cy.js @@ -0,0 +1,13 @@ +describe('Title Page for Preprint - Plugin setup', function () { + it('Enables Title Page for Preprint plugin', function () { + cy.login('dbarnes', null, 'publicknowledge'); + + cy.contains('a', 'Website').click(); + + cy.waitJQuery(); + cy.get('#plugins-button').click(); + + cy.get('input[id^=select-cell-titlepageforpreprintplugin]').check(); + cy.get('input[id^=select-cell-titlepageforpreprintplugin]').should('be.checked'); + }); +}); \ No newline at end of file diff --git a/cypress/tests/Test1_preprintPosting.cy.js b/cypress/tests/Test1_preprintPosting.cy.js new file mode 100644 index 0000000..f0ec152 --- /dev/null +++ b/cypress/tests/Test1_preprintPosting.cy.js @@ -0,0 +1,123 @@ +import '../support/commands.js'; + +function beginSubmission(submissionData) { + cy.get('input[name="locale"][value="en"]').click(); + cy.setTinyMceContent('startSubmission-title-control', submissionData.title); + cy.get('input[name="submissionRequirements"]').check(); + cy.get('input[name="privacyConsent"]').check(); + + cy.contains('button', 'Begin Submission').click(); +} + +function detailsStep(submissionData) { + cy.setTinyMceContent('titleAbstract-abstract-control-en', submissionData.abstract); + submissionData.keywords.forEach(keyword => { + cy.get('#titleAbstract-keywords-control-en').type(keyword, {delay: 0}); + cy.get('#titleAbstract-keywords-control-en').type('{enter}', {delay: 0}); + }); + + cy.contains('button', 'Continue').click(); +} + +function filesStep(submissionData) { + cy.addSubmissionGalleys(submissionData.files); + cy.contains('button', 'Continue').click(); +} + +function contributorsStep(submissionData) { + submissionData.contributors.forEach(authorData => { + cy.contains('button', 'Add Contributor').click(); + cy.get('input[name="givenName-en"]').type(authorData.given, {delay: 0}); + cy.get('input[name="familyName-en"]').type(authorData.family, {delay: 0}); + cy.get('input[name="email"]').type(authorData.email, {delay: 0}); + cy.get('select[name="country"]').select(authorData.country); + + cy.get('.modal__panel:contains("Add Contributor")').find('button').contains('Save').click(); + cy.waitJQuery(); + }); + + cy.contains('button', 'Continue').click(); +} + +describe('Title Page for Preprint Plugin - Title page stamping on preprint posting', function() { + let submissionData; + + before(function() { + Cypress.config('defaultCommandTimeout', 4000); + submissionData = { + title: "A Nightmare on Elm Street", + abstract: 'Teenagers start to dream with a creepy man', + keywords: ['plugin', 'testing'], + relations: 1, + contributors: [ + { + 'given': 'Wes', + 'family': 'Craven', + 'email': 'wes.craven@stab.com', + 'country': 'United States' + } + ], + files: [ + { + 'file': 'dummy.pdf', + 'fileName': 'dummy.pdf', + 'mimeType': 'application/pdf', + 'genre': 'Preprint Text' + } + ] + }; + }); + + it('Author creates new submission with galley', function() { + cy.login('eostrom', null, 'publicknowledge'); + cy.get('div#myQueue a:contains("New Submission")').click(); + + beginSubmission(submissionData); + detailsStep(submissionData); + filesStep(submissionData); + contributorsStep(submissionData); + cy.get('input[name="relationStatus"][value="1"]').check(); + cy.contains('button', 'Continue').click(); + cy.contains('button', 'Submit').click(); + cy.get('.modal__panel:visible').within(() => { + cy.contains('button', 'Submit').click(); + }); + + cy.waitJQuery(); + cy.contains('h1', 'Submission complete'); + }); + it('Moderator posts submission. Title page is stamped on PDF', function () { + cy.findSubmissionAsEditor('dbarnes', null, 'Ostrom'); + cy.get('#publication-button').click(); + cy.get('.pkpHeader__actions button:contains("Post")').click(); + cy.get('.pkp_modal_panel button:contains("Post")').click(); + cy.contains('span', 'Posted'); + + cy.contains('a', 'View').click(); + cy.contains('a', 'PDF').click(); + cy.get('a.download').invoke('attr', 'href').then(pdfUrl => { + cy.performTitlePageCheckings(submissionData, pdfUrl); + }); + }); + it('Title page updating', function () { + cy.findSubmissionAsEditor('dbarnes', null, 'Ostrom'); + cy.get('#publication-button').click(); + cy.get('.pkpHeader__actions button:contains("Unpost")').click(); + cy.get('.modal__panel button:contains("Unpost")').click(); + + submissionData.title = 'A new nightmare'; + cy.setTinyMceContent('titleAbstract-title-control-en', submissionData.title); + cy.get('#titleAbstract button:contains("Save")').click(); + cy.waitJQuery(); + + cy.get('.pkpHeader__actions button:contains("Post")').click(); + cy.get('.pkp_modal_panel button:contains("Post")').click(); + cy.contains('span', 'Posted'); + + cy.contains('a', 'View').click(); + cy.contains('a', 'PDF').click(); + cy.get('a.download').invoke('attr', 'href').then(pdfUrl => { + cy.performTitlePageCheckings(submissionData, pdfUrl); + }); + }); +}); \ No newline at end of file diff --git a/cypress/tests/Test2_relationChanging.cy.js b/cypress/tests/Test2_relationChanging.cy.js new file mode 100644 index 0000000..8576989 --- /dev/null +++ b/cypress/tests/Test2_relationChanging.cy.js @@ -0,0 +1,40 @@ +import '../support/commands.js'; + +describe('Title Page for Preprint Plugin - Title page update on relation changing', function() { + let submissionData; + + before(function() { + Cypress.config('defaultCommandTimeout', 4000); + submissionData = { + title: "A new nightmare", + relations: 3, + vorDoi: 'https://doi.org/10.1234/nonexistentDoi', + contributors: [ + { + 'given': 'Wes', + 'family': 'Craven', + 'email': 'wes.craven@stab.com', + 'country': 'United States' + } + ] + }; + }); + + it('Moderator changes submission relations after it has been posted', function() { + cy.findSubmissionAsEditor('dbarnes', null, 'Ostrom'); + cy.get('#publication-button').click(); + + cy.contains('button', 'Relations').click(); + cy.get('input[name="relationStatus"][value="3"]').check(); + cy.get('input[name="vorDoi"]').type(submissionData.vorDoi, {delay: 0}); + cy.get('.pkpWorkflow__relateForm button:contains("Save")').click(); + cy.waitJQuery(); + + cy.contains('a', 'View').click(); + cy.contains('a', 'PDF').click(); + cy.get('a.download').invoke('attr', 'href').then(pdfUrl => { + cy.performTitlePageCheckings(submissionData, pdfUrl); + }); + }); +}) + diff --git a/cypress/tests/functional/Test1_changeRelation.spec.js b/cypress/tests/functional/Test1_changeRelation.spec.js deleted file mode 100644 index c53edca..0000000 --- a/cypress/tests/functional/Test1_changeRelation.spec.js +++ /dev/null @@ -1,66 +0,0 @@ -import 'core-js/modules/es.regexp.exec'; - -function createDirectory(directory) { - let commandLineForCreateDirectory = 'mkdir ' + directory; - cy.exec(commandLineForCreateDirectory).its('code').should('eq', 0); -} - -function downloadFile(receivedFile, url) { - let commandLineForDownload = 'curl -o ' + receivedFile + url; - cy.exec(commandLineForDownload).its('code').should('eq', 0); -} - -function changeOnePageOfPdfToText(receivedFile, textFile) { - let CommandLineForPdfToText = 'pdftotext -f 1 -l 1 ' + receivedFile + textFile; - cy.exec(CommandLineForPdfToText).its('code').should('eq', 0); -} - -function removeDirectory(directory) { - let CommandLineForRemoveDirectory = 'rm -R ' + directory; - cy.exec(CommandLineForRemoveDirectory).its('code').should('eq', 0); -} - -function checkRelationAfterChoice(textFile) { - cy.readFile(textFile).should('contain','Preprint has been submitted for publication in journal'); -} - -describe('Title Page Plugin relation test', function() { - it('Change relation tests', function() { - cy.visit(Cypress.env('baseUrl') + 'index.php/f/submissions'); - cy.get('input[id=username]').click(); - cy.get('input[id=username]').type(Cypress.env('OPSAdminUsername'), { delay: 0 }); - cy.get('input[id=password]').click(); - cy.get('input[id=password]').type(Cypress.env('OPSAdminPassword'), { delay: 0 }); - cy.get('button[class=submit]').click(); - - cy.get('#archive-button').click(); - cy.get('.listPanel__itemActions > .pkpButton').click(); - cy.get('#publication-button').click(); - cy.get('.pkpPublication__relation > .pkpDropdown > .pkpButton').click(); - - cy.get('input[value^=2]').check(); - cy.get('button[class=pkpButton]').contains('Save').click(); - cy.contains('Save'); - - cy.get('a.pkpButton').click(); - cy.get('.obj_galley_link').click(); - cy.get('.download').then((anchor) => { - const url = anchor.attr('href'); - const directory = './plugins/generic/titlePageForPreprint/cypress/tests/result/'; - const receivedFile = directory +'receivedFile.pdf '; - const textFile = directory + 'titlePage.txt'; - - createDirectory(directory); - - downloadFile(receivedFile, url); - - changeOnePageOfPdfToText(receivedFile, textFile); - - checkRelationAfterChoice(textFile); - - removeDirectory(directory); - }); - - }); -}) - diff --git a/index.php b/index.php deleted file mode 100644 index b96f17a..0000000 --- a/index.php +++ /dev/null @@ -1,17 +0,0 @@ - ["The submission has not been previously published.", "Where available, URLs for the references have been provided."], + "pt_BR" => ["A submissão não foi publicado anteriormente.", "As URLs das referências foram fornecidas."] + ]; protected $locale = "pt_BR"; - protected $title = "Assim Falou Zaratustra-àáâã"; + protected $title = [ + 'pt_BR' => "Assim Falou Zaratustra-àáâã", + 'en' => 'Thus spoke Zarathustra' + ]; protected $authors = "Cleide Silva; João Carlos"; protected $submissionDate = "31/06/2020"; protected $publicationDate = "02/07/2020"; @@ -23,131 +33,21 @@ class PdfHandlingTest extends PKPTestCase protected $endorserOrcid = 'https://orcid.org/0123-4567-89AB-CDEF'; protected $version = "1"; protected $versionJustification = 'Nova versão criada para corrigir erros de ortografia'; - protected $translator; protected function setUp(): void { parent::setUp(); - $this->registerMockSubmissionFileDAO(); - - $this->translator = $this->buildMockTranslator(); - $this->pathOfTestPdf = TESTS_DIRECTORY.ASSETS_DIRECTORY."testOnePage.pdf"; - $this->copyOfTestPdfToRestore = TESTS_DIRECTORY.ASSETS_DIRECTORY."testOnePage_copy.pdf"; + $this->pathOfTestPdf = self::TESTS_DIRECTORY . self::ASSETS_DIRECTORY . "testOnePage.pdf"; + $this->copyOfTestPdfToRestore = self::TESTS_DIRECTORY . self::ASSETS_DIRECTORY . "testOnePage_copy.pdf"; copy($this->pathOfTestPdf, $this->copyOfTestPdfToRestore); - $this->pdfAsText = TESTS_DIRECTORY.ASSETS_DIRECTORY."testOnePage.txt"; + $this->pdfAsText = self::TESTS_DIRECTORY . self::ASSETS_DIRECTORY . "testOnePage.txt"; - $this->pathOfTestPdf2 = TESTS_DIRECTORY.ASSETS_DIRECTORY."testTwoPages.pdf"; - $this->copyOfTestPdfToRestore2 = TESTS_DIRECTORY.ASSETS_DIRECTORY."testTwoPages_copy.pdf"; + $this->pathOfTestPdf2 = self::TESTS_DIRECTORY . self::ASSETS_DIRECTORY . "testTwoPages.pdf"; + $this->copyOfTestPdfToRestore2 = self::TESTS_DIRECTORY . self::ASSETS_DIRECTORY . "testTwoPages_copy.pdf"; copy($this->pathOfTestPdf2, $this->copyOfTestPdfToRestore2); } - protected function getMockedDAOs() - { - return array('SubmissionFileDAO'); - } - - private function registerMockSubmissionFileDAO(): void - { - $submissionFileDAO = $this->getMockBuilder(SubmissionFileDAO::class) - ->setMethods(array('getById')) - ->getMock(); - - $submissionFile = new SubmissionFile(); - $submissionFile->setData('folhaDeRosto', 'nao'); - - $submissionFileDAO->expects($this->any()) - ->method('getById') - ->will($this->returnValue($submissionFile)); - - DAORegistry::registerDAO('SubmissionFileDAO', $submissionFileDAO); - } - - private function buildMockTranslator(): Translator - { - $mockContext = $this->getMockBuilder(Context::class) - ->setMethods(array('getData')) - ->getMock(); - - $mockPublication = $this->getMockBuilder(Publication::class) - ->setMethods(array('getLocalizedTitle')) - ->getMock(); - - $mockTranslator = $this->getMockBuilder(Translator::class) - ->setConstructorArgs(array($mockContext, $mockPublication)) - ->setMethods(array('translate', 'getTranslatedChecklist', 'getTranslatedTitle')) - ->getMock(); - - $mockTranslator->expects($this->any()) - ->method('getTranslatedChecklist') - ->will($this->returnValue($this->checklist)); - - $mockTranslator->expects($this->any()) - ->method('translate') - ->will($this->returnCallback(array($this, 'getTranslation'))); - - $mockTranslator->expects($this->any()) - ->method('getTranslatedTitle') - ->will($this->returnValue($this->getLanguageMap($this->locale)["title"])); - - return $mockTranslator; - } - - public function getTranslation($key, $locale, $params): string - { - $language = $this->getLanguageMap($locale); - $translatedString = $language[$key]; - if ($params) { - foreach ($params as $key => $value) { - $translatedString = strtr($translatedString, ['{!' . $key . '}' => $value]); - } - } - return $translatedString; - } - - private function getLanguageMap($locale): array - { - $languageMap["en_US"] = [ - "publication.relation.none" => "Preprint has not been submitted for publication", - "publication.relation.submitted" => "Preprint has been submitted for publication in journal", - "publication.relation.published" => "Preprint has been published in a journal as an article", - "metadata.property.displayName.doi" => "DOI", - "plugins.generic.titlePageForPreprint.publicationStatus" => "Publication status", - "plugins.generic.titlePageForPreprint.emptyPublicationStatus" => "Not informed by the submitting author", - "plugins.generic.titlePageForPreprint.checklistLabel" => "This preprint was submitted under the following conditions", - "plugins.generic.titlePageForPreprint.submissionDate" => "Submitted on: {!subDate}", - "plugins.generic.titlePageForPreprint.publicationDate" => "Posted on: {!postDate} (version {!version}", - "plugins.generic.titlePageForPreprint.dateFormat" => "(YYYY-MM-DD)", - "plugins.generic.titlePageForPreprint.headerText" => "SciELO Preprints - this preprint has not been peer reviewed", - "plugins.generic.titlePageForPreprint.endorsement" => "The moderation of this preprint received the endorsement of:
    {!endorserName} (ORCID: {!endorserOrcid})", - "plugins.generic.titlePageForPreprint.versionJustification" => "Version justification", - "item1CheckList" => "The submission has not been previously published.", - "item2CheckList" => "Where available, URLs for the references have been provided.", - "title" => "So spoke Zaratustra" - ]; - - $languageMap["pt_BR"] = [ - "publication.relation.none" => "O preprint não foi submetido para publicação", - "publication.relation.submitted" => "O preprint foi submetido para publicação em um periódico", - "publication.relation.published" => "O preprint foi publicado em um periódico como um artigo", - "metadata.property.displayName.doi" => "DOI", - "plugins.generic.titlePageForPreprint.publicationStatus" => "Estado da publicação", - "plugins.generic.titlePageForPreprint.emptyPublicationStatus" => "Não informado pelo autor submissor", - "plugins.generic.titlePageForPreprint.checklistLabel" => "Este preprint foi submetido sob as seguintes condições", - "plugins.generic.titlePageForPreprint.submissionDate" => "Submetido em: {!subDate}", - "plugins.generic.titlePageForPreprint.publicationDate" => "Postado em: {!postDate} (versão {!version})", - "plugins.generic.titlePageForPreprint.dateFormat" => "(AAAA-MM-DD)", - "plugins.generic.titlePageForPreprint.headerText" => "SciELO Preprints - este preprint não foi revisado por pares", - "plugins.generic.titlePageForPreprint.endorsement" => "A moderação deste preprint recebeu o endosso de:
    {!endorserName} (ORCID: {!endorserOrcid})", - "plugins.generic.titlePageForPreprint.versionJustification" => "Justificativa da versão", - "item1CheckList" => "A submissão não foi publicado anteriormente.", - "item2CheckList" => "As URLs das referências foram fornecidas.", - "title" => "Assim Falou Zaratustra-àáâã" - ]; - - return $languageMap[$locale]; - } - protected function tearDown(): void { parent::tearDown(); diff --git a/tests/PdfTest.php b/tests/PdfTest.php index 4868003..0389db8 100644 --- a/tests/PdfTest.php +++ b/tests/PdfTest.php @@ -1,43 +1,44 @@ assertEquals(1, $pdf->getNumberOfPages()); } public function testGetNumberOfPagesWhenPdfHasTwoPages(): void { - $pdf = new Pdf(TESTS_DIRECTORY. ASSETS_DIRECTORY. "testTwoPages.pdf"); + $pdf = new Pdf(PdfHandlingTest::TESTS_DIRECTORY . PdfHandlingTest::ASSETS_DIRECTORY . "testTwoPages.pdf"); $this->assertEquals(2, $pdf->getNumberOfPages()); } public function testGetPath(): void { - $path = TESTS_DIRECTORY. ASSETS_DIRECTORY. "testTwoPages.pdf"; - $pdf = new Pdf(TESTS_DIRECTORY. ASSETS_DIRECTORY. "testTwoPages.pdf"); + $path = PdfHandlingTest::TESTS_DIRECTORY . PdfHandlingTest::ASSETS_DIRECTORY . "testTwoPages.pdf"; + $pdf = new Pdf(PdfHandlingTest::TESTS_DIRECTORY . PdfHandlingTest::ASSETS_DIRECTORY . "testTwoPages.pdf"); $this->assertEquals($path, $pdf->getPath()); } public function testCreateFileNotPdf(): void { $this->expectException(InvalidArgumentException::class); - $pdf = new Pdf(TESTS_DIRECTORY. ASSETS_DIRECTORY. "logo_noAlphaChannel.png"); + $pdf = new Pdf(PdfHandlingTest::TESTS_DIRECTORY . PdfHandlingTest::ASSETS_DIRECTORY . "logo_noAlphaChannel.png"); } public function testIsPdf(): void { - $this->assertTrue(Pdf::isPdf(TESTS_DIRECTORY. ASSETS_DIRECTORY. "testTwoPages.pdf")); + $this->assertTrue(Pdf::isPdf(PdfHandlingTest::TESTS_DIRECTORY . PdfHandlingTest::ASSETS_DIRECTORY . "testTwoPages.pdf")); } public function testIsNotPdf(): void { - $this->assertFalse(Pdf::isPdf(TESTS_DIRECTORY. ASSETS_DIRECTORY. "fileNotPdf.odt")); + $this->assertFalse(Pdf::isPdf(PdfHandlingTest::TESTS_DIRECTORY . PdfHandlingTest::ASSETS_DIRECTORY . "fileNotPdf.odt")); } } ?> \ No newline at end of file diff --git a/tests/SubmissionPressTest.php b/tests/SubmissionPressTest.php index 85dc286..a6cd01b 100644 --- a/tests/SubmissionPressTest.php +++ b/tests/SubmissionPressTest.php @@ -1,9 +1,11 @@ getMockBuilder(GalleyAdapter::class) ->setConstructorArgs($args) - ->setMethods(array('getFullFilePath')) + ->onlyMethods(['getFullFilePath']) ->getMock(); $mockGalley->expects($this->any()) @@ -24,7 +26,7 @@ private function buildMockGalleyAdapter($args): GalleyAdapter private function buildMockSubmissionFileUpdater(): SubmissionFileUpdater { $mockUpdater = $this->getMockBuilder(SubmissionFileUpdater::class) - ->setMethods(array('updateRevisions')) + ->onlyMethods(['updateRevisions']) ->getMock(); return $mockUpdater; @@ -34,8 +36,8 @@ public function testInsertsCorrectlySingleGalley(): void { $galleyPath = $this->pathOfTestPdf; $galley = $this->buildMockGalleyAdapter(array($galleyPath, $this->locale, 1, 2)); - $submission = new SubmissionModel($this->status, $this->doi, $this->doiJournal, $this->authors, $this->submissionDate, $this->publicationDate, $this->endorserName, $this->endorserOrcid, $this->version, $this->versionJustification, array($galley)); - $press = new SubmissionPress($this->logo, $submission, $this->translator); + $submission = new SubmissionModel($this->title, $this->status, $this->doi, $this->doiJournal, $this->authors, $this->submissionDate, $this->publicationDate, $this->endorserName, $this->endorserOrcid, $this->version, $this->versionJustification, array($galley)); + $press = new SubmissionPress($submission, $this->checklist, $this->logo); $press->insertTitlePage($this->buildMockSubmissionFileUpdater()); @@ -48,10 +50,10 @@ public function testInsertsCorrectlyMultipleGalleys(): void $fistGalleyPath = $this->pathOfTestPdf; $secondGalleyPath = $this->pathOfTestPdf2; $firstGalley = $this->buildMockGalleyAdapter(array($fistGalleyPath, $this->locale, 2, 2)); - $secondGalley = $this->buildMockGalleyAdapter(array($secondGalleyPath, "en_US", 3, 2)); - $submission = new SubmissionModel($this->status, $this->doi, $this->doiJournal, $this->authors, $this->submissionDate, $this->publicationDate, $this->endorserName, $this->endorserOrcid, $this->version, $this->versionJustification, array($firstGalley, $secondGalley)); + $secondGalley = $this->buildMockGalleyAdapter(array($secondGalleyPath, "en", 3, 2)); + $submission = new SubmissionModel($this->title, $this->status, $this->doi, $this->doiJournal, $this->authors, $this->submissionDate, $this->publicationDate, $this->endorserName, $this->endorserOrcid, $this->version, $this->versionJustification, array($firstGalley, $secondGalley)); - $press = new SubmissionPress($this->logo, $submission, $this->translator); + $press = new SubmissionPress($submission, $this->checklist, $this->logo); $press->insertTitlePage($this->buildMockSubmissionFileUpdater()); $pdfOfFirstGalley = new Pdf($fistGalleyPath); @@ -64,13 +66,13 @@ public function testInsertsCorrectlyMultipleGalleys(): void public function testMustIgnoreNotPdfFiles(): void { $fistGalleyPath = $this->pathOfTestPdf; - $secondGalleyPath = TESTS_DIRECTORY . ASSETS_DIRECTORY . "fileNotPdf.odt"; + $secondGalleyPath = PdfHandlingTest::TESTS_DIRECTORY . PdfHandlingTest::ASSETS_DIRECTORY . "fileNotPdf.odt"; $firstGalley = $this->buildMockGalleyAdapter(array($fistGalleyPath, $this->locale, 4, 2)); $secondGalley = $this->buildMockGalleyAdapter(array($secondGalleyPath, $this->locale, 5, 2)); - $submission = new SubmissionModel($this->status, $this->doi, $this->doiJournal, $this->authors, $this->submissionDate, $this->publicationDate, $this->endorserName, $this->endorserOrcid, $this->version, $this->versionJustification, array($firstGalley, $secondGalley)); + $submission = new SubmissionModel($this->title, $this->status, $this->doi, $this->doiJournal, $this->authors, $this->submissionDate, $this->publicationDate, $this->endorserName, $this->endorserOrcid, $this->version, $this->versionJustification, array($firstGalley, $secondGalley)); $hashOfNotPdfGalley = md5_file($secondGalleyPath); - $press = new SubmissionPress($this->logo, $submission, $this->translator); + $press = new SubmissionPress($submission, $this->checklist, $this->logo); $press->insertTitlePage($this->buildMockSubmissionFileUpdater()); $pdfOfFirstGalley = new Pdf($fistGalleyPath); diff --git a/tests/SubmissionTest.php b/tests/SubmissionTest.php index 3cc251a..0f8f3e9 100644 --- a/tests/SubmissionTest.php +++ b/tests/SubmissionTest.php @@ -1,10 +1,12 @@ status, $this->doi, $this->doiJournal, $this->authors, $this->submissionDate, $this->publicationDate, $this->endorserName, $this->endorserOrcid, $this->version, $this->versionJustification, $this->galleys); + $title = [ + 'pt_BR' => $this->titlePt, + 'en' => $this->titleEn + ]; + return new SubmissionModel($title, $this->status, $this->doi, $this->doiJournal, $this->authors, $this->submissionDate, $this->publicationDate, $this->endorserName, $this->endorserOrcid, $this->version, $this->versionJustification, $this->galleys); + } + + public function testHasSubmissionTitle(): void + { + $submission = $this->getSubmissionForTests(); + $this->assertEquals($this->titlePt, $submission->getTitle('pt_BR')); + $this->assertEquals($this->titleEn, $submission->getTitle('en')); } public function testHasSubmissionStatus(): void @@ -36,7 +49,7 @@ public function testHasDoi(): void public function testDoiNotInformed(): void { - $submission = new SubmissionModel($this->status, null, $this->doiJournal, $this->authors, $this->submissionDate, $this->publicationDate, $this->endorserName, $this->endorserOrcid, $this->version, $this->versionJustification, $this->galleys); + $submission = new SubmissionModel(['pt_BR' => $this->titlePt], $this->status, null, $this->doiJournal, $this->authors, $this->submissionDate, $this->publicationDate, $this->endorserName, $this->endorserOrcid, $this->version, $this->versionJustification, $this->galleys); $this->assertEquals("Not informed", $submission->getDOI()); } @@ -48,7 +61,7 @@ public function testHasDoiJournal(): void public function testDoiJournalNotInformed(): void { - $submission = new SubmissionModel($this->status, $this->doi, null, $this->authors, $this->submissionDate, $this->publicationDate, $this->endorserName, $this->endorserOrcid, $this->version, $this->versionJustification, $this->galleys); + $submission = new SubmissionModel(['pt_BR' => $this->titlePt], $this->status, $this->doi, null, $this->authors, $this->submissionDate, $this->publicationDate, $this->endorserName, $this->endorserOrcid, $this->version, $this->versionJustification, $this->galleys); $this->assertEquals("Not informed", $submission->getJournalDOI()); } diff --git a/tests/TitlePageOnDatabaseTest.php b/tests/TitlePageOnDatabaseTest.php index 15e5cb8..b1435dd 100644 --- a/tests/TitlePageOnDatabaseTest.php +++ b/tests/TitlePageOnDatabaseTest.php @@ -1,25 +1,46 @@ createMock(SubmissionFileDAO::class); - $submissionFile = $this->createMock(SubmissionFile::class); + $schemaService = new PKPSchemaService(); + $submissionFileDAO = new SubmissionFileDAO($schemaService); + $request = new Request(); + + $submissionFileRepo = $this->getMockBuilder(Repo::submissionFile()::class) + ->setConstructorArgs([$submissionFileDAO, $request, $schemaService]) + ->onlyMethods(['getRevisions']) + ->getMock(); + $obj = new stdClass(); - $obj->fileId = 1; + $obj->fileId = 115; $obj->path = "files/document.pdf"; - $submissionFileDao->method('getRevisions') - ->willReturn(new \Illuminate\Support\Collection([$obj])); - $galleyAdapterFactory = new GalleyAdapterFactory($submissionFileDao); + + $submissionFileRepo->expects($this->any()) + ->method('getRevisions') + ->will($this->returnValue(new \Illuminate\Support\Collection([$obj]))); + + return $submissionFileRepo; + } + + private function checkIfLastRevisionHasTitlePage() + { + $mockSubmissionFileRepo = $this->getSubmissionFileRepoMock(); + $submissionFile = new SubmissionFile(); + $submissionFile->setId(360); + + $galleyAdapterFactory = new GalleyAdapterFactory($mockSubmissionFileRepo); list($lastRevisionId) = $galleyAdapterFactory->getLatestRevision($submissionFile->getId()); $lastRevisionHasTitlePage = !$galleyAdapterFactory->submissionFileHasNewRevisionWithoutTitlePage($submissionFile, $lastRevisionId); return $lastRevisionHasTitlePage; @@ -32,7 +53,8 @@ public function testCanDetectSubmissionFileHasTitlePage(): void public function testCanDetectLegacySubmissionFileHasTitlePage(): void { - $submissionFile = $this->createMock(SubmissionFile::class); + $submissionFile = new SubmissionFile(); + $submissionFile->setId(360); $titlePageTestsDao = new TitlePageTestsDAO(); $numberOfRevisions = 1; $newRevisoes = json_encode([$numberOfRevisions]); diff --git a/tests/TitlePageTest.php b/tests/TitlePageTest.php index b6db729..8bd2f1a 100644 --- a/tests/TitlePageTest.php +++ b/tests/TitlePageTest.php @@ -1,48 +1,48 @@ status, $this->doi, $this->doiJournal, $this->authors, $this->submissionDate, $this->publicationDate, $this->endorserName, $this->endorserOrcid, $this->version, $this->versionJustification); - return new TitlePage($submission, $this->logo, $this->locale, $this->translator); + $submission = new SubmissionModel($this->title, $this->status, $this->doi, $this->doiJournal, $this->authors, $this->submissionDate, $this->publicationDate, $this->endorserName, $this->endorserOrcid, $this->version, $this->versionJustification); + return new TitlePage($submission, $this->checklist, $this->logo, $this->locale); } - private function convertPdfToImage(string $pdfPath, $imagePath): imagick + private function convertPdfToImage(string $pdfPath, $imagePath): Imagick { - $image = new imagick($pdfPath); + $image = new Imagick($pdfPath); $image->setImageFormat('jpeg'); $image->writeImage($imagePath); return $image; } - private function imagesAreEqual(imagick $image1, imagick $image2): void + private function imagesAreEqual(Imagick $image1, Imagick $image2): void { $differenceBetweenThem = $image1->compareImages($image2, Imagick::METRIC_MEANSQUAREERROR); $this->assertEquals(0.0, $differenceBetweenThem[1]); } - private function extractImageFromPdf(pdf $pdf): string + private function extractImageFromPdf(Pdf $pdf): string { - $pathOfExtractedImage = TESTS_DIRECTORY; + $pathOfExtractedImage = self::TESTS_DIRECTORY; $result = shell_exec("pdfimages -f 1 -png ". $pdf->getPath() . " " . $pathOfExtractedImage); $extractedImage = $pathOfExtractedImage . DIRECTORY_SEPARATOR . "-000.png"; return $extractedImage; } - private function convertPdfToText(pdf $pdf, int $startPage = 1): void + private function searchForTextInPdf(Pdf $pdf, string $targetText, int $startPage = 1): bool { shell_exec("pdftotext -f " . $startPage . " ". $pdf->getPath() . " " . $this->pdfAsText); - } - private function searchInTextFiles($targetString, $filePath): string - { - $searchResult = shell_exec("grep '$targetString' ". $filePath); - return trim($searchResult); + $pdfText = file_get_contents($this->pdfAsText, FILE_TEXT); + $pdfText = str_replace(["\r", "\n"], ' ', $pdfText); + + return str_contains($pdfText, $targetText); } public function testInsertInExistingPdfFileCreatesNewPages(): void @@ -60,7 +60,7 @@ public function testInsertingInExistingPdfStampsChecklistOnLastPage(): void $pdf = new Pdf($this->pathOfTestPdf); $originalFile = $pdf->getPath(); - $originalFileCopy = OUTPUT_DIRECTORY . "original_file_copy.pdf"; + $originalFileCopy = self::OUTPUT_DIRECTORY . "original_file_copy.pdf"; copy($originalFile, $originalFileCopy); $checklistPage = $titlePage->generateChecklistPage(); @@ -68,18 +68,15 @@ public function testInsertingInExistingPdfStampsChecklistOnLastPage(): void rename($originalFileCopy, $originalFile); $numberOfPages = $pdf->getNumberOfPages(); - $this->convertPdfToText($pdf, $numberOfPages); - - $expectedLabel = "Este preprint foi submetido sob as seguintes condições:"; - $labelSearchResults = $this->searchInTextFiles($expectedLabel, $this->pdfAsText); - $this->assertEquals($expectedLabel, $labelSearchResults); - - $firstItem = $this->checklist[0]; - $resultOfSearchForFirstItemOfChecklist = $this->searchInTextFiles($firstItem, $this->pdfAsText); - $this->assertEquals($firstItem, $resultOfSearchForFirstItemOfChecklist); - $secondItem = $this->checklist[1]; - $resultOfSearchForSecondItemOfChecklist = $this->searchInTextFiles($secondItem, $this->pdfAsText); - $this->assertEquals($secondItem, $resultOfSearchForSecondItemOfChecklist); + + $expectedLabel = __('plugins.generic.titlePageForPreprint.checklistLabel', [], $this->locale) . ':'; + $this->assertTrue($this->searchForTextInPdf($pdf, $expectedLabel, $numberOfPages)); + + $firstItem = $this->checklist[$this->locale][0]; + $this->assertTrue($this->searchForTextInPdf($pdf, $firstItem, $numberOfPages)); + + $secondItem = $this->checklist[$this->locale][1]; + $this->assertTrue($this->searchForTextInPdf($pdf, $secondItem, $numberOfPages)); } public function testInsertingInExistingPdfStampsLogo(): void @@ -90,7 +87,7 @@ public function testInsertingInExistingPdfStampsLogo(): void $titlePage->insertTitlePageFirstTime($pdf); $extractedImage = $this->extractImageFromPdf($pdf); - $this->imagesAreEqual(new imagick($this->logo), new imagick($extractedImage)); + $this->imagesAreEqual(new Imagick($this->logo), new Imagick($extractedImage)); unlink($extractedImage); } @@ -101,23 +98,24 @@ public function testInsertingInExistingPdfStampsRelation(): void $titlePage->insertTitlePageFirstTime($pdf); - $this->convertPdfToText($pdf); - $expectedText = "Estado da publicação: O preprint não foi submetido para publicação"; - $searchResult = $this->searchInTextFiles($expectedText, $this->pdfAsText); - $this->assertEquals($expectedText, $searchResult); + $expectedText = __('plugins.generic.titlePageForPreprint.publicationStatus', [], $this->locale) + . ': ' . __('publication.relation.none', [], $this->locale); + + $this->assertTrue($this->searchForTextInPdf($pdf, $expectedText)); } public function testInsertingInExistingPdfStampsNotInformedRelation(): void { - $titlePage = new TitlePage(new SubmissionModel("", $this->doi, $this->doiJournal, $this->authors, $this->submissionDate, $this->publicationDate, $this->endorserName, $this->endorserOrcid, $this->version, $this->versionJustification), $this->logo, $this->locale, $this->translator); + $submission = new SubmissionModel($this->title, "", $this->doi, $this->doiJournal, $this->authors, $this->submissionDate, $this->publicationDate, $this->endorserName, $this->endorserOrcid, $this->version, $this->versionJustification); + $titlePage = new TitlePage($submission, $this->checklist, $this->logo, $this->locale); $pdf = new Pdf($this->pathOfTestPdf); $titlePage->insertTitlePageFirstTime($pdf); - $this->convertPdfToText($pdf); - $expectedText = "Estado da publicação: Não informado pelo autor submissor"; - $searchResult = $this->searchInTextFiles($expectedText, $this->pdfAsText); - $this->assertEquals($expectedText, $searchResult); + $expectedText = __('plugins.generic.titlePageForPreprint.publicationStatus', [], $this->locale) + . ': ' . __('plugins.generic.titlePageForPreprint.emptyPublicationStatus', [], $this->locale); + + $this->assertTrue($this->searchForTextInPdf($pdf, $expectedText)); } public function testInsertingInExistingPdfStampsTitle(): void @@ -127,10 +125,7 @@ public function testInsertingInExistingPdfStampsTitle(): void $titlePage->insertTitlePageFirstTime($pdf); - $this->convertPdfToText($pdf); - $expectedText = $this->title; - $searchResult = $this->searchInTextFiles($expectedText, $this->pdfAsText); - $this->assertEquals($expectedText, $searchResult); + $this->assertTrue($this->searchForTextInPdf($pdf, $this->title[$this->locale])); } public function testInsertingInExistingPdfStampsAuthors(): void @@ -140,10 +135,7 @@ public function testInsertingInExistingPdfStampsAuthors(): void $titlePage->insertTitlePageFirstTime($pdf); - $this->convertPdfToText($pdf); - $expectedText = $this->authors; - $searchResult = $this->searchInTextFiles($expectedText, $this->pdfAsText); - $this->assertEquals($expectedText, $searchResult); + $this->assertTrue($this->searchForTextInPdf($pdf, $this->authors)); } public function testInsertingInExistingPdfStampsDOI(): void @@ -153,10 +145,8 @@ public function testInsertingInExistingPdfStampsDOI(): void $titlePage->insertTitlePageFirstTime($pdf); - $this->convertPdfToText($pdf); $expectedText = "https://doi.org/" . $this->doi; - $searchResult = $this->searchInTextFiles($expectedText, $this->pdfAsText); - $this->assertEquals($expectedText, $searchResult); + $this->assertTrue($this->searchForTextInPdf($pdf, $expectedText)); } public function testInsertingInExistingPdfStampsSubmissionDate(): void @@ -166,10 +156,8 @@ public function testInsertingInExistingPdfStampsSubmissionDate(): void $titlePage->insertTitlePageFirstTime($pdf); - $this->convertPdfToText($pdf); - $expectedText = $this->translator->translate('plugins.generic.titlePageForPreprint.submissionDate', $this->locale, ['subDate' => $this->submissionDate]); - $searchResult = $this->searchInTextFiles($expectedText, $this->pdfAsText); - $this->assertEquals($expectedText, $searchResult); + $expectedText = __('plugins.generic.titlePageForPreprint.submissionDate', ['subDate' => $this->submissionDate], $this->locale); + $this->assertTrue($this->searchForTextInPdf($pdf, $expectedText)); } public function testInsertingInExistingPdfStampsPublicationDate(): void @@ -179,10 +167,8 @@ public function testInsertingInExistingPdfStampsPublicationDate(): void $titlePage->insertTitlePageFirstTime($pdf); - $this->convertPdfToText($pdf); - $expectedText = $this->translator->translate('plugins.generic.titlePageForPreprint.publicationDate', $this->locale, ['postDate' => $this->publicationDate, 'version' => $this->version]); - $searchResult = $this->searchInTextFiles($expectedText, $this->pdfAsText); - $this->assertEquals($expectedText, $searchResult); + $expectedText = __('plugins.generic.titlePageForPreprint.publicationDate', ['postDate' => $this->publicationDate, 'version' => $this->version], $this->locale); + $this->assertTrue($this->searchForTextInPdf($pdf, $expectedText)); } public function testDontStampVersionJustificationOnFirstVersion(): void @@ -192,10 +178,8 @@ public function testDontStampVersionJustificationOnFirstVersion(): void $titlePage->insertTitlePageFirstTime($pdf); - $this->convertPdfToText($pdf); - $expectedText = "Justificativa da versão: " . $this->versionJustification; - $searchResult = $this->searchInTextFiles($expectedText, $this->pdfAsText); - $this->assertEquals("", $searchResult); + $expectedText = __('plugins.generic.titlePageForPreprint.versionJustification', [], $this->locale) . ': ' . $this->versionJustification; + $this->assertFalse($this->searchForTextInPdf($pdf, $expectedText)); } public function testStampsVersionJustificationFromSecondVersion(): void @@ -206,10 +190,8 @@ public function testStampsVersionJustificationFromSecondVersion(): void $titlePage->insertTitlePageFirstTime($pdf); - $this->convertPdfToText($pdf); - $expectedText = "Justificativa da versão: " . $this->versionJustification; - $searchResult = $this->searchInTextFiles($expectedText, $this->pdfAsText); - $this->assertEquals($expectedText, $searchResult); + $expectedText = __('plugins.generic.titlePageForPreprint.versionJustification', [], $this->locale) . ': ' . $this->versionJustification; + $this->assertTrue($this->searchForTextInPdf($pdf, $expectedText)); } public function testInsertingInExistingPdfStampsEndorsement(): void @@ -219,10 +201,8 @@ public function testInsertingInExistingPdfStampsEndorsement(): void $titlePage->insertTitlePageFirstTime($pdf); - $this->convertPdfToText($pdf); - $expectedText = "A moderação deste preprint recebeu o endosso de:"; - $searchResult = $this->searchInTextFiles($expectedText, $this->pdfAsText); - $this->assertEquals($expectedText, $searchResult); + $expectedText = __('plugins.generic.titlePageForPreprint.endorsement', [], $this->locale); + $this->assertTrue($this->searchForTextInPdf($pdf, $expectedText)); } public function testInsertingInExistingPdfStampsHeader(): void @@ -232,16 +212,14 @@ public function testInsertingInExistingPdfStampsHeader(): void $titlePage->addDocumentHeader($this->pathOfTestPdf); - $this->convertPdfToText($pdf); - $expectedText = "SciELO Preprints - este preprint não foi revisado por pares"; - $searchResult = $this->searchInTextFiles($expectedText, $this->pdfAsText); - $this->assertEquals($expectedText, $searchResult); + $expectedText = __('plugins.generic.titlePageForPreprint.headerText', ['doiPreprint' => $this->doi], $this->locale); + $this->assertTrue($this->searchForTextInPdf($pdf, $expectedText)); } public function testInsertingInExistingPdfDontChangeOriginal(): void { $titlePage = $this->getTitlePageForTests(); - $pdfOriginalWithHeaders = OUTPUT_DIRECTORY . "originalWithHeaders.pdf"; + $pdfOriginalWithHeaders = self::OUTPUT_DIRECTORY . "originalWithHeaders.pdf"; copy($this->pathOfTestPdf, $pdfOriginalWithHeaders); $titlePage->addDocumentHeader($pdfOriginalWithHeaders); @@ -250,8 +228,8 @@ public function testInsertingInExistingPdfDontChangeOriginal(): void $fileImageOriginalWithHeaders = 'imagem_pdf_original.jpg'; $fileImagePdfWithTitlePage = 'imagem_pdf_folhaderosto.jpg'; - $imageOfOriginalPdf = $this->convertPdfToImage($pdfOriginalWithHeaders.'[0]', $fileImageOriginalWithHeaders); - $imageOfPdfWithTitlePage = $this->convertPdfToImage($pdfWithTitlePage->getPath().'[1]', $fileImagePdfWithTitlePage); + $imageOfOriginalPdf = $this->convertPdfToImage($pdfOriginalWithHeaders . '[0]', $fileImageOriginalWithHeaders); + $imageOfPdfWithTitlePage = $this->convertPdfToImage($pdfWithTitlePage->getPath() . '[1]', $fileImagePdfWithTitlePage); $this->imagesAreEqual($imageOfOriginalPdf, $imageOfPdfWithTitlePage); unlink($pdfOriginalWithHeaders); unlink($fileImageOriginalWithHeaders); @@ -260,95 +238,78 @@ public function testInsertingInExistingPdfDontChangeOriginal(): void public function testStampsTitlePageWithRelationTranslatedToGalleyLanguage(): void { - $titlePage = new TitlePage(new SubmissionModel($this->status, $this->doi, $this->doiJournal, $this->authors, $this->submissionDate, $this->publicationDate, $this->endorserName, $this->endorserOrcid, $this->version, $this->versionJustification), $this->logo, "en_US", $this->translator); + $submission = new SubmissionModel($this->title, $this->status, $this->doi, $this->doiJournal, $this->authors, $this->submissionDate, $this->publicationDate, $this->endorserName, $this->endorserOrcid, $this->version, $this->versionJustification); + $titlePage = new TitlePage($submission, $this->checklist, $this->logo, "en"); $pdf = new Pdf($this->pathOfTestPdf); $titlePage->insertTitlePageFirstTime($pdf); - $this->convertPdfToText($pdf); - $expectedText = "Publication status: Preprint has not been submitted for publication"; - $searchResult = $this->searchInTextFiles($expectedText, $this->pdfAsText); - $this->assertEquals($expectedText, $searchResult); + $expectedText = __('plugins.generic.titlePageForPreprint.publicationStatus', [], 'en') + . ': ' . __('publication.relation.none', [], 'en'); + $this->assertTrue($this->searchForTextInPdf($pdf, $expectedText)); } public function testInsertingInExistingPdfStampsNotInformedRelationTranslated(): void { - $titlePage = new TitlePage(new SubmissionModel("", $this->doi, $this->doiJournal, $this->authors, $this->submissionDate, $this->publicationDate, $this->endorserName, $this->endorserOrcid, $this->version, $this->versionJustification), $this->logo, "en_US", $this->translator); + $submission = new SubmissionModel($this->title, "", $this->doi, $this->doiJournal, $this->authors, $this->submissionDate, $this->publicationDate, $this->endorserName, $this->endorserOrcid, $this->version, $this->versionJustification); + $titlePage = new TitlePage($submission, $this->checklist, $this->logo, "en"); $pdf = new Pdf($this->pathOfTestPdf); $titlePage->insertTitlePageFirstTime($pdf); - $this->convertPdfToText($pdf); - $expectedText = "Publication status: Not informed by the submitting author"; - $searchResult = $this->searchInTextFiles($expectedText, $this->pdfAsText); - $this->assertEquals($expectedText, $searchResult); + $expectedText = __('plugins.generic.titlePageForPreprint.publicationStatus', [], 'en') + . ": " . __('plugins.generic.titlePageForPreprint.emptyPublicationStatus', [], 'en'); + $this->assertTrue($this->searchForTextInPdf($pdf, $expectedText)); } - public function testStampsTitlePageWithChecklistLabelTranslatedToGalleyLanguage(): void + public function testStampsChecklistTranslatedToGalleyLanguage(): void { - $titlePage = new TitlePage(new SubmissionModel($this->status, $this->doi, $this->doiJournal, $this->authors, $this->submissionDate, $this->publicationDate, $this->endorserName, $this->endorserOrcid, $this->version, $this->versionJustification), $this->logo, $this->locale, $this->translator); + $submission = new SubmissionModel($this->title, $this->status, $this->doi, $this->doiJournal, $this->authors, $this->submissionDate, $this->publicationDate, $this->endorserName, $this->endorserOrcid, $this->version, $this->versionJustification); + $titlePage = new TitlePage($submission, $this->checklist, $this->logo, 'en'); $pdf = new Pdf($this->pathOfTestPdf); $originalFile = $pdf->getPath(); - $originalFileCopy = OUTPUT_DIRECTORY . "original_file_copy.pdf"; + $originalFileCopy = self::OUTPUT_DIRECTORY . "original_file_copy.pdf"; copy($originalFile, $originalFileCopy); $checklistPage = $titlePage->generateChecklistPage(); $titlePage->concatenateChecklistPage($originalFileCopy, $checklistPage); rename($originalFileCopy, $originalFile); - $this->convertPdfToText($pdf); - $expectedText = $this->translator->translate("plugins.generic.titlePageForPreprint.checklistLabel", $this->locale) . ':'; - $searchResult = substr($this->searchInTextFiles($expectedText, $this->pdfAsText), 1); - $this->assertEquals($expectedText, $searchResult); - } - - public function testStampsTitlePageWithChecklistTranslatedToGalleyLanguage(): void - { - $titlePage = new TitlePage(new SubmissionModel($this->status, $this->doi, $this->doiJournal, $this->authors, $this->submissionDate, $this->publicationDate, $this->endorserName, $this->endorserOrcid, $this->version, $this->versionJustification), $this->logo, $this->locale, $this->translator); - $pdf = new Pdf($this->pathOfTestPdf); + $numberOfPages = $pdf->getNumberOfPages(); - $originalFile = $pdf->getPath(); - $originalFileCopy = OUTPUT_DIRECTORY . "original_file_copy.pdf"; - copy($originalFile, $originalFileCopy); + $expectedText = __("plugins.generic.titlePageForPreprint.checklistLabel", [], 'en') . ': '; + $this->assertTrue($this->searchForTextInPdf($pdf, $expectedText, $numberOfPages)); - $checklistPage = $titlePage->generateChecklistPage(); - $titlePage->concatenateChecklistPage($originalFileCopy, $checklistPage); - rename($originalFileCopy, $originalFile); + $firstItem = $this->checklist['en'][0]; + $this->assertTrue($this->searchForTextInPdf($pdf, $firstItem, $numberOfPages)); - $this->convertPdfToText($pdf); - $firstItem = $this->translator->translate("item1CheckList", $this->locale); - $resultOfSearchForFirstItemOfChecklist = $this->searchInTextFiles($firstItem, $this->pdfAsText); - $this->assertEquals($firstItem, $resultOfSearchForFirstItemOfChecklist); - $secondItem = $this->translator->translate("item2CheckList", $this->locale); - $resultOfSearchForSecondItemOfChecklist = $this->searchInTextFiles($secondItem, $this->pdfAsText); - $this->assertEquals($secondItem, $resultOfSearchForSecondItemOfChecklist); + $secondItem = $this->checklist['en'][1]; + $this->assertTrue($this->searchForTextInPdf($pdf, $secondItem, $numberOfPages)); } public function testStampsTitlePageWithSubmissionDateTranslatedToGalleyLanguage(): void { - $titlePage = new TitlePage(new SubmissionModel($this->status, $this->doi, $this->doiJournal, $this->authors, $this->submissionDate, $this->publicationDate, $this->endorserName, $this->endorserOrcid, $this->version, $this->versionJustification), $this->logo, $this->locale, $this->translator); + $submission = new SubmissionModel($this->title, $this->status, $this->doi, $this->doiJournal, $this->authors, $this->submissionDate, $this->publicationDate, $this->endorserName, $this->endorserOrcid, $this->version, $this->versionJustification); + $titlePage = new TitlePage($submission, $this->checklist, $this->logo, 'en'); $pdf = new Pdf($this->pathOfTestPdf); $titlePage->insertTitlePageFirstTime($pdf); - $this->convertPdfToText($pdf); - $expectedText = $this->translator->translate('plugins.generic.titlePageForPreprint.submissionDate', $this->locale, ['subDate' => $this->submissionDate]); - $searchResult = $this->searchInTextFiles($expectedText, $this->pdfAsText); - $this->assertEquals($expectedText, $searchResult); + $expectedText = __('plugins.generic.titlePageForPreprint.submissionDate', ['subDate' => $this->submissionDate], 'en'); + $this->assertTrue($this->searchForTextInPdf($pdf, $expectedText)); } public function testStampsTitlePageWithPublicationDateTranslatedToGalleyLanguage(): void { - $titlePage = new TitlePage(new SubmissionModel($this->status, $this->doi, $this->doiJournal, $this->authors, $this->submissionDate, $this->publicationDate, $this->endorserName, $this->endorserOrcid, $this->version, $this->versionJustification), $this->logo, $this->locale, $this->translator); + $submission = new SubmissionModel($this->title, $this->status, $this->doi, $this->doiJournal, $this->authors, $this->submissionDate, $this->publicationDate, $this->endorserName, $this->endorserOrcid, $this->version, $this->versionJustification); + $titlePage = new TitlePage($submission, $this->checklist, $this->logo, 'en'); $pdf = new Pdf($this->pathOfTestPdf); $titlePage->insertTitlePageFirstTime($pdf); - $this->convertPdfToText($pdf); - $expectedText = $this->translator->translate('plugins.generic.titlePageForPreprint.publicationDate', $this->locale, ['postDate' => $this->publicationDate, 'version' => $this->version]); - $searchResult = $this->searchInTextFiles($expectedText, $this->pdfAsText); - $this->assertEquals($expectedText, $searchResult); + $expectedText = __('plugins.generic.titlePageForPreprint.publicationDate', ['postDate' => $this->publicationDate, 'version' => $this->version], 'en'); + $this->assertTrue($this->searchForTextInPdf($pdf, $expectedText)); } public function testStampsTitlePageWithDateFormat(): void @@ -358,22 +319,19 @@ public function testStampsTitlePageWithDateFormat(): void $titlePage->insertTitlePageFirstTime($pdf); - $this->convertPdfToText($pdf); - $expectedText = "(AAAA-MM-DD)"; - $searchResult = $this->searchInTextFiles($expectedText, $this->pdfAsText); - $this->assertEquals($expectedText, $searchResult); + $expectedText = __('plugins.generic.titlePageForPreprint.dateFormat', [], $this->locale); + $this->assertTrue($this->searchForTextInPdf($pdf, $expectedText)); } public function testStampsTitlePageWithDateFormatTranslatedToGalleyLanguage(): void { - $titlePage = new TitlePage(new SubmissionModel($this->status, $this->doi, $this->doiJournal, $this->authors, $this->submissionDate, $this->publicationDate, $this->endorserName, $this->endorserOrcid, $this->version, $this->versionJustification), $this->logo, $this->locale, $this->translator); + $submission = new SubmissionModel($this->title, $this->status, $this->doi, $this->doiJournal, $this->authors, $this->submissionDate, $this->publicationDate, $this->endorserName, $this->endorserOrcid, $this->version, $this->versionJustification); + $titlePage = new TitlePage($submission, $this->checklist, $this->logo, 'en'); $pdf = new Pdf($this->pathOfTestPdf); $titlePage->insertTitlePageFirstTime($pdf); - $this->convertPdfToText($pdf); - $expectedText = $this->translator->translate('plugins.generic.titlePageForPreprint.dateFormat', $this->locale); - $searchResult = $this->searchInTextFiles($expectedText, $this->pdfAsText); - $this->assertEquals($expectedText, $searchResult); + $expectedText = __('plugins.generic.titlePageForPreprint.dateFormat', [], 'en'); + $this->assertTrue($this->searchForTextInPdf($pdf, $expectedText)); } } diff --git a/tests/TitlePageTestsDAO.inc.php b/tests/TitlePageTestsDAO.php similarity index 81% rename from tests/TitlePageTestsDAO.inc.php rename to tests/TitlePageTestsDAO.php index 525269f..98f1896 100644 --- a/tests/TitlePageTestsDAO.inc.php +++ b/tests/TitlePageTestsDAO.php @@ -1,15 +1,15 @@ insert([ + DB::table('submission_file_settings')->insert([ 'submission_file_id' => $submissionFile->getId(), 'setting_name' => 'folhaDeRosto', 'setting_value' => $folhaDeRosto, @@ -19,7 +19,7 @@ public function addTitlePagePresenceSettingToSubmissionFile($submissionFile, str public function addRevisionsWithTitlePageSettingToSubmissionFile($submissionFile, string $revisoes) { - Capsule::table('submission_file_settings')->insert([ + DB::table('submission_file_settings')->insert([ 'submission_file_id' => $submissionFile->getId(), 'setting_name' => 'revisoes', 'setting_value' => $revisoes, @@ -29,7 +29,7 @@ public function addRevisionsWithTitlePageSettingToSubmissionFile($submissionFile public function updateRevisionsWithTitlePageSettingFromSubmissionFile($submissionFile, string $revisoes) { - Capsule::table('submission_file_settings') + DB::table('submission_file_settings') ->where('submission_file_id', $submissionFile->getId()) ->where('setting_name', 'revisoes') ->update(['setting_value' => $revisoes]); @@ -37,7 +37,7 @@ public function updateRevisionsWithTitlePageSettingFromSubmissionFile($submissio public function insertTestFile(string $path, string $mimetype): int { - $id = Capsule::table('files')->insertGetId([ + $id = DB::table('files')->insertGetId([ 'path' => $path, 'mimetype' => $mimetype ]); diff --git a/version.xml b/version.xml index cc14622..0ede6bc 100644 --- a/version.xml +++ b/version.xml @@ -4,8 +4,8 @@