Fix Todo lib tests, and migrations

This commit is contained in:
Timothy Warren 2014-08-12 13:29:49 -04:00
parent be3623eb49
commit 0715d814b6
4 changed files with 46 additions and 10 deletions

View File

@ -0,0 +1 @@
# Tim's Todo

View File

@ -43,6 +43,9 @@ class InitialMigration extends AbstractMigration {
$this->table('todo_group') $this->table('todo_group')
->addColumn('name', 'string', ['limit' => 128]) ->addColumn('name', 'string', ['limit' => 128])
->create(); ->create();
// Seed data
$this->execute("INSERT INTO todo_group VALUES (0, 'global');");
} }
// Category table // Category table
@ -54,6 +57,15 @@ class InitialMigration extends AbstractMigration {
->addColumn('group_id', 'integer', ['default' => 0]) ->addColumn('group_id', 'integer', ['default' => 0])
->addForeignKey('group_id', 'todo_group', 'id') ->addForeignKey('group_id', 'todo_group', 'id')
->create(); ->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 // Priority list table
@ -62,6 +74,19 @@ class InitialMigration extends AbstractMigration {
$this->table('todo_priority') $this->table('todo_priority')
->addColumn('value', 'string') ->addColumn('value', 'string')
->create(); ->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 // Status list table
@ -70,6 +95,15 @@ class InitialMigration extends AbstractMigration {
$this->table('todo_status') $this->table('todo_status')
->addColumn('value', 'string') ->addColumn('value', 'string')
->create(); ->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 // Task table

View File

@ -22,9 +22,12 @@ class ViewCreationMigration extends AbstractMigration
*/ */
public function up() public function up()
{ {
$this->execute("CREATE VIEW todo_task_view AS if ( ! $this->hasTable('todo_task_view'))
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; {
"); $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;
");
}
} }
/** /**

View File

@ -4,10 +4,10 @@ class TodoLibTest extends Todo_TestCase {
protected $tables = [ protected $tables = [
'todo_priority' => 'todo_priority', 'todo_priority' => 'todo_priority',
'todo_category' => 'todo_category',
'todo_user' => 'todo_user', 'todo_user' => 'todo_user',
'todo_group' => 'todo_group', 'todo_group' => 'todo_group',
'todo_category' => 'todo_category', 'todo_category' => 'todo_category',
'todo_group_users_link' => 'todo_group_users_link',
'todo_user_friend_link' => 'todo_user_friend_link', 'todo_user_friend_link' => 'todo_user_friend_link',
]; ];
@ -15,7 +15,6 @@ class TodoLibTest extends Todo_TestCase {
{ {
parent::setUp(); parent::setUp();
$this->CI->load->library('todo'); $this->CI->load->library('todo');
$this->dbfixt('todo_priority', 'todo_category');
} }
public function testGetUserFromId() public function testGetUserFromId()
@ -357,7 +356,7 @@ class TodoLibTest extends Todo_TestCase {
[ [
'user_id' => 1, 'user_id' => 1,
'expected' => [] 'expected' => []
],/*[ ],[
'user_id' => 3, 'user_id' => 3,
'expected' => [ 'expected' => [
array ( array (
@ -365,7 +364,7 @@ class TodoLibTest extends Todo_TestCase {
'name' => 'shared', 'name' => 'shared',
), ),
] ]
]*/ ]
]; ];
} }
@ -417,7 +416,6 @@ class TodoLibTest extends Todo_TestCase {
public function testGetFriendsInGroup() public function testGetFriendsInGroup()
{ {
$this->markTestSkipped();
$expected = [ $expected = [
array ( array (
'user_id' => '7', 'user_id' => '7',
@ -547,10 +545,10 @@ $this->markTestSkipped();
public function dataGetGroupSelect() public function dataGetGroupSelect()
{ {
return [ return [
/*[ [
'user_id' => 3, 'user_id' => 3,
'expected' => T4 . '<option value="62">shared</option>' . NL 'expected' => T4 . '<option value="62">shared</option>' . NL
],*/ ],
[ [
'user_id' => 1, 'user_id' => 1,
'expected' => '' 'expected' => ''