3.8.1
This commit is contained in:
66
tests/base/Domain/RSA_Test.php
Normal file
66
tests/base/Domain/RSA_Test.php
Normal file
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
/**
|
||||
* PhalApi_Base\Domain\RSA_Test
|
||||
*
|
||||
* 针对 ../src/base/Domain/RSA.php Base\Domain\RSA 类的PHPUnit单元测试
|
||||
*
|
||||
* @author: dogstar 20200414
|
||||
*/
|
||||
|
||||
namespace tests\Base\Domain;
|
||||
use Base\Domain\RSA;
|
||||
|
||||
class PhpUnderControl_BaseDomainRSA_Test extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
public $baseDomainRSA;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$domain = new \Base\Domain\Apps();
|
||||
$domain->addApp('name_rsa', 'app_key_rsa', 'xxx');
|
||||
|
||||
$this->baseDomainRSA = new \Base\Domain\RSA('app_key_rsa');
|
||||
}
|
||||
|
||||
protected function tearDown()
|
||||
{
|
||||
// 输出本次单元测试所执行的SQL语句
|
||||
// var_dump(\PhalApi\DI()->tracer->getSqls());
|
||||
|
||||
// 输出本次单元测试所涉及的追踪埋点
|
||||
// var_dump(\PhalApi\DI()->tracer->getStack());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @group testEncrypt
|
||||
*/
|
||||
public function testEncrypt()
|
||||
{
|
||||
$data = 'pro';
|
||||
|
||||
$rs = $this->baseDomainRSA->encrypt($data);
|
||||
|
||||
$this->assertTrue(is_string($rs));
|
||||
$this->assertNotEmpty($rs);
|
||||
|
||||
$deRs = $this->baseDomainRSA->decrypt($rs);
|
||||
$this->assertEquals('pro', $deRs);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @group testDecrypt
|
||||
*/
|
||||
public function testDecrypt()
|
||||
{
|
||||
$data = 'mmmmm';
|
||||
|
||||
$rs = $this->baseDomainRSA->decrypt($data);
|
||||
|
||||
$this->assertNull($rs);
|
||||
}
|
||||
|
||||
}
|
||||
143
tests/base/Domain/Redis_Test.php
Normal file
143
tests/base/Domain/Redis_Test.php
Normal file
@@ -0,0 +1,143 @@
|
||||
<?php
|
||||
/**
|
||||
* PhalApi_Base\Domain\Redis_Test
|
||||
*
|
||||
* 针对 ../src/base/Domain/Redis.php Base\Domain\Redis 类的PHPUnit单元测试
|
||||
*
|
||||
* @author: dogstar 20200717
|
||||
*/
|
||||
|
||||
namespace tests\Base\Domain;
|
||||
use Base\Domain\Redis;
|
||||
|
||||
class PhpUnderControl_BaseDomainRedis_Test extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
public $baseDomainRedis;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->baseDomainRedis = new \Base\Domain\Redis();
|
||||
}
|
||||
|
||||
protected function tearDown()
|
||||
{
|
||||
// 输出本次单元测试所执行的SQL语句
|
||||
// var_dump(\PhalApi\DI()->tracer->getSqls());
|
||||
|
||||
// 输出本次单元测试所涉及的追踪埋点
|
||||
// var_dump(\PhalApi\DI()->tracer->getStack());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @group testGet
|
||||
*/
|
||||
public function testGet()
|
||||
{
|
||||
$key = 'unittest';
|
||||
|
||||
$this->baseDomainRedis->set($key, '2020');
|
||||
|
||||
$rs = $this->baseDomainRedis->get($key);
|
||||
|
||||
$this->assertEquals('2020', $rs);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group testSet
|
||||
*/
|
||||
public function testSet()
|
||||
{
|
||||
$key = 'testSet_pro';
|
||||
$value = 'pro';
|
||||
$expire = null;
|
||||
|
||||
$rs = $this->baseDomainRedis->set($key, $value, $expire);
|
||||
|
||||
$key = 'testSet_pro_1';
|
||||
$value = 'pro';
|
||||
$expire = 0;
|
||||
|
||||
$rs = $this->baseDomainRedis->set($key, $value, $expire);
|
||||
|
||||
$key = 'testSet_pro_2';
|
||||
$value = 'pro';
|
||||
$expire = 10;
|
||||
|
||||
$rs = $this->baseDomainRedis->set($key, $value, $expire);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group testIncr
|
||||
*/
|
||||
public function testIncr()
|
||||
{
|
||||
$key = 'testIncr_pro';
|
||||
|
||||
$rs = $this->baseDomainRedis->incr($key);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group testIncrBy
|
||||
*/
|
||||
public function testIncrBy()
|
||||
{
|
||||
$key = 'testIncr_pro';
|
||||
$value = 10;
|
||||
|
||||
$rs = $this->baseDomainRedis->incrBy($key, $value);
|
||||
|
||||
$this->assertGreaterThan($value, $this->baseDomainRedis->get($key));
|
||||
}
|
||||
|
||||
/**
|
||||
* @group testDecr
|
||||
*/
|
||||
public function testDecr()
|
||||
{
|
||||
$key = 'testDecr_pro';
|
||||
|
||||
$rs = $this->baseDomainRedis->decr($key);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group testDecrBy
|
||||
*/
|
||||
public function testDecrBy()
|
||||
{
|
||||
$key = 'testDecr';
|
||||
$value = '10';
|
||||
|
||||
$rs = $this->baseDomainRedis->decrBy($key, $value);
|
||||
|
||||
$this->assertLessThan(0, $this->baseDomainRedis->get($key));
|
||||
}
|
||||
|
||||
/**
|
||||
* @group testDel
|
||||
*/
|
||||
public function testDel()
|
||||
{
|
||||
$key = 'xxxxx_pro';
|
||||
|
||||
$rs = $this->baseDomainRedis->del($key);
|
||||
|
||||
$this->assertTrue(is_int($rs));
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @group testExists
|
||||
*/
|
||||
public function testExists()
|
||||
{
|
||||
$key = 'hhhhhh';
|
||||
|
||||
$rs = $this->baseDomainRedis->exists($key);
|
||||
|
||||
$this->assertEquals(0, $rs);
|
||||
}
|
||||
|
||||
}
|
||||
210
tests/base/Domain/Rights_Test.php
Normal file
210
tests/base/Domain/Rights_Test.php
Normal file
@@ -0,0 +1,210 @@
|
||||
<?php
|
||||
/**
|
||||
* PhalApi_Base\Domain\Rights_Test
|
||||
*
|
||||
* 针对 ../src/app/Domain/Rights.php Base\Domain\Rights 类的PHPUnit单元测试
|
||||
*
|
||||
* @author: dogstar 20200408
|
||||
*/
|
||||
|
||||
namespace tests\Base\Domain;
|
||||
use Base\Domain\Rights;
|
||||
|
||||
class PhpUnderControl_AppDomainRights_Test extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
public $appDomainRights;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->appDomainRights = new \Base\Domain\Rights();
|
||||
}
|
||||
|
||||
protected function tearDown()
|
||||
{
|
||||
// 输出本次单元测试所执行的SQL语句
|
||||
// var_dump(\PhalApi\DI()->tracer->getSqls());
|
||||
|
||||
// 输出本次单元测试所涉及的追踪埋点
|
||||
// var_dump(\PhalApi\DI()->tracer->getStack());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @group testCheckAppRights
|
||||
*/
|
||||
public function testCheckAppRights()
|
||||
{
|
||||
$appKey = 'xxxx';
|
||||
$service = 'App.HH.YY';
|
||||
|
||||
$rs = $this->appDomainRights->checkAppRights($appKey, $service);
|
||||
|
||||
$this->assertTrue($rs);
|
||||
}
|
||||
|
||||
// 整个流程的测试,从创建开发者账号、创建应用,到分配接口权限,检测权限,步步为营
|
||||
public function testCheckAppRightsAllInOne()
|
||||
{
|
||||
$appKey = 'rights_app_key';
|
||||
$service = 'App.AAA.BBBRights';
|
||||
|
||||
// 往回走,最终是true,测试配置
|
||||
$rs = $this->appDomainRights->checkAppRights($appKey, $service);
|
||||
$this->assertTrue($rs);
|
||||
|
||||
// 账号
|
||||
$userDomain = new \Base\Domain\User();
|
||||
$uid = $userDomain->register('rights_user', '123456', '', '', '', 0, '', 100);
|
||||
// 应用
|
||||
$appDomain = new \Base\Domain\Apps();
|
||||
$appDomain->addApp('test', $appKey, 'hjkghjhj', 0, $uid, '', 1);
|
||||
|
||||
// 账号类型权限-开
|
||||
$this->appDomainRights->assignRightsForDevTypeOrNot($service, 100);
|
||||
$rs = $this->appDomainRights->checkAppRights($appKey, $service);
|
||||
$this->assertTrue($rs);
|
||||
// 账号类型权限-关
|
||||
$this->appDomainRights->assignRightsForDevTypeOrNot($service, 100);
|
||||
$rs = $this->appDomainRights->checkAppRights($appKey, $service);
|
||||
$this->assertFalse($rs);
|
||||
|
||||
// 开发者账号权限-开
|
||||
$this->appDomainRights->createNewRightsRule($service, 0, $uid, '', true);
|
||||
$rs = $this->appDomainRights->checkAppRights($appKey, $service);
|
||||
$this->assertTrue($rs);
|
||||
// 开发者-关
|
||||
|
||||
// 最后,app_key-关
|
||||
$this->appDomainRights->createNewRightsRule($service, 0, 0, $appKey, false);
|
||||
$rs = $this->appDomainRights->checkAppRights($appKey, $service);
|
||||
$this->assertFalse($rs);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group testAssignRights
|
||||
*/
|
||||
//public function testAssignRights()
|
||||
//{
|
||||
// $appKey = '';
|
||||
// $service = '';
|
||||
|
||||
// $rs = $this->appDomainRights->assignRights($appKey, $service);
|
||||
//}
|
||||
|
||||
///**
|
||||
// * @group testRemoveRights
|
||||
// */
|
||||
//public function testRemoveRights()
|
||||
//{
|
||||
// $appKey = '';
|
||||
// $service = '';
|
||||
// $adminUid = null;
|
||||
|
||||
// $rs = $this->appDomainRights->removeRights($appKey, $service, $adminUid);
|
||||
//}
|
||||
|
||||
/**
|
||||
* @group testGetRightsForApp
|
||||
*/
|
||||
//public function testGetRightsForApp()
|
||||
//{
|
||||
// $appKey = 'xxxx';
|
||||
|
||||
// $rs = $this->appDomainRights->getRightsForApp($appKey);
|
||||
//}
|
||||
|
||||
/**
|
||||
* @group testListAllRightsForDeveloperType
|
||||
*/
|
||||
public function testListAllRightsForDeveloperType()
|
||||
{
|
||||
$rs = $this->appDomainRights->listAllRightsForDeveloperType();
|
||||
|
||||
$this->assertNotEmpty($rs['items']);
|
||||
$this->assertNotEmpty($rs['dev_types']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group testGetRightsForDevApp
|
||||
*/
|
||||
public function testGetRightsForDevApp()
|
||||
{
|
||||
$uid = '1';
|
||||
$appKey = 'xxx';
|
||||
|
||||
$rs = $this->appDomainRights->getRightsForDevApp($uid, $appKey);
|
||||
|
||||
$this->assertTrue(is_array($rs));
|
||||
}
|
||||
|
||||
/**
|
||||
* @group testAssignRightsForDevTypeOrNot
|
||||
*/
|
||||
public function testAssignRightsForDevTypeOrNot()
|
||||
{
|
||||
$rightsService = 'App.KK.LL';
|
||||
$memberType = 100;
|
||||
|
||||
$rs = $this->appDomainRights->assignRightsForDevTypeOrNot($rightsService, $memberType);
|
||||
|
||||
$this->assertTrue(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group testSearchRightsList
|
||||
*/
|
||||
public function testSearchRightsList()
|
||||
{
|
||||
$rightsService = 'App';
|
||||
$memberType = 100;
|
||||
$userId = 1;
|
||||
$appKey = 'abc';
|
||||
$page = 1;
|
||||
$perpage = 5;
|
||||
|
||||
$rs = $this->appDomainRights->searchRightsList($rightsService, $memberType, $userId, $appKey, $page, $perpage);
|
||||
|
||||
$this->assertNotEmpty($rs['dev_types']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group testAssignRightsOrNot
|
||||
*/
|
||||
public function testAssignRightsOrNot()
|
||||
{
|
||||
$id = '1';
|
||||
|
||||
$rs = $this->appDomainRights->assignRightsOrNot($id);
|
||||
|
||||
$this->assertTrue(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group testDelelteRightsRule
|
||||
*/
|
||||
public function testDelelteRightsRule()
|
||||
{
|
||||
$id = '9999';
|
||||
|
||||
$rs = $this->appDomainRights->delelteRightsRule($id);
|
||||
|
||||
$this->assertTrue(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group testCreateNewRightsRule
|
||||
*/
|
||||
public function testCreateNewRightsRule()
|
||||
{
|
||||
$rightsService = 'App.xxxxx.yyyyyy';
|
||||
$memberType = 100;
|
||||
$userId = 0;
|
||||
$appKey = '';
|
||||
$isAllow = true;
|
||||
|
||||
$rs = $this->appDomainRights->createNewRightsRule($rightsService, $memberType, $userId, $appKey, $isAllow);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user