aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/lib/App/DependencyAnalyzerTest.php15
-rw-r--r--tests/lib/AppConfigTest.php15
-rw-r--r--tests/lib/AppTest.php22
-rw-r--r--tests/lib/Comments/ManagerTest.php8
-rw-r--r--tests/lib/Encryption/DecryptAllTest.php2
-rw-r--r--tests/lib/Encryption/EncryptionWrapperTest.php8
-rw-r--r--tests/lib/Share/ShareTest.php20
-rw-r--r--tests/lib/Share20/DefaultShareProviderTest.php2
-rw-r--r--tests/lib/StreamWrappersTest.php36
-rw-r--r--tests/lib/TestCase.php29
-rw-r--r--tests/lib/UtilTest.php11
11 files changed, 64 insertions, 104 deletions
diff --git a/tests/lib/App/DependencyAnalyzerTest.php b/tests/lib/App/DependencyAnalyzerTest.php
index 684a1b52259..091479798b3 100644
--- a/tests/lib/App/DependencyAnalyzerTest.php
+++ b/tests/lib/App/DependencyAnalyzerTest.php
@@ -256,17 +256,18 @@ class DependencyAnalyzerTest extends TestCase {
* @return array
*/
function providesCommands() {
- return array(
- array(array(), null),
+ return [
+ [[], null],
// grep is known on linux
- array(array(), array(array('@attributes' => array('os' => 'Linux'), '@value' => 'grep'))),
+ [[], [['@attributes' => ['os' => 'Linux'], '@value' => 'grep']]],
// grepp is not known on linux
- array(array('The command line tool grepp could not be found'), array(array('@attributes' => array('os' => 'Linux'), '@value' => 'grepp'))),
+ [['The command line tool grepp could not be found'], [['@attributes' => ['os' => 'Linux'], '@value' => 'grepp']]],
// we don't care about tools on Windows - we are on Linux
- array(array(), array(array('@attributes' => array('os' => 'Windows'), '@value' => 'grepp'))),
+ [[], [['@attributes' => ['os' => 'Windows'], '@value' => 'grepp']]],
// grep is known on all systems
- array(array(), 'grep'),
- );
+ [[], 'grep'],
+ [[], ['@attributes' => ['os' => 'Linux'], '@value' => 'grep']],
+ ];
}
/**
diff --git a/tests/lib/AppConfigTest.php b/tests/lib/AppConfigTest.php
index 520dbf66d36..c4da7507752 100644
--- a/tests/lib/AppConfigTest.php
+++ b/tests/lib/AppConfigTest.php
@@ -40,7 +40,7 @@ class AppConfigTest extends TestCase {
$sql->delete('appconfig');
$sql->execute();
- $this->registerAppConfig(new \OC\AppConfig($this->connection));
+ $this->overwriteService('AppConfig', new \OC\AppConfig($this->connection));
$sql = $this->connection->getQueryBuilder();
$sql->insert('appconfig')
@@ -130,21 +130,10 @@ class AppConfigTest extends TestCase {
$sql->execute();
}
- $this->registerAppConfig(new \OC\AppConfig(\OC::$server->getDatabaseConnection()));
+ $this->restoreService('AppConfig');
parent::tearDown();
}
- /**
- * Register an app config object for testing purposes.
- *
- * @param \OCP\IAppConfig $appConfig
- */
- protected function registerAppConfig($appConfig) {
- \OC::$server->registerService('AppConfig', function () use ($appConfig) {
- return $appConfig;
- });
- }
-
public function testGetApps() {
$config = new \OC\AppConfig(\OC::$server->getDatabaseConnection());
diff --git a/tests/lib/AppTest.php b/tests/lib/AppTest.php
index ac4fb913beb..ea4f328b63a 100644
--- a/tests/lib/AppTest.php
+++ b/tests/lib/AppTest.php
@@ -493,24 +493,22 @@ class AppTest extends \Test\TestCase {
* @param IAppConfig $appConfig app config mock
*/
private function registerAppConfig(IAppConfig $appConfig) {
- \OC::$server->registerService('AppConfig', function ($c) use ($appConfig) {
- return $appConfig;
- });
- \OC::$server->registerService('AppManager', function (\OC\Server $c) use ($appConfig) {
- return new \OC\App\AppManager($c->getUserSession(), $appConfig, $c->getGroupManager(), $c->getMemCacheFactory(), $c->getEventDispatcher());
- });
+ $this->overwriteService('AppConfig', $appConfig);
+ $this->overwriteService('AppManager', new \OC\App\AppManager(
+ \OC::$server->getUserSession(),
+ $appConfig,
+ \OC::$server->getGroupManager(),
+ \OC::$server->getMemCacheFactory(),
+ \OC::$server->getEventDispatcher()
+ ));
}
/**
* Restore the original app config service.
*/
private function restoreAppConfig() {
- \OC::$server->registerService('AppConfig', function (\OC\Server $c) {
- return new \OC\AppConfig($c->getDatabaseConnection());
- });
- \OC::$server->registerService('AppManager', function (\OC\Server $c) {
- return new \OC\App\AppManager($c->getUserSession(), $c->getAppConfig(), $c->getGroupManager(), $c->getMemCacheFactory(), $c->getEventDispatcher());
- });
+ $this->restoreService('AppConfig');
+ $this->restoreService('AppManager');
// Remove the cache of the mocked apps list with a forceRefresh
\OC_App::getEnabledApps();
diff --git a/tests/lib/Comments/ManagerTest.php b/tests/lib/Comments/ManagerTest.php
index 71c918af6c7..5bacc794ba7 100644
--- a/tests/lib/Comments/ManagerTest.php
+++ b/tests/lib/Comments/ManagerTest.php
@@ -111,7 +111,7 @@ class ManagerTest extends TestCase {
$this->assertSame($comment->getVerb(), 'comment');
$this->assertSame($comment->getObjectType(), 'files');
$this->assertSame($comment->getObjectId(), 'file64');
- $this->assertEquals($comment->getCreationDateTime(), $creationDT);
+ $this->assertEquals($comment->getCreationDateTime()->getTimestamp(), $creationDT->getTimestamp());
$this->assertEquals($comment->getLatestChildDateTime(), $latestChildDT);
}
@@ -373,7 +373,7 @@ class ManagerTest extends TestCase {
$loadedComment = $manager->get($comment->getId());
$this->assertSame($comment->getMessage(), $loadedComment->getMessage());
- $this->assertEquals($comment->getCreationDateTime(), $loadedComment->getCreationDateTime());
+ $this->assertEquals($comment->getCreationDateTime()->getTimestamp(), $loadedComment->getCreationDateTime()->getTimestamp());
}
public function testSaveUpdate() {
@@ -444,7 +444,7 @@ class ManagerTest extends TestCase {
$this->assertSame($comment->getTopmostParentId(), strval($id));
$parentComment = $manager->get(strval($id));
$this->assertSame($parentComment->getChildrenCount(), $i + 1);
- $this->assertEquals($parentComment->getLatestChildDateTime(), $comment->getCreationDateTime());
+ $this->assertEquals($parentComment->getLatestChildDateTime()->getTimestamp(), $comment->getCreationDateTime()->getTimestamp());
}
}
@@ -577,7 +577,7 @@ class ManagerTest extends TestCase {
$dateTimeGet = $manager->getReadMark('robot', '36', $user);
- $this->assertEquals($dateTimeGet, $dateTimeSet);
+ $this->assertEquals($dateTimeGet->getTimestamp(), $dateTimeSet->getTimestamp());
}
public function testSetMarkReadUpdate() {
diff --git a/tests/lib/Encryption/DecryptAllTest.php b/tests/lib/Encryption/DecryptAllTest.php
index 7859a65ff6d..289e7de27ab 100644
--- a/tests/lib/Encryption/DecryptAllTest.php
+++ b/tests/lib/Encryption/DecryptAllTest.php
@@ -260,7 +260,7 @@ class DecryptAllTest extends TestCase {
->disableOriginalConstructor()->getMock();
$sharedStorage->expects($this->once())->method('instanceOfStorage')
- ->with('OC\Files\Storage\Shared')->willReturn(true);
+ ->with('OCA\Files_Sharing\SharedStorage')->willReturn(true);
$this->view->expects($this->at(0))->method('getDirectoryContent')
->with('/user1/files')->willReturn(
diff --git a/tests/lib/Encryption/EncryptionWrapperTest.php b/tests/lib/Encryption/EncryptionWrapperTest.php
index 6599428b364..6a6a3db2f68 100644
--- a/tests/lib/Encryption/EncryptionWrapperTest.php
+++ b/tests/lib/Encryption/EncryptionWrapperTest.php
@@ -91,13 +91,13 @@ class EncryptionWrapperTest extends TestCase {
[true, ['OCA\Files_Trashbin\Storage']],
// Do not wrap shared storages
- [false, ['OC\Files\Storage\Shared']],
+ [false, ['OCA\Files_Sharing\SharedStorage']],
[false, ['OCA\Files_Sharing\External\Storage']],
[false, ['OC\Files\Storage\OwnCloud']],
- [false, ['OC\Files\Storage\Shared', 'OCA\Files_Sharing\External\Storage']],
- [false, ['OC\Files\Storage\Shared', 'OC\Files\Storage\OwnCloud']],
+ [false, ['OCA\Files_Sharing\SharedStorage', 'OCA\Files_Sharing\External\Storage']],
+ [false, ['OCA\Files_Sharing\SharedStorage', 'OC\Files\Storage\OwnCloud']],
[false, ['OCA\Files_Sharing\External\Storage', 'OC\Files\Storage\OwnCloud']],
- [false, ['OC\Files\Storage\Shared', 'OCA\Files_Sharing\External\Storage', 'OC\Files\Storage\OwnCloud']],
+ [false, ['OCA\Files_Sharing\SharedStorage', 'OCA\Files_Sharing\External\Storage', 'OC\Files\Storage\OwnCloud']],
];
}
diff --git a/tests/lib/Share/ShareTest.php b/tests/lib/Share/ShareTest.php
index 42adee21d0c..63289529843 100644
--- a/tests/lib/Share/ShareTest.php
+++ b/tests/lib/Share/ShareTest.php
@@ -119,12 +119,6 @@ class ShareTest extends \Test\TestCase {
parent::tearDown();
}
- protected function setHttpHelper($httpHelper) {
- \OC::$server->registerService('HTTPHelper', function () use ($httpHelper) {
- return $httpHelper;
- });
- }
-
public function testShareInvalidShareType() {
$message = 'Share type foobar is not valid for test.txt';
try {
@@ -1046,11 +1040,10 @@ class ShareTest extends \Test\TestCase {
* @param string $urlHost
*/
public function testRemoteShareUrlCalls($shareWith, $urlHost) {
- $oldHttpHelper = \OC::$server->query('HTTPHelper');
- $httpHelperMock = $this->getMockBuilder('OC\HttpHelper')
+ $httpHelperMock = $this->getMockBuilder('OC\HTTPHelper')
->disableOriginalConstructor()
->getMock();
- $this->setHttpHelper($httpHelperMock);
+ $this->overwriteService('HTTPHelper', $httpHelperMock);
$httpHelperMock->expects($this->at(0))
->method('post')
@@ -1075,7 +1068,7 @@ class ShareTest extends \Test\TestCase {
->willReturn(['success' => true, 'result' => json_encode(['ocs' => ['meta' => ['statuscode' => 100]]])]);
\OCP\Share::unshare('test', 'test.txt', \OCP\Share::SHARE_TYPE_REMOTE, $shareWith);
- $this->setHttpHelper($oldHttpHelper);
+ $this->restoreService('HTTPHelper');
}
/**
@@ -1473,11 +1466,10 @@ class ShareTest extends \Test\TestCase {
* Make sure that a user cannot have multiple identical shares to remote users
*/
public function testOnlyOneRemoteShare() {
- $oldHttpHelper = \OC::$server->query('HTTPHelper');
- $httpHelperMock = $this->getMockBuilder('OC\HttpHelper')
+ $httpHelperMock = $this->getMockBuilder('OC\HTTPHelper')
->disableOriginalConstructor()
->getMock();
- $this->setHttpHelper($httpHelperMock);
+ $this->overwriteService('HTTPHelper', $httpHelperMock);
$httpHelperMock->expects($this->at(0))
->method('post')
@@ -1502,7 +1494,7 @@ class ShareTest extends \Test\TestCase {
->willReturn(['success' => true, 'result' => json_encode(['ocs' => ['meta' => ['statuscode' => 100]]])]);
\OCP\Share::unshare('test', 'test.txt', \OCP\Share::SHARE_TYPE_REMOTE, 'foo@localhost');
- $this->setHttpHelper($oldHttpHelper);
+ $this->restoreService('HTTPHelper');
}
/**
diff --git a/tests/lib/Share20/DefaultShareProviderTest.php b/tests/lib/Share20/DefaultShareProviderTest.php
index 0ae2ef922fc..778c1cb5722 100644
--- a/tests/lib/Share20/DefaultShareProviderTest.php
+++ b/tests/lib/Share20/DefaultShareProviderTest.php
@@ -743,7 +743,7 @@ class DefaultShareProviderTest extends \Test\TestCase {
$this->assertSame($path, $share2->getNode());
$this->assertSame('password', $share2->getPassword());
$this->assertSame('token', $share2->getToken());
- $this->assertEquals($expireDate, $share2->getExpirationDate());
+ $this->assertEquals($expireDate->getTimestamp(), $share2->getExpirationDate()->getTimestamp());
}
public function testGetShareByToken() {
diff --git a/tests/lib/StreamWrappersTest.php b/tests/lib/StreamWrappersTest.php
index a378f975fde..c0ecb5e738b 100644
--- a/tests/lib/StreamWrappersTest.php
+++ b/tests/lib/StreamWrappersTest.php
@@ -77,40 +77,4 @@ class StreamWrappersTest extends \Test\TestCase {
fclose($fh);
$this->assertSame($tmpFile, $actual);
}
-
- public function testOC() {
- // FIXME: use proper tearDown with $this->loginAsUser() and $this->logout()
- // (would currently break the tests for some reason)
- $originalStorage = \OC\Files\Filesystem::getStorage('/');
- \OC\Files\Filesystem::clearMounts();
-
- $storage = new \OC\Files\Storage\Temporary(array());
- $storage->file_put_contents('foo.txt', 'asd');
- \OC\Files\Filesystem::mount($storage, array(), '/');
-
- $this->assertTrue(file_exists('oc:///foo.txt'));
- $this->assertEquals('asd', file_get_contents('oc:///foo.txt'));
- $this->assertEquals(array('.', '..', 'foo.txt'), scandir('oc:///'));
-
- file_put_contents('oc:///bar.txt', 'qwerty');
- $this->assertEquals('qwerty', $storage->file_get_contents('bar.txt'));
- $this->assertEquals(array('.', '..', 'bar.txt', 'foo.txt'), scandir('oc:///'));
- $this->assertEquals('qwerty', file_get_contents('oc:///bar.txt'));
-
- $fh = fopen('oc:///bar.txt', 'rb');
- $this->assertSame(0, ftell($fh));
- $content = fread($fh, 4);
- $this->assertSame(4, ftell($fh));
- $this->assertSame('qwer', $content);
- $content = fread($fh, 1);
- $this->assertSame(5, ftell($fh));
- $this->assertSame(0, fseek($fh, 0));
- $this->assertSame(0, ftell($fh));
-
- unlink('oc:///foo.txt');
- $this->assertEquals(array('.', '..', 'bar.txt'), scandir('oc:///'));
-
- \OC\Files\Filesystem::clearMounts();
- \OC\Files\Filesystem::mount($originalStorage, array(), '/');
- }
}
diff --git a/tests/lib/TestCase.php b/tests/lib/TestCase.php
index 7ccff382357..61372d4ae90 100644
--- a/tests/lib/TestCase.php
+++ b/tests/lib/TestCase.php
@@ -102,6 +102,16 @@ abstract class TestCase extends \PHPUnit_Framework_TestCase {
return false;
}
+ public function restoreAllServices() {
+ if (!empty($this->services)) {
+ if (!empty($this->services)) {
+ foreach ($this->services as $name => $service) {
+ $this->restoreService($name);
+ }
+ }
+ }
+ }
+
protected function getTestTraits() {
$traits = [];
$class = $this;
@@ -132,9 +142,7 @@ abstract class TestCase extends \PHPUnit_Framework_TestCase {
// overwrite the command bus with one we can run ourselves
$this->commandBus = new QueueBus();
- \OC::$server->registerService('AsyncCommandBus', function () {
- return $this->commandBus;
- });
+ $this->overwriteService('AsyncCommandBus', $this->commandBus);
$traits = $this->getTestTraits();
foreach ($traits as $trait) {
@@ -145,7 +153,22 @@ abstract class TestCase extends \PHPUnit_Framework_TestCase {
}
}
+ protected function onNotSuccessfulTest($e) {
+ $this->restoreAllServices();
+
+ // restore database connection
+ if (!$this->IsDatabaseAccessAllowed()) {
+ \OC::$server->registerService('DatabaseConnection', function () {
+ return self::$realDatabase;
+ });
+ }
+
+ parent::onNotSuccessfulTest($e);
+ }
+
protected function tearDown() {
+ $this->restoreAllServices();
+
// restore database connection
if (!$this->IsDatabaseAccessAllowed()) {
\OC::$server->registerService('DatabaseConnection', function () {
diff --git a/tests/lib/UtilTest.php b/tests/lib/UtilTest.php
index 619963a2abf..a1671191ab8 100644
--- a/tests/lib/UtilTest.php
+++ b/tests/lib/UtilTest.php
@@ -87,24 +87,17 @@ class UtilTest extends \Test\TestCase {
function testFormatDateWithTZFromSession($offset, $expected, $expectedTimeZone) {
date_default_timezone_set("UTC");
- $oldDateTimeFormatter = \OC::$server->query('DateTimeFormatter');
\OC::$server->getSession()->set('timezone', $offset);
$selectedTimeZone = \OC::$server->getDateTimeZone()->getTimeZone(1350129205);
$this->assertEquals($expectedTimeZone, $selectedTimeZone->getName());
$newDateTimeFormatter = new \OC\DateTimeFormatter($selectedTimeZone, new \OC_L10N('lib', 'en'));
- $this->setDateFormatter($newDateTimeFormatter);
+ $this->overwriteService('DateTimeFormatter', $newDateTimeFormatter);
$result = OC_Util::formatDate(1350129205, false);
$this->assertEquals($expected, $result);
- $this->setDateFormatter($oldDateTimeFormatter);
- }
-
- protected function setDateFormatter($formatter) {
- \OC::$server->registerService('DateTimeFormatter', function ($c) use ($formatter) {
- return $formatter;
- });
+ $this->restoreService('DateTimeFormatter');
}
function testSanitizeHTML() {