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

Public Member Functions

 testBlockVariableInsteadOfThis ()
 
 testObsoleteBlockMethods ()
 
 testObsoleteJavascriptAttributeType ()
 

Detailed Description

Definition at line 10 of file PhtmlTemplateTest.php.

Member Function Documentation

◆ testBlockVariableInsteadOfThis()

testBlockVariableInsteadOfThis ( )

Test usage of methods and variables in template through $this

Parameters
string$file

Definition at line 12 of file PhtmlTemplateTest.php.

13  {
14  $invoker = new \Magento\Framework\App\Utility\AggregateInvoker($this);
15  $invoker(
21  function ($file) {
22  $this->assertNotRegExp(
23  '/this->(?!helper)\S*/iS',
24  file_get_contents($file),
25  'Access to members and methods of Block class through $this is ' .
26  'obsolete in phtml templates. Use only $block instead of $this.'
27  );
28  },
30  );
31  }

◆ testObsoleteBlockMethods()

testObsoleteBlockMethods ( )

Test usage of protected and private methods and variables in template

According to naming convention (B5.8, B6.2) all class members in protected or private scope should be prefixed with underscore. Member variables declared "public" should never start with an underscore. Access to protected and private members of Block class is obsolete in phtml templates since introduction of multiple template engines support

Parameters
string$file

Definition at line 33 of file PhtmlTemplateTest.php.

34  {
35  $invoker = new \Magento\Framework\App\Utility\AggregateInvoker($this);
36  $invoker(
48  function ($file) {
49  $this->assertNotRegexp(
50  '/block->_[^_]+\S*\(/iS',
51  file_get_contents($file),
52  'Access to protected and private members of Block class is ' .
53  'obsolete in phtml templates. Use only public members.'
54  );
55  },
57  );
58  }

◆ testObsoleteJavascriptAttributeType()

testObsoleteJavascriptAttributeType ( )

"text/javascript" type attribute in not obligatory to use in templates due to HTML5 standards. For more details please go to "http://www.w3.org/TR/html5/scripting-1.html".

Parameters
string$file

Definition at line 60 of file PhtmlTemplateTest.php.

61  {
62  $invoker = new \Magento\Framework\App\Utility\AggregateInvoker($this);
63  $invoker(
70  function ($file) {
71  $this->assertNotRegexp(
72  '/type="text\/javascript"/',
73  file_get_contents($file),
74  'Please do not use "text/javascript" type attribute.'
75  );
76  },
78  );
79  }

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