public function testSetId() { $c = new ae_CategoryModel(); $c->setId(4); $this->assertTrue($c->getId() === 4); $this->setExpectedException('Exception'); $c->setId(-1); }
public function testAddCategory() { $p = new ae_PostModel(); $c1 = new ae_CategoryModel(); $c1->setId(1); $c2 = new ae_CategoryModel(); $c2->setId(2); $p->addCategory($c1); $p->addCategory($c2); $this->assertEquals($p->getCategories(), array($c1, $c2)); }
/** * Assign the loaded category models to their post models. * @param {array} $categories Category models. */ protected function assignCategoriesToPosts($categories) { $id2Post = array(); foreach ($this->items as $item) { $id2Post[$item->getId()] = $item; } foreach ($categories as $row) { $ca = new ae_CategoryModel(); $ca->setId($row['ca_id']); $ca->setTitle($row['ca_title']); $ca->setPermalink($row['ca_permalink']); $ca->setParent($row['ca_parent']); $ca->setStatus(ae_CategoryModel::STATUS_AVAILABLE); $id2Post[$row['pc_post']]->addCategory($ca); } }
/** * Create the category. * @return {int} ID of the new category. */ function createCategory() { if (!isset($_POST['category-title'], $_POST['category-parent'], $_POST['category-permalink'])) { header('Location: ../admin.php?error=missing_data_for_category'); exit; } $permalink = trim($_POST['category-permalink']); $category = new ae_CategoryModel(); if (isset($_POST['edit-id'])) { $category->setId($_POST['edit-id']); } $category->setTitle($_POST['category-title']); $category->setParent($_POST['category-parent']); if ($permalink != '') { $category->setPermalink($permalink); } $category->save(); return $category->getId(); }