Skip to content

Commit

Permalink
added test of CommunityCategory (refs openpne#221)
Browse files Browse the repository at this point in the history
  • Loading branch information
kawahara committed Nov 23, 2009
1 parent 8fb9fe9 commit 45a399e
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/model/doctrine/CommunityCategoryTable.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@

class CommunityCategoryTable extends Doctrine_Table
{
//TODO: use findAll()
public function retrieveAll()
{
return $this->createQuery()->execute();
}

//TODO: use getTree()->fetchRoots()
public function retrieveAllRoots()
{
return $this->createQuery()
Expand Down
10 changes: 10 additions & 0 deletions test/fixtures/test_data.yml
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,16 @@ Community:
community_5:
name: "CommunityE"

CommunityCategory:
community_category:
name: "コミュニティカテゴリ"
is_allow_member_community: 1

community_category_1:
name: "CategoryA"
tree_key: 1
is_allow_member_community: 1

CommunityConfig:
community_1_description:
Community: community_1
Expand Down
21 changes: 21 additions & 0 deletions test/unit/model/doctrine/CommunityCategoryTableTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

include_once dirname(__FILE__) . '/../../../bootstrap/unit.php';
include_once dirname(__FILE__) . '/../../../bootstrap/database.php';

$t = new lime_test(3, new lime_output_color());

$table = Doctrine::getTable('CommunityCategory');

//------------------------------------------------------------
$t->diag('CommunityCategoryTable');
$t->diag('CommunityCategoryTable::retrieveAll()');
$t->isa_ok($table->retrieveAll(), 'Doctrine_Collection');

//------------------------------------------------------------
$t->diag('CommunityCategoryTable::retrieveAllRoots()');
$t->isa_ok($table->retrieveAllRoots(), 'Doctrine_Collection');

//------------------------------------------------------------
$t->diag('CommunityCategoryTable::retrieveAllChildren()');
$t->isa_ok($table->retrieveAllChildren(), 'Doctrine_Collection');
30 changes: 30 additions & 0 deletions test/unit/model/doctrine/CommunityCategoryTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

include_once dirname(__FILE__) . '/../../../bootstrap/unit.php';
include_once dirname(__FILE__) . '/../../../bootstrap/database.php';

$t = new lime_test(4, new lime_output_color());

$communityCategory1 = Doctrine::getTable('CommunityCategory')->findOneByName('CategoryA');

//------------------------------------------------------------
$t->diag('CommunityCategory');
$t->diag('CommunityCategory::__toString()');
$t->is((string)$communityCategory1, 'CategoryA');

//------------------------------------------------------------
$t->diag('CommunityCategory::save()');
$newCommunityCategory1 = new CommunityCategory();
$newCommunityCategory1->getName('newParentCategory');
$newCommunityCategory1->save();
$t->is($newCommunityCategory1->getLevel(), 0);

$newCommunityCategory2 = new CommunityCategory();
$newCommunityCategory2->setTreeKey($newCommunityCategory1->getId());
$newCommunityCategory2->getName('newCategory');
$newCommunityCategory2->save();
$t->is($newCommunityCategory2->getLevel(), 1);

//------------------------------------------------------------
$t->diag('CommunityCategory::getForm()');
$t->isa_ok($communityCategory1->getForm(), 'CommunityCategoryForm');

0 comments on commit 45a399e

Please sign in to comment.