Skip to content

Commit 4352229

Browse files
frankmayerwilsonge
authored andcommitted
Some improvements in tests #3: (#13402)
* Some improvements in tests #3: - call static methods correctly * Fix T_PAAMAYIM_NEKUDOTAYIM (for all PHP 5.x) * Remove forgotten call * Changed a few things after conversation with @mbabker * Fixes according to @andrepereiradasilva's comments
1 parent 6e07ca6 commit 4352229

File tree

14 files changed

+71
-75
lines changed

14 files changed

+71
-75
lines changed

tests/unit/core/case/cache.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,8 @@ public function testCacheClearNotGroup()
184184
*/
185185
public function testIsSupported()
186186
{
187-
$this->assertTrue($this->handler->isSupported(), 'Claims the cache handler is not supported.');
187+
$handler = $this->handler;
188+
189+
$this->assertTrue($handler::isSupported(), 'Claims the cache handler is not supported.');
188190
}
189191
}

tests/unit/suites/libraries/cms/application/JApplicationAdministratorTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ public function testGetPathway()
209209
*/
210210
public function testGetRouter()
211211
{
212-
$this->assertInstanceOf('JRouterAdministrator', $this->class->getRouter());
212+
$this->assertInstanceOf('JRouterAdministrator', JApplicationAdministrator::getRouter());
213213
}
214214

215215
/**

tests/unit/suites/libraries/cms/application/JApplicationCmsTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ public function testGetPathway()
346346
*/
347347
public function testGetRouter()
348348
{
349-
$this->assertInstanceOf('JRouter', $this->class->getRouter(''));
349+
$this->assertInstanceOf('JRouter', JApplicationCmsInspector::getRouter(''));
350350
}
351351

352352
/**

tests/unit/suites/libraries/cms/application/JApplicationSiteTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ public function testGetPathway()
229229
*/
230230
public function testGetRouter()
231231
{
232-
$this->assertInstanceOf('JRouterSite', $this->class->getRouter());
232+
$this->assertInstanceOf('JRouterSite', JApplicationSite::getRouter());
233233
}
234234

235235
/**

tests/unit/suites/libraries/cms/helper/JHelperMediaTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ public function testIsImage($fileName, $expected)
118118
*/
119119
public function testGetTypeIcon()
120120
{
121-
$name = $this->object->getTypeIcon('myfile.pdf');
121+
$name = JHelperMedia::getTypeIcon('myfile.pdf');
122122
$this->assertEquals($name, 'pdf');
123123
}
124124

@@ -208,7 +208,7 @@ public function imageResizeProvider()
208208
*/
209209
public function testImageResize($width, $height, $target, $expected)
210210
{
211-
$newSize = $this->object->imageResize($width, $height, $target);
211+
$newSize = JHelperMedia::imageResize($width, $height, $target);
212212
$this->assertEquals($newSize, $expected);
213213
}
214214
}

tests/unit/suites/libraries/joomla/access/JAccessTest.php

