Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Protected Member Functions | Protected Attributes
LayoutTest Class Reference
Inheritance diagram for LayoutTest:

Public Member Functions

 testLayoutFile ()
 
 testActionNodeMethods ()
 
 getAllowedActionNodeMethods ()
 

Protected Member Functions

 _testObsoleteReferences ($layoutXml)
 
 _testObsoleteAttributes ($layoutXml)
 

Protected Attributes

 $_obsoleteNodes
 
 $_obsoleteReferences
 

Detailed Description

Definition at line 14 of file LayoutTest.php.

Member Function Documentation

◆ _testObsoleteAttributes()

_testObsoleteAttributes (   $layoutXml)
protected

Tests the attributes of the top-level Layout Node. Verifies there are no longer attributes of "parent" or "owner"

Parameters
SimpleXMLElement$layoutXml

Definition at line 185 of file LayoutTest.php.

186  {
187  $issues = [];
188  $type = $layoutXml['type'];
189  $parent = $layoutXml['parent'];
190  $owner = $layoutXml['owner'];
191 
192  if ((string)$type === 'page') {
193  if ($parent) {
194  $issues[] = 'Attribute "parent" is not valid';
195  }
196  }
197  if ((string)$type === 'fragment') {
198  if ($owner) {
199  $issues[] = 'Attribute "owner" is not valid';
200  }
201  }
202  if ($issues) {
203  $this->fail("Issues found in handle declaration:\n" . implode("\n", $issues) . "\n");
204  }
205  }
$type
Definition: item.phtml:13

◆ _testObsoleteReferences()

_testObsoleteReferences (   $layoutXml)
protected
Parameters
SimpleXMLElement$layoutXml

Definition at line 164 of file LayoutTest.php.

165  {
166  foreach ($layoutXml as $handle) {
167  if (isset($this->_obsoleteReferences[$handle->getName()])) {
168  foreach ($handle->xpath('reference') as $reference) {
169  $this->assertNotContains(
170  (string)$reference['name'],
171  $this->_obsoleteReferences[$handle->getName()],
172  'The block being referenced is removed.'
173  );
174  }
175  }
176  }
177  }
$handle

◆ getAllowedActionNodeMethods()

getAllowedActionNodeMethods ( )

List of currently allowed (i.e. not refactored yet) methods for use in <action method="someMethod"> layout instruction.

@SuppressWarnings(PHPMD.ExcessiveMethodLength) Temporary method existing until <action> instruction in layout is not eliminated, no need to split it.

Returns
string[]

Definition at line 240 of file LayoutTest.php.

241  {
242  return [
243  'addBodyClass',
244  'addButtons',
245  'addColumnCountLayoutDepend',
246  'addCrumb',
247  'addDatabaseBlock',
248  'addInputTypeTemplate',
249  'addNotice',
250  'addReportTypeOption',
251  'addTab',
252  'addTabAfter',
253  'addText',
254  'append',
255  'removeTab',
256  'setActive',
257  'setAddressType',
258  'setAfterCondition',
259  'setAfterTotal',
260  'setAtCall',
261  'setAtCode',
262  'setAtLabel',
263  'setAuthenticationStartMode',
264  'setBeforeCondition',
265  'setBlockId',
266  'setBugreportUrl',
267  'setCanLoadExtJs',
268  'setCanLoadRulesJs',
269  'setCanLoadTinyMce',
270  'setClassName',
271  'setColClass',
272  'setColumnCount',
273  'setColumnsLimit',
274  'setCssClass',
275  'setDefaultFilter',
276  'setDefaultStoreName',
277  'setDestElementId',
278  'setDisplayArea',
279  'setDontDisplayContainer',
280  'setEmptyGridMessage',
281  'setEntityModelClass',
282  'setFieldOption',
283  'setFieldVisibility',
284  'setFormCode',
285  'setFormId',
286  'setFormPrefix',
287  'setGiftRegistryTemplate',
288  'setGiftRegistryUrl',
289  'setGridHtmlClass',
290  'setGridHtmlCss',
291  'setGridHtmlId',
292  'setHeaderTitle',
293  'setHideBalance',
294  'setHideLink',
295  'setHideRequiredNotice',
296  'setHtmlClass',
297  'setId',
298  'setImageType',
299  'setImgAlt',
300  'setImgHeight',
301  'setImgSrc',
302  'setImgWidth',
303  'setInList',
304  'setInfoTemplate',
305  'setIsCollapsed',
306  'setIsDisabled',
307  'setIsEnabled',
308  'setIsGuestNote',
309  'setIsHandle',
310  'setIsLinkMode',
311  'setIsPlaneMode',
312  'setIsTitleHidden',
313  'setIsViewCurrent',
314  'setItemLimit',
315  'setLabel',
316  'setLabelProperties',
317  'setLayoutCode',
318  'setLinkUrl',
319  'setListCollection',
320  'setListModes',
321  'setListOrders',
322  'setMAPTemplate',
323  'setMethodFormTemplate',
324  'setMyClass',
325  'setPageLayout',
326  'setPageTitle',
327  'setParentType',
328  'setControllerPath',
329  'setPosition',
330  'setPositioned',
331  'setRewardMessage',
332  'setRewardQtyLimitationMessage',
333  'setShouldPrepareInfoTabs',
334  'setShowPart',
335  'setSignupLabel',
336  'setSourceField',
337  'setStoreVarName',
338  'setStrong',
339  'setTemplate',
340  'setText',
341  'setThemeName',
342  'setTierPriceTemplate',
343  'setTitle',
344  'setTitleClass',
345  'setTitleId',
346  'setToolbarBlockName',
347  'setType',
348  'setUseConfirm',
349  'setValueProperties',
350  'setViewAction',
351  'setViewColumn',
352  'setViewLabel',
353  'setViewMode',
354  'setWrapperClass',
355  'unsetChild',
356  'unsetChildren',
357  'updateButton',
358  'setIsProductListingContext',
359  'checkCompanyStatus', // MAGETWO-88965
360  'setRendererType', // MAGETWO-88965
361  ];
362  }

