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);
 }
 public function testAddressFetchLatitudeAndLongitude()
 {
     $super = User::getByUsername('super');
     Yii::app()->user->userModel = $super;
     $address = array();
     $address['street1'] = '123 Knob Street';
     $address['street2'] = 'Apartment 4b';
     $address['city'] = 'Chicago';
     $address['state'] = 'Illinois';
     $address['postalCode'] = '60606';
     $address['country'] = 'USA';
     $account1 = AddressGeoCodeTestHelper::createTestAccountsWithBillingAddressAndGetAccount($address, $super);
     $accountId1 = $account1->id;
     unset($account1);
     $address = array();
     $address['street1'] = '18367 South Oak Creek';
     $address['street2'] = '';
     $address['city'] = 'San Jose';
     $address['state'] = 'California';
     $address['postalCode'] = '95131';
     $address['country'] = 'USA';
     $account2 = AddressGeoCodeTestHelper::createTestAccountsWithBillingAddressAndGetAccount($address, $super);
     $accountId2 = $account2->id;
     unset($account2);
     $address = array();
     $address['street1'] = '9570 West Michigan Street';
     $address['street2'] = '';
     $address['city'] = 'New York';
     $address['state'] = 'NY';
     $address['postalCode'] = '10169';
     $address['country'] = 'USA';
     $account3 = AddressGeoCodeTestHelper::createTestAccountsWithBillingAddressAndGetAccount($address, $super);
     $accountId3 = $account3->id;
     unset($account3);
     $address = array();
     $address['street1'] = '24948 West Thomas Trail';
     $address['street2'] = '';
     $address['city'] = 'Milwaukee';
     $address['state'] = 'WI';
     $address['postalCode'] = '53219';
     $address['country'] = '';
     $account4 = AddressGeoCodeTestHelper::createTestAccountsWithBillingAddressAndGetAccount($address, $super);
     $accountId4 = $account4->id;
     unset($account4);
     //Check lat/long and invalid values after address creation.
     $account1 = Account::getById($accountId1);
     $this->assertEquals(null, $account1->billingAddress->latitude);
     $this->assertEquals(null, $account1->billingAddress->longitude);
     $this->assertEquals(0, $account1->billingAddress->invalid);
     unset($account1);
     AddressMappingUtil::updateChangedAddresses(2);
     $account1 = Account::getById($accountId1);
     $this->assertEquals(round('41.8817767', 4), round($account1->billingAddress->latitude, 4));
     $this->assertEquals(round('-87.6371461', 4), round($account1->billingAddress->longitude, 4));
     $this->assertEquals(0, $account1->billingAddress->invalid);
     unset($account1);
     $account2 = Account::getById($accountId2);
     $this->assertEquals(round('37.39680', 4), round($account2->billingAddress->latitude, 4));
     $this->assertEquals(round('-121.87794', 4), round($account2->billingAddress->longitude, 4));
     $this->assertEquals(0, $account2->billingAddress->invalid);
     unset($account2);
     $account3 = Account::getById($accountId3);
     $this->assertEquals(null, $account3->billingAddress->latitude);
     $this->assertEquals(null, $account3->billingAddress->longitude);
     $this->assertEquals(0, $account3->billingAddress->invalid);
     unset($account3);
     $account4 = Account::getById($accountId4);
     $this->assertEquals(null, $account4->billingAddress->latitude);
     $this->assertEquals(null, $account4->billingAddress->longitude);
     $this->assertEquals(0, $account4->billingAddress->invalid);
     unset($account4);
     AddressMappingUtil::updateChangedAddresses();
     $account3 = Account::getById($accountId3);
     $this->assertNotNull($account3->billingAddress->latitude);
     $this->assertNotNull($account3->billingAddress->longitude);
     $this->assertEquals(0, $account3->billingAddress->invalid);
     $account4 = Account::getById($accountId4);
     $this->assertNotNull($account4->billingAddress->latitude);
     $this->assertNotNull($account4->billingAddress->longitude);
     $this->assertNotEquals($account3->billingAddress->latitude, $account4->billingAddress->latitude);
     $this->assertNotEquals($account3->billingAddress->longitude, $account4->billingAddress->longitude);
     $this->assertEquals(0, $account4->billingAddress->invalid);
     unset($account3);
     unset($account4);
     //Check after Modifying address lat / long set to null and flag to flase.
     $account1 = Account::getById($accountId1);
     $account1->billingAddress->street1 = 'xxxxxx';
     $account1->billingAddress->city = 'xxxxxx';
     $account1->billingAddress->state = 'xxxxxx';
     $account1->billingAddress->postalCode = '00000';
     $account1->billingAddress->country = '';
     $this->assertTrue($account1->save(false));
     unset($account1);
     $account1 = Account::getById($accountId1);
     $this->assertEquals(null, $account1->billingAddress->latitude);
     $this->assertEquals(null, $account1->billingAddress->longitude);
     $this->assertEquals(0, $account1->billingAddress->invalid);
     unset($account1);
     //Test for Invalid address and set invalid flag to true.
     AddressMappingUtil::updateChangedAddresses();
     $account1 = Account::getById($accountId1);
     $this->assertEquals(null, $account1->billingAddress->latitude);
     $this->assertEquals(null, $account1->billingAddress->longitude);
     $this->assertEquals(1, $account1->billingAddress->invalid);
     unset($account1);
     $account1 = Account::getById($accountId1);
     $account1->billingAddress->street1 = '123 Knob Street';
     $account1->billingAddress->street2 = 'Apartment 4b';
     $account1->billingAddress->city = 'Chicago';
     $account1->billingAddress->state = 'Illinois';
     $account1->billingAddress->postalCode = '60606';
     $account1->billingAddress->country = 'USA';
     $this->assertTrue($account1->save());
     unset($account1);
     $account1 = Account::getById($accountId1);
     $this->assertEquals(null, $account1->billingAddress->latitude);
     $this->assertEquals(null, $account1->billingAddress->longitude);
     $this->assertEquals(0, $account1->billingAddress->invalid);
     $accountId1 = $account1->id;
     unset($account1);
     AddressMappingUtil::updateChangedAddresses();
     $account1 = Account::getById($accountId1);
     $this->assertEquals(round('41.8817767', 4), round($account1->billingAddress->latitude, 4));
     $this->assertEquals(round('-87.6371461', 4), round($account1->billingAddress->longitude, 4));
     $this->assertEquals(0, $account1->billingAddress->invalid);
 }
 public function testCollectionFetchAndGeocodeFetchForAddress()
 {
     $super = User::getByUsername('super');
     Yii::app()->user->userModel = $super;
     $address = array();
     $address['street1'] = '123 Knob Street';
     $address['street2'] = 'Apartment 4b';
     $address['city'] = 'Chicago';
     $address['state'] = 'Illinois';
     $address['postalCode'] = '60606';
     $address['country'] = 'USA';
     $account1 = AddressGeoCodeTestHelper::createTestAccountsWithBillingAddressAndGetAccount($address, $super);
     $accountId1 = $account1->id;
     unset($account1);
     $address = array();
     $address['street1'] = '1600 Amphitheatre Parkway';
     $address['street2'] = '';
     $address['city'] = 'Mountain View';
     $address['state'] = 'California';
     $address['postalCode'] = '94043';
     $address['country'] = 'USA';
     $account2 = AddressGeoCodeTestHelper::createTestAccountsWithBillingAddressAndGetAccount($address, $super);
     $accountId2 = $account2->id;
     unset($account2);
     $address = array();
     $address['street1'] = '36826 East Oak Road';
     $address['street2'] = '';
     $address['city'] = 'New York';
     $address['state'] = 'NY';
     $address['postalCode'] = '10001';
     $address['country'] = 'USA';
     $account3 = AddressGeoCodeTestHelper::createTestAccountsWithBillingAddressAndGetAccount($address, $super);
     $accountId3 = $account3->id;
     unset($account3);
     $address = array();
     $address['street1'] = '24948 West Thomas Trail';
     $address['street2'] = '';
     $address['city'] = 'Milwaukee';
     $address['state'] = 'WI';
     $address['postalCode'] = '53219';
     $address['country'] = '';
     $account4 = AddressGeoCodeTestHelper::createTestAccountsWithBillingAddressAndGetAccount($address, $super);
     $accountId4 = $account4->id;
     unset($account4);
     $account1 = Account::getById($accountId1);
     $this->assertEquals(null, $account1->billingAddress->latitude);
     $this->assertEquals(null, $account1->billingAddress->longitude);
     $this->assertEquals(0, $account1->billingAddress->invalid);
     $account2 = Account::getById($accountId2);
     $this->assertEquals(null, $account2->billingAddress->latitude);
     $this->assertEquals(null, $account2->billingAddress->longitude);
     $this->assertEquals(0, $account2->billingAddress->invalid);
     $account3 = Account::getById($accountId3);
     $this->assertEquals(null, $account3->billingAddress->latitude);
     $this->assertEquals(null, $account3->billingAddress->longitude);
     $this->assertEquals(0, $account3->billingAddress->invalid);
     $account4 = Account::getById($accountId4);
     $this->assertEquals(null, $account4->billingAddress->latitude);
     $this->assertEquals(null, $account4->billingAddress->longitude);
     $this->assertEquals(0, $account4->billingAddress->invalid);
     $addressCollection = AddressMappingUtil::fetchChangedAddressCollection(2);
     $this->assertEquals(2, count($addressCollection));
     $account1 = Account::getById($accountId1);
     $addressString = $account1->billingAddress->makeAddress();
     $latitudeLongitudeCoordinates = AddressMappingUtil::fetchGeocodeForAddress($addressString);
     $this->assertTrue(is_array($latitudeLongitudeCoordinates));
     $this->assertEquals(2, count($latitudeLongitudeCoordinates));
     $this->assertTrue(isset($latitudeLongitudeCoordinates['latitude']));
     $this->assertTrue(isset($latitudeLongitudeCoordinates['longitude']));
     $this->assertEquals(round('41.8817767', 4), round($latitudeLongitudeCoordinates['latitude'], 4));
     $this->assertEquals(round('-87.6371461', 4), round($latitudeLongitudeCoordinates['longitude'], 4));
 }
 public function run()
 {
     AddressMappingUtil::updateChangedAddresses();
     return true;
 }
 public function testGeoCodeResultData()
 {
     $super = User::getByUsername('super');
     Yii::app()->user->userModel = $super;
     $address = array();
     $address['street1'] = '123 Knob Street';
     $address['street2'] = 'Apartment 4b';
     $address['city'] = 'Chicago';
     $address['state'] = 'Illinois';
     $address['postalCode'] = '60606';
     $address['country'] = 'USA';
     $account1 = AddressGeoCodeTestHelper::createTestAccountsWithBillingAddressAndGetAccount($address, $super);
     $accountId1 = $account1->id;
     unset($account1);
     $address = array();
     $address['street1'] = '18367 South Oak Creek';
     $address['street2'] = '';
     $address['city'] = 'San Jose';
     $address['state'] = 'California';
     $address['postalCode'] = '95131';
     $address['country'] = 'USA';
     $account2 = AddressGeoCodeTestHelper::createTestAccountsWithBillingAddressAndGetAccount($address, $super);
     $accountId2 = $account2->id;
     unset($account2);
     $address = array();
     $address['street1'] = '9570 West Michigan Street';
     $address['street2'] = '';
     $address['city'] = 'New York';
     $address['state'] = 'NY';
     $address['postalCode'] = '10169';
     $address['country'] = 'USA';
     $account3 = AddressGeoCodeTestHelper::createTestAccountsWithBillingAddressAndGetAccount($address, $super);
     $accountId3 = $account3->id;
     unset($account3);
     $address = array();
     $address['street1'] = '24948 West Thomas Trail';
     $address['street2'] = '';
     $address['city'] = 'Milwaukee';
     $address['state'] = 'WI';
     $address['postalCode'] = '53219';
     $address['country'] = '';
     $account4 = AddressGeoCodeTestHelper::createTestAccountsWithBillingAddressAndGetAccount($address, $super);
     $accountId4 = $account4->id;
     unset($account4);
     AddressMappingUtil::updateChangedAddresses(2);
     $account1 = Account::getById($accountId1);
     $this->assertEquals(round('42.11529', 4), round($account1->billingAddress->latitude, 4));
     $this->assertEquals(round('-87.976399', 4), round($account1->billingAddress->longitude, 4));
     $this->assertEquals(0, $account1->billingAddress->invalid);
     $account2 = Account::getById($accountId2);
     $this->assertEquals(round('37.19170', 4), round($account2->billingAddress->latitude, 4));
     $this->assertEquals(round('-121.82640', 4), round($account2->billingAddress->longitude, 4));
     $this->assertEquals(0, $account2->billingAddress->invalid);
     $account3 = Account::getById($accountId3);
     $this->assertEquals(null, $account3->billingAddress->latitude);
     $this->assertEquals(null, $account3->billingAddress->longitude);
     $this->assertEquals(0, $account3->billingAddress->invalid);
     $account4 = Account::getById($accountId4);
     $this->assertEquals(null, $account4->billingAddress->latitude);
     $this->assertEquals(null, $account4->billingAddress->longitude);
     $this->assertEquals(0, $account4->billingAddress->invalid);
     $account1 = Account::getById($accountId1);
     $geoCodeQueryData1 = array('query' => $account1->billingAddress->makeAddress(), 'latitude' => $account1->billingAddress->latitude, 'longitude' => $account1->billingAddress->longitude);
     $account2 = Account::getById($accountId2);
     $geoCodeQueryData2 = array('query' => $account2->billingAddress->makeAddress(), 'latitude' => $account2->billingAddress->latitude, 'longitude' => $account2->billingAddress->longitude);
     $account3 = Account::getById($accountId3);
     $geoCodeQueryData3 = array('query' => $account3->billingAddress->makeAddress(), 'latitude' => $account3->billingAddress->latitude, 'longitude' => $account3->billingAddress->longitude);
     $account4 = Account::getById($accountId4);
     $geoCodeQueryData4 = array('query' => $account4->billingAddress->makeAddress(), 'latitude' => $account4->billingAddress->latitude, 'longitude' => $account4->billingAddress->longitude);
     $apiKey = Yii::app()->params['testGoogleGeoCodeApiKey'];
     $geoCodeResultObj1 = GoogleMappingUtil::getGeoCodeResultByData($apiKey, $geoCodeQueryData1);
     $geoCodeResultObj2 = GoogleMappingUtil::getGeoCodeResultByData($apiKey, $geoCodeQueryData2);
     $geoCodeResultObj3 = GoogleMappingUtil::getGeoCodeResultByData($apiKey, $geoCodeQueryData3);
     $geoCodeResultObj4 = GoogleMappingUtil::getGeoCodeResultByData($apiKey, $geoCodeQueryData4);
     $this->assertEquals(round('42.11529', 4), round($geoCodeResultObj1->latitude, 4));
     $this->assertEquals(round('-87.976399', 4), round($geoCodeResultObj1->longitude, 4));
     $this->assertEquals(round('37.19170', 4), round($geoCodeResultObj2->latitude, 4));
     $this->assertEquals(round('-121.82640', 4), round($geoCodeResultObj2->longitude, 4));
     $this->assertEquals('43', round($geoCodeResultObj3->latitude, 0));
     $this->assertEquals('-79.0', round($geoCodeResultObj3->longitude, 0));
     $this->assertEquals('43.06132', round($geoCodeResultObj4->latitude, 5));
     $this->assertEquals('-87.88806', round($geoCodeResultObj4->longitude, 5));
 }