diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/Core/Controller/SvgControllerTest.php | 139 | ||||
-rw-r--r-- | tests/data/svg/mixed-red.svg | 1 | ||||
-rw-r--r-- | tests/data/svg/mixed-source.svg | 1 | ||||
-rw-r--r-- | tests/data/svg/rect-black.svg | 1 | ||||
-rw-r--r-- | tests/data/svg/rect-red.svg | 1 | ||||
-rw-r--r-- | tests/lib/Files/Cache/ScannerTest.php | 4 | ||||
-rw-r--r-- | tests/lib/Files/Cache/UpdaterLegacyTest.php | 8 | ||||
-rw-r--r-- | tests/lib/Files/Cache/WatcherTest.php | 2 | ||||
-rw-r--r-- | tests/lib/Files/ObjectStore/NoopScannerTest.php | 2 | ||||
-rw-r--r-- | tests/lib/Files/ViewTest.php | 4 | ||||
-rw-r--r-- | tests/lib/Settings/Admin/SecurityTest.php (renamed from tests/lib/Settings/Admin/EncryptionTest.php) | 12 |
11 files changed, 159 insertions, 16 deletions
diff --git a/tests/Core/Controller/SvgControllerTest.php b/tests/Core/Controller/SvgControllerTest.php new file mode 100644 index 00000000000..7a31d02b90f --- /dev/null +++ b/tests/Core/Controller/SvgControllerTest.php @@ -0,0 +1,139 @@ +<?php +declare (strict_types = 1); +/** + * @copyright Copyright (c) 2018 Michael Weimann <mail@michael-weimann.eu> + * + * @author Michael Weimann <mail@michael-weimann.eu> + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * 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 Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ + +namespace Tests\Core\Controller; + +use OC\AppFramework\Http; +use OC\Core\Controller\SvgController; +use OCP\App\IAppManager; +use OCP\AppFramework\Utility\ITimeFactory; +use OCP\IRequest; +use Test\TestCase; + +/** + * This class provides test cases for the svg controller + */ +class SvgControllerTest extends TestCase { + + const TEST_IMAGES_SOURCE_PATH = __DIR__ . '/../../data/svg'; + const TEST_IMAGES_PATH = __DIR__ . '/../../../core/img/testImages'; + const TEST_IMAGE_MIXED = 'mixed-source.svg'; + const TEST_IMAGE_RECT = 'rect-black.svg'; + const TEST_IMAGES = [ + self::TEST_IMAGE_MIXED, + self::TEST_IMAGE_RECT, + ]; + + /** + * @var SvgController + */ + private $svgController; + + /** + * Copy test svgs into the core img "test" directory. + * + * @beforeClass + * @return void + */ + public static function copyTestImagesIntoPlace() { + mkdir(self::TEST_IMAGES_PATH); + foreach (self::TEST_IMAGES as $testImage) { + copy( + self::TEST_IMAGES_SOURCE_PATH .'/' . $testImage, + self::TEST_IMAGES_PATH . '/' . $testImage + ); + } + } + + /** + * Removes the test svgs from the core img "test" directory. + * + * @afterClass + * @return void + */ + public static function removeTestImages() { + foreach (self::TEST_IMAGES as $testImage) { + unlink(self::TEST_IMAGES_PATH . '/' . $testImage); + } + rmdir(self::TEST_IMAGES_PATH); + } + + /** + * Setups a SVG controller instance for tests. + * + * @before + * @return void + */ + public function setupSvgController() { + $request = $this->getMockBuilder(IRequest::class)->getMock(); + $timeFactory = $this->getMockBuilder(ITimeFactory::class)->getMock(); + $appManager = $this->getMockBuilder(IAppManager::class)->getMock(); + $this->svgController = new SvgController('core', $request, $timeFactory, $appManager); + } + + /** + * Checks that requesting an unknown image results in a 404. + * + * @test + * @return void + */ + public function testGetSvgFromCoreNotFound() { + $response = $this->svgController->getSvgFromCore('huhuu', '2342', '#ff0000'); + self::assertEquals(Http::STATUS_NOT_FOUND, $response->getStatus()); + } + + /** + * Provides svg coloring test data. + * + * @return array + */ + public function provideGetSvgFromCoreTestData(): array { + return [ + 'mixed' => ['mixed-source', 'f00', file_get_contents(self::TEST_IMAGES_SOURCE_PATH . '/mixed-red.svg')], + 'black rect' => ['rect-black', 'f00', file_get_contents(self::TEST_IMAGES_SOURCE_PATH . '/rect-red.svg')], + ]; + } + + /** + * Tests that retrieving a colored SVG works. + * + * @test + * @dataProvider provideGetSvgFromCoreTestData + * @param string $name The requested svg name + * @param string $color The requested color + * @param string $expected The expected svg + * @return void + */ + public function testGetSvgFromCore(string $name, string $color, string $expected) { + $response = $this->svgController->getSvgFromCore('testImages', $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/mixed-red.svg b/tests/data/svg/mixed-red.svg new file mode 100644 index 00000000000..5e3727abd46 --- /dev/null +++ b/tests/data/svg/mixed-red.svg @@ -0,0 +1 @@ +<svg width="50mm" height="50mm" version="1.1" viewBox="0 0 50 50" xmlns="http://www.w3.org/2000/svg"><g transform="translate(0,-247)"><rect x="3.3609" y="250.93" width="16.253" height="15.497" fill="#f00"/><ellipse cx="37.089" cy="257.97" rx="8.5517" ry="7.9375" fill="#f00"/><circle cx="12.19" cy="281.31" r="10" fill="#f00"/><rect x="29.293" y="272.81" width="16.253" height="15.497" fill="#f00"/></g></svg> diff --git a/tests/data/svg/mixed-source.svg b/tests/data/svg/mixed-source.svg new file mode 100644 index 00000000000..e4a94136c52 --- /dev/null +++ b/tests/data/svg/mixed-source.svg @@ -0,0 +1 @@ +<svg width="50mm" height="50mm" version="1.1" viewBox="0 0 50 50" xmlns="http://www.w3.org/2000/svg"><g transform="translate(0,-247)"><rect x="3.3609" y="250.93" width="16.253" height="15.497"/><ellipse cx="37.089" cy="257.97" rx="8.5517" ry="7.9375" fill="#123456"/><circle cx="12.19" cy="281.31" r="10"/><rect x="29.293" y="272.81" width="16.253" height="15.497" fill="#6474a5"/></g></svg> diff --git a/tests/data/svg/rect-black.svg b/tests/data/svg/rect-black.svg new file mode 100644 index 00000000000..85ab8442c35 --- /dev/null +++ b/tests/data/svg/rect-black.svg @@ -0,0 +1 @@ +<svg width="50mm" height="50mm" version="1.1" viewBox="0 0 50 50" xmlns="http://www.w3.org/2000/svg"><g transform="translate(0,-247)"><rect x="10" y="257" width="30" height="30"/></g></svg> diff --git a/tests/data/svg/rect-red.svg b/tests/data/svg/rect-red.svg new file mode 100644 index 00000000000..8f0fae7f617 --- /dev/null +++ b/tests/data/svg/rect-red.svg @@ -0,0 +1 @@ +<svg width="50mm" height="50mm" version="1.1" viewBox="0 0 50 50" xmlns="http://www.w3.org/2000/svg"><g transform="translate(0,-247)"><rect x="10" y="257" width="30" height="30" fill="#f00"/></g></svg> diff --git a/tests/lib/Files/Cache/ScannerTest.php b/tests/lib/Files/Cache/ScannerTest.php index 075716f8033..736df2174d1 100644 --- a/tests/lib/Files/Cache/ScannerTest.php +++ b/tests/lib/Files/Cache/ScannerTest.php @@ -60,7 +60,7 @@ class ScannerTest extends \Test\TestCase { $this->assertEquals($cachedData['mimetype'], 'text/plain'); $this->assertNotEquals($cachedData['parent'], -1); //parent folders should be scanned automatically - $data = file_get_contents(\OC::$SERVERROOT . '/core/img/logo.png'); + $data = file_get_contents(\OC::$SERVERROOT . '/core/img/logo/logo.png'); $this->storage->file_put_contents('foo.png', $data); $this->scanner->scanFile('foo.png'); @@ -98,7 +98,7 @@ class ScannerTest extends \Test\TestCase { private function fillTestFolders() { $textData = "dummy file data\n"; - $imgData = file_get_contents(\OC::$SERVERROOT . '/core/img/logo.png'); + $imgData = file_get_contents(\OC::$SERVERROOT . '/core/img/logo/logo.png'); $this->storage->mkdir('folder'); $this->storage->file_put_contents('foo.txt', $textData); $this->storage->file_put_contents('foo.png', $imgData); diff --git a/tests/lib/Files/Cache/UpdaterLegacyTest.php b/tests/lib/Files/Cache/UpdaterLegacyTest.php index 707ed70af23..66fa8d51932 100644 --- a/tests/lib/Files/Cache/UpdaterLegacyTest.php +++ b/tests/lib/Files/Cache/UpdaterLegacyTest.php @@ -42,7 +42,7 @@ class UpdaterLegacyTest extends \Test\TestCase { $this->storage = new \OC\Files\Storage\Temporary(array()); $textData = "dummy file data\n"; - $imgData = file_get_contents(\OC::$SERVERROOT . '/core/img/logo.png'); + $imgData = file_get_contents(\OC::$SERVERROOT . '/core/img/logo/logo.png'); $this->storage->mkdir('folder'); $this->storage->file_put_contents('foo.txt', $textData); $this->storage->file_put_contents('foo.png', $imgData); @@ -84,7 +84,7 @@ class UpdaterLegacyTest extends \Test\TestCase { public function testWrite() { $textSize = strlen("dummy file data\n"); - $imageSize = filesize(\OC::$SERVERROOT . '/core/img/logo.png'); + $imageSize = filesize(\OC::$SERVERROOT . '/core/img/logo/logo.png'); $this->cache->put('foo.txt', array('mtime' => 100, 'storage_mtime' => 150)); $rootCachedData = $this->cache->get(''); $this->assertEquals(3 * $textSize + $imageSize, $rootCachedData['size']); @@ -145,7 +145,7 @@ class UpdaterLegacyTest extends \Test\TestCase { public function testDelete() { $textSize = strlen("dummy file data\n"); - $imageSize = filesize(\OC::$SERVERROOT . '/core/img/logo.png'); + $imageSize = filesize(\OC::$SERVERROOT . '/core/img/logo/logo.png'); $rootCachedData = $this->cache->get(''); $oldEtag = $rootCachedData['etag']; $this->assertEquals(3 * $textSize + $imageSize, $rootCachedData['size']); @@ -206,7 +206,7 @@ class UpdaterLegacyTest extends \Test\TestCase { public function testRename() { $textSize = strlen("dummy file data\n"); - $imageSize = filesize(\OC::$SERVERROOT . '/core/img/logo.png'); + $imageSize = filesize(\OC::$SERVERROOT . '/core/img/logo/logo.png'); $rootCachedData = $this->cache->get(''); $this->assertEquals(3 * $textSize + $imageSize, $rootCachedData['size']); diff --git a/tests/lib/Files/Cache/WatcherTest.php b/tests/lib/Files/Cache/WatcherTest.php index 3834b5591ff..d4aa9ac875e 100644 --- a/tests/lib/Files/Cache/WatcherTest.php +++ b/tests/lib/Files/Cache/WatcherTest.php @@ -179,7 +179,7 @@ class WatcherTest extends \Test\TestCase { private function getTestStorage($scan = true) { $storage = new \OC\Files\Storage\Temporary(array()); $textData = "dummy file data\n"; - $imgData = file_get_contents(\OC::$SERVERROOT . '/core/img/logo.png'); + $imgData = file_get_contents(\OC::$SERVERROOT . '/core/img/logo/logo.png'); $storage->mkdir('folder'); $storage->file_put_contents('foo.txt', $textData); $storage->file_put_contents('foo.png', $imgData); diff --git a/tests/lib/Files/ObjectStore/NoopScannerTest.php b/tests/lib/Files/ObjectStore/NoopScannerTest.php index 16bd325a8df..6d593225e97 100644 --- a/tests/lib/Files/ObjectStore/NoopScannerTest.php +++ b/tests/lib/Files/ObjectStore/NoopScannerTest.php @@ -38,7 +38,7 @@ class NoopScannerTest extends \Test\TestCase { private function fillTestFolders() { $textData = "dummy file data\n"; - $imgData = file_get_contents(\OC::$SERVERROOT . '/core/img/logo.png'); + $imgData = file_get_contents(\OC::$SERVERROOT . '/core/img/logo/logo.png'); $this->storage->mkdir('folder'); $this->storage->file_put_contents('foo.txt', $textData); $this->storage->file_put_contents('foo.png', $imgData); diff --git a/tests/lib/Files/ViewTest.php b/tests/lib/Files/ViewTest.php index 9b435f2b935..97e3d42684f 100644 --- a/tests/lib/Files/ViewTest.php +++ b/tests/lib/Files/ViewTest.php @@ -142,7 +142,7 @@ class ViewTest extends \Test\TestCase { Filesystem::mount($storage2, array(), $root . '/substorage'); Filesystem::mount($storage3, array(), $root . '/folder/anotherstorage'); $textSize = strlen("dummy file data\n"); - $imageSize = filesize(\OC::$SERVERROOT . '/core/img/logo.png'); + $imageSize = filesize(\OC::$SERVERROOT . '/core/img/logo/logo.png'); $storageSize = $textSize * 2 + $imageSize; $storageInfo = $storage3->getCache()->get(''); @@ -658,7 +658,7 @@ class ViewTest extends \Test\TestCase { */ $storage = new $class(array()); $textData = "dummy file data\n"; - $imgData = file_get_contents(\OC::$SERVERROOT . '/core/img/logo.png'); + $imgData = file_get_contents(\OC::$SERVERROOT . '/core/img/logo/logo.png'); $storage->mkdir('folder'); $storage->file_put_contents('foo.txt', $textData); $storage->file_put_contents('foo.png', $imgData); diff --git a/tests/lib/Settings/Admin/EncryptionTest.php b/tests/lib/Settings/Admin/SecurityTest.php index 9be2a3f46d9..a7c56f697b0 100644 --- a/tests/lib/Settings/Admin/EncryptionTest.php +++ b/tests/lib/Settings/Admin/SecurityTest.php @@ -24,13 +24,13 @@ namespace Test\Settings\Admin; use OC\Encryption\Manager; -use OC\Settings\Admin\Encryption; +use OC\Settings\Admin\Security; use OCP\AppFramework\Http\TemplateResponse; use OCP\IUserManager; use Test\TestCase; -class EncryptionTest extends TestCase { - /** @var Encryption */ +class SecurityTest extends TestCase { + /** @var Security */ private $admin; /** @var Manager */ private $manager; @@ -42,7 +42,7 @@ class EncryptionTest extends TestCase { $this->manager = $this->getMockBuilder('\OC\Encryption\Manager')->disableOriginalConstructor()->getMock(); $this->userManager = $this->getMockBuilder(IUserManager::class)->getMock(); - $this->admin = new Encryption( + $this->admin = new Security( $this->manager, $this->userManager ); @@ -81,7 +81,7 @@ class EncryptionTest extends TestCase { ->willReturn(['entry']); $expected = new TemplateResponse( 'settings', - 'settings/admin/encryption', + 'settings/admin/security', [ 'encryptionEnabled' => $enabled, 'encryptionReady' => $enabled, @@ -116,7 +116,7 @@ class EncryptionTest extends TestCase { ->willReturn(['entry', 'entry']); $expected = new TemplateResponse( 'settings', - 'settings/admin/encryption', + 'settings/admin/security', [ 'encryptionEnabled' => $enabled, 'encryptionReady' => $enabled, |