summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/lib/appframework/controller/ControllerTest.php22
-rw-r--r--tests/lib/db/mdb2schemamanager.php37
-rw-r--r--tests/lib/db/ts-autoincrement-after.xml32
-rw-r--r--tests/lib/db/ts-autoincrement-before.xml24
-rw-r--r--tests/lib/share/share.php77
5 files changed, 112 insertions, 80 deletions
diff --git a/tests/lib/appframework/controller/ControllerTest.php b/tests/lib/appframework/controller/ControllerTest.php
index 3c1716a91d8..65144e78f53 100644
--- a/tests/lib/appframework/controller/ControllerTest.php
+++ b/tests/lib/appframework/controller/ControllerTest.php
@@ -27,15 +27,8 @@ namespace OCP\AppFramework;
use OC\AppFramework\Http\Request;
use OCP\AppFramework\Http\TemplateResponse;
use OCP\AppFramework\Http\JSONResponse;
-use OCP\AppFramework\Http\IResponseSerializer;
-class ToUpperCaseSerializer implements IResponseSerializer {
- public function serialize($response) {
- return array(strtoupper($response));
- }
-}
-
class ChildController extends Controller {
public function custom($in) {
$this->registerResponder('json', function ($response) {
@@ -44,12 +37,6 @@ class ChildController extends Controller {
return $in;
}
-
- public function serializer($in) {
- $this->registerSerializer(new ToUpperCaseSerializer());
-
- return $in;
- }
};
class ControllerTest extends \PHPUnit_Framework_TestCase {
@@ -170,16 +157,9 @@ class ControllerTest extends \PHPUnit_Framework_TestCase {
$response = $this->controller->custom('hi');
$response = $this->controller->buildResponse($response, 'json');
- $this->assertEquals(array(2), $response->getData());
+ $this->assertEquals(array(2), $response->getData());
}
- public function testCustomSerializer() {
- $response = $this->controller->serializer('hi');
- $response = $this->controller->buildResponse($response, 'json');
-
- $this->assertEquals(array('HI'), $response->getData());
- }
-
}
diff --git a/tests/lib/db/mdb2schemamanager.php b/tests/lib/db/mdb2schemamanager.php
new file mode 100644
index 00000000000..51e3c7002f4
--- /dev/null
+++ b/tests/lib/db/mdb2schemamanager.php
@@ -0,0 +1,37 @@
+<?php
+
+/**
+ * Copyright (c) 2014 Thomas Müller <deepdiver@owncloud.com>
+ * This file is licensed under the Affero General Public License version 3 or
+ * later.
+ * See the COPYING-README file.
+ */
+
+namespace Test\DB;
+
+class MDB2SchemaManager extends \PHPUnit_Framework_TestCase {
+
+ public function tearDown() {
+ \OC_DB::dropTable('table');
+ }
+
+ public function testAutoIncrement() {
+
+ if (\OC::$server->getConfig()->getSystemValue('dbtype', 'sqlite') === 'oci') {
+ $this->markTestSkipped('Adding auto increment columns in Oracle is not supported.');
+ }
+
+ $connection = \OC_DB::getConnection();
+ $manager = new \OC\DB\MDB2SchemaManager($connection);
+
+ $manager->createDbFromStructure(__DIR__ . '/ts-autoincrement-before.xml');
+ $connection->executeUpdate('insert into `*PREFIX*table` values (?)', array('abc'));
+ $connection->executeUpdate('insert into `*PREFIX*table` values (?)', array('abc'));
+ $connection->executeUpdate('insert into `*PREFIX*table` values (?)', array('123'));
+ $connection->executeUpdate('insert into `*PREFIX*table` values (?)', array('123'));
+ $manager->updateDbFromStructure(__DIR__ . '/ts-autoincrement-after.xml');
+
+ $this->assertTrue(true);
+ }
+
+}
diff --git a/tests/lib/db/ts-autoincrement-after.xml b/tests/lib/db/ts-autoincrement-after.xml
new file mode 100644
index 00000000000..d4445f1e247
--- /dev/null
+++ b/tests/lib/db/ts-autoincrement-after.xml
@@ -0,0 +1,32 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<database>
+
+ <name>*dbname*</name>
+ <create>true</create>
+ <overwrite>false</overwrite>
+
+ <charset>utf8</charset>
+
+ <table>
+
+ <name>*dbprefix*table</name>
+
+ <declaration>
+ <field>
+ <name>auto_id</name>
+ <type>integer</type>
+ <default>0</default>
+ <notnull>true</notnull>
+ <autoincrement>1</autoincrement>
+ <length>4</length>
+ </field>
+ <field>
+ <name>textfield</name>
+ <type>text</type>
+ <default>foo</default>
+ <notnull>true</notnull>
+ <length>32</length>
+ </field>
+ </declaration>
+ </table>
+</database>
diff --git a/tests/lib/db/ts-autoincrement-before.xml b/tests/lib/db/ts-autoincrement-before.xml
new file mode 100644
index 00000000000..412739e9a71
--- /dev/null
+++ b/tests/lib/db/ts-autoincrement-before.xml
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<database>
+
+ <name>*dbname*</name>
+ <create>true</create>
+ <overwrite>false</overwrite>
+
+ <charset>utf8</charset>
+
+ <table>
+
+ <name>*dbprefix*table</name>
+
+ <declaration>
+ <field>
+ <name>textfield</name>
+ <type>text</type>
+ <default>foo</default>
+ <notnull>true</notnull>
+ <length>32</length>
+ </field>
+ </declaration>
+ </table>
+</database>
diff --git a/tests/lib/share/share.php b/tests/lib/share/share.php
index 95983ee70e6..5920b44a8e0 100644
--- a/tests/lib/share/share.php
+++ b/tests/lib/share/share.php
@@ -151,6 +151,12 @@ class Test_Share extends PHPUnit_Framework_TestCase {
);
}
+ protected function shareUserTestFileAsLink() {
+ OC_User::setUserId($this->user1);
+ $result = OCP\Share::shareItem('test', 'test.txt', OCP\Share::SHARE_TYPE_LINK, null, OCP\PERMISSION_READ);
+ $this->assertTrue(is_string($result));
+ }
+
/**
* @param string $sharer
* @param string $receiver
@@ -316,36 +322,35 @@ class Test_Share extends PHPUnit_Framework_TestCase {
}
public function testShareWithUserExpirationExpired() {
+ OC_User::setUserId($this->user1);
$this->shareUserOneTestFileWithUserTwo();
+ $this->shareUserTestFileAsLink();
- OC_User::setUserId($this->user1);
$this->assertTrue(
OCP\Share::setExpirationDate('test', 'test.txt', $this->dateInPast),
'Failed asserting that user 1 successfully set an expiration date for the test.txt share.'
);
- OC_User::setUserId($this->user2);
- $this->assertSame(array(),
- OCP\Share::getItemSharedWith('test', 'test.txt', Test_Share_Backend::FORMAT_SOURCE),
- 'Failed asserting that user 2 no longer has access to test.txt after expiration.'
- );
+ $shares = OCP\Share::getItemsShared('test');
+ $this->assertSame(1, count($shares));
+ $share = reset($shares);
+ $this->assertSame(\OCP\Share::SHARE_TYPE_USER, $share['share_type']);
}
public function testShareWithUserExpirationValid() {
+ OC_User::setUserId($this->user1);
$this->shareUserOneTestFileWithUserTwo();
+ $this->shareUserTestFileAsLink();
+
- OC_User::setUserId($this->user1);
$this->assertTrue(
OCP\Share::setExpirationDate('test', 'test.txt', $this->dateInFuture),
'Failed asserting that user 1 successfully set an expiration date for the test.txt share.'
);
- OC_User::setUserId($this->user2);
- $this->assertEquals(
- array('test.txt'),
- OCP\Share::getItemSharedWith('test', 'test.txt', Test_Share_Backend::FORMAT_SOURCE),
- 'Failed asserting that user 2 still has access to test.txt after expiration date has been set.'
- );
+ $shares = OCP\Share::getItemsShared('test');
+ $this->assertSame(2, count($shares));
+
}
protected function shareUserOneTestFileWithGroupOne() {
@@ -516,52 +521,6 @@ class Test_Share extends PHPUnit_Framework_TestCase {
$this->assertEquals(array(), OCP\Share::getItemsShared('test'));
}
- public function testShareWithGroupExpirationExpired() {
- $this->shareUserOneTestFileWithGroupOne();
-
- OC_User::setUserId($this->user1);
- $this->assertTrue(
- OCP\Share::setExpirationDate('test', 'test.txt', $this->dateInPast),
- 'Failed asserting that user 1 successfully set an expiration date for the test.txt share.'
- );
-
- OC_User::setUserId($this->user2);
- $this->assertSame(array(),
- OCP\Share::getItemSharedWith('test', 'test.txt', Test_Share_Backend::FORMAT_SOURCE),
- 'Failed asserting that user 2 no longer has access to test.txt after expiration.'
- );
-
- OC_User::setUserId($this->user3);
- $this->assertSame(array(),
- OCP\Share::getItemSharedWith('test', 'test.txt', Test_Share_Backend::FORMAT_SOURCE),
- 'Failed asserting that user 3 no longer has access to test.txt after expiration.'
- );
- }
-
- public function testShareWithGroupExpirationValid() {
- $this->shareUserOneTestFileWithGroupOne();
-
- OC_User::setUserId($this->user1);
- $this->assertTrue(
- OCP\Share::setExpirationDate('test', 'test.txt', $this->dateInFuture),
- 'Failed asserting that user 1 successfully set an expiration date for the test.txt share.'
- );
-
- OC_User::setUserId($this->user2);
- $this->assertEquals(
- array('test.txt'),
- OCP\Share::getItemSharedWith('test', 'test.txt', Test_Share_Backend::FORMAT_SOURCE),
- 'Failed asserting that user 2 still has access to test.txt after expiration date has been set.'
- );
-
- OC_User::setUserId($this->user3);
- $this->assertEquals(
- array('test.txt'),
- OCP\Share::getItemSharedWith('test', 'test.txt', Test_Share_Backend::FORMAT_SOURCE),
- 'Failed asserting that user 3 still has access to test.txt after expiration date has been set.'
- );
- }
-
/**
* @param boolean|string $token
*/