ConditionsTest.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Widget\Test\Unit\Helper;
  7. use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
  8. use Magento\Framework\Data\Wysiwyg\Normalizer;
  9. /**
  10. * Class ConditionsTest
  11. */
  12. class ConditionsTest extends \PHPUnit\Framework\TestCase
  13. {
  14. /**
  15. * @var \Magento\Widget\Helper\Conditions
  16. */
  17. protected $conditions;
  18. /**
  19. * @var \Magento\Framework\Serialize\Serializer\Json|\PHPUnit_Framework_MockObject_MockObject
  20. */
  21. private $serializer;
  22. /**
  23. * @var Normalizer|\PHPUnit_Framework_MockObject_MockObject
  24. */
  25. private $normalizer;
  26. /**
  27. * {@inheritdoc}
  28. */
  29. protected function setUp()
  30. {
  31. $this->serializer = $this->createMock(\Magento\Framework\Serialize\Serializer\Json::class);
  32. $this->normalizer = $this->createMock(Normalizer::class);
  33. $this->conditions = (new ObjectManager($this))->getObject(
  34. \Magento\Widget\Helper\Conditions::class,
  35. [
  36. 'serializer' => $this->serializer,
  37. 'normalizer' => $this->normalizer
  38. ]
  39. );
  40. }
  41. public function testEncodeDecode()
  42. {
  43. $value = ['string'];
  44. $serializedValue = 'serializedString';
  45. $normalizedValue = 'normalizedValue';
  46. $this->serializer->expects($this->once())
  47. ->method('serialize')
  48. ->with($value)
  49. ->willReturn($serializedValue);
  50. $this->serializer->expects($this->once())
  51. ->method('unserialize')
  52. ->with($serializedValue)
  53. ->willReturn($value);
  54. $this->normalizer->expects($this->once())
  55. ->method('replaceReservedCharacters')
  56. ->with($serializedValue)
  57. ->willReturn($normalizedValue);
  58. $this->normalizer->expects($this->once())
  59. ->method('restoreReservedCharacters')
  60. ->with($normalizedValue)
  61. ->willReturn($serializedValue);
  62. $encoded = $this->conditions->encode($value);
  63. $this->assertEquals($value, $this->conditions->decode($encoded));
  64. }
  65. }