AdapterTest.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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;
  7. class AdapterTest extends \PHPUnit\Framework\TestCase
  8. {
  9. /**
  10. * Check that translate calls are passed to given translator
  11. *
  12. * @param string $method
  13. * @param string $strToTranslate
  14. * @param string $translatedStr
  15. * @dataProvider translateDataProvider
  16. */
  17. public function testTranslate($method, $strToTranslate, $translatedStr)
  18. {
  19. $translatorMock = $this->getMockBuilder('stdClass')->setMethods(['translate'])->getMock();
  20. $translatorMock->expects(
  21. $this->once()
  22. )->method(
  23. 'translate'
  24. )->with(
  25. $strToTranslate
  26. )->will(
  27. $this->returnValue($translatedStr)
  28. );
  29. $translator = new \Magento\Framework\Translate\Adapter(
  30. ['translator' => [$translatorMock, 'translate']]
  31. );
  32. $this->assertEquals($translatedStr, $translator->{$method}($strToTranslate));
  33. }
  34. /**
  35. * @return array
  36. */
  37. public function translateDataProvider()
  38. {
  39. return [['translate', 'Translate me!', 'Translated string']];
  40. }
  41. /**
  42. * Test that string is returned in any case
  43. */
  44. public function testTranslateNoProxy()
  45. {
  46. $translator = new \Magento\Framework\Translate\Adapter();
  47. $this->assertEquals('test string', $translator->translate('test string'));
  48. }
  49. /**
  50. * Test translation with more than one parameter passed
  51. */
  52. public function testUnderscoresTranslation()
  53. {
  54. $this->markTestIncomplete('MAGETWO-1012: i18n Improvements - Localization/Translations');
  55. }
  56. }