Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Base64JsonTest.php
Go to the documentation of this file.
1 <?php
7 
8 class Base64JsonTest extends \PHPUnit\Framework\TestCase
9 {
13  private $base64json;
14 
15  protected function setUp()
16  {
17  $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
18  $this->base64json = $objectManager->getObject(\Magento\Framework\Serialize\Serializer\Base64Json::class, [
19  'jsonSerializer' => new \Magento\Framework\Serialize\Serializer\Json()
20  ]);
21  }
22 
28  public function testSerialize($value, $expected)
29  {
30  $this->assertEquals($expected, $this->base64json->serialize($value));
31  }
32 
36  public function serializeDataProvider()
37  {
38  $dataObject = new \Magento\Framework\DataObject(['something']);
39  return [
40  ['', 'IiI='], // ""
41  ['string', 'InN0cmluZyI='], // "string"
42  [null, 'bnVsbA=='], // null
43  [false, 'ZmFsc2U='], // false
44  [['a' => 'b', 'd' => 123], 'eyJhIjoiYiIsImQiOjEyM30='], // {"a":"b","d":123}
45  [123, 'MTIz'], // 123
46  [10.56, 'MTAuNTY='], // 10.56
47  [$dataObject, 'e30='], // {}
48  ];
49  }
50 
56  public function testUnserialize($value, $expected)
57  {
58  $this->assertEquals($expected, $this->base64json->unserialize($value));
59  }
60 
64  public function unserializeDataProvider()
65  {
66  return [
67  ['""', ''],
68  ['"string"', 'string'],
69  ['null', null],
70  ['false', false],
71  ['{"a":"b","d":123}', ['a' => 'b', 'd' => 123]],
72  ['123', 123],
73  ['10.56', 10.56],
74  ["IiI=", ''],
75  ['InN0cmluZyI=', 'string'],
76  ['bnVsbA==', null],
77  ['ZmFsc2U=', false],
78  ['eyJhIjoiYiIsImQiOjEyM30=', ['a' => 'b', 'd' => 123]],
79  ['MTIz', 123],
80  ['MTAuNTY=', 10.56],
81  ['e30=', []],
82  ];
83  }
84 }
$objectManager
Definition: bootstrap.php:17
$value
Definition: gender.phtml:16