summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorMorris Jobke <hey@morrisjobke.de>2015-07-01 08:53:37 +0200
committerMorris Jobke <hey@morrisjobke.de>2015-07-01 08:53:37 +0200
commitc703a3a63ed2808f92da677e7a798527a8034ae6 (patch)
treec553f2898f4ca008fc3619244e84d8dac453b84c /tests
parent044d2ece07025b9a9cd5fa3c0514c65369ac9e4e (diff)
parent1601867c9dd6a9ce28894d96e5dce3a7e003f4e3 (diff)
downloadnextcloud-server-c703a3a63ed2808f92da677e7a798527a8034ae6.tar.gz
nextcloud-server-c703a3a63ed2808f92da677e7a798527a8034ae6.zip
Merge pull request #15569 from owncloud/remove-getetag-properties
Remove unneeded getetag entries in properties table
Diffstat (limited to 'tests')
-rw-r--r--tests/lib/repair/removegetetagentriestest.php77
1 files changed, 77 insertions, 0 deletions
diff --git a/tests/lib/repair/removegetetagentriestest.php b/tests/lib/repair/removegetetagentriestest.php
new file mode 100644
index 00000000000..43b7bf323c0
--- /dev/null
+++ b/tests/lib/repair/removegetetagentriestest.php
@@ -0,0 +1,77 @@
+<?php
+/**
+ * @author Morris Jobke <hey@morrisjobke.de>
+ *
+ * @copyright Copyright (c) 2015, ownCloud, Inc.
+ * @license AGPL-3.0
+ *
+ * This code is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License, version 3,
+ * as published by the Free Software Foundation.
+ *
+ * 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, version 3,
+ * along with this program. If not, see <http://www.gnu.org/licenses/>
+ *
+ */
+
+namespace Test\Repair;
+
+use OC\Repair\RemoveGetETagEntries;
+use Test\TestCase;
+
+class RemoveGetETagEntriesTest extends TestCase {
+ /** @var \OCP\IDBConnection */
+ protected $connection;
+
+ protected function setUp() {
+ parent::setUp();
+
+ $this->connection = \OC::$server->getDatabaseConnection();
+ }
+
+ public function testRun() {
+
+ $userName = 'removePropertiesUser';
+ $data = [
+ [$userName, '/abc.def.txt', '{DAV:}getetag', 'abcdef'],
+ [$userName, '/abc.def.txt', '{DAV:}anotherRandomProperty', 'ghi'],
+ ];
+
+ // insert test data
+ $sqlToInsertProperties = 'INSERT INTO `*PREFIX*properties` (`userid`, `propertypath`, `propertyname`, `propertyvalue`) VALUES (?, ?, ? ,?)';
+ foreach ($data as $entry) {
+ $this->connection->executeUpdate($sqlToInsertProperties, $entry);
+ }
+
+ // check if test data is written to DB
+ $sqlToFetchProperties = 'SELECT `userid`, `propertypath`, `propertyname`, `propertyvalue` FROM `*PREFIX*properties` WHERE `userid` = ?';
+ $stmt = $this->connection->executeQuery($sqlToFetchProperties, [$userName]);
+ $entries = $stmt->fetchAll(\PDO::FETCH_NUM);
+
+ $this->assertCount(2, $entries, 'Asserts that two entries are returned as we have inserted two');
+ foreach($entries as $entry) {
+ $this->assertTrue(in_array($entry, $data), 'Asserts that the entries are the ones from the test data set');
+ }
+
+ // run repair step
+ $repair = new RemoveGetETagEntries($this->connection);
+ $repair->run();
+
+ // check if test data is correctly modified in DB
+ $stmt = $this->connection->executeQuery($sqlToFetchProperties, [$userName]);
+ $entries = $stmt->fetchAll(\PDO::FETCH_NUM);
+
+ $this->assertCount(1, $entries, 'Asserts that only one entry is returned after the repair step - the other one has to be removed');
+ $this->assertSame($data[1], $entries[0], 'Asserts that the returned entry is the correct one from the test data set');
+
+ // remove test data
+ $sqlToRemoveProperties = 'DELETE FROM `*PREFIX*properties` WHERE `userid` = ?';
+ $this->connection->executeUpdate($sqlToRemoveProperties, [$userName]);
+ }
+
+}