Skip to content

Commit

Permalink
BrowZine covers: skip over default images.
Browse files Browse the repository at this point in the history
  • Loading branch information
demiankatz committed Jan 31, 2025
1 parent feaa67e commit a72c79c
Show file tree
Hide file tree
Showing 4 changed files with 102 additions and 6 deletions.
14 changes: 8 additions & 6 deletions module/VuFind/src/VuFind/Content/Covers/BrowZine.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
use VuFindSearch\Backend\BrowZine\Command\LookupIssnsCommand;
use VuFindSearch\Service;

use function in_array;

/**
* BrowZine cover content loader.
*
Expand All @@ -44,20 +46,19 @@
class BrowZine extends \VuFind\Content\AbstractCover
{
/**
* Search service
* Cover image URLs to ignore (we don't want to display third-party generic images).
*
* @var Service
* @var string[]
*/
protected $searchService;
protected $ignoreList = ['https://assets.thirdiron.com/default-journal-cover.png'];

/**
* Constructor
*
* @param Service $searchService Search service
*/
public function __construct(Service $searchService)
public function __construct(protected Service $searchService)
{
$this->searchService = $searchService;
$this->supportsIssn = true;
}

Expand All @@ -82,6 +83,7 @@ public function getUrl($key, $size, $ids)

$command = new LookupIssnsCommand('BrowZine', $ids['issn']);
$result = $this->searchService->invoke($command)->getResult();
return $result['data'][0]['coverImageUrl'] ?? false;
$url = $result['data'][0]['coverImageUrl'] ?? false;
return ($url && in_array($url, $this->ignoreList)) ? false : $url;
}
}
1 change: 1 addition & 0 deletions module/VuFind/tests/fixtures/browzine/cover-default.json
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"}]}
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"}]}
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));
}
}

0 comments on commit a72c79c

Please sign in to comment.