pay/tests/Plugin/Alipay/HtmlResponsePluginTest.php

58 lines
2.2 KiB
PHP
Raw Normal View History

2021-06-07 22:18:15 +08:00
<?php
namespace Yansongda\Pay\Tests\Plugin\Alipay;
use GuzzleHttp\Psr7\Request;
use Psr\Http\Message\ResponseInterface;
use Yansongda\Pay\Plugin\Alipay\HtmlResponsePlugin;
use Yansongda\Pay\Rocket;
2021-07-17 15:37:43 +08:00
use Yansongda\Pay\Tests\TestCase;
2021-06-07 22:18:15 +08:00
use Yansongda\Supports\Collection;
class HtmlResponsePluginTest extends TestCase
{
public function testRedirect()
{
$rocket = new Rocket();
$rocket->setRadar(new Request('GET', 'https://yansongda.cn'))
->setPayload(new Collection(['name' => 'yansongda']));
$plugin = new HtmlResponsePlugin();
$result = $plugin->assembly($rocket, function ($rocket) { return $rocket; });
self::assertInstanceOf(ResponseInterface::class, $result->getDestination());
self::assertArrayHasKey('Location', $result->getDestination()->getHeaders());
self::assertEquals('https://yansongda.cn?name=yansongda', $result->getDestination()->getHeaderLine('Location'));
}
public function testRedirectIncludeMark()
{
$rocket = new Rocket();
$rocket->setRadar(new Request('GET', 'https://yansongda.cn?charset=utf8'))
->setPayload(new Collection(['name' => 'yansongda']));
$plugin = new HtmlResponsePlugin();
$result = $plugin->assembly($rocket, function ($rocket) { return $rocket; });
self::assertInstanceOf(ResponseInterface::class, $result->getDestination());
self::assertArrayHasKey('Location', $result->getDestination()->getHeaders());
self::assertEquals('https://yansongda.cn?charset=utf8&name=yansongda', $result->getDestination()->getHeaderLine('Location'));
}
2021-06-07 22:18:15 +08:00
public function testHtml()
{
$rocket = new Rocket();
$rocket->setRadar(new Request('POST', 'https://yansongda.cn'))
->setPayload(new Collection(['name' => 'yansongda']));
$plugin = new HtmlResponsePlugin();
$result = $plugin->assembly($rocket, function ($rocket) { return $rocket; });
$contents = $result->getDestination()->getBody()->getContents();
self::assertInstanceOf(ResponseInterface::class, $result->getDestination());
self::assertStringContainsString('alipay_submit', $contents);
self::assertStringContainsString('yansongda', $contents);
}
}