diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 0605aa5..633bf25 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -3,12 +3,7 @@ variables:
include:
- project: 'documentacao-e-tarefas/modelosparaintegracaocontinua'
- ref: stable-3_3_0
+ ref: main
file:
- 'templates/groups/pkp_plugin.yml'
- 'templates/groups/omp/unit_tests.yml'
-
-.unit_test_template:
- before_script:
- - rm -rf lib/APIKeyEncryption
- - git submodule update --init --depth 1
diff --git a/.gitmodules b/.gitmodules
deleted file mode 100644
index 9adff2e..0000000
--- a/.gitmodules
+++ /dev/null
@@ -1,3 +0,0 @@
-[submodule "lib/APIKeyEncryption"]
- path = lib/APIKeyEncryption
- url = https://github.com/lepidus/APIKeyEncryption.git
diff --git a/README.md b/README.md
index fe4f01f..dc8e7d2 100644
--- a/README.md
+++ b/README.md
@@ -9,6 +9,7 @@ Work in Progress Integration of OMP and [Thoth](https://thoth.pub/) for communic
This plugin is compatible with the following PKP applications:
- OMP 3.3.0-x
+- OMP 3.4.0-x
## Requirements
diff --git a/ThothPlugin.inc.php b/ThothPlugin.inc.php
index 8845d80..ac27bff 100644
--- a/ThothPlugin.inc.php
+++ b/ThothPlugin.inc.php
@@ -10,11 +10,15 @@
* Distributed under the GNU GPL v3. For full terms see the file docs/COPYING.
*
* @class ThothPlugin
+ *
* @ingroup plugins_generic_thoth
*
* @brief Plugin for integration with Thoth for communication and synchronization of book data between the two platforms
*/
+use APP\plugins\generic\thoth\classes\APIKeyEncryption;
+use PKP\core\JSONMessage;
+
import('lib.pkp.classes.plugins.GenericPlugin');
import('plugins.generic.thoth.classes.ThothBadgeRender');
import('plugins.generic.thoth.classes.ThothNotification');
@@ -129,10 +133,9 @@ public function getThothClient($contextId = null)
$password = $this->getSetting($contextId, 'password');
if (!$email || !$password) {
- throw new ThothException("Credentials not configured", 0);
+ throw new ThothException('Credentials not configured', 0);
}
- import('plugins.generic.thoth.lib.APIKeyEncryption.APIKeyEncryption');
$password = APIKeyEncryption::decryptString($password);
$testEnvironment = $this->getSetting($contextId, 'testEnvironment');
diff --git a/ThothSettingsForm.inc.php b/ThothSettingsForm.inc.php
index 2033f94..d4a9364 100644
--- a/ThothSettingsForm.inc.php
+++ b/ThothSettingsForm.inc.php
@@ -10,13 +10,18 @@
* Distributed under the GNU GPL v3. For full terms see the file docs/COPYING.
*
* @class ThothSettingsForm
+ *
* @ingroup plugins_generic_thoth
*
* @brief Form for managers to modify Thoth plugin settings
*/
-import('lib.pkp.classes.form.Form');
-import('plugins.generic.thoth.lib.APIKeyEncryption.APIKeyEncryption');
+use APP\plugins\generic\thoth\classes\APIKeyEncryption;
+use PKP\form\Form;
+use PKP\form\validation\FormValidatorCSRF;
+use PKP\form\validation\FormValidatorCustom;
+use PKP\form\validation\FormValidatorPost;
+
import('plugins.generic.thoth.lib.thothAPI.ThothClient');
class ThothSettingsForm extends Form
diff --git a/classes/APIKeyEncryption.php b/classes/APIKeyEncryption.php
new file mode 100644
index 0000000..1e4a0f9
--- /dev/null
+++ b/classes/APIKeyEncryption.php
@@ -0,0 +1,48 @@
+registerFilter("output", array($this, 'thothBadgeFilter'));
+ $templateMgr->registerFilter('output', [$this, 'thothBadgeFilter']);
return false;
}
@@ -55,7 +58,7 @@ public function thothBadgeFilter($output, $templateMgr)
$newOutput .= $templateMgr->fetch($this->plugin->getTemplateResource('thothBadge.tpl'));
$newOutput .= substr($output, $offset + strlen($match));
$output = $newOutput;
- $templateMgr->unregisterFilter('output', array($this, 'thothBadgeFilter'));
+ $templateMgr->unregisterFilter('output', [$this, 'thothBadgeFilter']);
}
return $output;
}
diff --git a/classes/ThothNotification.inc.php b/classes/ThothNotification.inc.php
index f3d8e22..710b891 100644
--- a/classes/ThothNotification.inc.php
+++ b/classes/ThothNotification.inc.php
@@ -8,11 +8,16 @@
* Distributed under the GNU GPL v3. For full terms see the file docs/COPYING.
*
* @class ThothNotification
+ *
* @ingroup plugins_generic_thoth
*
* @brief Manage function to display plugin notifications
*/
+use APP\core\Application;
+use APP\notification\NotificationManager;
+use PKP\core\JSONMessage;
+
class ThothNotification
{
private $plugin;
diff --git a/classes/ThothRegister.inc.php b/classes/ThothRegister.inc.php
index a736cba..fec2669 100644
--- a/classes/ThothRegister.inc.php
+++ b/classes/ThothRegister.inc.php
@@ -8,11 +8,17 @@
* Distributed under the GNU GPL v3. For full terms see the file docs/COPYING.
*
* @class ThothRegister
+ *
* @ingroup plugins_generic_thoth
*
* @brief Manage callback functions to register works in Thoth
*/
+use APP\facades\Repo;
+use APP\i18n\AppLocale;
+use APP\notification\Notification;
+use PKP\security\Role;
+
import('plugins.generic.thoth.classes.facades.ThothService');
class ThothRegister
@@ -42,7 +48,7 @@ public function addImprintField($hookName, $form)
return;
}
- $submission = Services::get('submission')->get($form->publication->getData('submissionId'));
+ $submission = Repo::submission()->get($form->publication->getData('submissionId'));
if ($submission->getData('thothWorkId')) {
return;
@@ -69,13 +75,13 @@ public function addImprintField($hookName, $form)
'value' => false,
'groupId' => 'default',
]))
- ->addField(new \PKP\components\forms\FieldSelect('imprint', [
- 'label' => __('plugins.generic.thoth.imprint'),
- 'options' => $imprintOptions,
- 'required' => true,
- 'showWhen' => 'registerConfirmation',
- 'groupId' => 'default'
- ]));
+ ->addField(new \PKP\components\forms\FieldSelect('imprint', [
+ 'label' => __('plugins.generic.thoth.imprint'),
+ 'options' => $imprintOptions,
+ 'required' => true,
+ 'showWhen' => 'registerConfirmation',
+ 'groupId' => 'default'
+ ]));
} catch (ThothException $e) {
$warningIconHtml = '';
$noticeMsg = __('plugins.generic.thoth.connectionError');
@@ -173,22 +179,18 @@ public function registerWork($submission, $imprint)
try {
$thothClient = $this->plugin->getThothClient($submissionContext->getId());
$thothBook = ThothService::work()->registerBook($thothClient, $submission, $imprint);
- $submission = Services::get('submission')->edit(
- $submission,
- ['thothWorkId' => $thothBook->getId()],
- $request
- );
+ $submission = Repo::submission()->edit($submission, ['thothWorkId' => $thothBook->getId()]);
ThothNotification::notify(
$request,
- NOTIFICATION_TYPE_SUCCESS,
+ Notification::NOTIFICATION_TYPE_SUCCESS,
__('plugins.generic.thoth.register.success')
);
} catch (ThothException $e) {
error_log($e->getMessage());
ThothNotification::notify(
$request,
- NOTIFICATION_TYPE_ERROR,
+ Notification::NOTIFICATION_TYPE_ERROR,
__('plugins.generic.thoth.register.error')
);
}
@@ -230,16 +232,17 @@ public function addThothEndpoint($hookName, $args)
$endpoints = & $args[0];
$handler = $args[1];
- if (!is_a($handler, 'PKPSubmissionHandler')) {
+ if (!is_a($handler, 'PKP\API\v1\submissions\PKPSubmissionHandler')) {
return false;
}
+
array_unshift(
$endpoints['PUT'],
[
'pattern' => $handler->getEndpointPattern() . '/{submissionId}/publications/{publicationId}/register',
'handler' => [$this, 'register'],
- 'roles' => [ROLE_ID_MANAGER, ROLE_ID_SUB_EDITOR],
+ 'roles' => [Role::ROLE_ID_MANAGER, Role::ROLE_ID_SUB_EDITOR],
]
);
@@ -253,7 +256,7 @@ public function register($slimRequest, $response, $args)
$request = Application::get()->getRequest();
$handler = $request->getRouter()->getHandler();
$submission = $handler->getAuthorizedContextObject(ASSOC_TYPE_SUBMISSION);
- $publication = Services::get('publication')->get((int) $args['publicationId']);
+ $publication = Repo::publication()->get($args['publicationId']);
$params = $slimRequest->getParsedBody();
if (empty($params['imprint'])) {
@@ -281,16 +284,16 @@ public function register($slimRequest, $response, $args)
$this->registerWork($submission, $params['imprint']);
- $userGroupDao = DAORegistry::getDAO('UserGroupDAO');
+ $userGroups = Repo::userGroup()->getCollector()
+ ->filterByContextIds([$submission->getData('contextId')])
+ ->getMany();
- $publicationProps = Services::get('publication')->getFullProperties(
- $publication,
- [
- 'request' => $request,
- 'userGroups' => $userGroupDao->getByContextId($submission->getData('contextId'))->toArray(),
- ]
- );
+ $genreDao = DAORegistry::getDAO('GenreDAO');
+ $genres = $genreDao->getByContextId($submission->getData('contextId'))->toArray();
- return $response->withJson($publicationProps, 200);
+ return $response->withJson(
+ Repo::publication()->getSchemaMap($submission, $userGroups, $genres)->map($publication),
+ 200
+ );
}
}
diff --git a/classes/ThothUpdater.inc.php b/classes/ThothUpdater.inc.php
index 491b941..8f37e92 100644
--- a/classes/ThothUpdater.inc.php
+++ b/classes/ThothUpdater.inc.php
@@ -8,11 +8,15 @@
* Distributed under the GNU GPL v3. For full terms see the file docs/COPYING.
*
* @class ThothUpdater
+ *
* @ingroup plugins_generic_thoth
*
* @brief Manage callback functions to update works in Thoth
*/
+use APP\facades\Repo;
+use APP\notification\Notification;
+
import('plugins.generic.thoth.classes.facades.ThothService');
class ThothUpdater
@@ -29,7 +33,7 @@ public function updateWork($hookName, $args)
$publication = $args[0];
$request = $args[3];
- $submission = Services::get('submission')->get($publication->getData('submissionId'));
+ $submission = Repo::submission()->get($publication->getData('submissionId'));
$thothWorkId = $submission->getData('thothWorkId');
if (!$thothWorkId) {
@@ -42,14 +46,14 @@ public function updateWork($hookName, $args)
ThothNotification::notify(
$request,
- NOTIFICATION_TYPE_SUCCESS,
+ Notification::NOTIFICATION_TYPE_SUCCESS,
__('plugins.generic.thoth.update.success')
);
} catch (ThothException $e) {
error_log($e->getMessage());
ThothNotification::notify(
$request,
- NOTIFICATION_TYPE_ERROR,
+ Notification::NOTIFICATION_TYPE_ERROR,
__('plugins.generic.thoth.update.error')
);
}
diff --git a/classes/components/forms/RegisterForm.inc.php b/classes/components/forms/RegisterForm.inc.php
index 07b2ed8..52ad046 100644
--- a/classes/components/forms/RegisterForm.inc.php
+++ b/classes/components/forms/RegisterForm.inc.php
@@ -9,6 +9,7 @@
* Distributed under the GNU GPL v3. For full terms see the file docs/COPYING.
*
* @class RegisterForm
+ *
* @ingroup plugins_generic_thoth
*
* @brief A preset form for confirming a publication's issue before publishing.
@@ -16,9 +17,9 @@
* publication.
*/
-use PKP\components\forms\FormComponent;
use PKP\components\forms\FieldHTML;
use PKP\components\forms\FieldSelect;
+use PKP\components\forms\FormComponent;
class RegisterForm extends FormComponent
{
@@ -68,9 +69,9 @@ public function __construct($action, $imprints, $errors)
]);
$this->addGroup([
- 'id' => 'default',
- 'pageId' => 'default',
- ])
+ 'id' => 'default',
+ 'pageId' => 'default',
+ ])
->addField(new FieldHTML('validation', [
'description' => $msg,
'groupId' => 'default',
diff --git a/classes/services/ThothAffiliationService.inc.php b/classes/services/ThothAffiliationService.inc.php
index be49a0e..f5b3d4b 100644
--- a/classes/services/ThothAffiliationService.inc.php
+++ b/classes/services/ThothAffiliationService.inc.php
@@ -8,6 +8,7 @@
* Distributed under the GNU GPL v3. For full terms see the file docs/COPYING.
*
* @class ThothAffiliationService
+ *
* @ingroup plugins_generic_thoth
*
* @brief Helper class that encapsulates business logic for Thoth affiliations
diff --git a/classes/services/ThothContributionService.inc.php b/classes/services/ThothContributionService.inc.php
index a6854a8..44108ec 100644
--- a/classes/services/ThothContributionService.inc.php
+++ b/classes/services/ThothContributionService.inc.php
@@ -8,11 +8,14 @@
* Distributed under the GNU GPL v3. For full terms see the file docs/COPYING.
*
* @class ThothContributionService
+ *
* @ingroup plugins_generic_thoth
*
* @brief Helper class that encapsulates business logic for Thoth contributions
*/
+use APP\facades\Repo;
+
import('plugins.generic.thoth.classes.facades.ThothService');
import('plugins.generic.thoth.lib.thothAPI.models.ThothContribution');
import('classes.core.Services');
@@ -86,11 +89,11 @@ public function register($thothClient, $author, $thothWorkId)
public function updateContributions($thothClient, $thothContributions, $publication, $thothWorkId)
{
- $authors = DAORegistry::getDAO('AuthorDAO')->getByPublicationId($publication->getId());
+ $authors = $publication->getData('authors');
$publicationContributions = array_map(function ($author) {
return $this->getDataByAuthor($author);
- }, $authors);
+ }, $authors->toArray());
foreach ($thothContributions as $thothContribution) {
if (!$this->contributionInList($thothContribution, $publicationContributions)) {
$thothClient->deleteContribution($thothContribution['contributionId']);
@@ -124,7 +127,7 @@ private function isMainContribution($author)
return (bool) $author->getPrimaryContact();
}
- $publication = Services::get('publication')->get($author->getData('publicationId'));
+ $publication = Repo::publication()->get($author->getData('publicationId'));
return $publication->getData('primaryContactId') == $author->getId();
}
diff --git a/classes/services/ThothContributorService.inc.php b/classes/services/ThothContributorService.inc.php
index 9567bad..f796abe 100644
--- a/classes/services/ThothContributorService.inc.php
+++ b/classes/services/ThothContributorService.inc.php
@@ -8,6 +8,7 @@
* Distributed under the GNU GPL v3. For full terms see the file docs/COPYING.
*
* @class ThothContributorService
+ *
* @ingroup plugins_generic_thoth
*
* @brief Helper class that encapsulates business logic for Thoth contributors
diff --git a/classes/services/ThothInstitutionService.inc.php b/classes/services/ThothInstitutionService.inc.php
index ff296d9..9221cfd 100644
--- a/classes/services/ThothInstitutionService.inc.php
+++ b/classes/services/ThothInstitutionService.inc.php
@@ -8,6 +8,7 @@
* Distributed under the GNU GPL v3. For full terms see the file docs/COPYING.
*
* @class ThothInstitutionService
+ *
* @ingroup plugins_generic_thoth
*
* @brief Helper class that encapsulates business logic for Thoth institutions
diff --git a/classes/services/ThothLanguageService.inc.php b/classes/services/ThothLanguageService.inc.php
index aa33ae1..2ef4e63 100644
--- a/classes/services/ThothLanguageService.inc.php
+++ b/classes/services/ThothLanguageService.inc.php
@@ -8,11 +8,14 @@
* Distributed under the GNU GPL v3. For full terms see the file docs/COPYING.
*
* @class ThothLanguageService
+ *
* @ingroup plugins_generic_thoth
*
* @brief Helper class that encapsulates business logic for Thoth languages
*/
+use PKP\i18n\LocaleConversion;
+
import('plugins.generic.thoth.lib.thothAPI.models.ThothLanguage');
class ThothLanguageService
@@ -32,7 +35,7 @@ public function register($thothClient, $submissionLocale, $thothWorkId)
{
$thothLanguage = $this->new([
'workId' => $thothWorkId,
- 'languageCode' => strtoupper(AppLocale::getIso3FromLocale($submissionLocale)),
+ 'languageCode' => strtoupper(LocaleConversion::getIso3FromLocale($submissionLocale)),
'languageRelation' => ThothLanguage::LANGUAGE_RELATION_ORIGINAL,
'mainLanguage' => true
]);
diff --git a/classes/services/ThothLocationService.inc.php b/classes/services/ThothLocationService.inc.php
index 414261e..f2480b5 100644
--- a/classes/services/ThothLocationService.inc.php
+++ b/classes/services/ThothLocationService.inc.php
@@ -8,11 +8,15 @@
* Distributed under the GNU GPL v3. For full terms see the file docs/COPYING.
*
* @class ThothLocationService
+ *
* @ingroup plugins_generic_thoth
*
* @brief Helper class that encapsulates business logic for Thoth locations
*/
+use APP\core\Application;
+use APP\facades\Repo;
+
import('plugins.generic.thoth.lib.thothAPI.models.ThothLocation');
class ThothLocationService
@@ -27,8 +31,8 @@ public function getDataByPublicationFormat($publicationFormat, $fileId = null)
$request = Application::get()->getRequest();
$dispatcher = $request->getDispatcher();
$context = $request->getContext();
- $publication = Services::get('publication')->get($publicationFormat->getData('publicationId'));
- $submission = Services::get('submission')->get($publication->getData('submissionId'));
+ $publication = Repo::publication()->get($publicationFormat->getData('publicationId'));
+ $submission = Repo::submission()->get($publication->getData('submissionId'));
$landingPage = $dispatcher->url(
$request,
@@ -90,10 +94,13 @@ public function updateLocations(
$chapterId = null
) {
$files = array_filter(
- iterator_to_array(Services::get('submissionFile')->getMany([
- 'assocTypes' => [ASSOC_TYPE_PUBLICATION_FORMAT],
- 'assocIds' => [$publicationFormat->getId()],
- ])),
+ iterator_to_array(Repo::submissionFile()
+ ->getCollector()
+ ->filterByAssoc(
+ Application::ASSOC_TYPE_PUBLICATION_FORMAT,
+ [$publicationFormat->getId()]
+ )
+ ->getMany()),
function ($file) use ($chapterId) {
return $file->getData('chapterId') == $chapterId;
}
diff --git a/classes/services/ThothPublicationService.inc.php b/classes/services/ThothPublicationService.inc.php
index 9d47f78..559b511 100644
--- a/classes/services/ThothPublicationService.inc.php
+++ b/classes/services/ThothPublicationService.inc.php
@@ -8,11 +8,15 @@
* Distributed under the GNU GPL v3. For full terms see the file docs/COPYING.
*
* @class ThothPublicationService
+ *
* @ingroup plugins_generic_thoth
*
* @brief Helper class that encapsulates business logic for Thoth publications
*/
+use APP\core\Application;
+use APP\facades\Repo;
+
import('plugins.generic.thoth.classes.facades.ThothService');
import('plugins.generic.thoth.lib.thothAPI.models.ThothPublication');
@@ -56,10 +60,13 @@ public function register($thothClient, $publicationFormat, $workId, $chapterId =
}
$files = array_filter(
- iterator_to_array(Services::get('submissionFile')->getMany([
- 'assocTypes' => [ASSOC_TYPE_PUBLICATION_FORMAT],
- 'assocIds' => [$publicationFormat->getId()],
- ])),
+ iterator_to_array(Repo::submissionFile()
+ ->getCollector()
+ ->filterByAssoc(
+ Application::ASSOC_TYPE_PUBLICATION_FORMAT,
+ [$publicationFormat->getId()]
+ )
+ ->getMany()),
function ($file) use ($chapterId) {
return $file->getData('chapterId') == $chapterId;
}
@@ -152,7 +159,7 @@ public function getPublicationTypeByPublicationFormat($publicationFormat)
$formatName = trim(
preg_replace(
"/[^a-z0-9\.\-]+/",
- "",
+ '',
str_replace(
[' ', '_', ':'],
'',
@@ -168,7 +175,7 @@ public function getIsbnByPublicationFormat($publicationFormat)
{
$identificationCodes = $publicationFormat->getIdentificationCodes()->toArray();
foreach ($identificationCodes as $identificationCode) {
- if ($identificationCode->getCode() == "15" || $identificationCode->getCode() == "24") {
+ if ($identificationCode->getCode() == '15' || $identificationCode->getCode() == '24') {
return $identificationCode->getValue();
}
}
diff --git a/classes/services/ThothReferenceService.inc.php b/classes/services/ThothReferenceService.inc.php
index 6c932f5..1f8a1eb 100644
--- a/classes/services/ThothReferenceService.inc.php
+++ b/classes/services/ThothReferenceService.inc.php
@@ -8,11 +8,16 @@
* Distributed under the GNU GPL v3. For full terms see the file docs/COPYING.
*
* @class ThothReferenceService
+ *
* @ingroup plugins_generic_thoth
*
* @brief Helper class that encapsulates business logic for Thoth references
*/
+use APP\facades\Repo;
+use PKP\citation\Citation;
+use PKP\citation\CitationListTokenizerFilter;
+
import('lib.pkp.classes.citation.Citation');
import('lib.pkp.classes.citation.CitationListTokenizerFilter');
import('plugins.generic.thoth.lib.thothAPI.models.ThothReference');
@@ -50,7 +55,7 @@ public function register($thothClient, $citation, $thothWorkId)
public function updateReferences($thothClient, $thothReferences, $publication, $thothWorkId)
{
- $oldPublication = Services::get('publication')->get($publication->getId());
+ $oldPublication = Repo::publication()->get($publication->getId());
if ($publication->getData('citationsRaw') == $oldPublication->getData('citationsRaw')) {
return;
diff --git a/classes/services/ThothSubjectService.inc.php b/classes/services/ThothSubjectService.inc.php
index 48a40a9..0197d35 100644
--- a/classes/services/ThothSubjectService.inc.php
+++ b/classes/services/ThothSubjectService.inc.php
@@ -8,11 +8,14 @@
* Distributed under the GNU GPL v3. For full terms see the file docs/COPYING.
*
* @class ThothSubjectService
+ *
* @ingroup plugins_generic_thoth
*
* @brief Helper class that encapsulates business logic for Thoth subjects
*/
+use APP\facades\Repo;
+
import('plugins.generic.thoth.lib.thothAPI.models.ThothSubject');
class ThothSubjectService
@@ -45,7 +48,7 @@ public function registerKeyword($thothClient, $submissionKeyword, $thothWorkId,
public function updateKeywords($thothClient, $thothKeywords, $publication, $thothWorkId)
{
- $submission = Services::get('submission')->get($publication->getData('submissionId'));
+ $submission = Repo::submission()->get($publication->getData('submissionId'));
$locale = $submission->getLocale();
$keywords = $publication->getData('keywords');
diff --git a/classes/services/ThothWorkService.inc.php b/classes/services/ThothWorkService.inc.php
index a865edb..200f501 100644
--- a/classes/services/ThothWorkService.inc.php
+++ b/classes/services/ThothWorkService.inc.php
@@ -8,11 +8,17 @@
* Distributed under the GNU GPL v3. For full terms see the file docs/COPYING.
*
* @class ThothWorkService
+ *
* @ingroup plugins_generic_thoth
*
* @brief Helper class that encapsulates business logic for Thoth works
*/
+use APP\core\Application;
+use APP\facades\Repo;
+use APP\submission\Submission;
+use PKP\db\DAORegistry;
+
import('plugins.generic.thoth.classes.facades.ThothService');
import('plugins.generic.thoth.lib.thothAPI.models.ThothWork');
import('plugins.generic.thoth.lib.thothAPI.models.ThothWorkRelation');
@@ -40,7 +46,7 @@ public function getDataBySubmission($submission, $publication = null)
$data['subtitle'] = $publication->getLocalizedData('subtitle');
$data['longAbstract'] = $publication->getLocalizedData('abstract');
$data['edition'] = $publication->getData('version');
- $data['doi'] = $publication->getStoredPubId('doi');
+ $data['doi'] = $publication->getDoi();
$data['publicationDate'] = $publication->getData('datePublished');
$data['license'] = $publication->getData('licenseUrl');
$data['copyrightHolder'] = $publication->getLocalizedData('copyrightHolder');
@@ -73,8 +79,8 @@ public function newByChapter($chapter)
$params['longAbstract'] = $chapter->getLocalizedData('abstract');
$params['pageCount'] = $chapter->getPages();
$params['publicationDate'] = $chapter->getDatePublished() ??
- Services::get('publication')->get($chapter->getData('publicationId'))->getData('datePublished');
- $params['doi'] = $chapter->getStoredPubId('doi');
+ Repo::publication()->get($chapter->getData('publicationId'))->getData('datePublished');
+ $params['doi'] = $chapter->getDoi();
return $this->new($params);
}
@@ -117,39 +123,39 @@ public function registerBook($thothClient, $submission, $thothImprintId)
$thothBookId = $thothClient->createWork($thothBook);
$thothBook->setId($thothBookId);
- $authors = DAORegistry::getDAO('AuthorDAO')
- ->getByPublicationId($submission->getData('currentPublicationId'));
+ $publication = $submission->getCurrentPublication();
+
+ $authors = Repo::author()->getCollector()
+ ->filterByPublicationIds([$publication->getId()])
+ ->getMany();
foreach ($authors as $author) {
ThothService::contribution()->register($thothClient, $author, $thothBookId);
}
- $chapters = DAORegistry::getDAO('ChapterDAO')
- ->getByPublicationId($submission->getData('currentPublicationId'))
- ->toArray();
+ $chapterDAO = DAORegistry::getDAO('ChapterDAO');
+ $chapters = $chapterDAO->getByPublicationId($publication->getId())->toArray();
foreach ($chapters as $chapter) {
$this->registerWorkRelation($thothClient, $chapter, $thothImprintId, $thothBookId);
}
- $publicationFormats = Application::getRepresentationDao()
- ->getApprovedByPublicationId($submission->getData('currentPublicationId'))
- ->toArray();
+ $publicationFormatDao = DAORegistry::getDAO('PublicationFormatDAO');
+ $publicationFormats = $publicationFormatDao->getApprovedByPublicationId($publication->getId())->toArray();
foreach ($publicationFormats as $publicationFormat) {
if ($publicationFormat->getIsAvailable()) {
ThothService::publication()->register($thothClient, $publicationFormat, $thothBookId);
}
}
- $submissionKeywords = DAORegistry::getDAO('SubmissionKeywordDAO')
- ->getKeywords($submission->getData('currentPublicationId'));
- foreach ($submissionKeywords[$submission->getLocale()] ?? [] as $seq => $submissionKeyword) {
- ThothService::subject()->registerKeyword($thothClient, $submissionKeyword, $thothBookId, $seq + 1);
- }
+ $locale = $submission->getData('locale');
+ ThothService::language()->register($thothClient, $locale, $thothBookId);
- $submissionLocale = $submission->getData('locale');
- ThothService::language()->register($thothClient, $submissionLocale, $thothBookId);
+ $keywords = $publication->getData('keywords');
+ foreach ($keywords[$locale] ?? [] as $seq => $keyword) {
+ ThothService::subject()->registerKeyword($thothClient, $keyword, $thothBookId, $seq + 1);
+ }
$citations = DAORegistry::getDAO('CitationDAO')
- ->getByPublicationId($submission->getData('currentPublicationId'))
+ ->getByPublicationId($publication->getId())
->toArray();
foreach ($citations as $citation) {
ThothService::reference()->register($thothClient, $citation, $thothBookId);
@@ -171,12 +177,13 @@ public function registerChapter($thothClient, $chapter, $thothImprintId)
ThothService::contribution()->register($thothClient, $author, $thothChapterId);
}
- $publication = Services::get('publication')->get($chapter->getData('publicationId'));
+ $publication = Repo::publication()->get($chapter->getData('publicationId'));
$files = array_filter(
- iterator_to_array(Services::get('submissionFile')->getMany([
- 'assocTypes' => [ASSOC_TYPE_PUBLICATION_FORMAT],
- 'submissionIds' => [$publication->getData('submissionId')],
- ])),
+ iterator_to_array(Repo::submissionFile()
+ ->getCollector()
+ ->filterByAssoc(Application::ASSOC_TYPE_PUBLICATION_FORMAT)
+ ->filterBySubmissionIds([$publication->getData('submissionId')])
+ ->getMany()),
function ($a) use ($chapter) {
return $a->getData('chapterId') == $chapter->getId();
}
@@ -244,7 +251,8 @@ public function updateBook($thothClient, $thothWorkId, $submission, $publication
$thothClient,
$thothWorkData['relations'],
$publication,
- $thothWorkId
+ $thothWorkId,
+ $thothWorkData['imprintId']
);
}
@@ -278,7 +286,7 @@ public function updateBook($thothClient, $thothWorkId, $submission, $publication
return $newThothWork;
}
- public function updateRelations($thothClient, $thothRelations, $publication, $thothWorkId)
+ public function updateRelations($thothClient, $thothRelations, $publication, $thothWorkId, $thothImprintId)
{
$chapterDAO = DAORegistry::getDAO('ChapterDAO');
$chapters = $chapterDAO->getByPublicationId($publication->getId())->toArray();
@@ -287,7 +295,12 @@ public function updateRelations($thothClient, $thothRelations, $publication, $th
return;
}
- $thothRelationsData = array_column($thothRelations, 'relatedWork', 'fullTitle');
+ $thothRelationsData = [];
+ foreach ($thothRelations as $thothRelation) {
+ $relatedWork = $thothRelation['relatedWork'];
+ $fullTitle = $relatedWork['fullTitle'];
+ $thothRelationsData[$fullTitle] = $relatedWork;
+ }
$chapterTitles = array_map(function ($chapter) {
return $chapter->getLocalizedFullTitle();
}, $chapters);
@@ -298,15 +311,8 @@ public function updateRelations($thothClient, $thothRelations, $publication, $th
}
}
- $submissionService = Services::get('submission');
- $submission = $submissionService->get($publication->getData('submissionId'));
-
+ $submission = Repo::submission()->get($publication->getData('submissionId'));
$pluginSettingsDAO = DAORegistry::getDAO('PluginSettingsDAO');
- $thothImprintId = $pluginSettingsDAO->getSetting(
- $submission->getData('contextId'),
- 'thothPlugin',
- 'imprintId'
- );
foreach ($chapters as $chapter) {
$chapterTitle = $chapter->getLocalizedFullTitle();
@@ -319,8 +325,8 @@ public function updateRelations($thothClient, $thothRelations, $publication, $th
public function getWorkTypeBySubmissionWorkType($submissionWorkType)
{
$workTypeMapping = [
- WORK_TYPE_EDITED_VOLUME => ThothWork::WORK_TYPE_EDITED_BOOK,
- WORK_TYPE_AUTHORED_WORK => ThothWork::WORK_TYPE_MONOGRAPH
+ Submission::WORK_TYPE_EDITED_VOLUME => ThothWork::WORK_TYPE_EDITED_BOOK,
+ Submission::WORK_TYPE_AUTHORED_WORK => ThothWork::WORK_TYPE_MONOGRAPH
];
return $workTypeMapping[$submissionWorkType];
diff --git a/classes/services/queryBuilders/ThothWorkQueryBuilder.inc.php b/classes/services/queryBuilders/ThothWorkQueryBuilder.inc.php
index dae6c19..58d96e1 100644
--- a/classes/services/queryBuilders/ThothWorkQueryBuilder.inc.php
+++ b/classes/services/queryBuilders/ThothWorkQueryBuilder.inc.php
@@ -8,6 +8,7 @@
* Distributed under the GNU GPL v3. For full terms see the file docs/COPYING.
*
* @class ThothWorkQueryBuilder
+ *
* @ingroup plugins_generic_thoth
*
* @brief Class for building graphQL queries for works
diff --git a/controllers/modal/RegisterHandler.inc.php b/controllers/modal/RegisterHandler.inc.php
index a4ff872..4488efb 100644
--- a/controllers/modal/RegisterHandler.inc.php
+++ b/controllers/modal/RegisterHandler.inc.php
@@ -10,12 +10,16 @@
* Distributed under the GNU GPL v3. For full terms see the file docs/COPYING.
*
* @class RegisterHandler
+ *
* @ingroup plugins_generic_thoth
*
* @brief A handler to load Thoth register confirmation
*/
-use APP\components\forms\publication\PublishForm;
+use APP\i18n\AppLocale;
+use APP\template\TemplateManager;
+use PKP\plugins\PluginRegistry;
+use PKP\security\Role;
import('classes.handler.Handler');
@@ -29,7 +33,7 @@ public function __construct()
{
parent::__construct();
$this->addRoleAssignment(
- [ROLE_ID_SUB_EDITOR, ROLE_ID_MANAGER, ROLE_ID_ASSISTANT],
+ [Role::ROLE_ID_SUB_EDITOR, Role::ROLE_ID_MANAGER, Role::ROLE_ID_ASSISTANT],
['register']
);
}
@@ -69,7 +73,7 @@ public function register($args, $request)
!$submissionContext
|| $submissionContext->getId() !== $this->submission->getData('contextId')
) {
- $submissionContext = Services::get('context')->get($this->submission->getData('contextId'));
+ $submissionContext = Repo::context()->get($this->submission->getData('contextId'));
}
$publicationApiUrl = $request->getDispatcher()->url(
diff --git a/docs/README-es.md b/docs/README-es.md
index 628e221..0af8a56 100644
--- a/docs/README-es.md
+++ b/docs/README-es.md
@@ -9,6 +9,7 @@ Integración en progreso de OMP y [Thoth](https://thoth.pub/) para la comunicaci
Este plugin es compatible con las siguientes aplicaciones PKP:
- OMP 3.3.0-x
+- OMP 3.4.0-x
## Requisitos
diff --git a/docs/README-pt_BR.md b/docs/README-pt_BR.md
index fb71d10..b882a97 100644
--- a/docs/README-pt_BR.md
+++ b/docs/README-pt_BR.md
@@ -9,6 +9,7 @@ Integração em progresso do OMP com o [Thoth](https://thoth.pub/) para comunica
Este plugin é compatível com as seguintes aplicações PKP:
- OMP 3.3.0-x
+- OMP 3.4.0-x
## Requisitos
diff --git a/images/link.png b/images/link.png
index 4a107a3..afae4fa 100644
Binary files a/images/link.png and b/images/link.png differ
diff --git a/js/Workflow.js b/js/Workflow.js
index 97f3b1d..c6ebf02 100644
--- a/js/Workflow.js
+++ b/js/Workflow.js
@@ -50,8 +50,9 @@
);
$.ajax({
- method: 'PUT',
url: url,
+ method: 'PUT',
+ data: {id: publicationId},
headers: {
'X-Csrf-Token': pkp.currentUser.csrfToken,
'X-Http-Method-Override': 'PUT'
diff --git a/lib/APIKeyEncryption b/lib/APIKeyEncryption
deleted file mode 160000
index a5bc1a7..0000000
--- a/lib/APIKeyEncryption
+++ /dev/null
@@ -1 +0,0 @@
-Subproject commit a5bc1a731b9c46e5250acfef89d6b77d3c8febf8
diff --git a/locale/en_US/locale.po b/locale/en/locale.po
similarity index 100%
rename from locale/en_US/locale.po
rename to locale/en/locale.po
diff --git a/locale/es_ES/locale.po b/locale/es/locale.po
similarity index 100%
rename from locale/es_ES/locale.po
rename to locale/es/locale.po
diff --git a/templates/thothBadge.tpl b/templates/thothBadge.tpl
index e6d8d43..a5bf487 100644
--- a/templates/thothBadge.tpl
+++ b/templates/thothBadge.tpl
@@ -16,7 +16,7 @@
{translate key="plugins.generic.thoth.thothBook"}
-
+
{translate key="common.view"}
setId('42d407e2-fd07-4c45-853d-74ddfc0a02a8');
@@ -48,7 +51,7 @@ public function testeCreateNewAffiliation()
'affiliationOrdinal' => 1,
];
- $thothAffiliation = $this->affiliationService->new($params);
+ $thothAffiliation = $this->affiliationService->new($params);
$this->assertEquals($expectedThothAffiliation, $thothAffiliation);
}
diff --git a/tests/classes/services/ThothContributionServiceTest.php b/tests/classes/services/ThothContributionServiceTest.php
index 76e6ed3..887640c 100644
--- a/tests/classes/services/ThothContributionServiceTest.php
+++ b/tests/classes/services/ThothContributionServiceTest.php
@@ -8,15 +8,18 @@
* Distributed under the GNU GPL v3. For full terms see the file docs/COPYING.
*
* @class ThothContributionServiceTest
+ *
* @ingroup plugins_generic_thoth_tests
+ *
* @see ThothContributionService
*
* @brief Test class for the ThothContributionService class
*/
-import('lib.pkp.tests.PKPTestCase');
-import('classes.monograph.Author');
-import('classes.publication.Publication');
+use APP\publication\Repository as PublicationRepository;
+use PKP\tests\PKPTestCase;
+use PKP\userGroup\Repository as UserGroupRepository;
+
import('plugins.generic.thoth.classes.services.ThothContributionService');
import('plugins.generic.thoth.lib.thothAPI.ThothClient');
@@ -35,38 +38,45 @@ protected function tearDown(): void
parent::tearDown();
}
- protected function getMockedDAOs()
+ protected function getMockedContainerKeys(): array
{
- return ['UserGroupDAO', 'PublicationDAO'];
+ return [...parent::getMockedContainerKeys(), UserGroupRepository::class, PublicationRepository::class];
}
private function setUpMockEnvironment()
{
- $userGroupMockDao = $this->getMockBuilder(UserGroupDAO::class)
- ->setMethods(['getById'])
+ $userGroupRepoMock = Mockery::mock(app(UserGroupRepository::class))
+ ->makePartial()
+ ->shouldReceive('get')
+ ->withAnyArgs()
+ ->andReturn(
+ Mockery::mock(\PKP\userGroup\UserGroup::class)
+ ->shouldReceive([
+ 'getId' => 1
+ ])
+ ->shouldReceive('getData')
+ ->with('nameLocaleKey')
+ ->andReturn('default.groups.name.author')
+ ->getMock()
+ )
->getMock();
- $userGroup = new UserGroup();
- $userGroup->setData('nameLocaleKey', 'default.groups.name.author');
-
- $userGroupMockDao->expects($this->any())
- ->method('getById')
- ->will($this->returnValue($userGroup));
-
- DAORegistry::registerDAO('UserGroupDAO', $userGroupMockDao);
-
- $publicationMockDao = $this->getMockBuilder(PublicationDAO::class)
- ->setMethods(['getById'])
+ app()->instance(UserGroupRepository::class, $userGroupRepoMock);
+
+ $publicationRepoMock = Mockery::mock(app(PublicationRepository::class))
+ ->makePartial()
+ ->shouldReceive('get')
+ ->withAnyArgs()
+ ->andReturn(
+ Mockery::mock(\APP\publication\Publication::class)
+ ->shouldReceive('getData')
+ ->with('primaryContactId')
+ ->andReturn(1)
+ ->getMock()
+ )
->getMock();
- $publication = new Publication();
- $publication->setData('primaryContactId', 7);
-
- $publicationMockDao->expects($this->any())
- ->method('getById')
- ->will($this->returnValue($publication));
-
- DAORegistry::registerDAO('PublicationDAO', $publicationMockDao);
+ app()->instance(PublicationRepository::class, $publicationRepoMock);
}
public function testGettingContributionTypeByUserGroupLocaleKey()
@@ -91,6 +101,26 @@ public function testGettingContributionTypeByUserGroupLocaleKey()
public function testCreateNewContributionByAuthor()
{
+ $authorMock = Mockery::mock(\APP\author\Author::class)
+ ->makePartial()
+ ->shouldReceive([
+ 'getId' => 1,
+ 'getUserGroupId' => 1,
+ 'getSequence' => 0,
+ 'getLocalizedGivenName' => 'Reza',
+ 'getFullName' => 'Reza Negarestani',
+ 'getLocalizedBiography' => 'Reza Negarestani is a philosopher. His current philosophical project ' .
+ 'is focused on rationalist universalism beginning with the evolution of the modern system of ' .
+ 'knowledge and advancing toward contemporary philosophies of rationalism.',
+ ])
+ ->shouldReceive('getLocalizedData')
+ ->with('familyName')
+ ->andReturn('Negarestani')
+ ->shouldReceive('getData')
+ ->with('publicationId')
+ ->andReturn(1)
+ ->getMock();
+
$expectedContribution = new ThothContribution();
$expectedContribution->setContributionType(ThothContribution::CONTRIBUTION_TYPE_AUTHOR);
$expectedContribution->setMainContribution(true);
@@ -104,20 +134,7 @@ public function testCreateNewContributionByAuthor()
'advancing toward contemporary philosophies of rationalism.'
);
- $author = new Author();
- $author->setId(7);
- $author->setGivenName('Reza', 'en_US');
- $author->setFamilyName('Negarestani', 'en_US');
- $author->setSequence(0);
- $author->setUserGroupId(2);
- $author->setBiography(
- 'Reza Negarestani is a philosopher. His current philosophical project is focused on rationalist ' .
- 'universalism beginning with the evolution of the modern system of knowledge and ' .
- 'advancing toward contemporary philosophies of rationalism.',
- 'en_US'
- );
-
- $contribution = $this->contributionService->newByAuthor($author);
+ $contribution = $this->contributionService->newByAuthor($authorMock);
$this->assertEquals($expectedContribution, $contribution);
}
@@ -155,19 +172,22 @@ public function testRegisterContribution()
$expectedContribution->setLastName('Wilson');
$expectedContribution->setFullName('Michael Wilson');
- $userGroup = new UserGroup();
- $userGroup->setData('nameLocaleKey', 'default.groups.name.author');
-
- $author = $this->getMockBuilder(Author::class)
- ->setMethods(['getUserGroup'])
+ $authorMock = Mockery::mock(\APP\author\Author::class)
+ ->makePartial()
+ ->shouldReceive([
+ 'getId' => 2,
+ 'getUserGroupId' => 4,
+ 'getSequence' => 0,
+ 'getLocalizedGivenName' => 'Michael',
+ 'getFullName' => 'Michael Wilson',
+ ])
+ ->shouldReceive('getLocalizedData')
+ ->with('familyName')
+ ->andReturn('Wilson')
+ ->shouldReceive('getData')
+ ->with('publicationId')
+ ->andReturn(1)
->getMock();
- $author->expects($this->any())
- ->method('getUserGroup')
- ->will($this->returnValue($userGroup));
- $author->setId(13);
- $author->setGivenName('Michael', 'en_US');
- $author->setFamilyName('Wilson', 'en_US');
- $author->setSequence(0);
$mockThothClient = $this->getMockBuilder(ThothClient::class)
->setMethods(['createContribution','contributors'])
@@ -185,7 +205,11 @@ public function testRegisterContribution()
]
]));
- $contribution = $this->contributionService->register($mockThothClient, $author, '45a6622c-a306-4559-bb77-25367dc881b8');
+ $contribution = $this->contributionService->register(
+ $mockThothClient,
+ $authorMock,
+ '45a6622c-a306-4559-bb77-25367dc881b8'
+ );
$this->assertEquals($expectedContribution, $contribution);
}
}
diff --git a/tests/classes/services/ThothContributorServiceTest.php b/tests/classes/services/ThothContributorServiceTest.php
index eb4f488..7c8c32b 100644
--- a/tests/classes/services/ThothContributorServiceTest.php
+++ b/tests/classes/services/ThothContributorServiceTest.php
@@ -8,14 +8,16 @@
* Distributed under the GNU GPL v3. For full terms see the file docs/COPYING.
*
* @class ThothContributorServiceTest
+ *
* @ingroup plugins_generic_thoth_tests
+ *
* @see ThothContributorService
*
* @brief Test class for the ThothContributorService class
*/
-import('lib.pkp.tests.PKPTestCase');
-import('classes.monograph.Author');
+use PKP\tests\PKPTestCase;
+
import('plugins.generic.thoth.classes.services.ThothContributorService');
import('plugins.generic.thoth.lib.thothAPI.ThothClient');
@@ -59,13 +61,26 @@ public function testCreateNewContributorByAuthor()
$expectedContributor->setOrcid('https://orcid.org/0000-0002-1825-0097');
$expectedContributor->setWebsite('https://sites.google.com/site/chantalallan');
- $author = new Author();
- $author->setGivenName('Chantal', 'en_US');
- $author->setFamilyName('Allan', 'en_US');
- $author->setOrcid('https://orcid.org/0000-0002-1825-0097');
- $author->setUrl('https://sites.google.com/site/chantalallan');
+ $authorMock = Mockery::mock(\APP\author\Author::class)
+ ->makePartial()
+ ->shouldReceive('getLocalizedGivenName')
+ ->withAnyArgs()
+ ->andReturn('Chantal')
+ ->shouldReceive('getLocalizedData')
+ ->with('familyName')
+ ->andReturn('Allan')
+ ->shouldReceive('getFullName')
+ ->withAnyArgs()
+ ->andReturn('Chantal Allan')
+ ->shouldReceive('getOrcid')
+ ->withAnyArgs()
+ ->andReturn('https://orcid.org/0000-0002-1825-0097')
+ ->shouldReceive('getUrl')
+ ->withAnyArgs()
+ ->andReturn('https://sites.google.com/site/chantalallan')
+ ->getMock();
- $contributor = $this->contributorService->newByAuthor($author);
+ $contributor = $this->contributorService->newByAuthor($authorMock);
$this->assertEquals($expectedContributor, $contributor);
}
@@ -78,9 +93,18 @@ public function testRegisterContributor()
$expectedContributor->setLastName('Dupuis');
$expectedContributor->setFullName('Brian Dupuis');
- $author = new Author();
- $author->setGivenName('Brian', 'en_US');
- $author->setFamilyName('Dupuis', 'en_US');
+ $authorMock = Mockery::mock(\APP\author\Author::class)
+ ->makePartial()
+ ->shouldReceive('getLocalizedGivenName')
+ ->withAnyArgs()
+ ->andReturn('Brian')
+ ->shouldReceive('getLocalizedData')
+ ->with('familyName')
+ ->andReturn('Dupuis')
+ ->shouldReceive('getFullName')
+ ->withAnyArgs()
+ ->andReturn('Brian Dupuis')
+ ->getMock();
$mockThothClient = $this->getMockBuilder(ThothClient::class)
->setMethods([
@@ -91,7 +115,7 @@ public function testRegisterContributor()
->method('createContributor')
->will($this->returnValue('f70f709e-2137-4c87-a2e5-d52b263759ec'));
- $contributor = $this->contributorService->register($mockThothClient, $author);
+ $contributor = $this->contributorService->register($mockThothClient, $authorMock);
$this->assertEquals($expectedContributor, $contributor);
}
diff --git a/tests/classes/services/ThothInstitutionServiceTest.php b/tests/classes/services/ThothInstitutionServiceTest.php
index ef6f1e0..8761067 100644
--- a/tests/classes/services/ThothInstitutionServiceTest.php
+++ b/tests/classes/services/ThothInstitutionServiceTest.php
@@ -8,13 +8,16 @@
* Distributed under the GNU GPL v3. For full terms see the file docs/COPYING.
*
* @class ThothInstitutionServiceTest
+ *
* @ingroup plugins_generic_thoth_tests
+ *
* @see ThothInstitutionService
*
* @brief Test class for the ThothInstitutionService class
*/
-import('lib.pkp.tests.PKPTestCase');
+use PKP\tests\PKPTestCase;
+
import('plugins.generic.thoth.classes.services.ThothInstitutionService');
import('plugins.generic.thoth.lib.thothAPI.models.ThothInstitution');
import('plugins.generic.thoth.lib.thothAPI.ThothClient');
diff --git a/tests/classes/services/ThothLanguageServiceTest.php b/tests/classes/services/ThothLanguageServiceTest.php
index f69a2e8..cca44ef 100644
--- a/tests/classes/services/ThothLanguageServiceTest.php
+++ b/tests/classes/services/ThothLanguageServiceTest.php
@@ -8,13 +8,16 @@
* Distributed under the GNU GPL v3. For full terms see the file docs/COPYING.
*
* @class ThothLanguageServiceTest
+ *
* @ingroup plugins_generic_thoth_tests
+ *
* @see ThothLanguageService
*
* @brief Test class for the ThothLanguageService class
*/
-import('lib.pkp.tests.PKPTestCase');
+use PKP\tests\PKPTestCase;
+
import('plugins.generic.thoth.classes.services.ThothLanguageService');
import('plugins.generic.thoth.lib.thothAPI.ThothClient');
diff --git a/tests/classes/services/ThothLocationServiceTest.php b/tests/classes/services/ThothLocationServiceTest.php
index 6cda3c2..59b1749 100644
--- a/tests/classes/services/ThothLocationServiceTest.php
+++ b/tests/classes/services/ThothLocationServiceTest.php
@@ -8,19 +8,20 @@
* Distributed under the GNU GPL v3. For full terms see the file docs/COPYING.
*
* @class ThothLocationServiceTest
+ *
* @ingroup plugins_generic_thoth_tests
+ *
* @see ThothLocationService
*
* @brief Test class for the ThothLocationService class
*/
-import('classes.core.Application');
-import('classes.press.Press');
-import('classes.submission.Submission');
-import('classes.publication.Publication');
-import('lib.pkp.classes.core.Dispatcher');
-import('lib.pkp.classes.core.PKPRequest');
-import('lib.pkp.tests.PKPTestCase');
+use APP\core\Application;
+use PKP\core\Dispatcher;
+use PKP\core\PKPRequest;
+use PKP\core\Registry;
+use PKP\tests\PKPTestCase;
+
import('plugins.generic.thoth.classes.services.ThothLocationService');
import('plugins.generic.thoth.lib.thothAPI.ThothClient');
@@ -39,22 +40,21 @@ protected function tearDown(): void
parent::tearDown();
}
- protected function getMockedRegistryKeys()
+ protected function getMockedRegistryKeys(): array
{
return ['application', 'request'];
}
- protected function getMockedDAOs()
- {
- return ['SubmissionDAO'];
- }
-
private function setUpMockEnvironment()
{
- $press = new Press();
- $press->setId(2);
- $press->setPrimaryLocale('en_US');
- $press->setPath('press');
+ $pressMock = Mockery::mock(\APP\press\Press::class)
+ ->makePartial()
+ ->shouldReceive([
+ 'getId' => 2,
+ 'getPrimaryLocale' => 'en',
+ 'getPath' => 'press'
+ ])
+ ->getMock();
$mockApplication = $this->getMockBuilder(Application::class)
->setMethods(['getContextDepth', 'getContextList'])
@@ -83,28 +83,8 @@ private function setUpMockEnvironment()
$mockRequest->setDispatcher($mockDispatcher);
$mockRequest->expects($this->any())
->method('getContext')
- ->will($this->returnValue($press));
+ ->will($this->returnValue($pressMock));
Registry::set('request', $mockRequest);
-
- $submissionDaoMock = $this->getMockBuilder(SubmissionDAO::class)
- ->setMethods(['getById'])
- ->getMock();
- $submission = new Submission();
- $submission->setId(23);
- $submissionDaoMock->expects($this->any())
- ->method('getById')
- ->will($this->returnValue($submission));
- DAORegistry::registerDAO('SubmissionDAO', $submissionDaoMock);
-
- $publicationDaoMock = $this->getMockBuilder(PublicationDAO::class)
- ->setMethods(['getById'])
- ->getMock();
- $publication = new Publication();
- $publication->setId(23);
- $publicationDaoMock->expects($this->any())
- ->method('getById')
- ->will($this->returnValue($publication));
- DAORegistry::registerDAO('PublicationDAO', $publicationDaoMock);
}
public function testCreateNewLocationByPublicationFormat()
@@ -114,10 +94,14 @@ public function testCreateNewLocationByPublicationFormat()
$expectedLocation->setFullTextUrl('https://omp.publicknowledgeproject.org/press/catalog/view/23/5/17');
$expectedLocation->setLocationPlatform(ThothLocation::LOCATION_PLATFORM_OTHER);
- $publicationFormat = DAORegistry::getDAO('PublicationFormatDAO')->newDataObject();
- $publicationFormat->setId(5);
+ $publicationFormatMock = Mockery::mock(\APP\publicationFormat\PublicationFormat::class)
+ ->makePartial()
+ ->shouldReceive('getData')
+ ->with('publicationId')
+ ->andReturn(1)
+ ->getMock();
- $location = $this->locationService->newByPublicationFormat($publicationFormat, 17);
+ $location = $this->locationService->newByPublicationFormat($publicationFormatMock, 17);
$this->assertEquals($expectedLocation, $location);
}
@@ -150,9 +134,18 @@ public function testRegisterLocation()
$expectedLocation->setLocationPlatform(ThothLocation::LOCATION_PLATFORM_OTHER);
$expectedLocation->setCanonical(true);
- $publicationFormat = DAORegistry::getDAO('PublicationFormatDAO')->newDataObject();
- $publicationFormat->setId(41);
- $publicationFormat->setRemoteUrl('https://www.bookstore.com/site/books/book5');
+ $publicationFormatMock = Mockery::mock(\APP\publicationFormat\PublicationFormat::class)
+ ->makePartial()
+ ->shouldReceive('getId')
+ ->withAnyArgs()
+ ->andReturn(1)
+ ->shouldReceive('getData')
+ ->with('publicationId')
+ ->andReturn(1)
+ ->shouldReceive('getRemoteUrl')
+ ->with()
+ ->andReturn('https://www.bookstore.com/site/books/book5')
+ ->getMock();
$mockThothClient = $this->getMockBuilder(ThothClient::class)
->setMethods([
@@ -163,7 +156,7 @@ public function testRegisterLocation()
->method('createLocation')
->will($this->returnValue('03b0367d-bba3-4e26-846a-4c36d3920db2'));
- $location = $this->locationService->register($mockThothClient, $publicationFormat, $thothPublicationId);
+ $location = $this->locationService->register($mockThothClient, $publicationFormatMock, $thothPublicationId);
$this->assertEquals($expectedLocation, $location);
}
}
diff --git a/tests/classes/services/ThothPublicationServiceTest.php b/tests/classes/services/ThothPublicationServiceTest.php
index 36208ef..65d602d 100644
--- a/tests/classes/services/ThothPublicationServiceTest.php
+++ b/tests/classes/services/ThothPublicationServiceTest.php
@@ -8,16 +8,19 @@
* Distributed under the GNU GPL v3. For full terms see the file docs/COPYING.
*
* @class ThothPublicationServiceTest
+ *
* @ingroup plugins_generic_thoth_tests
+ *
* @see ThothPublicationService
*
* @brief Test class for the ThothPublicationService class
*/
-import('classes.core.Services');
-import('classes.monograph.Author');
-import('lib.pkp.classes.services.PKPSchemaService');
-import('lib.pkp.tests.PKPTestCase');
+use APP\publicationFormat\PublicationFormat;
+use PKP\db\DAORegistry;
+use PKP\db\DAOResultFactory;
+use PKP\tests\PKPTestCase;
+
import('plugins.generic.thoth.classes.services.ThothPublicationService');
class ThothPublicationServiceTest extends PKPTestCase
diff --git a/tests/classes/services/ThothReferenceServiceTest.php b/tests/classes/services/ThothReferenceServiceTest.php
index c62a424..88e935a 100644
--- a/tests/classes/services/ThothReferenceServiceTest.php
+++ b/tests/classes/services/ThothReferenceServiceTest.php
@@ -8,13 +8,17 @@
* Distributed under the GNU GPL v3. For full terms see the file docs/COPYING.
*
* @class ThothReferenceServiceTest
+ *
* @ingroup plugins_generic_thoth_tests
+ *
* @see ThothReferenceService
*
* @brief Test class for the ThothReferenceService class
*/
-import('lib.pkp.tests.PKPTestCase');
+use PKP\db\DAORegistry;
+use PKP\tests\PKPTestCase;
+
import('plugins.generic.thoth.classes.services.ThothReferenceService');
class ThothReferenceServiceTest extends PKPTestCase
diff --git a/tests/classes/services/ThothSubjectServiceTest.php b/tests/classes/services/ThothSubjectServiceTest.php
index 5df670e..1e8e6e7 100644
--- a/tests/classes/services/ThothSubjectServiceTest.php
+++ b/tests/classes/services/ThothSubjectServiceTest.php
@@ -8,13 +8,16 @@
* Distributed under the GNU GPL v3. For full terms see the file docs/COPYING.
*
* @class ThothSubjectServiceTest
+ *
* @ingroup plugins_generic_thoth_tests
+ *
* @see ThothSubjectService
*
* @brief Test class for the ThothSubjectService class
*/
-import('lib.pkp.tests.PKPTestCase');
+use PKP\tests\PKPTestCase;
+
import('plugins.generic.thoth.classes.services.ThothSubjectService');
class ThothSubjectServiceTest extends PKPTestCase
diff --git a/tests/classes/services/ThothWorkServiceTest.php b/tests/classes/services/ThothWorkServiceTest.php
index deb430e..a87ff06 100644
--- a/tests/classes/services/ThothWorkServiceTest.php
+++ b/tests/classes/services/ThothWorkServiceTest.php
@@ -8,18 +8,23 @@
* Distributed under the GNU GPL v3. For full terms see the file docs/COPYING.
*
* @class ThothWorkServiceTest
+ *
* @ingroup plugins_generic_thoth_tests
+ *
* @see WorkService
*
* @brief Test class for the ThothWorkService class
*/
-import('classes.core.Application');
-import('classes.press.Press');
-import('classes.submission.Submission');
-import('lib.pkp.classes.core.PKPRequest');
-import('lib.pkp.classes.core.PKPRouter');
-import('lib.pkp.tests.PKPTestCase');
+use APP\core\Application;
+use APP\publication\Publication;
+use APP\publication\Repository as PublicationRepository;
+use APP\submission\Submission;
+use PKP\core\PKPRequest;
+use PKP\core\Registry;
+use PKP\db\DAORegistry;
+use PKP\tests\PKPTestCase;
+
import('plugins.generic.thoth.classes.services.ThothWorkService');
import('plugins.generic.thoth.lib.thothAPI.models.ThothWork');
import('plugins.generic.thoth.lib.thothAPI.ThothClient');
@@ -38,17 +43,44 @@ protected function tearDown(): void
parent::tearDown();
}
- protected function getMockedRegistryKeys()
+ protected function getMockedRegistryKeys(): array
{
return ['application', 'request'];
}
+ protected function getMockedContainerKeys(): array
+ {
+ return [...parent::getMockedContainerKeys(), PublicationRepository::class];
+ }
+
private function setUpMockEnvironment()
{
- $press = new Press();
- $press->setId(2);
- $press->setPrimaryLocale('en_US');
- $press->setPath('press');
+ $publicationRepoMock = Mockery::mock(app(PublicationRepository::class))
+ ->makePartial()
+ ->shouldReceive('get')
+ ->withAnyArgs()
+ ->andReturn(
+ Mockery::mock(\APP\publication\Publication::class)
+ ->shouldReceive('getData')
+ ->with('submissionId')
+ ->andReturn(1)
+ ->shouldReceive('getData')
+ ->with('datePublished')
+ ->andReturn('2020-01-01')
+ ->getMock()
+ )
+ ->getMock();
+
+ app()->instance(PublicationRepository::class, $publicationRepoMock);
+
+ $pressMock = Mockery::mock(\APP\press\Press::class)
+ ->makePartial()
+ ->shouldReceive([
+ 'getId' => 2,
+ 'getPrimaryLocale' => 'en',
+ 'getPath' => 'press'
+ ])
+ ->getMock();
$mockApplication = $this->getMockBuilder(Application::class)
->setMethods(['getContextDepth', 'getContextList'])
@@ -68,32 +100,12 @@ private function setUpMockEnvironment()
$mockRequest->setDispatcher($dispatcher);
$mockRequest->expects($this->any())
->method('getContext')
- ->will($this->returnValue($press));
+ ->will($this->returnValue($pressMock));
$mockRequest->expects($this->any())
->method('getBaseUrl')
->will($this->returnValue('https://omp.publicknowledgeproject.org'));
Registry::set('request', $mockRequest);
- $submissionDaoMock = $this->getMockBuilder(SubmissionDAO::class)
- ->setMethods(['getById'])
- ->getMock();
- $submission = new Submission();
- $submission->setId(53);
- $submissionDaoMock->expects($this->any())
- ->method('getById')
- ->will($this->returnValue($submission));
- DAORegistry::registerDAO('SubmissionDAO', $submissionDaoMock);
-
- $publicationMockDao = $this->getMockBuilder(PublicationDAO::class)
- ->setMethods(['getById'])
- ->getMock();
- $publication = new Publication();
- $publication->setData('primaryContactId', 13);
- $publicationMockDao->expects($this->any())
- ->method('getById')
- ->will($this->returnValue($publication));
- DAORegistry::registerDAO('PublicationDAO', $publicationMockDao);
-
$mockThothClient = $this->getMockBuilder(ThothClient::class)
->setMethods([
'createWork',
@@ -167,57 +179,64 @@ public function testCreateNewWorkBySubmission()
'educational theory.'
);
- $publication = DAORegistry::getDAO('PublicationDAO')->newDataObject();
- $publication->setId(4);
- $publication->setData(
- 'title',
- 'Accessible Elements',
- 'en_US'
- );
- $publication->setData(
- 'subtitle',
- 'Teaching Science Online and at a Distance',
- 'en_US'
- );
- $publication->setData(
- 'version',
- 1
- );
- $publication->setData(
- 'pub-id::doi',
- 'https://doi.org/10.1234/0000af0000'
- );
- $publication->setData(
- 'datePublished',
- '2024-07-16'
- );
- $publication->setData(
- 'licenseUrl',
- 'https://creativecommons.org/licenses/by-nc/4.0/'
- );
- $publication->setData(
- 'copyrightHolder',
- 'Public Knowledge Press',
- 'en_US'
- );
- $publication->setData(
- 'abstract',
- 'Accessible Elements informs science educators about current practices in online and distance education: ' .
- 'distance-delivered methods for laboratory coursework, the requisite administrative and institutional ' .
- 'aspects of online and distance teaching, and the relevant educational theory.',
- 'en_US'
- );
-
- $submission = DAORegistry::getDAO('SubmissionDAO')->newDataObject();
- $submission->setData('id', 3);
- $submission->setData('locale', 'en_US');
- $submission->setData('workType', WORK_TYPE_AUTHORED_WORK);
- $submission->setData('currentPublicationId', 4);
- $submission->setData('publications', [$publication]);
+ $submissionMock = Mockery::mock(\APP\submission\Submission::class)
+ ->makePartial()
+ ->shouldReceive('getId')
+ ->withAnyArgs()
+ ->andReturn(3)
+ ->shouldReceive('getLocale')
+ ->withAnyArgs()
+ ->andReturn('en')
+ ->shouldReceive('getData')
+ ->with('workType')
+ ->andReturn(Submission::WORK_TYPE_AUTHORED_WORK)
+ ->shouldReceive('getCurrentPublication')
+ ->withAnyArgs()
+ ->andReturn(
+ Mockery::mock(\APP\publication\Publication::class)
+ ->makePartial()
+ ->shouldReceive('getId')
+ ->withAnyArgs()
+ ->andReturn(4)
+ ->shouldReceive('getLocalizedFullTitle')
+ ->withAnyArgs()
+ ->andReturn('Accessible Elements: Teaching Science Online and at a Distance')
+ ->shouldReceive('getLocalizedTitle')
+ ->withAnyArgs()
+ ->andReturn('Accessible Elements')
+ ->shouldReceive('getLocalizedData')
+ ->with('subtitle')
+ ->andReturn('Teaching Science Online and at a Distance')
+ ->shouldReceive('getLocalizedData')
+ ->with('abstract')
+ ->andReturn(
+ 'Accessible Elements informs science educators about current practices in online ' .
+ 'and distance education: distance-delivered methods for laboratory coursework, the requisite ' .
+ 'administrative and institutional aspects of online and distance teaching, and the relevant ' .
+ 'educational theory.'
+ )
+ ->shouldReceive('getLocalizedData')
+ ->with('copyrightHolder')
+ ->andReturn('Public Knowledge Press')
+ ->shouldReceive('getData')
+ ->with('version')
+ ->andReturn(1)
+ ->shouldReceive('getData')
+ ->with('datePublished')
+ ->andReturn('2024-07-16')
+ ->shouldReceive('getData')
+ ->with('licenseUrl')
+ ->andReturn('https://creativecommons.org/licenses/by-nc/4.0/')
+ ->shouldReceive('getDoi')
+ ->withAnyArgs()
+ ->andReturn('https://doi.org/10.1234/0000af0000')
+ ->getMock()
+ )
+ ->getMock();
$this->setUpMockEnvironment();
- $thothWork = $this->workService->newBySubmission($submission);
+ $thothWork = $this->workService->newBySubmission($submissionMock);
$this->assertEquals($expectedThothWork, $thothWork);
}
@@ -232,13 +251,26 @@ public function testCreateNewWorkByChapter()
$expectedThothWork->setPageCount('27');
$expectedThothWork->setDoi('https://doi.org/10.1234/jpk.14.c54');
- $chapter = DAORegistry::getDAO('ChapterDAO')->newDataObject();
- $chapter->setTitle('Chapter 1: Interactions Affording Distance Science Education', 'en_US');
- $chapter->setDatePublished('2024-03-21');
- $chapter->setPages(27);
- $chapter->setStoredPubId('doi', 'https://doi.org/10.1234/jpk.14.c54');
+ $chapterMock = Mockery::mock(\APP\monograph\Chapter::class)
+ ->makePartial()
+ ->shouldReceive('getLocalizedFullTitle')
+ ->withAnyArgs()
+ ->andReturn('Chapter 1: Interactions Affording Distance Science Education')
+ ->shouldReceive('getLocalizedTitle')
+ ->withAnyArgs()
+ ->andReturn('Chapter 1: Interactions Affording Distance Science Education')
+ ->shouldReceive('getDatePublished')
+ ->withAnyArgs()
+ ->andReturn('2024-03-21')
+ ->shouldReceive('getPages')
+ ->withAnyArgs()
+ ->andReturn(27)
+ ->shouldReceive('getDoi')
+ ->withAnyArgs()
+ ->andReturn('https://doi.org/10.1234/jpk.14.c54')
+ ->getMock();
- $thothWork = $this->workService->newByChapter($chapter);
+ $thothWork = $this->workService->newByChapter($chapterMock);
$this->assertEquals($expectedThothWork, $thothWork);
}
@@ -301,7 +333,7 @@ public function testRegisterBook()
$submission = new Submission();
$submission->setData('id', 999);
$submission->setData('locale', 'en_US');
- $submission->setData('workType', WORK_TYPE_AUTHORED_WORK);
+ $submission->setData('workType', Submission::WORK_TYPE_AUTHORED_WORK);
$submission->setData('currentPublicationId', 999);
$submission->setData('publications', [$publication]);
@@ -322,6 +354,7 @@ public function testRegisterChapter()
$expectedThothChapter->setWorkStatus(ThothWork::WORK_STATUS_ACTIVE);
$expectedThothChapter->setFullTitle('Chapter 2: Classical Music and the Classical Mind');
$expectedThothChapter->setTitle('Chapter 2: Classical Music and the Classical Mind');
+ $expectedThothChapter->setPublicationDate('2020-01-01');
$chapter = DAORegistry::getDAO('ChapterDAO')->newDataObject();
$chapter->setTitle('Chapter 2: Classical Music and the Classical Mind');
diff --git a/tests/classes/services/queryBuilders/ThothWorkQueryBuilderTest.php b/tests/classes/services/queryBuilders/ThothWorkQueryBuilderTest.php
index 68b4f62..25a599d 100644
--- a/tests/classes/services/queryBuilders/ThothWorkQueryBuilderTest.php
+++ b/tests/classes/services/queryBuilders/ThothWorkQueryBuilderTest.php
@@ -8,13 +8,16 @@
* Distributed under the GNU GPL v3. For full terms see the file docs/COPYING.
*
* @class ThothWorkQueryBuilderTest
+ *
* @ingroup plugins_generic_thoth_tests
+ *
* @see ThothWorkQueryBuilder
*
* @brief Test class for the ThothWorkQueryBuilder class
*/
-import('lib.pkp.tests.PKPTestCase');
+use PKP\tests\PKPTestCase;
+
import('plugins.generic.thoth.classes.services.queryBuilders.ThothWorkQueryBuilder');
import('plugins.generic.thoth.lib.thothAPI.ThothClient');
diff --git a/version.xml b/version.xml
index c215229..856f32d 100644
--- a/version.xml
+++ b/version.xml
@@ -3,8 +3,8 @@
thoth
plugins.generic
- 0.1.2.0
- 2024-09-30
+ 0.2.0.0
+ 2024-10-18
1
ThothPlugin