/** * Tests if the user group can save and return a id. */ public function testId() { $group = new Group(); $group->setId(3); $this->assertEquals(3, $group->getId(), 'The group id did not save correctly.'); $this->assertTrue(is_int($group->getId()), 'The group id was not returned as an Integer.'); }
/** * Inserts or updates a user group model into the database. * * @param GroupModel $group */ public function save(GroupModel $group) { $fields = array(); $name = $group->getName(); if (!empty($name)) { $fields['name'] = $group->getName(); } $groupId = (int) $this->db()->select('id', 'groups', array('id' => $group->getId()))->execute()->fetchCell(); if ($groupId) { /* * Group does exist already, update. */ $this->db()->update('groups')->values($fields)->where(array('id' => $groupId))->execute(); } else { /* * Group does not exist yet, insert. */ $groupId = $this->db()->insert('groups')->values($fields)->execute(); } return $groupId; }