LayoutTestWithExceptions.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Framework\View;
  7. use \Magento\Framework\App\State;
  8. class LayoutTestWithExceptions extends \PHPUnit\Framework\TestCase
  9. {
  10. /**
  11. * @var \Magento\Framework\View\Layout
  12. */
  13. protected $layout;
  14. public function setUp()
  15. {
  16. $objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
  17. $layoutFactory = $objectManager->get(\Magento\Framework\View\LayoutFactory::class);
  18. $this->layout = $layoutFactory->create();
  19. $layoutElement = new \Magento\Framework\View\Layout\Element(
  20. __DIR__ . '/_files/layout_with_exceptions/layout.xml',
  21. 0,
  22. true
  23. );
  24. $this->layout->setXml($layoutElement);
  25. $objectManager->get(\Magento\Framework\App\Cache\Type\Layout::class)->clean();
  26. }
  27. /**
  28. * @expectedException \Magento\Framework\Exception\LocalizedException
  29. * @expectedExceptionMessage Construction problem.
  30. */
  31. public function testProcessWithExceptionsDeveloperMode()
  32. {
  33. $this->layout->generateElements();
  34. }
  35. /**
  36. * @magentoAppIsolation enabled
  37. */
  38. public function testProcessWithExceptions()
  39. {
  40. \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(\Magento\Framework\App\State::class)
  41. ->setMode(State::MODE_DEFAULT);
  42. $this->layout->generateElements();
  43. $this->layout->addOutputElement('block.with.broken.constructor');
  44. $this->layout->addOutputElement('block.with.broken.layout');
  45. $this->layout->addOutputElement('block.with.broken.action');
  46. $this->assertEmpty($this->layout->getOutput());
  47. }
  48. }