Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion tests/unit/core/case/cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,8 @@ public function testCacheClearNotGroup()
*/
public function testIsSupported()
{
$this->assertTrue($this->handler->isSupported(), 'Claims the cache handler is not supported.');
$handler = $this->handler;

$this->assertTrue($handler::isSupported(), 'Claims the cache handler is not supported.');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ public function testGetPathway()
*/
public function testGetRouter()
{
$this->assertInstanceOf('JRouterAdministrator', $this->class->getRouter());
$this->assertInstanceOf('JRouterAdministrator', JApplicationAdministrator::getRouter());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ public function testGetPathway()
*/
public function testGetRouter()
{
$this->assertInstanceOf('JRouter', $this->class->getRouter(''));
$this->assertInstanceOf('JRouter', JApplicationCmsInspector::getRouter(''));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,9 @@ public function testGetPathway()
*/
public function testGetRouter()
{
$this->assertInstanceOf('JRouterSite', $this->class->getRouter());
$class = $this->class;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we need this now?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missed that. Thanks!


$this->assertInstanceOf('JRouterSite', JApplicationSite::getRouter());
}

/**
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/suites/libraries/cms/helper/JHelperMediaTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public function testIsImage($fileName, $expected)
*/
public function testGetTypeIcon()
{
$name = $this->object->getTypeIcon('myfile.pdf');
$name = JHelperMedia::getTypeIcon('myfile.pdf');
$this->assertEquals($name, 'pdf');
}

Expand Down Expand Up @@ -208,7 +208,7 @@ public function imageResizeProvider()
*/
public function testImageResize($width, $height, $target, $expected)
{
$newSize = $this->object->imageResize($width, $height, $target);
$newSize = JHelperMedia::imageResize($width, $height, $target);
$this->assertEquals($newSize, $expected);
}
}
44 changes: 18 additions & 26 deletions tests/unit/suites/libraries/joomla/access/JAccessTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,10 @@ public function testGetAuthorisedViewLevels()
{
usleep(100);

$access = new JAccess;
$array1 = array(0 => 1, 1 => 1, 2 => 2, 3 => 3);

$this->assertThat(
$access->getAuthorisedViewLevels(42),
JAccess::getAuthorisedViewLevels(42),
$this->equalTo($array1),
'Line:' . __Line__ . ' Super user gets Public (levels 1)'
);
Expand Down Expand Up @@ -94,8 +93,8 @@ public function casesCheck()
*/
public function testCheck($userId, $action, $assetId, $result, $message)
{
$access = new JAccess;
$this->assertThat($access->check($userId, $action, $assetId), $this->equalTo($result), $message);

$this->assertThat(JAccess::check($userId, $action, $assetId), $this->equalTo($result), $message);
}

/**
Expand Down Expand Up @@ -149,8 +148,7 @@ public function casesCheckGroup()
*/
public function testCheckGroup($groupId, $action, $assetId, $result, $message)
{
$access = new JAccess;
$this->assertThat($access->checkGroup($groupId, $action, $assetId), $this->equalTo($result), $message);
$this->assertThat(JAccess::checkGroup($groupId, $action, $assetId), $this->equalTo($result), $message);
}

/**
Expand All @@ -162,8 +160,8 @@ public function testCheckGroup($groupId, $action, $assetId, $result, $message)
*/
public function testGetAssetRulesValidTrue()
{
$access = new JAccess;
$ObjArrayJrules = $access->getAssetRules(3, true);
$ObjArrayJrules = JAccess::getAssetRules(3, true);

$string1 = '{"core.login.site":{"6":1,"2":1},"core.login.admin":{"6":1},"core.admin":{"8":1,"7":1},' .
'"core.manage":{"7":1,"6":1},"core.create":{"6":1,"3":1},"core.delete":{"6":1},"core.edit":{"6":1,"4":1},"core.edit.state":{"6":1,"5":1},' .
'"core.edit.own":{"6":1,"3":1}}';
Expand All @@ -179,8 +177,8 @@ public function testGetAssetRulesValidTrue()
*/
public function testGetAssetRulesValidFalse()
{
$access = new JAccess;
$ObjArrayJrules = $access->getAssetRules(3, false);
$ObjArrayJrules = JAccess::getAssetRules(3, false);

$string1 = '{"core.admin":{"7":1},"core.manage":{"6":1}}';
$this->assertThat((string) $ObjArrayJrules, $this->equalTo($string1), 'Non recursive rules from a valid asset. Line: ' . __LINE__);
}
Expand All @@ -194,8 +192,8 @@ public function testGetAssetRulesValidFalse()
*/
public function testGetAssetRulesInvalidFalse()
{
$access = new JAccess;
$ObjArrayJrules = $access->getAssetRules(1550, false);
$ObjArrayJrules = JAccess::getAssetRules(1550, false);

$string1 = '{"core.login.site":{"6":1,"2":1},"core.login.admin":{"6":1},"core.admin":{"8":1},"core.manage":{"7":1},' .
'"core.create":{"6":1,"3":1},"core.delete":{"6":1},"core.edit":{"6":1,"4":1},"core.edit.state":{"6":1,"5":1},"core.edit.own":{"6":1,"3":1}}';
$this->assertThat((string) $ObjArrayJrules, $this->equalTo($string1), 'Invalid asset uses rule from root. Line: ' . __LINE__);
Expand All @@ -210,8 +208,8 @@ public function testGetAssetRulesInvalidFalse()
*/
public function testGetAssetRulesTextFalse()
{
$access = new JAccess;
$ObjArrayJrules = $access->getAssetRules('testasset', false);
$ObjArrayJrules = JAccess::getAssetRules('testasset', false);

$string1 = '{"core.login.site":{"6":1,"2":1},"core.login.admin":{"6":1},"core.admin":{"8":1},"core.manage":{"7":1},' .
'"core.create":{"6":1,"3":1},"core.delete":{"6":1},"core.edit":{"6":1,"4":1},"core.edit.state":{"6":1,"5":1},"core.edit.own":{"6":1,"3":1}}';
$this->assertThat((string) $ObjArrayJrules, $this->equalTo($string1), 'Invalid asset uses rule from root. Line: ' . __LINE__);
Expand All @@ -226,8 +224,8 @@ public function testGetAssetRulesTextFalse()
*/
public function testGetAssetRulesTextTrue()
{
$access = new JAccess;
$ObjArrayJrules = $access->getAssetRules('testasset', true);
$ObjArrayJrules = JAccess::getAssetRules('testasset', true);

$string1 = '{"core.login.site":{"6":1,"2":1},"core.login.admin":{"6":1},"core.admin":{"8":1},"core.manage":{"7":1},' .
'"core.create":{"6":1,"3":1},"core.delete":{"6":1},"core.edit":{"6":1,"4":1},"core.edit.state":{"6":1,"5":1},"core.edit.own":{"6":1,"3":1}}';
$this->assertThat((string) $ObjArrayJrules, $this->equalTo($string1), 'Invalid asset uses rule from root. Line: ' . __LINE__);
Expand All @@ -242,8 +240,7 @@ public function testGetAssetRulesTextTrue()
*/
public function testGetGroupTitle()
{
$access = new JAccess;
$this->assertThat($access->getGroupTitle(1), $this->equalTo('Public'), 'Get group title. Line: ' . __LINE__);
$this->assertThat(JAccess::getGroupTitle(1), $this->equalTo('Public'), 'Get group title. Line: ' . __LINE__);
}

/**
Expand All @@ -255,9 +252,8 @@ public function testGetGroupTitle()
*/
public function testGetUsersByGroupSimple()
{
$access = new JAccess;
$array1 = array(0 => 42);
$this->assertThat($access->getUsersByGroup(8, true), $this->equalTo($array1), 'Get one user. Line: ' . __LINE__);
$this->assertThat(JAccess::getUsersByGroup(8, true), $this->equalTo($array1), 'Get one user. Line: ' . __LINE__);
}

/**
Expand All @@ -269,10 +265,8 @@ public function testGetUsersByGroupSimple()
*/
public function testGetUsersByGroupTwoUsers()
{
$access = new JAccess;

$array3 = array(0 => 42, 1 => 43, 2 => 44);
$this->assertThat($access->getUsersByGroup(1, true), $this->equalTo($array3), 'Get multiple users. Line: ' . __LINE__);
$this->assertThat(JAccess::getUsersByGroup(1, true), $this->equalTo($array3), 'Get multiple users. Line: ' . __LINE__);
}

/**
Expand All @@ -284,10 +278,8 @@ public function testGetUsersByGroupTwoUsers()
*/
public function testGetUsersByGroupInvalidGroup()
{
$access = new JAccess;

$array2 = array();
$this->assertThat($access->getUsersByGroup(15, false), $this->equalTo($array2), 'No group specified. Line: ' . __LINE__);
$this->assertThat(JAccess::getUsersByGroup(15, false), $this->equalTo($array2), 'No group specified. Line: ' . __LINE__);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -360,8 +360,10 @@ public function testGc()
*/
public function testIsSupported()
{
$object = $this->object;

$this->assertThat(
$this->object->isSupported(),
$object::isSupported(),
$this->isTrue()
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,11 @@ public function testGetConnection()
*/
public function testGetConnectors()
{
$db = $this->db;

$this->assertContains(
'sqlite',
$this->db->getConnectors(),
$db::getConnectors(),
'The getConnectors method should return an array with Sqlite as an available option.'
);
}
Expand Down Expand Up @@ -194,8 +196,10 @@ public function testGetDateFormat()
*/
public function testSplitSql()
{
$db = $this->db;

$this->assertThat(
$this->db->splitSql('SELECT * FROM #__foo;SELECT * FROM #__bar;'),
$db::splitSql('SELECT * FROM #__foo;SELECT * FROM #__bar;'),
$this->equalTo(
array(
'SELECT * FROM #__foo;',
Expand Down
23 changes: 8 additions & 15 deletions tests/unit/suites/libraries/joomla/filter/JFilterOutputTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,6 @@ public function __construct()
*/
class JFilterOutputTest extends PHPUnit_Framework_TestCase
{
/**
* @var JFilterOutput
*/
protected $object;

/**
* @var beforeObject
*/
Expand All @@ -63,7 +58,6 @@ protected function setUp()
{
parent::setUp();

$this->object = new JFilterOutput;
$this->safeObject = new FilterTestObject;
$this->safeObjectArrayTest = new FilterTestObject;
}
Expand All @@ -79,7 +73,6 @@ protected function setUp()
*/
protected function tearDown()
{
unset($this->object);
unset($this->safeObject);
unset($this->safeObjectArrayTest);
parent::tearDown();
Expand All @@ -92,7 +85,7 @@ protected function tearDown()
*/
public function testObjectHTMLSafe()
{
$this->object->objectHTMLSafe($this->safeObject, null, 'string3');
JFilterOutput::objectHTMLSafe($this->safeObject, null, 'string3');
$this->assertEquals('<script>alert();</script>', $this->safeObject->string1, "Script tag should be defused");
$this->assertEquals('This is a test.', $this->safeObject->string2, "Plain text should pass");
$this->assertEquals('<script>alert(3);</script>', $this->safeObject->string3, "This Script tag should be passed");
Expand All @@ -105,7 +98,7 @@ public function testObjectHTMLSafe()
*/
public function testObjectHTMLSafeWithArray()
{
$this->object->objectHTMLSafe($this->safeObject, null, array('string1', 'string3'));
JFilterOutput::objectHTMLSafe($this->safeObject, null, array('string1', 'string3'));
$this->assertEquals('<script>alert();</script>', $this->safeObject->string1, "Script tag should pass array test");
$this->assertEquals('This is a test.', $this->safeObject->string2, "Plain text should pass array test");
$this->assertEquals('<script>alert(3);</script>', $this->safeObject->string3, "This Script tag should pass array test");
Expand All @@ -120,7 +113,7 @@ public function testLinkXHTMLSafe()
{
$this->assertEquals(
'<a href="http://www.example.com/index.frd?one=1&amp;two=2&amp;three=3">This & That</a>',
$this->object->linkXHTMLSafe('<a href="http://www.example.com/index.frd?one=1&two=2&three=3">This & That</a>'),
JFilterOutput::linkXHTMLSafe('<a href="http://www.example.com/index.frd?one=1&two=2&three=3">This & That</a>'),
'Should clean ampersands only out of link, not out of link text'
);
}
Expand All @@ -134,7 +127,7 @@ public function testStringURLSafe()
{
$this->assertEquals(
'1234567890-qwertyuiop-qwertyuiop-asdfghjkl-asdfghjkl-zxcvbnm-zxcvbnm',
$this->object->stringURLSafe('`1234567890-=~!@#$%^&*()_+ qwertyuiop[]\QWERTYUIOP{}|asdfghjkl;\'ASDFGHJKL:"zxcvbnm,./ZXCVBNM<>?'),
JFilterOutput::stringURLSafe('`1234567890-=~!@#$%^&*()_+ qwertyuiop[]\QWERTYUIOP{}|asdfghjkl;\'ASDFGHJKL:"zxcvbnm,./ZXCVBNM<>?'),
'Should clean keyboard string down to ASCII-7'
);
}
Expand All @@ -150,7 +143,7 @@ public function testStringURLUnicodeSlug()
{
$this->assertEquals(
'what-if-i-do-not-get_this-right',
$this->object->stringURLUnicodeSlug('What-if I do.not get_this right?'),
JFilterOutput::stringURLUnicodeSlug('What-if I do.not get_this right?'),
'Should be URL unicoded'
);
}
Expand All @@ -165,7 +158,7 @@ public function testAmpReplace()
{
$this->assertEquals(
'&&george&amp;mary&#3son',
$this->object->ampReplace('&&george&mary&#3son'),
JFilterOutput::ampReplace('&&george&mary&#3son'),
'Should replace single ampersands with HTML entity'
);
}
Expand Down Expand Up @@ -221,7 +214,7 @@ public function testStripImages()
{
$this->assertEquals(
'Hello I am waving at you.',
$this->object->stripImages('Hello <img src="wave.jpg"> I am waving at you.'),
JFilterOutput::stripImages('Hello <img src="wave.jpg"> I am waving at you.'),
'Should remove img tags'
);
}
Expand All @@ -237,7 +230,7 @@ public function testStripIframes()
{
$this->assertEquals(
'Hello I am waving at you.',
$this->object->stripIframes('Hello <iframe src="http://player.vimeo.com/video/37576499" width="500"' .
JFilterOutput::stripIframes('Hello <iframe src="http://player.vimeo.com/video/37576499" width="500"' .
' height="281" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe> I am waving at you.'),
'Should remove iFrame tags'
);
Expand Down
6 changes: 3 additions & 3 deletions tests/unit/suites/libraries/joomla/language/JLanguageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -739,17 +739,17 @@ public function testSetSearchDisplayedCharactersNumberCallback()
public function testExists()
{
$this->assertFalse(
$this->object->exists(null)
JLanguage::exists(null)
);

$basePath = __DIR__ . '/data';

$this->assertTrue(
$this->object->exists('en-GB', $basePath)
JLanguage::exists('en-GB', $basePath)
);

$this->assertFalse(
$this->object->exists('es-ES', $basePath)
JLanguage::exists('es-ES', $basePath)
);
}

Expand Down
5 changes: 4 additions & 1 deletion tests/unit/suites/libraries/joomla/session/JSessionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,10 @@ public function testGetFormToken()
$user = JFactory::getUser();

$expected = md5($user->get('id', 0) . $this->object->getToken(false));
$this->assertEquals($expected, $this->object->getFormToken(false), 'Form token should be calculated as above.');

$object = $this->object;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cs: please remove one tab here


$this->assertEquals($expected, $object::getFormToken(false), 'Form token should be calculated as above.');
}

/**
Expand Down
9 changes: 5 additions & 4 deletions tests/unit/suites/libraries/joomla/table/JTableNestedTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,17 +129,17 @@ public function testGetRootId()

// Change the id of the root node.
self::$driver->setQuery('UPDATE #__categories SET parent_id = 99 WHERE id = 1')->execute();
$this->class->resetRootId();
NestedTable::resetRootId();
$this->assertEquals(1, $this->class->getRootId(), 'Checks for lft = 0 case.');

// Change the lft of the root node.
self::$driver->setQuery('UPDATE #__categories SET lft = 99, alias = ' . self::$driver->q('root') . ' WHERE id = 1')->execute();
$this->class->resetRootId();
NestedTable::resetRootId();
$this->assertEquals(1, $this->class->getRootId(), 'Checks for alias = root case.');

// Change the alias of the root node.
self::$driver->setQuery('UPDATE #__categories SET alias = ' . self::$driver->q('foo') . ' WHERE id = 1')->execute();
$this->class->resetRootId();
NestedTable::resetRootId();
$this->assertFalse($this->class->getRootId(), 'Checks for failure.');
}

Expand Down Expand Up @@ -481,7 +481,8 @@ public function testRebuild()
// Reset the root node.
self::$driver->setQuery('UPDATE #__categories SET parent_id = 99, lft = 99, rgt = 99 WHERE id = 1')
->execute();
$this->class->resetRootId();

NestedTable::resetRootId();

TestReflection::setValue($this->class, '_cache', array());
$this->assertFalse($this->class->rebuild(), 'Checks failure where no root node is found.');
Expand Down
Loading