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,76 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);
namespace Magento\Contact\Block;
use Magento\Contact\ViewModel\UserDataProvider;
use Magento\Framework\View\Element\Block\ArgumentInterface;
use Magento\TestFramework\Helper\Bootstrap;
use PHPUnit\Framework\TestCase;
/**
* Testing behavior when view model was not preset before
* and view model was pre-installed before
*/
class ContactFormTest extends TestCase
{
/**
* Some classname
*/
private const SOME_VIEW_MODEL = 'Magento_Contact_ViewModel_Some_View_Model';
/**
* @var ContactForm
*/
private $block;
/**
* @inheirtDoc
*/
protected function setUp(): void
{
parent::setUp();
Bootstrap::getInstance()->loadArea('frontend');
$this->block = Bootstrap::getObjectManager()->create(ContactForm::class);
}
/**
* @param $setViewModel
* @param $expectedViewModelType
*
* @dataProvider dataProvider
*/
public function testViewModel($setViewModel, $expectedViewModelType)
{
if ($setViewModel) {
$someViewModel = $this->getMockForAbstractClass(
ArgumentInterface::class,
[],
self::SOME_VIEW_MODEL
);
$this->block->setData('view_model', $someViewModel);
}
$this->block->toHtml();
$this->assertInstanceOf($expectedViewModelType, $this->block->getData('view_model'));
}
public function dataProvider(): array
{
return [
'view model was not preset before' => [
'set view model' => false,
'expected view model type' => UserDataProvider::class
],
'view model was pre-installed before' => [
'set view model' => true,
'expected view model type' => self::SOME_VIEW_MODEL
]
];
}
}
@@ -0,0 +1,94 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Contact\Controller;
use Magento\Framework\App\Request\Http as HttpRequest;
/**
* Contact index controller test
*/
class IndexTest extends \Magento\TestFramework\TestCase\AbstractController
{
/**
* Test contacting.
*/
public function testPostAction()
{
$params = [
'name' => 'customer name',
'comment' => 'comment',
'email' => 'user@example.com',
'hideit' => '',
];
$this->getRequest()->setPostValue($params)->setMethod(HttpRequest::METHOD_POST);
$this->dispatch('contact/index/post');
$this->assertRedirect($this->stringContains('contact/index'));
$this->assertSessionMessages(
$this->containsEqual(
"Thanks for contacting us with your comments and questions. We&#039;ll respond to you very soon."
),
\Magento\Framework\Message\MessageInterface::TYPE_SUCCESS
);
}
/**
* Test validation.
*
* @param array $params For Request.
* @param string $expectedMessage Expected response.
*
* @dataProvider dataInvalidPostAction
*/
public function testInvalidPostAction($params, $expectedMessage)
{
$this->getRequest()->setPostValue($params)->setMethod(HttpRequest::METHOD_POST);
$this->dispatch('contact/index/post');
$this->assertRedirect($this->stringContains('contact/index'));
$this->assertSessionMessages(
$this->containsEqual($expectedMessage),
\Magento\Framework\Message\MessageInterface::TYPE_ERROR
);
}
/**
* @return array
*/
public static function dataInvalidPostAction()
{
return [
'missing_comment' => [
'params' => [
'name' => 'customer name',
'comment' => '',
'email' => 'user@example.com',
'hideit' => '',
],
'expectedMessage' => "Enter the comment and try again.",
],
'missing_name' => [
'params' => [
'name' => '',
'comment' => 'customer comment',
'email' => 'user@example.com',
'hideit' => '',
],
'expectedMessage' => "Enter the Name and try again.",
],
'invalid_email' => [
'params' => [
'name' => 'customer name',
'comment' => 'customer comment',
'email' => 'invalidemail',
'hideit' => '',
],
'expectedMessage' => "The email address is invalid. Verify the email address and try again.",
],
];
}
}
@@ -0,0 +1,61 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Contact\Helper;
use Magento\TestFramework\Helper\Bootstrap;
/**
* Test for Magento\Contact\Helper\Data
*
* @magentoDataFixture Magento/Customer/_files/customer.php
*/
class DataTest extends \PHPUnit\Framework\TestCase
{
/**
* @var Data
*/
protected $contactsHelper;
/**
* @var \Magento\Customer\Model\Session
*/
protected $customerSession;
/**
* Setup customer data
*/
protected function setUp(): void
{
$customerIdFromFixture = 1;
$this->contactsHelper = Bootstrap::getObjectManager()->create(\Magento\Contact\Helper\Data::class);
$this->customerSession = Bootstrap::getObjectManager()->create(\Magento\Customer\Model\Session::class);
/**
* @var $customerRepository \Magento\Customer\Api\CustomerRepositoryInterface
*/
$customerRepository = Bootstrap::getObjectManager()->create(
\Magento\Customer\Api\CustomerRepositoryInterface::class
);
$customerData = $customerRepository->getById($customerIdFromFixture);
$this->customerSession->setCustomerDataObject($customerData);
}
/**
* Verify if username is set in session
*/
public function testGetUserName()
{
$this->assertEquals('John Smith', $this->contactsHelper->getUserName());
}
/**
* Verify if user email is set in session
*/
public function testGetEmail()
{
$this->assertEquals('customer@example.com', $this->contactsHelper->getUserEmail());
}
}
@@ -0,0 +1,42 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Contact\Model;
use Magento\TestFramework\Helper\Bootstrap;
class ConfigTest extends \PHPUnit\Framework\TestCase
{
/**
* @var ConfigInterface
*/
private $configModel;
protected function setUp(): void
{
$this->configModel = Bootstrap::getObjectManager()->create(\Magento\Contact\Model\ConfigInterface::class);
}
/**
* @magentoAppArea frontend
* @magentoAppIsolation enabled
* @magentoConfigFixture current_store contact/contact/enabled 1
*/
public function testIsEnabled()
{
$this->assertTrue($this->configModel->isEnabled());
}
/**
* @magentoAppArea frontend
* @magentoAppIsolation enabled
* @magentoConfigFixture current_store contact/contact/enabled 0
*/
public function testIsNotEnabled()
{
$this->assertFalse($this->configModel->isEnabled());
}
}