Skip to content

Commit 7a2481c

Browse files
committed
MC-17868: Break jQuery UI into widgets and make a prototype
- Add static tests for js, php, phtml files;
1 parent 1e19860 commit 7a2481c

File tree

2 files changed

+57
-0
lines changed

2 files changed

+57
-0
lines changed

dev/tests/static/testsuite/Magento/Test/Legacy/ObsoleteCodeTest.php

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ function ($file) {
127127
$this->_testObsoleteActions($content);
128128
$this->_testObsoleteConstants($content);
129129
$this->_testObsoletePropertySkipCalculate($content);
130+
$this->_testJqueryUiLibraryIsNotUsedInPhp($content);
130131
},
131132
$changedFiles
132133
);
@@ -184,6 +185,11 @@ public function testJsFiles()
184185
function ($file) {
185186
$content = file_get_contents($file);
186187
$this->_testObsoletePropertySkipCalculate($content);
188+
if (!strpos($file, 'requirejs-config.js')
189+
&& (strpos($file, '/view/frontend/web/') || strpos($file, '/view/base/web/'))
190+
) {
191+
$this->_testJqueryUiLibraryIsNotUsedInJs($content);
192+
}
187193
},
188194
Files::init()->getJsFiles()
189195
);
@@ -947,4 +953,32 @@ private function getBlacklistFiles($absolutePath = false)
947953
}
948954
return $ignored;
949955
}
956+
957+
/**
958+
* Assert that jquery/ui library is not used in JS content.
959+
*
960+
* @param string $fileContent
961+
*/
962+
private function _testJqueryUiLibraryIsNotUsedInJs($fileContent)
963+
{
964+
$this->_assertNotRegexp(
965+
'/(["\'])jquery\/ui\1/',
966+
$fileContent,
967+
$this->_suggestReplacement(sprintf("Dependency '%s' is redundant.", 'jquery/ui'), 'Use separate jquery ui widget instead of all library.')
968+
);
969+
}
970+
971+
/**
972+
* Assert that jquery/ui library is not used in PHP content.
973+
*
974+
* @param string $fileContent
975+
*/
976+
private function _testJqueryUiLibraryIsNotUsedInPhp($fileContent)
977+
{
978+
$this->_assertNotRegExp(
979+
'/(["\'])jquery\/ui\1/',
980+
$fileContent,
981+
$this->_suggestReplacement(sprintf("Dependency '%s' is redundant.", 'jquery/ui'), 'Use separate jquery ui widget instead of all library.')
982+
);
983+
}
950984
}

dev/tests/static/testsuite/Magento/Test/Legacy/PhtmlTemplateTest.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,4 +77,27 @@ function ($file) {
7777
\Magento\Framework\App\Utility\Files::init()->getPhtmlFiles()
7878
);
7979
}
80+
81+
public function testJqueryUiLibraryIsNotUsedInTemplates()
82+
{
83+
$invoker = new \Magento\Framework\App\Utility\AggregateInvoker($this);
84+
$invoker(
85+
/**
86+
* 'jquery/ui' library is not obligatory to use in phtml files.
87+
* It's better to use needed jquery ui widget instead.
88+
*
89+
* @param string $file
90+
*/
91+
function ($file) {
92+
if (strpos($file, '/view/frontend/templates/') || strpos($file, '/view/base/templates/')) {
93+
$this->assertNotRegexp(
94+
'/(["\'])jquery\/ui\1/',
95+
file_get_contents($file),
96+
'Please do not use "jquery/ui" library in templates. Use needed jquery ui widget instead.'
97+
);
98+
}
99+
},
100+
\Magento\Framework\App\Utility\Files::init()->getPhtmlFiles()
101+
);
102+
}
80103
}

0 commit comments

Comments
 (0)