Skip to content

Commit

Permalink
Merge pull request #1864 from magento-engcom/develop-prs
Browse files Browse the repository at this point in the history
Public Pull Requests
magento/magento2#12631 [2.3-develop] Add customer login url from Customer Url model to checkout config so … by @quisse
magento/magento2#12637 [Backport 2.3] #12625: Add Current Date to update_time Field for Block and Pages by @osrecio

Fixed Public Issues
magento/magento2#12627 Referer is not added to login url in checkout config
magento/magento2#12625 when saving a page in magento 2.2.1, 'Modified' date field is not getting updated
  • Loading branch information
Oleksii Korshenko authored Dec 20, 2017
2 parents cf85308 + f369824 commit fc97826
Show file tree
Hide file tree
Showing 8 changed files with 121 additions and 41 deletions.
5 changes: 4 additions & 1 deletion app/code/Magento/Cms/Model/Block.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
namespace Magento\Cms\Model;

use Magento\Cms\Api\Data\BlockInterface;
use Magento\Cms\Model\ResourceModel\Block as ResourceCmsBlock;
use Magento\Framework\DataObject\IdentityInterface;
use Magento\Framework\Model\AbstractModel;

Expand Down Expand Up @@ -57,6 +56,10 @@ protected function _construct()
*/
public function beforeSave()
{
if ($this->hasDataChanges()) {
$this->setUpdateTime(null);
}

$needle = 'block_id="' . $this->getId() . '"';
if (false == strstr($this->getContent(), $needle)) {
return parent::beforeSave();
Expand Down
7 changes: 5 additions & 2 deletions app/code/Magento/Cms/Model/Page.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,11 @@
namespace Magento\Cms\Model;

use Magento\Cms\Api\Data\PageInterface;
use Magento\Cms\Model\ResourceModel\Page as ResourceCmsPage;
use Magento\Cms\Helper\Page as PageHelper;
use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Framework\DataObject\IdentityInterface;
use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\Model\AbstractModel;
use Magento\Cms\Helper\Page as PageHelper;

/**
* Cms Page Model
Expand Down Expand Up @@ -547,6 +546,10 @@ public function beforeSave()
$originalIdentifier = $this->getOrigData('identifier');
$currentIdentifier = $this->getIdentifier();

if ($this->hasDataChanges()) {
$this->setUpdateTime(null);
}

if (!$this->getId() || $originalIdentifier === $currentIdentifier) {
return parent::beforeSave();
}
Expand Down
4 changes: 2 additions & 2 deletions app/code/Magento/Cms/Model/ResourceModel/Block.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@

use Magento\Cms\Api\Data\BlockInterface;
use Magento\Framework\DB\Select;
use Magento\Framework\EntityManager\EntityManager;
use Magento\Framework\EntityManager\MetadataPool;
use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\Model\AbstractModel;
use Magento\Framework\EntityManager\MetadataPool;
use Magento\Framework\EntityManager\EntityManager;
use Magento\Framework\Model\ResourceModel\Db\AbstractDb;
use Magento\Framework\Model\ResourceModel\Db\Context;
use Magento\Store\Model\Store;
Expand Down
6 changes: 3 additions & 3 deletions app/code/Magento/Cms/Model/ResourceModel/Page.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,18 @@

namespace Magento\Cms\Model\ResourceModel;

use Magento\Cms\Api\Data\PageInterface;
use Magento\Cms\Model\Page as CmsPage;
use Magento\Framework\DB\Select;
use Magento\Framework\EntityManager\EntityManager;
use Magento\Framework\EntityManager\MetadataPool;
use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\Model\AbstractModel;
use Magento\Framework\EntityManager\MetadataPool;
use Magento\Framework\Model\ResourceModel\Db\AbstractDb;
use Magento\Framework\Model\ResourceModel\Db\Context;
use Magento\Framework\Stdlib\DateTime;
use Magento\Store\Model\Store;
use Magento\Store\Model\StoreManagerInterface;
use Magento\Framework\EntityManager\EntityManager;
use Magento\Cms\Api\Data\PageInterface;

/**
* Cms page mysql resource
Expand Down
15 changes: 13 additions & 2 deletions app/code/Magento/Customer/Model/Checkout/ConfigProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

use Magento\Checkout\Model\ConfigProviderInterface;
use Magento\Customer\Model\Url;
use Magento\Framework\App\ObjectManager;
use Magento\Framework\UrlInterface;
use Magento\Store\Model\StoreManagerInterface;
use Magento\Framework\App\Config\ScopeConfigInterface;
Expand All @@ -22,6 +23,7 @@ class ConfigProvider implements ConfigProviderInterface

/**
* @var UrlInterface
* @deprecated
*/
protected $urlBuilder;

Expand All @@ -30,19 +32,28 @@ class ConfigProvider implements ConfigProviderInterface
*/
protected $scopeConfig;

/**
* @var Url
*/
private $customerUrl;

/**
* @param UrlInterface $urlBuilder
* @param StoreManagerInterface $storeManager
* @param ScopeConfigInterface $scopeConfig
* @param Url|null $customerUrl
*/
public function __construct(
UrlInterface $urlBuilder,
StoreManagerInterface $storeManager,
ScopeConfigInterface $scopeConfig
ScopeConfigInterface $scopeConfig,
Url $customerUrl = null
) {
$this->urlBuilder = $urlBuilder;
$this->storeManager = $storeManager;
$this->scopeConfig = $scopeConfig;
$this->customerUrl = $customerUrl ?? ObjectManager::getInstance()
->get(Url::class);
}

/**
Expand Down Expand Up @@ -78,7 +89,7 @@ protected function isAutocompleteEnabled()
*/
protected function getLoginUrl()
{
return $this->urlBuilder->getUrl(Url::ROUTE_ACCOUNT_LOGIN);
return $this->customerUrl->getLoginUrl();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ class ConfigProviderTest extends \PHPUnit\Framework\TestCase
*/
protected $store;

/**
* @var Url|\PHPUnit_Framework_MockObject_MockObject
*/
private $customerUrl;

protected function setUp()
{
$this->storeManager = $this->getMockForAbstractClass(
Expand All @@ -49,12 +54,14 @@ protected function setUp()
'',
false
);

$this->urlBuilder = $this->getMockForAbstractClass(
\Magento\Framework\UrlInterface::class,
[],
'',
false
);

$this->scopeConfig = $this->getMockForAbstractClass(
\Magento\Framework\App\Config\ScopeConfigInterface::class,
[],
Expand All @@ -71,10 +78,13 @@ protected function setUp()
['getBaseUrl']
);

$this->customerUrl = $this->createMock(\Magento\Customer\Model\Url::class);

$this->provider = new ConfigProvider(
$this->urlBuilder,
$this->storeManager,
$this->scopeConfig
$this->scopeConfig,
$this->customerUrl
);
}

Expand All @@ -83,9 +93,8 @@ public function testGetConfigWithoutRedirect()
$loginUrl = 'http://url.test/customer/login';
$baseUrl = 'http://base-url.test';

$this->urlBuilder->expects($this->exactly(2))
->method('getUrl')
->with(Url::ROUTE_ACCOUNT_LOGIN)
$this->customerUrl->expects($this->exactly(2))
->method('getLoginUrl')
->willReturn($loginUrl);
$this->storeManager->expects($this->once())
->method('getStore')
Expand All @@ -112,9 +121,8 @@ public function testGetConfig()
$loginUrl = 'http://base-url.test/customer/login';
$baseUrl = 'http://base-url.test';

$this->urlBuilder->expects($this->exactly(2))
->method('getUrl')
->with(Url::ROUTE_ACCOUNT_LOGIN)
$this->customerUrl->expects($this->exactly(2))
->method('getLoginUrl')
->willReturn($loginUrl);
$this->storeManager->expects($this->once())
->method('getStore')
Expand Down
97 changes: 76 additions & 21 deletions dev/tests/integration/testsuite/Magento/Cms/Model/BlockTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,51 @@
*/
namespace Magento\Cms\Model;

use Magento\Cms\Model\ResourceModel\Block;
use Magento\Cms\Model\BlockFactory;
use Magento\Framework\ObjectManagerInterface;
use Magento\Framework\Stdlib\DateTime\DateTime;
use Magento\TestFramework\Helper\Bootstrap;
use PHPUnit\Framework\TestCase;

/**
* @magentoAppArea adminhtml
*/
class BlockTest extends \PHPUnit\Framework\TestCase
class BlockTest extends TestCase
{

/**
* @var ObjectManagerInterface
*/
private $objectManager;

/**
* @var Block
*/
private $blockResource;

/**
* @var BlockFactory
*/
private $blockFactory;

/**
* @var GetBlockByIdentifier
*/
private $blockIdentifier;

protected function setUp()
{
$this->objectManager = Bootstrap::getObjectManager();

/** @var BlockFactory $blockFactory */
/** @var Block $blockResource */
/** @var GetBlockByIdentifier $getBlockByIdentifierCommand */
$this->blockResource = $this->objectManager->create(Block::class);
$this->blockFactory = $this->objectManager->create(BlockFactory::class);
$this->blockIdentifier = $this->objectManager->create(GetBlockByIdentifier::class);
}

/**
* Tests the get by identifier command
* @param array $blockData
Expand All @@ -20,40 +60,55 @@ class BlockTest extends \PHPUnit\Framework\TestCase
*/
public function testGetByIdentifier(array $blockData)
{
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
# Prepare and save the temporary block
$tempBlock = $this->blockFactory->create();
$tempBlock->setData($blockData);
$this->blockResource->save($tempBlock);

/** @var \Magento\Cms\Model\BlockFactory $blockFactory */
/** @var \Magento\Cms\Model\ResourceModel\Block $blockResource */
/** @var \Magento\Cms\Model\GetBlockByIdentifier $getBlockByIdentifierCommand */
$blockResource = $objectManager->create(\Magento\Cms\Model\ResourceModel\Block::class);
$blockFactory = $objectManager->create(\Magento\Cms\Model\BlockFactory::class);
$getBlockByIdentifierCommand = $objectManager->create(\Magento\Cms\Model\GetBlockByIdentifier::class);
# Load previously created block and compare identifiers
$storeId = reset($blockData['stores']);
$block = $this->blockIdentifier->execute($blockData['identifier'], $storeId);
$this->assertEquals($blockData['identifier'], $block->getIdentifier());
}

/**
* Tests the get by identifier command
* @param array $blockData
* @throws \Exception
* @throws \Magento\Framework\Exception\NoSuchEntityException
* @magentoDbIsolation enabled
* @dataProvider testGetByIdentifierDataProvider
*/
public function testUpdateTime(array $blockData)
{
# Prepare and save the temporary block
$tempBlock = $blockFactory->create();
$tempBlock = $this->blockFactory->create();
$tempBlock->setData($blockData);
$blockResource->save($tempBlock);
$this->blockResource->save($tempBlock);

# Load previously created block and compare identifiers
$storeId = reset($blockData['stores']);
$block = $getBlockByIdentifierCommand->execute($blockData['identifier'], $storeId);
$this->assertEquals($blockData['identifier'], $block->getIdentifier());
$block = $this->blockIdentifier->execute($blockData['identifier'], $storeId);
$date = $this->objectManager->get(DateTime::class)->date();
$this->assertEquals($date, $block->getUpdateTime());
}

/**
* Data provider for "testGetByIdentifier" method
* Data provider for "testGetByIdentifier" and "testUpdateTime" method
* @return array
*/
public function testGetByIdentifierDataProvider() : array
public function testGetByIdentifierDataProvider(): array
{
return [
['data' => [
'title' => 'Test title',
'stores' => [0],
'identifier' => 'test-identifier',
'content' => 'Test content',
'is_active' => 1
]]
[
'data' => [
'title' => 'Test title',
'stores' => [0],
'identifier' => 'test-identifier',
'content' => 'Test content',
'is_active' => 1
]
]
];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
namespace Magento\Cms\Model;

use Magento\Cms\Api\PageRepositoryInterface;
use Magento\Framework\Stdlib\DateTime\DateTime;

/**
* @magentoAppArea adminhtml
Expand Down Expand Up @@ -77,15 +78,14 @@ public function testGenerateIdentifierFromTitle($data, $expectedIdentifier)
*/
public function testUpdateTime()
{
$updateTime = '2016-09-01 00:00:00';
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
/** @var \Magento\Cms\Model\Page $page */
$page = $objectManager->create(\Magento\Cms\Model\Page::class);
$page->setData(['title' => 'Test', 'stores' => [1]]);
$page->setUpdateTime($updateTime);
$page->save();
$page = $objectManager->get(PageRepositoryInterface::class)->getById($page->getId());
$this->assertEquals($updateTime, $page->getUpdateTime());
$date = $objectManager->get(DateTime::class)->date();
$this->assertEquals($date, $page->getUpdateTime());
}

public function generateIdentifierFromTitleDataProvider() : array
Expand Down

0 comments on commit fc97826

Please sign in to comment.