pay/tests/Plugin/Alipay/HtmlResponsePluginTest.php
yansongda c88f0c2d5c
fix: 支付宝 wap/web 支付 get 方法时url拼接问题 (#488)
* fix: 支付宝 wap/web 支付 get 方法时url拼接问题

* style: code style optimized
2021-09-10 16:28:51 +08:00

58 lines
2.2 KiB
PHP

<?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;
use Yansongda\Pay\Tests\TestCase;
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'));
}
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);
}
}