38 $this->layoutFactory = $this->objectManager->get(\
Magento\Framework\View\LayoutFactory::class);
39 $this->state = $this->objectManager->get(\
Magento\Framework\
App\State::class);
48 protected function _getLayoutModel($fixtureFile)
50 $this->objectManager->get(\
Magento\Framework\
App\Cache\Type\Layout::class)->clean();
51 $layout = $this->layoutFactory->create();
53 $xml = simplexml_load_file(
54 __DIR__ .
"/_files/layout_directives_test/{$fixtureFile}",
57 $layout->loadString($xml->asXml());
58 $layout->generateElements();
78 $layout = $this->_getLayoutModel(
'render.xml');
79 $this->assertEquals(
'124', $layout->renderElement(
'container_one'));
80 $this->assertEquals(
'12', $layout->renderElement(
'block_one'));
89 $layout = $this->_getLayoutModel(
'render.xml');
90 $this->assertEmpty($layout->renderElement(
'nonexisting_element'));
92 $this->expectExceptionMessage(
93 'The element with the "nonexisting_element" ID wasn\'t found. Verify the ID and try again.' 105 $layout = $this->_getLayoutModel(
'get_block.xml');
106 $this->assertInstanceOf(\
Magento\Framework\View\
Element\Text::class, $layout->getBlock(
'block_first'));
107 $this->assertInstanceOf(\
Magento\Framework\View\
Element\Text::class, $layout->getBlock(
'block_second'));
112 $layout = $this->_getLayoutModel(
'arguments.xml');
113 $this->assertEquals(
'1', $layout->getBlock(
'block_with_args')->getOne());
114 $this->assertEquals(
'two', $layout->getBlock(
'block_with_args')->getTwo());
115 $this->assertEquals(
'3', $layout->getBlock(
'block_with_args')->getThree());
120 $layout = $this->_getLayoutModel(
'arguments_complex_values.xml');
122 [
'parameters' => [
'first' =>
'1',
'second' =>
'2']],
123 $layout->getBlock(
'block_with_args_complex_values')->getOne()
125 $this->assertEquals(
'two', $layout->getBlock(
'block_with_args_complex_values')->getTwo());
127 [
'extra' => [
'key1' =>
'value1',
'key2' =>
'value2']],
128 $layout->getBlock(
'block_with_args_complex_values')->getThree()
134 $layout = $this->_getLayoutModel(
'arguments_object_type.xml');
135 $this->assertInstanceOf(
136 \
Magento\Framework\Data\Collection::class,
137 $layout->getBlock(
'block_with_object_args')->getOne()
139 $this->assertInstanceOf(
140 \
Magento\Framework\Data\Collection::class,
141 $layout->getBlock(
'block_with_object_args')->getTwo()
143 $this->assertEquals(3, $layout->getBlock(
'block_with_object_args')->getThree());
148 $layout = $this->_getLayoutModel(
'arguments_url_type.xml');
149 $this->assertContains(
'customer/account/login', $layout->getBlock(
'block_with_url_args')->getOne());
150 $this->assertContains(
'customer/account/logout', $layout->getBlock(
'block_with_url_args')->getTwo());
151 $this->assertContains(
'customer_id/3', $layout->getBlock(
'block_with_url_args')->getTwo());
156 $this->markTestSkipped(
'Will be fixed after MAGETWO-33840 will be done');
157 $layout = $this->_getLayoutModel(
'arguments_object_type_updaters.xml');
159 $expectedObjectData = [0 =>
'updater call', 1 =>
'updater call'];
161 $expectedSimpleData = 1;
163 $dataSource = $layout->getBlock(
'block_with_object_updater_args')->getOne();
164 $this->assertInstanceOf(\
Magento\Framework\Data\Collection::class, $dataSource);
165 $this->assertEquals($expectedObjectData, $dataSource->getUpdaterCall());
166 $this->assertEquals($expectedSimpleData, $layout->getBlock(
'block_with_object_updater_args')->getTwo());
174 $layout = $this->_getLayoutModel(
'move_the_same_alias.xml');
175 $this->assertEquals(
'container1', $layout->getParentName(
'no_name3'));
183 $layout = $this->_getLayoutModel(
'move_new_alias.xml');
184 $this->assertEquals(
'new_alias', $layout->getElementAlias(
'no_name3'));
189 $layout = $this->_getLayoutModel(
'action_for_anonymous_parent_block.xml');
190 $this->assertEquals(
'schedule_block0', $layout->getParentName(
'test.block.insert'));
191 $this->assertEquals(
'schedule_block1', $layout->getParentName(
'test.block.append'));
199 $layout = $this->_getLayoutModel(
'remove.xml');
200 $this->assertFalse($layout->getBlock(
'no_name2'));
201 $this->assertFalse($layout->getBlock(
'child_block1'));
202 $this->assertTrue($layout->isBlock(
'child_block2'));
210 $layout = $this->_getLayoutModel(
'remove_cancellation.xml');
211 $this->assertTrue($layout->isContainer(
'container1'));
212 $this->assertTrue($layout->isBlock(
'child_block1'));
213 $this->assertTrue($layout->isBlock(
'no_name2'));
214 $this->assertFalse($layout->getBlock(
'not_exist'));
222 $layout = $this->_getLayoutModel(
'move.xml');
223 $this->assertEquals(
'container2', $layout->getParentName(
'container1'));
224 $this->assertEquals(
'container1', $layout->getParentName(
'no.name2'));
225 $this->assertEquals(
'block_container', $layout->getParentName(
'no_name3'));
228 $this->assertEquals(
'block_container', $layout->getParentName(
'no_name'));
229 $childrenOrderArray = array_keys($layout->getChildBlocks($layout->getParentName(
'no_name')));
230 $positionAfter = array_search(
'child_block1', $childrenOrderArray);
231 $positionToVerify = array_search(
'no_name', $childrenOrderArray);
232 $this->assertEquals($positionAfter, --$positionToVerify);
235 $this->assertEquals(
'block_container', $layout->getParentName(
'no_name4'));
236 $childrenOrderArray = array_keys($layout->getChildBlocks($layout->getParentName(
'no_name4')));
237 $positionBefore = array_search(
'child_block2', $childrenOrderArray);
238 $positionToVerify = array_search(
'no_name4', $childrenOrderArray);
239 $this->assertEquals($positionBefore, ++$positionToVerify);
247 $this->_getLayoutModel(
'move_broken.xml');
255 $this->_getLayoutModel(
'move_alias_broken.xml');
261 $this->expectException(
'OutOfBoundsException');
263 $this->_getLayoutModel(
'remove_broken.xml');
274 $layout = $this->_getLayoutModel(
$case);
275 $this->assertEquals($expectedResult, $layout->renderElement(
'root'));
284 'Before element which is after' => [
'sort_before_after.xml',
'312'],
285 'Before element which is previous' => [
'sort_before_before.xml',
'213'],
286 'After element which is after' => [
'sort_after_after.xml',
'312'],
287 'After element which is previous' => [
'sort_after_previous.xml',
'321']
297 $layout = $this->_getLayoutModel(
'ifconfig.xml');
298 $this->assertFalse($layout->getBlock(
'block1'));
299 $this->assertFalse($layout->getBlock(
'block2'));
300 $this->assertInstanceOf(\
Magento\Framework\View\
Element\BlockInterface::class, $layout->getBlock(
'block3'));
301 $this->assertFalse($layout->getBlock(
'block4'));
310 $layout = $this->_getLayoutModel(
'group.xml');
311 $childNames = $layout->getBlock(
'block1')->getGroupChildNames(
'group1');
312 $this->assertEquals([
'block2',
'block3'], $childNames);
testLayoutObjectArgumentsDirective()
testLayoutUrlArgumentsDirective()
testLayoutObjectArgumentUpdatersDirective()
defined('TESTS_BP')||define('TESTS_BP' __DIR__
testRenderNonExistentElementShouldThrowException()
testLayoutArgumentsDirectiveIfComplexValues()
testGetBlockUnscheduled()
testActionAnonymousParentBlock()
testLayoutArgumentsDirective()
sortSpecialCasesDataProvider()
testSortSpecialCases($case, $expectedResult)
static getObjectManager()