SwitcherTest.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Backend\Test\Unit\Block\Store;
  7. class SwitcherTest extends \PHPUnit\Framework\TestCase
  8. {
  9. /**
  10. * @var \Magento\Backend\Block\Store\Switcher
  11. */
  12. private $switcherBlock;
  13. private $storeManagerMock;
  14. protected function setUp()
  15. {
  16. $this->storeManagerMock = $this->createMock(\Magento\Store\Model\StoreManagerInterface::class);
  17. $objectHelper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
  18. $context = $objectHelper->getObject(
  19. \Magento\Backend\Block\Template\Context::class,
  20. [
  21. 'storeManager' => $this->storeManagerMock,
  22. ]
  23. );
  24. $this->switcherBlock = $objectHelper->getObject(
  25. \Magento\Backend\Block\Store\Switcher::class,
  26. ['context' => $context]
  27. );
  28. }
  29. public function testGetWebsites()
  30. {
  31. $websiteMock = $this->createMock(\Magento\Store\Model\Website::class);
  32. $websites = [0 => $websiteMock, 1 => $websiteMock];
  33. $this->storeManagerMock->expects($this->once())->method('getWebsites')->will($this->returnValue($websites));
  34. $this->assertEquals($websites, $this->switcherBlock->getWebsites());
  35. }
  36. public function testGetWebsitesIfSetWebsiteIds()
  37. {
  38. $websiteMock = $this->createMock(\Magento\Store\Model\Website::class);
  39. $websites = [0 => $websiteMock, 1 => $websiteMock];
  40. $this->storeManagerMock->expects($this->once())->method('getWebsites')->will($this->returnValue($websites));
  41. $this->switcherBlock->setWebsiteIds([1]);
  42. $expected = [1 => $websiteMock];
  43. $this->assertEquals($expected, $this->switcherBlock->getWebsites());
  44. }
  45. }