ParserTest.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Backend\Test\Unit\Model\Widget\Grid;
  7. class ParserTest extends \PHPUnit\Framework\TestCase
  8. {
  9. /**
  10. * @var \Magento\Backend\Model\Widget\Grid\Parser
  11. */
  12. protected $_model;
  13. protected function setUp()
  14. {
  15. $this->_model = new \Magento\Backend\Model\Widget\Grid\Parser();
  16. }
  17. /**
  18. * @param string $expression
  19. * @param array $expected
  20. * @dataProvider parseExpressionDataProvider
  21. */
  22. public function testParseExpression($expression, $expected)
  23. {
  24. $this->assertEquals($expected, $this->_model->parseExpression($expression));
  25. }
  26. /**
  27. * @return array
  28. */
  29. public function parseExpressionDataProvider()
  30. {
  31. return [
  32. ['1-2', ['1', '2', '-']],
  33. ['1*2', ['1', '2', '*']],
  34. ['1/2', ['1', '2', '/']],
  35. ['1+2+3', ['1', '2', '+', '3', '+']],
  36. ['1*2*3+4', ['1', '2', '*', '3', '*', '4', '+']],
  37. ['1-2-3', ['1', '2', '-', '3', '-']],
  38. ['1*2*3', ['1', '2', '*', '3', '*']],
  39. ['1/2/3', ['1', '2', '/', '3', '/']],
  40. [
  41. '1 * 2 / 3 + 4 * 5 * 6 - 7 - 8',
  42. ['1', '2', '*', '3', '/', '4', '5', '*', '6', '*', '+', '7', '-', '8', '-']
  43. ]
  44. ];
  45. }
  46. /**
  47. * @param $operation
  48. * @param $expected
  49. * @dataProvider isOperationDataProvider
  50. */
  51. public function testIsOperation($operation, $expected)
  52. {
  53. $this->assertEquals($expected, $this->_model->isOperation($operation));
  54. }
  55. /**
  56. * @return array
  57. */
  58. public function isOperationDataProvider()
  59. {
  60. return [
  61. ['+', true],
  62. ['-', true],
  63. ['*', true],
  64. ['/', true],
  65. ['0', false],
  66. ['aa', false]
  67. ];
  68. }
  69. }