/** * Tests if the user group can save and return a name. */ public function testName() { $group = new Group(); $group->setName('newGroup'); $this->assertEquals('newGroup', $group->getName(), 'The group name did not save correctly.'); }
/** * 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; }