Skip to content
This repository was archived by the owner on Sep 10, 2021. It is now read-only.

Commit 6383a1f

Browse files
author
Charles Marion
committed
ENH: Added UserControllerTest.php
1 parent 3b6ade7 commit 6383a1f

File tree

9 files changed

+364
-22
lines changed

9 files changed

+364
-22
lines changed

core/AppController.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public function preDispatch()
5959
$modelLoad = new MIDAS_ModelLoader();
6060
if(Zend_Registry::get('configGlobal')->environment == 'testing' && isset($testingUserId))
6161
{
62-
$user = new Zend_Session_Namespace('Auth_User');
62+
$user = new Zend_Session_Namespace('Auth_User_Testing');
6363
$userModel = $modelLoad->loadModel('User');
6464
$user->Dao = $userModel->load($testingUserId);
6565
if($user->Dao == false)
@@ -227,6 +227,10 @@ public function preDispatch()
227227
/** get server's url */
228228
function getServerURL()
229229
{
230+
if($this->isTestingEnv())
231+
{
232+
return 'http://localhost';
233+
}
230234
$currentPort = "";
231235
$prefix = "http://";
232236

core/controllers/UserController.php

Lines changed: 40 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@ function recoverpasswordAction()
2525
{
2626
throw new Zend_Exception('Shouldn\'t be logged in');
2727
}
28-
$this->_helper->layout->disableLayout();
28+
$this->disableLayout();
2929
$email = $this->_getParam('email');
3030
if(isset($email))
3131
{
32-
$this->_helper->viewRenderer->setNoRender();
32+
$this->disableView();
3333
$user = $this->User->getByEmail($email);
3434

3535
// Check ifthe email is already registered
@@ -76,7 +76,7 @@ function make_seed_recoverpass()
7676
$text .= "Your new password is: ".$pass."<br>";
7777
$text .= "<br><br>Generated by MIDAS";
7878

79-
if(mail("$email", "MIDAS: Password request", "$text", "From: \nReply-To: no-reply\nX-Mailer: PHP/" . phpversion()."\nMIME-Version: 1.0\nContent-type: text/html; charset = iso-8859-1"))
79+
if($this->isTestingEnv() || mail("$email", "MIDAS: Password request", "$text", "From: \nReply-To: no-reply\nX-Mailer: PHP/" . phpversion()."\nMIME-Version: 1.0\nContent-type: text/html; charset = iso-8859-1"))
8080
{
8181
$this->User->save($user);
8282
echo JsonComponent::encode(array(true, $this->t('An Email has been sent to').' '.$email));
@@ -115,7 +115,7 @@ function registerAction()
115115
$this->_redirect("/");
116116
}
117117
$this->view->form = $this->getFormAsArray($form);
118-
$this->_helper->layout->disableLayout();
118+
$this->disableLayout();
119119
$this->view->jsonRegister = JsonComponent::encode(array(
120120
'MessageNotValid' => $this->t('The e-mail is not valid'), 'MessageNotAvailable' => $this->t('This e-mail is not available'), 'MessagePassword' => $this->t('Password too short'), 'MessagePasswords' => $this->t('The passwords are not the same'), 'MessageLastname' => $this->t('Please set your lastname'), 'MessageTerms' => $this->t('Please validate the terms of service'), 'MessageFirstname' => $this->t('Please set your firstname')
121121
));
@@ -128,7 +128,7 @@ function loginAction()
128128
$this->Form->User->uri = $this->getRequest()->getRequestUri();
129129
$form = $this->Form->User->createLoginForm();
130130
$this->view->form = $this->getFormAsArray($form);
131-
$this->_helper->layout->disableLayout();
131+
$this->disableLayout();
132132
if($this->_request->isPost())
133133
{
134134
$this->_helper->viewRenderer->setNoRender();
@@ -152,14 +152,21 @@ function loginAction()
152152
$passwordPrefix = Zend_Registry::get('configGlobal')->password->prefix;
153153
if($authLdap || $userDao != false && md5($passwordPrefix.$form->getValue('password')) == $userDao->getPassword())
154154
{
155+
155156
$remember = $form->getValue('remerberMe');
156157
if(isset($remember) && $remember == 1)
157158
{
158-
setcookie('midasUtil', $userDao->getKey().'-'.md5($userDao->getPassword()), time() + 60 * 60 * 24 * 30, '/'); //30 days
159+
if(!$this->isTestingEnv())
160+
{
161+
setcookie('midasUtil', $userDao->getKey().'-'.md5($userDao->getPassword()), time() + 60 * 60 * 24 * 30, '/'); //30 days
162+
}
159163
}
160164
else
161165
{
162-
setcookie('midasUtil', null, time() + 60 * 60 * 24 * 30, '/'); //30 days
166+
if(!$this->isTestingEnv())
167+
{
168+
setcookie('midasUtil', null, time() + 60 * 60 * 24 * 30, '/'); //30 days
169+
}
163170
}
164171
Zend_Session::start();
165172
$user = new Zend_Session_Namespace('Auth_User');
@@ -168,6 +175,12 @@ function loginAction()
168175
$url = $form->getValue('url');
169176
$user->lock();
170177
$this->getLogger()->info(__METHOD__ . " Log in : " . $userDao->getFullName());
178+
if($this->isTestingEnv())
179+
{
180+
echo 'Test Pass';
181+
$this->disableView();
182+
return;
183+
}
171184
}
172185
}
173186

@@ -196,13 +209,13 @@ public function termofserviceAction()
196209
/** valid entries (ajax)*/
197210
public function validentryAction()
198211
{
199-
if(!$this->getRequest()->isXmlHttpRequest())
212+
if(!$this->getRequest()->isXmlHttpRequest() && !$this->isTestingEnv())
200213
{
201214
throw new Zend_Exception("Why are you here? Should be ajax.");
202215
}
203216

204-
$this->_helper->layout->disableLayout();
205-
$this->_helper->viewRenderer->setNoRender();
217+
$this->disableLayout();
218+
$this->disableView();
206219
$entry = $this->_getParam("entry");
207220
$type = $this->_getParam("type");
208221
if(!is_string($entry) || !is_string($type))
@@ -255,10 +268,10 @@ public function settingsAction()
255268
{
256269
if(!$this->logged)
257270
{
258-
$this->_helper->viewRenderer->setNoRender();
271+
$this->disableView();
259272
return false;
260273
}
261-
$this->_helper->layout->disableLayout();
274+
$this->disableLayout();
262275

263276
$userId = $this->_getParam('userId');
264277
if(isset($userId) && $userId != $this->userSession->Dao->getKey() && !$this->userSession->Dao->isAdmin())
@@ -345,10 +358,21 @@ public function settingsAction()
345358
}
346359
if(isset($modifyPicture) && $this->logged)
347360
{
348-
$upload = new Zend_File_Transfer();
349-
$upload->receive();
350-
$path = $upload->getFileName();
351-
if(!empty($path) && file_exists($path) && $upload->getFileSize() > 0)
361+
if($this->isTestingEnv())
362+
{
363+
//simulate file upload
364+
$path = BASE_PATH.'/tests/testfiles/search.png';
365+
$size = filesize($path);
366+
}
367+
else
368+
{
369+
$upload = new Zend_File_Transfer();
370+
$upload->receive();
371+
$path = $upload->getFileName();
372+
$size = $upload->getFileSize();
373+
}
374+
375+
if(!empty($path) && file_exists($path) && $size > 0)
352376
{
353377
//create thumbnail
354378
$thumbnailCreator = $this->Component->Filter->getFilter('ThumbnailCreator');

core/models/base/GroupModelBase.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,25 @@ abstract function addUser($group, $user);
2323
abstract function removeUser($group, $user);
2424
abstract function findByCommunity($communityDao);
2525
abstract function getGroupFromSearch($search, $limit = 14);
26+
27+
/** load */
28+
public function load($key = null)
29+
{
30+
if($key == MIDAS_GROUP_ANONYMOUS_KEY)
31+
{
32+
$this->loadDaoClass('GroupDao');
33+
$dao = new GroupDao();
34+
$dao->setGroupId(MIDAS_GROUP_ANONYMOUS_KEY);
35+
$dao->setCommunityId(0);
36+
$dao->setName('Anonymous');
37+
$dao->saved = true;
38+
return $dao;
39+
}
40+
else
41+
{
42+
return parent::load($key);
43+
}
44+
}
2645

2746
/** Delete a group */
2847
public function deleteGroup($group)

core/views/user/settings.phtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ echo '<script type="text/javascript" src="' . $this->coreWebroot . '/public/js/u
109109
echo "<ul>";
110110
foreach($this->communities as $community)
111111
{
112-
echo "<li><a style='color:white;' href='{$this->webroot}/community/{$community->getKey()}'>{$community->getName()}</a>";
112+
echo "<li class='settingsCommunityList'><a style='color:white;' href='{$this->webroot}/community/{$community->getKey()}'>{$community->getName()}</a>";
113113
echo "<ul>";
114114
foreach($community->groups as $group)
115115
{

tests/core/ControllerTestCase.php

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@ public function setUp()
1313
parent::setUp();
1414
}
1515

16+
17+
public function getBody()
18+
{
19+
return $this->response->outputBody();
20+
}
1621
/**
1722
* @return PHPUnit_Extensions_Database_DataSet_IDataSet
1823
*/
@@ -100,9 +105,16 @@ public function dispatchUrI($uri, $userDao = null, $withException = false){
100105
{
101106
$this->params['testingUserId'] = $userDao->getKey();
102107
}
103-
104-
$this->request->setQuery($this->params);
108+
if($this->request->isPost())
109+
{
110+
$this->request->setPost($this->params);
111+
}
112+
else
113+
{
114+
$this->request->setQuery($this->params);
115+
}
105116
$this->dispatch($uri);
117+
$this->assertNotResponseCode('404');
106118
if($this->request->getControllerName()=="error")
107119
{
108120
if($withException)

tests/core/controllers/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
add_midas_test( IndexController IndexControllerTest.php )
22
add_midas_test( FeedController FeedControllerTest.php )
3+
add_midas_test( UserController UserControllerTest.php )
34

45

56
# Syle

0 commit comments

Comments
 (0)