LoaderTest.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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. /**
  8. * @package Magento\Config\Test\Unit\Model\Config
  9. */
  10. class LoaderTest extends \PHPUnit\Framework\TestCase
  11. {
  12. /**
  13. * @var \Magento\Config\Model\Config\Loader
  14. */
  15. protected $_model;
  16. /**
  17. * @var \PHPUnit_Framework_MockObject_MockObject
  18. */
  19. protected $_configValueFactory;
  20. /**
  21. * @var \PHPUnit_Framework_MockObject_MockObject
  22. */
  23. protected $_configCollection;
  24. protected function setUp()
  25. {
  26. $this->_configValueFactory = $this->createPartialMock(
  27. \Magento\Framework\App\Config\ValueFactory::class,
  28. ['create', 'getCollection']
  29. );
  30. $this->_model = new \Magento\Config\Model\Config\Loader($this->_configValueFactory);
  31. $this->_configCollection = $this->createMock(\Magento\Config\Model\ResourceModel\Config\Data\Collection::class);
  32. $this->_configCollection->expects(
  33. $this->once()
  34. )->method(
  35. 'addScopeFilter'
  36. )->with(
  37. 'scope',
  38. 'scopeId',
  39. 'section'
  40. )->will(
  41. $this->returnSelf()
  42. );
  43. $configDataMock = $this->createMock(\Magento\Framework\App\Config\Value::class);
  44. $this->_configValueFactory->expects(
  45. $this->once()
  46. )->method(
  47. 'create'
  48. )->will(
  49. $this->returnValue($configDataMock)
  50. );
  51. $configDataMock->expects(
  52. $this->any()
  53. )->method(
  54. 'getCollection'
  55. )->will(
  56. $this->returnValue($this->_configCollection)
  57. );
  58. $this->_configCollection->expects(
  59. $this->once()
  60. )->method(
  61. 'getItems'
  62. )->will(
  63. $this->returnValue(
  64. [new \Magento\Framework\DataObject(['path' => 'section', 'value' => 10, 'config_id' => 20])]
  65. )
  66. );
  67. }
  68. protected function tearDown()
  69. {
  70. unset($this->_configValueFactory);
  71. unset($this->_model);
  72. unset($this->_configCollection);
  73. }
  74. public function testGetConfigByPathInFullMode()
  75. {
  76. $expected = ['section' => ['path' => 'section', 'value' => 10, 'config_id' => 20]];
  77. $this->assertEquals($expected, $this->_model->getConfigByPath('section', 'scope', 'scopeId', true));
  78. }
  79. public function testGetConfigByPath()
  80. {
  81. $expected = ['section' => 10];
  82. $this->assertEquals($expected, $this->_model->getConfigByPath('section', 'scope', 'scopeId', false));
  83. }
  84. }