邹景立 34104dad22 Update plugin headers and add rewrite-model script
Replace header text "Payment Plugin for ThinkAdmin" with "ThinkAdmin Plugin for ThinkAdmin" across project files (configs, controllers, plugins, php-cs-fixer, etc.) to unify branding. Add a new composer script "rewrite-model" to regenerate models and run php-cs-fixer. Also apply a minor newline fix in .copilot-commit-message-instructions.md.
2026-02-01 14:24:36 +08:00

98 lines
3.1 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
declare(strict_types=1);
/**
* +----------------------------------------------------------------------
* | ThinkAdmin Plugin for ThinkAdmin
* +----------------------------------------------------------------------
* | 版权所有 2014~2026 ThinkAdmin [ thinkadmin.top ]
* +----------------------------------------------------------------------
* | 官方网站: https://thinkadmin.top
* +----------------------------------------------------------------------
* | 开源协议 ( https://mit-license.org )
* | 免责声明 ( https://thinkadmin.top/disclaimer )
* | 会员特权 ( https://thinkadmin.top/vip-introduce )
* +----------------------------------------------------------------------
* | gitee 代码仓库https://gitee.com/zoujingli/ThinkAdmin
* | github 代码仓库https://github.com/zoujingli/ThinkAdmin
* +----------------------------------------------------------------------
*/
namespace think\admin\tests;
use PHPUnit\Framework\TestCase;
use plugin\account\service\Account;
use think\admin\Exception;
/**
* @internal
* @coversNothing
*/
class AccountTest extends TestCase
{
public function testAddType()
{
Account::add('test', '测试接口');
$this->assertIsString(Account::field('test'));
}
public function testGetTypes()
{
$info = Account::types();
$this->assertIsArray($info);
}
public function testChangeType()
{
$field = Account::field('web');
$this->assertNotEmpty($field);
Account::set('web', 0);
$field = Account::field('web');
$this->assertEmpty($field);
try {
Account::mk('web');
} catch (Exception $exception) {
$this->assertStringContainsString('未定义', $exception->getMessage());
}
}
public function testAddAccount()
{
$account = Account::mk(Account::WAP);
$info = $account->set(['phone' => '138888888888', 'nickname' => '账号创建测试'], true);
$this->assertEquals($info['id'], $account->get()['id'], '创建用户测试成功!');
}
public function testBindAccount()
{
$username = 'UserName' . uniqid();
$account = Account::mk(Account::WAP);
$phone = '13888888' . mt_rand(1000, 9999);
$account->set(['phone' => $phone]);
// 关联绑定主账号
$info = $account->bind(['phone' => $phone], ['username' => $username]);
$this->assertEquals($info['user']['username'], $username, '账号绑定关联成功!');
// 刷新主账号序号
$news = $account->recode();
$this->assertNotEquals($info['user']['code'], $news['user']['code'], '刷新用户序号成功');
}
public function testUnbindAccount()
{
$account = Account::mk(Account::WAP);
$account->set(['phone' => '138888888888']);
// 关联绑定主账号
$info = $account->bind(['phone' => '138888888888'], ['username' => 'UserName' . uniqid()]);
$this->assertNotEmpty($info['user'], '账号绑定成功!');
$info = $account->unBind();
$this->assertEmpty($info['user'], '账号解绑成功!');
}
}