change test to provider mode

This commit is contained in:
crazywhalecc
2022-04-01 19:20:10 +08:00
parent 7caebaa6ba
commit a454f2c523

View File

@@ -12,24 +12,44 @@ use ZM\API\CQ;
*/ */
class CQTest extends TestCase class CQTest extends TestCase
{ {
public function testShare() /**
* @dataProvider providerShare
* @param mixed $url
* @param mixed $title
* @param mixed $content
* @param mixed $image
* @param mixed $expected
*/
public function testShare($url, $title, $content, $image, $expected)
{ {
$this->assertEquals( $this->assertEquals($expected, CQ::share($url, $title, $content, $image));
'[CQ:share,url=https://www.baidu.com,title=hello,content=world,image=https://www.baidu.com/img/bd_logo1.png]', }
CQ::share('https://www.baidu.com', 'hello', 'world', 'https://www.baidu.com/img/bd_logo1.png')
); public function providerShare(): array
$this->assertEquals( {
'[CQ:share,url=https://www.baidu.com,title=123]', return [
CQ::share('https://www.baidu.com', '123') 'all' => [
); 'https://www.baidu.com',
$this->assertEquals( 'hello',
'[CQ:share,url=https://www.baidu.com,title=123,content=456]', 'world',
CQ::share('https://www.baidu.com', '123', '456') 'https://www.baidu.com/img/bd_logo1.png',
); '[CQ:share,url=https://www.baidu.com,title=hello,content=world,image=https://www.baidu.com/img/bd_logo1.png]',
$this->assertEquals( ],
'[CQ:share,url=https://www.baidu.com,title=123,content=456,image=https://www.baidu.com/img/bd_logo1.png]', 'url title' => [
CQ::share('https://www.baidu.com', '123', '456', 'https://www.baidu.com/img/bd_logo1.png') 'https://www.baidu.com',
); '123',
null,
null,
'[CQ:share,url=https://www.baidu.com,title=123]',
],
'url title content' => [
'https://www.baidu.com',
'123',
'456',
null,
'[CQ:share,url=https://www.baidu.com,title=123,content=456]',
],
];
} }
public function testShake() public function testShake()
@@ -72,16 +92,52 @@ class CQTest extends TestCase
$this->assertEquals('hello[],', CQ::escape('hello[],')); $this->assertEquals('hello[],', CQ::escape('hello[],'));
} }
public function testMusic() /**
* @dataProvider providerMusic
* @param mixed $data
* @param mixed $expected
*/
public function testMusic($data, $expected)
{ {
$this->assertEquals('[CQ:music,type=qq,id=123456789]', CQ::music('qq', '123456789')); $this->assertEquals($expected, CQ::music(...$data));
$this->assertEquals('[CQ:music,type=163,id=123456789]', CQ::music('163', '123456789')); }
$this->assertEquals('[CQ:music,type=xiami,id=123456789]', CQ::music('xiami', '123456789'));
$this->assertEquals(' ', CQ::music('custom', '123456789')); public function providerMusic(): array
$this->assertEquals('[CQ:music,type=custom,url=123456789,audio=test,title=test1]', CQ::music('custom', '123456789', 'test', 'test1')); {
$this->assertEquals('[CQ:music,type=custom,url=123456789,audio=test,title=test1,content=test2]', CQ::music('custom', '123456789', 'test', 'test1', 'test2')); return [
$this->assertEquals('[CQ:music,type=custom,url=123456789,audio=test,title=test1,content=test2,image=test3]', CQ::music('custom', '123456789', 'test', 'test1', 'test2', 'test3')); 'music qq' => [
$this->assertEquals(' ', CQ::music('custom test', '123456789', 'test', 'test1', 'test2', 'test3')); ['qq', '123456789'],
'[CQ:music,type=qq,id=123456789]',
],
'music 163' => [
['163', '123456789'],
'[CQ:music,type=163,id=123456789]',
],
'music xiami' => [
['xiami', '123456789'],
'[CQ:music,type=xiami,id=123456789]',
],
'music custom' => [
['custom', '123456789'],
' ',
],
'music custom url audio title' => [
['custom', '123456789', 'test', 'test1'],
'[CQ:music,type=custom,url=123456789,audio=test,title=test1]',
],
'music custom url audio title content' => [
['custom', '123456789', 'test', 'test1', 'test2'],
'[CQ:music,type=custom,url=123456789,audio=test,title=test1,content=test2]',
],
'music custom url audio title content image' => [
['custom', '123456789', 'test', 'test1', 'test2', 'test3'],
'[CQ:music,type=custom,url=123456789,audio=test,title=test1,content=test2,image=test3]',
],
'music custom test' => [
['custom test', '123456789', 'test', 'test1', 'test2', 'test3'],
' ',
],
];
} }
public function testPoke() public function testPoke()
@@ -114,11 +170,23 @@ class CQTest extends TestCase
$this->assertEquals('hello[],', CQ::decode('hello[],')); $this->assertEquals('hello[],', CQ::decode('hello[],'));
} }
public function testRemoveCQ() /**
* @dataProvider providerRemoveCQ
* @param mixed $msg
* @param mixed $expected
*/
public function testRemoveCQ($msg, $expected)
{ {
$this->assertEquals('hello,', CQ::removeCQ('hello[CQ:at,qq=123456789],')); $this->assertEquals($expected, CQ::removeCQ($msg));
$this->assertEquals('hello[CQ:at,qq=123456789,', CQ::removeCQ('hello[CQ:at,qq=123456789,')); }
$this->assertEquals('hello', CQ::removeCQ('[CQ:dice]hello[CQ:at,qq=123456789]'));
public function providerRemoveCQ(): array
{
return [
'remove cq 1' => ['hello[CQ:at,qq=123456789],', 'hello,'],
'remove cq 2' => ['hello[CQ:at,qq=123456789,', 'hello[CQ:at,qq=123456789,'],
'remove cq 3' => ['[CQ:dice]hello[CQ:at,qq=123456789]', 'hello'],
];
} }
public function testGetAllCQ() public function testGetAllCQ()
@@ -141,23 +209,33 @@ class CQTest extends TestCase
], $array); ], $array);
} }
public function testGetCQ() /**
* @dataProvider providerGetCQ
*/
public function testGetCQ($cq, $expected)
{ {
$this->assertEquals([ $this->assertEquals($expected, CQ::getCQ($cq));
'type' => 'dice', }
'start' => 0,
'end' => 8, public function providerGetCQ(): array
], CQ::getCQ('[CQ:dice]')); {
$this->assertEquals([ return [
'type' => 'at', 'one dice' => ['[CQ:dice]', [
'params' => [ 'type' => 'dice',
'qq' => '123456789', 'start' => 0,
], 'end' => 8,
'start' => 0, ]],
'end' => 19, 'one at' => ['[CQ:at,qq=123456789]', [
], CQ::getCQ('[CQ:at,qq=123456789]')); 'type' => 'at',
$this->assertNull(CQ::getCQ('[CQ:at,qq=123456789')); 'params' => [
$this->assertNull(CQ::getCQ('[CQ;at,qq=123456789]')); 'qq' => '123456789',
],
'start' => 0,
'end' => 19,
]],
'invalid cq 1' => ['[CQ:at,qq=123456789', null],
'invalid cq 2' => ['[CQ;at,qq=123456789]', null],
];
} }
public function testImage() public function testImage()