Skip to content

Commit

Permalink
Unit Test CS (joomla#13433)
Browse files Browse the repository at this point in the history
* Whats going on now

* Some exclusions

* Remove function comment

* Add some more excludes

* Remove for now

* Add another exception

* Lots of small tweaks to codestyle in tests

* Fix some the plugins CS

* More plugin cs fixing

* Uppercase

* Couple of extra fixes

* empty lines around control structure

* PHPCS autofixers

* Apply PHPCS2.x autofixers to JRouter tests

* Apply PHPCS2.x autofixers to JComponentRouter

* Fix null lowercase

* Code style in application tests

* Fix JApplicationWeb tests

* Remove non-PHP files from tests

* Clean up email cloak unit test

* Remove commented code

* Fix tests failing after merging in develop
  • Loading branch information
wilsonge authored and mbabker committed Jul 26, 2017
1 parent 73577db commit ff11ae9
Show file tree
Hide file tree
Showing 45 changed files with 299 additions and 253 deletions.
28 changes: 25 additions & 3 deletions build/phpcs/Joomla/ruleset.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
<!-- Exclude folders not containing production code -->
<exclude-pattern type="relative">build/*</exclude-pattern>
<exclude-pattern type="relative">docs/*</exclude-pattern>
<exclude-pattern type="relative">tests/*</exclude-pattern>
<exclude-pattern type="relative">cache/*</exclude-pattern>
<exclude-pattern type="relative">tmp/*</exclude-pattern>
<exclude-pattern type="relative">logs/*</exclude-pattern>
Expand All @@ -25,6 +24,15 @@
<exclude-pattern type="relative">configuration.php</exclude-pattern>
<exclude-pattern type="relative">installation/template/index.php</exclude-pattern>
<exclude-pattern type="relative">plugins/captcha/recaptcha/recaptchalib.php</exclude-pattern>
<!-- Exclude some test related files that don't actually include PHP code -->
<exclude-pattern type="relative">tests/unit/suites/libraries/joomla/model/stubs/barbaz.php</exclude-pattern>
<exclude-pattern type="relative">tests/unit/suites/libraries/joomla/view/layouts1/fringe/division.php</exclude-pattern>
<exclude-pattern type="relative">tests/unit/suites/libraries/joomla/view/layouts1/olivia.php</exclude-pattern>
<exclude-pattern type="relative">tests/unit/suites/libraries/joomla/view/layouts1/peter.php</exclude-pattern>
<exclude-pattern type="relative">tests/unit/suites/libraries/joomla/view/layouts2/fauxlivia.php</exclude-pattern>
<exclude-pattern type="relative">tests/unit/suites/libraries/joomla/view/layouts2/olivia.php</exclude-pattern>
<exclude-pattern type="relative">tests/unit/suites/libraries/legacy/controller/stubs/component1/controller.json.php</exclude-pattern>
<exclude-pattern type="relative">tests/unit/suites/libraries/legacy/controller/stubs/component2/controller.php</exclude-pattern>

<!-- Exclude the RoboFile.php -->
<exclude-pattern type="relative">RoboFile.php</exclude-pattern>
Expand Down Expand Up @@ -54,6 +62,7 @@
<exclude-pattern type="relative">*/tmpl/*</exclude-pattern>
<exclude-pattern type="relative">templates/*</exclude-pattern>
<exclude-pattern type="relative">layouts/*</exclude-pattern>
<exclude-pattern type="relative">tests/*</exclude-pattern>
</rule>

<rule ref="Generic.Formatting.DisallowMultipleStatements">
Expand Down Expand Up @@ -136,12 +145,23 @@

<!-- Remove the following when the folder limitations are dropped -->

<rule ref="Joomla.Classes.MethodScope"/>
<rule ref="Joomla.Classes.MethodScope">
<exclude-pattern type="relative">tests/*</exclude-pattern>
</rule>

<rule ref="Joomla.Commenting.FileComment">
<exclude-pattern type="relative">tests/*</exclude-pattern>
</rule>

<rule ref="Joomla.Functions.FunctionCallSignature">
<exclude-pattern type="relative">tests/*</exclude-pattern>
</rule>

<rule ref="Joomla.Commenting.FunctionComment">
<!-- We only want this for libraries, language and cli for now -->
<exclude-pattern type="relative">templates/*</exclude-pattern>
<exclude-pattern type="relative">layouts/*</exclude-pattern>
<exclude-pattern type="relative">tests/*</exclude-pattern>
</rule>

<rule ref="Joomla.Commenting.SingleComment">
Expand All @@ -151,7 +171,9 @@
<exclude-pattern type="relative">layouts/*</exclude-pattern>
</rule>

<rule ref="Joomla.Commenting.ClassComment"/>
<rule ref="Joomla.Commenting.ClassComment">
<exclude-pattern type="relative">tests/*</exclude-pattern>
</rule>

<rule ref="Joomla.ControlStructures.ControlSignature">
<!-- These exceptions are permanent -->
Expand Down
1 change: 1 addition & 0 deletions tests/codeception/_bootstrap.php
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
<?php

// This is global bootstrap for autoloading
1 change: 1 addition & 0 deletions tests/codeception/functional/_bootstrap.php
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
<?php

// Here you can initialize variables that will be available to your tests
1 change: 1 addition & 0 deletions tests/unit/core/mock/dispatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ public static function create($test, $defaults = true)
->setMockClassName('')
->disableOriginalConstructor()
->getMock();

// Mock selected methods.
$test->assignMockReturns(
$mockObject, array(
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/stubs/discover2/endeavour.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@

class ShuttleEndeavour
{
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ class JAdministratorHelperTest extends TestCase
*/
protected function setUp()
{
//$this->object = new JErrorPage;
$this->saveFactoryState();

JFactory::$application = $this->getMockCmsApp();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ public function testForEach($select, $from, $column, $class, $limit, $offset, $e
$iterator = self::$driver->getIterator($column, $class);

// Run the Iterator pattern
$this->assertEquals($expected,iterator_to_array($iterator));
$this->assertEquals($expected, iterator_to_array($iterator));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1180,7 +1180,7 @@ public function testReturning()
public function seedDateAdd()
{
return array(
// date, interval, datepart, expected
// Elements: date, interval, datepart, expected
'Add date' => array('2008-12-31', '1', 'day', "timestamp '2008-12-31' + interval '1 day'"),
'Subtract date' => array('2008-12-31', '-1', 'day', "timestamp '2008-12-31' - interval '1 day'"),
'Add datetime' => array('2008-12-31 23:59:59', '1', 'day', "timestamp '2008-12-31 23:59:59' + interval '1 day'"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ protected function tearDown()
public function seedDateAdd()
{
return array(
// date, interval, datepart, expected
// Elements: date, interval, datepart, expected
'Add date' => array('2008-12-31', '1', 'DAY', "datetime('2008-12-31', '+1 DAY')"),
'Subtract date' => array('2008-12-31', '-1', 'DAY', "datetime('2008-12-31', '-1 DAY')"),
'Add datetime' => array('2008-12-31 23:59:59', '1', 'DAY', "datetime('2008-12-31 23:59:59', '+1 DAY')"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ protected function tearDown()
public function seedDateAdd()
{
return array(
// date, interval, datepart, expected
// Elements: date, interval, datepart, expected
'Add date' => array('2008-12-31', '1', 'day', "DATEADD('day', '1', '2008-12-31')"),
'Subtract date' => array('2008-12-31', '-1', 'day', "DATEADD('day', '-1', '2008-12-31')"),
'Add datetime' => array('2008-12-31 23:59:59', '1', 'day', "DATEADD('day', '1', '2008-12-31 23:59:59')"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -459,9 +459,9 @@ public function testRedirect()
$this->class->headers[2]
);

$this->assertRegexp('/Expires/',$this->class->headers[3][0]);
$this->assertRegexp('/Expires/', $this->class->headers[3][0]);

$this->assertRegexp('/Last-Modified/',$this->class->headers[4][0]);
$this->assertRegexp('/Last-Modified/', $this->class->headers[4][0]);

$this->assertEquals(
array('Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0', true, null),
Expand Down Expand Up @@ -529,9 +529,9 @@ public function testRedirectLegacy()
$this->class->headers[2]
);

$this->assertRegexp('/Expires/',$this->class->headers[3][0]);
$this->assertRegexp('/Expires/', $this->class->headers[3][0]);

$this->assertRegexp('/Last-Modified/',$this->class->headers[4][0]);
$this->assertRegexp('/Last-Modified/', $this->class->headers[4][0]);

$this->assertEquals(
array('Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0', true, null),
Expand Down Expand Up @@ -595,9 +595,9 @@ public function testRedirectLegacyWithEmptyMessageAndEmptyStatus()
$this->class->headers[2]
);

$this->assertRegexp('/Expires/',$this->class->headers[3][0]);
$this->assertRegexp('/Expires/', $this->class->headers[3][0]);

$this->assertRegexp('/Last-Modified/',$this->class->headers[4][0]);
$this->assertRegexp('/Last-Modified/', $this->class->headers[4][0]);

$this->assertEquals(
array('Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0', true, null),
Expand Down Expand Up @@ -704,7 +704,7 @@ public function testRedirectWithMoved()
);

$this->assertEquals(
array('Location: ' . $url, true, null),
array('Location: ' . $url, true, null),
$this->class->headers[1]
);

Expand All @@ -713,9 +713,9 @@ public function testRedirectWithMoved()
$this->class->headers[2]
);

$this->assertRegexp('/Expires/',$this->class->headers[3][0]);
$this->assertRegexp('/Expires/', $this->class->headers[3][0]);

$this->assertRegexp('/Last-Modified/',$this->class->headers[4][0]);
$this->assertRegexp('/Last-Modified/', $this->class->headers[4][0]);

$this->assertEquals(
array('Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0', true, null),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public function testConstruct()
* Test if standard setup of JComponentRouterBase works and $app and
* $menu are properly populated
*/
$object = new JComponentRouterBaseInspector();
$object = new JComponentRouterBaseInspector;
$this->assertInstanceOf('JComponentRouterInterface', $object);
$this->assertInstanceOf('JComponentRouterBase', $object);
$this->assertEquals($app, $object->app);
Expand All @@ -51,13 +51,14 @@ public function testConstruct()
$app2 = TestMockApplication::create($this);
$object = new JComponentRouterBaseInspector($app2);
$this->assertEquals($app2, $object->app);
//The original $app is not the same object as $app2, thus we did not use JFactory

// The original $app is not the same object as $app2, thus we did not use JFactory
$this->assertNotSame($app, $object->app);

/**
* Test if the setup works when both an app and menu object is handed over
*/
$menu2 = new stdClass();
$menu2 = new stdClass;
$object = new JComponentRouterBaseInspector($app, $menu2);
$this->assertEquals($app, $object->app);
$this->assertEquals($menu2, $object->menu);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ public function testGetViews()
public function casesGetPath()
{
$cases = array();

// No view, so we don't have a path to return.
$cases[] = array(array('task' => 'edit'), array());

Expand All @@ -140,7 +141,7 @@ public function casesGetPath()
// View with parent and children
$cases[] = array(array('view' => 'category', 'id' => '9'), array('category' => array(9 => '9:uncategorised'), 'categories' => array(9 => '9:uncategorised')));

//View with parent, no children
// View with parent, no children
$cases[] = array(array('view' => 'article', 'id' => '42:question-for-everything', 'catid' => '9'),
array(
'article' => array(42 => '42:question-for-everything'),
Expand All @@ -149,7 +150,7 @@ public function casesGetPath()
)
);

//View with parent, no children and nested view
// View with parent, no children and nested view
$cases[] = array(array('view' => 'article', 'id' => '42:question-for-everything', 'catid' => '20'),
array(
'article' => array(42 => '42:question-for-everything'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ public function testSetParent()
$this->assertEquals(array($this->object), $parent2->children);
$this->assertEquals(array('category', 'test'), $this->object->path);
$this->assertEquals(array('catid'), $parent2->child_keys);

// Make sure that the original parent is cleaned up
$this->assertEquals(array(), $parent->children);
$this->assertEquals(array(), $parent->child_keys);
Expand All @@ -154,6 +155,7 @@ public function testSetParent()
$this->assertEquals($parent3, $this->object->parent);
$this->assertEquals('formid', $this->object->parent_key);
$this->assertEquals(array('formid'), $parent3->child_keys);

// Make sure that the original parent is cleaned up
$this->assertEquals(array(), $parent2->children);
$this->assertEquals(array(), $parent2->child_keys);
Expand Down Expand Up @@ -191,6 +193,7 @@ public function testAddLayout()
$this->assertEquals(array('default'), $this->object->layouts);
$this->assertEquals($this->object, $this->object->addLayout('form'));
$this->assertEquals(array('default', 'form'), $this->object->layouts);

// Make sure that a layout can only be added once
$this->object->addLayout('form');
$this->assertEquals(array('default', 'form'), $this->object->layouts);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
* @subpackage Component
* @since 3.5
*/
class JComponentRouterRulesMenuTest extends TestCaseDatabase {

class JComponentRouterRulesMenuTest extends TestCaseDatabase
{
/**
* Object under test
*
Expand Down Expand Up @@ -63,7 +63,7 @@ protected function setUp()
$router->registerView($featured);
$form = new JComponentRouterViewconfiguration('form');
$router->registerView($form);
$router->menu = new MockJComponentRouterRulesMenuMenuObject();
$router->menu = new MockJComponentRouterRulesMenuMenuObject;

$this->object = new JComponentRouterRulesMenuInspector($router);
}
Expand Down Expand Up @@ -116,7 +116,8 @@ public function testConstruct()
'featured' => '47',
'categories' => array(14 => '48'),
'category' => array (20 => '49'))
), $this->object->get('lookup'));
), $this->object->get('lookup')
);
}

/**
Expand All @@ -129,7 +130,7 @@ public function testConstruct()
public function casesPreprocess()
{
$cases = array();

// Check direct link to a simple view
$cases[] = array(array('option' => 'com_content', 'view' => 'featured'),
array('option' => 'com_content', 'view' => 'featured', 'Itemid' => '47'));
Expand Down Expand Up @@ -244,8 +245,9 @@ public function testBuildLookup()
'featured' => '47',
'categories' => array(14 => '48'),
'category' => array (20 => '49'))
), $this->object->get('lookup'));

), $this->object->get('lookup')
);

$this->object->runBuildLookUp('en-GB');
$this->assertEquals(array(
'*' => array(
Expand All @@ -256,6 +258,7 @@ public function testBuildLookup()
'featured' => '51',
'categories' => array(14 => '50'),
'category' => array (20 => '49'))
), $this->object->get('lookup'));
), $this->object->get('lookup')
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
* @subpackage Component
* @since 3.4
*/
class JComponentRouterRulesNomenuTest extends TestCase {

class JComponentRouterRulesNomenuTest extends TestCase
{
/**
* Object under test
*
Expand Down Expand Up @@ -115,7 +115,7 @@ public function testParse()
$router = $this->object->get('router');
$router->menu->expects($this->any())
->method('getActive')
->will($this->returnValue(new stdClass()));
->will($this->returnValue(new stdClass));
$segments = array('article', '42:the-answer');
$vars = array('option' => 'com_content');
$this->object->parse($segments, $vars);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
* @subpackage Component
* @since 3.7.0
*/
class JComponentRouterRulesStandardTest extends TestCaseDatabase {

class JComponentRouterRulesStandardTest extends TestCaseDatabase
{
/**
* Object under test
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class JComponentRouterRulesMenuInspector extends JComponentRouterRulesMenu
{
/**
* Gets an attribute of the object
*
*
* @param string $key Attributename to return
*
* @return mixed Attributes of the object
Expand All @@ -32,7 +32,7 @@ public function get($key)

/**
* Sets an attribute of the object
*
*
* @param string $key Attributename to return
* @param mixed $value Value to be set
*
Expand All @@ -44,9 +44,9 @@ public function set($key, $value)
{
$this->$key = $value;
}

public function runBuildLookup($language = '*')
{
return $this->buildLookup($language);
}
}
}
Loading

0 comments on commit ff11ae9

Please sign in to comment.