XmlTest.php 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Cron\Test\Unit\Model\Config\Converter;
  7. class XmlTest extends \PHPUnit\Framework\TestCase
  8. {
  9. /**
  10. * @var \Magento\Cron\Model\Config\Converter\Xml
  11. */
  12. protected $_converter;
  13. /**
  14. * Initialize parameters
  15. */
  16. protected function setUp()
  17. {
  18. $this->_converter = new \Magento\Cron\Model\Config\Converter\Xml();
  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 not existing of node <job>
  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. 'default' => [
  43. 'job1' => [
  44. 'name' => 'job1',
  45. 'schedule' => '30 2 * * *',
  46. 'instance' => 'Model1',
  47. 'method' => 'method1',
  48. ],
  49. 'job2' => [
  50. 'name' => 'job2',
  51. 'schedule' => '* * * * *',
  52. 'instance' => 'Model2',
  53. 'method' => 'method2',
  54. ],
  55. 'job3' => [
  56. 'name' => 'job3',
  57. 'instance' => 'Model3',
  58. 'method' => 'method3',
  59. 'config_path' => 'some/config/path',
  60. ],
  61. ],
  62. ];
  63. $xmlFile = __DIR__ . '/../_files/crontab_valid.xml';
  64. $dom = new \DOMDocument();
  65. $dom->loadXML(file_get_contents($xmlFile));
  66. $result = $this->_converter->convert($dom);
  67. $this->assertEquals($expected, $result);
  68. }
  69. /**
  70. * Testing converting not valid cron configuration, expect to get exception
  71. *
  72. * @expectedException \InvalidArgumentException
  73. */
  74. public function testConvertWrongConfiguration()
  75. {
  76. $xmlFile = __DIR__ . '/../_files/crontab_invalid.xml';
  77. $dom = new \DOMDocument();
  78. $dom->loadXML(file_get_contents($xmlFile));
  79. $this->_converter->convert($dom);
  80. }
  81. }