diff options
author | Vincent Petry <pvince81@owncloud.com> | 2016-06-10 10:42:04 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-06-10 10:42:04 +0200 |
commit | d81dac24aaeea49fc942686c144d570f11497e01 (patch) | |
tree | 0038c6c7abc354dc04f533428026fcceb1c08550 /tests | |
parent | 67c3a974012770757ec63ef5257008fdb5902d37 (diff) | |
parent | 7d51fd0310ef74ae9db7358e524b8a679ef2df39 (diff) | |
download | nextcloud-server-d81dac24aaeea49fc942686c144d570f11497e01.tar.gz nextcloud-server-d81dac24aaeea49fc942686c144d570f11497e01.zip |
Merge pull request #25025 from owncloud/clear_old_calendar_shares
Add repair step to clean old calendar shares
Diffstat (limited to 'tests')
-rw-r--r-- | tests/lib/Repair/RemoveOldSharesTest.php | 160 |
1 files changed, 160 insertions, 0 deletions
diff --git a/tests/lib/Repair/RemoveOldSharesTest.php b/tests/lib/Repair/RemoveOldSharesTest.php new file mode 100644 index 00000000000..ac30585bdc5 --- /dev/null +++ b/tests/lib/Repair/RemoveOldSharesTest.php @@ -0,0 +1,160 @@ +<?php +/** + * @author Roeland Jago Douma <rullzer@owncloud.com> + * + * @copyright Copyright (c) 2016, 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\RemoveOldShares; +use OCP\IDBConnection; +use OCP\Migration\IOutput; + +/** + * Class RemoveOldSharesTest + * + * @package Test\Repair + * @group DB + */ +class RemoveOldSharesTest extends \Test\TestCase { + + /** @var RemoveOldShares */ + protected $repair; + + /** @var IDBConnection */ + protected $connection; + + /** @var IOutput */ + private $outputMock; + + protected function setUp() { + parent::setUp(); + + $this->outputMock = $this->getMockBuilder('\OCP\Migration\IOutput') + ->disableOriginalConstructor() + ->getMock(); + + $this->connection = \OC::$server->getDatabaseConnection(); + $this->repair = new RemoveOldShares($this->connection); + } + + protected function tearDown() { + $qb = $this->connection->getQueryBuilder(); + $qb->delete('share'); + $qb->execute(); + + return parent::tearDown(); + } + + public function testRun() { + $qb = $this->connection->getQueryBuilder(); + $qb->insert('share') + ->values([ + 'share_type' => $qb->createNamedParameter(0), + 'share_with' => $qb->createNamedParameter('foo'), + 'uid_owner' => $qb->createNamedParameter('owner'), + 'item_type' => $qb->createNamedParameter('file'), + 'item_source' => $qb->createNamedParameter(42), + 'item_target' => $qb->createNamedParameter('/target'), + 'file_source' => $qb->createNamedParameter(42), + 'file_target' => $qb->createNamedParameter('/target'), + 'permissions' => $qb->createNamedParameter(1), + ]); + $qb->execute(); + + $qb = $this->connection->getQueryBuilder(); + $qb->insert('share') + ->values([ + 'share_type' => $qb->createNamedParameter(0), + 'share_with' => $qb->createNamedParameter('foo'), + 'uid_owner' => $qb->createNamedParameter('owner'), + 'item_type' => $qb->createNamedParameter('calendar'), + 'item_source' => $qb->createNamedParameter(42), + 'item_target' => $qb->createNamedParameter('/target'), + 'file_source' => $qb->createNamedParameter(42), + 'file_target' => $qb->createNamedParameter('/target'), + 'permissions' => $qb->createNamedParameter(1), + ]); + $qb->execute(); + + $qb = $this->connection->getQueryBuilder(); + $qb->insert('share') + ->values([ + 'share_type' => $qb->createNamedParameter(0), + 'share_with' => $qb->createNamedParameter('foo'), + 'uid_owner' => $qb->createNamedParameter('owner'), + 'item_type' => $qb->createNamedParameter('event'), + 'item_source' => $qb->createNamedParameter(42), + 'item_target' => $qb->createNamedParameter('/target'), + 'file_source' => $qb->createNamedParameter(42), + 'file_target' => $qb->createNamedParameter('/target'), + 'permissions' => $qb->createNamedParameter(1), + ]); + $qb->execute(); + + $qb = $this->connection->getQueryBuilder(); + $qb->insert('share') + ->values([ + 'share_type' => $qb->createNamedParameter(0), + 'share_with' => $qb->createNamedParameter('foo'), + 'uid_owner' => $qb->createNamedParameter('owner'), + 'item_type' => $qb->createNamedParameter('contact'), + 'item_source' => $qb->createNamedParameter(42), + 'item_target' => $qb->createNamedParameter('/target'), + 'file_source' => $qb->createNamedParameter(42), + 'file_target' => $qb->createNamedParameter('/target'), + 'permissions' => $qb->createNamedParameter(1), + ]); + $qb->execute(); + + $qb = $this->connection->getQueryBuilder(); + $qb->insert('share') + ->values([ + 'share_type' => $qb->createNamedParameter(0), + 'share_with' => $qb->createNamedParameter('foo'), + 'uid_owner' => $qb->createNamedParameter('owner'), + 'item_type' => $qb->createNamedParameter('addressbook'), + 'item_source' => $qb->createNamedParameter(42), + 'item_target' => $qb->createNamedParameter('/target'), + 'file_source' => $qb->createNamedParameter(42), + 'file_target' => $qb->createNamedParameter('/target'), + 'permissions' => $qb->createNamedParameter(1), + ]); + $qb->execute(); + + $qb = $this->connection->getQueryBuilder(); + $qb->selectAlias($qb->createFunction('COUNT(*)'), 'count') + ->from('share'); + + $cursor = $qb->execute(); + $data = $cursor->fetchAll(); + $cursor->closeCursor(); + $this->assertEquals(5, $data[0]['count']); + + $this->repair->run($this->outputMock); + + $qb = $this->connection->getQueryBuilder(); + $qb->select('*') + ->from('share'); + + $cursor = $qb->execute(); + $data = $cursor->fetchAll(); + $cursor->closeCursor(); + $this->assertCount(1, $data); + $this->assertEquals('file', $data[0]['item_type']); + } +} |