Modified:
development/trunk/tests/CHANGELOG
development/trunk/tests/unit/suite/libraries/joomla/user/JUserTest.php
Log:
Added JUser::save test
Modified: development/trunk/tests/CHANGELOG
===================================================================
--- development/trunk/tests/CHANGELOG 2010-09-02 01:53:15 UTC (rev 18755)
+++ development/trunk/tests/CHANGELOG 2010-09-02 02:59:02 UTC (rev 18756)
@@ -27,6 +27,9 @@
- -> Removed
! -> Note
+1-Sep-2010 Ian MacLennan
+ + Added JUser::save test
+
30-Aug-2010 Mark Dexter
^ Improve documentation for JUserHelper unit tests (Thanks Niels Braczek!)
Modified: development/trunk/tests/unit/suite/libraries/joomla/user/JUserTest.php
===================================================================
--- development/trunk/tests/unit/suite/libraries/joomla/user/JUserTest.php 2010-09-02 01:53:15 UTC (rev 18755)
+++ development/trunk/tests/unit/suite/libraries/joomla/user/JUserTest.php 2010-09-02 02:59:02 UTC (rev 18756)
@@ -409,6 +409,62 @@
}
/**
+ * Testing save() for the case where check() returns false
+ *
+ * @return void
+ */
+ public function testSaveCheckIsFalse()
+ {
+ // This is the error message that check is going to return.
+ $myErrorMessage = 'This is the error that bind returns';
+
+ // we need two mock objects - one to mock the other methods of JUser, and one to serve as a JTable mock
+ // the false in the $tableMock means that our constructor doesn't get called
+ $testObject = $this->getMock('JUser', array('getTable', 'getProperties', 'setError'));
+ $tableMock = $this->getMock('JTableUser', array('bind', 'check', 'getError'), array(), '', false);
+
+ // we expect getTable to be called once. We are going to return our mock table object.
+ $testObject->expects($this->once())
+ ->method('getTable')
+ ->will($this->returnValue($tableMock));
+
+ // we expect getProperties to be called once. We are going to return some random user data
+ // this data should get passed to the bind method.
+ $testObject->expects($this->once())
+ ->method('getProperties')
+ ->will($this->returnValue(array('id' => 5, 'username' => 'jimbo')));
+
+ // We expect setError to be called with the error message that check returned.
+ $testObject->expects($this->once())
+ ->method('setError')
+ ->with($this->equalTo($myErrorMessage));
+
+ // We expect bind to be called with the data that was returned from getProperties
+ $tableMock->expects($this->once())
+ ->method('bind')
+ ->with($this->equalTo(array('id' => 5, 'username' => 'jimbo')));
+
+ // We expect check to be called. We will return false.
+ $tableMock->expects($this->once())
+ ->method('check')
+ ->will($this->returnValue(false));
+
+ // If check behaves properly, it will have set the error message in the table object. So we expect getError to be called on
+ // the table object and it should return the error message.
+ $tableMock->expects($this->once())
+ ->method('getError')
+ ->will($this->returnValue($myErrorMessage));
+
+ // Now when we call our actual save() method, it will return false
+ $this->assertThat(
+ $testObject->save(),
+ $this->equalTo(false),
+ 'JUser::save() did not return false when JTable::check returned failed'
+ );
+ }
+
+
+ /**
* Testing creation and deletion of users
*
* @return void
_______________________________________________
Joomla-commits mailing list
Joomla-...@joomlacode.org
http://joomlacode.org/mailman/listinfo/joomla-commits