Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
ConditionsTest.php
Go to the documentation of this file.
1 <?php
8 
11 
15 class ConditionsTest extends \PHPUnit\Framework\TestCase
16 {
20  protected $conditions;
21 
25  private $serializer;
26 
30  private $normalizer;
31 
35  protected function setUp()
36  {
37  $this->serializer = $this->createMock(\Magento\Framework\Serialize\Serializer\Json::class);
38  $this->normalizer = $this->createMock(Normalizer::class);
39  $this->conditions = (new ObjectManager($this))->getObject(
40  \Magento\Widget\Helper\Conditions::class,
41  [
42  'serializer' => $this->serializer,
43  'normalizer' => $this->normalizer
44  ]
45  );
46  }
47 
48  public function testEncodeDecode()
49  {
50  $value = ['string'];
51  $serializedValue = 'serializedString';
52  $normalizedValue = 'normalizedValue';
53  $this->serializer->expects($this->once())
54  ->method('serialize')
55  ->with($value)
56  ->willReturn($serializedValue);
57  $this->serializer->expects($this->once())
58  ->method('unserialize')
59  ->with($serializedValue)
60  ->willReturn($value);
61  $this->normalizer->expects($this->once())
62  ->method('replaceReservedCharacters')
63  ->with($serializedValue)
64  ->willReturn($normalizedValue);
65  $this->normalizer->expects($this->once())
66  ->method('restoreReservedCharacters')
67  ->with($normalizedValue)
68  ->willReturn($serializedValue);
69  $encoded = $this->conditions->encode($value);
70  $this->assertEquals($value, $this->conditions->decode($encoded));
71  }
72 }
$value
Definition: gender.phtml:16