public function testRegularUserAllControllerActionsNoElevation()
 {
     $super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super');
     $superAccount = AccountTestHelper::createAccountByNameForOwner('accountOwnedBySuper', $super);
     //Create address array for the account owned by super user.
     $address = array('street1' => '123 Knob Street', 'street2' => 'Apartment 4b', 'city' => 'Chicago', 'state' => 'Illinois', 'postalCode' => '60606', 'country' => 'USA');
     //Assign Address to the user account.
     AddressGeoCodeTestHelper::updateTestAccountsWithBillingAddress($superAccount->id, $address, $super);
     //Fetch Latitute and Longitude values for address and save in Address.
     AddressMappingUtil::updateChangedAddresses();
     $accounts = Account::getByName('accountOwnedBySuper');
     $this->assertEquals(1, count($accounts));
     $this->assertEquals(round('42.11529', 4), round($accounts[0]->billingAddress->latitude, 4));
     $this->assertEquals(round('-87.976399', 4), round($accounts[0]->billingAddress->longitude, 4));
     $this->assertEquals(0, $accounts[0]->billingAddress->invalid);
     $addressString = $accounts[0]->billingAddress->makeAddress();
     $this->setGetArray(array('addressString' => $addressString, 'latitude' => $accounts[0]->billingAddress->latitude, 'longitude' => $accounts[0]->billingAddress->longitude));
     Yii::app()->user->userModel = User::getByUsername('nobody');
     //Now test account details portlet controller actions
     $this->setGetArray(array('id' => $superAccount->id));
     $this->resetPostArray();
     $this->runControllerShouldResultInAccessFailureAndGetContent('accounts/default/details');
     //The map should always be available.  Not controlled by rights.
     $this->setGetArray(array('addressString' => 'anAddress String', 'latitude' => '45.00', 'longitude' => '45.00'));
     $content = $this->runControllerWithNoExceptionsAndGetContent('maps/default/mapAndPoint');
     $this->assertNotContains('Access Failure', $content);
 }
 public function testAddingMapPortletToAccountsDetailView()
 {
     //Lougout previous use and log in as super user
     $super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super');
     //Retriving the super account id.
     $superAccountId = self::getModelIdByModelNameAndName('Account', 'superAccount');
     //Create address array for the super account id.
     $address = array('street1' => '123 Knob Street', 'street2' => 'Apartment 4b', 'city' => 'Chicago', 'state' => 'Illinois', 'postalCode' => '60606', 'country' => 'USA');
     //Assign Address to the super user account.
     AddressGeoCodeTestHelper::updateTestAccountsWithBillingAddress($superAccountId, $address, $super);
     //Fetch Latitute and Longitude values for address and save in Address.
     AddressMappingUtil::updateChangedAddresses();
     $accounts = Account::getByName('superAccount');
     $this->assertEquals(1, count($accounts));
     $this->assertEquals(round('41.8817767', 4), round($accounts[0]->billingAddress->latitude, 4));
     $this->assertEquals(round('-87.6371461', 4), round($accounts[0]->billingAddress->longitude, 4));
     $this->assertEquals(0, $accounts[0]->billingAddress->invalid);
     $addressString = $accounts[0]->billingAddress->makeAddress();
     $this->setGetArray(array('addressString' => $addressString, 'latitude' => $accounts[0]->billingAddress->latitude, 'longitude' => $accounts[0]->billingAddress->longitude));
     $content = $this->runControllerWithNoExceptionsAndGetContent('maps/default/mapAndPoint');
     $this->assertContains('plotMap', $content);
     $accounts = Account::getAll();
     $this->assertEquals(1, count($accounts));
     //Load Model Detail Views
     $this->setGetArray(array('id' => $superAccountId, 'lockPortlets' => '0'));
     $this->resetPostArray();
     $this->runControllerWithNoExceptionsAndGetContent('accounts/default/details');
     $portlets = Portlet::getByLayoutIdAndUserSortedByColumnIdAndPosition('AccountDetailsAndRelationsView', $super->id, array());
     $this->assertEquals(3, count($portlets[1]));
     $this->assertFalse(array_key_exists(3, $portlets));
     $this->assertEquals(4, count($portlets[2]));
     foreach ($portlets[2] as $position => $portlet) {
         $portlet->delete();
     }
     $portlets = Portlet::getByLayoutIdAndUserSortedByColumnIdAndPosition('AccountDetailsAndRelationsView', $super->id, array());
     $this->assertFalse(array_key_exists(2, $portlets));
     $this->setGetArray(array('modelId' => $superAccountId, 'uniqueLayoutId' => 'AccountDetailsAndRelationsView', 'portletType' => 'MapForAccountAddress', 'redirect' => '0'));
     $this->resetPostArray();
     $this->runControllerWithNoExceptionsAndGetContent('accounts/defaultPortlet/add', true);
     $portlets = Portlet::getByLayoutIdAndUserSortedByColumnIdAndPosition('AccountDetailsAndRelationsView', $super->id, array());
     $this->assertEquals(1, count($portlets[2]));
     //Load Model Detail Views
     $this->setGetArray(array('id' => $superAccountId, 'lockPortlets' => '0'));
     $this->resetPostArray();
     $this->runControllerWithNoExceptionsAndGetContent('accounts/default/details');
 }
 public function testSuperUserAllDefaultControllerActions()
 {
     $super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super');
     //Retriving the super account id.
     $superAccountId = self::getModelIdByModelNameAndName('Account', 'superAccount');
     //Create address array for the super account id.
     $address = array('street1' => '123 Knob Street', 'street2' => 'Apartment 4b', 'city' => 'Chicago', 'state' => 'Illinois', 'postalCode' => '60606', 'country' => 'USA');
     //Assign Address to the super user account.
     AddressGeoCodeTestHelper::updateTestAccountsWithBillingAddress($superAccountId, $address, $super);
     //Fetch Latitute and Longitude values for address and save in Address.
     AddressMappingUtil::updateChangedAddresses();
     $accounts = Account::getByName('superAccount');
     $this->assertEquals(1, count($accounts));
     $this->assertEquals(round('41.8817767', 4), round($accounts[0]->billingAddress->latitude, 4));
     $this->assertEquals(round('-87.6371461', 4), round($accounts[0]->billingAddress->longitude, 4));
     $this->assertEquals(0, $accounts[0]->billingAddress->invalid);
     $addressString = $accounts[0]->billingAddress->makeAddress();
     $this->setGetArray(array('addressString' => $addressString, 'latitude' => $accounts[0]->billingAddress->latitude, 'longitude' => $accounts[0]->billingAddress->longitude));
     $content = $this->runControllerWithNoExceptionsAndGetContent('maps/default/mapAndPoint');
     $this->assertContains('plotMap', $content);
 }