diff options
author | Thomas Müller <thomas.mueller@tmit.eu> | 2016-04-22 15:35:39 +0200 |
---|---|---|
committer | Thomas Müller <thomas.mueller@tmit.eu> | 2016-04-25 15:01:13 +0200 |
commit | c7542c02dbc997d818e984dae23bdf1780843559 (patch) | |
tree | eaa5e6b7230b531a4e5f494544be41449a0100f5 /tests | |
parent | a4b1d9feee79218268abcb0c20ed16bec82c993c (diff) | |
download | nextcloud-server-c7542c02dbc997d818e984dae23bdf1780843559.tar.gz nextcloud-server-c7542c02dbc997d818e984dae23bdf1780843559.zip |
Introduce OCP\Migration\IRepairStep and adopt all repair steps to this new interface - refs #24198
Diffstat (limited to 'tests')
-rw-r--r-- | tests/lib/repair.php | 10 | ||||
-rw-r--r-- | tests/lib/repair/cleantags.php | 16 | ||||
-rw-r--r-- | tests/lib/repair/dropoldjobs.php | 8 | ||||
-rw-r--r-- | tests/lib/repair/dropoldtables.php | 8 | ||||
-rw-r--r-- | tests/lib/repair/oldgroupmembershipsharestest.php | 8 | ||||
-rw-r--r-- | tests/lib/repair/removegetetagentriestest.php | 8 | ||||
-rw-r--r-- | tests/lib/repair/repaircollation.php | 9 | ||||
-rw-r--r-- | tests/lib/repair/repairinnodb.php | 11 | ||||
-rw-r--r-- | tests/lib/repair/repairinvalidsharestest.php | 18 | ||||
-rw-r--r-- | tests/lib/repair/repairlegacystorage.php | 47 | ||||
-rw-r--r-- | tests/lib/repair/repairmimetypes.php | 20 | ||||
-rw-r--r-- | tests/lib/repair/repairsharepropagation.php | 8 | ||||
-rw-r--r-- | tests/lib/repair/repairsqliteautoincrement.php | 8 | ||||
-rw-r--r-- | tests/lib/repair/updateoutdatedocsids.php | 2 |
14 files changed, 130 insertions, 51 deletions
diff --git a/tests/lib/repair.php b/tests/lib/repair.php index 248db382140..a598d3c1a29 100644 --- a/tests/lib/repair.php +++ b/tests/lib/repair.php @@ -6,9 +6,9 @@ * See the COPYING-README file. */ -use OC\Hooks\BasicEmitter; +use OCP\Migration\IRepairStep; -class TestRepairStep extends BasicEmitter implements \OC\RepairStep{ +class TestRepairStep implements IRepairStep { private $warning; public function __construct($warning = false) { @@ -19,12 +19,12 @@ class TestRepairStep extends BasicEmitter implements \OC\RepairStep{ return 'Test Name'; } - public function run() { + public function run(\OCP\Migration\IOutput $out) { if ($this->warning) { - $this->emit('\OC\Repair', 'warning', array('Simulated warning')); + $out->warning('Simulated warning'); } else { - $this->emit('\OC\Repair', 'info', array('Simulated info')); + $out->info('Simulated info'); } } } diff --git a/tests/lib/repair/cleantags.php b/tests/lib/repair/cleantags.php index fa11a7f736e..214e2a17c94 100644 --- a/tests/lib/repair/cleantags.php +++ b/tests/lib/repair/cleantags.php @@ -8,6 +8,7 @@ namespace Test\Repair; use OCP\DB\QueryBuilder\IQueryBuilder; +use OCP\Migration\IOutput; /** * Tests for the cleaning the tags tables @@ -18,7 +19,7 @@ use OCP\DB\QueryBuilder\IQueryBuilder; */ class CleanTags extends \Test\TestCase { - /** @var \OC\RepairStep */ + /** @var \OC\Repair\CleanTags */ protected $repair; /** @var \OCP\IDBConnection */ @@ -27,9 +28,16 @@ class CleanTags extends \Test\TestCase { /** @var int */ protected $createdFile; + /** @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 \OC\Repair\CleanTags($this->connection); $this->cleanUpTables(); @@ -67,15 +75,15 @@ class CleanTags extends \Test\TestCase { $this->assertEntryCount('vcategory_to_object', 4, 'Assert tag entries count before repair step'); $this->assertEntryCount('vcategory', 4, 'Assert tag categories count before repair step'); - self::invokePrivate($this->repair, 'deleteOrphanFileEntries'); + self::invokePrivate($this->repair, 'deleteOrphanFileEntries', [$this->outputMock]); $this->assertEntryCount('vcategory_to_object', 3, 'Assert tag entries count after cleaning file entries'); $this->assertEntryCount('vcategory', 4, 'Assert tag categories count after cleaning file entries'); - self::invokePrivate($this->repair, 'deleteOrphanTagEntries'); + self::invokePrivate($this->repair, 'deleteOrphanTagEntries', [$this->outputMock]); $this->assertEntryCount('vcategory_to_object', 2, 'Assert tag entries count after cleaning tag entries'); $this->assertEntryCount('vcategory', 4, 'Assert tag categories count after cleaning tag entries'); - self::invokePrivate($this->repair, 'deleteOrphanCategoryEntries'); + self::invokePrivate($this->repair, 'deleteOrphanCategoryEntries', [$this->outputMock]); $this->assertEntryCount('vcategory_to_object', 2, 'Assert tag entries count after cleaning category entries'); $this->assertEntryCount('vcategory', 2, 'Assert tag categories count after cleaning category entries'); } diff --git a/tests/lib/repair/dropoldjobs.php b/tests/lib/repair/dropoldjobs.php index a85c6506dbb..c8a4aa3f1c2 100644 --- a/tests/lib/repair/dropoldjobs.php +++ b/tests/lib/repair/dropoldjobs.php @@ -9,6 +9,7 @@ namespace Test\Repair; use OCP\BackgroundJob\IJobList; +use OCP\Migration\IOutput; /** * Tests for the dropping old tables @@ -33,8 +34,13 @@ class DropOldJobs extends \Test\TestCase { $this->assertTrue($this->jobList->has('OC\Cache\FileGlobalGC', null), 'Asserting that the job OC\Cache\FileGlobalGC exists before repairing'); $this->assertTrue($this->jobList->has('OC_Cache_FileGlobalGC', null), 'Asserting that the job OC_Cache_FileGlobalGC exists before repairing'); + /** @var IOutput | \PHPUnit_Framework_MockObject_MockObject $outputMock */ + $outputMock = $this->getMockBuilder('\OCP\Migration\IOutput') + ->disableOriginalConstructor() + ->getMock(); + $repair = new \OC\Repair\DropOldJobs($this->jobList); - $repair->run(); + $repair->run($outputMock); $this->assertFalse($this->jobList->has('OC\Cache\FileGlobalGC', null), 'Asserting that the job OC\Cache\FileGlobalGC does not exist after repairing'); $this->assertFalse($this->jobList->has('OC_Cache_FileGlobalGC', null), 'Asserting that the job OC_Cache_FileGlobalGC does not exist after repairing'); diff --git a/tests/lib/repair/dropoldtables.php b/tests/lib/repair/dropoldtables.php index 6ece8cf04d5..d2e1d7c3449 100644 --- a/tests/lib/repair/dropoldtables.php +++ b/tests/lib/repair/dropoldtables.php @@ -7,6 +7,7 @@ */ namespace Test\Repair; +use OCP\Migration\IOutput; /** * Tests for the dropping old tables @@ -31,8 +32,13 @@ class DropOldTables extends \Test\TestCase { $this->assertFalse($this->connection->tableExists('sharing'), 'Asserting that the table oc_sharing does not exist before repairing'); $this->assertTrue($this->connection->tableExists('permissions'), 'Asserting that the table oc_permissions does exist before repairing'); + /** @var IOutput | \PHPUnit_Framework_MockObject_MockObject $outputMock */ + $outputMock = $this->getMockBuilder('\OCP\Migration\IOutput') + ->disableOriginalConstructor() + ->getMock(); + $repair = new \OC\Repair\DropOldTables($this->connection); - $repair->run(); + $repair->run($outputMock); $this->assertFalse($this->connection->tableExists('sharing'), 'Asserting that the table oc_sharing does not exist after repairing'); $this->assertFalse($this->connection->tableExists('permissions'), 'Asserting that the table oc_permissions does not exist after repairing'); diff --git a/tests/lib/repair/oldgroupmembershipsharestest.php b/tests/lib/repair/oldgroupmembershipsharestest.php index f02babab21d..cc04a80eef9 100644 --- a/tests/lib/repair/oldgroupmembershipsharestest.php +++ b/tests/lib/repair/oldgroupmembershipsharestest.php @@ -10,6 +10,7 @@ namespace Test\Repair; use OC\Repair\OldGroupMembershipShares; use OC\Share\Constants; +use OCP\Migration\IOutput; /** * Class OldGroupMembershipSharesTest @@ -82,7 +83,12 @@ class OldGroupMembershipSharesTest extends \Test\TestCase { $this->assertEquals([['id' => $parent], ['id' => $group2], ['id' => $user1], ['id' => $member], ['id' => $notAMember]], $rows); $result->closeCursor(); - $repair->run(); + /** @var IOutput | \PHPUnit_Framework_MockObject_MockObject $outputMock */ + $outputMock = $this->getMockBuilder('\OCP\Migration\IOutput') + ->disableOriginalConstructor() + ->getMock(); + + $repair->run($outputMock); $query = $this->connection->getQueryBuilder(); $result = $query->select('id') diff --git a/tests/lib/repair/removegetetagentriestest.php b/tests/lib/repair/removegetetagentriestest.php index 12f0ae8a8d6..c00923228d0 100644 --- a/tests/lib/repair/removegetetagentriestest.php +++ b/tests/lib/repair/removegetetagentriestest.php @@ -22,6 +22,7 @@ namespace Test\Repair; use OC\Repair\RemoveGetETagEntries; +use OCP\Migration\IOutput; use Test\TestCase; /** @@ -65,9 +66,14 @@ class RemoveGetETagEntriesTest extends TestCase { $this->assertTrue(in_array($entry, $data), 'Asserts that the entries are the ones from the test data set'); } + /** @var IOutput | \PHPUnit_Framework_MockObject_MockObject $outputMock */ + $outputMock = $this->getMockBuilder('\OCP\Migration\IOutput') + ->disableOriginalConstructor() + ->getMock(); + // run repair step $repair = new RemoveGetETagEntries($this->connection); - $repair->run(); + $repair->run($outputMock); // check if test data is correctly modified in DB $stmt = $this->connection->executeQuery($sqlToFetchProperties, [$userName]); diff --git a/tests/lib/repair/repaircollation.php b/tests/lib/repair/repaircollation.php index 8d609aeed38..4efa8ccc552 100644 --- a/tests/lib/repair/repaircollation.php +++ b/tests/lib/repair/repaircollation.php @@ -1,4 +1,6 @@ <?php +use OCP\Migration\IOutput; + /** * Copyright (c) 2014 Thomas Müller <deepdiver@owncloud.com> * This file is licensed under the Affero General Public License version 3 or @@ -70,7 +72,12 @@ class TestRepairCollation extends \Test\TestCase { $tables = $this->repair->getAllNonUTF8BinTables($this->connection); $this->assertGreaterThanOrEqual(1, count($tables)); - $this->repair->run(); + /** @var IOutput | \PHPUnit_Framework_MockObject_MockObject $outputMock */ + $outputMock = $this->getMockBuilder('\OCP\Migration\IOutput') + ->disableOriginalConstructor() + ->getMock(); + + $this->repair->run($outputMock); $tables = $this->repair->getAllNonUTF8BinTables($this->connection); $this->assertCount(0, $tables); diff --git a/tests/lib/repair/repairinnodb.php b/tests/lib/repair/repairinnodb.php index 5c73b931367..9b02bc46e29 100644 --- a/tests/lib/repair/repairinnodb.php +++ b/tests/lib/repair/repairinnodb.php @@ -6,6 +6,8 @@ * See the COPYING-README file. */ namespace Test\Repair; +use OCP\Migration\IOutput; +use OCP\Migration\IRepairStep; /** * Tests for the converting of MySQL tables to InnoDB engine @@ -16,7 +18,7 @@ namespace Test\Repair; */ class RepairInnoDB extends \Test\TestCase { - /** @var \OC\RepairStep */ + /** @var IRepairStep */ private $repair; /** @var \Doctrine\DBAL\Connection */ @@ -49,7 +51,12 @@ class RepairInnoDB extends \Test\TestCase { $result = $this->countMyIsamTables(); $this->assertEquals(1, $result); - $this->repair->run(); + /** @var IOutput | \PHPUnit_Framework_MockObject_MockObject $outputMock */ + $outputMock = $this->getMockBuilder('\OCP\Migration\IOutput') + ->disableOriginalConstructor() + ->getMock(); + + $this->repair->run($outputMock); $result = $this->countMyIsamTables(); $this->assertEquals(0, $result); diff --git a/tests/lib/repair/repairinvalidsharestest.php b/tests/lib/repair/repairinvalidsharestest.php index 9655e0eacbc..a1e871bcc80 100644 --- a/tests/lib/repair/repairinvalidsharestest.php +++ b/tests/lib/repair/repairinvalidsharestest.php @@ -11,6 +11,8 @@ namespace Test\Repair; use OC\Repair\RepairInvalidShares; use OC\Share\Constants; +use OCP\Migration\IOutput; +use OCP\Migration\IRepairStep; use Test\TestCase; /** @@ -22,7 +24,7 @@ use Test\TestCase; */ class RepairInvalidSharesTest extends TestCase { - /** @var \OC\RepairStep */ + /** @var IRepairStep */ private $repair; /** @var \OCP\IDBConnection */ @@ -98,7 +100,12 @@ class RepairInvalidSharesTest extends TestCase { 'token' => $qb->expr()->literal('abcdefg') ])->execute(); - $this->repair->run(); + /** @var IOutput | \PHPUnit_Framework_MockObject_MockObject $outputMock */ + $outputMock = $this->getMockBuilder('\OCP\Migration\IOutput') + ->disableOriginalConstructor() + ->getMock(); + + $this->repair->run($outputMock); $results = $this->connection->getQueryBuilder() ->select('*') @@ -167,7 +174,12 @@ class RepairInvalidSharesTest extends TestCase { $this->assertEquals([['id' => $parent], ['id' => $validChild], ['id' => $invalidChild]], $rows); $result->closeCursor(); - $this->repair->run(); + /** @var IOutput | \PHPUnit_Framework_MockObject_MockObject $outputMock */ + $outputMock = $this->getMockBuilder('\OCP\Migration\IOutput') + ->disableOriginalConstructor() + ->getMock(); + + $this->repair->run($outputMock); $query = $this->connection->getQueryBuilder(); $result = $query->select('id') diff --git a/tests/lib/repair/repairlegacystorage.php b/tests/lib/repair/repairlegacystorage.php index 3ae6578f7ec..5b560458e76 100644 --- a/tests/lib/repair/repairlegacystorage.php +++ b/tests/lib/repair/repairlegacystorage.php @@ -10,6 +10,8 @@ namespace Test\Repair; use OC\Files\Cache\Cache; use OC\Files\Cache\Storage; +use OCP\Migration\IOutput; +use PHPUnit_Framework_MockObject_MockObject; use Test\TestCase; /** @@ -34,7 +36,8 @@ class RepairLegacyStorages extends TestCase { private $legacyStorageId; private $newStorageId; - private $warnings; + /** @var IOutput | PHPUnit_Framework_MockObject_MockObject */ + private $outputMock; protected function setUp() { parent::setUp(); @@ -45,11 +48,9 @@ class RepairLegacyStorages extends TestCase { $this->repair = new \OC\Repair\RepairLegacyStorages($this->config, $this->connection); - $this->warnings = []; - - $this->repair->listen('\OC\Repair', 'warning', function ($description){ - $this->warnings[] = $description; - }); + $this->outputMock = $this->getMockBuilder('\OCP\Migration\IOutput') + ->disableOriginalConstructor() + ->getMock(); } protected function tearDown() { @@ -141,7 +142,7 @@ class RepairLegacyStorages extends TestCase { $this->prepareSettings($dataDir, $userId); $newStorageNumId = $this->createStorage($this->newStorageId); - $this->repair->run(); + $this->repair->run($this->outputMock); $this->assertNull($this->getStorageId($this->legacyStorageId)); $this->assertEquals($newStorageNumId, $this->getStorageId($this->newStorageId)); @@ -160,7 +161,7 @@ class RepairLegacyStorages extends TestCase { $this->prepareSettings($dataDir, $userId); $legacyStorageNumId = $this->createStorage($this->legacyStorageId); - $this->repair->run(); + $this->repair->run($this->outputMock); $this->assertNull($this->getStorageId($this->legacyStorageId)); $this->assertEquals($legacyStorageNumId, $this->getStorageId($this->newStorageId)); @@ -182,7 +183,7 @@ class RepairLegacyStorages extends TestCase { $this->createData($this->legacyStorageId); - $this->repair->run(); + $this->repair->run($this->outputMock); $this->assertNull($this->getStorageId($this->legacyStorageId)); $this->assertEquals($legacyStorageNumId, $this->getStorageId($this->newStorageId)); @@ -205,7 +206,7 @@ class RepairLegacyStorages extends TestCase { $this->createData($this->newStorageId); - $this->repair->run(); + $this->repair->run($this->outputMock); $this->assertNull($this->getStorageId($this->legacyStorageId)); $this->assertEquals($newStorageNumId, $this->getStorageId($this->newStorageId)); @@ -228,10 +229,8 @@ class RepairLegacyStorages extends TestCase { $this->createData($this->legacyStorageId); $this->createData($this->newStorageId); - $this->repair->run(); - - $this->assertEquals(2, count($this->warnings)); - $this->assertEquals('Could not repair legacy storage ', substr(current($this->warnings), 0, 32)); + $this->outputMock->expects($this->exactly(2))->method('warning'); + $this->repair->run($this->outputMock); // storages left alone $this->assertEquals($legacyStorageNumId, $this->getStorageId($this->legacyStorageId)); @@ -254,7 +253,7 @@ class RepairLegacyStorages extends TestCase { $storageId = 'local::' . $this->dataDir; $numId = $this->createStorage($storageId); - $this->repair->run(); + $this->repair->run($this->outputMock); $this->assertEquals($numId, $this->getStorageId($storageId)); } @@ -272,7 +271,7 @@ class RepairLegacyStorages extends TestCase { $storageId = 'local::/tmp/somedir/' . $this->user; $numId = $this->createStorage($storageId); - $this->repair->run(); + $this->repair->run($this->outputMock); $this->assertEquals($numId, $this->getStorageId($storageId)); } @@ -290,7 +289,7 @@ class RepairLegacyStorages extends TestCase { $storageId = 'smb::user@password/tmp/somedir/' . $this->user; $numId = $this->createStorage($storageId); - $this->repair->run(); + $this->repair->run($this->outputMock); $this->assertEquals($numId, $this->getStorageId($storageId)); } @@ -322,21 +321,15 @@ class RepairLegacyStorages extends TestCase { * Only run the repair once */ public function testOnlyRunOnce() { - $output = array(); - $this->repair->listen('\OC\Repair', 'info', function ($description) use (&$output) { - $output[] = 'info: ' . $description; - }); + $this->outputMock->expects($this->exactly(1))->method('info'); $this->prepareSettings('/tmp/oc-autotest/datadir', $this->getUniqueID('user_')); $this->assertNotEquals('yes', $this->config->getAppValue('core', 'repairlegacystoragesdone')); - $this->repair->run(); - $this->assertEquals(1, count($output)); + $this->repair->run($this->outputMock); $this->assertEquals('yes', $this->config->getAppValue('core', 'repairlegacystoragesdone')); - $output = array(); - $this->repair->run(); - // no output which means it did not run - $this->assertEquals(0, count($output)); + $this->outputMock->expects($this->never())->method('info'); + $this->repair->run($this->outputMock); $this->assertEquals('yes', $this->config->getAppValue('core', 'repairlegacystoragesdone')); } } diff --git a/tests/lib/repair/repairmimetypes.php b/tests/lib/repair/repairmimetypes.php index a9ebb7bc88a..d8ef95e9546 100644 --- a/tests/lib/repair/repairmimetypes.php +++ b/tests/lib/repair/repairmimetypes.php @@ -8,6 +8,12 @@ */ namespace Test\Repair; +use OC\Files\Storage\Temporary; +use OCP\Files\IMimeTypeLoader; +use OCP\IConfig; +use OCP\Migration\IOutput; +use OCP\Migration\IRepairStep; + /** * Tests for the converting of legacy storages to home storages. * @@ -17,17 +23,22 @@ namespace Test\Repair; */ class RepairMimeTypes extends \Test\TestCase { - /** @var \OC\RepairStep */ + /** @var IRepairStep */ private $repair; + /** @var Temporary */ private $storage; + /** @var IMimeTypeLoader */ + private $mimetypeLoader; + protected function setUp() { parent::setUp(); $this->savedMimetypeLoader = \OC::$server->getMimeTypeLoader(); $this->mimetypeLoader = \OC::$server->getMimeTypeLoader(); + /** @var IConfig | \PHPUnit_Framework_MockObject_MockObject $config */ $config = $this->getMockBuilder('OCP\IConfig') ->disableOriginalConstructor() ->getMock(); @@ -96,7 +107,12 @@ class RepairMimeTypes extends \Test\TestCase { private function renameMimeTypes($currentMimeTypes, $fixedMimeTypes) { $this->addEntries($currentMimeTypes); - $this->repair->run(); + /** @var IOutput | \PHPUnit_Framework_MockObject_MockObject $outputMock */ + $outputMock = $this->getMockBuilder('\OCP\Migration\IOutput') + ->disableOriginalConstructor() + ->getMock(); + + $this->repair->run($outputMock); // force mimetype reload $this->mimetypeLoader->reset(); diff --git a/tests/lib/repair/repairsharepropagation.php b/tests/lib/repair/repairsharepropagation.php index 6ec8b98ec56..34b47397a53 100644 --- a/tests/lib/repair/repairsharepropagation.php +++ b/tests/lib/repair/repairsharepropagation.php @@ -9,6 +9,7 @@ namespace Test\Repair; use OC\Repair\SharePropagation; +use OCP\Migration\IOutput; class RepairSharePropagation extends \Test\TestCase { public function keyProvider() { @@ -40,8 +41,13 @@ class RepairSharePropagation extends \Test\TestCase { $removedKeys[] = $key; })); + /** @var IOutput | \PHPUnit_Framework_MockObject_MockObject $outputMock */ + $outputMock = $this->getMockBuilder('\OCP\Migration\IOutput') + ->disableOriginalConstructor() + ->getMock(); + $step = new SharePropagation($config); - $step->run(); + $step->run($outputMock); sort($expectedRemovedKeys); sort($removedKeys); diff --git a/tests/lib/repair/repairsqliteautoincrement.php b/tests/lib/repair/repairsqliteautoincrement.php index 6f0c2cb8d28..581857ebfc9 100644 --- a/tests/lib/repair/repairsqliteautoincrement.php +++ b/tests/lib/repair/repairsqliteautoincrement.php @@ -7,6 +7,7 @@ */ namespace Test\Repair; +use OCP\Migration\IOutput; /** * Tests for fixing the SQLite id recycling @@ -76,7 +77,12 @@ class RepairSqliteAutoincrement extends \Test\TestCase { public function testConvertIdColumn() { $this->assertFalse($this->checkAutoincrement()); - $this->repair->run(); + /** @var IOutput | \PHPUnit_Framework_MockObject_MockObject $outputMock */ + $outputMock = $this->getMockBuilder('\OCP\Migration\IOutput') + ->disableOriginalConstructor() + ->getMock(); + + $this->repair->run($outputMock); $this->assertTrue($this->checkAutoincrement()); } diff --git a/tests/lib/repair/updateoutdatedocsids.php b/tests/lib/repair/updateoutdatedocsids.php index 3669a64371f..06e2cb1d610 100644 --- a/tests/lib/repair/updateoutdatedocsids.php +++ b/tests/lib/repair/updateoutdatedocsids.php @@ -30,7 +30,7 @@ use Test\TestCase; * @package Test\Repair */ class UpdateOutdatedOcsIds extends TestCase { - /** @var IConfig */ + /** @var IConfig | \PHPUnit_Framework_MockObject_MockObject */ private $config; /** @var \OC\Repair\UpdateOutdatedOcsIds */ private $updateOutdatedOcsIds; |