mirror of
https://github.com/FOSSBilling/FOSSBilling.git
synced 2026-11-09 13:36:07 +09:00
notification message is stored at session variable and shown via JS create api call system.guest_get_pending_messages to fetch pending messages. create partial template: partial_pending_messages.phtml
251 lines
7.1 KiB
PHP
251 lines
7.1 KiB
PHP
<?php
|
|
|
|
|
|
namespace Box\Mod\System\Api;
|
|
|
|
|
|
class GuestTest extends \PHPUnit_Framework_TestCase {
|
|
/**
|
|
* @var \Box\Mod\System\Api\Guest
|
|
*/
|
|
protected $api = null;
|
|
|
|
public function setup()
|
|
{
|
|
$this->api= new \Box\Mod\System\Api\Guest();
|
|
}
|
|
|
|
public function testgetDi()
|
|
{
|
|
$di = new \Box_Di();
|
|
$this->api->setDi($di);
|
|
$getDi = $this->api->getDi();
|
|
$this->assertEquals($di, $getDi);
|
|
}
|
|
|
|
public function testversion()
|
|
{
|
|
$servuceMock = $this->getMockBuilder('\Box\Mod\System\Service')->getMock();
|
|
$servuceMock->expects($this->atLeastOnce())
|
|
->method('getVersion')
|
|
->will($this->returnValue(\Box_Version::VERSION));
|
|
|
|
$this->api->setService($servuceMock);
|
|
$result = $this->api->version();
|
|
$this->assertInternalType('string', $result);
|
|
$this->assertNotEmpty($result);
|
|
}
|
|
|
|
public function testcompany()
|
|
{
|
|
$data = array(
|
|
|
|
);
|
|
$servuceMock = $this->getMockBuilder('\Box\Mod\System\Service')->getMock();
|
|
$servuceMock->expects($this->atLeastOnce())
|
|
->method('getCompany')
|
|
->will($this->returnValue(array()));
|
|
|
|
$this->api->setService($servuceMock);
|
|
|
|
$result = $this->api->company($data);
|
|
$this->assertInternalType('array', $result);
|
|
}
|
|
|
|
public function testphone_codes()
|
|
{
|
|
$data = array(
|
|
|
|
);
|
|
$servuceMock = $this->getMockBuilder('\Box\Mod\System\Service')->getMock();
|
|
$servuceMock->expects($this->atLeastOnce())
|
|
->method('getPhoneCodes')
|
|
->will($this->returnValue(array()));
|
|
|
|
$this->api->setService($servuceMock);
|
|
|
|
$result = $this->api->phone_codes($data);
|
|
$this->assertInternalType('array', $result);
|
|
}
|
|
|
|
public function teststates()
|
|
{
|
|
$servuceMock = $this->getMockBuilder('\Box\Mod\System\Service')->getMock();
|
|
$servuceMock->expects($this->atLeastOnce())
|
|
->method('getStates')
|
|
->will($this->returnValue(array()));
|
|
|
|
$this->api->setService($servuceMock);
|
|
|
|
$result = $this->api->states();
|
|
$this->assertInternalType('array', $result);
|
|
}
|
|
|
|
public function testcountries_eunion()
|
|
{
|
|
$servuceMock = $this->getMockBuilder('\Box\Mod\System\Service')->getMock();
|
|
$servuceMock->expects($this->atLeastOnce())
|
|
->method('getEuCountries')
|
|
->will($this->returnValue(array()));
|
|
|
|
$this->api->setService($servuceMock);
|
|
|
|
$result = $this->api->countries_eunion();
|
|
$this->assertInternalType('array', $result);
|
|
}
|
|
|
|
public function testcountries()
|
|
{
|
|
$servuceMock = $this->getMockBuilder('\Box\Mod\System\Service')->getMock();
|
|
$servuceMock->expects($this->atLeastOnce())
|
|
->method('getCountries')
|
|
->will($this->returnValue(array()));
|
|
|
|
$this->api->setService($servuceMock);
|
|
|
|
$result = $this->api->countries();
|
|
$this->assertInternalType('array', $result);
|
|
}
|
|
|
|
public function testparam()
|
|
{
|
|
$data = array('key' => 'keyValue');
|
|
|
|
$servuceMock = $this->getMockBuilder('\Box\Mod\System\Service')->getMock();
|
|
$servuceMock->expects($this->atLeastOnce())
|
|
->method('getPublicParamValue')
|
|
->will($this->returnValue('paramValue'));
|
|
|
|
$this->api->setService($servuceMock);
|
|
|
|
$result = $this->api->param($data);
|
|
$this->assertInternalType('string', $result);
|
|
}
|
|
|
|
public function testparamMissingKeyParam()
|
|
{
|
|
$data = array();
|
|
|
|
$this->setExpectedException('\Box_Exception', 'Parameter key is missing');
|
|
$this->api->param($data);
|
|
}
|
|
|
|
public function periods()
|
|
{
|
|
$result = $this->api->periods();
|
|
$this->assertInternalType('array', $result);
|
|
}
|
|
|
|
public function testperiod_title()
|
|
{
|
|
$data = array('code' => 'periodCode');
|
|
|
|
$servuceMock = $this->getMockBuilder('\Box\Mod\System\Service')->getMock();
|
|
$servuceMock->expects($this->atLeastOnce())
|
|
->method('getPeriod')
|
|
->will($this->returnValue('periodTtitleValue'));
|
|
|
|
$this->api->setService($servuceMock);
|
|
|
|
$result = $this->api->period_title($data);
|
|
$this->assertInternalType('string', $result);
|
|
}
|
|
|
|
public function testperiod_titleMissingCode()
|
|
{
|
|
$data = array();
|
|
$expected = '-';
|
|
|
|
$result = $this->api->period_title($data);
|
|
$this->assertInternalType('string', $result);
|
|
$this->assertEquals($expected, $result);
|
|
}
|
|
|
|
public function testcurrent_url()
|
|
{
|
|
$requestMock = $this->getMockBuilder('\Box_Request')->getMock();
|
|
$requestMock->expects($this->atLeastOnce())
|
|
->method('getURI')
|
|
->will($this->returnValue('StringTypeUrl'));
|
|
|
|
$di = new \Box_Di();
|
|
$di['request'] = $requestMock;
|
|
|
|
$this->api->setDi($di);
|
|
$result = $this->api->current_url();
|
|
$this->assertInternalType('string', $result);
|
|
}
|
|
|
|
public function testtemplate_exists()
|
|
{
|
|
$data = array(
|
|
'file' => 'testing.txt',
|
|
);
|
|
|
|
$servuceMock = $this->getMockBuilder('\Box\Mod\System\Service')->getMock();
|
|
$servuceMock->expects($this->atLeastOnce())
|
|
->method('templateExists')
|
|
->will($this->returnValue(true));
|
|
|
|
$this->api->setService($servuceMock);
|
|
|
|
$result = $this->api->template_exists($data);
|
|
$this->assertInternalType('bool', $result);
|
|
$this->assertTrue($result);
|
|
}
|
|
|
|
public function testtemplate_existsFileParamMissing()
|
|
{
|
|
$data = array(
|
|
);
|
|
|
|
$result = $this->api->template_exists($data);
|
|
$this->assertInternalType('bool', $result);
|
|
$this->assertFalse($result);
|
|
}
|
|
|
|
public function testlocale()
|
|
{
|
|
$setLang = 'FR';
|
|
$di = new \Box_Di();
|
|
|
|
$cookieMock = $this->getMockBuilder('\Box_Cookie')->getMock();
|
|
$cookieMock->expects($this->atLeastOnce())
|
|
->method('has')
|
|
->will($this->returnValue(true));
|
|
$cookieMock->expects($this->atLeastOnce())
|
|
->method('get')
|
|
->with('BBLANG')
|
|
->will($this->returnValue($setLang));
|
|
|
|
$di['cookie'] = $cookieMock;
|
|
$di['config'] = array('locale' => 'EN');
|
|
|
|
|
|
$this->api->setDi($di);
|
|
|
|
$result = $this->api->locale();
|
|
$this->assertInternalType('string', $result);
|
|
$this->assertNotEmpty($result);
|
|
$this->assertEquals($setLang, $result);
|
|
}
|
|
|
|
public function testget_pending_messages()
|
|
{
|
|
$serviceMock = $this->getMockBuilder('\Box\Mod\System\Service')->getMock();
|
|
$messageArr = array('Important message to user');
|
|
$serviceMock->expects($this->atLeastOnce())
|
|
->method('getPendingMessages')
|
|
->willReturn($messageArr);
|
|
|
|
$serviceMock->expects($this->atLeastOnce())
|
|
->method('clearPendingMessages');
|
|
|
|
$this->api->setService($serviceMock);
|
|
$result = $this->api->get_pending_messages();
|
|
$this->assertInternalType('array', $result);
|
|
$this->assertEquals($messageArr, $result);
|
|
}
|
|
|
|
}
|
|
|