From 0715d814b6d362479da279aea623b452b3fa0a85 Mon Sep 17 00:00:00 2001 From: "Timothy J. Warren" Date: Tue, 12 Aug 2014 13:29:49 -0400 Subject: [PATCH] Fix Todo lib tests, and migrations --- README.md | 1 + .../20140808164827_initial_migration.php | 34 +++++++++++++++++++ ...20140811203650_view_creation_migration.php | 9 +++-- tests/libs/TodoLibTest.php | 12 +++---- 4 files changed, 46 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index e69de29..7ea1a38 100644 --- a/README.md +++ b/README.md @@ -0,0 +1 @@ +# Tim's Todo \ No newline at end of file diff --git a/migrations/20140808164827_initial_migration.php b/migrations/20140808164827_initial_migration.php index f7abc61..aa68285 100644 --- a/migrations/20140808164827_initial_migration.php +++ b/migrations/20140808164827_initial_migration.php @@ -43,6 +43,9 @@ class InitialMigration extends AbstractMigration { $this->table('todo_group') ->addColumn('name', 'string', ['limit' => 128]) ->create(); + + // Seed data + $this->execute("INSERT INTO todo_group VALUES (0, 'global');"); } // Category table @@ -54,6 +57,15 @@ class InitialMigration extends AbstractMigration { ->addColumn('group_id', 'integer', ['default' => 0]) ->addForeignKey('group_id', 'todo_group', 'id') ->create(); + + // Seed the data + $this->execute(" + INSERT INTO todo_category VALUES (1, 'Work', 'Tasks related to work', 0); + INSERT INTO todo_category VALUES (7, 'Optional ', 'Tasks that are not necessary, but it would be nice to see them completed.', 0); + INSERT INTO todo_category VALUES (10, 'School', 'School related tasks', 0); + INSERT INTO todo_category VALUES (11, 'Other', 'Tasks that don''t fit in another category.', 0); + INSERT INTO todo_category VALUES (13, 'Personal', 'Personal tasks to do', 0); + "); } // Priority list table @@ -62,6 +74,19 @@ class InitialMigration extends AbstractMigration { $this->table('todo_priority') ->addColumn('value', 'string') ->create(); + + // Seed the data + $this->execute(" + INSERT INTO todo_priority VALUES (1, 'Optional'); + INSERT INTO todo_priority VALUES (2, 'Lowest'); + INSERT INTO todo_priority VALUES (3, 'Lower'); + INSERT INTO todo_priority VALUES (4, 'Low'); + INSERT INTO todo_priority VALUES (5, 'Normal'); + INSERT INTO todo_priority VALUES (6, 'High'); + INSERT INTO todo_priority VALUES (7, 'Higher'); + INSERT INTO todo_priority VALUES (8, 'Highest'); + INSERT INTO todo_priority VALUES (9, 'Immediate'); + "); } // Status list table @@ -70,6 +95,15 @@ class InitialMigration extends AbstractMigration { $this->table('todo_status') ->addColumn('value', 'string') ->create(); + + // Seed the data + $this->execute(" + INSERT INTO todo_status VALUES (3, 'In Progress'); + INSERT INTO todo_status VALUES (4, 'On Hold'); + INSERT INTO todo_status VALUES (5, 'Canceled'); + INSERT INTO todo_status VALUES (2, 'Completed'); + INSERT INTO todo_status VALUES (1, 'Created'); + "); } // Task table diff --git a/migrations/20140811203650_view_creation_migration.php b/migrations/20140811203650_view_creation_migration.php index 236f1a0..598e035 100644 --- a/migrations/20140811203650_view_creation_migration.php +++ b/migrations/20140811203650_view_creation_migration.php @@ -22,9 +22,12 @@ class ViewCreationMigration extends AbstractMigration */ public function up() { - $this->execute("CREATE VIEW todo_task_view AS - SELECT todo_item.id, todo_item.user_id, todo_item.category_id, todo_item.title, todo_item.due, todo_item.modified, todo_item.created, todo_category.title AS category, todo_priority.value AS priority, todo_status.value AS status, todo_status.id AS status_id FROM (((todo_item LEFT JOIN todo_category ON ((todo_category.id = todo_item.category_id))) LEFT JOIN todo_priority ON ((todo_priority.id = todo_item.priority))) LEFT JOIN todo_status ON ((todo_status.id = todo_item.status))) ORDER BY todo_item.due, todo_item.priority DESC, todo_item.created; - "); + if ( ! $this->hasTable('todo_task_view')) + { + $this->execute("CREATE VIEW todo_task_view AS + SELECT todo_item.id, todo_item.user_id, todo_item.category_id, todo_item.title, todo_item.due, todo_item.modified, todo_item.created, todo_category.title AS category, todo_priority.value AS priority, todo_status.value AS status, todo_status.id AS status_id FROM (((todo_item LEFT JOIN todo_category ON ((todo_category.id = todo_item.category_id))) LEFT JOIN todo_priority ON ((todo_priority.id = todo_item.priority))) LEFT JOIN todo_status ON ((todo_status.id = todo_item.status))) ORDER BY todo_item.due, todo_item.priority DESC, todo_item.created; + "); + } } /** diff --git a/tests/libs/TodoLibTest.php b/tests/libs/TodoLibTest.php index ca34027..9611931 100755 --- a/tests/libs/TodoLibTest.php +++ b/tests/libs/TodoLibTest.php @@ -4,10 +4,10 @@ class TodoLibTest extends Todo_TestCase { protected $tables = [ 'todo_priority' => 'todo_priority', - 'todo_category' => 'todo_category', 'todo_user' => 'todo_user', 'todo_group' => 'todo_group', 'todo_category' => 'todo_category', + 'todo_group_users_link' => 'todo_group_users_link', 'todo_user_friend_link' => 'todo_user_friend_link', ]; @@ -15,7 +15,6 @@ class TodoLibTest extends Todo_TestCase { { parent::setUp(); $this->CI->load->library('todo'); - $this->dbfixt('todo_priority', 'todo_category'); } public function testGetUserFromId() @@ -357,7 +356,7 @@ class TodoLibTest extends Todo_TestCase { [ 'user_id' => 1, 'expected' => [] - ],/*[ + ],[ 'user_id' => 3, 'expected' => [ array ( @@ -365,7 +364,7 @@ class TodoLibTest extends Todo_TestCase { 'name' => 'shared', ), ] - ]*/ + ] ]; } @@ -417,7 +416,6 @@ class TodoLibTest extends Todo_TestCase { public function testGetFriendsInGroup() { -$this->markTestSkipped(); $expected = [ array ( 'user_id' => '7', @@ -547,10 +545,10 @@ $this->markTestSkipped(); public function dataGetGroupSelect() { return [ - /*[ + [ 'user_id' => 3, 'expected' => T4 . '' . NL - ],*/ + ], [ 'user_id' => 1, 'expected' => ''