1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Store\Block;
use Magento\Framework\App\ActionInterface;
use Magento\TestFramework\Helper\Bootstrap;
use Magento\Framework\Url\DecoderInterface;
use Magento\Framework\App\ScopeInterface;
/**
* Integration tests for \Magento\Store\Block\Switcher block.
*/
class SwitcherTest extends \PHPUnit\Framework\TestCase
{
/**
* @var \Magento\TestFramework\ObjectManager
*/
private $_objectManager;
/**
* @var DecoderInterface
*/
private $decoder;
/**
* Set up.
*
* @return void
*/
protected function setUp()
{
$this->_objectManager = Bootstrap::getObjectManager();
$this->decoder = Bootstrap::getObjectManager()->create(DecoderInterface::class);
}
/**
* Test that GetTargetStorePostData() method returns correct data.
*
* @magentoDataFixture Magento/Store/_files/store.php
* @return void
*/
public function testGetTargetStorePostData()
{
$storeCode = 'test';
/** @var \Magento\Store\Block\Switcher $block */
$block = $this->_objectManager->create(\Magento\Store\Block\Switcher::class);
/** @var \Magento\Store\Api\StoreRepositoryInterface $storeRepository */
$storeRepository = $this->_objectManager->create(\Magento\Store\Api\StoreRepositoryInterface::class);
$store = $storeRepository->get($storeCode);
$result = json_decode($block->getTargetStorePostData($store), true);
$url = parse_url($this->decoder->decode($result['data'][ActionInterface::PARAM_NAME_URL_ENCODED]));
$storeParsedQuery = [];
if (isset($url['query'])) {
parse_str($url['query'], $storeParsedQuery);
}
$this->assertSame($storeCode, $result['data']['___store']);
$this->assertSame($storeCode, $storeParsedQuery['___store']);
$this->assertSame(ScopeInterface::SCOPE_DEFAULT, $result['data']['___from_store']);
}
}