ltsecurityinc安防产品在线商城代码

This commit is contained in:
2026-09-14 17:47:10 +08:00
parent 57d8444c15
commit 6a3c9c5bd8
14539 changed files with 1775310 additions and 0 deletions
@@ -0,0 +1,112 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);
namespace Magento\Paypal\Controller\Transparent;
use Magento\TestFramework\TestCase\AbstractController;
use Zend\Stdlib\Parameters;
/**
* Tests PayPal transparent redirect controller.
*/
class RedirectTest extends AbstractController
{
/**
* Tests transparent redirect for PayPal PayflowPro payment flow.
*
* @SuppressWarnings(PHPMD.Superglobals)
*/
public function testRequestRedirect()
{
$redirectUri = 'paypal/transparent/redirect';
$postData = [
'BILLTOCITY' => 'culver city',
'AMT' => '0.00',
'BILLTOEMAIL' => 'user_1@example.com',
'BILLTOSTREET' => '123 Freedom Blvd. #123 app.111',
'VISACARDLEVEL' => '12',
'SHIPTOCITY' => 'culver city'
];
$this->setRequestUri($redirectUri);
$this->getRequest()->setPostValue($postData);
$this->getRequest()->setMethod('POST');
$this->dispatch($redirectUri);
$responseHtml = $this->getResponse()->getBody();
try {
$responseNvp = $this->convertToNvp($responseHtml);
$this->assertEquals(
$postData,
$responseNvp,
'POST form should contain all params from POST request'
);
} catch (\InvalidArgumentException $exception) {
$this->fail($exception->getMessage());
}
$this->assertEmpty(
$_SESSION,
'Session start has to be skipped for current controller'
);
}
/**
* Sets REQUEST_URI into request object.
*
* @param string $requestUri
* @return void
*/
private function setRequestUri(string $requestUri)
{
$request = $this->getRequest();
$reflection = new \ReflectionClass($request);
$property = $reflection->getProperty('requestUri');
$property->setAccessible(true);
$property->setValue($request, null);
$request->setServer(new Parameters(['REQUEST_URI' => $requestUri]));
}
/**
* Converts HTML response to NVP structure
*
* @param string $response
* @return array
*/
private function convertToNvp(string $response): array
{
$document = new \DOMDocument();
libxml_use_internal_errors(true);
if (!$document->loadHTML($response)) {
throw new \InvalidArgumentException(
__('The response format was incorrect. Should be valid HTML')
);
}
libxml_use_internal_errors(false);
$document->getElementsByTagName('input');
$convertedResponse = [];
/** @var \DOMNode $inputNode */
foreach ($document->getElementsByTagName('input') as $inputNode) {
if (!$inputNode->attributes->getNamedItem('value')
|| !$inputNode->attributes->getNamedItem('name')
) {
continue;
}
$convertedResponse[$inputNode->attributes->getNamedItem('name')->nodeValue]
= $inputNode->attributes->getNamedItem('value')->nodeValue;
}
unset($convertedResponse['form_key']);
return $convertedResponse;
}
}
@@ -0,0 +1,133 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);
namespace Magento\Paypal\Controller\Transparent;
use Magento\Checkout\Model\Session;
use Magento\Framework\Api\SearchCriteriaBuilder;
use Magento\Framework\Exception\NoSuchEntityException;
use Magento\Framework\Intl\DateTimeFactory;
use Magento\Quote\Api\CartRepositoryInterface;
use Magento\Quote\Api\Data\CartInterface;
use Magento\Quote\Api\PaymentMethodManagementInterface;
/**
* Tests PayPal transparent response controller.
*/
class ResponseTest extends \Magento\TestFramework\TestCase\AbstractController
{
/**
* Tests setting credit card expiration month and year to payment from PayPal response.
*
* @param string $currentDateTime
* @param string $paypalExpDate
* @param int $expectedCcMonth
* @param int $expectedCcYear
* @throws NoSuchEntityException
*
* @magentoConfigFixture current_store payment/payflowpro/active 1
* @magentoDataFixture Magento/Sales/_files/quote.php
* @dataProvider paymentCcExpirationDateDataProvider
*/
public function testPaymentCcExpirationDate(
string $currentDateTime,
string $paypalExpDate,
int $expectedCcMonth,
int $expectedCcYear
) {
$reservedOrderId = 'test01';
$postData = [
'EXPDATE' => $paypalExpDate,
'AMT' => '0.00',
'RESPMSG' => 'Verified',
'CVV2MATCH' => 'Y',
'PNREF' => 'A10AAD866C87',
'SECURETOKEN' => '3HYEHfG06skydAdBXbpIl8QJZ',
'AVSDATA' => 'YNY',
'RESULT' => '0',
'IAVS' => 'N',
'AVSADDR' => 'Y',
'SECURETOKENID' => 'yqanLisRZbI0HAG8q3SbbKbhiwjNZAGf',
];
$quote = $this->getQuote($reservedOrderId);
$this->getRequest()->setPostValue($postData);
$this->getRequest()->setMethod('POST');
/** @var Session $checkoutSession */
$checkoutSession = $this->_objectManager->get(Session::class);
$checkoutSession->setQuoteId($quote->getId());
$this->setCurrentDateTime($currentDateTime);
$this->dispatch('paypal/transparent/response');
/** @var PaymentMethodManagementInterface $paymentManagment */
$paymentManagment = $this->_objectManager->get(PaymentMethodManagementInterface::class);
$payment = $paymentManagment->get($quote->getId());
$this->assertEquals($expectedCcMonth, $payment->getCcExpMonth());
$this->assertEquals($expectedCcYear, $payment->getCcExpYear());
}
/**
* @return array
*/
public function paymentCcExpirationDateDataProvider(): array
{
return [
'Expiration year in current century' => [
'currentDateTime' => '2019-07-05 00:00:00',
'paypalExpDate' => '0321',
'expectedCcMonth' => 3,
'expectedCcYear' => 2021
],
'Expiration year in next century' => [
'currentDateTime' => '2099-01-01 00:00:00',
'paypalExpDate' => '1002',
'expectedCcMonth' => 10,
'expectedCcYear' => 2102
]
];
}
/**
* Sets current date and time.
*
* @param string $date
*/
private function setCurrentDateTime(string $dateTime): void
{
$dateTime = new \DateTime($dateTime, new \DateTimeZone('UTC'));
$dateTimeFactory = $this->getMockBuilder(DateTimeFactory::class)
->disableOriginalConstructor()
->getMock();
$dateTimeFactory->method('create')
->willReturn($dateTime);
$this->_objectManager->addSharedInstance($dateTimeFactory, DateTimeFactory::class);
}
/**
* Gets quote by reserved order ID.
*
* @param string $reservedOrderId
* @return CartInterface
*/
private function getQuote(string $reservedOrderId): CartInterface
{
$searchCriteria = $this->_objectManager->get(SearchCriteriaBuilder::class)
->addFilter('reserved_order_id', $reservedOrderId)
->create();
/** @var CartRepositoryInterface $quoteRepository */
$quoteRepository = $this->_objectManager->get(CartRepositoryInterface::class);
$items = $quoteRepository->getList($searchCriteria)
->getItems();
return array_pop($items);
}
}