[Joomla-commits] r18758 - development/trunk/tests/unit/suite/libraries/joomla/user

0 views
Skip to first unread message

i...@jcode001.directrouter.com

unread,
Sep 2, 2010, 1:16:04 AM9/2/10
to joomla-...@joomlacode.org
Author: ian
Date: 2010-09-02 00:16:04 -0500 (Thu, 02 Sep 2010)
New Revision: 18758

Modified:
development/trunk/tests/unit/suite/libraries/joomla/user/JUserTest.php
Log:
Added testSaveNoCreateNewUser

Modified: development/trunk/tests/unit/suite/libraries/joomla/user/JUserTest.php
===================================================================
--- development/trunk/tests/unit/suite/libraries/joomla/user/JUserTest.php 2010-09-02 04:00:08 UTC (rev 18757)
+++ development/trunk/tests/unit/suite/libraries/joomla/user/JUserTest.php 2010-09-02 05:16:04 UTC (rev 18758)
@@ -71,6 +71,7 @@
protected function tearDown()
{
$this->setErrorhandlers($this->savedErrorState);
+ $this->restoreFactoryState();
}

/**
@@ -462,8 +463,56 @@
'JUser::save() did not return false when JTable::check returned failed'
);
}
+
+ /**
+ * Testing save() for the case where updateOnly is true and it is a new user
+ *
+ * @return void
+ */
+ public function testSaveNoCreateNewUser()
+ {
+ // here we inject a mock user object into a mock session object so that when JFactory::getUser gets called
+ // we already have an object in place and we don't get complaints about not being able to send cookies
+ $sessionMock = $this->getMock('JSession', array('get'), array(), '', false);
+ $userMock = $this->getMock('JUser', array(), array(), '', false);
+
+ $sessionMock->expects($this->any())
+ ->method('get')
+ ->with($this->equalTo('user'))
+ ->will($this->returnValue($userMock));
+
+ JFactory::$session = $sessionMock;
+
+ // 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
+ // We don't care too much about these methods, because all we're primarily concerned about is that
+ // it doesn't try to create a new user
+ $testObject = $this->getMock('JUser', array('getTable', 'getProperties'));
+ $tableMock = $this->getMock('JTableUser', array('bind', 'check', 'store'), array(), '', false);

+ // we expect getTable to be called once. We are going to return our mock table object.
+ $testObject->expects($this->any())
+ ->method('getTable')
+ ->will($this->returnValue($tableMock));

+ $testObject->id = null;
+
+ $tableMock->expects($this->never())
+ ->method('store');
+
+ $tableMock->expects($this->any())
+ ->method('check')
+ ->will($this->returnValue(true));
+
+ // Now when we call our actual save() method, it will return false
+ $this->assertThat(
+ $testObject->save(true),
+ $this->equalTo(true),
+ 'JUser::save() did not get stopped when trying to save a new user when it was not supposed to'
+ );
+
+ }
+
/**
* Testing creation and deletion of users
*

_______________________________________________
Joomla-commits mailing list
Joomla-...@joomlacode.org
http://joomlacode.org/mailman/listinfo/joomla-commits

Reply all
Reply to author
Forward
0 new messages