ValueCheckerTest.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Theme\Test\Unit\Model\Design\Config;
  7. use Magento\Theme\Model\Design\Config\ValueChecker;
  8. class ValueCheckerTest extends \PHPUnit\Framework\TestCase
  9. {
  10. /** @var \Magento\Framework\App\ScopeFallbackResolverInterface|\PHPUnit_Framework_MockObject_MockObject */
  11. protected $fallbackResolver;
  12. /** @var \Magento\Framework\App\Config|\PHPUnit_Framework_MockObject_MockObject */
  13. protected $appConfig;
  14. /** @var ValueChecker */
  15. protected $valueChecker;
  16. /** @var \Magento\Theme\Model\Design\Config\ValueProcessor|\PHPUnit_Framework_MockObject_MockObject */
  17. protected $valueProcessor;
  18. public function setUp()
  19. {
  20. $this->fallbackResolver = $this->getMockForAbstractClass(
  21. \Magento\Framework\App\ScopeFallbackResolverInterface::class,
  22. [],
  23. '',
  24. false
  25. );
  26. $this->appConfig = $this->createMock(\Magento\Framework\App\Config::class);
  27. $this->valueProcessor = $this->getMockBuilder(\Magento\Theme\Model\Design\Config\ValueProcessor::class)
  28. ->disableOriginalConstructor()
  29. ->getMock();
  30. $this->valueChecker = new ValueChecker(
  31. $this->fallbackResolver,
  32. $this->appConfig,
  33. $this->valueProcessor
  34. );
  35. }
  36. public function testIsDifferentFromDefault()
  37. {
  38. $this->fallbackResolver->expects($this->once())
  39. ->method('getFallbackScope')
  40. ->with('default', 0)
  41. ->willReturn([null, null]);
  42. $this->assertTrue(
  43. $this->valueChecker->isDifferentFromDefault(
  44. 'value',
  45. 'default',
  46. 0,
  47. ['path' => 'design/head/default_title']
  48. )
  49. );
  50. }
  51. public function testIsDifferentFromDefaultWithWebsiteScope()
  52. {
  53. $this->fallbackResolver->expects($this->once())
  54. ->method('getFallbackScope')
  55. ->with('website', 1)
  56. ->willReturn(['default', 0]);
  57. $this->appConfig->expects($this->once())
  58. ->method('getValue')
  59. ->with('design/head/default_title', 'default', 0)
  60. ->willReturn('');
  61. $this->valueProcessor->expects($this->atLeastOnce())
  62. ->method('process')
  63. ->willReturnArgument(0);
  64. $this->assertTrue(
  65. $this->valueChecker->isDifferentFromDefault(
  66. 'value',
  67. 'website',
  68. 1,
  69. ['path' => 'design/head/default_title']
  70. )
  71. );
  72. }
  73. public function testIsDifferentFromDefaultWithArrays()
  74. {
  75. $path = 'design/head/default_title';
  76. $this->fallbackResolver->expects($this->once())
  77. ->method('getFallbackScope')
  78. ->with('website', 1)
  79. ->willReturn(['default', 0]);
  80. $this->appConfig
  81. ->expects($this->once())
  82. ->method('getValue')
  83. ->with($path, 'default', 0)
  84. ->willReturn([
  85. [
  86. 'qwe' => 123
  87. ],
  88. ]);
  89. $this->valueProcessor->expects($this->atLeastOnce())
  90. ->method('process')
  91. ->willReturnArgument(0);
  92. $this->assertTrue(
  93. $this->valueChecker->isDifferentFromDefault(
  94. [
  95. [
  96. 'sdf' => 1
  97. ],
  98. ],
  99. 'website',
  100. 1,
  101. ['path' => $path]
  102. )
  103. );
  104. }
  105. }