3.8.1
This commit is contained in:
109
tests/platform/Api/Apps_Test.php
Normal file
109
tests/platform/Api/Apps_Test.php
Normal file
@@ -0,0 +1,109 @@
|
||||
<?php
|
||||
/**
|
||||
* PhalApi_Platform\Api\Apps_Test
|
||||
*
|
||||
* 针对 ../src/admin/Api/Apps.php Platform\Api\Apps 类的PHPUnit单元测试
|
||||
*
|
||||
* @author: dogstar 20200112
|
||||
*/
|
||||
|
||||
namespace tests\Platform\Api;
|
||||
use Platform\Api\Apps;
|
||||
use Base\Domain\Apps as AppsDomain;
|
||||
use PhalApi\Helper\TestRunner;
|
||||
|
||||
class PhpUnderControl_PlatformApiApps_Test extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
public $adminApiApps;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
\PhalApi\DI()->context->setUid(888);
|
||||
|
||||
$this->adminApiApps = new \Platform\Api\Apps();
|
||||
}
|
||||
|
||||
protected function tearDown()
|
||||
{
|
||||
// 输出本次单元测试所执行的SQL语句
|
||||
// var_dump(\PhalApi\DI()->tracer->getSqls());
|
||||
|
||||
// 输出本次单元测试所涉及的追踪埋点
|
||||
// var_dump(\PhalApi\DI()->tracer->getStack());
|
||||
|
||||
\PhalApi\DI()->context->setUid(0);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @group testGetRules
|
||||
*/
|
||||
public function testGetRules()
|
||||
{
|
||||
$rs = $this->adminApiApps->getRules();
|
||||
$this->assertTrue(is_array($rs));
|
||||
}
|
||||
|
||||
/**
|
||||
* @group testGetAppList
|
||||
*/
|
||||
public function testGetAppList()
|
||||
{
|
||||
$domain = new AppsDomain();
|
||||
$domain->addApp('appName_testGetAppList', 'appKey_testGetAppListplatform', 'appSecret_123_platform', 0, 888);
|
||||
$domain->addApp('appName_testGetAppList', 'appKey_testGetAppListplatform22', 'appSecret_123_platform', 0, 888);
|
||||
|
||||
$url = 's=Platform.Apps.GetAppList';
|
||||
$rs = TestRunner::go($url);
|
||||
|
||||
$this->assertNotEmpty($rs['list']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group testAddApp
|
||||
*/
|
||||
public function testAddApp()
|
||||
{
|
||||
|
||||
$url = 's=Platform.Apps.AddApp&app_key=testAddApp&app_secret=xxx&appName=testAddApp&app_owner=hhhhhhhh&apply_reason=test';
|
||||
$rs = TestRunner::go($url);
|
||||
|
||||
$this->assertTrue($rs['is_add']);
|
||||
|
||||
return $rs['app_key'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @group testAddApp
|
||||
* @depends testAddApp
|
||||
*/
|
||||
public function testGetMyApp($appkey)
|
||||
{
|
||||
|
||||
$url = 's=Platform.Apps.GetMyAppInfo&app_key='.$appkey.'&app_secret=xxx&appName=testAddApp&app_owner=hhhhhhhh';
|
||||
$rs = TestRunner::go($url);
|
||||
|
||||
$this->assertNotEmpty($rs['info']);
|
||||
$this->assertEquals('testAddApp', $rs['info']['app_name']);
|
||||
}
|
||||
|
||||
/**
|
||||
*/
|
||||
public function testEditApp()
|
||||
{
|
||||
|
||||
$url = 's=Platform.Apps.AddApp&app_key=testAddApp&app_secret=xxx&appName=testAddApp&app_owner=hhhhhhhh&apply_reason=test';
|
||||
$rs = TestRunner::go($url);
|
||||
|
||||
$this->assertTrue($rs['is_add']);
|
||||
|
||||
$url = 's=Platform.Apps.EditMyApp&&app_secret=xxx&appName=testAddApp&app_owner=hhhhhhhh22&app_icon=1234567&apply_reason=99999&app_key='.$rs['app_key'];
|
||||
$rs = TestRunner::go($url);
|
||||
|
||||
$this->assertTrue($rs['is_updated']);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
69
tests/platform/Api/Rigths_Test.php
Normal file
69
tests/platform/Api/Rigths_Test.php
Normal file
@@ -0,0 +1,69 @@
|
||||
<?php
|
||||
/**
|
||||
* PhalApi_Platform\Api\Rights_Test
|
||||
*
|
||||
* 针对 ../src/platform/Api/Rights.php Platform\Api\Rights 类的PHPUnit单元测试
|
||||
*
|
||||
* @author: dogstar 20200408
|
||||
*/
|
||||
|
||||
namespace tests\Platform\Api;
|
||||
use Platform\Api\Rights;
|
||||
use PhalApi\Helper\TestRunner;
|
||||
use Base\Domain\Apps as AppsDomain;
|
||||
|
||||
class PhpUnderControl_PlatformApiRights_Test extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
public $platformApiRights;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
\PhalApi\DI()->context->setUid(8889);
|
||||
|
||||
$this->platformApiRights = new \Platform\Api\Rights();
|
||||
}
|
||||
|
||||
protected function tearDown()
|
||||
{
|
||||
// 输出本次单元测试所执行的SQL语句
|
||||
// var_dump(\PhalApi\DI()->tracer->getSqls());
|
||||
|
||||
// 输出本次单元测试所涉及的追踪埋点
|
||||
// var_dump(\PhalApi\DI()->tracer->getStack());
|
||||
|
||||
\PhalApi\DI()->context->setUid(0);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @group testGetRules
|
||||
*/
|
||||
public function testGetRules()
|
||||
{
|
||||
$rs = $this->platformApiRights->getRules();
|
||||
$this->assertTrue(is_array($rs));
|
||||
}
|
||||
|
||||
/**
|
||||
* @group testGetAllAppApis
|
||||
*/
|
||||
public function testGetAllAppApis()
|
||||
{
|
||||
$domain = new AppsDomain();
|
||||
$domain->addApp('appName_testGetAppList', 'appKey_testGetAppListplatform8889', 'appSecret_123_platform', 0, 8889);
|
||||
|
||||
$url = 's=Platform.Rights.GetAllAppApis&app_key=appKey_testGetAppListplatform8889';
|
||||
$rs = TestRunner::go($url);
|
||||
// var_dump($rs);
|
||||
|
||||
$this->assertNotEmpty($rs['apis']);
|
||||
foreach ($rs['apis'] as $it) {
|
||||
$this->assertArrayHasKey('service', $it);
|
||||
$this->assertArrayHasKey('title', $it);
|
||||
$this->assertArrayHasKey('is_allow', $it);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
137
tests/platform/Api/User_Test.php
Normal file
137
tests/platform/Api/User_Test.php
Normal file
@@ -0,0 +1,137 @@
|
||||
<?php
|
||||
/**
|
||||
* PhalApi_App\Api\User_Test
|
||||
*
|
||||
* 针对 ../src/app/Api/User.php App\Api\User 类的PHPUnit单元测试
|
||||
*
|
||||
* @author: dogstar 20191219
|
||||
*/
|
||||
|
||||
namespace tests\Platform\Api;
|
||||
use Platform\Api\User;
|
||||
use PhalApi\Helper\TestRunner;
|
||||
|
||||
class PhpUnderControl_PlatformApiUser_Test extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
public $appApiUser;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->appApiUser = new \Platform\Api\User();
|
||||
}
|
||||
|
||||
protected function tearDown()
|
||||
{
|
||||
// 输出本次单元测试所执行的SQL语句
|
||||
// var_dump(\PhalApi\DI()->tracer->getSqls());
|
||||
|
||||
// 输出本次单元测试所涉及的追踪埋点
|
||||
// var_dump(\PhalApi\DI()->tracer->getStack());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @group testGetRules
|
||||
*/
|
||||
public function testGetRules()
|
||||
{
|
||||
$rs = $this->appApiUser->getRules();
|
||||
$this->assertTrue(is_array($rs));
|
||||
}
|
||||
|
||||
/**
|
||||
* @group testRegister
|
||||
*/
|
||||
public function testRegister()
|
||||
{
|
||||
//Step 1. 构建请求URL
|
||||
$url = 'service=Platform.User.Register&username=test_dev&password=123456&member_type=100';
|
||||
|
||||
//Step 2. 执行请求
|
||||
$rs = TestRunner::go($url);
|
||||
|
||||
//Step 3. 验证
|
||||
$this->assertNotEmpty($rs);
|
||||
$this->assertTrue($rs['is_register']);
|
||||
$this->assertGreaterThan(0, $rs['uid']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group testRegister
|
||||
* @expectedException PhalApi\Exception\BadRequestException
|
||||
*/
|
||||
public function testRegisterFailType()
|
||||
{
|
||||
//Step 1. 构建请求URL
|
||||
$url = 'service=Platform.User.Register&username=test_dev&password=123456&member_type=98';
|
||||
|
||||
//Step 2. 执行请求
|
||||
$rs = TestRunner::go($url);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group testAlterPass
|
||||
*/
|
||||
public function testAlterPass()
|
||||
{
|
||||
// \PhalApi\DI()->context->setUid(1);
|
||||
|
||||
//Step 1. 构建请求URL
|
||||
$url = 'service=Platform.User.AlterPass&username=test_dev&password=123456&new_password=654321&_uid=1&access_token=123';
|
||||
|
||||
//Step 2. 执行请求
|
||||
$rs = TestRunner::go($url);
|
||||
|
||||
//Step 3. 验证
|
||||
$this->assertNotEmpty($rs);
|
||||
$this->assertTrue($rs['is_alter']);
|
||||
|
||||
//Step 1. 构建请求URL
|
||||
$url = 'service=Platform.User.AlterPass&username=test_dev&password=654321&new_password=123456&_uid=1&access_token=123';
|
||||
|
||||
//Step 2. 执行请求
|
||||
$rs = TestRunner::go($url);
|
||||
|
||||
//Step 3. 验证
|
||||
$this->assertNotEmpty($rs);
|
||||
$this->assertTrue($rs['is_alter']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group testProfile
|
||||
*/
|
||||
public function testUserProfile()
|
||||
{
|
||||
//Step 1. 构建请求URL
|
||||
$url = 'service=Platform.User.UserProfile&username=test_dev&access_token=123';
|
||||
|
||||
//Step 2. 执行请求
|
||||
$rs = TestRunner::go($url);
|
||||
|
||||
//Step 3. 验证
|
||||
$this->assertNotEmpty($rs);
|
||||
$this->assertNotEmpty($rs['profile']);
|
||||
$this->assertNotEmpty($rs['profile']['id']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group testUpdateProfile
|
||||
*/
|
||||
public function testUpdateProfile()
|
||||
{
|
||||
// \PhalApi\DI()->context->setUid(1);
|
||||
|
||||
//Step 1. 构建请求URL
|
||||
$url = 'service=Platform.User.UpdateProfile&access_token=123&username=test_dev&_uid=1&mobile='.time();
|
||||
|
||||
//Step 2. 执行请求
|
||||
$rs = TestRunner::go($url);
|
||||
|
||||
//Step 3. 验证
|
||||
$this->assertNotEmpty($rs);
|
||||
$this->assertTrue($rs['is_update']);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user