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); }
/** * @dataProvider datarecaptchaConfig */ public function testrecaptcha($config, $expected) { $di = new \Box_Di(); $di['mod_config'] = $di->protect(function () use($config) { return $config; }); $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->recaptcha(array()); $this->assertEquals($expected, $result); }
public function testTicket_get_list() { $simpleResultArr = array('list' => array(array('id' => 1))); $paginatorMock = $this->getMockBuilder('\\Box_Pagination')->disableOriginalConstructor()->getMock(); $paginatorMock->expects($this->atLeastOnce())->method('getAdvancedResultSet')->will($this->returnValue($simpleResultArr)); $serviceMock = $this->getMockBuilder('\\Box\\Mod\\Support\\Service')->setMethods(array('getSearchQuery', 'toApiArray'))->getMock(); $serviceMock->expects($this->atLeastOnce())->method('getSearchQuery')->will($this->returnValue(array('query', array()))); $serviceMock->expects($this->atLeastOnce())->method('toApiArray')->will($this->returnValue(array())); $model = new \Model_SupportTicket(); $model->loadBean(new \RedBeanPHP\OODBBean()); $dbMock = $this->getMockBuilder('\\Box_Database')->getMock(); $dbMock->expects($this->atLeastOnce())->method('getExistingModelById')->will($this->returnValue($model)); $di = new \Box_Di(); $di['pager'] = $paginatorMock; $di['db'] = $dbMock; $di['array_get'] = $di->protect(function (array $array, $key, $default = null) use($di) { return isset($array[$key]) ? $array[$key] : $default; }); $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(); $result = $this->clientApi->ticket_get_list($data); $this->assertInternalType('array', $result); }
public function testdeductFunds() { $di = new \Box_Di(); $clientBalance = new \Model_ClientBalance(); $clientBalance->loadBean(new \RedBeanPHP\OODBBean()); $dbMock = $this->getMockBuilder('\\Box_Database')->getMock(); $dbMock->expects($this->atLeastOnce())->method('dispense')->with('ClientBalance')->willReturn($clientBalance); $dbMock->expects($this->atLeastOnce())->method('store')->with($clientBalance); $di['db'] = $dbMock; $di['array_get'] = $di->protect(function (array $array, $key, $default = null) use($di) { return isset($array[$key]) ? $array[$key] : $default; }); $service = new \Box\Mod\Client\ServiceBalance(); $service->setDi($di); $clientModel = new \Model_Client(); $clientModel->loadBean(new \RedBeanPHP\OODBBean()); $description = 'Charged for product'; $amount = 5.55; $extra = array('rel_id' => 1); $result = $service->deductFunds($clientModel, $amount, $description, $extra); $this->assertInstanceOf('\\Model_ClientBalance', $result); $this->assertEquals(-$amount, $result->amount); $this->assertEquals($description, $result->description); $this->assertEquals($extra['rel_id'], $result->rel_id); $this->assertEquals('default', $result->type); }
public function testGet_list() { $clientApi = new \Box\Mod\Email\Api\Client(); $emailService = new \Box\Mod\Email\Service(); $willReturn = array("list" => array('id' => 1)); $pager = $this->getMockBuilder('Box_Pagination')->getMock(); $pager->expects($this->atLeastOnce())->method('getSimpleResultSet')->will($this->returnValue($willReturn)); $di = new \Box_Di(); $di['pager'] = $pager; $di['array_get'] = $di->protect(function (array $array, $key, $default = null) use($di) { return isset($array[$key]) ? $array[$key] : $default; }); $clientApi->setDi($di); $emailService->setDi($di); $service = $emailService; $clientApi->setService($service); $client = new \Model_Client(); $client->loadBean(new \RedBeanPHP\OODBBean()); $client->id = rand(1, 100); $clientApi->setIdentity($client); $result = $clientApi->get_list(array()); $this->assertInternalType('array', $result); $this->assertArrayHasKey('list', $result); $this->assertInternalType('array', $result['list']); }
public function testEvents() { $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->service->setDi($di); $result = $this->service->getSearchQuery(array()); $this->assertInternalType('array', $result); }
public function testlanguages() { $systemServiceMock = $this->getMockBuilder('\\Box\\Mod\\System\\Service')->getMock(); $systemServiceMock->expects($this->atLeastOnce())->method('getLanguages')->will($this->returnValue(array())); $di = new \Box_Di(); $di['mod_service'] = $di->protect(function ($name) use($systemServiceMock) { return $systemServiceMock; }); $this->api->setDi($di); $result = $this->api->languages(); $this->assertInternalType('array', $result); }
public function testbatch_connect() { $serviceMock = $this->getMockBuilder('\\Box\\Mod\\Hook\\Service')->getMock(); $serviceMock->expects($this->atLeastOnce())->method('batchConnect')->will($this->returnValue(1)); $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->api->setDi($di); $this->api->setService($serviceMock); $result = $this->api->batch_connect(array()); $this->assertNotEmpty($result); }
public function testgetPairs() { $service = new \Box\Mod\Page\Service(); $themeService = $this->getMockBuilder('\\Box\\Mod\\Theme\\Service')->getMock(); $themeService->expects($this->atLeastOnce())->method('getCurrentClientAreaThemeCode'); $di = new \Box_Di(); $di['mod_service'] = $di->protect(function () use($themeService) { return $themeService; }); $service->setDi($di); $result = $service->getPairs(); $this->assertInternalType('array', $result); }
public function testgetLastExecutionTime() { $systemServiceMock = $this->getMockBuilder('\\Box\\Mod\\System\\Service')->getMock(); $systemServiceMock->expects($this->atLeastOnce())->method('getParamValue')->will($this->returnValue('2012-12-12 12:12:12')); $di = new \Box_Di(); $di['mod_service'] = $di->protect(function ($name) use($systemServiceMock) { return $systemServiceMock; }); $service = new \Box\Mod\Cron\Service(); $service->setDi($di); $result = $service->getLastExecutionTime(); $this->assertInternalType('string', $result); }
public function testGet() { $clientService = $this->getMockBuilder('\\Box\\Mod\\Client\\Service')->getMock(); $clientService->expects($this->atLeastOnce())->method('toApiArray')->will($this->returnValue(array())); $di = new \Box_Di(); $di['mod_service'] = $di->protect(function () use($clientService) { return $clientService; }); $this->clientApi->setDi($di); $this->clientApi->setIdentity(new \Model_Client()); $result = $this->clientApi->get(); $this->assertInternalType('array', $result); }
public function testtop_songs() { $xmlString = "<note>\n<to>Tove</to>\n<from>Jani</from>\n<heading>Reminder</heading>\n<body>Don't forget me this weekend!</body>\n</note>"; $data = array(); $toolsMock = $this->getMockBuilder('\\Box_Tools')->getMock(); $toolsMock->expects($this->atLeastOnce())->method('file_get_contents')->willReturn($xmlString); $di = new \Box_Di(); $di['tools'] = $toolsMock; $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->top_songs($data); $this->assertInternalType('array', $result); }
public function testGetSearchQuery() { $service = new Box\Mod\Example\Service(); $di = new \Box_Di(); $di['array_get'] = $di->protect(function (array $array, $key, $default = null) use($di) { return isset($array[$key]) ? $array[$key] : $default; }); $service->setDi($di); $data = array('client_id' => 1); list($sql, $params) = $service->getSearchQuery($data); $this->assertInternalType('string', $sql); $this->assertInternalType('array', $params); $this->assertArrayHasKey(':client_id', $params); $this->assertEquals($params[':client_id'], $data['client_id']); }
public function testTlds() { $serviceMock = $this->getMockBuilder('\\Box\\Mod\\Servicedomain\\Service')->setMethods(array('tldToApiArray'))->getMock(); $serviceMock->expects($this->atLeastOnce())->method('tldToApiArray')->will($this->returnValue(array())); $this->guestApi->setService($serviceMock); $dbMock = $this->getMockBuilder('\\Box_Database')->getMock(); $dbMock->expects($this->atLeastOnce())->method('find')->will($this->returnValue(array(new \Model_Tld()))); $di = new \Box_Di(); $di['db'] = $dbMock; $di['array_get'] = $di->protect(function (array $array, $key, $default = null) use($di) { return isset($array[$key]) ? $array[$key] : $default; }); $this->guestApi->setDi($di); $result = $this->guestApi->tlds(array()); $this->assertInternalType('array', $result); $this->assertInternalType('array', $result[0]); }
public function testgetAmountInCents() { $model = new \Model_Invoice(); $model->loadBean(new RedBeanPHP\OODBBean()); $totalAmountWithTax = 12.23; $invoiceServiceMock = $this->getMockBuilder('\\Box\\Mod\\Invoice\\Service')->getMock(); $invoiceServiceMock->expects($this->atLeastOnce())->method('getTotalWithTax')->with($model)->willReturn($totalAmountWithTax); $di = new \Box_Di(); $di['mod_service'] = $di->protect(function ($serviceName) use($invoiceServiceMock) { if ($serviceName == 'Invoice') { return $invoiceServiceMock; } }); $adapter = new Payment_Adapter_Stripe($this->defaultConfig); $adapter->setDi($di); $result = $adapter->getAmountInCents($model); $this->assertEquals($totalAmountWithTax * 100, $result); }
public function testLogEvent() { $service = new \Box\Mod\Activity\Service(); $data = array('message' => 'Logging test message'); $di = new \Box_Di(); $db = $this->getMockBuilder('Box_Database')->getMock(); $model = new \Model_ActivitySystem(); $model->loadBean(new \RedBeanPHP\OODBBean()); $db->expects($this->atLeastOnce())->method('dispense')->will($this->returnValue($model)); $db->expects($this->atLeastOnce())->method('store')->will($this->returnValue(array())); $di['request'] = $this->getMockBuilder('Box_Request')->getMock(); $di['db'] = $db; $di['array_get'] = $di->protect(function (array $array, $key, $default = null) use($di) { return isset($array[$key]) ? $array[$key] : $default; }); $service->setDi($di); $result = $service->logEvent($data); $this->assertNull($result); }
public function testsetConfig() { $di = new \Box_Di(); $di['array_get'] = $di->protect(function (array $array, $key, $default = null) use($di) { return isset($array[$key]) ? $array[$key] : $default; }); $validatorMock = $this->getMockBuilder('\\Box_Validate')->getMock(); $validatorMock->expects($this->atLeastOnce())->method('checkRequiredParamsForArray'); $di['validator'] = $validatorMock; $config = array('id' => 123, 'key' => 'verysecrectKey', 'ipaddress' => '123.123.123.123'); $updatedConfig = array('id' => 123, 'key' => 'verysecrectKey', 'ipaddress' => '123.123.123.123', 'usertype' => 'admin', 'secure' => false, 'port' => NULL); $solusVmMock = $this->getMockBuilder('\\Box\\Mod\\Servicesolusvm\\SolusVM')->setMethods(array('getUrl', 'getSecureUrl'))->getMock(); $url = "http://" . $updatedConfig['ipaddress'] . ":5353/api/" . $updatedConfig['usertype'] . "/command.php"; $solusVmMock->expects($this->atLeastOnce())->method('getUrl')->with($updatedConfig)->willReturn($url); $solusVmMock->expects($this->never())->method('getSecureUrl'); $solusVmMock->setDi($di); $solusVmMock->setConfig($config); $this->assertEquals($url, $solusVmMock->getApiHost()); $this->assertEquals($config['id'], $solusVmMock->getApiID()); $this->assertEquals($config['key'], $solusVmMock->getApiKey()); }
public function testfree_tlds_ProductTypeIsNotHosting() { $di = new \Box_Di(); $validatorMock = $this->getMockBuilder('\\Box_Validate')->disableOriginalConstructor()->getMock(); $validatorMock->expects($this->atLeastOnce())->method('checkRequiredParamsForArray')->will($this->returnValue(null)); $di['validator'] = $validatorMock; $di['array_get'] = $di->protect(function (array $array, $key, $default = null) use($di) { return isset($array[$key]) ? $array[$key] : $default; }); $model = new \Model_Product(); $model->loadBean(new \RedBeanPHP\OODBBean()); $dbMock = $this->getMockBuilder('\\Box_Database')->getMock(); $dbMock->expects($this->atLeastOnce())->method('getExistingModelById')->will($this->returnValue($model)); $di['db'] = $dbMock; $serviceMock = $this->getMockBuilder('\\Box\\Mod\\Servicehosting\\Service')->getMock(); $serviceMock->expects($this->never())->method('getFreeTlds'); $this->api->setService($serviceMock); $this->api->setDi($di); $this->setExpectedException('\\Box_Exception', 'Product type is invalid'); $this->api->free_tlds(array('product_id' => 1)); }
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 testselect_AdminTheme() { $data = array('code' => 'pjw'); $themeMock = $this->getMockBuilder('\\Box\\Mod\\Theme\\Model\\Theme')->disableOriginalConstructor()->getMock(); $themeMock->expects($this->atLeastOnce())->method('isAdminAreaTheme')->will($this->returnValue(true)); $serviceMock = $this->getMockBuilder('\\Box\\Mod\\Theme\\Service')->getMock(); $serviceMock->expects($this->atLeastOnce())->method('getTheme')->will($this->returnValue($themeMock)); $systemServiceMock = $this->getMockBuilder('\\Box\\Mod\\System\\Service')->getMock(); $systemServiceMock->expects($this->atLeastOnce())->method('setParamValue')->with($this->equalTo('admin_theme')); $validatorMock = $this->getMockBuilder('\\Box_Validate')->disableOriginalConstructor()->getMock(); $validatorMock->expects($this->atLeastOnce())->method('checkRequiredParamsForArray')->will($this->returnValue(null)); $loggerMock = $this->getMockBuilder('\\Box_Log')->getMock(); $di = new \Box_Di(); $di['mod_service'] = $di->protect(function () use($systemServiceMock) { return $systemServiceMock; }); $di['logger'] = $loggerMock; $di['validator'] = $validatorMock; $this->api->setDi($di); $this->api->setService($serviceMock); $result = $this->api->select($data); $this->assertTrue($result); }
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); }
/** * @dataProvider paymentsAdapterProvider_withprocessTransaction */ public function testprocessTransaction_supportProcessTransaction($adapter) { $id = 1; $transactionModel = new \Model_Transaction(); $transactionModel->loadBean(new \RedBeanPHP\OODBBean()); $transactionModel->gateway_id = 2; $transactionModel->ipn = '{}'; $payGatewayModel = new \Model_PayGateway(); $payGatewayModel->loadBean(new \RedBeanPHP\OODBBean()); $dbMock = $this->getMockBuilder('\\Box_Database')->getMock(); $dbMock->expects($this->atLeastOnce())->method('load')->will($this->onConsecutiveCalls($transactionModel, $payGatewayModel)); $paymentAdapterMock = $this->getMockBuilder($adapter)->disableOriginalConstructor()->getMock(); $paymentAdapterMock->expects($this->atLeastOnce())->method('processTransaction'); $payGatewayService = $this->getMockBuilder('\\Box\\Mod\\Invoice\\ServicePayGateway')->getMock(); $payGatewayService->expects($this->atLeastOnce())->method('getPaymentAdapter')->will($this->returnValue($paymentAdapterMock)); $di = new \Box_Di(); $di['db'] = $dbMock; $di['mod_service'] = $di->protect(function () use($payGatewayService) { return $payGatewayService; }); $di['api_system'] = new \Api_Handler(new \Model_Admin()); $this->service->setDi($di); $this->service->processTransaction($id); }
public function testtoApiArray() { $cartModel = new \Model_Cart(); $cartModel->loadBean(new \RedBeanPHP\OODBBean()); $cartProductModel = new \Model_CartProduct(); $cartProductModel->loadBean(new \RedBeanPHP\OODBBean()); $serviceMock = $this->getMockBuilder('\\Box\\Mod\\Cart\\Service')->setMethods(array('getCartProducts', 'cartProductToApiArray'))->getMock(); $serviceMock->expects($this->atLeastOnce())->method('getCartProducts')->will($this->returnValue(array($cartProductModel))); $cartProductApiArray = array('total' => 1, 'discount' => 0); $serviceMock->expects($this->atLeastOnce())->method('cartProductToApiArray')->will($this->returnValue($cartProductApiArray)); $dbMock = $this->getMockBuilder('\\Box_Database')->getMock(); $currencyModel = new \Model_Currency(); $currencyModel->loadBean(new \RedBeanPHP\OODBBean()); $dbMock->expects($this->atLeastOnce())->method('getExistingModelById')->will($this->returnValue($currencyModel)); $currencyService = $this->getMockBuilder('\\Box\\Mod\\Currency\\Service')->getMock(); $currencyService->expects($this->atLeastOnce())->method('toApiArray')->will($this->returnValue(array())); $di = new \Box_Di(); $di['db'] = $dbMock; $di['mod_service'] = $di->protect(function () use($currencyService) { return $currencyService; }); $serviceMock->setDi($di); $result = $serviceMock->toApiArray($cartModel); $expected = array('promocode' => null, 'discount' => 0, 'total' => 1, 'items' => array($cartProductApiArray), 'currency' => array()); $this->assertInternalType('array', $result); $this->assertEquals($expected, $result); }
public function testdownloadAndExtractExceptionExtract() { $extensionMock = $this->getMockBuilder('\\Box_Extension')->getMock(); $extensionMock->expects($this->atLeastOnce())->method('getExtension')->will($this->returnValue(array('download_url' => 'www.boxbillig.com'))); $curlMock = $this->getMockBuilder('\\Box_Curl')->disableOriginalConstructor()->getMock(); $curlMock->expects($this->atLeastOnce())->method('downloadTo'); $zipArchiveMock = $this->getMockBuilder('ZipArchive')->getMock(); $zipArchiveMock->expects($this->atLeastOnce())->method('open')->will($this->returnValue(false)); $di = new \Box_Di(); $di['extension'] = $extensionMock; $di['curl'] = $di->protect(function ($name) use($curlMock) { return $curlMock; }); $di['zip_archive'] = $zipArchiveMock; $this->service->setDi($di); $this->setExpectedException('\\Box_Exception', 'Could not extract extension zip file'); $this->service->downloadAndExtract('mod', 'extensionId'); }
public function testpromo_get_list() { $serviceMock = $this->getMockBuilder('\\Box\\Mod\\Product\\Service')->getMock(); $serviceMock->expects($this->atLeastOnce())->method('getPromoSearchQuery')->will($this->returnValue(array('sqlString', array()))); $pagerMock = $this->getMockBuilder('\\Box_Pagination')->getMock(); $pagerMock->expects($this->atLeastOnce())->method('getSimpleResultSet')->will($this->returnValue(array('list' => array()))); $di = new \Box_Di(); $di['pager'] = $pagerMock; $di['array_get'] = $di->protect(function (array $array, $key, $default = null) use($di) { return isset($array[$key]) ? $array[$key] : $default; }); $this->api->setService($serviceMock); $this->api->setDi($di); $result = $this->api->promo_get_list(array()); $this->assertInternalType('array', $result); }
public function testsendMail() { $dbMock = $this->getMockBuilder('\\Box_Database')->getMock(); $queueEmail = new \Model_ModEmailQueue(); $queueEmail->loadBean(new \RedBeanPHP\OODBBean()); $dbMock->expects($this->atLeastOnce())->method('dispense')->with('ModEmailQueue')->willReturn($queueEmail); $dbMock->expects($this->atLeastOnce())->method('store'); $licenseMock = $this->getMockBuilder('\\Box_License')->getMock(); $licenseMock->expects($this->atLeastOnce())->method('isPro')->will($this->returnValue(false)); $modMock = $this->getMockBuilder('\\Box_Mod')->disableOriginalConstructor()->getMock(); $modMock->expects($this->atLeastOnce())->method('getConfig')->will($this->returnValue(array('cancel_after' => 1))); $mailMock = $this->getMockBuilder('\\Box_Mail')->disableOriginalConstructor()->getMock(); $di = new \Box_Di(); $di['db'] = $dbMock; $di['mail'] = $mailMock; $di['logger'] = $this->getMockBuilder('Box_Log')->getMock(); $di['mod'] = $di->protect(function () use($modMock) { return $modMock; }); $di['license'] = $licenseMock; $di['array_get'] = $di->protect(function (array $array, $key, $default = null) use($di) { return isset($array[$key]) ? $array[$key] : $default; }); $service = new \Box\Mod\Email\Service(); $service->setDi($di); $to = '*****@*****.**'; $from = '*****@*****.**'; $subject = 'Important message'; $content = 'content'; $result = $service->sendMail($to, $from, $subject, $content); $this->assertTrue($result); }
public function testCreateCurrency() { $service = new \Box\Mod\Currency\Service(); $code = 'EUR'; $format = '€{{price}}'; $systemService = $this->getMockBuilder('\\Box\\Mod\\System\\Service')->setMethods(array('checkLimits'))->getMock(); $systemService->expects($this->atLeastOnce())->method('checkLimits')->will($this->returnValue(null)); $currencyModel = new \Model_Tld(); $currencyModel->loadBean(new \RedBeanPHP\OODBBean()); $dbMock = $this->getMockBuilder('\\Box_Database')->getMock(); $dbMock->expects($this->atLeastOnce())->method('store')->will($this->returnValue(rand(1, 100))); $dbMock->expects($this->atLeastOnce())->method('dispense')->will($this->returnValue($currencyModel)); $di = new \Box_Di(); $di['logger'] = new \Box_Log(); $di['db'] = $dbMock; $di['mod_service'] = $di->protect(function () use($systemService) { return $systemService; }); $service->setDi($di); $result = $service->createCurrency($code, $format, 'Euros', 0.6); $this->assertInternalType('string', $result); $this->assertEquals(strlen($result), 3); $this->assertEquals($result, $code); }
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); }
/** * @expectedException \Box_Exception */ public function testCategory_getNotFoundBySlug() { $guestApi = new \Box\Mod\Kb\Api\Guest(); $kbService = $this->getMockBuilder('Box\\Mod\\Kb\\Service')->setMethods(array('findCategoryById', 'hitView', 'categoryToApiArray', 'findCategoryBySlug'))->getMock(); $kbService->expects($this->never())->method('findCategoryById')->will($this->returnValue(new \Model_KbArticleCategory())); $kbService->expects($this->atLeastOnce())->method('findCategoryBySlug')->will($this->returnValue(null)); $kbService->expects($this->never())->method('categoryToApiArray')->will($this->returnValue(array())); $guestApi->setService($kbService); $data = array('slug' => 'article-slug'); $di = new \Box_Di(); $di['array_get'] = $di->protect(function (array $array, $key, $default = null) use($di) { return isset($array[$key]) ? $array[$key] : $default; }); $guestApi->setDi($di); $result = $guestApi->category_get($data); $this->assertInternalType('array', $result); }