PageRenderTime 50ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/dev/tests/unit/testsuite/Mage/DesignEditor/Model/History/Compact/LayoutTest.php

https://bitbucket.org/sunil_nextbits/magento2
PHP | 141 lines | 74 code | 7 blank | 60 comment | 0 complexity | 2c029c034f053893404a9dc990a95be6 MD5 | raw file
  1. <?php
  2. /**
  3. * Magento
  4. *
  5. * NOTICE OF LICENSE
  6. *
  7. * This source file is subject to the Open Software License (OSL 3.0)
  8. * that is bundled with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://opensource.org/licenses/osl-3.0.php
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@magentocommerce.com so we can send you a copy immediately.
  14. *
  15. * DISCLAIMER
  16. *
  17. * Do not edit or add to this file if you wish to upgrade Magento to newer
  18. * versions in the future. If you wish to customize Magento for your
  19. * needs please refer to http://www.magentocommerce.com for more information.
  20. *
  21. * @category Magento
  22. * @package Mage_DesignEditor
  23. * @subpackage unit_tests
  24. * @copyright Copyright (c) 2012 X.commerce, Inc. (http://www.magentocommerce.com)
  25. * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
  26. */
  27. class Mage_DesignEditor_Model_History_Compact_LayoutTest extends PHPUnit_Framework_TestCase
  28. {
  29. /**
  30. * Layout object
  31. *
  32. * @var Mage_DesignEditor_Model_History_Compact_Layout
  33. */
  34. protected $_layout;
  35. /**
  36. * Init test environment
  37. */
  38. protected function setUp()
  39. {
  40. $this->_layout = new Mage_DesignEditor_Model_History_Compact_Layout;
  41. }
  42. /**
  43. * Get mocked object of collection
  44. *
  45. * @param array $data
  46. * @return Mage_DesignEditor_Model_Change_Collection|PHPUnit_Framework_MockObject_MockObject
  47. */
  48. protected function _mockCollection(array $data)
  49. {
  50. /** @var $collectionMock Mage_DesignEditor_Model_Change_Collection */
  51. $collectionMock = $this->getMock(
  52. 'Mage_DesignEditor_Model_Change_Collection', array('_init'), array(), '', true
  53. );
  54. foreach ($data as $item) {
  55. $changeClassName = Mage_DesignEditor_Model_Change_Factory::getClass($item);
  56. /** @var $itemMock Mage_DesignEditor_Model_Change_LayoutAbstract */
  57. $itemMock = $this->getMock(
  58. $changeClassName, array('getLayoutUpdateData', 'getLayoutDirective'), array(), '', false
  59. );
  60. $itemMock->setData($item);
  61. $collectionMock->addItem($itemMock);
  62. }
  63. return $collectionMock;
  64. }
  65. /**
  66. * Test compact logic with wrong collection
  67. *
  68. * @expectedException Magento_Exception
  69. * @expectedExceptionMessage Compact collection is missed
  70. */
  71. public function testBrokenCompactCollection()
  72. {
  73. $this->_layout->compact();
  74. }
  75. /**
  76. * Test compact logic
  77. *
  78. * @param array $data
  79. * @param array $expectedData
  80. * @dataProvider removeDataSamples
  81. */
  82. public function testCompact($data, $expectedData)
  83. {
  84. $collection = $this->_mockCollection($data);
  85. $this->_layout->compact($collection);
  86. $compactedData = array();
  87. /** @var $change Mage_DesignEditor_Model_Change_LayoutAbstract */
  88. foreach ($collection as $change) {
  89. $compactedData[] = $change->getData();
  90. }
  91. $this->assertEquals($expectedData, $compactedData);
  92. }
  93. /**
  94. * DataProvider with remove directives
  95. *
  96. * @return array
  97. */
  98. public function removeDataSamples()
  99. {
  100. return array(
  101. array(array(
  102. array('type' => 'layout', 'action_name' => 'remove', 'element_name' => 'head'),
  103. array('type' => 'layout', 'action_name' => 'move', 'element_name' => 'head',
  104. 'origin_container' => 'root', 'destination_container' => 'footer'),
  105. array('type' => 'layout', 'action_name' => 'remove', 'element_name' => 'page.pools'),
  106. array('type' => 'layout', 'action_name' => 'remove', 'element_name' => 'head'),
  107. array('type' => 'layout', 'action_name' => 'remove', 'element_name' => 'page.pools'),
  108. array('type' => 'layout', 'action_name' => 'remove', 'element_name' => 'page.pools'),
  109. array('type' => 'layout', 'action_name' => 'remove', 'element_name' => 'head')
  110. ), array(
  111. array('type' => 'layout', 'action_name' => 'remove', 'element_name' => 'page.pools'),
  112. array('type' => 'layout', 'action_name' => 'remove', 'element_name' => 'head'),
  113. )),
  114. array(array(
  115. array('type' => 'layout', 'action_name' => 'move', 'element_name' => 'head', 'origin_order' => 0,
  116. 'origin_container' => 'root', 'destination_container' => 'footer', 'destination_order' => 1),
  117. array('type' => 'layout', 'action_name' => 'move', 'element_name' => 'head', 'origin_order' => 1,
  118. 'origin_container' => 'footer', 'destination_container' => 'page.pools', 'destination_order' => 2),
  119. array('type' => 'layout', 'action_name' => 'move', 'element_name' => 'head', 'origin_order' => 2,
  120. 'origin_container' => 'page.pools', 'destination_container' => 'footer', 'destination_order' => 3),
  121. ), array(
  122. array('type' => 'layout', 'action_name' => 'move', 'element_name' => 'head', 'origin_order' => 2,
  123. 'origin_container' => 'page.pools', 'destination_container' => 'footer', 'destination_order' => 3)
  124. )),
  125. array(array(
  126. array('type' => 'layout', 'action_name' => 'move', 'element_name' => 'head', 'origin_order' => 0,
  127. 'origin_container' => 'root', 'destination_container' => 'footer', 'destination_order' => 1),
  128. array('type' => 'layout', 'action_name' => 'move', 'element_name' => 'head', 'origin_order' => 1,
  129. 'origin_container' => 'footer', 'destination_container' => 'root', 'destination_order' => 0),
  130. ), array(
  131. )),
  132. );
  133. }
  134. }