From faef2e85d191a940782aed2f3142f79c20fab96c Mon Sep 17 00:00:00 2001 From: Frederic Guillot Date: Fri, 2 Dec 2016 20:49:30 -0500 Subject: Fix field too small for application settings --- ChangeLog | 1 + app/Schema/Mysql.php | 7 +- app/Schema/Postgres.php | 7 +- tests/units/Model/ConfigModelTest.php | 125 ++++++++++++++++++++++++++++++++++ tests/units/Model/ConfigTest.php | 116 ------------------------------- 5 files changed, 138 insertions(+), 118 deletions(-) create mode 100644 tests/units/Model/ConfigModelTest.php delete mode 100644 tests/units/Model/ConfigTest.php diff --git a/ChangeLog b/ChangeLog index b218dbd3..d67d8e02 100644 --- a/ChangeLog +++ b/ChangeLog @@ -15,6 +15,7 @@ Breaking changes: Bug fixes: +* Change column type for application settings value (field too small) * Fix link generation when user mention is followed by a punctuation mark * Make user mentions works again diff --git a/app/Schema/Mysql.php b/app/Schema/Mysql.php index b50164ca..17285b12 100644 --- a/app/Schema/Mysql.php +++ b/app/Schema/Mysql.php @@ -6,7 +6,12 @@ use PDO; use Kanboard\Core\Security\Token; use Kanboard\Core\Security\Role; -const VERSION = 116; +const VERSION = 117; + +function version_117(PDO $pdo) +{ + $pdo->exec("ALTER TABLE `settings` MODIFY `value` TEXT"); +} function version_116(PDO $pdo) { diff --git a/app/Schema/Postgres.php b/app/Schema/Postgres.php index 83926f19..082c31eb 100644 --- a/app/Schema/Postgres.php +++ b/app/Schema/Postgres.php @@ -6,7 +6,12 @@ use PDO; use Kanboard\Core\Security\Token; use Kanboard\Core\Security\Role; -const VERSION = 95; +const VERSION = 96; + +function version_96(PDO $pdo) +{ + $pdo->exec('ALTER TABLE "settings" ALTER COLUMN "value" TYPE TEXT'); +} function version_95(PDO $pdo) { diff --git a/tests/units/Model/ConfigModelTest.php b/tests/units/Model/ConfigModelTest.php new file mode 100644 index 00000000..bbc792e3 --- /dev/null +++ b/tests/units/Model/ConfigModelTest.php @@ -0,0 +1,125 @@ +container); + $token = $configModel->getOption('api_token'); + $this->assertTrue($configModel->regenerateToken('api_token')); + $this->assertNotEquals($token, $configModel->getOption('api_token')); + } + + public function testCRUDOperations() + { + $configModel = new ConfigModel($this->container); + + $this->assertTrue($configModel->save(array('key1' => 'value1'))); + $this->assertTrue($configModel->save(array('key1' => 'value2'))); + $this->assertTrue($configModel->save(array('key2' => 'value2'))); + + $this->assertEquals('value2', $configModel->getOption('key1')); + $this->assertEquals('value2', $configModel->getOption('key2')); + $this->assertEquals('', $configModel->getOption('key3')); + $this->assertEquals('default', $configModel->getOption('key3', 'default')); + + $this->assertTrue($configModel->exists('key1')); + $this->assertFalse($configModel->exists('key3')); + + $this->assertTrue($configModel->save(array('key1' => 'value1'))); + + $this->assertArrayHasKey('key1', $configModel->getAll()); + $this->assertArrayHasKey('key2', $configModel->getAll()); + + $this->assertContains('value1', $configModel->getAll()); + $this->assertContains('value2', $configModel->getAll()); + } + + public function testSaveApplicationUrl() + { + $configModel = new ConfigModel($this->container); + + $this->assertTrue($configModel->save(array('application_url' => 'http://localhost/'))); + $this->assertEquals('http://localhost/', $configModel->getOption('application_url')); + + $this->assertTrue($configModel->save(array('application_url' => 'http://localhost'))); + $this->assertEquals('http://localhost/', $configModel->getOption('application_url')); + + $this->assertTrue($configModel->save(array('application_url' => ''))); + $this->assertEquals('', $configModel->getOption('application_url')); + } + + public function testDefaultValues() + { + $configModel = new ConfigModel($this->container); + + $this->assertEquals(172800, $configModel->getOption('board_highlight_period')); + $this->assertEquals(60, $configModel->getOption('board_public_refresh_interval')); + $this->assertEquals(10, $configModel->getOption('board_private_refresh_interval')); + $this->assertEmpty($configModel->getOption('board_columns')); + + $this->assertEquals('yellow', $configModel->getOption('default_color')); + $this->assertEquals('en_US', $configModel->getOption('application_language')); + $this->assertEquals('UTC', $configModel->getOption('application_timezone')); + $this->assertEquals('m/d/Y', $configModel->getOption('application_date_format')); + $this->assertEmpty($configModel->getOption('application_url')); + $this->assertEmpty($configModel->getOption('application_stylesheet')); + $this->assertEquals('USD', $configModel->getOption('application_currency')); + + $this->assertEquals(0, $configModel->getOption('calendar_user_subtasks_time_tracking')); + $this->assertEquals('date_started', $configModel->getOption('calendar_user_tasks')); + $this->assertEquals('date_started', $configModel->getOption('calendar_user_tasks')); + + $this->assertEquals(0, $configModel->getOption('integration_gravatar')); + $this->assertEquals(1, $configModel->getOption('cfd_include_closed_tasks')); + $this->assertEquals(1, $configModel->getOption('password_reset')); + + $this->assertEquals(1, $configModel->getOption('subtask_time_tracking')); + $this->assertEquals(0, $configModel->getOption('subtask_restriction')); + $this->assertEmpty($configModel->getOption('project_categories')); + + $this->assertEmpty($configModel->getOption('webhook_url_task_modification')); + $this->assertEmpty($configModel->getOption('webhook_url_task_creation')); + $this->assertNotEmpty($configModel->getOption('webhook_token')); + $this->assertEmpty($configModel->getOption('webhook_url')); + + $this->assertNotEmpty($configModel->getOption('api_token')); + } + + public function testGetOption() + { + $configModel = new ConfigModel($this->container); + + $this->assertEquals('', $configModel->getOption('board_columns')); + $this->assertEquals('test', $configModel->getOption('board_columns', 'test')); + $this->assertEquals(0, $configModel->getOption('board_columns', 0)); + } + + public function testGetWithCaching() + { + $configModel = new ConfigModel($this->container); + + $this->assertEquals('UTC', $configModel->get('application_timezone')); + $this->assertTrue($configModel->save(array('application_timezone' => 'Europe/Paris'))); + + $this->assertEquals('UTC', $configModel->get('application_timezone')); // cached value + $this->assertEquals('Europe/Paris', $configModel->getOption('application_timezone')); + + $this->assertEquals('', $configModel->get('board_columns')); + $this->assertEquals('test', $configModel->get('board_columns', 'test')); + $this->assertEquals('test', $configModel->get('empty_value', 'test')); + } + + public function testValueLength() + { + $configModel = new ConfigModel($this->container); + $string = str_repeat('a', 65535); + + $this->assertTrue($configModel->save(array('application_stylesheet' => $string))); + $this->assertSame($string, $configModel->getOption('application_stylesheet')); + } +} diff --git a/tests/units/Model/ConfigTest.php b/tests/units/Model/ConfigTest.php deleted file mode 100644 index 3345ee3e..00000000 --- a/tests/units/Model/ConfigTest.php +++ /dev/null @@ -1,116 +0,0 @@ -container); - $token = $configModel->getOption('api_token'); - $this->assertTrue($configModel->regenerateToken('api_token')); - $this->assertNotEquals($token, $configModel->getOption('api_token')); - } - - public function testCRUDOperations() - { - $c = new ConfigModel($this->container); - - $this->assertTrue($c->save(array('key1' => 'value1'))); - $this->assertTrue($c->save(array('key1' => 'value2'))); - $this->assertTrue($c->save(array('key2' => 'value2'))); - - $this->assertEquals('value2', $c->getOption('key1')); - $this->assertEquals('value2', $c->getOption('key2')); - $this->assertEquals('', $c->getOption('key3')); - $this->assertEquals('default', $c->getOption('key3', 'default')); - - $this->assertTrue($c->exists('key1')); - $this->assertFalse($c->exists('key3')); - - $this->assertTrue($c->save(array('key1' => 'value1'))); - - $this->assertArrayHasKey('key1', $c->getAll()); - $this->assertArrayHasKey('key2', $c->getAll()); - - $this->assertContains('value1', $c->getAll()); - $this->assertContains('value2', $c->getAll()); - } - - public function testSaveApplicationUrl() - { - $c = new ConfigModel($this->container); - - $this->assertTrue($c->save(array('application_url' => 'http://localhost/'))); - $this->assertEquals('http://localhost/', $c->getOption('application_url')); - - $this->assertTrue($c->save(array('application_url' => 'http://localhost'))); - $this->assertEquals('http://localhost/', $c->getOption('application_url')); - - $this->assertTrue($c->save(array('application_url' => ''))); - $this->assertEquals('', $c->getOption('application_url')); - } - - public function testDefaultValues() - { - $c = new ConfigModel($this->container); - - $this->assertEquals(172800, $c->getOption('board_highlight_period')); - $this->assertEquals(60, $c->getOption('board_public_refresh_interval')); - $this->assertEquals(10, $c->getOption('board_private_refresh_interval')); - $this->assertEmpty($c->getOption('board_columns')); - - $this->assertEquals('yellow', $c->getOption('default_color')); - $this->assertEquals('en_US', $c->getOption('application_language')); - $this->assertEquals('UTC', $c->getOption('application_timezone')); - $this->assertEquals('m/d/Y', $c->getOption('application_date_format')); - $this->assertEmpty($c->getOption('application_url')); - $this->assertEmpty($c->getOption('application_stylesheet')); - $this->assertEquals('USD', $c->getOption('application_currency')); - - $this->assertEquals(0, $c->getOption('calendar_user_subtasks_time_tracking')); - $this->assertEquals('date_started', $c->getOption('calendar_user_tasks')); - $this->assertEquals('date_started', $c->getOption('calendar_user_tasks')); - - $this->assertEquals(0, $c->getOption('integration_gravatar')); - $this->assertEquals(1, $c->getOption('cfd_include_closed_tasks')); - $this->assertEquals(1, $c->getOption('password_reset')); - - $this->assertEquals(1, $c->getOption('subtask_time_tracking')); - $this->assertEquals(0, $c->getOption('subtask_restriction')); - $this->assertEmpty($c->getOption('project_categories')); - - $this->assertEmpty($c->getOption('webhook_url_task_modification')); - $this->assertEmpty($c->getOption('webhook_url_task_creation')); - $this->assertNotEmpty($c->getOption('webhook_token')); - $this->assertEmpty($c->getOption('webhook_url')); - - $this->assertNotEmpty($c->getOption('api_token')); - } - - public function testGetOption() - { - $c = new ConfigModel($this->container); - - $this->assertEquals('', $c->getOption('board_columns')); - $this->assertEquals('test', $c->getOption('board_columns', 'test')); - $this->assertEquals(0, $c->getOption('board_columns', 0)); - } - - public function testGetWithCaching() - { - $c = new ConfigModel($this->container); - - $this->assertEquals('UTC', $c->get('application_timezone')); - $this->assertTrue($c->save(array('application_timezone' => 'Europe/Paris'))); - - $this->assertEquals('UTC', $c->get('application_timezone')); // cached value - $this->assertEquals('Europe/Paris', $c->getOption('application_timezone')); - - $this->assertEquals('', $c->get('board_columns')); - $this->assertEquals('test', $c->get('board_columns', 'test')); - $this->assertEquals('test', $c->get('empty_value', 'test')); - } -} -- cgit v1.2.3