r89298 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r89297‎ | r89298 | r89299 >
Date:22:13, 1 June 2011
Author:brion
Status:ok
Tags:
Comment:
Refactor validateCookieDomain test cases to use a data provider and report which bit's being tested so we can identify failures (there is still one failure in this set)
Modified paths:
  • /trunk/phase3/tests/phpunit/includes/HttpTest.php (modified) (history)

Diff [purge]

Index: trunk/phase3/tests/phpunit/includes/HttpTest.php
@@ -316,29 +316,43 @@
317317 function testIsValidUrl() {
318318 }
319319
320 - function testValidateCookieDomain() {
321 - $this->assertFalse( Cookie::validateCookieDomain( "co.uk" ) );
322 - $this->assertFalse( Cookie::validateCookieDomain( ".co.uk" ) );
323 - $this->assertFalse( Cookie::validateCookieDomain( "gov.uk" ) );
324 - $this->assertFalse( Cookie::validateCookieDomain( ".gov.uk" ) );
325 - $this->assertTrue( Cookie::validateCookieDomain( "supermarket.uk" ) );
326 - $this->assertFalse( Cookie::validateCookieDomain( "uk" ) );
327 - $this->assertFalse( Cookie::validateCookieDomain( ".uk" ) );
328 - $this->assertFalse( Cookie::validateCookieDomain( "127.0.0." ) );
329 - $this->assertFalse( Cookie::validateCookieDomain( "127." ) );
330 - $this->assertFalse( Cookie::validateCookieDomain( "127.0.0.1." ) );
331 - $this->assertTrue( Cookie::validateCookieDomain( "127.0.0.1" ) );
332 - $this->assertFalse( Cookie::validateCookieDomain( "333.0.0.1" ) );
333 - $this->assertTrue( Cookie::validateCookieDomain( "example.com" ) );
334 - $this->assertFalse( Cookie::validateCookieDomain( "example.com." ) );
335 - $this->assertTrue( Cookie::validateCookieDomain( ".example.com" ) );
 320+ /**
 321+ * @dataProvider cookieDomains
 322+ */
 323+ function testValidateCookieDomain( $expected, $domain, $origin=null ) {
 324+ if ( $origin ) {
 325+ $ok = Cookie::validateCookieDomain( $domain, $origin );
 326+ $msg = "$domain against origin $origin";
 327+ } else {
 328+ $ok = Cookie::validateCookieDomain( $domain );
 329+ $msg = "$domain";
 330+ }
 331+ $this->assertEquals( $expected, $ok, $msg );
 332+ }
 333+
 334+ function cookieDomains() {
 335+ return array(
 336+ array( false, "co.uk" ),
 337+ array( false, ".co.uk" ),
 338+ array( false, "gov.uk" ),
 339+ array( false, ".gov.uk" ),
 340+ array( true, "supermarket.uk" ),
 341+ array( false, "uk" ),
 342+ array( false, ".uk" ),
 343+ array( false, "127.0.0." ),
 344+ array( false, "127." ),
 345+ array( false, "127.0.0.1." ),
 346+ array( true, "127.0.0.1" ),
 347+ array( false, "333.0.0.1" ),
 348+ array( true, "example.com" ),
 349+ array( false, "example.com." ),
 350+ array( true, ".example.com" ),
336351
337 - $this->assertTrue( Cookie::validateCookieDomain( ".example.com", "www.example.com" ) );
338 - $this->assertFalse( Cookie::validateCookieDomain( "example.com", "www.example.com" ) );
339 - $this->assertTrue( Cookie::validateCookieDomain( "127.0.0.1", "127.0.0.1" ) );
340 - $this->assertFalse( Cookie::validateCookieDomain( "127.0.0.1", "localhost" ) );
341 -
342 -
 352+ array( true, ".example.com", "www.example.com" ),
 353+ array( false, "example.com", "www.example.com" ),
 354+ array( true, "127.0.0.1", "127.0.0.1" ),
 355+ array( false, "127.0.0.1", "localhost" ),
 356+ );
343357 }
344358
345359 function testSetCooke() {

Status & tagging log