summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/Core/Controller/CssControllerTest.php111
-rw-r--r--tests/karma.config.js1
-rw-r--r--tests/lib/DB/DBSchemaTest.php13
-rw-r--r--tests/lib/DB/LegacyDBTest.php7
-rw-r--r--tests/lib/DB/SchemaDiffTest.php8
-rw-r--r--tests/lib/Files/Stream/StaticStreamTest.php70
-rw-r--r--tests/lib/Memcache/APCTest.php26
-rw-r--r--tests/lib/Repair/RepairInvalidSharesTest.php67
-rw-r--r--tests/lib/User/SessionTest.php14
-rw-r--r--tests/lib/UserTest.php2
10 files changed, 215 insertions, 104 deletions
diff --git a/tests/Core/Controller/CssControllerTest.php b/tests/Core/Controller/CssControllerTest.php
new file mode 100644
index 00000000000..60fef9dddad
--- /dev/null
+++ b/tests/Core/Controller/CssControllerTest.php
@@ -0,0 +1,111 @@
+<?php
+/**
+ * @copyright 2017, Roeland Jago Douma <roeland@famdouma.nl>
+ *
+ * @author Roeland Jago Douma <roeland@famdouma.nl>
+ *
+ * @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\Core\Controller\CssController;
+use OC\HintException;
+use OCP\AppFramework\Http;
+use OCP\AppFramework\Http\FileDisplayResponse;
+use OCP\AppFramework\Http\NotFoundResponse;
+use OCP\AppFramework\Utility\ITimeFactory;
+use OCP\Files\IAppData;
+use OCP\Files\NotFoundException;
+use OCP\Files\SimpleFS\ISimpleFile;
+use OCP\Files\SimpleFS\ISimpleFolder;
+use OCP\IRequest;
+use Test\TestCase;
+
+class CssControllerTest extends TestCase {
+
+ /** @var IAppData|\PHPUnit_Framework_MockObject_MockObject */
+ private $appData;
+
+ /** @var CssController */
+ private $controller;
+
+ public function setUp() {
+ parent::setUp();
+
+ $this->appData = $this->createMock(IAppData::class);
+
+ $timeFactory = $this->createMock(ITimeFactory::class);
+ $timeFactory->method('getTime')
+ ->willReturn(1337);
+
+ $this->controller = new CssController(
+ 'core',
+ $this->createMock(IRequest::class),
+ $this->appData,
+ $timeFactory
+ );
+ }
+
+ public function testNoCssFolderForApp() {
+ $this->appData->method('getFolder')
+ ->with('myapp')
+ ->willThrowException(new NotFoundException());
+
+ $result = $this->controller->getCss('file.css', 'myapp');
+
+ $this->assertInstanceOf(NotFoundResponse::class, $result);
+ }
+
+
+ public function testNoCssFile() {
+ $folder = $this->createMock(ISimpleFolder::class);
+ $this->appData->method('getFolder')
+ ->with('myapp')
+ ->willReturn($folder);
+
+ $folder->method('getFile')
+ ->willThrowException(new NotFoundException());
+
+ $result = $this->controller->getCss('file.css', 'myapp');
+
+ $this->assertInstanceOf(NotFoundResponse::class, $result);
+ }
+
+ public function testGetFile() {
+ $folder = $this->createMock(ISimpleFolder::class);
+ $file = $this->createMock(ISimpleFile::class);
+ $this->appData->method('getFolder')
+ ->with('myapp')
+ ->willReturn($folder);
+
+ $folder->method('getFile')
+ ->with('file.css')
+ ->willReturn($file);
+
+ $expected = new FileDisplayResponse($file, Http::STATUS_OK, ['Content-Type' => 'text/css']);
+ $expected->cacheFor(86400);
+ $expires = new \DateTime();
+ $expires->setTimestamp(1337);
+ $expires->add(new \DateInterval('PT24H'));
+ $expected->addHeader('Expires', $expires->format(\DateTime::RFC1123));
+ $expected->addHeader('Pragma', 'cache');
+
+ $result = $this->controller->getCss('file.css', 'myapp');
+ $this->assertEquals($expected, $result);
+ }
+
+}
diff --git a/tests/karma.config.js b/tests/karma.config.js
index f20672f4a55..933d6c57410 100644
--- a/tests/karma.config.js
+++ b/tests/karma.config.js
@@ -223,6 +223,7 @@ module.exports = function(config) {
// include core CSS
files.push({pattern: 'core/css/*.css', watched: true, included: true, served: true});
+ files.push({pattern: 'tests/css/*.css', watched: true, included: true, served: true});
config.set({
diff --git a/tests/lib/DB/DBSchemaTest.php b/tests/lib/DB/DBSchemaTest.php
index ba17546a34a..8eb7fcf81b4 100644
--- a/tests/lib/DB/DBSchemaTest.php
+++ b/tests/lib/DB/DBSchemaTest.php
@@ -10,6 +10,7 @@ namespace Test\DB;
use Doctrine\DBAL\Platforms\SqlitePlatform;
use OC_DB;
+use OCP\ITempManager;
use OCP\Security\ISecureRandom;
use Test\TestCase;
@@ -19,14 +20,20 @@ use Test\TestCase;
* @group DB
*/
class DBSchemaTest extends TestCase {
- protected $schema_file = 'static://test_db_scheme';
- protected $schema_file2 = 'static://test_db_scheme2';
+ protected $schema_file;
+ protected $schema_file2;
protected $table1;
protected $table2;
+ /** @var ITempManager */
+ protected $tempManager;
protected function setUp() {
parent::setUp();
+ $this->tempManager = \OC::$server->getTempManager();
+ $this->schema_file = $this->tempManager->getTemporaryFile();
+ $this->schema_file2 = $this->tempManager->getTemporaryFile();
+
$dbfile = \OC::$SERVERROOT.'/tests/data/db_structure.xml';
$dbfile2 = \OC::$SERVERROOT.'/tests/data/db_structure2.xml';
@@ -73,7 +80,7 @@ class DBSchemaTest extends TestCase {
}
public function doTestSchemaDumping() {
- $outfile = 'static://db_out.xml';
+ $outfile = $this->tempManager->getTemporaryFile();
OC_DB::getDbStructure($outfile);
$content = file_get_contents($outfile);
$this->assertContains($this->table1, $content);
diff --git a/tests/lib/DB/LegacyDBTest.php b/tests/lib/DB/LegacyDBTest.php
index f3de570c52d..3cf40228225 100644
--- a/tests/lib/DB/LegacyDBTest.php
+++ b/tests/lib/DB/LegacyDBTest.php
@@ -18,9 +18,14 @@ use OC_DB;
class LegacyDBTest extends \Test\TestCase {
protected $backupGlobals = FALSE;
- protected static $schema_file = 'static://test_db_scheme';
+ protected static $schema_file;
protected $test_prefix;
+ public static function setUpBeforeClass() {
+ self::$schema_file = \OC::$server->getTempManager()->getTemporaryFile();
+ }
+
+
/**
* @var string
*/
diff --git a/tests/lib/DB/SchemaDiffTest.php b/tests/lib/DB/SchemaDiffTest.php
index b7bb3c2a9cb..88c9abeb431 100644
--- a/tests/lib/DB/SchemaDiffTest.php
+++ b/tests/lib/DB/SchemaDiffTest.php
@@ -47,9 +47,13 @@ class SchemaDiffTest extends TestCase {
/** @var string */
private $testPrefix;
+ private $schemaFile;
+
protected function setUp() {
parent::setUp();
+ $this->schemaFile = \OC::$server->getTempManager()->getTemporaryFile();
+
$this->config = \OC::$server->getConfig();
$this->connection = \OC::$server->getDatabaseConnection();
$this->manager = new MDB2SchemaManager($this->connection);
@@ -57,7 +61,7 @@ class SchemaDiffTest extends TestCase {
}
protected function tearDown() {
- $this->manager->removeDBStructure('static://test_db_scheme');
+ $this->manager->removeDBStructure($this->schemaFile);
parent::tearDown();
}
@@ -68,7 +72,7 @@ class SchemaDiffTest extends TestCase {
public function testZeroChangeOnSchemaMigrations($xml) {
$xml = str_replace( '*dbprefix*', $this->testPrefix, $xml );
- $schemaFile = 'static://test_db_scheme';
+ $schemaFile = $this->schemaFile;
file_put_contents($schemaFile, $xml);
// apply schema
diff --git a/tests/lib/Files/Stream/StaticStreamTest.php b/tests/lib/Files/Stream/StaticStreamTest.php
deleted file mode 100644
index 309291a3a5b..00000000000
--- a/tests/lib/Files/Stream/StaticStreamTest.php
+++ /dev/null
@@ -1,70 +0,0 @@
-<?php
-/**
- * Copyright (c) 2013 Robin Appelman <icewind@owncloud.com>
- * This file is licensed under the Affero General Public License version 3 or
- * later.
- * See the COPYING-README file.
- */
-
-namespace Test\Files\Stream;
-
-class StaticStreamTest extends \Test\TestCase {
-
- private $sourceFile;
- private $sourceText;
-
- protected function setUp() {
- parent::setUp();
- $this->sourceFile = \OC::$SERVERROOT . '/tests/data/lorem.txt';
- $this->sourceText = file_get_contents($this->sourceFile);
- }
-
- protected function tearDown() {
- \OC\Files\Stream\StaticStream::clear();
- parent::tearDown();
- }
-
- public function testContent() {
- file_put_contents('static://foo', $this->sourceText);
- $this->assertEquals($this->sourceText, file_get_contents('static://foo'));
- }
-
- public function testMultipleFiles() {
- file_put_contents('static://foo', $this->sourceText);
- file_put_contents('static://bar', strrev($this->sourceText));
- $this->assertEquals($this->sourceText, file_get_contents('static://foo'));
- $this->assertEquals(strrev($this->sourceText), file_get_contents('static://bar'));
- }
-
- public function testOverwrite() {
- file_put_contents('static://foo', $this->sourceText);
- file_put_contents('static://foo', 'qwerty');
- $this->assertEquals('qwerty', file_get_contents('static://foo'));
- }
-
- public function testIsFile() {
- $this->assertFalse(is_file('static://foo'));
- file_put_contents('static://foo', $this->sourceText);
- $this->assertTrue(is_file('static://foo'));
- }
-
- public function testIsDir() {
- $this->assertFalse(is_dir('static://foo'));
- file_put_contents('static://foo', $this->sourceText);
- $this->assertFalse(is_dir('static://foo'));
- }
-
- public function testFileType() {
- file_put_contents('static://foo', $this->sourceText);
- $this->assertEquals('file', filetype('static://foo'));
- }
-
- public function testUnlink() {
- $this->assertFalse(file_exists('static://foo'));
- file_put_contents('static://foo', $this->sourceText);
- $this->assertTrue(file_exists('static://foo'));
- unlink('static://foo');
- clearstatcache();
- $this->assertFalse(file_exists('static://foo'));
- }
-}
diff --git a/tests/lib/Memcache/APCTest.php b/tests/lib/Memcache/APCTest.php
deleted file mode 100644
index 4bd7e62b94a..00000000000
--- a/tests/lib/Memcache/APCTest.php
+++ /dev/null
@@ -1,26 +0,0 @@
-<?php
-
-/**
- * Copyright (c) 2013 Robin Appelman <icewind@owncloud.com>
- * This file is licensed under the Affero General Public License version 3 or
- * later.
- * See the COPYING-README file.
- */
-
-namespace Test\Memcache;
-
-class APCTest extends Cache {
- protected function setUp() {
- parent::setUp();
-
- if(!\OC\Memcache\APC::isAvailable()) {
- $this->markTestSkipped('The apc extension is not available.');
- return;
- }
- if(\OC\Memcache\APCu::isAvailable()) {
- $this->markTestSkipped('The apc extension is emulated by ACPu.');
- return;
- }
- $this->instance=new \OC\Memcache\APC($this->getUniqueID());
- }
-}
diff --git a/tests/lib/Repair/RepairInvalidSharesTest.php b/tests/lib/Repair/RepairInvalidSharesTest.php
index 1ac42e53bf6..83dbed7d202 100644
--- a/tests/lib/Repair/RepairInvalidSharesTest.php
+++ b/tests/lib/Repair/RepairInvalidSharesTest.php
@@ -278,6 +278,73 @@ class RepairInvalidSharesTest extends TestCase {
$result->closeCursor();
}
+ public function fileSharePermissionsProvider() {
+ return [
+ // unchanged for folder
+ [
+ 'folder',
+ 31,
+ 31,
+ ],
+ // unchanged for read-write + share
+ [
+ 'file',
+ \OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_UPDATE | \OCP\Constants::PERMISSION_SHARE,
+ \OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_UPDATE | \OCP\Constants::PERMISSION_SHARE,
+ ],
+ // fixed for all perms
+ [
+ 'file',
+ \OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_CREATE | \OCP\Constants::PERMISSION_UPDATE | \OCP\Constants::PERMISSION_DELETE | \OCP\Constants::PERMISSION_SHARE,
+ \OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_UPDATE | \OCP\Constants::PERMISSION_SHARE,
+ ],
+ ];
+ }
+
+ /**
+ * Test adjusting file share permissions
+ *
+ * @dataProvider fileSharePermissionsProvider
+ */
+ public function testFileSharePermissions($itemType, $testPerms, $expectedPerms) {
+ $qb = $this->connection->getQueryBuilder();
+ $qb->insert('share')
+ ->values([
+ 'share_type' => $qb->expr()->literal(Constants::SHARE_TYPE_LINK),
+ 'uid_owner' => $qb->expr()->literal('user1'),
+ 'item_type' => $qb->expr()->literal($itemType),
+ 'item_source' => $qb->expr()->literal(123),
+ 'item_target' => $qb->expr()->literal('/123'),
+ 'file_source' => $qb->expr()->literal(123),
+ 'file_target' => $qb->expr()->literal('/test'),
+ 'permissions' => $qb->expr()->literal($testPerms),
+ 'stime' => $qb->expr()->literal(time()),
+ ])
+ ->execute();
+
+ $shareId = $this->getLastShareId();
+
+ /** @var IOutput | \PHPUnit_Framework_MockObject_MockObject $outputMock */
+ $outputMock = $this->getMockBuilder('\OCP\Migration\IOutput')
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ $this->repair->run($outputMock);
+
+ $results = $this->connection->getQueryBuilder()
+ ->select('*')
+ ->from('share')
+ ->orderBy('permissions', 'ASC')
+ ->execute()
+ ->fetchAll();
+
+ $this->assertCount(1, $results);
+
+ $updatedShare = $results[0];
+
+ $this->assertEquals($expectedPerms, $updatedShare['permissions']);
+ }
+
/**
* @return int
*/
diff --git a/tests/lib/User/SessionTest.php b/tests/lib/User/SessionTest.php
index 27cb92d6732..51560d78a6a 100644
--- a/tests/lib/User/SessionTest.php
+++ b/tests/lib/User/SessionTest.php
@@ -528,7 +528,7 @@ class SessionTest extends \Test\TestCase {
->getMock();
$userSession = $this->getMockBuilder(Session::class)
//override, otherwise tests will fail because of setcookie()
- ->setMethods(['setMagicInCookie'])
+ ->setMethods(['setMagicInCookie', 'setLoginName'])
->setConstructorArgs([$manager, $session, $this->timeFactory, $this->tokenProvider, $this->config, $this->random])
->getMock();
@@ -566,6 +566,15 @@ class SessionTest extends \Test\TestCase {
->with($oldSessionId, $sessionId)
->will($this->returnValue(true));
+ $tokenObject = $this->createMock(IToken::class);
+ $tokenObject->expects($this->once())
+ ->method('getLoginName')
+ ->willReturn('foobar');
+ $this->tokenProvider->expects($this->once())
+ ->method('getToken')
+ ->with($sessionId)
+ ->willReturn($tokenObject);
+
$user->expects($this->any())
->method('getUID')
->will($this->returnValue('foo'));
@@ -576,6 +585,9 @@ class SessionTest extends \Test\TestCase {
$session->expects($this->once())
->method('set')
->with('user_id', 'foo');
+ $userSession->expects($this->once())
+ ->method('setLoginName')
+ ->willReturn('foobar');
$granted = $userSession->loginWithCookie('foo', $token, $oldSessionId);
diff --git a/tests/lib/UserTest.php b/tests/lib/UserTest.php
index 7a033c2921e..2a477522dea 100644
--- a/tests/lib/UserTest.php
+++ b/tests/lib/UserTest.php
@@ -25,7 +25,7 @@ class UserTest extends TestCase {
protected function setUp(){
parent::setUp();
- $this->backend = $this->getMock('\Test\Util\User\Dummy');
+ $this->backend = $this->createMock(\Test\Util\User\Dummy::class);
$manager = \OC::$server->getUserManager();
$manager->registerBackend($this->backend);
}