[3877] trunk/tests/system/classes/bitmaskTest.php: Fix two failing tests.

0 views
Skip to first unread message

svn-N...@habariproject.org

unread,
Dec 11, 2009, 10:05:54 PM12/11/09
to habar...@googlegroups.com
Revision
3877
Author
rickc
Date
2009-12-12 03:05:52 +0000 (Sat, 12 Dec 2009)

Log Message

Fix two failing tests. Increase code coverage for the Bitmask class. If anyone can tell me how to reach the second exception in Bitmask::__set(), I would appreciate it.

Modified Paths

Diff

Modified: trunk/tests/system/classes/bitmaskTest.php (3876 => 3877)


--- trunk/tests/system/classes/bitmaskTest.php	2009-12-11 02:58:28 UTC (rev 3876)
+++ trunk/tests/system/classes/bitmaskTest.php	2009-12-12 03:05:52 UTC (rev 3877)
@@ -11,6 +11,30 @@
 		$this->bitmask = new Bitmask($this->access_names);
 	}
 
+	public function test_constructor()
+	{
+		$mask = new Bitmask( array( 'dog', 'cat' ), 3 );
+		$this->assertTrue( $mask->dog );
+		$this->assertTrue( $mask->cat );
+
+		$mask = new Bitmask( array( 'dog', 'cat' ), 'blue' );
+		$this->assertTrue( $mask->dog );
+		$this->assertFalse( $mask->cat );
+	}
+
+	public function test_constructor_exception()
+	{
+		try {
+		$mask = new Bitmask( 'brute' );
+		}
+		catch( Exception $e ) {
+			$this->assertEquals( 'Bitmask constructor expects either no arguments or an array as a first argument', $e->getMessage() );
+			return;
+
+		}
+		$this->fail( 'Expected InvalidArgumentException in test_constructor()' );
+	}
+
 	public function test_write_by_name()
 	{
 		$this->bitmask->read = true;
@@ -57,10 +81,29 @@
 		$this->assertTrue($this->bitmask->create);
 		$this->assertFalse($this->bitmask->read);
 		$this->assertTrue($this->bitmask->delete);
-		$this->assertFalse($this->bitmask->edit);
+		$this->assertTrue($this->bitmask->edit);
 
+		$this->bitmask->full = true;
+		$this->assertEquals( $this->bitmask->value, 15 );
+		$this->bitmask->full = false;
+		$this->assertEquals( $this->bitmask->value, 0 );
 	}
 
+	public function test_set_Exception()
+	{
+		try {
+			$mask = new Bitmask( array( 'dog', 'cat', 'mule' ) );
+			$val = null;
+			$mask->$val = true;
+
+		}
+		catch ( InvalidArgumentException $e ) {
+			$this->assertEquals( 'Bitmask names must be pre-defined strings or bitmask indexes', $e->getMessage() );
+			return;
+		}
+		$this->fail( 'An expected InvalidArgumentException has not been raised in test_setException()' );
+	}
+
 	public function test_write_by_array()
 	{
 		// TODO Bitmask should support this but the current implementation uses a public variable called value rather than the value setter.
@@ -75,9 +118,12 @@
 		$this->bitmask->value = 1;
 		$this->assertEquals('read', (string)$this->bitmask);
 
-		$this->markTestIncomplete();
-	}
+		$this->bitmask->value = 0;
+		$this->assertEquals( 'none', (string)$this->bitmask );
 
+		$this->bitmask->value = 15;
+		$this->assertEquals( 'full', (string)$this->bitmask );	}
+
 	/**
 	 * Ported from old test suite
 	 */
@@ -87,10 +133,16 @@
 		define('POST_FLAG_ALLOWS_TRACKBACKS',1 << 1);
 		define('POST_FLAG_ALLOWS_PINGBACKS' ,1 << 2);
 
+//		$flags= array(
+//			'allows_comments'=>POST_FLAG_ALLOWS_COMMENTS,
+//			'allows_trackbacks'=>POST_FLAG_ALLOWS_TRACKBACKS,
+//			'allows_pingbacks'=>POST_FLAG_ALLOWS_PINGBACKS
+//		);
 		$flags= array(
-		        'allows_comments'=>POST_FLAG_ALLOWS_COMMENTS
-		      , 'allows_trackbacks'=>POST_FLAG_ALLOWS_TRACKBACKS
-		      , 'allows_pingbacks'=>POST_FLAG_ALLOWS_PINGBACKS);
+			'allows_comments',
+			'allows_trackbacks',
+			'allows_pingbacks'
+		);
 
 		$bitmask= new Bitmask($flags);
 
Reply all
Reply to author
Forward
0 new messages