Skip to content

Commit

Permalink
pkp/pkp-lib#9899 notification mocks added
Browse files Browse the repository at this point in the history
  • Loading branch information
touhidurabir authored and asmecher committed Nov 8, 2024
1 parent d674591 commit 395e781
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 17 deletions.
47 changes: 43 additions & 4 deletions tests/jobs/notifications/IssuePublishedNotifyUsersTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@

namespace APP\tests\jobs\notifications;

use APP\jobs\notifications\IssuePublishedNotifyUsers;
use Mockery;
use PKP\db\DAORegistry;
use PKP\emailTemplate\Repository as EmailTemplateRepository;
use APP\core\Application;
use PKP\tests\PKPTestCase;
use APP\jobs\notifications\IssuePublishedNotifyUsers;
use PKP\emailTemplate\Repository as EmailTemplateRepository;

/**
* @runTestsInSeparateProcesses
Expand Down Expand Up @@ -56,11 +57,20 @@ public function testRunSerializedJob(): void
/** @var IssuePublishedNotifyUsers $issuePublishedNotifyUsersJob */
$issuePublishedNotifyUsersJob = unserialize(($this->serializedJobData));

$contextMock = Mockery::mock(get_class(Application::getContextDAO()->newDataObject()))
->makePartial()
->shouldReceive([
'getId' => 0,
'getLocalizedData' => '',
])
->withAnyArgs()
->getMock();

$journalDAOMock = Mockery::mock(\APP\journal\JournalDAO::class)
->makePartial()
->shouldReceive('getId')
->shouldReceive('getById')
->withAnyArgs()
->andReturn(new \APP\journal\JournalDAO())
->andReturn($contextMock)
->getMock();

DAORegistry::registerDAO('JournalDAO', $journalDAOMock);
Expand All @@ -83,6 +93,35 @@ public function testRunSerializedJob(): void

app()->instance(EmailTemplateRepository::class, $emailTemplateRepoMock);

$notificationMock = Mockery::mock(\APP\notification\Notification::class)
->makePartial()
->shouldReceive([
'setData' => null,
'getContextId' => 0,
])
->withAnyArgs()
->getMock();

$notifiactionDaoMock = Mockery::mock(\PKP\notification\NotificationDAO::class)
->makePartial()
->shouldReceive([
'newDataObject' => $notificationMock,
'insertObject' => 0,
])
->withAnyArgs()
->getMock();

DAORegistry::registerDAO('NotificationDAO', $notifiactionDaoMock);

$notificationSettingsDaoMock = Mockery::mock(\PKP\notification\NotificationSettingsDAO::class)
->makePartial()
->shouldReceive('updateNotificationSetting')
->withAnyArgs()
->andReturn(null)
->getMock();

DAORegistry::registerDAO('NotificationSettingsDAO', $notificationSettingsDaoMock);

$this->assertNull($issuePublishedNotifyUsersJob->handle());
}
}
57 changes: 44 additions & 13 deletions tests/jobs/notifications/OpenAccessMailUsersTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,13 @@

namespace APP\tests\jobs\notifications;

use APP\issue\Repository as IssueRepository;
use APP\jobs\notifications\OpenAccessMailUsers;
use Mockery;
use PKP\db\DAORegistry;
use PKP\emailTemplate\Repository as EmailTemplateRepository;
use APP\core\Application;
use PKP\tests\PKPTestCase;
use APP\issue\Repository as IssueRepository;
use APP\jobs\notifications\OpenAccessMailUsers;
use PKP\emailTemplate\Repository as EmailTemplateRepository;

/**
* @runTestsInSeparateProcesses
Expand Down Expand Up @@ -57,20 +58,21 @@ public function testRunSerializedJob(): void
/** @var OpenAccessMailUsers $openAccessMailUsersJob */
$openAccessMailUsersJob = unserialize($this->serializedJobData);

$contextMock = Mockery::mock(get_class(Application::getContextDAO()->newDataObject()))
->makePartial()
->shouldReceive([
'getId' => 0,
'getLocalizedData' => '',
'getPrimaryLocale' => 'en',
])
->withAnyArgs()
->getMock();

$journalDAOMock = Mockery::mock(\APP\journal\JournalDAO::class)
->makePartial()
->shouldReceive('getId')
->withAnyArgs()
->andReturn(
Mockery::mock(\APP\journal\Journal::class)
->makePartial()
->shouldReceive([
'getData' => '',
'getPrimaryLocale' => 'en'
])
->withAnyArgs()
->getMock()
)
->andReturn($contextMock)
->getMock();

DAORegistry::registerDAO('JournalDAO', $journalDAOMock);
Expand Down Expand Up @@ -103,6 +105,35 @@ public function testRunSerializedJob(): void

app()->instance(EmailTemplateRepository::class, $emailTemplateRepoMock);

$notificationMock = Mockery::mock(\APP\notification\Notification::class)
->makePartial()
->shouldReceive([
'setData' => null,
'getContextId' => 0,
])
->withAnyArgs()
->getMock();

$notifiactionDaoMock = Mockery::mock(\PKP\notification\NotificationDAO::class)
->makePartial()
->shouldReceive([
'newDataObject' => $notificationMock,
'insertObject' => 0,
])
->withAnyArgs()
->getMock();

DAORegistry::registerDAO('NotificationDAO', $notifiactionDaoMock);

$notificationSettingsDaoMock = Mockery::mock(\PKP\notification\NotificationSettingsDAO::class)
->makePartial()
->shouldReceive('updateNotificationSetting')
->withAnyArgs()
->andReturn(null)
->getMock();

DAORegistry::registerDAO('NotificationSettingsDAO', $notificationSettingsDaoMock);

$this->assertNull($openAccessMailUsersJob->handle());
}
}

0 comments on commit 395e781

Please sign in to comment.