Пример #1
0
 public function createAccount(Server_Account $a)
 {
     $this->getLog()->info('Creating account ' . $a->getUsername());
     if ($a->getReseller()) {
         $ips = $this->_getIps();
         foreach ($ips['exclusive'] as $key => $ip) {
             if (!$ip['empty']) {
                 unset($ips['exclusive'][$key]);
             }
         }
         if (count($ips['exclusive']) == 0) {
             throw new Server_Exception('Out of free IP adresses');
         }
         $ips['exclusive'] = array_values($ips['exclusive']);
         $rand = array_rand($ips['exclusive']);
         $a->setIp($ips['exclusive'][$rand]['ip']);
     }
     $id = $this->_creatClient($a);
     $client = $a->getClient();
     if (!$id) {
         throw new Server_Exception('Failed to create new account');
     } else {
         $client->setId((string) $id);
     }
     $this->setSubscription($a);
     if ($a->getReseller()) {
         $this->_setIp($a);
         $this->_changeIpType($a);
     }
     if ($a->getReseller()) {
         $this->_addNs($a, $domainId);
     }
     return true;
 }
Пример #2
0
 public function testsync()
 {
     $data = array('password' => 'topsecret', 'password_confirm' => 'topsecret');
     $orderModel = new \Model_ClientOrder();
     $orderModel->loadBean(new \RedBeanPHP\OODBBean());
     $model = new \Model_ServiceHosting();
     $model->loadBean(new \RedBeanPHP\OODBBean());
     $serviceMock = $this->getMockBuilder('\\Box\\Mod\\Servicehosting\\Service')->setMethods(array('_getAM'))->getMock();
     $accountObj = new \Server_Account();
     $accountObj->setUsername('testUser1');
     $accountObj->setIp('1.1.1.1');
     $accountObj2 = new \Server_Account();
     $accountObj2->setUsername('testUser2');
     $accountObj2->setIp('2.2.2.2');
     $serverManagerMock = $this->getMockBuilder('\\Server_Manager_Custom')->disableOriginalConstructor()->getMock();
     $serverManagerMock->expects($this->atLeastOnce())->method('synchronizeAccount')->will($this->returnValue($accountObj2));
     $AMresultArray = array($serverManagerMock, $accountObj);
     $serviceMock->expects($this->atLeastOnce())->method('_getAM')->will($this->returnValue($AMresultArray));
     $dbMock = $this->getMockBuilder('\\Box_Database')->getMock();
     $dbMock->expects($this->atLeastOnce())->method('store');
     $di = new \Box_Di();
     $di['db'] = $dbMock;
     $di['logger'] = new \Box_Log();
     $serviceMock->setDi($di);
     $result = $serviceMock->sync($orderModel, $model, $data);
     $this->assertTrue($result);
 }