2014-02-20 18:21:53 +04:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* ownCloud
|
|
|
|
*
|
|
|
|
* @author Morris Jobke
|
|
|
|
* @copyright 2014 Morris Jobke <morris.jobke@gmail.com>
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 3 of the License, or any later version.
|
|
|
|
*
|
|
|
|
* This library 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 along with this library. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Class Test_Files_Sharing_Updater
|
|
|
|
*/
|
|
|
|
class Test_Files_Sharing_Updater extends \PHPUnit_Framework_TestCase {
|
|
|
|
|
|
|
|
function setUp() {
|
2014-02-27 16:27:24 +04:00
|
|
|
// some previous tests didn't clean up and therefore this has to be done here
|
|
|
|
// FIXME: DIRTY HACK - TODO: find tests, that don't clean up and fix it there
|
|
|
|
$this->tearDown();
|
|
|
|
|
2014-02-20 18:21:53 +04:00
|
|
|
// add items except one - because this is the test case for the broken share table
|
2014-03-26 12:29:28 +04:00
|
|
|
$addItems = \OC_DB::prepare('INSERT INTO `*PREFIX*filecache` (`storage`, `path_hash`, ' .
|
2014-02-28 18:28:50 +04:00
|
|
|
'`parent`, `mimetype`, `mimepart`, `size`, `mtime`, `storage_mtime`) ' .
|
2014-03-26 12:29:28 +04:00
|
|
|
'VALUES (1, ?, 1, 1, 1, 1, 1, 1)');
|
2014-02-20 18:21:53 +04:00
|
|
|
$items = array(1, 3);
|
2014-03-25 23:18:58 +04:00
|
|
|
$fileIds = array();
|
2014-02-20 18:21:53 +04:00
|
|
|
foreach($items as $item) {
|
2014-03-26 12:29:28 +04:00
|
|
|
// the number is used as path_hash
|
|
|
|
$addItems->execute(array($item));
|
2014-03-25 23:18:58 +04:00
|
|
|
$fileIds[] = \OC_DB::insertId('*PREFIX*filecache');
|
2014-02-20 18:21:53 +04:00
|
|
|
}
|
2014-03-25 23:18:58 +04:00
|
|
|
|
2014-03-26 12:29:28 +04:00
|
|
|
$addShares = \OC_DB::prepare('INSERT INTO `*PREFIX*share` (`file_source`, `item_type`, `uid_owner`) VALUES (?, \'file\', 1)');
|
|
|
|
// the number is used as item_source
|
|
|
|
$addShares->execute(array($fileIds[0]));
|
|
|
|
$addShares->execute(array(200)); // id of "deleted" file
|
|
|
|
$addShares->execute(array($fileIds[1]));
|
2014-02-20 18:21:53 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
function tearDown() {
|
|
|
|
$removeShares = \OC_DB::prepare('DELETE FROM `*PREFIX*share`');
|
|
|
|
$removeShares->execute();
|
|
|
|
$removeItems = \OC_DB::prepare('DELETE FROM `*PREFIX*filecache`');
|
|
|
|
$removeItems->execute();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @medium
|
|
|
|
*/
|
|
|
|
function testRemoveBrokenShares() {
|
|
|
|
// check if there are just 3 shares (see setUp - precondition: empty table)
|
2014-02-28 18:28:50 +04:00
|
|
|
$countShares = \OC_DB::prepare('SELECT COUNT(`id`) FROM `*PREFIX*share`');
|
2014-02-20 18:21:53 +04:00
|
|
|
$result = $countShares->execute()->fetchOne();
|
|
|
|
$this->assertEquals(3, $result);
|
|
|
|
|
|
|
|
// check if there are just 2 items (see setUp - precondition: empty table)
|
2014-02-28 18:28:50 +04:00
|
|
|
$countItems = \OC_DB::prepare('SELECT COUNT(`fileid`) FROM `*PREFIX*filecache`');
|
2014-02-20 18:21:53 +04:00
|
|
|
$result = $countItems->execute()->fetchOne();
|
|
|
|
$this->assertEquals(2, $result);
|
|
|
|
|
|
|
|
// execute actual code which should be tested
|
|
|
|
\OC\Files\Cache\Shared_Updater::fixBrokenSharesOnAppUpdate();
|
|
|
|
|
|
|
|
// check if there are just 2 shares (one gets killed by the code as there is no filecache entry for this)
|
2014-02-28 18:28:50 +04:00
|
|
|
$countShares = \OC_DB::prepare('SELECT COUNT(`id`) FROM `*PREFIX*share`');
|
2014-02-20 18:21:53 +04:00
|
|
|
$result = $countShares->execute()->fetchOne();
|
|
|
|
$this->assertEquals(2, $result);
|
|
|
|
|
2014-03-25 23:18:58 +04:00
|
|
|
// check if the share of file '200' is removed as there is no entry for this in filecache table
|
|
|
|
$countShares = \OC_DB::prepare('SELECT COUNT(`id`) FROM `*PREFIX*share` WHERE `file_source` = 200');
|
2014-02-20 18:21:53 +04:00
|
|
|
$result = $countShares->execute()->fetchOne();
|
|
|
|
$this->assertEquals(0, $result);
|
|
|
|
|
|
|
|
// check if there are just 2 items
|
2014-02-28 18:28:50 +04:00
|
|
|
$countItems = \OC_DB::prepare('SELECT COUNT(`fileid`) FROM `*PREFIX*filecache`');
|
2014-02-20 18:21:53 +04:00
|
|
|
$result = $countItems->execute()->fetchOne();
|
|
|
|
$this->assertEquals(2, $result);
|
|
|
|
}
|
|
|
|
}
|