This commit is contained in:
2026-09-15 10:26:34 +08:00
commit ecf36afa56
10493 changed files with 1404888 additions and 0 deletions
@@ -0,0 +1,79 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);
namespace Magento\Newsletter\Block\Account;
use Magento\Framework\ObjectManagerInterface;
use Magento\Framework\View\Result\Page;
use Magento\TestFramework\Helper\Bootstrap;
use PHPUnit\Framework\TestCase;
/**
* Checks Newsletter Subscriptions link displaying in account dashboard
*
* @magentoAppArea frontend
* @magentoDbIsolation enabled
* @magentoAppIsolation enabled
*/
class LinkTest extends TestCase
{
/** @var ObjectManagerInterface */
private $objectManager;
/** @var Page */
private $page;
/**
* @inheritdoc
*/
protected function setUp(): void
{
parent::setUp();
$this->objectManager = Bootstrap::getObjectManager();
$this->page = $this->objectManager->create(Page::class);
}
/**
* @return void
*/
public function testNewsletterLink(): void
{
$this->preparePage();
$block = $this->page->getLayout()->getBlock('customer-account-navigation-newsletter-subscriptions-link');
$this->assertNotFalse($block);
$html = $block->toHtml();
$this->assertStringContainsString('newsletter/manage/', $html);
$this->assertEquals('Newsletter Subscriptions', strip_tags($html));
}
/**
* @magentoConfigFixture current_store newsletter/general/active 0
*
* @return void
*/
public function testNewsletterLinkDisabled(): void
{
$this->preparePage();
$block = $this->page->getLayout()->getBlock('customer-account-navigation-newsletter-subscriptions-link');
$this->assertFalse($block);
}
/**
* Prepare page before render
*
* @return void
*/
private function preparePage(): void
{
$this->page->addHandle([
'default',
'customer_account',
]);
$this->page->getLayout()->generateXml();
}
}
@@ -0,0 +1,58 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Newsletter\Block\Adminhtml\Queue\Edit;
/**
* Test class for \Magento\Newsletter\Block\Adminhtml\Queue\Edit\Form
* @magentoAppArea adminhtml
*/
class FormTest extends \PHPUnit\Framework\TestCase
{
/**
* @magentoAppIsolation enabled
*/
public function testPrepareForm()
{
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
$queue = $objectManager->get(\Magento\Newsletter\Model\Queue::class);
/** @var \Magento\Framework\Registry $registry */
$registry = $objectManager->get(\Magento\Framework\Registry::class);
$registry->register('current_queue', $queue);
$objectManager->get(
\Magento\Framework\View\DesignInterface::class
)->setArea(
\Magento\Backend\App\Area\FrontNameResolver::AREA_CODE
)->setDefaultDesignTheme();
$objectManager->get(
\Magento\Framework\Config\ScopeInterface::class
)->setCurrentScope(
\Magento\Backend\App\Area\FrontNameResolver::AREA_CODE
);
$block = $objectManager->create(
\Magento\Newsletter\Block\Adminhtml\Queue\Edit\Form::class,
['registry' => $registry]
);
$prepareFormMethod = new \ReflectionMethod(
\Magento\Newsletter\Block\Adminhtml\Queue\Edit\Form::class,
'_prepareForm'
);
$prepareFormMethod->setAccessible(true);
$statuses = [
\Magento\Newsletter\Model\Queue::STATUS_NEVER,
\Magento\Newsletter\Model\Queue::STATUS_PAUSE,
];
foreach ($statuses as $status) {
$queue->setQueueStatus($status);
$prepareFormMethod->invoke($block);
$element = $block->getForm()->getElement('date');
$this->assertNotNull($element);
$this->assertNotEmpty($element->getTimeFormat());
$this->assertNotEmpty($element->getDateFormat());
}
}
}
@@ -0,0 +1,105 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);
namespace Magento\Newsletter\Block\Adminhtml\Subscriber;
/**
* @magentoAppArea adminhtml
* @magentoDbIsolation enabled
*
* @see \Magento\Newsletter\Block\Adminhtml\Subscriber\Grid
*/
class GridTest extends \PHPUnit\Framework\TestCase
{
/**
* @var null|\Magento\Framework\ObjectManagerInterface
*/
private $objectManager = null;
/**
* @var null|\Magento\Framework\View\LayoutInterface
*/
private $layout = null;
/**
* Set up layout.
*/
protected function setUp(): void
{
parent::setUp();
$this->objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
$this->layout = $this->objectManager->create(\Magento\Framework\View\LayoutInterface::class);
$this->layout->getUpdate()->load('newsletter_subscriber_grid');
$this->layout->generateXml();
$this->layout->generateElements();
}
/**
* Check if mass action block exists.
*/
public function testMassActionBlockExists()
{
$this->assertNotFalse(
$this->getMassActionBlock(),
'Mass action block does not exist in the grid, or it name was changed.'
);
}
/**
* Check if mass action id field is correct.
*/
public function testMassActionFieldIdIsCorrect()
{
$this->assertEquals(
'subscriber_id',
$this->getMassActionBlock()->getMassactionIdField(),
'Mass action id field is incorrect.'
);
}
/**
* Check if function returns correct result.
*
* @magentoDataFixture Magento/Newsletter/_files/subscribers.php
*/
public function testMassActionBlockContainsCorrectIdList()
{
$this->assertEquals(
implode(',', $this->getAllSubscriberIdList()),
$this->getMassActionBlock()->getGridIdsJson(),
'Function returns incorrect result.'
);
}
/**
* Retrieve mass action block.
*
* @return bool|\Magento\Backend\Block\Widget\Grid\Massaction
*/
private function getMassActionBlock()
{
return $this->layout->getBlock('adminhtml.newslettrer.subscriber.grid.massaction');
}
/**
* Retrieve list of id of all subscribers.
*
* @return array
*/
private function getAllSubscriberIdList()
{
/** @var \Magento\Framework\App\ResourceConnection $resourceConnection */
$resourceConnection = $this->objectManager->get(\Magento\Framework\App\ResourceConnection::class);
$select = $resourceConnection->getConnection()
->select()
->from($resourceConnection->getTableName('newsletter_subscriber'))
->columns(['subscriber_id' => 'subscriber_id']);
return $resourceConnection->getConnection()->fetchCol($select);
}
}
@@ -0,0 +1,29 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Newsletter\Block\Adminhtml;
/**
* @magentoAppArea adminhtml
*/
class SubscriberTest extends \PHPUnit\Framework\TestCase
{
public function testGetShowQueueAdd()
{
/** @var $layout \Magento\Framework\View\Layout */
$layout = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
\Magento\Framework\View\LayoutInterface::class
);
/** @var $block \Magento\Newsletter\Block\Adminhtml\Subscriber */
$block = $layout->createBlock(\Magento\Newsletter\Block\Adminhtml\Subscriber::class, 'block');
/** @var $childBlock \Magento\Framework\View\Element\Template */
$childBlock = $layout->addBlock(\Magento\Framework\View\Element\Template::class, 'grid', 'block');
$expected = 'test_data';
$this->assertNotEquals($expected, $block->getShowQueueAdd());
$childBlock->setShowQueueAdd($expected);
$this->assertEquals($expected, $block->getShowQueueAdd());
}
}