aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/lib/AppFramework/DependencyInjection/DIContainerTest.php19
-rw-r--r--tests/lib/AppFramework/DependencyInjection/DIIntergrationTests.php136
-rw-r--r--tests/lib/Authentication/TwoFactorAuth/ManagerTest.php2
-rw-r--r--tests/lib/InfoXmlTest.php8
-rw-r--r--tests/lib/Repair/RepairCollationTest.php13
-rw-r--r--tests/lib/Share20/LegacyHooksTest.php138
-rw-r--r--tests/lib/Share20/ManagerTest.php222
-rw-r--r--tests/lib/Template/SCSSCacherTest.php124
-rw-r--r--tests/lib/TestCase.php8
-rw-r--r--tests/phpunit-autotest.xml1
10 files changed, 454 insertions, 217 deletions
diff --git a/tests/lib/AppFramework/DependencyInjection/DIContainerTest.php b/tests/lib/AppFramework/DependencyInjection/DIContainerTest.php
index 2e450d897bd..fd6fe84b879 100644
--- a/tests/lib/AppFramework/DependencyInjection/DIContainerTest.php
+++ b/tests/lib/AppFramework/DependencyInjection/DIContainerTest.php
@@ -27,23 +27,29 @@
namespace Test\AppFramework\DependencyInjection;
+use OC\AppFramework\Core\API;
+use OC\AppFramework\DependencyInjection\DIContainer;
use \OC\AppFramework\Http\Request;
+use OCP\AppFramework\QueryException;
+use OCP\IConfig;
+use OCP\Security\ISecureRandom;
/**
* @group DB
*/
class DIContainerTest extends \Test\TestCase {
+ /** @var DIContainer|\PHPUnit_Framework_MockObject_MockObject */
private $container;
private $api;
protected function setUp(){
parent::setUp();
- $this->container = $this->getMockBuilder('OC\AppFramework\DependencyInjection\DIContainer')
+ $this->container = $this->getMockBuilder(DIContainer::class)
->setMethods(['isAdminUser'])
->setConstructorArgs(['name'])
->getMock();
- $this->api = $this->getMockBuilder('OC\AppFramework\Core\API')
+ $this->api = $this->getMockBuilder(API::class)
->setConstructorArgs(['hi'])
->getMock();
}
@@ -80,10 +86,10 @@ class DIContainerTest extends \Test\TestCase {
public function testMiddlewareDispatcherIncludesSecurityMiddleware(){
$this->container['Request'] = new Request(
['method' => 'GET'],
- $this->getMockBuilder('\OCP\Security\ISecureRandom')
+ $this->getMockBuilder(ISecureRandom::class)
->disableOriginalConstructor()
->getMock(),
- $this->getMockBuilder('\OCP\IConfig')
+ $this->getMockBuilder(IConfig::class)
->disableOriginalConstructor()
->getMock()
);
@@ -93,5 +99,8 @@ class DIContainerTest extends \Test\TestCase {
$this->assertContains($security, $dispatcher->getMiddlewares());
}
-
+ public function testInvalidAppClass() {
+ $this->expectException(QueryException::class);
+ $this->container->query('\OCA\Name\Foo');
+ }
}
diff --git a/tests/lib/AppFramework/DependencyInjection/DIIntergrationTests.php b/tests/lib/AppFramework/DependencyInjection/DIIntergrationTests.php
new file mode 100644
index 00000000000..e77f2021d9e
--- /dev/null
+++ b/tests/lib/AppFramework/DependencyInjection/DIIntergrationTests.php
@@ -0,0 +1,136 @@
+<?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 Test\AppFramework\DependencyInjection;
+
+use OC\AppFramework\DependencyInjection\DIContainer;
+use OC\AppFramework\Utility\SimpleContainer;
+use OC\ServerContainer;
+use Test\TestCase;
+
+interface Interface1 {}
+
+class ClassA1 implements Interface1 {}
+
+class ClassA2 implements Interface1 {}
+
+class ClassB {
+ /** @var Interface1 */
+ public $interface1;
+
+ /**
+ * ClassB constructor.
+ *
+ * @param Interface1 $interface1
+ */
+ public function __construct(Interface1 $interface1) {
+ $this->interface1 = $interface1;
+ }
+}
+
+class DIIntergrationTests extends TestCase {
+
+ /** @var DIContainer */
+ private $container;
+
+ /** @var ServerContainer */
+ private $server;
+
+ public function setUp() {
+ parent::setUp();
+
+ $this->server = new ServerContainer();
+ $this->container = new DIContainer('App1', [], $this->server);
+ }
+
+ public function testInjectFromServer() {
+ $this->server->registerService(Interface1::class, function () {
+ return new ClassA1();
+ });
+
+ $this->server->registerService(ClassB::class, function (SimpleContainer $c) {
+ return new ClassB(
+ $c->query(Interface1::class)
+ );
+ });
+
+ /** @var ClassB $res */
+ $res = $this->container->query(ClassB::class);
+ $this->assertSame(ClassA1::class, get_class($res->interface1));
+ }
+
+ public function testInjectDepFromServer() {
+ $this->server->registerService(Interface1::class, function () {
+ return new ClassA1();
+ });
+
+ $this->container->registerService(ClassB::class, function (SimpleContainer $c) {
+ return new ClassB(
+ $c->query(Interface1::class)
+ );
+ });
+
+ /** @var ClassB $res */
+ $res = $this->container->query(ClassB::class);
+ $this->assertSame(ClassA1::class, get_class($res->interface1));
+ }
+
+ public function testOverwriteDepFromServer() {
+ $this->server->registerService(Interface1::class, function () {
+ return new ClassA1();
+ });
+
+ $this->container->registerService(Interface1::class, function () {
+ return new ClassA2();
+ });
+
+ $this->container->registerService(ClassB::class, function (SimpleContainer $c) {
+ return new ClassB(
+ $c->query(Interface1::class)
+ );
+ });
+
+ /** @var ClassB $res */
+ $res = $this->container->query(ClassB::class);
+ $this->assertSame(ClassA2::class, get_class($res->interface1));
+ }
+
+ public function testIgnoreOverwriteInServerClass() {
+ $this->server->registerService(Interface1::class, function () {
+ return new ClassA1();
+ });
+
+ $this->container->registerService(Interface1::class, function () {
+ return new ClassA2();
+ });
+
+ $this->server->registerService(ClassB::class, function (SimpleContainer $c) {
+ return new ClassB(
+ $c->query(Interface1::class)
+ );
+ });
+
+ /** @var ClassB $res */
+ $res = $this->container->query(ClassB::class);
+ $this->assertSame(ClassA1::class, get_class($res->interface1));
+ }
+}
diff --git a/tests/lib/Authentication/TwoFactorAuth/ManagerTest.php b/tests/lib/Authentication/TwoFactorAuth/ManagerTest.php
index 1ea17f5d307..c031c39b5f2 100644
--- a/tests/lib/Authentication/TwoFactorAuth/ManagerTest.php
+++ b/tests/lib/Authentication/TwoFactorAuth/ManagerTest.php
@@ -68,7 +68,7 @@ class ManagerTest extends TestCase {
parent::setUp();
$this->user = $this->createMock(IUser::class);
- $this->appManager = $this->createMock('\OC\App\AppManager');
+ $this->appManager = $this->createMock(AppManager::class);
$this->session = $this->createMock(ISession::class);
$this->config = $this->createMock(IConfig::class);
$this->activityManager = $this->createMock(IManager::class);
diff --git a/tests/lib/InfoXmlTest.php b/tests/lib/InfoXmlTest.php
index 4e75ca78203..18391a20c03 100644
--- a/tests/lib/InfoXmlTest.php
+++ b/tests/lib/InfoXmlTest.php
@@ -63,6 +63,14 @@ class InfoXmlTest extends TestCase {
$appPath = \OC_App::getAppPath($app);
\OC_App::registerAutoloading($app, $appPath);
+ //Add the appcontainer
+ $applicationClassName = \OCP\AppFramework\App::buildAppNamespace($app) . '\\AppInfo\\Application';
+ if (class_exists($applicationClassName)) {
+ $application = new $applicationClassName();
+ } else {
+ $application = new \OCP\AppFramework\App($app);
+ }
+
if (isset($appInfo['background-jobs'])) {
foreach ($appInfo['background-jobs'] as $job) {
$this->assertTrue(class_exists($job), 'Asserting background job "' . $job . '" exists');
diff --git a/tests/lib/Repair/RepairCollationTest.php b/tests/lib/Repair/RepairCollationTest.php
index 897f772a794..7ff069d37be 100644
--- a/tests/lib/Repair/RepairCollationTest.php
+++ b/tests/lib/Repair/RepairCollationTest.php
@@ -8,10 +8,15 @@
namespace Test\Repair;
+use Doctrine\DBAL\Connection;
+use Doctrine\DBAL\Platforms\MySqlPlatform;
+use OC\Repair\Collation;
+use OCP\IDBConnection;
use OCP\ILogger;
use OCP\Migration\IOutput;
+use Test\TestCase;
-class TestCollationRepair extends \OC\Repair\Collation {
+class TestCollationRepair extends Collation {
/**
* @param \Doctrine\DBAL\Connection $connection
* @return string[]
@@ -28,7 +33,7 @@ class TestCollationRepair extends \OC\Repair\Collation {
*
* @see \OC\Repair\RepairMimeTypes
*/
-class RepairCollationTest extends \Test\TestCase {
+class RepairCollationTest extends TestCase {
/**
* @var TestCollationRepair
@@ -36,7 +41,7 @@ class RepairCollationTest extends \Test\TestCase {
private $repair;
/**
- * @var \Doctrine\DBAL\Connection
+ * @var Connection|IDBConnection
*/
private $connection;
@@ -59,7 +64,7 @@ class RepairCollationTest extends \Test\TestCase {
$this->connection = \OC::$server->getDatabaseConnection();
$this->logger = $this->createMock(ILogger::class);
$this->config = \OC::$server->getConfig();
- if (!$this->connection->getDatabasePlatform() instanceof \Doctrine\DBAL\Platforms\MySqlPlatform) {
+ if (!$this->connection->getDatabasePlatform() instanceof MySqlPlatform) {
$this->markTestSkipped("Test only relevant on MySql");
}
diff --git a/tests/lib/Share20/LegacyHooksTest.php b/tests/lib/Share20/LegacyHooksTest.php
new file mode 100644
index 00000000000..d3a538f1d8d
--- /dev/null
+++ b/tests/lib/Share20/LegacyHooksTest.php
@@ -0,0 +1,138 @@
+<?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 Test\Share20;
+
+use OC\Share20\LegacyHooks;
+use OC\Share20\Manager;
+use OCP\Files\File;
+use Symfony\Component\EventDispatcher\EventDispatcher;
+use Symfony\Component\EventDispatcher\GenericEvent;
+use Test\TestCase;
+
+class LegacyHooksTest extends TestCase {
+
+ /** @var LegacyHooks */
+ private $hooks;
+
+ /** @var EventDispatcher */
+ private $eventDispatcher;
+
+ /** @var Manager */
+ private $manager;
+
+ public function setUp() {
+ parent::setUp();
+
+ $this->eventDispatcher = new EventDispatcher();
+ $this->hooks = new LegacyHooks($this->eventDispatcher);
+ $this->manager = \OC::$server->getShareManager();
+ }
+
+ public function testPreUnshare() {
+ $path = $this->createMock(File::class);
+ $path->method('getId')->willReturn(1);
+
+ $share = $this->manager->newShare();
+ $share->setId(42)
+ ->setProviderId('prov')
+ ->setShareType(\OCP\Share::SHARE_TYPE_USER)
+ ->setSharedWith('awesomeUser')
+ ->setSharedBy('sharedBy')
+ ->setNode($path)
+ ->setTarget('myTarget');
+
+ $hookListner = $this->getMockBuilder('Dummy')->setMethods(['pre'])->getMock();
+ \OCP\Util::connectHook('OCP\Share', 'pre_unshare', $hookListner, 'pre');
+
+ $hookListnerExpectsPre = [
+ 'id' => 42,
+ 'itemType' => 'file',
+ 'itemSource' => 1,
+ 'shareType' => \OCP\Share::SHARE_TYPE_USER,
+ 'shareWith' => 'awesomeUser',
+ 'itemparent' => null,
+ 'uidOwner' => 'sharedBy',
+ 'fileSource' => 1,
+ 'fileTarget' => 'myTarget',
+ ];
+
+ $hookListner
+ ->expects($this->exactly(1))
+ ->method('pre')
+ ->with($hookListnerExpectsPre);
+
+ $event = new GenericEvent($share);
+ $this->eventDispatcher->dispatch('OCP\Share::preUnshare', $event);
+ }
+
+ public function testPostUnshare() {
+ $path = $this->createMock(File::class);
+ $path->method('getId')->willReturn(1);
+
+ $share = $this->manager->newShare();
+ $share->setId(42)
+ ->setProviderId('prov')
+ ->setShareType(\OCP\Share::SHARE_TYPE_USER)
+ ->setSharedWith('awesomeUser')
+ ->setSharedBy('sharedBy')
+ ->setNode($path)
+ ->setTarget('myTarget');
+
+ $hookListner = $this->getMockBuilder('Dummy')->setMethods(['post'])->getMock();
+ \OCP\Util::connectHook('OCP\Share', 'pre_unshare', $hookListner, 'post');
+
+ $hookListnerExpectsPost = [
+ 'id' => 42,
+ 'itemType' => 'file',
+ 'itemSource' => 1,
+ 'shareType' => \OCP\Share::SHARE_TYPE_USER,
+ 'shareWith' => 'awesomeUser',
+ 'itemparent' => null,
+ 'uidOwner' => 'sharedBy',
+ 'fileSource' => 1,
+ 'fileTarget' => 'myTarget',
+ 'deletedShares' => [
+ [
+ 'id' => 42,
+ 'itemType' => 'file',
+ 'itemSource' => 1,
+ 'shareType' => \OCP\Share::SHARE_TYPE_USER,
+ 'shareWith' => 'awesomeUser',
+ 'itemparent' => null,
+ 'uidOwner' => 'sharedBy',
+ 'fileSource' => 1,
+ 'fileTarget' => 'myTarget',
+ ],
+ ],
+ ];
+
+ $hookListner
+ ->expects($this->exactly(1))
+ ->method('post')
+ ->with($hookListnerExpectsPost);
+
+ $event = new GenericEvent($share);
+ $event->setArgument('deletedShares', [$share]);
+ $this->eventDispatcher->dispatch('OCP\Share::postUnshare', $event);
+ }
+}
diff --git a/tests/lib/Share20/ManagerTest.php b/tests/lib/Share20/ManagerTest.php
index 2a7df0df50f..5436b188350 100644
--- a/tests/lib/Share20/ManagerTest.php
+++ b/tests/lib/Share20/ManagerTest.php
@@ -196,56 +196,23 @@ class ManagerTest extends \Test\TestCase {
->method('delete')
->with($share);
- $hookListner = $this->getMockBuilder('Dummy')->setMethods(['pre', 'post'])->getMock();
- \OCP\Util::connectHook('OCP\Share', 'pre_unshare', $hookListner, 'pre');
- \OCP\Util::connectHook('OCP\Share', 'post_unshare', $hookListner, 'post');
-
- $hookListnerExpectsPre = [
- 'id' => 42,
- 'itemType' => 'file',
- 'itemSource' => 1,
- 'shareType' => $shareType,
- 'shareWith' => $sharedWith,
- 'itemparent' => null,
- 'uidOwner' => 'sharedBy',
- 'fileSource' => 1,
- 'fileTarget' => 'myTarget',
- ];
-
- $hookListnerExpectsPost = [
- 'id' => 42,
- 'itemType' => 'file',
- 'itemSource' => 1,
- 'shareType' => $shareType,
- 'shareWith' => $sharedWith,
- 'itemparent' => null,
- 'uidOwner' => 'sharedBy',
- 'fileSource' => 1,
- 'fileTarget' => 'myTarget',
- 'deletedShares' => [
- [
- 'id' => 42,
- 'itemType' => 'file',
- 'itemSource' => 1,
- 'shareType' => $shareType,
- 'shareWith' => $sharedWith,
- 'itemparent' => null,
- 'uidOwner' => 'sharedBy',
- 'fileSource' => 1,
- 'fileTarget' => 'myTarget',
- ],
- ],
- ];
-
-
- $hookListner
- ->expects($this->exactly(1))
- ->method('pre')
- ->with($hookListnerExpectsPre);
- $hookListner
- ->expects($this->exactly(1))
- ->method('post')
- ->with($hookListnerExpectsPost);
+ $this->eventDispatcher->expects($this->at(0))
+ ->method('dispatch')
+ ->with(
+ 'OCP\Share::preUnshare',
+ $this->callBack(function(GenericEvent $e) use ($share) {
+ return $e->getSubject() === $share;
+ })
+ );
+ $this->eventDispatcher->expects($this->at(1))
+ ->method('dispatch')
+ ->with(
+ 'OCP\Share::postUnshare',
+ $this->callBack(function(GenericEvent $e) use ($share) {
+ return $e->getSubject() === $share &&
+ $e->getArgument('deletedShares') === [$share];
+ })
+ );
$manager->deleteShare($share);
}
@@ -275,56 +242,23 @@ class ManagerTest extends \Test\TestCase {
->method('delete')
->with($share);
- $hookListner = $this->getMockBuilder('Dummy')->setMethods(['pre', 'post'])->getMock();
- \OCP\Util::connectHook('OCP\Share', 'pre_unshare', $hookListner, 'pre');
- \OCP\Util::connectHook('OCP\Share', 'post_unshare', $hookListner, 'post');
-
- $hookListnerExpectsPre = [
- 'id' => 42,
- 'itemType' => 'file',
- 'itemSource' => 1,
- 'shareType' => \OCP\Share::SHARE_TYPE_USER,
- 'shareWith' => 'sharedWith',
- 'itemparent' => null,
- 'uidOwner' => 'sharedBy',
- 'fileSource' => 1,
- 'fileTarget' => 'myTarget',
- ];
-
- $hookListnerExpectsPost = [
- 'id' => 42,
- 'itemType' => 'file',
- 'itemSource' => 1,
- 'shareType' => \OCP\Share::SHARE_TYPE_USER,
- 'shareWith' => 'sharedWith',
- 'itemparent' => null,
- 'uidOwner' => 'sharedBy',
- 'fileSource' => 1,
- 'fileTarget' => 'myTarget',
- 'deletedShares' => [
- [
- 'id' => 42,
- 'itemType' => 'file',
- 'itemSource' => 1,
- 'shareType' => \OCP\Share::SHARE_TYPE_USER,
- 'shareWith' => 'sharedWith',
- 'itemparent' => null,
- 'uidOwner' => 'sharedBy',
- 'fileSource' => 1,
- 'fileTarget' => 'myTarget',
- ],
- ],
- ];
-
-
- $hookListner
- ->expects($this->exactly(1))
- ->method('pre')
- ->with($hookListnerExpectsPre);
- $hookListner
- ->expects($this->exactly(1))
- ->method('post')
- ->with($hookListnerExpectsPost);
+ $this->eventDispatcher->expects($this->at(0))
+ ->method('dispatch')
+ ->with(
+ 'OCP\Share::preUnshare',
+ $this->callBack(function(GenericEvent $e) use ($share) {
+ return $e->getSubject() === $share;
+ })
+ );
+ $this->eventDispatcher->expects($this->at(1))
+ ->method('dispatch')
+ ->with(
+ 'OCP\Share::postUnshare',
+ $this->callBack(function(GenericEvent $e) use ($share) {
+ return $e->getSubject() === $share &&
+ $e->getArgument('deletedShares') === [$share];
+ })
+ );
$manager->deleteShare($share);
}
@@ -377,77 +311,23 @@ class ManagerTest extends \Test\TestCase {
->method('delete')
->withConsecutive($share3, $share2, $share1);
- $hookListner = $this->getMockBuilder('Dummy')->setMethods(['pre', 'post'])->getMock();
- \OCP\Util::connectHook('OCP\Share', 'pre_unshare', $hookListner, 'pre');
- \OCP\Util::connectHook('OCP\Share', 'post_unshare', $hookListner, 'post');
-
- $hookListnerExpectsPre = [
- 'id' => 42,
- 'itemType' => 'file',
- 'itemSource' => 1,
- 'shareType' => \OCP\Share::SHARE_TYPE_USER,
- 'shareWith' => 'sharedWith1',
- 'itemparent' => null,
- 'uidOwner' => 'sharedBy1',
- 'fileSource' => 1,
- 'fileTarget' => 'myTarget1',
- ];
-
- $hookListnerExpectsPost = [
- 'id' => 42,
- 'itemType' => 'file',
- 'itemSource' => 1,
- 'shareType' => \OCP\Share::SHARE_TYPE_USER,
- 'shareWith' => 'sharedWith1',
- 'itemparent' => null,
- 'uidOwner' => 'sharedBy1',
- 'fileSource' => 1,
- 'fileTarget' => 'myTarget1',
- 'deletedShares' => [
- [
- 'id' => 44,
- 'itemType' => 'file',
- 'itemSource' => 1,
- 'shareType' => \OCP\Share::SHARE_TYPE_LINK,
- 'shareWith' => '',
- 'itemparent' => 43,
- 'uidOwner' => 'sharedBy3',
- 'fileSource' => 1,
- 'fileTarget' => 'myTarget3',
- ],
- [
- 'id' => 43,
- 'itemType' => 'file',
- 'itemSource' => 1,
- 'shareType' => \OCP\Share::SHARE_TYPE_GROUP,
- 'shareWith' => 'sharedWith2',
- 'itemparent' => 42,
- 'uidOwner' => 'sharedBy2',
- 'fileSource' => 1,
- 'fileTarget' => 'myTarget2',
- ],
- [
- 'id' => 42,
- 'itemType' => 'file',
- 'itemSource' => 1,
- 'shareType' => \OCP\Share::SHARE_TYPE_USER,
- 'shareWith' => 'sharedWith1',
- 'itemparent' => null,
- 'uidOwner' => 'sharedBy1',
- 'fileSource' => 1,
- 'fileTarget' => 'myTarget1',
- ],
- ],
- ];
-
- $hookListner
- ->expects($this->exactly(1))
- ->method('pre')
- ->with($hookListnerExpectsPre);
- $hookListner
- ->expects($this->exactly(1))
- ->method('post')
- ->with($hookListnerExpectsPost);
+ $this->eventDispatcher->expects($this->at(0))
+ ->method('dispatch')
+ ->with(
+ 'OCP\Share::preUnshare',
+ $this->callBack(function(GenericEvent $e) use ($share1) {
+ return $e->getSubject() === $share1;
+ })
+ );
+ $this->eventDispatcher->expects($this->at(1))
+ ->method('dispatch')
+ ->with(
+ 'OCP\Share::postUnshare',
+ $this->callBack(function(GenericEvent $e) use ($share1, $share2, $share3) {
+ return $e->getSubject() === $share1 &&
+ $e->getArgument('deletedShares') === [$share3, $share2, $share1];
+ })
+ );
$manager->deleteShare($share1);
}
diff --git a/tests/lib/Template/SCSSCacherTest.php b/tests/lib/Template/SCSSCacherTest.php
index d49f0cdc6a1..898ea89cf40 100644
--- a/tests/lib/Template/SCSSCacherTest.php
+++ b/tests/lib/Template/SCSSCacherTest.php
@@ -28,6 +28,7 @@ use OCP\Files\IAppData;
use OCP\Files\NotFoundException;
use OCP\Files\SimpleFS\ISimpleFile;
use OCP\Files\SimpleFS\ISimpleFolder;
+use OCP\ICache;
use OCP\IConfig;
use OCP\ILogger;
use OCP\IURLGenerator;
@@ -45,6 +46,8 @@ class SCSSCacherTest extends \Test\TestCase {
protected $defaults;
/** @var SCSSCacher */
protected $scssCacher;
+ /** @var ICache|\PHPUnit_Framework_MockObject_MockObject */
+ protected $depsCache;
protected function setUp() {
parent::setUp();
@@ -52,12 +55,14 @@ class SCSSCacherTest extends \Test\TestCase {
$this->appData = $this->createMock(IAppData::class);
$this->urlGenerator = $this->createMock(IURLGenerator::class);
$this->config = $this->createMock(IConfig::class);
+ $this->depsCache = $this->createMock(ICache::class);
$this->scssCacher = new SCSSCacher(
$this->logger,
$this->appData,
$this->urlGenerator,
$this->config,
- \OC::$SERVERROOT
+ \OC::$SERVERROOT,
+ $this->depsCache
);
}
@@ -68,11 +73,22 @@ class SCSSCacherTest extends \Test\TestCase {
$file = $this->createMock(ISimpleFile::class);
$file->expects($this->any())->method('getSize')->willReturn(1);
$fileDeps = $this->createMock(ISimpleFile::class);
- $folder->expects($this->at(0))->method('getFile')->with('styles.css')->willReturn($file);
- $folder->expects($this->at(1))->method('getFile')->with('styles.css.deps')->willThrowException(new NotFoundException());
- $folder->expects($this->at(2))->method('getFile')->with('styles.css')->willReturn($file);
- $folder->expects($this->at(3))->method('getFile')->with('styles.css.deps')->willThrowException(new NotFoundException());
- $folder->expects($this->at(4))->method('newFile')->with('styles.css.deps')->willReturn($fileDeps);
+
+ $folder->method('getFile')
+ ->will($this->returnCallback(function($path) use ($file) {
+ if ($path === 'styles.css') {
+ return $file;
+ } else if ($path === 'styles.css.deps') {
+ throw new NotFoundException();
+ } else {
+ $this->fail();
+ }
+ }));
+ $folder->expects($this->once())
+ ->method('newFile')
+ ->with('styles.css.deps')
+ ->willReturn($fileDeps);
+
$actual = $this->scssCacher->process(\OC::$SERVERROOT, '/core/css/styles.scss', 'core');
$this->assertTrue($actual);
}
@@ -83,66 +99,110 @@ class SCSSCacherTest extends \Test\TestCase {
$file = $this->createMock(ISimpleFile::class);
$file->expects($this->any())->method('getSize')->willReturn(1);
$fileDeps = $this->createMock(ISimpleFile::class);
- $folder->expects($this->at(0))->method('getFile')->with('styles.css')->willReturn($file);
- $folder->expects($this->at(1))->method('getFile')->with('styles.css.deps')->willThrowException(new NotFoundException());
- $folder->expects($this->at(2))->method('getFile')->with('styles.css')->willReturn($file);
- $folder->expects($this->at(3))->method('getFile')->with('styles.css.deps')->willThrowException(new NotFoundException());
- $folder->expects($this->at(4))->method('newFile')->with('styles.css.deps')->willReturn($fileDeps);
+
+ $folder->method('getFile')
+ ->will($this->returnCallback(function($path) use ($file) {
+ if ($path === 'styles.css') {
+ return $file;
+ } else if ($path === 'styles.css.deps') {
+ throw new NotFoundException();
+ } else {
+ $this->fail();
+ }
+ }));
+ $folder->expects($this->once())
+ ->method('newFile')
+ ->with('styles.css.deps')
+ ->willReturn($fileDeps);
+
$actual = $this->scssCacher->process(\OC::$SERVERROOT, '/core/css/styles.scss', 'core');
$this->assertTrue($actual);
}
- public function testProcessCacheFile() {
+ public function testProcessCachedFile() {
$folder = $this->createMock(ISimpleFolder::class);
$this->appData->expects($this->once())->method('getFolder')->with('core')->willReturn($folder);
$file = $this->createMock(ISimpleFile::class);
- $file->expects($this->any())->method('getSize')->willReturn(1);
+ $file->expects($this->once())->method('getSize')->willReturn(1);
$fileDeps = $this->createMock(ISimpleFile::class);
$fileDeps->expects($this->any())->method('getSize')->willReturn(1);
$fileDeps->expects($this->once())->method('getContent')->willReturn('{}');
- $folder->expects($this->at(0))->method('getFile')->with('styles.css')->willReturn($file);
- $folder->expects($this->at(1))->method('getFile')->with('styles.css.deps')->willReturn($fileDeps);
+
+ $folder->method('getFile')
+ ->will($this->returnCallback(function($path) use ($file, $fileDeps) {
+ if ($path === 'styles.css') {
+ return $file;
+ } else if ($path === 'styles.css.deps') {
+ return $fileDeps;
+ } else {
+ $this->fail();
+ }
+ }));
+
$actual = $this->scssCacher->process(\OC::$SERVERROOT, '/core/css/styles.scss', 'core');
$this->assertTrue($actual);
}
- public function testProcessCachedFile() {
+ public function testProcessCachedFileMemcache() {
$folder = $this->createMock(ISimpleFolder::class);
- $this->appData->expects($this->once())->method('getFolder')->with('core')->willReturn($folder);
+ $this->appData->expects($this->once())
+ ->method('getFolder')
+ ->with('core')
+ ->willReturn($folder);
+ $folder->method('getName')
+ ->willReturn('core');
+
$file = $this->createMock(ISimpleFile::class);
- $file->expects($this->once())->method('getSize')->willReturn(1);
- $fileDeps = $this->createMock(ISimpleFile::class);
- $fileDeps->expects($this->any())->method('getSize')->willReturn(1);
- $fileDeps->expects($this->once())->method('getContent')->willReturn('{}');
- $folder->expects($this->at(0))->method('getFile')->with('styles.css')->willReturn($file);
- $folder->expects($this->at(1))->method('getFile')->with('styles.css.deps')->willReturn($fileDeps);
+ $file->expects($this->once())
+ ->method('getSize')
+ ->willReturn(1);
+
+ $this->depsCache->method('get')
+ ->with('core-styles.css.deps')
+ ->willReturn('{}');
+
+ $folder->method('getFile')
+ ->will($this->returnCallback(function($path) use ($file) {
+ if ($path === 'styles.css') {
+ return $file;
+ } else if ($path === 'styles.css.deps') {
+ $this->fail();
+ } else {
+ $this->fail();
+ }
+ }));
+
$actual = $this->scssCacher->process(\OC::$SERVERROOT, '/core/css/styles.scss', 'core');
$this->assertTrue($actual);
}
public function testIsCachedNoFile() {
$fileNameCSS = "styles.css";
- $fileNameSCSS = "styles.scss";
$folder = $this->createMock(ISimpleFolder::class);
- $path = \OC::$SERVERROOT . '/core/css/';
$folder->expects($this->at(0))->method('getFile')->with($fileNameCSS)->willThrowException(new NotFoundException());
- $actual = self::invokePrivate($this->scssCacher, 'isCached', [$fileNameCSS, $fileNameSCSS, $folder, $path]);
+ $actual = self::invokePrivate($this->scssCacher, 'isCached', [$fileNameCSS, $folder]);
$this->assertFalse($actual);
}
public function testIsCachedNoDepsFile() {
$fileNameCSS = "styles.css";
- $fileNameSCSS = "styles.scss";
$folder = $this->createMock(ISimpleFolder::class);
$file = $this->createMock(ISimpleFile::class);
- $path = \OC::$SERVERROOT . '/core/css/';
$file->expects($this->once())->method('getSize')->willReturn(1);
- $folder->expects($this->at(0))->method('getFile')->with($fileNameCSS)->willReturn($file);
- $folder->expects($this->at(1))->method('getFile')->with($fileNameCSS . '.deps')->willThrowException(new NotFoundException());
+ $folder->method('getFile')
+ ->will($this->returnCallback(function($path) use ($file) {
+ if ($path === 'styles.css') {
+ return $file;
+ } else if ($path === 'styles.css.deps') {
+ throw new NotFoundException();
+ } else {
+ $this->fail();
+ }
+ }));
- $actual = self::invokePrivate($this->scssCacher, 'isCached', [$fileNameCSS, $fileNameSCSS, $folder, $path]);
+ $actual = self::invokePrivate($this->scssCacher, 'isCached', [$fileNameCSS, $folder]);
$this->assertFalse($actual);
}
public function testCacheNoFile() {
@@ -275,4 +335,4 @@ class SCSSCacherTest extends \Test\TestCase {
}
-} \ No newline at end of file
+}
diff --git a/tests/lib/TestCase.php b/tests/lib/TestCase.php
index 021682ae8e4..23a66f73ec7 100644
--- a/tests/lib/TestCase.php
+++ b/tests/lib/TestCase.php
@@ -139,7 +139,7 @@ abstract class TestCase extends \PHPUnit_Framework_TestCase {
if (is_null(self::$realDatabase)) {
self::$realDatabase = \OC::$server->getDatabaseConnection();
}
- \OC::$server->registerService('DatabaseConnection', function () {
+ \OC::$server->registerService(IDBConnection::class, function () {
$this->fail('Your test case is not allowed to access the database.');
});
}
@@ -158,7 +158,7 @@ abstract class TestCase extends \PHPUnit_Framework_TestCase {
// restore database connection
if (!$this->IsDatabaseAccessAllowed()) {
- \OC::$server->registerService('DatabaseConnection', function () {
+ \OC::$server->registerService(IDBConnection::class, function () {
return self::$realDatabase;
});
}
@@ -171,7 +171,7 @@ abstract class TestCase extends \PHPUnit_Framework_TestCase {
// restore database connection
if (!$this->IsDatabaseAccessAllowed()) {
- \OC::$server->registerService('DatabaseConnection', function () {
+ \OC::$server->registerService(IDBConnection::class, function () {
return self::$realDatabase;
});
}
@@ -259,7 +259,7 @@ abstract class TestCase extends \PHPUnit_Framework_TestCase {
if (!self::$wasDatabaseAllowed && self::$realDatabase !== null) {
// in case an error is thrown in a test, PHPUnit jumps straight to tearDownAfterClass,
// so we need the database again
- \OC::$server->registerService('DatabaseConnection', function () {
+ \OC::$server->registerService(IDBConnection::class, function () {
return self::$realDatabase;
});
}
diff --git a/tests/phpunit-autotest.xml b/tests/phpunit-autotest.xml
index ba16bbdbaac..9a9c9c957e3 100644
--- a/tests/phpunit-autotest.xml
+++ b/tests/phpunit-autotest.xml
@@ -2,6 +2,7 @@
<phpunit bootstrap="bootstrap.php"
strict="true"
verbose="true"
+ backupGlobals="false"
timeoutForSmallTests="900"
timeoutForMediumTests="900"
timeoutForLargeTests="900"