ConverterTest.php 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Sales\Test\Unit\Model\Config;
  7. class ConverterTest extends \PHPUnit\Framework\TestCase
  8. {
  9. /**
  10. * @var \Magento\Sales\Model\Config\Converter
  11. */
  12. protected $_converter;
  13. /**
  14. * Initialize parameters
  15. */
  16. protected function setUp()
  17. {
  18. $this->_converter = new \Magento\Sales\Model\Config\Converter();
  19. }
  20. /**
  21. * Testing wrong data incoming
  22. */
  23. public function testConvertWrongIncomingData()
  24. {
  25. $result = $this->_converter->convert(['wrong data']);
  26. $this->assertEmpty($result);
  27. }
  28. /**
  29. * Testing empty data
  30. */
  31. public function testConvertNoElements()
  32. {
  33. $result = $this->_converter->convert(new \DOMDocument());
  34. $this->assertEmpty($result);
  35. }
  36. /**
  37. * Testing converting valid cron configuration
  38. */
  39. public function testConvert()
  40. {
  41. $expected = [
  42. 'section1' => [
  43. 'group1' => [
  44. 'item1' => [
  45. 'instance' => 'instance1',
  46. 'sort_order' => '1',
  47. 'renderers' => ['renderer1' => 'instance1'],
  48. ],
  49. ],
  50. 'group2' => [
  51. 'item1' => ['instance' => 'instance1', 'sort_order' => '1', 'renderers' => []],
  52. ],
  53. ],
  54. 'section2' => [
  55. 'group1' => [
  56. 'item1' => ['instance' => 'instance1', 'sort_order' => '1', 'renderers' => []],
  57. ],
  58. ],
  59. 'order' => ['available_product_types' => ['type1', 'type2']],
  60. ];
  61. $xmlFile = __DIR__ . '/_files/sales_valid.xml';
  62. $dom = new \DOMDocument();
  63. $dom->loadXML(file_get_contents($xmlFile));
  64. $result = $this->_converter->convert($dom);
  65. $this->assertEquals($expected, $result);
  66. }
  67. /**
  68. * Testing converting not valid cron configuration, expect to get exception
  69. *
  70. * @expectedException \InvalidArgumentException
  71. */
  72. public function testConvertWrongConfiguration()
  73. {
  74. $xmlFile = __DIR__ . '/_files/sales_invalid.xml';
  75. $dom = new \DOMDocument();
  76. $dom->loadXML(file_get_contents($xmlFile));
  77. $this->_converter->convert($dom);
  78. }
  79. }