public function postUp()
 {
     $conn = Doctrine_Manager::connection();
     $conn->export->createForeignKey('community', array('name' => 'community_FK_2', 'local' => 'community_category_id', 'foreign' => 'id', 'foreignTable' => 'community_category', 'onDelete' => 'SET NULL'));
     $conn->export->createIndex('community_category', 'community_category_I_1', array('fields' => array('lft_key' => array())));
     $conn->export->createIndex('community_category', 'community_category_I_2', array('fields' => array('rht_key' => array())));
     $conn->export->createIndex('community_category', 'community_category_I_3', array('fields' => array('tree_key' => array())));
     $category = new CommunityCategory();
     $category->setName('コミュニティカテゴリ');
     $category->setIsAllowMemberCommunity(true);
     $category->save();
     $treeKey = $category->getId();
     $child = new CommunityCategory();
     $child->setName('地域');
     $child->setTreeKey($treeKey);
     $child->setIsAllowMemberCommunity(true);
     $child->save();
     $child = new CommunityCategory();
     $child->setName('グルメ');
     $child->setTreeKey($treeKey);
     $child->setIsAllowMemberCommunity(true);
     $child->save();
     $child = new CommunityCategory();
     $child->setName('スポーツ');
     $child->setTreeKey($treeKey);
     $child->setIsAllowMemberCommunity(true);
     $child->save();
 }
Exemplo n.º 2
0
include_once dirname(__FILE__) . '/../../../bootstrap/unit.php';
include_once dirname(__FILE__) . '/../../../bootstrap/database.php';
$t = new lime_test(9, 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');
//------------------------------------------------------------
$t->diag('CommunityCategory::getChildren()');
$t->isa_ok($communityCategory1->getChildren(), 'Doctrine_Collection');
$t->is(count($communityCategory1->getChildren()), 0);
$communityCategory = Doctrine::getTable('CommunityCategory')->find(1);
$category = $communityCategory->getChildren();
$t->is(count($category), 2);
$t->is($category[0]->getName(), 'CategoryB');