summaryrefslogtreecommitdiffstats
path: root/tests/lib
diff options
context:
space:
mode:
authorThomas Müller <thomas.mueller@tmit.eu>2013-09-30 10:46:50 +0200
committerThomas Müller <thomas.mueller@tmit.eu>2013-09-30 10:46:50 +0200
commite3dee633393514402bc828e90b493d5168fdf837 (patch)
tree576e0d81276f8b498b511909ca5ad76e0b208223 /tests/lib
parent1ec7dff2fe1922a4690dc2537c0c64369ca86ea1 (diff)
parent5899485ca17045e93528c29d1ed63b02192c4191 (diff)
downloadnextcloud-server-e3dee633393514402bc828e90b493d5168fdf837.tar.gz
nextcloud-server-e3dee633393514402bc828e90b493d5168fdf837.zip
Merge branch 'master' into fixing-4011-master
Conflicts: lib/connector/sabre/directory.php lib/connector/sabre/file.php
Diffstat (limited to 'tests/lib')
-rw-r--r--tests/lib/connector/sabre/objecttree.php87
-rw-r--r--tests/lib/preview.php43
-rw-r--r--tests/lib/user.php43
-rw-r--r--tests/lib/user/manager.php45
-rw-r--r--tests/lib/user/session.php32
-rw-r--r--tests/lib/user/user.php40
6 files changed, 227 insertions, 63 deletions
diff --git a/tests/lib/connector/sabre/objecttree.php b/tests/lib/connector/sabre/objecttree.php
new file mode 100644
index 00000000000..1d76bb59676
--- /dev/null
+++ b/tests/lib/connector/sabre/objecttree.php
@@ -0,0 +1,87 @@
+<?php
+/**
+ * Copyright (c) 2013 Thomas Müller <thomas.mueller@tmit.eu>
+ * This file is licensed under the Affero General Public License version 3 or
+ * later.
+ * See the COPYING-README file.
+ */
+
+namespace Test\OC\Connector\Sabre;
+
+
+use OC_Connector_Sabre_Directory;
+use PHPUnit_Framework_TestCase;
+use Sabre_DAV_Exception_Forbidden;
+
+class TestDoubleFileView extends \OC\Files\View{
+
+ public function __construct($updatables, $canRename = true) {
+ $this->updatables = $updatables;
+ $this->canRename = $canRename;
+ }
+
+ public function isUpdatable($path) {
+ return $this->updatables[$path];
+ }
+
+ public function rename($path1, $path2) {
+ return $this->canRename;
+ }
+}
+
+class ObjectTree extends PHPUnit_Framework_TestCase {
+
+ /**
+ * @dataProvider moveFailedProvider
+ * @expectedException Sabre_DAV_Exception_Forbidden
+ */
+ public function testMoveFailed($source, $dest, $updatables) {
+ $this->moveTest($source, $dest, $updatables);
+ }
+
+ /**
+ * @dataProvider moveSuccessProvider
+ */
+ public function testMoveSuccess($source, $dest, $updatables) {
+ $this->moveTest($source, $dest, $updatables);
+ $this->assertTrue(true);
+ }
+
+ function moveFailedProvider() {
+ return array(
+ array('a/b', 'a/c', array('a' => false, 'a/b' => false, 'a/c' => false)),
+ array('a/b', 'b/b', array('a' => false, 'a/b' => false, 'b' => false, 'b/b' => false)),
+ array('a/b', 'b/b', array('a' => false, 'a/b' => true, 'b' => false, 'b/b' => false)),
+ array('a/b', 'b/b', array('a' => true, 'a/b' => true, 'b' => false, 'b/b' => false)),
+ );
+ }
+
+ function moveSuccessProvider() {
+ return array(
+ array('a/b', 'a/c', array('a' => false, 'a/b' => true, 'a/c' => false)),
+ array('a/b', 'b/b', array('a' => true, 'a/b' => true, 'b' => true, 'b/b' => false)),
+ );
+ }
+
+ /**
+ * @param $source
+ * @param $dest
+ * @param $updatables
+ */
+ private function moveTest($source, $dest, $updatables) {
+ $rootDir = new OC_Connector_Sabre_Directory('');
+ $objectTree = $this->getMock('\OC\Connector\Sabre\ObjectTree',
+ array('nodeExists', 'getNodeForPath'),
+ array($rootDir));
+
+ $objectTree->expects($this->once())
+ ->method('getNodeForPath')
+ ->with($this->identicalTo($source))
+ ->will($this->returnValue(false));
+
+ /** @var $objectTree \OC\Connector\Sabre\ObjectTree */
+ $objectTree->fileView = new TestDoubleFileView($updatables);
+ $objectTree->move($source, $dest);
+ }
+
+}
diff --git a/tests/lib/preview.php b/tests/lib/preview.php
index bebdc12b500..d0cdd2c44fb 100644
--- a/tests/lib/preview.php
+++ b/tests/lib/preview.php
@@ -92,6 +92,47 @@ class Preview extends \PHPUnit_Framework_TestCase {
$this->assertEquals($image->height(), $maxY);
}
+ public function txtBlacklist() {
+ $txt = 'random text file';
+ $ics = file_get_contents(__DIR__ . '/../data/testcal.ics');
+ $vcf = file_get_contents(__DIR__ . '/../data/testcontact.vcf');
+
+ return array(
+ array('txt', $txt, false),
+ array('ics', $ics, true),
+ array('vcf', $vcf, true),
+ );
+ }
+
+ /**
+ * @dataProvider txtBlacklist
+ */
+ public function testIsTransparent($extension, $data, $expectedResult) {
+ $user = $this->initFS();
+
+ $rootView = new \OC\Files\View('');
+ $rootView->mkdir('/'.$user);
+ $rootView->mkdir('/'.$user.'/files');
+
+ $x = 32;
+ $y = 32;
+
+ $sample = '/'.$user.'/files/test.'.$extension;
+ $rootView->file_put_contents($sample, $data);
+ $preview = new \OC\Preview($user, 'files/', 'test.'.$extension, $x, $y);
+ $image = $preview->getPreview();
+ $resource = $image->resource();
+
+ //http://stackoverflow.com/questions/5702953/imagecolorat-and-transparency
+ $colorIndex = imagecolorat($resource, 1, 1);
+ $colorInfo = imagecolorsforindex($resource, $colorIndex);
+ $this->assertEquals(
+ $expectedResult,
+ $colorInfo['alpha'] === 127,
+ 'Failed asserting that only previews for text files are transparent.'
+ );
+ }
+
private function initFS() {
if(\OC\Files\Filesystem::getView()){
$user = \OC_User::getUser();
@@ -105,4 +146,4 @@ class Preview extends \PHPUnit_Framework_TestCase {
return $user;
}
-} \ No newline at end of file
+}
diff --git a/tests/lib/user.php b/tests/lib/user.php
new file mode 100644
index 00000000000..66c7f3f0d74
--- /dev/null
+++ b/tests/lib/user.php
@@ -0,0 +1,43 @@
+<?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;
+
+use OC\Hooks\PublicEmitter;
+
+class User extends \PHPUnit_Framework_TestCase {
+
+ public function testCheckPassword() {
+ /**
+ * @var \OC_User_Backend | \PHPUnit_Framework_MockObject_MockObject $backend
+ */
+ $backend = $this->getMock('\OC_User_Dummy');
+ $backend->expects($this->once())
+ ->method('checkPassword')
+ ->with($this->equalTo('foo'), $this->equalTo('bar'))
+ ->will($this->returnValue('foo'));
+
+ $backend->expects($this->any())
+ ->method('implementsActions')
+ ->will($this->returnCallback(function ($actions) {
+ if ($actions === \OC_USER_BACKEND_CHECK_PASSWORD) {
+ return true;
+ } else {
+ return false;
+ }
+ }));
+
+ $manager = \OC_User::getManager();
+ $manager->registerBackend($backend);
+
+ $uid = \OC_User::checkPassword('foo', 'bar');
+ $this->assertEquals($uid, 'foo');
+ }
+
+} \ No newline at end of file
diff --git a/tests/lib/user/manager.php b/tests/lib/user/manager.php
index bc49f6db4b2..00901dd4115 100644
--- a/tests/lib/user/manager.php
+++ b/tests/lib/user/manager.php
@@ -98,6 +98,51 @@ class Manager extends \PHPUnit_Framework_TestCase {
$this->assertTrue($manager->userExists('foo'));
}
+ public function testCheckPassword() {
+ /**
+ * @var \OC_User_Backend | \PHPUnit_Framework_MockObject_MockObject $backend
+ */
+ $backend = $this->getMock('\OC_User_Dummy');
+ $backend->expects($this->once())
+ ->method('checkPassword')
+ ->with($this->equalTo('foo'), $this->equalTo('bar'))
+ ->will($this->returnValue(true));
+
+ $backend->expects($this->any())
+ ->method('implementsActions')
+ ->will($this->returnCallback(function ($actions) {
+ if ($actions === \OC_USER_BACKEND_CHECK_PASSWORD) {
+ return true;
+ } else {
+ return false;
+ }
+ }));
+
+ $manager = new \OC\User\Manager();
+ $manager->registerBackend($backend);
+
+ $user = $manager->checkPassword('foo', 'bar');
+ $this->assertTrue($user instanceof \OC\User\User);
+ }
+
+ public function testCheckPasswordNotSupported() {
+ /**
+ * @var \OC_User_Backend | \PHPUnit_Framework_MockObject_MockObject $backend
+ */
+ $backend = $this->getMock('\OC_User_Dummy');
+ $backend->expects($this->never())
+ ->method('checkPassword');
+
+ $backend->expects($this->any())
+ ->method('implementsActions')
+ ->will($this->returnValue(false));
+
+ $manager = new \OC\User\Manager();
+ $manager->registerBackend($backend);
+
+ $this->assertFalse($manager->checkPassword('foo', 'bar'));
+ }
+
public function testGetOneBackendExists() {
/**
* @var \OC_User_Dummy | \PHPUnit_Framework_MockObject_MockObject $backend
diff --git a/tests/lib/user/session.php b/tests/lib/user/session.php
index 274e9e2831e..e457a7bda30 100644
--- a/tests/lib/user/session.php
+++ b/tests/lib/user/session.php
@@ -62,10 +62,6 @@ class Session extends \PHPUnit_Framework_TestCase {
$user = $this->getMock('\OC\User\User', array(), array('foo', $backend));
$user->expects($this->once())
- ->method('checkPassword')
- ->with('bar')
- ->will($this->returnValue(true));
- $user->expects($this->once())
->method('isEnabled')
->will($this->returnValue(true));
$user->expects($this->any())
@@ -73,8 +69,8 @@ class Session extends \PHPUnit_Framework_TestCase {
->will($this->returnValue('foo'));
$manager->expects($this->once())
- ->method('get')
- ->with('foo')
+ ->method('checkPassword')
+ ->with('foo', 'bar')
->will($this->returnValue($user));
$userSession = new \OC\User\Session($manager, $session);
@@ -93,16 +89,12 @@ class Session extends \PHPUnit_Framework_TestCase {
$user = $this->getMock('\OC\User\User', array(), array('foo', $backend));
$user->expects($this->once())
- ->method('checkPassword')
- ->with('bar')
- ->will($this->returnValue(true));
- $user->expects($this->once())
->method('isEnabled')
->will($this->returnValue(false));
$manager->expects($this->once())
- ->method('get')
- ->with('foo')
+ ->method('checkPassword')
+ ->with('foo', 'bar')
->will($this->returnValue($user));
$userSession = new \OC\User\Session($manager, $session);
@@ -119,17 +111,13 @@ class Session extends \PHPUnit_Framework_TestCase {
$backend = $this->getMock('OC_User_Dummy');
$user = $this->getMock('\OC\User\User', array(), array('foo', $backend));
- $user->expects($this->once())
- ->method('checkPassword')
- ->with('bar')
- ->will($this->returnValue(false));
$user->expects($this->never())
->method('isEnabled');
$manager->expects($this->once())
- ->method('get')
- ->with('foo')
- ->will($this->returnValue($user));
+ ->method('checkPassword')
+ ->with('foo', 'bar')
+ ->will($this->returnValue(false));
$userSession = new \OC\User\Session($manager, $session);
$userSession->login('foo', 'bar');
@@ -145,9 +133,9 @@ class Session extends \PHPUnit_Framework_TestCase {
$backend = $this->getMock('OC_User_Dummy');
$manager->expects($this->once())
- ->method('get')
- ->with('foo')
- ->will($this->returnValue(null));
+ ->method('checkPassword')
+ ->with('foo', 'bar')
+ ->will($this->returnValue(false));
$userSession = new \OC\User\Session($manager, $session);
$userSession->login('foo', 'bar');
diff --git a/tests/lib/user/user.php b/tests/lib/user/user.php
index b0d170cbfc5..de5ccbf38c1 100644
--- a/tests/lib/user/user.php
+++ b/tests/lib/user/user.php
@@ -100,46 +100,6 @@ class User extends \PHPUnit_Framework_TestCase {
$this->assertTrue($user->delete());
}
- public function testCheckPassword() {
- /**
- * @var \OC_User_Backend | \PHPUnit_Framework_MockObject_MockObject $backend
- */
- $backend = $this->getMock('\OC_User_Dummy');
- $backend->expects($this->once())
- ->method('checkPassword')
- ->with($this->equalTo('foo'), $this->equalTo('bar'))
- ->will($this->returnValue(true));
-
- $backend->expects($this->any())
- ->method('implementsActions')
- ->will($this->returnCallback(function ($actions) {
- if ($actions === \OC_USER_BACKEND_CHECK_PASSWORD) {
- return true;
- } else {
- return false;
- }
- }));
-
- $user = new \OC\User\User('foo', $backend);
- $this->assertTrue($user->checkPassword('bar'));
- }
-
- public function testCheckPasswordNotSupported() {
- /**
- * @var \OC_User_Backend | \PHPUnit_Framework_MockObject_MockObject $backend
- */
- $backend = $this->getMock('\OC_User_Dummy');
- $backend->expects($this->never())
- ->method('checkPassword');
-
- $backend->expects($this->any())
- ->method('implementsActions')
- ->will($this->returnValue(false));
-
- $user = new \OC\User\User('foo', $backend);
- $this->assertFalse($user->checkPassword('bar'));
- }
-
public function testGetHome() {
/**
* @var \OC_User_Backend | \PHPUnit_Framework_MockObject_MockObject $backend