aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/lib/app.php53
-rw-r--r--tests/lib/files/view.php14
-rw-r--r--tests/lib/repair/cleantags.php143
3 files changed, 208 insertions, 2 deletions
diff --git a/tests/lib/app.php b/tests/lib/app.php
index 23c1a340e03..1bd350f216a 100644
--- a/tests/lib/app.php
+++ b/tests/lib/app.php
@@ -112,7 +112,7 @@ class Test_App extends \Test\TestCase {
),
true
),
- // multiple OC number
+ // multiple OC number
array(
'4.3.1',
array(
@@ -120,7 +120,7 @@ class Test_App extends \Test\TestCase {
),
true
),
- // single app number
+ // single app number
array(
'4',
array(
@@ -208,6 +208,55 @@ class Test_App extends \Test\TestCase {
),
true
),
+ // dependencies versions before require*
+ array(
+ '6.0.0.0',
+ array(
+ 'requiremin' => '5.0',
+ 'requiremax' => '7.0',
+ 'dependencies' => array(
+ 'owncloud' => array(
+ '@attributes' => array(
+ 'min-version' => '7.0',
+ 'max-version' => '7.0',
+ ),
+ ),
+ ),
+ ),
+ false
+ ),
+ array(
+ '6.0.0.0',
+ array(
+ 'requiremin' => '5.0',
+ 'requiremax' => '7.0',
+ 'dependencies' => array(
+ 'owncloud' => array(
+ '@attributes' => array(
+ 'min-version' => '5.0',
+ 'max-version' => '5.0',
+ ),
+ ),
+ ),
+ ),
+ false
+ ),
+ array(
+ '6.0.0.0',
+ array(
+ 'requiremin' => '5.0',
+ 'requiremax' => '5.0',
+ 'dependencies' => array(
+ 'owncloud' => array(
+ '@attributes' => array(
+ 'min-version' => '5.0',
+ 'max-version' => '7.0',
+ ),
+ ),
+ ),
+ ),
+ true
+ ),
);
}
diff --git a/tests/lib/files/view.php b/tests/lib/files/view.php
index 25065967260..3ff19d7385d 100644
--- a/tests/lib/files/view.php
+++ b/tests/lib/files/view.php
@@ -703,6 +703,20 @@ class View extends \Test\TestCase {
$this->assertEquals($expectedPath, $view->getAbsolutePath($relativePath));
}
+ public function testPartFileInfo() {
+ $storage = new Temporary(array());
+ $scanner = $storage->getScanner();
+ \OC\Files\Filesystem::mount($storage, array(), '/test/');
+ $storage->file_put_contents('test.part', 'foobar');
+ $scanner->scan('');
+ $view = new \OC\Files\View('/test');
+ $info = $view->getFileInfo('test.part');
+
+ $this->assertInstanceOf('\OCP\Files\FileInfo', $info);
+ $this->assertNull($info->getId());
+ $this->assertEquals(6, $info->getSize());
+ }
+
function absolutePathProvider() {
return array(
array('/files/', ''),
diff --git a/tests/lib/repair/cleantags.php b/tests/lib/repair/cleantags.php
new file mode 100644
index 00000000000..29a1a8b432e
--- /dev/null
+++ b/tests/lib/repair/cleantags.php
@@ -0,0 +1,143 @@
+<?php
+/**
+ * Copyright (c) 2015 Joas Schilling <nickvergessen@owncloud.com>
+ * This file is licensed under the Affero General Public License version 3 or
+ * later.
+ * See the COPYING-README file.
+ */
+
+namespace Test\Repair;
+
+/**
+ * Tests for the cleaning the tags tables
+ *
+ * @see \OC\Repair\CleanTags
+ */
+class CleanTags extends \Test\TestCase {
+
+ /** @var \OC\RepairStep */
+ private $repair;
+
+ /** @var \Doctrine\DBAL\Connection */
+ private $connection;
+
+ /** @var array */
+ protected $tagCategories;
+
+ /** @var int */
+ protected $createdFile;
+
+ protected function setUp() {
+ parent::setUp();
+
+ $this->connection = \OC::$server->getDatabaseConnection();
+ $this->repair = new \OC\Repair\CleanTags($this->connection);
+ }
+
+ protected function tearDown() {
+ $qb = $this->connection->createQueryBuilder();
+ $qb->delete('*PREFIX*vcategory')
+ ->where('uid = ' . $qb->createNamedParameter('TestRepairCleanTags'))
+ ->execute();
+
+ $qb->delete('*PREFIX*vcategory_to_object')
+ ->where($qb->expr()->in('categoryid', ':ids'));
+ $qb->setParameter('ids', $this->tagCategories, \Doctrine\DBAL\Connection::PARAM_INT_ARRAY);
+ $qb->execute();
+
+ $qb->delete('*PREFIX*filecache')
+ ->where('fileid = ' . $qb->createNamedParameter($this->createdFile, \PDO::PARAM_INT))
+ ->execute();
+
+ parent::tearDown();
+ }
+
+ public function testRun() {
+ $cat1 = $this->addTagCategory('TestRepairCleanTags', 'files'); // Retained
+ $cat2 = $this->addTagCategory('TestRepairCleanTags2', 'files'); // Deleted: Category is empty
+ $cat3 = $this->addTagCategory('TestRepairCleanTags', 'contacts'); // Retained
+ $file = $this->getFileID();
+
+ $this->addTagEntry($file, $cat2, 'files'); // Retained
+ $this->addTagEntry($file + 1, $cat1, 'files'); // Deleted: File is NULL
+ $this->addTagEntry(9999999, $cat3, 'contacts'); // Retained
+ $this->addTagEntry($file, $cat3 + 1, 'files'); // Deleted: Category is NULL
+
+ $this->assertEntryCount('*PREFIX*vcategory', 3, 'Assert tag categories count before repair step');
+ $this->assertEntryCount('*PREFIX*vcategory_to_object', 4, 'Assert tag entries count before repair step');
+ $this->repair->run();
+ $this->assertEntryCount('*PREFIX*vcategory', 2, 'Assert tag categories count after repair step');
+ $this->assertEntryCount('*PREFIX*vcategory_to_object', 2, 'Assert tag entries count after repair step');
+ }
+
+ /**
+ * @param string $tableName
+ * @param int $expected
+ * @param string $message
+ */
+ protected function assertEntryCount($tableName, $expected, $message = '') {
+ $qb = $this->connection->createQueryBuilder();
+ $result = $qb->select('COUNT(*)')
+ ->from($tableName)
+ ->execute();
+
+ $this->assertEquals($expected, $result->fetchColumn(), $message);
+ }
+
+ /**
+ * Adds a new tag category to the database
+ *
+ * @param string $category
+ * @param string $type
+ * @return int
+ */
+ protected function addTagCategory($category, $type) {
+ $qb = $this->connection->createQueryBuilder();
+ $qb->insert('*PREFIX*vcategory')
+ ->values([
+ 'uid' => $qb->createNamedParameter('TestRepairCleanTags'),
+ 'category' => $qb->createNamedParameter($category),
+ 'type' => $qb->createNamedParameter($type),
+ ])
+ ->execute();
+
+ $id = (int) $this->connection->lastInsertId();
+ $this->tagCategories[] = $id;
+ return $id;
+ }
+
+ /**
+ * Adds a new tag entry to the database
+ * @param int $objectId
+ * @param int $category
+ * @param string $type
+ */
+ protected function addTagEntry($objectId, $category, $type) {
+ $qb = $this->connection->createQueryBuilder();
+ $qb->insert('*PREFIX*vcategory_to_object')
+ ->values([
+ 'objid' => $qb->createNamedParameter($objectId, \PDO::PARAM_INT),
+ 'categoryid' => $qb->createNamedParameter($category, \PDO::PARAM_INT),
+ 'type' => $qb->createNamedParameter($type),
+ ])
+ ->execute();
+ }
+
+ /**
+ * Gets the last fileid from the file cache
+ *
+ * @return int
+ */
+ protected function getFileID() {
+ $qb = $this->connection->createQueryBuilder();
+
+ // We create a new file entry and delete it after the test again
+ $qb->insert('*PREFIX*filecache')
+ ->values([
+ 'path' => $qb->createNamedParameter('TestRepairCleanTags'),
+ ])
+ ->execute();
+ $this->createdFile = (int) $this->connection->lastInsertId();
+ return $this->createdFile;
+ }
+}