Skip to content

Commit

Permalink
Merge branch '2.4-develop' into ACP2E-2787
Browse files Browse the repository at this point in the history
  • Loading branch information
lakshmana49 committed Feb 26, 2024
2 parents d274f96 + a2519ca commit 4c03af8
Show file tree
Hide file tree
Showing 197 changed files with 5,662 additions and 11,844 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ private function markUserNotified(): ResultInterface
public function execute()
{
$this->enableAdminUsage();
$this->markUserNotified();
return $this->markUserNotified();
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
<?php

/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\AdminAnalytics\Test\Unit\Controller\Adminhtml\Config;

use Magento\AdminAnalytics\Controller\Adminhtml\Config\EnableAdminUsage;
use Magento\AdminAnalytics\Model\ResourceModel\Viewer\Logger as NotificationLogger;
use Magento\Config\Model\Config;
use Magento\Config\Model\Config\Factory as ConfigFactory;
use Magento\Framework\App\ProductMetadataInterface;
use Magento\Framework\Controller\Result\Json as JsonResult;
use Magento\Framework\Controller\ResultFactory;
use Magento\Framework\Controller\ResultInterface;
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
use PHPUnit\Framework\MockObject\MockObject;

/**
* @covers \Magento\AdminAnalytics\Controller\Adminhtml\Config\EnableAdminUsage
*/
class EnableAdminUsageTest extends \PHPUnit\Framework\TestCase
{
private const STUB_PRODUCT_VERSION = 'Product Version';

/** @var EnableAdminUsage */
private $controller;

/** @var MockObject|Config */
private $configMock;

/** @var MockObject|ProductMetadataInterface */
private $productMetadataMock;

/** @var MockObject|NotificationLogger */
private $notificationLoggerMock;

/** @var MockObject|ResultFactory */
private $resultFactoryMock;

/** @var JsonResult|MockObject */
private $resultMock;

protected function setUp(): void
{
$objectManager = new ObjectManager($this);

$this->configMock = $this->getMockBuilder(Config::class)
->disableOriginalConstructor()
->onlyMethods(['setDataByPath', 'save'])
->getMock();

$configFactory = $this->getMockBuilder(ConfigFactory::class)
->disableOriginalConstructor()
->onlyMethods(['create'])
->getMock();

$configFactory->method('create')
->willReturn($this->configMock);

$this->productMetadataMock = $this->getMockBuilder(ProductMetadataInterface::class)
->onlyMethods(['getVersion'])
->getMockForAbstractClass();

$this->productMetadataMock->method('getVersion')
->willReturn(self::STUB_PRODUCT_VERSION);

$this->notificationLoggerMock = $this->getMockBuilder(NotificationLogger::class)
->disableOriginalConstructor()
->onlyMethods(['log'])
->getMock();

$this->resultFactoryMock = $this->getMockBuilder(ResultFactory::class)
->disableOriginalConstructor()
->onlyMethods(['create'])
->getMock();

$this->resultMock = $this->getMockBuilder(JsonResult::class)
->disableOriginalConstructor()
->onlyMethods(['setData'])
->getMock();

$this->resultFactoryMock->method('create')
->with(ResultFactory::TYPE_JSON)
->willReturn($this->resultMock);

$this->controller = $objectManager->getObject(EnableAdminUsage::class, [
'configFactory' => $configFactory,
'productMetadata' => $this->productMetadataMock,
'notificationLogger' => $this->notificationLoggerMock,
'resultFactory' => $this->resultFactoryMock
]);
}

/**
* If Controller returns `null`, no data is passed to the browser
*/
public function testResponseAfterAdminUsageChange()
{
// Given
$this->resultMock->method('setData')->willReturnSelf();

// When
$response = $this->controller->execute();

// Then
$this->assertInstanceOf(ResultInterface::class, $response);
}

public function testResponseWhenExceptionThrown()
{
$this->markTestSkipped('magento/magento2#31393 Lack of exception handling');

$this->configMock->method('setDataByPath')
->willThrowException(
new \Exception('System Exception')
);

// When
$response = $this->controller->execute();

// Then
$this->assertInstanceOf(ResultInterface::class, $response);
}
}
8 changes: 5 additions & 3 deletions app/code/Magento/Backend/etc/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Store:etc/config.xsd">
<default>
<admin>
<dashboard>
<enable_charts>0</enable_charts>
</dashboard>
</admin>
<dev>
<template>
<minify_html>0</minify_html>
Expand All @@ -22,9 +27,6 @@
<forgot_email_template>system_emails_forgot_email_template</forgot_email_template>
<forgot_email_identity>general</forgot_email_identity>
</emails>
<dashboard>
<enable_charts>1</enable_charts>
</dashboard>
<upload_configuration>
<enable_resize>1</enable_resize>
<max_width>1920</max_width>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

// phpcs:disable PHPCompatibility.Miscellaneous.RemovedAlternativePHPTags.MaybeASPOpenTagFound
/** @var $block \Magento\Backend\Block\Media\Uploader */
/** @var \Magento\Framework\Escaper $escaper */
?>

<div id="<?= $block->getHtmlId() ?>" class="uploader"
Expand All @@ -19,9 +20,8 @@
}'
>
<div class="fileinput-button form-buttons button">
<span><?= $block->escapeHtml(__('Browse Files...')) ?></span>
<input id="fileupload" type="file" name="<?= $block->escapeHtmlAttr($block->getConfig()->getFileField()) ?>"
data-url="<?= $block->escapeHtmlAttr($block->getConfig()->getUrl()) ?>" multiple="multiple" />
<span><?= $escaper->escapeHtml(__('Browse Files...')) ?></span>
<div id="fileUploader" data-url="<?= $escaper->escapeHtmlAttr($block->getConfig()->getUrl()) ?>"></div>
</div>
<div class="clear"></div>
<script id="<?= $block->getHtmlId() ?>-template" type="text/x-magento-template" data-template="uploader">
Expand Down
Loading

0 comments on commit 4c03af8

Please sign in to comment.