public function testget_info() { $data = array('microsoft'); $eventMock = $this->getMockBuilder('\\Box_EventManager')->getMock(); $eventMock->expects($this->atLeastOnce())->method('fire'); $modelClient = new \Model_Client(); $modelClient->loadBean(new \RedBeanPHP\OODBBean()); $clientService = $this->getMockBuilder('\\Box\\Mod\\Client\\Service')->getMock(); $clientService->expects($this->atLeastOnce())->method('toApiArray')->with($modelClient)->willReturn(array()); $systemService = $this->getMockBuilder('\\Box\\Mod\\System\\Service')->getMock(); $systemService->expects($this->atLeastOnce())->method('getVersion')->willReturn(\Box_Version::VERSION); $systemService->expects($this->atLeastOnce())->method('getMessages')->willReturn(array()); $di = new \Box_Di(); $di['logger'] = new \Box_Log(); $di['events_manager'] = $eventMock; $di['mod_service'] = $di->protect(function ($serviceName) use($clientService, $systemService) { if ($serviceName == 'Client') { return $clientService; } if ($serviceName == 'System') { return $systemService; } return -1; }); $di['loggedin_client'] = $modelClient; $di['array_get'] = $di->protect(function (array $array, $key, $default = null) use($di) { return isset($array[$key]) ? $array[$key] : $default; }); $this->api->setDi($di); $result = $this->api->get_info($data); $this->assertInternalType('array', $result); $this->assertArrayHasKey('version', $result); $this->assertArrayHasKey('profile', $result); $this->assertArrayHasKey('messages', $result); }
public function testtoApiArray() { $subscriptionModel = new \Model_Subscription(); $subscriptionModel->loadBean(new \RedBeanPHP\OODBBean()); $clientModel = new \Model_Client(); $clientModel->loadBean(new \RedBeanPHP\OODBBean()); $gatewayModel = new \Model_PayGateway(); $gatewayModel->loadBean(new \RedBeanPHP\OODBBean()); $dbMock = $this->getMockBuilder('\\Box_Database')->getMock(); $dbMock->expects($this->atLeastOnce())->method('load')->will($this->onConsecutiveCalls($clientModel, $gatewayModel)); $clientServiceMock = $this->getMockBuilder('\\Box\\Mod\\Client\\Service')->getMock(); $clientServiceMock->expects($this->atLeastOnce())->method('toApiArray')->will($this->returnValue(array())); $payGatewayService = $this->getMockBuilder('\\Box\\Mod\\Invoice\\ServicePayGateway')->getMock(); $payGatewayService->expects($this->atLeastOnce())->method('toApiArray')->will($this->returnValue(array())); $di = new \Box_Di(); $di['mod_service'] = $di->protect(function ($serviceName, $sub = '') use($clientServiceMock, $payGatewayService) { if ($serviceName == 'Client') { return $clientServiceMock; } if ($sub == 'PayGateway') { return $payGatewayService; } }); $di['db'] = $dbMock; $this->service->setDi($di); $expected = array('id' => '', 'sid' => '', 'period' => '', 'amount' => '', 'currency' => '', 'status' => '', 'created_at' => '', 'updated_at' => '', 'client' => array(), 'gateway' => array()); $result = $this->service->toApiArray($subscriptionModel); $this->assertInternalType('array', $result); $this->assertInternalType('array', $result['client']); $this->assertInternalType('array', $result['gateway']); $this->assertEquals($expected, $result); }
public function testApi_key_get() { $client = new \Model_Client(); $client->loadBean(new \RedBeanPHP\OODBBean()); $client->api_token = '16047a3e69f5245756d73b419348f0c7'; $this->clientApi->setIdentity($client); $result = $this->clientApi->api_key_get(array()); $this->assertEquals($result, $client->api_token); }
public function testdeductFunds_InvalidAmount() { $service = new \Box\Mod\Client\ServiceBalance(); $clientModel = new \Model_Client(); $clientModel->loadBean(new \RedBeanPHP\OODBBean()); $description = 'Charged'; $amount = "5.5adadzxc"; $extra = array('rel_id' => 1); $this->setExpectedException('\\Box_Exception', 'Funds amount is not valid'); $service->deductFunds($clientModel, $amount, $description, $extra); }
public function test_getServiceOrderNotActivated() { $data = array('order_id' => 17); $client = new Model_Client(); $client->loadBean(new RedBeanPHP\OODBBean()); $client->id = 1; $clientApi = new Box\Mod\Serviceboxbillinglicense\Api\Client(); $clientApi->setDi($this->di); $clientApi->setIdentity($client); $this->setExpectedException('\\Box_Exception', 'Order is not activated'); $bool = $clientApi->reset($data); }
public function testforumSpamChecker() { $params = array('client_id' => 1, 'message' => 'Hello world'); $model = new \Model_Client(); $model->loadBean(new \RedBeanPHP\OODBBean()); $dbMock = $this->getMockBuilder('\\Box_Database')->getMock(); $dbMock->expects($this->atLeastOnce())->method('load')->willReturn($model); $spamCheckerService = $this->getMockBuilder('\\Box\\Mod\\Spamchecker\\Service')->getMock(); $spamCheckerService->expects($this->atLeastOnce())->method('isCommentSpam'); $spamCheckerService->expects($this->atLeastOnce())->method('isBlockedIp'); $di = new \Box_Di(); $di['db'] = $dbMock; $di['mod_service'] = $di->protect(function () use($spamCheckerService) { return $spamCheckerService; }); $boxEventMock = $this->getMockBuilder('\\Box_Event')->disableOriginalConstructor()->getMock(); $boxEventMock->expects($this->atLeastOnce())->method('getDi')->willReturn($di); $boxEventMock->expects($this->atLeastOnce())->method('getParameters')->willReturn($params); $this->service->forumSpamChecker($boxEventMock); }
public function testSearchArticles() { $service = new \Box\Mod\Kb\Service(); $willReturn = array("pages" => 5, "page" => 2, "per_page" => 2, "total" => 10, "list" => array()); $di = new \Box_Di(); $pager = $this->getMockBuilder('Box_Pagination')->getMock(); $pager->expects($this->atLeastOnce())->method('getSimpleResultSet')->will($this->returnValue($willReturn)); $client = new \Model_Client(); $client->loadBean(new \RedBeanPHP\OODBBean()); $client->id = 5; $di['pager'] = $pager; $service->setDi($di); $result = $service->searchArticles('active', 'keyword', 'category'); $this->assertInternalType('array', $result); $this->assertArrayHasKey('list', $result); $this->assertInternalType('array', $result['list']); $this->assertArrayHasKey('pages', $result); $this->assertArrayHasKey('page', $result); $this->assertArrayHasKey('per_page', $result); $this->assertArrayHasKey('total', $result); }
public function testCheckout() { $cart = new \Model_Cart(); $cart->loadBean(new \RedBeanPHP\OODBBean()); $serviceMock = $this->getMockBuilder('\\Box\\Mod\\Cart\\Service')->setMethods(array('getSessionCart', 'checkoutCart'))->getMock(); $serviceMock->expects($this->atLeastOnce())->method('getSessionCart')->will($this->returnValue($cart)); $checkOutCartResult = array('gateway_id' => 1, 'invoice_hash' => null, 'order_id' => 1, 'orders' => 1); $serviceMock->expects($this->atLeastOnce())->method('checkoutCart')->will($this->returnValue($checkOutCartResult)); $this->clientApi->setService($serviceMock); $client = new \Model_Client(); $client->loadBean(new \RedBeanPHP\OODBBean()); $this->clientApi->setIdentity($client); $data = array('id' => rand(1, 100)); $di = new \Box_Di(); $di['array_get'] = $di->protect(function (array $array, $key, $default = null) use($di) { return isset($array[$key]) ? $array[$key] : $default; }); $this->clientApi->setDi($di); $result = $this->clientApi->checkout($data); $this->assertInternalType('array', $result); }
public function test_getServiceOrderNotActivated() { $data['order_id'] = 1; $orderServiceMock = $this->getMockBuilder('\\Box\\Mod\\Order\\Service')->getMock(); $orderServiceMock->expects($this->atLeastOnce())->method('getOrderService')->will($this->returnValue(null)); $dbMock = $this->getMockBuilder('\\Box_Database')->getMock(); $dbMock->expects($this->atLeastOnce())->method('findOne')->with('ClientOrder')->will($this->returnValue(new \Model_ClientOrder())); $validatorMock = $this->getMockBuilder('\\Box_Validate')->getMock(); $validatorMock->expects($this->atLeastOnce())->method('checkRequiredParamsForArray'); $di = new \Box_Di(); $di['validator'] = $validatorMock; $di['db'] = $dbMock; $di['mod_service'] = $di->protect(function () use($orderServiceMock) { return $orderServiceMock; }); $this->api->setDi($di); $clientModel = new \Model_Client(); $clientModel->loadBean(new \RedBeanPHP\OODBBean()); $this->api->setIdentity($clientModel); $this->setExpectedException('\\Box_Exception', 'Order is not activated'); $this->api->_getService($data); }
public function testsend_file() { $data = array('order_id' => 1); $modelClient = new \Model_Client(); $modelClient->loadBean(new \RedBeanPHP\OODBBean()); $serviceMock = $this->getMockBuilder('\\Box\\Mod\\Servicedownloadable\\Service')->getMock(); $serviceMock->expects($this->atLeastOnce())->method('sendFile')->will($this->returnValue(true)); $orderServiceMock = $this->getMockBuilder('\\Box\\Mod\\Order\\Service')->getMock(); $orderServiceMock->expects($this->atLeastOnce())->method('getOrderService')->will($this->returnValue(new \Model_ServiceDownloadable())); $dbMock = $this->getMockBuilder('\\Box_Database')->getMock(); $dbMock->expects($this->atLeastOnce())->method('findOne')->will($this->returnValue(new \Model_ClientOrder())); $di = new \Box_Di(); $di['db'] = $dbMock; $di['mod_service'] = $di->protect(function () use($orderServiceMock) { return $orderServiceMock; }); $this->api->setDi($di); $this->api->setIdentity($modelClient); $this->api->setService($serviceMock); $result = $this->api->send_file($data); $this->assertInternalType('bool', $result); $this->assertTrue($result); }
public function testget_tax_rate() { $client = new \Model_Client(); $client->loadBean(new \RedBeanPHP\OODBBean()); $taxRate = 20; $invoiceTaxService = $this->getMockBuilder('\\Box\\Mod\\Invoice\\ServiceTax')->getMock(); $invoiceTaxService->expects($this->atLeastOnce())->method('getTaxRateForClient')->willReturn($taxRate); $di = new \Box_Di(); $di['mod_service'] = $di->protect(function ($service, $sub) use($invoiceTaxService) { if ($service == 'Invoice' && $sub == 'Tax') { return $invoiceTaxService; } }); $this->api->setDi($di); $this->api->setIdentity($client); $result = $this->api->get_tax_rate(); $this->assertEquals($taxRate, $result); }
public function testrmByClient() { $clientModel = new \Model_Client(); $clientModel->loadBean(new \RedBeanPHP\OODBBean()); $pdoStatment = $this->getMockBuilder('\\Box\\Mod\\Order\\PdoStatmentsMock')->getMock(); $pdoStatment->expects($this->atLeastOnce())->method('execute'); $pdoMock = $this->getMockBuilder('\\Box\\Mod\\Order\\PdoMock')->getMock(); $pdoMock->expects($this->atLeastOnce())->method('prepare')->will($this->returnValue($pdoStatment)); $di = new \Box_Di(); $di['pdo'] = $pdoMock; $this->service->setDi($di); $this->service->rmByClient($clientModel); }
/** * @dataProvider testSendTemplateExistsStaffProvider */ public function testSendTemplateExistsStaff($data, $clientGetExpects, $staffgetListExpects) { $serviceMock = $this->getMockBuilder('\\Box\\Mod\\Email\\Service')->setMethods(array('sendMail'))->getMock(); $serviceMock->expects($this->atLeastOnce())->method('sendMail')->willReturn(true); $di = new \Box_Di(); $emailTemplate = new \Model_EmailTemplate(); $emailTemplate->loadBean(new \RedBeanPHP\OODBBean()); $db = $this->getMockBuilder('Box_Database')->getMock(); $db->expects($this->atLeastOnce())->method('dispense')->will($this->returnValue($emailTemplate)); $db->expects($this->atLeastOnce())->method('store')->will($this->returnValue(1)); $system = $this->getMockBuilder('Box\\Mod\\System\\Service')->getMock(); $system->expects($this->atLeastOnce())->method('getParamValue')->will($this->returnValue('value')); $staffServiceMock = $this->getMockBuilder('Box\\Mod\\Staff\\Service')->getMock(); $staffServiceMock->expects($staffgetListExpects)->method('getList')->will($this->returnValue(array('list' => array(0 => array('id' => 1, 'email' => '*****@*****.**', 'name' => 'George'))))); $clientServiceMock = $this->getMockBuilder('Box\\Mod\\Client\\Service')->getMock(); $clientModel = new \Model_Client(); $clientModel->loadBean(new \RedBeanPHP\OODBBean()); $clientServiceMock->expects($clientGetExpects)->method('get')->will($this->returnValue($clientModel)); $clientApiArray = array('id' => 1, 'email' => '*****@*****.**', 'first_name' => 'John', 'last_name' => 'Smith'); $clientServiceMock->expects($clientGetExpects)->method('toApiArray')->will($this->returnValue($clientApiArray)); $twig = $this->getMockBuilder('Twig_Environment')->getMock(); $twig->expects($this->atLeastOnce())->method('render')->will($this->returnValue('value')); $cryptMock = $this->getMockBuilder('\\Box_Crypt')->disableOriginalConstructor()->getMock(); $cryptMock->expects($this->atLeastOnce())->method('encrypt'); $di['api_admin'] = function () use($di) { $api = new \Api_Handler(new \Model_Admin()); $api->setDi($di); return $api; }; $validatorMock = $this->getMockBuilder('\\Box_Validate')->disableOriginalConstructor()->getMock(); $validatorMock->expects($this->atLeastOnce())->method('checkRequiredParamsForArray')->will($this->returnValue(null)); $di['validator'] = $validatorMock; $di['db'] = $db; $di['twig'] = $twig; $di['crypt'] = $cryptMock; $di['mod_service'] = $di->protect(function ($name) use($system, $staffServiceMock, $clientServiceMock) { if ($name == 'staff') { return $staffServiceMock; } elseif ($name == 'system') { return $system; } elseif ($name == 'client') { return $clientServiceMock; } }); $di['tools'] = new \Box_Tools(); $di['array_get'] = $di->protect(function (array $array, $key, $default = null) use($di) { return isset($array[$key]) ? $array[$key] : $default; }); $serviceMock->setDi($di); $result = $serviceMock->sendTemplate($data); $this->assertTrue($result); }
public function testsubscription_createCurrencyMismatch() { $data = array('client_id' => 1, 'gateway_id' => 1, 'currency' => 'EU'); $validatorMock = $this->getMockBuilder('\\Box_Validate')->getMock(); $validatorMock->expects($this->atLeastOnce())->method('checkRequiredParamsForArray'); $dbMock = $this->getMockBuilder('\\Box_Database')->getMock(); $model = new \Model_PayGateway(); $model->loadBean(new \RedBeanPHP\OODBBean()); $client = new \Model_Client(); $client->loadBean(new \RedBeanPHP\OODBBean()); $dbMock->expects($this->atLeastOnce())->method('getExistingModelById')->will($this->onConsecutiveCalls($client, $model)); $di = new \Box_Di(); $di['validator'] = $validatorMock; $di['db'] = $dbMock; $this->api->setDi($di); $this->setExpectedException('\\Box_Exception', 'Client currency must match subscription currency. Check if clients currency is defined.'); $this->api->subscription_create($data); }
/** * @dataProvider testCanClientSubmitNewTicketProvider */ public function testCanClientSubmitNewTicket($ticket, $hours, $expected) { if (!$expected) { $this->setExpectedException('\\Box_Exception'); } $dbMock = $this->getMockBuilder('\\Box_Database')->disableOriginalConstructor()->getMock(); $dbMock->expects($this->atLeastOnce())->method('findOne')->will($this->returnValue($ticket)); $di = new \Box_Di(); $di['db'] = $dbMock; $this->service->setDi($di); $client = new \Model_Client(); $client->loadBean(new \RedBeanPHP\OODBBean()); $client->id = 5; $config = array('wait_hours' => $hours); $result = $this->service->canClientSubmitNewTicket($client, $config); $this->assertTrue($result); }
public function testconfirm_reset() { $data = array('hash' => 'hashedString'); $modelClient = new \Model_Client(); $modelClient->loadBean(new \RedBeanPHP\OODBBean()); $modelPasswordReset = new \Model_ClientPasswordReset(); $modelPasswordReset->loadBean(new \RedBeanPHP\OODBBean()); $dbMock = $this->getMockBuilder('\\Box_Database')->getMock(); $dbMock->expects($this->atLeastOnce())->method('findOne')->will($this->returnValue($modelPasswordReset)); $dbMock->expects($this->atLeastOnce())->method('getExistingModelById')->will($this->returnValue($modelClient)); $dbMock->expects($this->atLeastOnce())->method('store')->will($this->returnValue(1)); $dbMock->expects($this->atLeastOnce())->method('trash'); $emailServiceMock = $serviceMock = $this->getMockBuilder('\\Box\\Mod\\Email\\Service')->getMock(); $emailServiceMock->expects($this->atLeastOnce())->method('sendTemplate'); $passwordMock = $this->getMockBuilder('\\Box_Password')->getMock(); $passwordMock->expects($this->atLeastOnce())->method('hashIt'); $di = new \Box_Di(); $di['db'] = $dbMock; $di['logger'] = new \Box_Log(); $di['mod_service'] = $di->protect(function ($name) use($emailServiceMock) { return $emailServiceMock; }); $di['password'] = $passwordMock; $validatorMock = $this->getMockBuilder('\\Box_Validate')->disableOriginalConstructor()->getMock(); $validatorMock->expects($this->atLeastOnce())->method('checkRequiredParamsForArray')->will($this->returnValue(null)); $di['validator'] = $validatorMock; $client = new \Box\Mod\Client\Api\Guest(); $client->setDi($di); $result = $client->confirm_reset($data); $this->assertTrue($result); }
public function testTicket_create() { $validatorMock = $this->getMockBuilder('\\Box_Validate')->disableOriginalConstructor()->getMock(); $validatorMock->expects($this->atLeastOnce())->method('checkRequiredParamsForArray')->will($this->returnValue(null)); $clientModel = new \Model_Client(); $clientModel->loadBean(new \RedBeanPHP\OODBBean()); $supportHelpdeskModel = new \Model_SupportHelpdesk(); $supportHelpdeskModel->loadBean(new \RedBeanPHP\OODBBean()); $dbMock = $this->getMockBuilder('\\Box_Database')->disableOriginalConstructor()->getMock(); $dbMock->expects($this->atLeastOnce())->method('getExistingModelById')->will($this->onConsecutiveCalls($clientModel, $supportHelpdeskModel)); $randID = rand(1, 100); $serviceMock = $this->getMockBuilder('\\Box\\Mod\\Support\\Service')->getMock(); $serviceMock->expects($this->atLeastOnce())->method('ticketCreateForAdmin')->will($this->returnValue($randID)); $di = new \Box_Di(); $di['validator'] = $validatorMock; $di['db'] = $dbMock; $this->adminApi->setDi($di); $this->adminApi->setService($serviceMock); $this->adminApi->setIdentity(new \Model_Admin()); $data = array('client_id' => rand(1, 100), 'content' => 'Content', 'subject' => 'Subject', 'support_helpdesk_id' => rand(1, 100)); $result = $this->adminApi->ticket_create($data); $this->assertInternalType('integer', $result); $this->assertEquals($randID, $result); }
public function testonAfterClientOpenTicket_PaidSupportDisabledForHelpdesk() { $di = new \Box_Di(); $supportTicketModel = new \Model_SupportTicket(); $supportTicketModel->loadBean(new \RedBeanPHP\OODBBean()); $clientModel = new \Model_Client(); $clientModel->loadBean(new \RedBeanPHP\OODBBean()); $dbMock = $this->getMockBuilder('\\Box_Database')->getMock(); $dbMock->expects($this->atLeastOnce())->method('load')->withConsecutive(array('SupportTicket'), array('Client'))->willReturnOnConsecutiveCalls($supportTicketModel, $clientModel); $di['db'] = $dbMock; $paidSupportMock = $this->getMockBuilder('\\Box\\Mod\\Paidsupport\\Service')->getMock(); $paidSupportMock->expects($this->atLeastOnce())->method('hasHelpdeskPaidSupport')->willReturn(false); $paidSupportMock->expects($this->never())->method('enoughInBalanceToOpenTicket')->with($clientModel); $di['mod_service'] = $di->protect(function ($serviceName, $sub = '') use($paidSupportMock) { if ($serviceName == 'Paidsupport') { return $paidSupportMock; } }); $params = array('id' => 1, 'support_helpdesk_id' => 1); $boxEventMock = $this->getMockBuilder('\\Box_Event')->disableOriginalConstructor()->getMock(); $boxEventMock->expects($this->atLeastOnce())->method('getDi')->willReturn($di); $boxEventMock->expects($this->atLeastOnce())->method('getParameters')->willReturn($params); $result = $this->service->onAfterClientOpenTicket($boxEventMock); $this->assertTrue($result); }
public function testcanChangeEmail_CanntChangeEmail() { $clientModel = new \Model_Client(); $clientModel->loadBean(new \RedBeanPHP\OODBBean()); $email = '*****@*****.**'; $config = array('allow_change_email' => false); $di = new \Box_Di(); $di['mod_config'] = $di->protect(function ($modName) use($config) { return $config; }); $service = new \Box\Mod\Client\Service(); $service->setDi($di); $this->setExpectedException('Box_Exception', 'Email can not be changed'); $service->canChangeEmail($clientModel, $email); }
public function testcreditInvoiceItem() { $serviceMock = $this->getMockBuilder('\\Box\\Mod\\Invoice\\ServiceInvoiceItem')->setMethods(array('getTotalWithTax'))->getMock(); $serviceMock->expects($this->atLeastOnce())->method('getTotalWithTax')->will($this->returnValue(11.2)); $invoiceItemModel = new \Model_InvoiceItem(); $invoiceItemModel->loadBean(new \RedBeanPHP\OODBBean()); $invoiceModel = new \Model_Invoice(); $invoiceModel->loadBean(new \RedBeanPHP\OODBBean()); $clientModel = new \Model_Client(); $clientModel->loadBean(new \RedBeanPHP\OODBBean()); $clientBalanceModel = new \Model_Client(); $clientBalanceModel->loadBean(new \RedBeanPHP\OODBBean()); $dbMock = $this->getMockBuilder('\\Box_Database')->getMock(); $dbMock->expects($this->atLeastOnce())->method('getExistingModelById')->will($this->onConsecutiveCalls($invoiceModel, $clientModel)); $dbMock->expects($this->atLeastOnce())->method('dispense')->will($this->returnValue($clientBalanceModel)); $dbMock->expects($this->atLeastOnce())->method('store'); $invoiceServiceMock = $this->getMockBuilder('\\Box\\Mod\\Invoice\\Service')->getMock(); $invoiceServiceMock->expects($this->atLeastOnce())->method('addNote'); $di = new \Box_Di(); $di['db'] = $dbMock; $di['mod_service'] = $di->protect(function () use($invoiceServiceMock) { return $invoiceServiceMock; }); $serviceMock->setDi($di); $serviceMock->creditInvoiceItem($invoiceItemModel); }
public function testsave_theme_settings_PathIsNotWritable() { $boxAppMock = $this->getMockBuilder('\\Box_App')->disableOriginalConstructor()->getMock(); $boxAppMock->expects($this->atLeastOnce())->method('redirect'); $themeMock = $this->getMockBuilder('\\Box\\Mod\\Theme\\Model\\Theme')->disableOriginalConstructor()->getMock(); $themeMock->expects($this->atLeastOnce())->method('isAssetsPathWritable')->willReturn(false); $themeMock->expects($this->atLeastOnce())->method('getName')->willReturn('PHPUnit Controlled exception'); $themeServiceMock = $this->getMockBuilder('\\Box\\Mod\\Theme\\Service')->getMock(); $themeServiceMock->expects($this->atLeastOnce())->method('getTheme')->willReturn($themeMock); $themeServiceMock->expects($this->atLeastOnce())->method('getCurrentThemePreset')->willReturn('default'); $themeServiceMock->expects($this->atLeastOnce())->method('setCurrentThemePreset'); $themeServiceMock->expects($this->atLeastOnce())->method('regenerateThemeSettingsDataFile')->willThrowException(new \Exception('PHPUnit controoled exception')); $modMock = $this->getMockBuilder('\\Box_Mod')->disableOriginalConstructor()->getMock(); $modMock->expects($this->atLeastOnce())->method('getService')->willReturn($themeServiceMock); $eventMock = $this->getMockBuilder('\\Box_EventManager')->getMock(); $eventMock->expects($this->atLeastOnce())->method('fire'); $di = new \Box_Di(); $di['mod'] = $di->protect(function ($name) use($modMock) { if ($name == 'theme') { return $modMock; } }); $di['events_manager'] = $eventMock; $adminModel = new \Model_Client(); $adminModel->loadBean(new \RedBeanPHP\OODBBean()); $di['api_admin'] = new \Api_Handler($adminModel); $controller = new \Box\Mod\Theme\Controller\Admin(); $controller->setDi($di); $_POST['save-current-setting-preset'] = '{}'; $_POST['save-current-setting'] = true; $controller->save_theme_settings($boxAppMock, 'huraga'); }
public function testLogoutClient() { $sessionMock = $this->getMockBuilder("Box_Session")->disableOriginalConstructor()->getMock(); $sessionMock->expects($this->atLeastOnce())->method("delete"); $cookieMock = $this->getMockBuilder('Box_Cookie')->getMock(); $cookieMock->expects($this->any())->method('set'); $di = new \Box_Di(); $di['logger'] = new \Box_Log(); $di['session'] = $sessionMock; $di['cookie'] = $cookieMock; $model = new \Model_Client(); $model->loadBean(new \RedBeanPHP\OODBBean()); $service = new Service(); $service->setDi($di); $result = $service->logoutClient($model, 'new password'); $this->assertTrue($result); }
public function testActionCreate() { $tldModel = new \Model_Tld(); $tldModel->loadBean(new \RedBeanPHP\OODBBean()); $tldModel->tld_registrar_id = rand(1, 100); $data = array('action' => 'register', 'register_sld' => 'example', 'register_tld' => '.com', 'register_years' => 2); $orderServiceMock = $this->getMockBuilder('\\Box\\Mod\\Order\\Service')->setMethods(array('getConfig'))->getMock(); $orderServiceMock->expects($this->atLeastOnce())->method('getConfig')->will($this->returnValue($data)); $nameservers = array('nameserver_1' => 'ns1.example.com', 'nameserver_2' => 'ns2.example.com', 'nameserver_3' => 'ns3.example.com', 'nameserver_4' => 'ns4.example.com'); $systemServiceMock = $this->getMockBuilder('\\Box\\Mod\\System\\Service')->setMethods(array('getNameservers'))->getMock(); $systemServiceMock->expects($this->atLeastOnce())->method('getNameservers')->will($this->returnValue($nameservers)); $serviceMock = $this->getMockBuilder('\\Box\\Mod\\Servicedomain\\Service')->setMethods(array('tldFindOneByTld', 'validateOrderData'))->getMock(); $serviceMock->expects($this->atLeastOnce())->method('tldFindOneByTld')->will($this->returnValue($tldModel)); $serviceMock->expects($this->atLeastOnce())->method('validateOrderData')->will($this->returnValue(null)); $client = new \Model_Client(); $client->loadBean(new \RedBeanPHP\OODBBean()); $client->first_name = 'first_name'; $client->last_name = 'last_name'; $client->email = 'email'; $client->company = 'company'; $client->address_1 = 'address_1'; $client->address_2 = 'address_2'; $client->country = 'country'; $client->city = 'city'; $client->state = 'state'; $client->postcode = 'postcode'; $client->phone_cc = 'phone_cc'; $client->phone = 'phone'; $serviceDomainModel = new \Model_ServiceDomain(); $serviceDomainModel->loadBean(new \RedBeanPHP\OODBBean()); $dbMock = $this->getMockBuilder('\\Box_Database')->getMock(); $dbMock->expects($this->atLeastOnce())->method('getExistingModelById')->will($this->returnValue($client)); $dbMock->expects($this->atLeastOnce())->method('dispense')->will($this->returnValue($serviceDomainModel)); $di = new \Box_Di(); $di['mod_service'] = $di->protect(function ($name) use($orderServiceMock, $systemServiceMock) { if ($name == 'order') { return $orderServiceMock; } else { return $systemServiceMock; } }); $di['db'] = $dbMock; $di['array_get'] = $di->protect(function (array $array, $key, $default = null) use($di) { return isset($array[$key]) ? $array[$key] : $default; }); $serviceMock->setDi($di); $order = new \Model_ClientOrder(); $order->loadBean(new \RedBeanPHP\OODBBean()); $order->client_id = rand(1, 100); $result = $serviceMock->action_create($order); $this->assertInstanceOf('Model_ServiceDomain', $result); }
/** * @dataProvider amountsProvider */ public function testenoughInBalanceToCoverInvoice($inBalance, $invoiceSum, $expectedResult) { $di = new \Box_Di(); $dbMock = $this->getMockBuilder('\\Box_Database')->getMock(); $clientModel = new Model_Client(); $clientModel->loadBean(new \RedBeanPHP\OODBBean()); $dbMock->expects($this->atLeastOnce())->method('load')->with('Client')->willReturn($clientModel); $di['db'] = $dbMock; $clientBalanceServiceMock = $this->getMockBuilder('\\Box\\Mod\\Client\\ServiceBalance')->getMock(); $clientBalanceServiceMock->expects($this->atLeastOnce())->method('getClientBalance')->with($clientModel)->willReturn($inBalance); $invoiceModel = new \Model_Invoice(); $invoiceModel->loadBean(new \RedBeanPHP\OODBBean()); $invoiceServiceMock = $this->getMockBuilder('\\Box\\Mod\\Invoice\\Service')->getMock(); $invoiceServiceMock->expects($this->atLeastOnce())->method('getTotalWithTax')->with($invoiceModel)->willReturn($invoiceSum); $di['mod_service'] = $di->protect(function ($serviceName, $sub = '') use($invoiceServiceMock, $clientBalanceServiceMock) { if ('Invoice' == $serviceName) { return $invoiceServiceMock; } if ('Client' == $serviceName && $sub == 'Balance') { return $clientBalanceServiceMock; } }); $adapter = new Payment_Adapter_ClientBalance(); $adapter->setDi($di); $result = $adapter->enoughInBalanceToCoverInvoice($invoiceModel); $this->assertEquals($expectedResult, $result); }
public function testTicket_close() { $serviceMock = $this->getMockBuilder('\\Box\\Mod\\Support\\Service')->setMethods(array('findOneByClient', 'closeTicket'))->getMock(); $serviceMock->expects($this->atLeastOnce())->method('findOneByClient')->will($this->returnValue(new \Model_SupportTicket())); $serviceMock->expects($this->atLeastOnce())->method('closeTicket')->will($this->returnValue(rand(1, 100))); $validatorMock = $this->getMockBuilder('\\Box_Validate')->disableOriginalConstructor()->getMock(); $validatorMock->expects($this->atLeastOnce())->method('checkRequiredParamsForArray')->will($this->returnValue(null)); $di = new \Box_Di(); $di['validator'] = $validatorMock; $this->clientApi->setDi($di); $client = new \Model_Client(); $client->loadBean(new \RedBeanPHP\OODBBean()); $client->id = rand(1, 100); $this->clientApi->setService($serviceMock); $this->clientApi->setIdentity($client); $data = array('content' => 'Content', 'id' => rand(1, 100)); $result = $this->clientApi->ticket_close($data); $this->assertInternalType('integer', $result); }
public function testhasPermissionRoleStaffWithGoodPerms() { $member = new \Model_Client(); $member->loadBean(new \RedBeanPHP\OODBBean()); $member->role = 'staff'; $serviceMock = $this->getMockBuilder('\\Box\\Mod\\Staff\\Service')->setMethods(array('getPermissions'))->getMock(); $serviceMock->expects($this->atLeastOnce())->method('getPermissions')->will($this->returnValue(array('example' => array('get_list'), 'client' => array()))); $result = $serviceMock->hasPermission($member, 'example', 'get_list'); $this->assertTrue($result); }
public function testIsPromoAvailableForClientGroupProvider() { $promo1 = new \Model_Promo(); $promo1->loadBean(new \RedBeanPHP\OODBBean()); $promo1->client_groups = json_encode(array()); $client1 = new \Model_Client(); $client1->loadBean(new \RedBeanPHP\OODBBean()); $promo2 = new \Model_Promo(); $promo2->loadBean(new \RedBeanPHP\OODBBean()); $promo2->client_groups = json_encode(array(1, 2)); $client2 = new \Model_Client(); $client2->loadBean(new \RedBeanPHP\OODBBean()); $client2->client_group_id = null; $promo3 = new \Model_Promo(); $promo3->loadBean(new \RedBeanPHP\OODBBean()); $promo3->client_groups = json_encode(array(1, 2)); $client3 = new \Model_Client(); $client3->loadBean(new \RedBeanPHP\OODBBean()); $client3->client_group_id = 3; $promo4 = new \Model_Promo(); $promo4->loadBean(new \RedBeanPHP\OODBBean()); $promo4->client_groups = json_encode(array(1, 2)); $client4 = new \Model_Client(); $client4->loadBean(new \RedBeanPHP\OODBBean()); $client4->client_group_id = 2; $promo5 = new \Model_Promo(); $promo5->loadBean(new \RedBeanPHP\OODBBean()); $promo5->client_groups = json_encode(array()); $client5 = null; $promo6 = new \Model_Promo(); $promo6->loadBean(new \RedBeanPHP\OODBBean()); $promo6->client_groups = json_encode(array(1, 2)); $client6 = null; return array(array($promo1, $client1, true), array($promo2, $client2, false), array($promo3, $client3, false), array($promo4, $client4, true), array($promo5, null, true), array($promo6, null, false)); }
public function testgenerateFundsInvoice() { $invoiceModel = new \Model_Invoice(); $invoiceModel->loadBean(new \RedBeanPHP\OODBBean()); $clientModel = new \Model_Client(); $clientModel->loadBean(new \RedBeanPHP\OODBBean()); $clientModel->currency = 'EUR'; $fundsAmount = 20; $minAmount = 10; $maxAmount = 50; $serviceMock = $this->getMockBuilder('\\Box\\Mod\\Invoice\\Service')->setMethods(array('setInvoiceDefaults'))->getMock(); $serviceMock->expects($this->once())->method('setInvoiceDefaults'); $systemService = $this->getMockBuilder('\\Box\\Mod\\System\\Service')->getMock(); $systemService->expects($this->atLeastOnce())->method('getParamValue')->will($this->onConsecutiveCalls($minAmount, $maxAmount, true)); $itemInvoiceServiceMock = $this->getMockBuilder('\\Box\\Mod\\Invoice\\ServiceInvoiceItem')->getMock(); $itemInvoiceServiceMock->expects($this->atLeastOnce())->method('generateForAddFunds'); $dbMock = $this->getMockBuilder('\\Box_Database')->getMock(); $dbMock->expects($this->atLeastOnce())->method('dispense')->will($this->returnValue($invoiceModel)); $dbMock->expects($this->atLeastOnce())->method('store'); $di = new \Box_Di(); $di['mod_service'] = $di->protect(function ($serviceName, $sub = '') use($systemService, $itemInvoiceServiceMock) { if ('system' == $serviceName) { return $systemService; } if ('InvoiceItem' == $sub) { return $itemInvoiceServiceMock; } }); $di['db'] = $dbMock; $serviceMock->setDi($di); $result = $serviceMock->generateFundsInvoice($clientModel, $fundsAmount); $this->assertInstanceOf('\\Model_Invoice', $result); }
public function testdebitTransaction() { $currency = 'EUR'; $invoiceModel = new \Model_Invoice(); $invoiceModel->loadBean(new \RedBeanPHP\OODBBean()); $invoiceModel->currency = $currency; $clientModdel = new \Model_Client(); $clientModdel->loadBean(new \RedBeanPHP\OODBBean()); $clientModdel->currency = $currency; $transactionModel = new \Model_Transaction(); $transactionModel->loadBean(new \RedBeanPHP\OODBBean()); $transactionModel->amount = 11; $clientBalanceModel = new \Model_ClientBalance(); $clientBalanceModel->loadBean(new \RedBeanPHP\OODBBean()); $dbMock = $this->getMockBuilder('\\Box_Database')->getMock(); $dbMock->expects($this->atLeastOnce())->method('load')->will($this->onConsecutiveCalls($invoiceModel, $clientModdel)); $dbMock->expects($this->atLeastOnce())->method('dispense')->will($this->returnValue($clientBalanceModel)); $dbMock->expects($this->atLeastOnce())->method('store'); $di = new \Box_Di(); $di['db'] = $dbMock; $this->service->setDi($di); $this->service->debitTransaction($transactionModel); }
public function testprocessTransaction_IpnDuplicate() { $adapterMock = $this->getMockBuilder('\\Payment_Adapter_Interkassa')->disableOriginalConstructor()->setMethods(array('isIpnValid', 'isIpnDuplicate'))->getMock(); $adapterMock->expects($this->atLeastOnce())->method('isIpnValid')->willReturn(true); $adapterMock->expects($this->atLeastOnce())->method('isIpnDuplicate')->willReturn(true); $dbMock = $this->getMockBuilder('\\Box_Database')->getMock(); $transactionModel = new \Model_Transaction(); $transactionModel->loadBean(new \RedBeanPHP\OODBBean()); $invoiceModel = new \Model_Invoice(); $invoiceModel->loadBean(new \RedBeanPHP\OODBBean()); $clientModel = new \Model_Client(); $clientModel->loadBean(new \RedBeanPHP\OODBBean()); $dbMock->expects($this->atLeastOnce())->method('load')->withConsecutive(array('Transaction'), array('Invoice'), array('Client'))->willReturnOnConsecutiveCalls($transactionModel, $invoiceModel, $clientModel); $dbMock->expects($this->atLeastOnce())->method('store')->with($transactionModel); $clientServiceMock = $this->getMockBuilder('\\Box\\Mod\\Client\\Service')->getMock(); $clientServiceMock->expects($this->never())->method('addFunds'); $invoiceServiceMock = $this->getMockBuilder('\\Box\\Mod\\Invoice\\Service')->getMock(); $invoiceServiceMock->expects($this->never())->method('payInvoiceWithCredits')->with($invoiceModel); $invoiceServiceMock->expects($this->never())->method('doBatchPayWithCredits'); $di = new \Box_Di(); $di['mod_service'] = $di->protect(function ($serviceName) use($clientServiceMock, $invoiceServiceMock) { if ($serviceName == 'Client') { return $clientServiceMock; } if ($serviceName == 'Invoice') { return $invoiceServiceMock; } }); $di['db'] = $dbMock; $adapterMock->setDi($di); $adminModel = new \Model_Admin(); $api_admin = new \Api_Handler($adminModel); $transaction_id = 1; $invoice_id = 22; $data = array('post' => array('ik_x_iid' => $invoice_id, 'ik_trn_id' => 2, 'ik_inv_st' => 'success', 'ik_am' => 1.0, 'ik_cur' => 'USD'), 'get' => array('bb_invoice_id' => $invoice_id)); $gateway_id = 1; $this->setExpectedException('Payment_Exception', 'IPN is duplicate'); $adapterMock->processTransaction($api_admin, $transaction_id, $data, $gateway_id); }