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

Commit 28aa36e

Browse files
committed
ENH: refs #231. Added tests and fixed identation
1 parent dd3a9cc commit 28aa36e

File tree

13 files changed

+238
-71
lines changed

13 files changed

+238
-71
lines changed

modules/communityagreement/AppController.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,13 @@
1313

1414
class Communityagreement_AppController extends MIDAS_GlobalModule
1515
{
16-
public $moduleName='communityagreement';
16+
public $moduleName='communityagreement';
1717

1818
/**
1919
* Communityagreement_Agreement Model
2020
* @var Communityagreement_AgreementModelBase
2121
*/
2222
var $Communityagreement_Agreement;
2323
} //end class
24-
?>
24+
?>
25+

modules/communityagreement/Notification.php

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
/** notification manager*/
33
class Communityagreement_Notification extends MIDAS_Notification
44
{
5-
public $_models=array('Community');
5+
public $_models = array('Community');
66

77
/** init notification process*/
88
public function init()
@@ -19,20 +19,23 @@ public function getCommunityManageTabs()
1919
$moduleWebroot = $fc->getBaseUrl().'/communityagreement';
2020
return array('Community Agreement' => $moduleWebroot.'/config/agreementtab');
2121
}
22-
23-
public function getCommunityViewJSs()
22+
23+
/** get Java scripts */
24+
public function getCommunityViewJSs()
2425
{
2526
$fc = Zend_Controller_Front::getInstance();
2627
$moduleUriroot = $fc->getBaseUrl().'/modules/communityagreement';
2728
return array($moduleUriroot.'/public/js/config/config.agreementcheckbox.js');
2829
}
29-
30-
public function getCommunityViewCSSs()
30+
31+
/** get CSS */
32+
public function getCommunityViewCSSs()
3133
{
3234
$fc = Zend_Controller_Front::getInstance();
3335
$moduleUriroot = $fc->getBaseUrl().'/modules/communityagreement';
3436
return array($moduleUriroot.'/public/css/config/config.agreementcheckbox.css');
3537
}
3638

3739
} //end class
38-
?>
40+
?>
41+

modules/communityagreement/controllers/ConfigController.php

Lines changed: 69 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@
1313
class Communityagreement_ConfigController extends Communityagreement_AppController
1414
{
1515
public $_models = array('Community');
16-
public $_components=array('Utility');
17-
public $_moduleModels=array('Agreement');
16+
public $_moduleModels = array('Agreement');
1817
public $_moduleForms = array('Config');
1918

2019
/** index */
@@ -26,77 +25,87 @@ function indexAction()
2625
}
2726
}
2827

29-
/**
28+
/**
3029
* @method agreementtabAction()
3130
* community agreement tab. It is shown in the community manage page when the 'community agreement' module is enabled
3231
*/
33-
function agreementtabAction()
34-
{
32+
function agreementtabAction()
33+
{
3534

36-
if(!$this->logged)
35+
if(!$this->logged)
3736
{
3837
$this->haveToBeLogged();
3938
return false;
4039
}
40+
if($this->_helper->hasHelper('layout'))
41+
{
42+
$this->_helper->layout->disableLayout();
43+
}
4144

42-
$this->_helper->layout->disableLayout();
43-
44-
$communityId = $this->_getParam("communityId");
45+
$communityId = $this->_getParam("communityId");
4546
if(!isset($communityId) || (!is_numeric($communityId) && strlen($communityId) != 32)) // This is tricky! and for Cassandra for now
4647
{
4748
throw new Zend_Exception("Community ID should be a number");
4849
}
49-
50+
5051
$agreementDao = $this->Communityagreement_Agreement->getByCommunityId($communityId);
5152

5253
// If community agreement does not exist, show an emtpy string to the cummunity administrator
5354
if($agreementDao == false)
5455
{
55-
$agreement = '';
56-
$agreementDao = $this->Communityagreement_Agreement->createAgreement($communityId, $agreement);
56+
$agreement = '';
57+
$agreementDao = $this->Communityagreement_Agreement->createAgreement($communityId, $agreement);
5758
}
5859

5960
$formAgreement = $this->ModuleForm->Config->createCreateAgreementForm($communityId);
6061
if($this->_request->isPost() && $formAgreement->isValid($this->getRequest()->getPost()))
6162
{
62-
$this->_helper->layout->disableLayout();
63-
$this->_helper->viewRenderer->setNoRender();
64-
$agreementDao->setAgreement($formAgreement->getValue('agreement'));
65-
if($agreementDao != false)
66-
{
67-
echo JsonComponent::encode(array(true, $this->t('Changes saved')));
68-
}
69-
else
70-
{
71-
echo JsonComponent::encode(array(false, $this->t('Error')));
72-
}
63+
if($this->_helper->hasHelper('layout'))
64+
{
65+
$this->_helper->layout->disableLayout();
66+
}
67+
$this->_helper->viewRenderer->setNoRender();
68+
$agreementDao->setAgreement($formAgreement->getValue('agreement'));
69+
if($agreementDao != false)
70+
{
71+
echo JsonComponent::encode(array(true, $this->t('Changes saved')));
72+
}
73+
else
74+
{
75+
echo JsonComponent::encode(array(false, $this->t('Error')));
76+
}
7377
}
7478

7579
// if agreement only contains white spaces, delete it from the database.
7680
$chopped_agreement = chop($agreementDao->getAgreement());
77-
if ($chopped_agreement != '' ) {
78-
$this->Communityagreement_Agreement->save($agreementDao);
79-
} else if ($this->Communityagreement_Agreement->getByCommunityId($communityId) != false)
80-
{
81-
$this->Communityagreement_Agreement->delete($agreementDao);
82-
}
81+
if($chopped_agreement != '' )
82+
{
83+
$this->Communityagreement_Agreement->save($agreementDao);
84+
}
85+
else if($this->Communityagreement_Agreement->getByCommunityId($communityId) != false)
86+
{
87+
$this->Communityagreement_Agreement->delete($agreementDao);
88+
}
8389

8490
//init form
8591
$agreement = $formAgreement->getElement('agreement');
8692
$agreement->setValue($agreementDao->getAgreement());
8793
$this->view->agreementForm = $this->getFormAsArray($formAgreement);
8894
$this->view->agreementDao = $agreementDao;
89-
}
95+
}
9096

