forked from vufind-org/vufind
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
BrowZine covers: skip over default images.
- Loading branch information
1 parent
feaa67e
commit a72c79c
Showing
4 changed files
with
102 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"data":[{"id":1,"type":"journals","title":"Default Cover Journal","issn":"12345678","sjrValue":0,"coverImageUrl":"https:\/\/assets.thirdiron.com\/default-journal-cover.png","browzineEnabled":false,"externalLink":"https:\/\/fake-external-link.com"}]} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"data":[{"id":1,"type":"journals","title":"Non-default Cover Journal","issn":"12345678","sjrValue":0,"coverImageUrl":"https:\/\/assets.thirdiron.com\/simulated-real-cover.png","browzineEnabled":false,"externalLink":"https:\/\/fake-external-link.com"}]} |
92 changes: 92 additions & 0 deletions
92
module/VuFind/tests/unit-tests/src/VuFindTest/Content/Covers/BrowZineTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
<?php | ||
|
||
/** | ||
* Unit tests for BrowZine cover loader. | ||
* | ||
* PHP version 8 | ||
* | ||
* Copyright (C) Villanova University 2025. | ||
* | ||
* This program is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License version 2, | ||
* as published by the Free Software Foundation. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program; if not, write to the Free Software | ||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
* | ||
* @category VuFind | ||
* @package Tests | ||
* @author Demian Katz <demian.katz@villanova.edu> | ||
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License | ||
* @link https://vufind.org | ||
*/ | ||
|
||
namespace VuFindTest\Content\Covers; | ||
|
||
use VuFind\Content\Covers\BrowZine; | ||
|
||
/** | ||
* Unit tests for BrowZine cover loader. | ||
* | ||
* @category VuFind | ||
* @package Tests | ||
* @author Demian Katz <demian.katz@villanova.edu> | ||
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License | ||
* @link https://vufind.org | ||
*/ | ||
class BrowZineTest extends \PHPUnit\Framework\TestCase | ||
{ | ||
use \VuFindTest\Feature\FixtureTrait; | ||
|
||
/** | ||
* Data provider for testCoverLoading. | ||
* | ||
* @return array[] | ||
*/ | ||
public static function coverProvider(): array | ||
{ | ||
return [ | ||
'no issn' => [[], null, false], | ||
'default cover' => [['issn' => '12345678'], 'browzine/cover-default.json', false], | ||
'non-default cover' => [ | ||
['issn' => '12345678'], | ||
'browzine/cover-non-default.json', | ||
'https://assets.thirdiron.com/simulated-real-cover.png', | ||
], | ||
]; | ||
} | ||
|
||
/** | ||
* Test cover loading | ||
* | ||
* @param array $ids Array of IDs to look up | ||
* @param ?string $fixture Fixture to return from backend | ||
* @param string|bool $expected Expected cover URL | ||
* | ||
* @return void | ||
* | ||
* @dataProvider coverProvider | ||
*/ | ||
public function testCoverLoading(array $ids, ?string $fixture, string|bool $expected): void | ||
{ | ||
$service = $this->createMock(\VuFindSearch\Service::class); | ||
if ($fixture) { | ||
$service->method('invoke')->willReturnCallback( | ||
function ($command) use ($fixture, $ids) { | ||
$this->assertEquals([$ids['issn']], $command->getArguments()); | ||
$fakeCommand = $this->createMock($command::class); | ||
$fakeCommand->method('getResult')->willReturn($this->getJsonFixture($fixture)); | ||
return $fakeCommand; | ||
} | ||
); | ||
} | ||
$loader = new BrowZine($service); | ||
$this->assertEquals($expected, $loader->getUrl('', 'small', $ids)); | ||
} | ||
} |