Skip to content

Commit 17e10a2

Browse files
Merge pull request #57868 from nextcloud/backport/57861/stable33
[stable33] test(preview): properly test postscript preview provider
2 parents f878a4e + 4fba873 commit 17e10a2

File tree

4 files changed

+25
-20
lines changed

4 files changed

+25
-20
lines changed

.github/workflows/phpunit-sqlite.yml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,14 +86,17 @@ jobs:
8686
with:
8787
php-version: ${{ matrix.php-versions }}
8888
# https://docs.nextcloud.com/server/stable/admin_manual/installation/source_installation.html#prerequisites-for-manual-installation
89-
extensions: bz2, ctype, curl, dom, fileinfo, gd, iconv, intl, json, libxml, mbstring, openssl, pcntl, posix, redis, session, simplexml, xmlreader, xmlwriter, zip, zlib, sqlite, pdo_sqlite
89+
extensions: bz2, ctype, curl, dom, fileinfo, gd, iconv, imagick, intl, json, libxml, mbstring, openssl, pcntl, posix, redis, session, simplexml, xmlreader, xmlwriter, zip, zlib, sqlite, pdo_sqlite
9090
coverage: ${{ matrix.coverage && 'xdebug' || 'none' }}
9191
ini-file: development
9292
env:
9393
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
9494

9595
- name: Set up dependencies
96-
run: composer i
96+
run: |
97+
sudo apt-get update
98+
sudo apt-get install -y ghostscript
99+
composer i
97100
98101
- name: Set up Nextcloud
99102
run: |
@@ -107,7 +110,7 @@ jobs:
107110
run: ./occ app:list && echo "======= System config =======" && ./occ config:list system
108111

109112
- name: PHPUnit database tests
110-
run: composer run test:db -- --log-junit junit.xml ${{ matrix.coverage && '--coverage-clover ./clover.db.xml' || '' }}
113+
run: composer run test:db -- --log-junit junit.xml ${{ matrix.coverage && '--coverage-clover ./clover.db.xml' || '' }} tests/lib/Preview/PostscriptTest.php
111114

112115
- name: Upload db code coverage
113116
if: ${{ !cancelled() && matrix.coverage }}
@@ -125,6 +128,8 @@ jobs:
125128
- name: Print logs
126129
if: always()
127130
run: |
131+
gs --version
132+
cat /etc/ImageMagick-6/policy.xml
128133
cat data/nextcloud.log
129134
130135
summary:

lib/private/Preview/Postscript.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,6 @@ public function getMimeType(): string {
2020
* {@inheritDoc}
2121
*/
2222
protected function getAllowedMimeTypes(): string {
23-
return '/application\/postscript/';
23+
return '/(application\/postscript|image\/x-eps)/';
2424
}
2525
}
Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,22 @@
88

99
namespace Test\Preview;
1010

11+
use OC\BinaryFinder;
1112
use OC\Preview\Postscript;
1213

13-
/**
14-
* Class BitmapTest
15-
*
16-
*
17-
* @package Test\Preview
18-
*/
1914
#[\PHPUnit\Framework\Attributes\Group('DB')]
20-
class BitmapTest extends Provider {
15+
#[\PHPUnit\Framework\Attributes\RequiresPhpExtension('imagick')]
16+
class PostscriptTest extends Provider {
17+
2118
protected function setUp(): void {
19+
if (\Imagick::queryFormats('EPS') === false || \Imagick::queryFormats('PS') === false) {
20+
$this->markTestSkipped('Imagick does not support postscript.');
21+
}
22+
if (\OCP\Server::get(BinaryFinder::class)->findBinaryPath('gs') === false) {
23+
// Imagick forwards postscript rendering to Ghostscript but does not report this in queryFormats
24+
$this->markTestSkipped('Ghostscript is not installed.');
25+
}
26+
2227
parent::setUp();
2328

2429
$fileName = 'testimage.eps';

tests/lib/Preview/Provider.php

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,19 @@
1313
use OC\Files\Storage\Storage;
1414
use OC\Files\Storage\Temporary;
1515
use OC\Files\View;
16+
use OC\Preview\ProviderV2;
1617
use OC\Preview\TXT;
1718
use OCP\Files\IRootFolder;
1819
use OCP\IImage;
1920
use OCP\IUserManager;
21+
use OCP\Preview\IProviderV2;
2022
use OCP\Server;
2123

2224
abstract class Provider extends \Test\TestCase {
2325
protected string $imgPath;
2426
protected int $width;
2527
protected int $height;
26-
/** @var \OC\Preview\Provider|mixed $provider */
27-
protected $provider;
28+
protected IProviderV2 $provider;
2829
protected int $maxWidth = 1024;
2930
protected int $maxHeight = 1024;
3031
protected bool $scalingUp = false;
@@ -119,18 +120,12 @@ protected function prepareTestFile($fileName, $fileContent) {
119120
/**
120121
* Retrieves a max size thumbnail can be created
121122
*
122-
* @param \OC\Preview\Provider $provider
123-
*
124123
* @return bool|IImage
125124
*/
126-
private function getPreview($provider) {
125+
private function getPreview(ProviderV2 $provider) {
127126
$file = new File(Server::get(IRootFolder::class), $this->rootView, $this->imgPath);
128127
$preview = $provider->getThumbnail($file, $this->maxWidth, $this->maxHeight, $this->scalingUp);
129128

130-
if (get_class($this) === BitmapTest::class && $preview === null) {
131-
$this->markTestSkipped('An error occured while operating with Imagick.');
132-
}
133-
134129
$this->assertNotEquals(false, $preview);
135130
$this->assertEquals(true, $preview->valid());
136131

0 commit comments

Comments
 (0)