Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
ValueCheckerTest.php
Go to the documentation of this file.
1 <?php
7 
9 
10 class ValueCheckerTest extends \PHPUnit\Framework\TestCase
11 {
13  protected $fallbackResolver;
14 
16  protected $appConfig;
17 
19  protected $valueChecker;
20 
22  protected $valueProcessor;
23 
24  public function setUp()
25  {
26  $this->fallbackResolver = $this->getMockForAbstractClass(
27  \Magento\Framework\App\ScopeFallbackResolverInterface::class,
28  [],
29  '',
30  false
31  );
32  $this->appConfig = $this->createMock(\Magento\Framework\App\Config::class);
33  $this->valueProcessor = $this->getMockBuilder(\Magento\Theme\Model\Design\Config\ValueProcessor::class)
34  ->disableOriginalConstructor()
35  ->getMock();
36 
37  $this->valueChecker = new ValueChecker(
38  $this->fallbackResolver,
39  $this->appConfig,
40  $this->valueProcessor
41  );
42  }
43 
44  public function testIsDifferentFromDefault()
45  {
46  $this->fallbackResolver->expects($this->once())
47  ->method('getFallbackScope')
48  ->with('default', 0)
49  ->willReturn([null, null]);
50 
51  $this->assertTrue(
52  $this->valueChecker->isDifferentFromDefault(
53  'value',
54  'default',
55  0,
56  ['path' => 'design/head/default_title']
57  )
58  );
59  }
60 
62  {
63  $this->fallbackResolver->expects($this->once())
64  ->method('getFallbackScope')
65  ->with('website', 1)
66  ->willReturn(['default', 0]);
67  $this->appConfig->expects($this->once())
68  ->method('getValue')
69  ->with('design/head/default_title', 'default', 0)
70  ->willReturn('');
71  $this->valueProcessor->expects($this->atLeastOnce())
72  ->method('process')
73  ->willReturnArgument(0);
74 
75  $this->assertTrue(
76  $this->valueChecker->isDifferentFromDefault(
77  'value',
78  'website',
79  1,
80  ['path' => 'design/head/default_title']
81  )
82  );
83  }
84 
86  {
87  $path = 'design/head/default_title';
88  $this->fallbackResolver->expects($this->once())
89  ->method('getFallbackScope')
90  ->with('website', 1)
91  ->willReturn(['default', 0]);
92  $this->appConfig
93  ->expects($this->once())
94  ->method('getValue')
95  ->with($path, 'default', 0)
96  ->willReturn([
97  [
98  'qwe' => 123
99  ],
100  ]);
101  $this->valueProcessor->expects($this->atLeastOnce())
102  ->method('process')
103  ->willReturnArgument(0);
104  $this->assertTrue(
105  $this->valueChecker->isDifferentFromDefault(
106  [
107  [
108  'sdf' => 1
109  ],
110 
111  ],
112  'website',
113  1,
114  ['path' => $path]
115  )
116  );
117  }
118 }