91-
/**
97+
/**
9298
* @method agreementdialogAction()
9399
* community agreement dialog, show the community agreements to peaple who want to join the community
94-
*/
95-
function agreementdialogAction()
96-
{
97-
$this->disableLayout();
100+
*/
101+
function agreementdialogAction()
102+
{
103+
if($this->_helper->hasHelper('layout'))
104+
{
105+
$this->_helper->layout->disableLayout();
106+
}
98107

99-
$communityId = $this->_getParam("communityId");
108+
$communityId = $this->_getParam("communityId");
100109
if(!isset($communityId) || (!is_numeric($communityId) && strlen($communityId) != 32)) // This is tricky! and for Cassandra for now
101110
{
102111
throw new Zend_Exception("Community ID should be a number");
@@ -105,36 +114,36 @@ function agreementdialogAction()
105114
$agreementDao = $this->Communityagreement_Agreement->getByCommunityId($communityId);
106115
if($agreementDao == false)
107116
{
108-
$agreement = '';
109-
$agreementDao = $this->Communityagreement_Agreement->createAgreement($communityId, $agreement);
117+
$agreement = '';
118+
$agreementDao = $this->Communityagreement_Agreement->createAgreement($communityId, $agreement);
110119
}
111120
$this->view->agreementDao = $agreementDao;
112-
}
121+
}
113122

114123

115124
/**
116125
* @method checkIfAgreementEmptyAction()
117-
* ajax function which checks if the community agreement has been set
118-
*/
119-
public function checkagreementAction()
120-
{
121-
if(!$this->getRequest()->isXmlHttpRequest())
122-
{
123-
throw new Zend_Exception("Why are you here ? Should be ajax.");
124-
}
125-
$this->_helper->layout->disableLayout();
126-
$this->_helper->viewRenderer->setNoRender();
126+
* ajax function which checks if the community agreement has been set
127+
*/
128+
public function checkagreementAction()
129+
{
130+
if(!$this->getRequest()->isXmlHttpRequest())
131+
{
132+
throw new Zend_Exception("Why are you here ? Should be ajax.");
133+
}
134+
$this->_helper->layout->disableLayout();
135+
$this->_helper->viewRenderer->setNoRender();
127136

128-
$communityId = $this->_getParam("communityId");
129-
$agreementDao = $this->Communityagreement_Agreement->getByCommunityId($communityId);
130-
if($agreementDao != false)
131-
{
132-
echo JsonComponent::encode(MIDAS_COMMUNITYAGREEMENT_AGREEMENT_NOT_EMPTY);
133-
}
134-
else
135-
{
136-
echo JsonComponent::encode(MIDAS_COMMUNITYAGREEMENT_AGREEMENT_IS_EMPTY);
137-
}
138-
}
137+
$communityId = $this->_getParam("communityId");
138+
$agreementDao = $this->Communityagreement_Agreement->getByCommunityId($communityId);
139+
if($agreementDao != false)
140+
{
141+
echo JsonComponent::encode(MIDAS_COMMUNITYAGREEMENT_AGREEMENT_NOT_EMPTY);
142+
}
143+
else
144+
{
145+
echo JsonComponent::encode(MIDAS_COMMUNITYAGREEMENT_AGREEMENT_IS_EMPTY);
146+
}
147+
}
139148

140149
}//end class

modules/communityagreement/database/mysql/1.0.0.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
-- `communityagreement_agreement` table
33
ALTER TABLE `community` ENGINE = InnoDB;
44

