summaryrefslogtreecommitdiffstats
path: root/tests/Unit/Migration
diff options
context:
space:
mode:
authorDaniel Opitz <danopz@users.noreply.github.com>2017-08-14 10:34:53 +0200
committerBernhard Posselt <BernhardPosselt@users.noreply.github.com>2017-08-14 10:34:53 +0200
commita97dd58e3b499b60ac8b37786d402d7f2e371a88 (patch)
tree98bb8a6c750fb33fbef38d22407fa29fbf6c7b1e /tests/Unit/Migration
parent7d8a85c82c4c13a71b70ddb4ecb8c40ede4c9b70 (diff)
Split binary to booleans (#203)
* replaced old status with 2 flags for unread and starred * add fields to db, replace int(1,0) with booleans in sql queries, removed StatusFlags class + refactor code relying to it * add repair step for migration * again use integer(1,0) instead of bool in sql queries, because of sqlite doesn't support true/false * add/fix unit tests for new boolean status * set unread/starred flags as statements in sql * fixed mysql unknown column items.unread, fixed marking of read items on repair step * remove unnecessary bool casts * add empty checks to Items::is* methods * update migration to use native sql instead of the querybuilder * don't cast the flags manually, let the api do the work
Diffstat (limited to 'tests/Unit/Migration')
-rw-r--r--tests/Unit/Migration/MigrateStatusFlagsTest.php99
1 files changed, 99 insertions, 0 deletions
diff --git a/tests/Unit/Migration/MigrateStatusFlagsTest.php b/tests/Unit/Migration/MigrateStatusFlagsTest.php
new file mode 100644
index 000000000..bee3532c1
--- /dev/null
+++ b/tests/Unit/Migration/MigrateStatusFlagsTest.php
@@ -0,0 +1,99 @@
+<?php
+/**
+ * Nextcloud - News
+ *
+ * This file is licensed under the Affero General Public License version 3 or
+ * later. See the COPYING file.
+ *
+ * @author Daniel Opitz <dev@copynpaste.de>
+ * @copyright Daniel Opitz 2017
+ */
+
+namespace OCA\News\Migration;
+
+use Doctrine\DBAL\Driver\Statement;
+use OCP\IConfig;
+use OCP\IDBConnection;
+use OCP\Migration\IOutput;
+use Test\TestCase;
+
+class MigrateStatusFlagsTest extends TestCase {
+
+ /** @var IDBConnection|\PHPUnit_Framework_MockObject_MockObject */
+ protected $db;
+ /** @var IConfig|\PHPUnit_Framework_MockObject_MockObject */
+ protected $config;
+ /** @var IOutput|\PHPUnit_Framework_MockObject_MockObject */
+ protected $output;
+
+ protected function setUp() {
+ $this->db = $this->createMock(IDBConnection::class);
+ $this->config = $this->createMock(IConfig::class);
+ $this->output = $this->createMock(IOutput::class);
+ }
+
+ public function testRun() {
+ $statement = $this->createMock(Statement::class);
+ $statement->expects($this->exactly(1))
+ ->method('execute')
+ ->with()
+ ->willReturn(true);
+
+ $this->config->expects($this->exactly(1))
+ ->method('getAppValue')
+ ->with('news', 'installed_version', '0.0.0')
+ ->willReturn('11.0.5');
+
+ $sql = 'UPDATE `*PREFIX*news_items` '
+ . 'SET `unread` = ((`status` & 2) = 2), '
+ . '`starred` = ((`status` & 4) = 4)';
+
+ $this->db->expects($this->exactly(1))
+ ->method('prepare')
+ ->with($sql)
+ ->willReturn($statement);
+
+ $migration = new MigrateStatusFlags($this->db, $this->config);
+ $migration->run($this->output);
+ }
+
+ /**
+ * @expectedException \Exception
+ */
+ public function testRunException() {
+ $statement = $this->createMock(Statement::class);
+ $statement->expects($this->exactly(1))
+ ->method('execute')
+ ->with()
+ ->willReturn(false);
+
+ $this->config->expects($this->exactly(1))
+ ->method('getAppValue')
+ ->with('news', 'installed_version', '0.0.0')
+ ->willReturn('11.0.5');
+
+ $sql = 'UPDATE `*PREFIX*news_items` '
+ . 'SET `unread` = ((`status` & 2) = 2), '
+ . '`starred` = ((`status` & 4) = 4)';
+
+ $this->db->expects($this->exactly(1))
+ ->method('prepare')
+ ->with($sql)
+ ->willReturn($statement);
+
+ $migration = new MigrateStatusFlags($this->db, $this->config);
+ $migration->run($this->output);
+ }
+
+ public function testRunNewerVersion() {
+ $this->config->expects($this->exactly(1))
+ ->method('getAppValue')
+ ->with('news', 'installed_version', '0.0.0')
+ ->willReturn('11.1.0');
+ $this->db->expects($this->exactly(0))
+ ->method('prepare');
+
+ $migration = new MigrateStatusFlags($this->db, $this->config);
+ $migration->run($this->output);
+ }
+} \ No newline at end of file