ProxyTest.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Framework\Translate\Test\Unit\Inline;
  7. use \Magento\Framework\Translate\Inline\Proxy;
  8. class ProxyTest extends \PHPUnit\Framework\TestCase
  9. {
  10. /**
  11. * @var \Magento\Framework\ObjectManagerInterface|\PHPUnit_Framework_MockObject_MockObject
  12. */
  13. protected $objectManagerMock;
  14. /**
  15. * @var \Magento\Framework\Translate\Inline|\PHPUnit_Framework_MockObject_MockObject
  16. */
  17. protected $translateMock;
  18. protected function setUp()
  19. {
  20. $this->objectManagerMock = $this->createMock(\Magento\Framework\ObjectManagerInterface::class);
  21. $this->translateMock = $this->createMock(\Magento\Framework\Translate\Inline::class);
  22. }
  23. public function testIsAllowed()
  24. {
  25. $this->objectManagerMock->expects(
  26. $this->once()
  27. )->method(
  28. 'get'
  29. )->with(
  30. \Magento\Framework\Translate\Inline::class
  31. )->will(
  32. $this->returnValue($this->translateMock)
  33. );
  34. $this->objectManagerMock->expects($this->never())->method('create');
  35. $this->translateMock->expects($this->once())->method('isAllowed')->will($this->returnValue(false));
  36. $model = new Proxy(
  37. $this->objectManagerMock,
  38. \Magento\Framework\Translate\Inline::class,
  39. true
  40. );
  41. $this->assertFalse($model->isAllowed());
  42. }
  43. public function testGetParser()
  44. {
  45. $parser = new \stdClass();
  46. $this->objectManagerMock->expects(
  47. $this->once()
  48. )->method(
  49. 'create'
  50. )->with(
  51. \Magento\Framework\Translate\Inline::class
  52. )->will(
  53. $this->returnValue($this->translateMock)
  54. );
  55. $this->objectManagerMock->expects($this->never())->method('get');
  56. $this->translateMock->expects($this->once())->method('getParser')->will($this->returnValue($parser));
  57. $model = new Proxy(
  58. $this->objectManagerMock,
  59. \Magento\Framework\Translate\Inline::class,
  60. false
  61. );
  62. $this->assertEquals($parser, $model->getParser());
  63. }
  64. public function testProcessResponseBody()
  65. {
  66. $isJson = true;
  67. $this->objectManagerMock->expects(
  68. $this->once()
  69. )->method(
  70. 'get'
  71. )->with(
  72. \Magento\Framework\Translate\Inline::class
  73. )->will(
  74. $this->returnValue($this->translateMock)
  75. );
  76. $this->objectManagerMock->expects($this->never())->method('create');
  77. $this->translateMock->expects($this->once())
  78. ->method('processResponseBody')
  79. ->with('', $isJson)
  80. ->will($this->returnSelf());
  81. $model = new Proxy(
  82. $this->objectManagerMock,
  83. \Magento\Framework\Translate\Inline::class,
  84. true
  85. );
  86. $body = '';
  87. $this->assertEquals($this->translateMock, $model->processResponseBody($body, $isJson));
  88. }
  89. public function testGetAdditionalHtmlAttribute()
  90. {
  91. $this->objectManagerMock->expects(
  92. $this->once()
  93. )->method(
  94. 'create'
  95. )->with(
  96. \Magento\Framework\Translate\Inline::class
  97. )->will(
  98. $this->returnValue($this->translateMock)
  99. );
  100. $this->objectManagerMock->expects($this->never())->method('get');
  101. $this->translateMock->expects($this->exactly(2))
  102. ->method('getAdditionalHtmlAttribute')
  103. ->with($this->logicalOr('some_value', null))
  104. ->will($this->returnArgument(0));
  105. $model = new Proxy(
  106. $this->objectManagerMock,
  107. \Magento\Framework\Translate\Inline::class,
  108. false
  109. );
  110. $this->assertEquals('some_value', $model->getAdditionalHtmlAttribute('some_value'));
  111. $this->assertNull($model->getAdditionalHtmlAttribute());
  112. }
  113. }