5-
DROP TABLE IF EXISTS communityagreement_agreement;
5+
# DROP TABLE IF EXISTS communityagreement_agreement;
66
CREATE TABLE communityagreement_agreement (
77
`agreement_id` bigint(20) NOT NULL AUTO_INCREMENT,
88
`community_id` bigint(20) NOT NULL REFERENCES community.community_id,

modules/communityagreement/models/base/AgreementModelBase.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public function __construct()
3333
* */
3434
function createAgreement($community_id, $agreement)
3535
{
36-
$this->loadDaoClass('AgreementDao','communityagreement');
36+
$this->loadDaoClass('AgreementDao', 'communityagreement');
3737
$agreementDao = new Communityagreement_AgreementDao();
3838
$agreementDao->setCommunityId($community_id);
3939
$agreementDao->setAgreement($agreement);

modules/communityagreement/models/pdo/AgreementModel.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
class Communityagreement_AgreementModel extends Communityagreement_AgreementModelBase
1717
{
1818
/** Get all */
19-
function getAll()
19+
function getAll()
2020
{
2121
$sql = $this->database->select();
2222
$rowset = $this->database->fetchAll($sql);
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
add_subdirectory( controllers )
2+
add_subdirectory( models )
3+
4+
add_midas_style_test( StyleCommunityagreementNotification ${CMAKE_SOURCE_DIR}/modules/communityagreement/Notification.php )
5+
add_midas_style_test( StyleTestsCommunityagreementControllers ${CMAKE_SOURCE_DIR}/modules/communityagreement/tests/controllers )
6+
add_midas_style_test( StyleTestsCommunityagreementModels ${CMAKE_SOURCE_DIR}/modules/communityagreement/tests/models )
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
add_midas_mysql_test( CommunityagreementConfigController ConfigControllerTest.php )
2+
3+
4+
# Syle
5+
add_midas_style_test( StyleCommunityagreementControllers ${CMAKE_SOURCE_DIR}/modules/communityagreement/controllers )
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
<?php
2+
/*=========================================================================
3+
MIDAS Server
4+
Copyright (c) Kitware SAS. 20 rue de la Villette. All rights reserved.
5+
69328 Lyon, FRANCE.
6+
7+
See Copyright.txt for details.
8+
This software is distributed WITHOUT ANY WARRANTY; without even
9+
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
10+
PURPOSE. See the above copyright notices for more information.
11+
=========================================================================*/
12+
13+
// need to include the module constant for this test
14+
require_once str_replace('tests', 'constant', str_replace('controllers', 'module.php', dirname(__FILE__)));
15+
16+
/** config controller test*/
17+
class ConfigControllerTest extends ControllerTestCase
18+
{
19+
/** set up tests*/
20+
public function setUp()
21+
{
22+
$this->setupDatabase(array('default'), 'communityagreement');
23+
$this->setupDatabase(array('default'));
24+
$this->_models = array('Community', 'User');
25+
$this->_moduleModels = array('Agreement');
26+
$this->enabledModules = array('communityagreement');
27+
parent::setUp();
28+
}
29+
30+
/** test agreementdialog*/
31+
public function testAgreementdialogAction()
32+
{
33+
$communitiesFile = $this->loadData('Community', 'default');
34+
$community_id = $communitiesFile[0]->getKey();
35+
36+
$this->getRequest()->setMethod('POST');
37+
$page = '/communityagreement/config/agreementdialog?communityId='.$community_id;
38+
$this->dispatchUrI($page);
39+
40+
$this->assertModule("communityagreement");
41+
$this->assertController("config");
42+
$this->assertAction("agreementdialog");
43+
44+
$body = $this->getBody();
45+
if(strpos($body, "Community agreement for Community test User 1") === false)
46+
{
47+
$this->fail('Unable to find body element');
48+
}
49+
}
50+
51+
/** test agreementtab*/
52+
public function testAgreementtabAction()
53+
{
54+
$communitiesFile = $this->loadData('Community', 'default');
55+
$community_id = $communitiesFile[0]->getKey();
56+
57+
$this->params = array();
58+
$this->params['email'] = 'user1@user1.com';
59+
$this->params['password'] = 'test';
60+
$this->request->setMethod('POST');
61+
$this->dispatchUrI("/user/login");
62+
63+
$page = '/communityagreement/config/agreementtab?communityId='.$community_id;
64+
$this->params = array();
65+
$this->getRequest()->setMethod('GET');
66+
$this->dispatchUrI($page);
67+
68+
$this->assertModule("communityagreement");
69+
$this->assertController("config");
70+
$this->assertAction("agreementtab");
71+
72+
$this->params['agreement'] = 'test agreement tab';
73+
$this->getRequest()->setMethod('POST');
74+
$this->dispatchUrI($page);
75+
76+
$modelLoad = new MIDAS_ModelLoader();
77+
$agreementModel = $modelLoad->loadModel('Agreement', 'communityagreement');
78+
$saved_agreement = $agreementModel->getByCommunityId($community_id)->getAgreement();
79+
$this->assertEquals('test agreement tab', $saved_agreement);
80+
}
81+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
<dataset>
3+
<communityagreement_agreement agreement_id="5000" community_id="2000"
4+
agreement="Community agreement for Community test User 1" />
5+
</dataset>
6+

0 commit comments

Comments
 (0)