mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
Add lint-clean and cleanup code linting
This commit is contained in:
parent
3da1587289
commit
7a8dfd2785
@ -84,7 +84,8 @@
|
|||||||
"thirdparty/"
|
"thirdparty/"
|
||||||
],
|
],
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"lint": "phpcs --standard=tests/phpcs/ruleset.xml src/ tests/php",
|
"lint": "phpcs src/ tests/php",
|
||||||
|
"lint-clean": "phpcbf src/ tests/php",
|
||||||
"php-peg": "php thirdparty/php-peg/cli.php src/View/SSTemplateParser.peg > src/View/SSTemplateParser.php"
|
"php-peg": "php thirdparty/php-peg/cli.php src/View/SSTemplateParser.peg > src/View/SSTemplateParser.php"
|
||||||
},
|
},
|
||||||
"minimum-stability": "dev",
|
"minimum-stability": "dev",
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace SilverStripe\View\Tests;
|
namespace SilverStripe\View\Tests;
|
||||||
|
|
||||||
|
use PHPUnit_Framework_MockObject_MockObject;
|
||||||
use SilverStripe\Control\Controller;
|
use SilverStripe\Control\Controller;
|
||||||
use SilverStripe\Control\Director;
|
use SilverStripe\Control\Director;
|
||||||
use SilverStripe\Control\ContentNegotiator;
|
use SilverStripe\Control\ContentNegotiator;
|
||||||
@ -80,12 +81,7 @@ class SSViewerTest extends SapphireTest
|
|||||||
*/
|
*/
|
||||||
public function testTemplateWithoutHeadRenders()
|
public function testTemplateWithoutHeadRenders()
|
||||||
{
|
{
|
||||||
$data = new ArrayData(
|
$data = new ArrayData([ 'Var' => 'var value' ]);
|
||||||
array(
|
|
||||||
'Var' => 'var value'
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
$result = $data->renderWith("SSViewerTestPartialTemplate");
|
$result = $data->renderWith("SSViewerTestPartialTemplate");
|
||||||
$this->assertEquals('Test partial template: var value', trim(preg_replace("/<!--.*-->/U", '', $result)));
|
$this->assertEquals('Test partial template: var value', trim(preg_replace("/<!--.*-->/U", '', $result)));
|
||||||
}
|
}
|
||||||
@ -121,54 +117,46 @@ class SSViewerTest extends SapphireTest
|
|||||||
|
|
||||||
public function testIncludeTruthyness()
|
public function testIncludeTruthyness()
|
||||||
{
|
{
|
||||||
$data = new ArrayData(
|
$data = new ArrayData([
|
||||||
array(
|
|
||||||
'Title' => 'TruthyTest',
|
'Title' => 'TruthyTest',
|
||||||
'Items' => new ArrayList(
|
'Items' => new ArrayList([
|
||||||
array(
|
new ArrayData(['Title' => 'Item 1']),
|
||||||
new ArrayData(array('Title' => 'Item 1')),
|
new ArrayData(['Title' => '']),
|
||||||
new ArrayData(array('Title' => '')),
|
new ArrayData(['Title' => true]),
|
||||||
new ArrayData(array('Title' => true)),
|
new ArrayData(['Title' => false]),
|
||||||
new ArrayData(array('Title' => false)),
|
new ArrayData(['Title' => null]),
|
||||||
new ArrayData(array('Title' => null)),
|
new ArrayData(['Title' => 0]),
|
||||||
new ArrayData(array('Title' => 0)),
|
new ArrayData(['Title' => 7])
|
||||||
new ArrayData(array('Title' => 7))
|
])
|
||||||
)
|
]);
|
||||||
)
|
|
||||||
)
|
|
||||||
);
|
|
||||||
$result = $data->renderWith('SSViewerTestIncludeScopeInheritanceWithArgs');
|
$result = $data->renderWith('SSViewerTestIncludeScopeInheritanceWithArgs');
|
||||||
|
|
||||||
// We should not end up with empty values appearing as empty
|
// We should not end up with empty values appearing as empty
|
||||||
$expected = array(
|
$expected = [
|
||||||
'Item 1 _ Item 1 - First-ODD top:Item 1',
|
'Item 1 _ Item 1 - First-ODD top:Item 1',
|
||||||
'Untitled - EVEN top:',
|
'Untitled - EVEN top:',
|
||||||
'1 _ 1 - ODD top:1',
|
'1 _ 1 - ODD top:1',
|
||||||
'Untitled - EVEN top:',
|
'Untitled - EVEN top:',
|
||||||
'Untitled - ODD top:',
|
'Untitled - ODD top:',
|
||||||
'Untitled - EVEN top:0',
|
'Untitled - EVEN top:0',
|
||||||
'7 _ 7 - Last-ODD top:7'
|
'7 _ 7 - Last-ODD top:7',
|
||||||
);
|
];
|
||||||
$this->assertExpectedStrings($result, $expected);
|
$this->assertExpectedStrings($result, $expected);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getScopeInheritanceTestData()
|
private function getScopeInheritanceTestData()
|
||||||
{
|
{
|
||||||
return new ArrayData(
|
return new ArrayData([
|
||||||
array(
|
|
||||||
'Title' => 'TopTitleValue',
|
'Title' => 'TopTitleValue',
|
||||||
'Items' => new ArrayList(
|
'Items' => new ArrayList([
|
||||||
array(
|
new ArrayData(['Title' => 'Item 1']),
|
||||||
new ArrayData(array('Title' => 'Item 1')),
|
new ArrayData(['Title' => 'Item 2']),
|
||||||
new ArrayData(array('Title' => 'Item 2')),
|
new ArrayData(['Title' => 'Item 3']),
|
||||||
new ArrayData(array('Title' => 'Item 3')),
|
new ArrayData(['Title' => 'Item 4']),
|
||||||
new ArrayData(array('Title' => 'Item 4')),
|
new ArrayData(['Title' => 'Item 5']),
|
||||||
new ArrayData(array('Title' => 'Item 5')),
|
new ArrayData(['Title' => 'Item 6'])
|
||||||
new ArrayData(array('Title' => 'Item 6'))
|
])
|
||||||
)
|
]);
|
||||||
)
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private function assertExpectedStrings($result, $expected)
|
private function assertExpectedStrings($result, $expected)
|
||||||
@ -200,7 +188,10 @@ class SSViewerTest extends SapphireTest
|
|||||||
|
|
||||||
public function testRequirements()
|
public function testRequirements()
|
||||||
{
|
{
|
||||||
$requirements = $this->getMockBuilder(Requirements_Backend::class)->setMethods(array("javascript", "css"))
|
/** @var Requirements_Backend|PHPUnit_Framework_MockObject_MockObject $requirements */
|
||||||
|
$requirements = $this
|
||||||
|
->getMockBuilder(Requirements_Backend::class)
|
||||||
|
->setMethods(array("javascript", "css"))
|
||||||
->getMock();
|
->getMock();
|
||||||
$jsFile = FRAMEWORK_DIR . '/tests/forms/a.js';
|
$jsFile = FRAMEWORK_DIR . '/tests/forms/a.js';
|
||||||
$cssFile = FRAMEWORK_DIR . '/tests/forms/a.js';
|
$cssFile = FRAMEWORK_DIR . '/tests/forms/a.js';
|
||||||
@ -285,8 +276,7 @@ class SSViewerTest extends SapphireTest
|
|||||||
|
|
||||||
public function testComments()
|
public function testComments()
|
||||||
{
|
{
|
||||||
$output = $this->render(
|
$input = <<<SS
|
||||||
<<<SS
|
|
||||||
This is my template<%-- this is a comment --%>This is some content<%-- this is another comment --%>Final content
|
This is my template<%-- this is a comment --%>This is some content<%-- this is another comment --%>Final content
|
||||||
<%-- Alone multi
|
<%-- Alone multi
|
||||||
line comment --%>
|
line comment --%>
|
||||||
@ -294,8 +284,8 @@ Some more content
|
|||||||
Mixing content and <%-- multi
|
Mixing content and <%-- multi
|
||||||
line comment --%> Final final
|
line comment --%> Final final
|
||||||
content
|
content
|
||||||
SS
|
SS;
|
||||||
);
|
$output = $this->render($input);
|
||||||
$shouldbe = <<<SS
|
$shouldbe = <<<SS
|
||||||
This is my templateThis is some contentFinal content
|
This is my templateThis is some contentFinal content
|
||||||
|
|
||||||
@ -303,7 +293,6 @@ Some more content
|
|||||||
Mixing content and Final final
|
Mixing content and Final final
|
||||||
content
|
content
|
||||||
SS;
|
SS;
|
||||||
|
|
||||||
$this->assertEquals($shouldbe, $output);
|
$this->assertEquals($shouldbe, $output);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -479,11 +468,9 @@ SS;
|
|||||||
|
|
||||||
public function testLocalFunctionsTakePriorityOverGlobals()
|
public function testLocalFunctionsTakePriorityOverGlobals()
|
||||||
{
|
{
|
||||||
$data = new ArrayData(
|
$data = new ArrayData([
|
||||||
array(
|
|
||||||
'Page' => new SSViewerTest\TestObject()
|
'Page' => new SSViewerTest\TestObject()
|
||||||
)
|
]);
|
||||||
);
|
|
||||||
|
|
||||||
//call method with lots of arguments
|
//call method with lots of arguments
|
||||||
$result = $this->render(
|
$result = $this->render(
|
||||||
@ -512,38 +499,24 @@ SS;
|
|||||||
public function testCurrentScopeLoopWith()
|
public function testCurrentScopeLoopWith()
|
||||||
{
|
{
|
||||||
// Data to run the loop tests on - one sequence of three items, each with a subitem
|
// Data to run the loop tests on - one sequence of three items, each with a subitem
|
||||||
$data = new ArrayData(
|
$data = new ArrayData([
|
||||||
array(
|
'Foo' => new ArrayList([
|
||||||
'Foo' => new ArrayList(
|
'Subocean' => new ArrayData([
|
||||||
array(
|
|
||||||
'Subocean' => new ArrayData(
|
|
||||||
array(
|
|
||||||
'Name' => 'Higher'
|
'Name' => 'Higher'
|
||||||
)
|
]),
|
||||||
),
|
new ArrayData([
|
||||||
new ArrayData(
|
'Sub' => new ArrayData([
|
||||||
array(
|
|
||||||
'Sub' => new ArrayData(
|
|
||||||
array(
|
|
||||||
'Name' => 'SubKid1'
|
'Name' => 'SubKid1'
|
||||||
)
|
])
|
||||||
)
|
]),
|
||||||
)
|
new ArrayData([
|
||||||
),
|
'Sub' => new ArrayData([
|
||||||
new ArrayData(
|
|
||||||
array(
|
|
||||||
'Sub' => new ArrayData(
|
|
||||||
array(
|
|
||||||
'Name' => 'SubKid2'
|
'Name' => 'SubKid2'
|
||||||
)
|
])
|
||||||
)
|
]),
|
||||||
)
|
|
||||||
),
|
|
||||||
new SSViewerTest\TestObject('Number6')
|
new SSViewerTest\TestObject('Number6')
|
||||||
)
|
])
|
||||||
)
|
]);
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
$result = $this->render(
|
$result = $this->render(
|
||||||
'<% loop Foo %>$Number<% if Sub %><% with Sub %>$Name<% end_with %><% end_if %><% end_loop %>',
|
'<% loop Foo %>$Number<% if Sub %><% with Sub %>$Name<% end_with %><% end_if %><% end_loop %>',
|
||||||
|
Loading…
Reference in New Issue
Block a user