ScopeDefinerTest.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Config\Test\Unit\Model\Config;
  7. use Magento\Framework\App\Config\ScopeConfigInterface;
  8. use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
  9. class ScopeDefinerTest extends \PHPUnit\Framework\TestCase
  10. {
  11. /**
  12. * @var \Magento\Config\Model\Config\ScopeDefiner
  13. */
  14. protected $_model;
  15. /**
  16. * @var \PHPUnit_Framework_MockObject_MockObject
  17. */
  18. protected $_requestMock;
  19. protected function setUp()
  20. {
  21. $this->_requestMock = $this->createMock(\Magento\Framework\App\RequestInterface::class);
  22. $objectManager = new ObjectManager($this);
  23. $this->_model = $objectManager->getObject(
  24. \Magento\Config\Model\Config\ScopeDefiner::class,
  25. ['request' => $this->_requestMock]
  26. );
  27. }
  28. public function testGetScopeReturnsDefaultScopeIfNoScopeDataIsSpecified()
  29. {
  30. $this->assertEquals(ScopeConfigInterface::SCOPE_TYPE_DEFAULT, $this->_model->getScope());
  31. }
  32. public function testGetScopeReturnsStoreScopeIfStoreIsSpecified()
  33. {
  34. $this->_requestMock->expects(
  35. $this->any()
  36. )->method(
  37. 'getParam'
  38. )->will(
  39. $this->returnValueMap([['website', null, 'someWebsite'], ['store', null, 'someStore']])
  40. );
  41. $this->assertEquals(\Magento\Store\Model\ScopeInterface::SCOPE_STORE, $this->_model->getScope());
  42. }
  43. public function testGetScopeReturnsWebsiteScopeIfWebsiteIsSpecified()
  44. {
  45. $this->_requestMock->expects(
  46. $this->any()
  47. )->method(
  48. 'getParam'
  49. )->will(
  50. $this->returnValueMap([['website', null, 'someWebsite'], ['store', null, null]])
  51. );
  52. $this->assertEquals(\Magento\Store\Model\ScopeInterface::SCOPE_WEBSITE, $this->_model->getScope());
  53. }
  54. }