ltsecurityinc安防产品在线商城代码
This commit is contained in:
@@ -0,0 +1,85 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\Framework\HTTP;
|
||||
|
||||
use Magento\Framework\HTTP\AsyncClient\Request;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* Testing asynchronous HTTP client.
|
||||
*/
|
||||
class AsyncClientInterfaceTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @var AsyncClientInterface
|
||||
*/
|
||||
private $client;
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->client = Bootstrap::getObjectManager()->get(AsyncClientInterface::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Making a request.
|
||||
*/
|
||||
public function testRequest(): void
|
||||
{
|
||||
$request = new Request('https://adobe.com', Request::METHOD_GET, [], null);
|
||||
$response1 = $this->client->request($request);
|
||||
$response2 = $this->client->request($request);
|
||||
$this->assertEquals(200, $response2->get()->getStatusCode());
|
||||
$this->assertEquals(200, $response1->get()->getStatusCode());
|
||||
$this->assertStringContainsString(
|
||||
'Adobe: Creative, marketing and document management solutions',
|
||||
$response1->get()->getBody()
|
||||
);
|
||||
$this->assertStringContainsString(
|
||||
'Adobe: Creative, marketing and document management solutions',
|
||||
$response2->get()->getBody()
|
||||
);
|
||||
$date1 = new \DateTime($response1->get()->getHeaders()['date']);
|
||||
$date2 = new \DateTime($response2->get()->getHeaders()['date']);
|
||||
$this->assertLessThanOrEqual(1, abs((int)$date1->format('U') - (int)$date2->format('U')));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test cancelling a request.
|
||||
*
|
||||
*/
|
||||
public function testCancel(): void
|
||||
{
|
||||
$this->expectException(\Magento\Framework\Async\CancelingDeferredException::class);
|
||||
$this->expectExceptionMessage('Deferred is canceled');
|
||||
|
||||
$request = new Request('https://adobe.com/', Request::METHOD_GET, [], null);
|
||||
$response = $this->client->request($request);
|
||||
$response->cancel(true);
|
||||
$this->assertTrue($response->isCancelled());
|
||||
$response->get();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test failing cancelling a request.
|
||||
*
|
||||
*/
|
||||
public function testCancelFail(): void
|
||||
{
|
||||
$this->expectException(\Magento\Framework\Async\CancelingDeferredException::class);
|
||||
$this->expectExceptionMessage('Failed to cancel HTTP request');
|
||||
|
||||
$request = new Request('https://adobe.com/', Request::METHOD_GET, [], null);
|
||||
$response = $this->client->request($request);
|
||||
$response->cancel();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Framework\HTTP;
|
||||
|
||||
use Laminas\Stdlib\Parameters;
|
||||
|
||||
class HeaderTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @var \Magento\Framework\HTTP\Header
|
||||
*/
|
||||
protected $_header;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
|
||||
$this->_header = $objectManager->get(\Magento\Framework\HTTP\Header::class);
|
||||
|
||||
/** @var \Magento\TestFramework\Request $request */
|
||||
$request = $objectManager->get(\Magento\TestFramework\Request::class);
|
||||
$request->setServer(new Parameters(['HTTP_HOST' => 'localhost']));
|
||||
}
|
||||
|
||||
public function testGetHttpHeaderMethods()
|
||||
{
|
||||
$host = 'localhost';
|
||||
$this->assertEquals($host, $this->_header->getHttpHost());
|
||||
$this->assertEquals('', $this->_header->getHttpUserAgent());
|
||||
$this->assertEquals('', $this->_header->getHttpAcceptLanguage());
|
||||
$this->assertEquals('', $this->_header->getHttpAcceptCharset());
|
||||
$this->assertEquals('', $this->_header->getHttpReferer());
|
||||
}
|
||||
|
||||
public function testGetRequestUri()
|
||||
{
|
||||
$this->assertEquals('/', $this->_header->getRequestUri());
|
||||
}
|
||||
}
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Framework\HTTP\PhpEnvironment;
|
||||
|
||||
class RemoteAddressTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @var \Magento\Framework\HTTP\PhpEnvironment\RemoteAddress
|
||||
*/
|
||||
protected $_helper;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
|
||||
$this->_helper = $objectManager->get(\Magento\Framework\HTTP\PhpEnvironment\RemoteAddress::class);
|
||||
}
|
||||
|
||||
public function testGetRemoteAddress()
|
||||
{
|
||||
$this->assertFalse($this->_helper->getRemoteAddress());
|
||||
}
|
||||
}
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Framework\HTTP\PhpEnvironment;
|
||||
|
||||
class ServerAddressTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @var \Magento\Framework\HTTP\PhpEnvironment\ServerAddress
|
||||
*/
|
||||
protected $_helper;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
|
||||
$this->_helper = $objectManager->get(\Magento\Framework\HTTP\PhpEnvironment\ServerAddress::class);
|
||||
}
|
||||
|
||||
public function testGetServerAddress()
|
||||
{
|
||||
$this->assertFalse($this->_helper->getServerAddress());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user