ConfigTest.php 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Backend\Test\Unit\App;
  7. use Magento\Backend\App\Config;
  8. /**
  9. * Test reading by path and reading flag from config
  10. *
  11. * @see \Magento\Backend\App\Config
  12. * @package Magento\Backend\Test\Unit\App
  13. */
  14. class ConfigTest extends \PHPUnit\Framework\TestCase
  15. {
  16. /**
  17. * @var \Magento\Framework\App\Config|\PHPUnit_Framework_MockObject_MockObject
  18. */
  19. protected $appConfig;
  20. /**
  21. * @var Config
  22. */
  23. protected $model;
  24. protected function setUp()
  25. {
  26. $this->appConfig = $this->createPartialMock(\Magento\Framework\App\Config::class, ['get']);
  27. $this->model = new \Magento\Backend\App\Config($this->appConfig);
  28. }
  29. public function testGetValue()
  30. {
  31. $expectedValue = 'some value';
  32. $path = 'some path';
  33. $this->appConfig->expects(
  34. $this->once()
  35. )->method(
  36. 'get'
  37. )->with(
  38. $this->equalTo('system'),
  39. $this->equalTo('default/' . $path),
  40. $this->isNull()
  41. )->will(
  42. $this->returnValue($expectedValue)
  43. );
  44. $this->assertEquals($expectedValue, $this->model->getValue($path));
  45. }
  46. /**
  47. * @param string $configPath
  48. * @param mixed $configValue
  49. * @param bool $expectedResult
  50. * @dataProvider isSetFlagDataProvider
  51. */
  52. public function testIsSetFlag($configPath, $configValue, $expectedResult)
  53. {
  54. $this->appConfig->expects(
  55. $this->any()
  56. )->method(
  57. 'get'
  58. )->with(
  59. $this->equalTo('system'),
  60. $this->equalTo('default/' . $configPath)
  61. )->will(
  62. $this->returnValue($configValue)
  63. );
  64. $this->assertEquals($expectedResult, $this->model->isSetFlag($configPath));
  65. }
  66. /**
  67. * @return array
  68. */
  69. public function isSetFlagDataProvider()
  70. {
  71. return [
  72. ['a', 0, false],
  73. ['b', true, true],
  74. ['c', '0', false],
  75. ['d', '', false],
  76. ['e', 'some string', true],
  77. ['f', 1, true]
  78. ];
  79. }
  80. /**
  81. * Get ConfigData mock
  82. *
  83. * @param $mockedMethod
  84. * @return \PHPUnit_Framework_MockObject_MockObject|\Magento\Framework\App\Config\Data
  85. */
  86. protected function getConfigDataMock($mockedMethod)
  87. {
  88. return $this->createPartialMock(\Magento\Framework\App\Config\Data::class, [$mockedMethod]);
  89. }
  90. }