Lines changed: 18 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,10 @@ public function testGetAuthorisedViewLevels()
3535
{
3636
usleep(100);
3737

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

4140
$this->assertThat(
42-
$access->getAuthorisedViewLevels(42),
41+
JAccess::getAuthorisedViewLevels(42),
4342
$this->equalTo($array1),
4443
'Line:' . __Line__ . ' Super user gets Public (levels 1)'
4544
);
@@ -94,8 +93,8 @@ public function casesCheck()
9493
*/
9594
public function testCheck($userId, $action, $assetId, $result, $message)
9695
{
97-
$access = new JAccess;
98-
$this->assertThat($access->check($userId, $action, $assetId), $this->equalTo($result), $message);
96+
97+
$this->assertThat(JAccess::check($userId, $action, $assetId), $this->equalTo($result), $message);
9998
}
10099

101100
/**
@@ -149,8 +148,7 @@ public function casesCheckGroup()
149148
*/
150149
public function testCheckGroup($groupId, $action, $assetId, $result, $message)
151150
{
152-
$access = new JAccess;
153-
$this->assertThat($access->checkGroup($groupId, $action, $assetId), $this->equalTo($result), $message);
151+
$this->assertThat(JAccess::checkGroup($groupId, $action, $assetId), $this->equalTo($result), $message);
154152
}
155153

156154
/**
@@ -162,8 +160,8 @@ public function testCheckGroup($groupId, $action, $assetId, $result, $message)
162160
*/
163161
public function testGetAssetRulesValidTrue()
164162
{
165-
$access = new JAccess;
166-
$ObjArrayJrules = $access->getAssetRules(3, true);
163+
$ObjArrayJrules = JAccess::getAssetRules(3, true);
164+
167165
$string1 = '{"core.login.site":{"6":1,"2":1},"core.login.admin":{"6":1},"core.admin":{"8":1,"7":1},' .
168166
'"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},' .
169167
'"core.edit.own":{"6":1,"3":1}}';
@@ -179,8 +177,8 @@ public function testGetAssetRulesValidTrue()
179177
*/
180178
public function testGetAssetRulesValidFalse()
181179
{
182-
$access = new JAccess;
183-
$ObjArrayJrules = $access->getAssetRules(3, false);
180+
$ObjArrayJrules = JAccess::getAssetRules(3, false);
181+
184182
$string1 = '{"core.admin":{"7":1},"core.manage":{"6":1}}';
185183
$this->assertThat((string) $ObjArrayJrules, $this->equalTo($string1), 'Non recursive rules from a valid asset. Line: ' . __LINE__);
186184
}
@@ -194,8 +192,8 @@ public function testGetAssetRulesValidFalse()
194192
*/
195193
public function testGetAssetRulesInvalidFalse()
196194
{
197-
$access = new JAccess;
198-
$ObjArrayJrules = $access->getAssetRules(1550, false);
195+
$ObjArrayJrules = JAccess::getAssetRules(1550, false);
196+
199197
$string1 = '{"core.login.site":{"6":1,"2":1},"core.login.admin":{"6":1},"core.admin":{"8":1},"core.manage":{"7":1},' .
200198
'"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}}';
201199
$this->assertThat((string) $ObjArrayJrules, $this->equalTo($string1), 'Invalid asset uses rule from root. Line: ' . __LINE__);
@@ -210,8 +208,8 @@ public function testGetAssetRulesInvalidFalse()
210208
*/
211209
public function testGetAssetRulesTextFalse()
212210
{
213-
$access = new JAccess;
214-
$ObjArrayJrules = $access->getAssetRules('testasset', false);
211+
$ObjArrayJrules = JAccess::getAssetRules('testasset', false);
212+
215213
$string1 = '{"core.login.site":{"6":1,"2":1},"core.login.admin":{"6":1},"core.admin":{"8":1},"core.manage":{"7":1},' .
216214
'"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}}';
217215
$this->assertThat((string) $ObjArrayJrules, $this->equalTo($string1), 'Invalid asset uses rule from root. Line: ' . __LINE__);
@@ -226,8 +224,8 @@ public function testGetAssetRulesTextFalse()
226224
*/
227225
public function testGetAssetRulesTextTrue()
228226
{
229-
$access = new JAccess;
230-
$ObjArrayJrules = $access->getAssetRules('testasset', true);
227+
$ObjArrayJrules = JAccess::getAssetRules('testasset', true);
228+
231229
$string1 = '{"core.login.site":{"6":1,"2":1},"core.login.admin":{"6":1},"core.admin":{"8":1},"core.manage":{"7":1},' .
232230
'"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}}';
233231
$this->assertThat((string) $ObjArrayJrules, $this->equalTo($string1), 'Invalid asset uses rule from root. Line: ' . __LINE__);
@@ -242,8 +240,7 @@ public function testGetAssetRulesTextTrue()
242240
*/
243241
public function testGetGroupTitle()
244242
{
245-
$access = new JAccess;
246-
$this->assertThat($access->getGroupTitle(1), $this->equalTo('Public'), 'Get group title. Line: ' . __LINE__);
243+
$this->assertThat(JAccess::getGroupTitle(1), $this->equalTo('Public'), 'Get group title. Line: ' . __LINE__);
247244
}
248245

249246
/**
@@ -255,9 +252,8 @@ public function testGetGroupTitle()
255252
*/
256253
public function testGetUsersByGroupSimple()
257254
{
258-
$access = new JAccess;
259255
$array1 = array(0 => 42);
260-
$this->assertThat($access->getUsersByGroup(8, true), $this->equalTo($array1), 'Get one user. Line: ' . __LINE__);
256+
$this->assertThat(JAccess::getUsersByGroup(8, true), $this->equalTo($array1), 'Get one user. Line: ' . __LINE__);
261257
}
262258

263259
/**
@@ -269,10 +265,8 @@ public function testGetUsersByGroupSimple()
269265
*/
270266
public function testGetUsersByGroupTwoUsers()
271267
{
272-
$access = new JAccess;
273-
274268
$array3 = array(0 => 42, 1 => 43, 2 => 44);
275-
$this->assertThat($access->getUsersByGroup(1, true), $this->equalTo($array3), 'Get multiple users. Line: ' . __LINE__);
269+
$this->assertThat(JAccess::getUsersByGroup(1, true), $this->equalTo($array3), 'Get multiple users. Line: ' . __LINE__);
276270
}
277271

278272
/**
@@ -284,10 +278,8 @@ public function testGetUsersByGroupTwoUsers()
284278
*/
285279
public function testGetUsersByGroupInvalidGroup()
286280
{
287-
$access = new JAccess;
288-
289281
$array2 = array();
290-
$this->assertThat($access->getUsersByGroup(15, false), $this->equalTo($array2), 'No group specified. Line: ' . __LINE__);
282+
$this->assertThat(JAccess::getUsersByGroup(15, false), $this->equalTo($array2), 'No group specified. Line: ' . __LINE__);
291283
}
292284

293285
/**

tests/unit/suites/libraries/joomla/cache/JCacheStorageTest.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -360,8 +360,10 @@ public function testGc()
360360
*/
361361
public function testIsSupported()
362362
{
363+
$object = $this->object;
364+
363365
$this->assertThat(
364-
$this->object->isSupported(),
366+
$object::isSupported(),
365367
$this->isTrue()
366368
);
367369
}

tests/unit/suites/libraries/joomla/database/JDatabaseDriverTest.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,9 +131,11 @@ public function testGetConnection()
131131
*/
132132
public function testGetConnectors()
133133
{
134+
$db = $this->db;
135+
134136
$this->assertContains(
135137
'sqlite',
136-
$this->db->getConnectors(),
138+
$db::getConnectors(),
137139
'The getConnectors method should return an array with Sqlite as an available option.'
138140
);
139141
}
@@ -194,8 +196,10 @@ public function testGetDateFormat()
194196
*/
195197
public function testSplitSql()
196198
{
199+
$db = $this->db;
200+
197201
$this->assertThat(
198-
$this->db->splitSql('SELECT * FROM #__foo;SELECT * FROM #__bar;'),
202+
$db::splitSql('SELECT * FROM #__foo;SELECT * FROM #__bar;'),
199203
$this->equalTo(
200204
array(
201205
'SELECT * FROM #__foo;',

tests/unit/suites/libraries/joomla/filter/JFilterOutputTest.php

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,6 @@ public function __construct()
4343
*/
4444
class JFilterOutputTest extends PHPUnit_Framework_TestCase
4545
{
46-
/**
47-
* @var JFilterOutput
48-
*/
49-
protected $object;
50-
5146
/**
5247
* @var beforeObject
5348
*/
@@ -63,7 +58,6 @@ protected function setUp()
6358
{
6459
parent::setUp();
6560

66-
$this->object = new JFilterOutput;
6761
$this->safeObject = new FilterTestObject;
6862
$this->safeObjectArrayTest = new FilterTestObject;
6963
}
@@ -79,7 +73,6 @@ protected function setUp()
7973
*/
8074
protected function tearDown()
8175
{
82-
unset($this->object);
8376
unset($this->safeObject);
8477
unset($this->safeObjectArrayTest);
8578
parent::tearDown();
@@ -92,7 +85,7 @@ protected function tearDown()
9285
*/
9386
public function testObjectHTMLSafe()
9487
{
95-
$this->object->objectHTMLSafe($this->safeObject, null, 'string3');
88+
JFilterOutput::objectHTMLSafe($this->safeObject, null, 'string3');
9689
$this->assertEquals('<script>alert();</script>', $this->safeObject->string1, "Script tag should be defused");
9790
$this->assertEquals('This is a test.', $this->safeObject->string2, "Plain text should pass");
9891
$this->assertEquals('<script>alert(3);</script>', $this->safeObject->string3, "This Script tag should be passed");
@@ -105,7 +98,7 @@ public function testObjectHTMLSafe()
10598
*/
10699
public function testObjectHTMLSafeWithArray()
107100
{
108-
$this->object->objectHTMLSafe($this->safeObject, null, array('string1', 'string3'));
101+
JFilterOutput::objectHTMLSafe($this->safeObject, null, array('string1', 'string3'));
109102
$this->assertEquals('<script>alert();</script>', $this->safeObject->string1, "Script tag should pass array test");
110103
$this->assertEquals('This is a test.', $this->safeObject->string2, "Plain text should pass array test");
111104
$this->assertEquals('<script>alert(3);</script>', $this->safeObject->string3, "This Script tag should pass array test");
@@ -120,7 +113,7 @@ public function testLinkXHTMLSafe()
120113
{
121114
$this->assertEquals(
122115
'<a href="http://www.example.com/index.frd?one=1&amp;two=2&amp;three=3">This & That</a>',
123-
$this->object->linkXHTMLSafe('<a href="http://www.example.com/index.frd?one=1&two=2&three=3">This & That</a>'),
116+
JFilterOutput::linkXHTMLSafe('<a href="http://www.example.com/index.frd?one=1&two=2&three=3">This & That</a>'),
124117
'Should clean ampersands only out of link, not out of link text'
125118
);
126119
}
@@ -134,7 +127,7 @@ public function testStringURLSafe()
134127
{
135128
$this->assertEquals(
136129
'1234567890-qwertyuiop-qwertyuiop-asdfghjkl-asdfghjkl-zxcvbnm-zxcvbnm',
137-
$this->object->stringURLSafe('`1234567890-=~!@#$%^&*()_+ qwertyuiop[]\QWERTYUIOP{}|asdfghjkl;\'ASDFGHJKL:"zxcvbnm,./ZXCVBNM<>?'),
130+
JFilterOutput::stringURLSafe('`1234567890-=~!@#$%^&*()_+ qwertyuiop[]\QWERTYUIOP{}|asdfghjkl;\'ASDFGHJKL:"zxcvbnm,./ZXCVBNM<>?'),
138131
'Should clean keyboard string down to ASCII-7'
139132
);
140133
}
@@ -150,7 +143,7 @@ public function testStringURLUnicodeSlug()
150143
{
151144
$this->assertEquals(
152145
'what-if-i-do-not-get_this-right',
153-
$this->object->stringURLUnicodeSlug('What-if I do.not get_this right?'),
146+
JFilterOutput::stringURLUnicodeSlug('What-if I do.not get_this right?'),
154147
'Should be URL unicoded'
155148
);
156149
}
@@ -165,7 +158,7 @@ public function testAmpReplace()
165158
{
166159
$this->assertEquals(
167160
'&&george&amp;mary&#3son',
168-
$this->object->ampReplace('&&george&mary&#3son'),
161+
JFilterOutput::ampReplace('&&george&mary&#3son'),
169162
'Should replace single ampersands with HTML entity'
170163
);
171164
}
@@ -221,7 +214,7 @@ public function testStripImages()
221214
{
222215
$this->assertEquals(
223216
'Hello I am waving at you.',
224-
$this->object->stripImages('Hello <img src="wave.jpg"> I am waving at you.'),
217+
JFilterOutput::stripImages('Hello <img src="wave.jpg"> I am waving at you.'),
225218
'Should remove img tags'
226219
);
227220
}
@@ -237,7 +230,7 @@ public function testStripIframes()
237230
{
238231
$this->assertEquals(
239232
'Hello I am waving at you.',
240-
$this->object->stripIframes('Hello <iframe src="http://player.vimeo.com/video/37576499" width="500"' .
233+
JFilterOutput::stripIframes('Hello <iframe src="http://player.vimeo.com/video/37576499" width="500"' .
241234
' height="281" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe> I am waving at you.'),
242235
'Should remove iFrame tags'
243236
);

tests/unit/suites/libraries/joomla/language/JLanguageTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -739,17 +739,17 @@ public function testSetSearchDisplayedCharactersNumberCallback()
739739
public function testExists()
740740
{
741741
$this->assertFalse(
742-
$this->object->exists(null)
742+
JLanguage::exists(null)
743743
);
744744

745745
$basePath = __DIR__ . '/data';
746746

747747
$this->assertTrue(
748-
$this->object->exists('en-GB', $basePath)
748+
JLanguage::exists('en-GB', $basePath)
749749
);
750750

751751
$this->assertFalse(
752-
$this->object->exists('es-ES', $basePath)
752+
JLanguage::exists('es-ES', $basePath)
753753
);
754754
}
755755

0 commit comments

Comments
 (0)