-
Notifications
You must be signed in to change notification settings - Fork 9.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1114 from magento-tango/MAGETWO-66825-1
[Tango] MAGETWO-66825: Caching of attribute options for Layered Navigation
- Loading branch information
Showing
3 changed files
with
258 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
91 changes: 91 additions & 0 deletions
91
...integration/testsuite/Magento/Eav/Model/Entity/Attribute/Frontend/DefaultFrontendTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
namespace Magento\Eav\Model\Entity\Attribute\Frontend; | ||
|
||
use Magento\TestFramework\Helper\Bootstrap; | ||
use Magento\TestFramework\Helper\CacheCleaner; | ||
use Magento\Eav\Model\Entity\Attribute\AbstractAttribute; | ||
use Magento\Framework\App\CacheInterface; | ||
use Magento\Store\Api\StoreResolverInterface; | ||
use Magento\Framework\Serialize\Serializer\Json as Serializer; | ||
use Magento\Eav\Model\Entity\Attribute; | ||
|
||
/** | ||
* @magentoAppIsolation enabled | ||
*/ | ||
class DefaultFrontendTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
/** | ||
* @var DefaultFrontend | ||
*/ | ||
private $defaultFrontend; | ||
|
||
/** | ||
* @var \Magento\Framework\ObjectManagerInterface | ||
*/ | ||
private $objectManager; | ||
|
||
/** | ||
* @var AbstractAttribute | ||
*/ | ||
private $attribute; | ||
|
||
/** | ||
* @var array | ||
*/ | ||
private $options; | ||
|
||
/** | ||
* @var CacheInterface | ||
*/ | ||
private $cache; | ||
|
||
/** | ||
* @var StoreResolverInterface | ||
*/ | ||
private $storeResolver; | ||
|
||
/** | ||
* @var Serializer | ||
*/ | ||
private $serializer; | ||
|
||
protected function setUp() | ||
{ | ||
CacheCleaner::cleanAll(); | ||
$this->objectManager = Bootstrap::getObjectManager(); | ||
|
||
$this->defaultFrontend = $this->objectManager->get(DefaultFrontend::class); | ||
$this->cache = $this->objectManager->get(CacheInterface::class); | ||
$this->storeResolver = $this->objectManager->get(StoreResolverInterface::class); | ||
$this->serializer = $this->objectManager->get(Serializer::class); | ||
$this->attribute = $this->objectManager->get(Attribute::class); | ||
|
||
$this->attribute->setAttributeCode('store_id'); | ||
$this->options = $this->attribute->getSource()->getAllOptions(); | ||
$this->defaultFrontend->setAttribute($this->attribute); | ||
} | ||
|
||
public function testGetSelectOptions() | ||
{ | ||
$this->assertSame($this->options, $this->defaultFrontend->getSelectOptions()); | ||
$this->assertSame( | ||
$this->serializer->serialize($this->options), | ||
$this->cache->load($this->getCacheKey()) | ||
); | ||
} | ||
|
||
/** | ||
* Cache key generation | ||
* @return string | ||
*/ | ||
private function getCacheKey() | ||
{ | ||
return 'attribute-navigation-option-' . | ||
$this->defaultFrontend->getAttribute()->getAttributeCode() . '-' . | ||
$this->storeResolver->getCurrentStoreId(); | ||
} | ||
} |
938313e
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@voleye: be aware that this commit introduces a nasty bug where the wrong translation of the attribute option is getting cached if you work with multiple storeviews. This is because the StoreResolver isn't the correct class to get the current store id, see #9704 for more details.