Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.
 All Data Structures Functions Variables Pages
NotesSuperUserWalkthroughTest.php
1 <?php
2  /*********************************************************************************
3  * Zurmo is a customer relationship management program developed by
4  * Zurmo, Inc. Copyright (C) 2017 Zurmo Inc.
5  *
6  * Zurmo is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU Affero General Public License version 3 as published by the
8  * Free Software Foundation with the addition of the following permission added
9  * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
10  * IN WHICH THE COPYRIGHT IS OWNED BY ZURMO, ZURMO DISCLAIMS THE WARRANTY
11  * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
12  *
13  * Zurmo is distributed in the hope that it will be useful, but WITHOUT
14  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15  * FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
16  * details.
17  *
18  * You should have received a copy of the GNU Affero General Public License along with
19  * this program; if not, see http://www.gnu.org/licenses or write to the Free
20  * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21  * 02110-1301 USA.
22  *
23  * You can contact Zurmo, Inc. with a mailing address at 27 North Wacker Drive
24  * Suite 370 Chicago, IL 60606. or at email address contact@zurmo.com.
25  *
26  * The interactive user interfaces in original and modified versions
27  * of this program must display Appropriate Legal Notices, as required under
28  * Section 5 of the GNU Affero General Public License version 3.
29  *
30  * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
31  * these Appropriate Legal Notices must retain the display of the Zurmo
32  * logo and Zurmo copyright notice. If the display of the logo is not reasonably
33  * feasible for technical reasons, the Appropriate Legal Notices must display the words
34  * "Copyright Zurmo Inc. 2017. All rights reserved".
35  ********************************************************************************/
36 
41  {
42  public static function setUpBeforeClass()
43  {
44  parent::setUpBeforeClass();
45  SecurityTestHelper::createSuperAdmin();
46  $super = User::getByUsername('super');
47  Yii::app()->user->userModel = $super;
48 
49  //Setup test data owned by the super user.
50  $account = AccountTestHelper::createAccountByNameForOwner('superAccount', $super);
51  AccountTestHelper::createAccountByNameForOwner('superAccount2', $super);
52  ContactTestHelper::createContactWithAccountByNameForOwner('superContact', $super, $account);
53  }
54 
55  public function testSuperUserAllDefaultControllerActions()
56  {
57  $super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super');
58 
59  $superAccountId = self::getModelIdByModelNameAndName ('Account', 'superAccount');
60  $superAccountId2 = self::getModelIdByModelNameAndName ('Account', 'superAccount2');
61  $superContactId = self::getModelIdByModelNameAndName ('Contact', 'superContact superContactson');
62  $account = Account::getById($superAccountId);
63  $account2 = Account::getById($superAccountId2);
64  $contact = Contact::getById($superContactId);
65 
66  //confirm no existing activities exist
67  $activities = Activity::getAll();
68  $this->assertEquals(0, count($activities));
69 
70  //Test just going to the create from relation view.
71  $this->setGetArray(array( 'relationAttributeName' => 'Account', 'relationModelId' => $superAccountId,
72  'relationModuleId' => 'accounts', 'redirectUrl' => 'someRedirect'));
73  $this->runControllerWithNoExceptionsAndGetContent('notes/default/createFromRelation');
74 
75  //add related note for account using createFromRelation action
76  $activityItemPostData = array('account' => array('id' => $superAccountId));
77  $this->setGetArray(array('relationAttributeName' => 'Account', 'relationModelId' => $superAccountId,
78  'relationModuleId' => 'accounts', 'redirectUrl' => 'someRedirect'));
79  $this->setPostArray(array('ActivityItemForm' => $activityItemPostData, 'Note' => array('description' => 'myNote')));
80  $this->runControllerWithRedirectExceptionAndGetContent('notes/default/createFromRelation');
81 
82  //now test that the new note exists, and is related to the account.
83  $notes = Note::getAll();
84  $this->assertEquals(1, count($notes));
85  $this->assertEquals('myNote', $notes[0]->description);
86  $this->assertEquals(1, $notes[0]->activityItems->count());
87  $activityItem1 = $notes[0]->activityItems->offsetGet(0);
88  $this->assertEquals($account, $activityItem1);
89 
90  //test viewing the existing note in a details view
91  $this->setGetArray(array('id' => $notes[0]->id));
92  $this->resetPostArray();
93  $this->runControllerWithNoExceptionsAndGetContent('notes/default/details');
94 
95  //test editing an existing note and saving.
96  //First just go to the edit view and confirm it loads ok.
97  $this->setGetArray(array('id' => $notes[0]->id, 'redirectUrl' => 'someRedirect'));
98  $this->resetPostArray();
99  $this->runControllerWithNoExceptionsAndGetContent('notes/default/edit');
100  //Save changes via edit action.
101  $activityItemPostData = array('Account' => array('id' => $superAccountId),
102  'Contact' => array('id' => $superContactId));
103  $this->setGetArray(array('id' => $notes[0]->id, 'redirectUrl' => 'someRedirect'));
104  $this->setPostArray(array('ActivityItemForm' => $activityItemPostData, 'Note' => array('description' => 'myNoteX')));
105  $this->runControllerWithRedirectExceptionAndGetContent('notes/default/edit');
106  //Confirm changes applied correctly.
107  $notes = Note::getAll();
108  $this->assertEquals(1, count($notes));
109  $this->assertEquals('myNoteX', $notes[0]->description);
110  $this->assertEquals(2, $notes[0]->activityItems->count());
111  $activityItem1 = $notes[0]->activityItems->offsetGet(0);
112  $activityItem2 = $notes[0]->activityItems->offsetGet(1);
113  $this->assertEquals($account, $activityItem1);
114  $this->assertEquals($contact, $activityItem2);
115 
116  //Remove contact relation. Switch account relation to a different account.
117  $activityItemPostData = array('Account' => array('id' => $superAccountId2));
118  $this->setGetArray(array('id' => $notes[0]->id));
119  $this->setPostArray(array('ActivityItemForm' => $activityItemPostData, 'Note' => array('description' => 'myNoteX')));
120  $this->runControllerWithRedirectExceptionAndGetContent('notes/default/edit');
121  //Confirm changes applied correctly.
122  $notes = Note::getAll();
123  $this->assertEquals(1, count($notes));
124  $this->assertEquals('myNoteX', $notes[0]->description);
125  $this->assertEquals(1, $notes[0]->activityItems->count());
126  $activityItem1 = $notes[0]->activityItems->offsetGet(0);
127  $this->assertEquals($account2, $activityItem1);
128 
129  //Test validating an existing note via the inline edit validation (failed Validation)
130  $activityItemPostData = array('Account' => array('id' => $superAccountId),
131  'Contact' => array('id' => $superContactId));
132  $this->setGetArray(array('id' => $notes[0]->id, 'redirectUrl' => 'someRedirect'));
133  $this->setPostArray(array('ActivityItemForm' => $activityItemPostData,
134  'ajax' => 'inline-edit-form',
135  'Note' => array('description' => '')));
136  $content = $this->runControllerWithExitExceptionAndGetContent('notes/default/inlineCreateSave');
137  $this->assertTrue(strlen($content) > 20); //approximate, but should definetely be larger than 20.
138 
139  //Test validating an existing note via the inline edit validation (Success)
140  $this->setPostArray(array('ActivityItemForm' => $activityItemPostData,
141  'ajax' => 'inline-edit-form',
142  'Note' => array('description' => 'a Valid Name of a Note')));
143  $content = $this->runControllerWithExitExceptionAndGetContent('notes/default/inlineCreateSave');
144  $this->assertEquals('[]', $content);
145 
146  //Test saving an existing note via the inline edit validation
147  $this->setPostArray(array('ActivityItemForm' => $activityItemPostData,
148  'Note' => array('description' => 'a Valid Name of a Note')));
149  $content = $this->runControllerWithRedirectExceptionAndGetContent('notes/default/inlineCreateSave');
150  //Confirm changes applied correctly.
151  $notes = Note::getAll();
152  $this->assertEquals(2, count($notes));
153  $this->assertEquals('a Valid Name of a Note', $notes[1]->description);
154 
155  //test removing a note.
156  $this->setGetArray(array('id' => $notes[1]->id));
157  $this->resetPostArray();
158  $this->runControllerWithRedirectExceptionAndGetContent('notes/default/delete');
159  //Confirm no more notes exist.
160  $notes = Note::getAll();
161  $this->assertEquals(1, count($notes));
162  }
163  }
164 ?>
static getByUsername($username)
Definition: User.php:49
runControllerWithRedirectExceptionAndGetContent($route, $compareUrl=null, $compareUrlContains=false)
static getById($id, $modelClassName=null)
logoutCurrentUserLoginNewUserAndGetByUsername($username)
runControllerWithNoExceptionsAndGetContent($route, $empty=false)
static getAll($orderBy=null, $sortDescending=false, $modelClassName=null)
Generated on Mon Nov 30 2020 07:10:44
Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.