◆ testActionNodeMethods()

testActionNodeMethods ( )
Parameters
string$layoutFile

Definition at line 207 of file LayoutTest.php.

208  {
209  $invoker = new \Magento\Framework\App\Utility\AggregateInvoker($this);
210  $invoker(
214  function ($layoutFile) {
215  $layoutXml = simplexml_load_file($layoutFile);
216  $methodFilter = '@method!="' . implode('" and @method!="', $this->getAllowedActionNodeMethods()) . '"';
217  foreach ($layoutXml->xpath('//action[' . $methodFilter . ']') as $node) {
218  $attributes = $node->attributes();
219  $this->fail(
220  sprintf(
221  'Call of method "%s" via layout instruction <action> is not allowed.',
222  $attributes['method']
223  )
224  );
225  }
226  },
228  );
229  }
$attributes
Definition: matrix.phtml:13

◆ testLayoutFile()

testLayoutFile ( )
Parameters
string$layoutFile

Definition at line 88 of file LayoutTest.php.

89  {
90  $invoker = new \Magento\Framework\App\Utility\AggregateInvoker($this);
91  $invoker(
95  function ($layoutFile) {
96  $layoutXml = simplexml_load_file($layoutFile);
97 
98  $this->_testObsoleteReferences($layoutXml);
99  $this->_testObsoleteAttributes($layoutXml);
100 
101  $selectorHeadBlock = '(name()="block" or name()="referenceBlock") and ' .
102  '(@name="head" or @name="convert_root_head" or @name="vde_head")';
103  $this->assertSame(
104  [],
105  $layoutXml->xpath(
106  '//block[@class="Magento\Theme\Block\Html\Head\Css" ' .
107  'or @class="Magento\Theme\Block\Html\Head\Link" ' .
108  'or @class="Magento\Theme\Block\Html\Head\Script"]' .
109  '/parent::*[not(' .
110  $selectorHeadBlock .
111  ')]'
112  ),
113  'Blocks \Magento\Theme\Block\Html\Head\{Css,Link,Script} ' .
114  'are allowed within the "head" block only. ' .
115  'Verify integrity of the nodes nesting.'
116  );
117  $this->assertSame(
118  [],
119  $layoutXml->xpath('/layout//*[@output="toHtml"]'),
120  'output="toHtml" is obsolete. Use output="1"'
121  );
122  foreach ($layoutXml as $handle) {
123  $this->assertNotContains(
124  (string)$handle['id'],
125  $this->_obsoleteNodes,
126  'This layout handle is obsolete.'
127  );
128  }
129  foreach ($layoutXml->xpath('@helper') as $action) {
130  $this->assertNotContains('/', $action->getAttribute('helper'));
131  $this->assertContains('::', $action->getAttribute('helper'));
132  }
133 
134  $componentRegistrar = new ComponentRegistrar();
135  if (false !== strpos(
136  $layoutFile,
137  $componentRegistrar->getPath(ComponentRegistrar::MODULE, 'Magento_Sales')
138  . '/view/adminhtml/layout/sales_order'
139  ) || false !== strpos(
140  $layoutFile,
141  $componentRegistrar->getPath(ComponentRegistrar::MODULE, 'Magento_Shipping')
142  . '/view/adminhtml/layout/adminhtml_order'
143  )
144  ) {
145  $this->markTestIncomplete(
146  "The file {$layoutFile} has to use \\Magento\\Core\\Block\\Text\\List, \n" .
147  'there is no solution to get rid of it right now.'
148  );
149  }
150  $this->assertSame(
151  [],
152  $layoutXml->xpath('/layout//block[@class="Magento\Framework\View\Element\Text\ListText"]'),
153  'The class \Magento\Framework\View\Element\Text\ListTest' .
154  ' is not supposed to be used in layout anymore.'
155  );
156  },
158  );
159  }
$componentRegistrar
Definition: bootstrap.php:23
$handle

Field Documentation

◆ $_obsoleteNodes

$_obsoleteNodes
protected
Initial value:
= [
'PRODUCT_TYPE_simple',
'PRODUCT_TYPE_configurable',
'PRODUCT_TYPE_grouped',
'PRODUCT_TYPE_bundle',
'PRODUCT_TYPE_virtual',
'PRODUCT_TYPE_downloadable',
'PRODUCT_TYPE_giftcard',
'catalog_category_default',
'catalog_category_layered',
'catalog_category_layered_nochildren',
'customer_logged_in',
'customer_logged_out',
'customer_logged_in_psc_handle',
'customer_logged_out_psc_handle',
'cms_page',
'sku_failed_products_handle',
'catalog_product_send',
'reference',
]

Definition at line 21 of file LayoutTest.php.

◆ $_obsoleteReferences

$_obsoleteReferences
protected

Definition at line 47 of file LayoutTest.php.


The documentation for this class was generated from the following file: