/** * #8380: write a test for saveMyPhone as unprivileged user * https://forge.tine20.org/mantisbt/view.php?id=8380 */ public function testSaveMyPhoneAsUnprivilegedUser() { // first save the phone as privileged user $userPhone = $this->_json->getMyPhone($this->_objects['phone']->getId()); $userPhone['lines'][0]['asteriskline_id']['cfi_mode'] = "number"; $userPhone['lines'][0]['asteriskline_id']['cfi_number'] = "+494949302111"; // try to set a property which should be overwritten again $userPhone['description'] = 'no phone'; $phone = $this->_json->saveMyPhone($userPhone); $this->assertEquals('number', $phone['lines'][0]['asteriskline_id']['cfi_mode']); $this->assertEquals('+494949302111', $phone['lines'][0]['asteriskline_id']['cfi_number']); $this->assertEquals('user phone', $phone['description']); $additionalLine = array('id' => Tinebase_Record_Abstract::generateUID(), 'snomphone_id' => $this->_objects['phone']->getId(), 'asteriskline_id' => $this->_objects['sippeer']->getId(), 'linenumber' => 2, 'lineactive' => 2); // use another user which doesn't have access to the phone Tinebase_Core::set(Tinebase_Core::USER, Tinebase_User::getInstance()->getFullUserByLoginName('pwulf')); $e = new Exception('No Exception has been thrown!'); try { $this->_json->saveMyPhone($userPhone); } catch (Exception $e) { } $this->assertEquals('Tinebase_Exception_AccessDenied', get_class($e)); // try to save with a line removed Tinebase_Core::set(Tinebase_Core::USER, $this->_adminUser); $snomLineBackend = new Voipmanager_Backend_Snom_Line(); $snomLineBackend->create(new Voipmanager_Model_Snom_Line($additionalLine)); $userPhone = $this->_json->getMyPhone($this->_objects['phone']->getId()); unset($userPhone['lines'][1]); $this->setExpectedException('Tinebase_Exception_AccessDenied'); $this->_json->saveMyPhone($userPhone); }
/** * Sets up the fixture. * This method is called before a test is executed. * * @access protected */ protected function setUp() { $this->_json = new Phone_Frontend_Json(); $this->_objects['location'] = new Voipmanager_Model_Snom_Location(array('id' => 20001, 'name' => 'phpunit test location', 'registrar' => 'registrar')); $this->_objects['software'] = new Voipmanager_Model_Snom_Software(array('id' => 20003)); $this->_objects['setting'] = new Voipmanager_Model_Snom_Setting(array('id' => 20004, 'name' => 'test setting', 'description' => 'test setting')); $this->_objects['phonesetting'] = new Voipmanager_Model_Snom_PhoneSettings(array('phone_id' => 1001, 'web_language' => 'English')); $this->_objects['template'] = new Voipmanager_Model_Snom_Template(array('id' => 20002, 'name' => 'phpunit test location', 'model' => 'snom320', 'software_id' => $this->_objects['software']->getId(), 'setting_id' => $this->_objects['setting']->getId())); $this->_objects['phone'] = new Voipmanager_Model_Snom_Phone(array('id' => 1001, 'macaddress' => "1234567890cd", 'description' => 'user phone', 'location_id' => $this->_objects['location']->getId(), 'template_id' => $this->_objects['template']->getId(), 'current_model' => 'snom320', 'redirect_event' => 'none')); $this->_objects['phoneOwner'] = array('account_id' => Zend_Registry::get('currentAccount')->getId(), 'account_type' => 'user'); $rights = new Tinebase_Record_RecordSet('Voipmanager_Model_Snom_PhoneRight', array($this->_objects['phoneOwner'])); $this->_objects['phone']->rights = $rights; $this->_objects['line'] = new Voipmanager_Model_Snom_Line(array('id' => 1001, 'snomphone_id' => $this->_objects['phone']->getId(), 'asteriskline_id' => 1001, 'linenumber' => 1, 'lineactive' => 1)); $this->_objects['context'] = new Voipmanager_Model_Asterisk_Context(array('id' => 1001, 'name' => 'test context', 'description' => 'test context')); $this->_objects['sippeer'] = new Voipmanager_Model_Asterisk_SipPeer(array('id' => 1001, 'context_id' => 1001)); // create phone, location, template, rights $phoneBackend = new Voipmanager_Backend_Snom_Phone(array('modelName' => 'Phone_Model_MyPhone')); $snomLocationBackend = new Voipmanager_Backend_Snom_Location(); $snomSettingBackend = new Voipmanager_Backend_Snom_Setting(); $snomPhoneSettingBackend = new Voipmanager_Backend_Snom_PhoneSettings(); $snomTemplateBackend = new Voipmanager_Backend_Snom_Template(); $snomSoftwareBackend = new Voipmanager_Backend_Snom_Software(); $snomLineBackend = new Voipmanager_Backend_Snom_Line(); $asteriskSipPeerBackend = new Voipmanager_Backend_Asterisk_SipPeer(); $asteriskContextBackend = new Voipmanager_Backend_Asterisk_Context(); try { $snomSoftwareBackend->create($this->_objects['software']); } catch (Zend_Db_Statement_Exception $e) { Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' ' . $e->getMessage()); } try { $snomLocationBackend->create($this->_objects['location']); } catch (Zend_Db_Statement_Exception $e) { Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' ' . $e->getMessage()); } try { $snomSettingBackend->create($this->_objects['setting']); } catch (Zend_Db_Statement_Exception $e) { Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' ' . $e->getMessage()); } try { $snomTemplateBackend->create($this->_objects['template']); } catch (Zend_Db_Statement_Exception $e) { Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' ' . $e->getMessage()); } try { $phoneBackend->create($this->_objects['phone']); } catch (Zend_Db_Statement_Exception $e) { Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' ' . $e->getMessage()); } try { $phoneBackend->setPhoneRights($this->_objects['phone']); } catch (Zend_Db_Statement_Exception $e) { Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' ' . $e->getMessage()); } try { $asteriskContextBackend->create($this->_objects['context']); } catch (Zend_Db_Statement_Exception $e) { Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' ' . $e->getMessage()); } try { $asteriskSipPeerBackend->create($this->_objects['sippeer']); } catch (Zend_Db_Statement_Exception $e) { Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' ' . $e->getMessage()); } try { $snomLineBackend->create($this->_objects['line']); } catch (Zend_Db_Statement_Exception $e) { Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' ' . $e->getMessage()); } try { $snomPhoneSettingBackend->create($this->_objects['phonesetting']); } catch (Zend_Db_Statement_Exception $e) { Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' ' . $e->getMessage()); } /******************** call history *************************/ $phoneController = Phone_Controller::getInstance(); $this->_objects['call1'] = new Phone_Model_Call(array('id' => 'phpunitcallhistoryid1', 'line_id' => $this->_objects['line']->getId(), 'phone_id' => $this->_objects['phone']->getId(), 'direction' => Phone_Model_Call::TYPE_INCOMING, 'source' => '26', 'destination' => '0406437435')); $this->_objects['call2'] = new Phone_Model_Call(array('id' => 'phpunitcallhistoryid2', 'line_id' => $this->_objects['line']->getId(), 'phone_id' => $this->_objects['phone']->getId(), 'direction' => Phone_Model_Call::TYPE_INCOMING, 'source' => '26', 'destination' => '050364354')); $this->_objects['paging'] = array('start' => 0, 'limit' => 50, 'sort' => 'start', 'dir' => 'ASC'); $this->_objects['filter1'] = array(array('field' => 'query', 'operator' => 'contains', 'value' => '')); $this->_objects['filter2'] = array(array('field' => 'query', 'operator' => 'contains', 'value' => '050')); $this->_objects['filter3'] = array(array('field' => 'phone_id', 'operator' => 'equals', 'value' => $this->_objects['phone']->getId())); // create calls try { $call = $phoneController->callStarted($this->_objects['call1']); $call = $phoneController->callStarted($this->_objects['call2']); } catch (Zend_Db_Statement_Exception $e) { // exists //echo $e->getMessage(); } }