summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorMorris Jobke <hey@morrisjobke.de>2020-04-27 10:58:34 +0200
committerGitHub <noreply@github.com>2020-04-27 10:58:34 +0200
commit9b7e24a7a1c1059c7f2a0568b2d5c29f512618f8 (patch)
tree423ff5692fa16e047b2a8a608d6b1e27ea64d613 /tests
parent3c5c4caa4da7fee700ba683bb75e3b8aa7c1b190 (diff)
parentd766d09f01314c5db7dc54288884edb6a159321e (diff)
downloadnextcloud-server-9b7e24a7a1c1059c7f2a0568b2d5c29f512618f8.tar.gz
nextcloud-server-9b7e24a7a1c1059c7f2a0568b2d5c29f512618f8.zip
Merge pull request #19084 from nextcloud/bug/13556/wrong-paths-for-svg
Make it possible to resolve svg's outside \OC::$SERVERROOT
Diffstat (limited to 'tests')
-rw-r--r--tests/Core/Controller/SvgControllerTest.php65
-rw-r--r--tests/data/svg/files-app-red.svg1
-rw-r--r--tests/data/svg/settings-admin-red.svg1
-rw-r--r--tests/lib/App/AppManagerTest.php29
4 files changed, 92 insertions, 4 deletions
diff --git a/tests/Core/Controller/SvgControllerTest.php b/tests/Core/Controller/SvgControllerTest.php
index 76d04d1af32..f6208d6f6c4 100644
--- a/tests/Core/Controller/SvgControllerTest.php
+++ b/tests/Core/Controller/SvgControllerTest.php
@@ -28,6 +28,7 @@ namespace Tests\Core\Controller;
use OC\AppFramework\Http;
use OC\Core\Controller\SvgController;
use OC\Template\IconsCacher;
+use OCP\App\AppPathNotFoundException;
use OCP\App\IAppManager;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\IRequest;
@@ -46,6 +47,9 @@ class SvgControllerTest extends TestCase {
self::TEST_IMAGE_RECT,
];
+ /** @var IAppManager|\PHPUnit_Framework_MockObject_MockObject */
+ private $appManager;
+
/**
* @var SvgController
*/
@@ -87,17 +91,20 @@ class SvgControllerTest extends TestCase {
* @return void
*/
public function setupSvgController() {
+ /** @var IRequest */
$request = $this->getMockBuilder(IRequest::class)->getMock();
+ /** @var ITimeFactory $timeFactory */
$timeFactory = $this->getMockBuilder(ITimeFactory::class)->getMock();
- $appManager = $this->getMockBuilder(IAppManager::class)->getMock();
+ /** @var IAppManager */
+ $this->appManager = $this->getMockBuilder(IAppManager::class)->getMock();
+ /** @var IconsCacher $iconsCacher */
$iconsCacher = $this->getMockBuilder(IconsCacher::class)->disableOriginalConstructor()->setMethods(['__construct'])->getMock();
- $this->svgController = new SvgController('core', $request, $timeFactory, $appManager, $iconsCacher);
+ $this->svgController = new SvgController('core', $request, $timeFactory, $this->appManager, $iconsCacher);
}
/**
* Checks that requesting an unknown image results in a 404.
*
- * @test
* @return void
*/
public function testGetSvgFromCoreNotFound() {
@@ -120,7 +127,6 @@ class SvgControllerTest extends TestCase {
/**
* Tests that retrieving a colored SVG works.
*
- * @test
* @dataProvider provideGetSvgFromCoreTestData
* @param string $name The requested svg name
* @param string $color The requested color
@@ -138,4 +144,55 @@ class SvgControllerTest extends TestCase {
self::assertEquals($expected, $response->getData());
}
+
+ /**
+ * Checks that requesting an unknown image results in a 404.
+ */
+ public function testGetSvgFromAppNotFound(): void {
+ $this->appManager->expects($this->once())
+ ->method('getAppPath')
+ ->with('invalid_app')
+ ->willThrowException(new AppPathNotFoundException('Could not find path for invalid_app'));
+
+ $response = $this->svgController->getSvgFromApp('invalid_app', 'some-icon', '#ff0000');
+ self::assertEquals(Http::STATUS_NOT_FOUND, $response->getStatus());
+ }
+
+ /**
+ * Provides svg coloring test data.
+ *
+ * @return array
+ */
+ public function provideGetSvgFromAppTestData(): array {
+ return [
+ 'settings admin' => ['settings', 'admin', 'f00', file_get_contents(self::TEST_IMAGES_SOURCE_PATH . '/settings-admin-red.svg')],
+ 'files app' => ['files', 'app', 'f00', file_get_contents(self::TEST_IMAGES_SOURCE_PATH . '/files-app-red.svg')],
+ ];
+ }
+
+ /**
+ * Tests that retrieving a colored SVG works.
+ *
+ * @dataProvider provideGetSvgFromAppTestData
+ * @param string $appName
+ * @param string $name The requested svg name
+ * @param string $color The requested color
+ * @param string $expected
+ */
+ public function testGetSvgFromApp(string $appName, string $name, string $color, string $expected): void {
+ $this->appManager->expects($this->once())
+ ->method('getAppPath')
+ ->with($appName)
+ ->willReturn(__DIR__ . '/../../../apps/' . $appName);
+
+ $response = $this->svgController->getSvgFromApp($appName, $name, $color);
+
+ self::assertEquals(Http::STATUS_OK, $response->getStatus());
+
+ $headers = $response->getHeaders();
+ self::assertArrayHasKey('Content-Type', $headers);
+ self::assertEquals($headers['Content-Type'], 'image/svg+xml');
+
+ self::assertEquals($expected, $response->getData());
+ }
}
diff --git a/tests/data/svg/files-app-red.svg b/tests/data/svg/files-app-red.svg
new file mode 100644
index 00000000000..81d7fca1472
--- /dev/null
+++ b/tests/data/svg/files-app-red.svg
@@ -0,0 +1 @@
+<svg xmlns="http://www.w3.org/2000/svg" height="32" viewBox="0 0 32 32" width="32" version="1.1"><path fill="#f00" d="m3 4c-0.5 0-1 0.5-1 1v22c0 0.52 0.48 1 1 1h26c0.52 0 1-0.482 1-1v-18c0-0.5-0.5-1-1-1h-13l-4-4z"/></svg>
diff --git a/tests/data/svg/settings-admin-red.svg b/tests/data/svg/settings-admin-red.svg
new file mode 100644
index 00000000000..54d7d3a9b15
--- /dev/null
+++ b/tests/data/svg/settings-admin-red.svg
@@ -0,0 +1 @@
+<svg xmlns="http://www.w3.org/2000/svg" viewbox="0 0 16 16" height="16" width="16" version="1.1"><path color="#000" d="m1 1v4h4v-4h-4zm5 1v2h8v-2h-8zm-5 4v4h4v-4h-4zm5 1v2h8v-2h-8zm-5 4v4h4v-4h-4zm1 1h2v2h-2v-2zm4 0v2h8v-2h-8z" fill="#f00"/></svg>
diff --git a/tests/lib/App/AppManagerTest.php b/tests/lib/App/AppManagerTest.php
index 1a5d6c648a1..5b6fedb1cc2 100644
--- a/tests/lib/App/AppManagerTest.php
+++ b/tests/lib/App/AppManagerTest.php
@@ -338,6 +338,35 @@ class AppManagerTest extends TestCase {
$this->assertEquals(\OC::$SERVERROOT . '/apps/files', $this->manager->getAppPath('files'));
}
+ public function testGetAppPathSymlink() {
+ $fakeAppDirname = sha1(uniqid('test', true));
+ $fakeAppPath = sys_get_temp_dir() . '/' . $fakeAppDirname;
+ $fakeAppLink = \OC::$SERVERROOT . '/' . $fakeAppDirname;
+
+ mkdir($fakeAppPath);
+ if (symlink($fakeAppPath, $fakeAppLink) === false) {
+ $this->markTestSkipped('Failed to create symlink');
+ }
+
+ // Use the symlink as the app path
+ \OC::$APPSROOTS[] = [
+ 'path' => $fakeAppLink,
+ 'url' => \OC::$WEBROOT . '/' . $fakeAppDirname,
+ 'writable' => false,
+ ];
+
+ $fakeTestAppPath = $fakeAppPath . '/' . 'test-test-app';
+ mkdir($fakeTestAppPath);
+
+ $generatedAppPath = $this->manager->getAppPath('test-test-app');
+
+ rmdir($fakeTestAppPath);
+ unlink($fakeAppLink);
+ rmdir($fakeAppPath);
+
+ $this->assertEquals($fakeAppLink . '/test-test-app', $generatedAppPath);
+ }
+
public function testGetAppPathFail() {
$this->expectException(AppPathNotFoundException::class);
$this->manager->getAppPath('testnotexisting');