PhtmlTemplateTest.php 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <?php
  2. /**
  3. * Backwards-incompatible changes in file system
  4. *
  5. * Copyright © Magento, Inc. All rights reserved.
  6. * See COPYING.txt for license details.
  7. */
  8. namespace Magento\Test\Legacy;
  9. class PhtmlTemplateTest extends \PHPUnit\Framework\TestCase
  10. {
  11. public function testBlockVariableInsteadOfThis()
  12. {
  13. $invoker = new \Magento\Framework\App\Utility\AggregateInvoker($this);
  14. $invoker(
  15. /**
  16. * Test usage of methods and variables in template through $this
  17. *
  18. * @param string $file
  19. */
  20. function ($file) {
  21. $this->assertNotRegExp(
  22. '/this->(?!helper)\S*/iS',
  23. file_get_contents($file),
  24. 'Access to members and methods of Block class through $this is ' .
  25. 'obsolete in phtml templates. Use only $block instead of $this.'
  26. );
  27. },
  28. \Magento\Framework\App\Utility\Files::init()->getPhtmlFiles()
  29. );
  30. }
  31. public function testObsoleteBlockMethods()
  32. {
  33. $invoker = new \Magento\Framework\App\Utility\AggregateInvoker($this);
  34. $invoker(
  35. /**
  36. * Test usage of protected and private methods and variables in template
  37. *
  38. * According to naming convention (B5.8, B6.2) all class members
  39. * in protected or private scope should be prefixed with underscore.
  40. * Member variables declared "public" should never start with an underscore.
  41. * Access to protected and private members of Block class is obsolete in phtml templates
  42. * since introduction of multiple template engines support
  43. *
  44. * @param string $file
  45. */
  46. function ($file) {
  47. $this->assertNotRegexp(
  48. '/block->_[^_]+\S*\(/iS',
  49. file_get_contents($file),
  50. 'Access to protected and private members of Block class is ' .
  51. 'obsolete in phtml templates. Use only public members.'
  52. );
  53. },
  54. \Magento\Framework\App\Utility\Files::init()->getPhtmlFiles()
  55. );
  56. }
  57. public function testObsoleteJavascriptAttributeType()
  58. {
  59. $invoker = new \Magento\Framework\App\Utility\AggregateInvoker($this);
  60. $invoker(
  61. /**
  62. * "text/javascript" type attribute in not obligatory to use in templates due to HTML5 standards.
  63. * For more details please go to "http://www.w3.org/TR/html5/scripting-1.html".
  64. *
  65. * @param string $file
  66. */
  67. function ($file) {
  68. $this->assertNotRegexp(
  69. '/type="text\/javascript"/',
  70. file_get_contents($file),
  71. 'Please do not use "text/javascript" type attribute.'
  72. );
  73. },
  74. \Magento\Framework\App\Utility\Files::init()->getPhtmlFiles()
  75. );
  76. }
  77. }