public function createUser($username, $password) { $safeCode = self::makeToken($username); $this->username = $username; $this->password = self::makePassword($password, $safeCode); $this->safecode = $safeCode; $this->save(); $user_id = $this->getId(); //为新用户分配其他数据,如附赠系统分类 //$query = 'CALL register(?)'; //$query = $this->_db->quoteInto($query,$user_id); //$this->_db->query($query); //附赠系统分类 //TODO : 应该order表中读取分类时依赖于category_id //所以目前category表无法作为字典表,用户不能复用相同id的category //今后可以改进,避免每注册一个用户就无谓的为category表添加相同的系统分类 $userDB = new Database_Notes($this->_db); $system_categories = array('Inbox', 'Today', 'Next', 'Maybe', 'Projects', 'Areas'); foreach ($system_categories as $category_name) { $userDB->addCategory($category_name, $user_id); } return $user_id; }
/** * 测试 categorys * * @return */ public function testCategorys() { $db = Zend_Registry::get('db'); $new_note_id = Zend_Registry::get('new_note_id'); $note = new Database_Notes($db); $note->load($new_note_id); $category_name = 'new category1'; //新建一个category $note->addCategory($category_name); //重载用于确认add成功 $note->load($new_note_id); $this->assertEquals($note->getId(), $new_note_id); /* //测试 createCategory $category_id = $note->createCategory($category_name); $c_id = $note->categoryNameToId($category_name); $this->assertEquals($c_id,$category_id); */ //测试 makeCategoryLink //$category_link_id = $note->makeCategoryLink($category_id); $note->load($new_note_id); $new_category_is_added = $note->CategoryIsExistInThisNote($category_name); $this->assertTrue($new_category_is_added); //删除刚才新建的category $note->delCategory($category_name); //重载用于确认del成功 $note->load($new_note_id); $new_category_is_gone = $note->CategoryIsExistInThisNote($category_name); $this->assertFalse($new_category_is_gone); //cleanup $note->delNote($new_note_id); }