public static function setUpBeforeClass()
 {
     parent::setUpBeforeClass();
     SecurityTestHelper::createSuperAdmin();
     $super = User::getByUsername('super');
     Yii::app()->user->userModel = $super;
     // create ContactStates
     ContactsModule::loadStartingData();
     static::$baseUsername = StringUtil::generateRandomString(6, implode(range('a', 'z')));
 }
 public static function generateRandomUsername($safe = false)
 {
     $username = StringUtil::generateRandomString(5, implode(range("a", "z")));
     if ($safe) {
         do {
             try {
                 $userFound = User::getByUsername($username);
                 $username = StringUtil::generateRandomString(5, implode(range("a", "z")));
             } catch (NotFoundException $e) {
                 $userFound = false;
             }
         } while ($userFound);
     }
     return $username;
 }
 public static function setUpBeforeClass()
 {
     parent::setUpBeforeClass();
     ContactsModule::loadStartingData();
     SecurityTestHelper::createSuperAdmin();
     SecurityTestHelper::createUsers();
     self::$super = User::getByUsername('super');
     Yii::app()->user->userModel = self::$super;
     $emailSignature = new EmailSignature();
     $emailSignature->htmlContent = 'my email signature';
     self::$super->emailSignatures->add($emailSignature);
     self::$super->save();
     $currencies = Currency::getAll();
     $currencyValue1 = new CurrencyValue();
     $currencyValue1->value = 100;
     $currencyValue1->currency = $currencies[0];
     $multiDropDownCustomFieldData1 = new CustomFieldData();
     $multiDropDownCustomFieldData1->name = 'multiDropDown1';
     $multiDropDownCustomFieldData1->serializedData = serialize(array('Ten', 11, 'XII'));
     $saved = $multiDropDownCustomFieldData1->save();
     assert('$saved');
     // Not Coding Standard
     $multiDropDownCustomFieldValue1 = new CustomFieldValue();
     $multiDropDownCustomFieldValue1->value = 'Ten';
     $multiDropDownCustomFieldValue2 = new CustomFieldValue();
     $multiDropDownCustomFieldValue2->value = 11;
     $multiDropDownCustomFieldValue3 = new CustomFieldValue();
     $multiDropDownCustomFieldValue3->value = 'XII';
     $tagCustomFieldData1 = new CustomFieldData();
     $tagCustomFieldData1->name = 'tagCloud1';
     $tagCustomFieldData1->serializedData = serialize(array('Apache', 'PHP'));
     $saved = $tagCustomFieldData1->save();
     assert('$saved');
     // Not Coding Standard
     $tagCustomFieldValue1 = new CustomFieldValue();
     $tagCustomFieldValue1->value = 'PHP';
     $tagCustomFieldValue2 = new CustomFieldValue();
     $tagCustomFieldValue2->value = 'Apache';
     $primaryEmail1 = new Email();
     $primaryEmail1->emailAddress = "*****@*****.**";
     $primaryEmail1->isInvalid = true;
     $primaryEmail1->optOut = false;
     $secondaryEmail1 = new Email();
     $secondaryEmail1->emailAddress = "*****@*****.**";
     $secondaryEmail1->isInvalid = false;
     $secondaryEmail1->optOut = true;
     $address1 = new Address();
     $address1->street1 = "SomeStreet1";
     $address1->street2 = "SomeStreet2";
     $address1->city = "SomeCity";
     $address1->state = "SomeState";
     $address1->postalCode = 1111;
     $address1->country = "SomeCountry";
     $likeContactState1 = new ContactState();
     $likeContactState1->name = 'Customer';
     $likeContactState1->order = 0;
     static::$userHash = StringUtil::generateRandomString(60);
     $users = User::getAll();
     $user1 = new User();
     $user1->lastName = 'Kevin';
     $user1->hash = static::$userHash;
     $user1->language = 'es';
     $user1->timeZone = 'America/Chicago';
     $user1->username = '******';
     $user1->currency = $currencies[0];
     $user1->manager = $users[0];
     //Custom attribute
     $attributeForm = new TextAttributeForm();
     $attributeForm->attributeName = 'custom';
     $attributeForm->attributeLabels = array('en' => 'test label en');
     $modelAttributesAdapterClassName = $attributeForm::getModelAttributeAdapterNameForSavingAttributeFormData();
     $adapter = new $modelAttributesAdapterClassName(new EmailTemplateModelTestItem());
     $adapter->setAttributeMetadataFromForm($attributeForm);
     //ManyMany
     $manyModel = new EmailTemplateModelTestItem2();
     $manyModel->name = 'manyOriginalName';
     $model = new EmailTemplateModelTestItem();
     $model->string = 'abc';
     $model->firstName = 'James';
     $model->lastName = 'Jackson';
     $model->phone = 1122334455;
     $model->boolean = true;
     $model->date = '2008-12-31';
     $model->dateTime = '2008-12-31 07:48:04';
     $model->textArea = 'Multiple Lines\\nOf Text';
     $model->url = 'http://www.zurmo.com/';
     $model->integer = 999;
     $model->float = 999.999;
     $model->currencyValue = $currencyValue1;
     $model->dropDown->value = "DropdownSelectedValue";
     $model->radioDropDown->value = "RadioDropdownSelectedValue";
     $model->primaryEmail = $primaryEmail1;
     $model->secondaryEmail = $secondaryEmail1;
     $model->primaryAddress = $address1;
     $model->likeContactState = $likeContactState1;
     $model->user = $user1;
     $model->multiDropDown->data = $multiDropDownCustomFieldData1;
     $model->tagCloud->data = $tagCustomFieldData1;
     $model->multiDropDown->values->add($multiDropDownCustomFieldValue1);
     $model->multiDropDown->values->add($multiDropDownCustomFieldValue2);
     $model->multiDropDown->values->add($multiDropDownCustomFieldValue3);
     $model->tagCloud->values->add($tagCustomFieldValue1);
     $model->tagCloud->values->add($tagCustomFieldValue2);
     $model->customCstm = 'text custom';
     $model->hasMany->add($manyModel);
     $saved = $model->save();
     assert('$saved');
     // Not Coding Standard
     self::$emailTemplate = $model;
     // Update all values but do not save the model.
     $multiDropDownCustomFieldData2 = new CustomFieldData();
     $multiDropDownCustomFieldData2->name = 'multiDropDown2';
     $multiDropDownCustomFieldData2->serializedData = serialize(array('Thirteen', 14, 'XV'));
     $saved = $multiDropDownCustomFieldData2->save();
     assert('$saved');
     // Not Coding Standard
     $multiDropDownCustomFieldValue4 = new CustomFieldValue();
     $multiDropDownCustomFieldValue4->value = 'Thirteen';
     $multiDropDownCustomFieldValue5 = new CustomFieldValue();
     $multiDropDownCustomFieldValue5->value = 14;
     $multiDropDownCustomFieldValue6 = new CustomFieldValue();
     $multiDropDownCustomFieldValue6->value = 'XV';
     $tagCustomFieldData2 = new CustomFieldData();
     $tagCustomFieldData2->name = 'tagCloud2';
     $tagCustomFieldData2->serializedData = serialize(array('Nginx', 'Python'));
     $saved = $tagCustomFieldData2->save();
     assert('$saved');
     // Not Coding Standard
     $tagCustomFieldValue3 = new CustomFieldValue();
     $tagCustomFieldValue3->value = 'Python';
     $tagCustomFieldValue4 = new CustomFieldValue();
     $tagCustomFieldValue4->value = 'Nginx';
     $manyModel->name = 'manyChangedName';
     $manyModel2 = new EmailTemplateModelTestItem2();
     $manyModel2->name = 'newOriginalName';
     self::$emailTemplate->hasMany->add($manyModel2);
     static::$emailTemplateUserHash = StringUtil::generateRandomString(60);
     self::$emailTemplate->string = 'def';
     self::$emailTemplate->firstName = 'Jane';
     self::$emailTemplate->lastName = 'Bond';
     self::$emailTemplate->phone = 66778899;
     self::$emailTemplate->boolean = false;
     self::$emailTemplate->date = '2009-12-31';
     self::$emailTemplate->dateTime = '2009-12-31 07:48:04';
     self::$emailTemplate->textArea = 'Multiple Lines\\nOf\\nText';
     self::$emailTemplate->url = 'http://www.zurmo.org/';
     self::$emailTemplate->integer = 888;
     self::$emailTemplate->float = 888.888;
     self::$emailTemplate->currencyValue->value = 99;
     self::$emailTemplate->dropDown->value = "DropdownSelectedVal";
     self::$emailTemplate->radioDropDown->value = "RadioDropdownSelectedVal";
     self::$emailTemplate->primaryEmail->emailAddress = "*****@*****.**";
     self::$emailTemplate->primaryEmail->isInvalid = false;
     self::$emailTemplate->primaryEmail->optOut = true;
     self::$emailTemplate->secondaryEmail->emailAddress = "*****@*****.**";
     self::$emailTemplate->secondaryEmail->isInvalid = true;
     self::$emailTemplate->secondaryEmail->optOut = false;
     self::$emailTemplate->primaryAddress->street1 = "SomeOtherStreet1";
     self::$emailTemplate->primaryAddress->street2 = "SomeOtherStreet2";
     self::$emailTemplate->primaryAddress->city = "SomeOtherCity";
     self::$emailTemplate->primaryAddress->state = "SomeOtherState";
     self::$emailTemplate->primaryAddress->postalCode = 2222;
     self::$emailTemplate->primaryAddress->country = "SomeOtherCountry";
     self::$emailTemplate->likeContactState->name = 'New';
     self::$emailTemplate->likeContactState->order = 1;
     self::$emailTemplate->user->lastName = 'Dean';
     self::$emailTemplate->user->hash = static::$emailTemplateUserHash;
     self::$emailTemplate->user->language = 'en';
     self::$emailTemplate->user->timeZone = 'America/Denver';
     self::$emailTemplate->user->username = '******';
     self::$emailTemplate->multiDropDown->data = $multiDropDownCustomFieldData2;
     self::$emailTemplate->multiDropDown->values->remove($multiDropDownCustomFieldValue1);
     self::$emailTemplate->multiDropDown->values->remove($multiDropDownCustomFieldValue2);
     self::$emailTemplate->multiDropDown->values->remove($multiDropDownCustomFieldValue3);
     self::$emailTemplate->multiDropDown->values->add($multiDropDownCustomFieldValue4);
     self::$emailTemplate->multiDropDown->values->add($multiDropDownCustomFieldValue5);
     self::$emailTemplate->multiDropDown->values->add($multiDropDownCustomFieldValue6);
     self::$emailTemplate->tagCloud->data = $tagCustomFieldData2;
     self::$emailTemplate->tagCloud->values->remove($tagCustomFieldValue1);
     self::$emailTemplate->tagCloud->values->remove($tagCustomFieldValue2);
     self::$emailTemplate->tagCloud->values->add($tagCustomFieldValue3);
     self::$emailTemplate->tagCloud->values->add($tagCustomFieldValue4);
     self::$emailTemplate->customCstm = 'text custom changed';
     self::$content = 'Current: [[STRING]] [[FIRST^NAME]] [[LAST^NAME]] ' . '[[PHONE]] Old: [[WAS%STRING]] [[WAS%FIRST^NAME]] ' . '[[WAS%LAST^NAME]] [[WAS%PHONE]]';
     self::$compareContent = 'Current: def Jane Bond 66778899 Old: abc James ' . 'Jackson 1122334455';
     self::$contact = ContactTestHelper::createContactByNameForOwner('Jason', self::$super);
 }
 public static function setUpBeforeClass()
 {
     parent::setUpBeforeClass();
     SecurityTestHelper::createSuperAdmin();
     SecurityTestHelper::createUsers();
     self::$super = User::getByUsername('super');
     Yii::app()->user->userModel = self::$super;
     $loaded = ContactsModule::loadStartingData();
     if (!$loaded) {
         throw new NotSupportedException();
     }
     $emailSignature = new EmailSignature();
     $emailSignature->htmlContent = 'my email signature';
     self::$super->emailSignatures->add($emailSignature);
     self::$super->save();
     $currencies = Currency::getAll();
     $currencyValue = new CurrencyValue();
     $currencyValue->value = 100;
     $currencyValue->currency = $currencies[0];
     $multiDropDownCustomFieldData = new CustomFieldData();
     $multiDropDownCustomFieldData->name = 'multiDropDown';
     $multiDropDownCustomFieldData->serializedData = serialize(array('Ten', 11, 'XII'));
     $saved = $multiDropDownCustomFieldData->save();
     assert('$saved');
     // Not Coding Standard
     $multiDropDownCustomFieldValue1 = new CustomFieldValue();
     $multiDropDownCustomFieldValue1->value = 'Ten';
     $multiDropDownCustomFieldValue2 = new CustomFieldValue();
     $multiDropDownCustomFieldValue2->value = 11;
     $multiDropDownCustomFieldValue3 = new CustomFieldValue();
     $multiDropDownCustomFieldValue3->value = 'XII';
     $tagCustomFieldData = new CustomFieldData();
     $tagCustomFieldData->name = 'tagCloud';
     $tagCustomFieldData->serializedData = serialize(array('Apache', 'PHP'));
     $saved = $tagCustomFieldData->save();
     assert('$saved');
     // Not Coding Standard
     $tagCustomFieldValue1 = new CustomFieldValue();
     $tagCustomFieldValue1->value = 'PHP';
     $tagCustomFieldValue2 = new CustomFieldValue();
     $tagCustomFieldValue2->value = 'Apache';
     $primaryEmail = new Email();
     $primaryEmail->emailAddress = "*****@*****.**";
     $primaryEmail->isInvalid = true;
     $primaryEmail->optOut = false;
     $secondaryEmail = new Email();
     $secondaryEmail->emailAddress = "*****@*****.**";
     $secondaryEmail->isInvalid = false;
     $secondaryEmail->optOut = true;
     $address = new Address();
     $address->street1 = "SomeStreet1";
     $address->street2 = "SomeStreet2";
     $address->city = "SomeCity";
     $address->state = "SomeState";
     $address->postalCode = 1111;
     $address->country = "SomeCountry";
     $likeContactState = new ContactState();
     $likeContactState->name = 'Customer';
     $likeContactState->order = 0;
     static::$hash = StringUtil::generateRandomString(60);
     $users = User::getAll();
     $user = new User();
     $user->lastName = 'Kevin';
     $user->hash = static::$hash;
     $user->language = 'es';
     $user->timeZone = 'America/Chicago';
     $user->username = '******';
     $user->currency = $currencies[0];
     $user->manager = $users[0];
     //Custom attribute
     $attributeForm = new TextAttributeForm();
     $attributeForm->attributeName = 'custom';
     $attributeForm->attributeLabels = array('en' => 'test label en');
     $modelAttributesAdapterClassName = $attributeForm::getModelAttributeAdapterNameForSavingAttributeFormData();
     $adapter = new $modelAttributesAdapterClassName(new EmailTemplateModelTestItem());
     $adapter->setAttributeMetadataFromForm($attributeForm);
     //Custom attribute with underscore and number
     $attributeForm = new TextAttributeForm();
     $attributeForm->attributeName = 'custom_attr_2';
     $attributeForm->attributeLabels = array('en' => 'custom test label en');
     $modelAttributesAdapterClassName = $attributeForm::getModelAttributeAdapterNameForSavingAttributeFormData();
     $adapter = new $modelAttributesAdapterClassName(new EmailTemplateModelTestItem());
     $adapter->setAttributeMetadataFromForm($attributeForm);
     $model = new EmailTemplateModelTestItem();
     $model->string = 'We will add a $100 discount to this deal';
     $model->firstName = 'James';
     $model->lastName = 'Jackson';
     $model->phone = 1122334455;
     $model->boolean = true;
     $model->date = '2008-12-31';
     $model->dateTime = '2008-12-31 07:48:04';
     $model->textArea = 'Multiple Lines\\nOf Text';
     $model->url = 'http://www.zurmo.com/';
     $model->integer = 999;
     $model->float = 999.999;
     $model->currencyValue = $currencyValue;
     $model->dropDown->value = "DropdownSelectedValue";
     $model->radioDropDown->value = "RadioDropdownSelectedValue";
     $model->primaryEmail = $primaryEmail;
     $model->secondaryEmail = $secondaryEmail;
     $model->primaryAddress = $address;
     $model->likeContactState = $likeContactState;
     $model->user = $user;
     $model->multiDropDown->data = $multiDropDownCustomFieldData;
     $model->tagCloud->data = $tagCustomFieldData;
     $model->multiDropDown->values->add($multiDropDownCustomFieldValue1);
     $model->multiDropDown->values->add($multiDropDownCustomFieldValue2);
     $model->multiDropDown->values->add($multiDropDownCustomFieldValue3);
     $model->tagCloud->values->add($tagCustomFieldValue1);
     $model->tagCloud->values->add($tagCustomFieldValue2);
     $model->customCstm = 'text custom';
     $model->custom_attr_2Cstm = 'text custom 2';
     $saved = $model->save();
     assert('$saved');
     // Not Coding Standard
     self::$emailTemplate = $model;
     self::$content = '[[STRING]] [[FIRST^NAME]] [[LAST^NAME]] [[PHONE]]';
     self::$compareContent = 'We will add a $100 discount to this deal' . ' James Jackson 1122334455';
     self::$account = AccountTestHelper::createAccountByNameForOwner('Account1', self::$super);
     self::$account->billingAddress = new Address();
     self::$account->billingAddress->street1 = 'AccountStreet1';
     $saved = self::$account->save();
     if (!$saved) {
         throw new FailedToSaveModelException();
     }
     self::$contact = ContactTestHelper::createContactWithAccountByNameForOwner('Jason', self::$super, self::$account);
     self::$lead = LeadTestHelper::createLeadByNameForOwner('Laura', self::$super);
 }
 public function testCloneSetsRightPermissions()
 {
     // create users and groups.
     $everyoneGroup = Group::getByName(Group::EVERYONE_GROUP_NAME);
     $everyoneGroup->setRight('ReportsModule', ReportsModule::getAccessRight());
     $everyoneGroup->setRight('AccountsModule', AccountsModule::RIGHT_ACCESS_ACCOUNTS);
     $this->assertTrue($everyoneGroup->save());
     $everyoneGroup->forgetAll();
     $jim = UserTestHelper::createBasicUser('jim');
     $john = UserTestHelper::createBasicUser('john');
     $johnGroup = new Group();
     $johnGroup->name = 'John Group';
     $johnGroup->users->add($john);
     $this->assertTrue($johnGroup->save());
     $john->forgetAll();
     $johnGroup->forgetAll();
     $john = User::getByUsername('john');
     $johnGroup = Group::getByName('John Group');
     $basePostData = static::makeRowsAndColumnsReportPostDataForAccounts();
     $basePostData['save'] = 'save';
     $description = StringUtil::generateRandomString(40);
     // create a report with everyone group permission, ensure everyone can access it.
     // clone it, ensure everyone group can still access it.
     $super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super');
     SavedReport::deleteAll();
     $modelSpecificPostData = array('RowsAndColumnsReportWizardForm' => array('name' => 'Everyone Report 01', 'description' => $description, 'ownerId' => $super->id, 'ownerName' => strval($super), 'explicitReadWriteModelPermissions' => array('type' => ExplicitReadWriteModelPermissionsUtil::MIXED_TYPE_EVERYONE_GROUP, 'nonEveryoneGroup' => null)));
     $postData = CMap::mergeArray($basePostData, $modelSpecificPostData);
     $this->setGetArray(array('type' => 'RowsAndColumns'));
     $this->setPostArray($postData);
     $this->runControllerWithExitExceptionAndGetContent('/reports/default/save');
     ForgetAllCacheUtil::forgetAllCaches();
     $savedReports = SavedReport::getAll();
     $this->assertCount(1, $savedReports);
     $this->assertEquals(Permission::ALL, $savedReports[0]->getEffectivePermissions($super));
     $this->assertEquals(Permission::READ_WRITE_CHANGE_PERMISSIONS_CHANGE_OWNER, $savedReports[0]->getEffectivePermissions($everyoneGroup));
     $this->assertEquals(Permission::READ_WRITE_CHANGE_PERMISSIONS_CHANGE_OWNER, $savedReports[0]->getEffectivePermissions($jim));
     // ensure jim can access it.
     $this->logoutCurrentUserLoginNewUserAndGetByUsername('jim');
     $this->resetPostArray();
     $this->resetGetArray();
     $content = $this->runControllerWithNoExceptionsAndGetContent('/reports/default/list');
     $this->assertContains($postData['RowsAndColumnsReportWizardForm']['name'], $content);
     $this->assertEquals(substr_count($content, $postData['RowsAndColumnsReportWizardForm']['name']), 1);
     $this->setGetArray(array('id' => $savedReports[0]->id));
     $content = $this->runControllerWithNoExceptionsAndGetContent('/reports/default/details');
     $this->assertContains($postData['RowsAndColumnsReportWizardForm']['name'], $content);
     $this->assertEquals(substr_count($content, $postData['RowsAndColumnsReportWizardForm']['name']), 3);
     // clone the report.
     $this->logoutCurrentUserLoginNewUserAndGetByUsername('super');
     $this->setGetArray(array('type' => 'RowsAndColumns', 'id' => $savedReports[0]->id, 'isBeingCopied' => '1'));
     $postData['RowsAndColumnsReportWizardForm']['name'] = 'Cloned ' . $postData['RowsAndColumnsReportWizardForm']['name'];
     $this->setPostArray($postData);
     $this->runControllerWithExitExceptionAndGetContent('/reports/default/save');
     ForgetAllCacheUtil::forgetAllCaches();
     $savedReports = SavedReport::getAll();
     $this->assertCount(2, $savedReports);
     $sourcePermissions = ExplicitReadWriteModelPermissionsUtil::makeBySecurableItem($savedReports[0]);
     $clonePermissions = ExplicitReadWriteModelPermissionsUtil::makeBySecurableItem($savedReports[1]);
     $this->assertEquals($sourcePermissions, $clonePermissions);
     $this->assertEquals(Permission::ALL, $savedReports[1]->getEffectivePermissions($super));
     $this->assertEquals(Permission::READ_WRITE_CHANGE_PERMISSIONS_CHANGE_OWNER, $savedReports[1]->getEffectivePermissions($everyoneGroup));
     $this->assertEquals(Permission::READ_WRITE_CHANGE_PERMISSIONS_CHANGE_OWNER, $savedReports[1]->getEffectivePermissions($jim));
     // ensure jim can access it.
     $this->logoutCurrentUserLoginNewUserAndGetByUsername('jim');
     $this->resetPostArray();
     $this->resetGetArray();
     $content = $this->runControllerWithNoExceptionsAndGetContent('/reports/default/list');
     $this->assertContains($postData['RowsAndColumnsReportWizardForm']['name'], $content);
     $this->assertEquals(substr_count($content, $postData['RowsAndColumnsReportWizardForm']['name']), 1);
     $this->setGetArray(array('id' => $savedReports[1]->id));
     $content = $this->runControllerWithNoExceptionsAndGetContent('/reports/default/details');
     $this->assertContains($postData['RowsAndColumnsReportWizardForm']['name'], $content);
     $this->assertEquals(substr_count($content, $postData['RowsAndColumnsReportWizardForm']['name']), 3);
     // create a report with specific group permissions, ensure only members of that group can access it.
     // clone it, ensure only that specific group members can access it.
     $super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super');
     SavedReport::deleteAll();
     $modelSpecificPostData = array('RowsAndColumnsReportWizardForm' => array('name' => 'Group Specific Report 01', 'description' => $description, 'ownerId' => $super->id, 'ownerName' => strval($super), 'explicitReadWriteModelPermissions' => array('type' => ExplicitReadWriteModelPermissionsUtil::MIXED_TYPE_NONEVERYONE_GROUP, 'nonEveryoneGroup' => $johnGroup->id)));
     $postData = CMap::mergeArray($basePostData, $modelSpecificPostData);
     $this->setGetArray(array('type' => 'RowsAndColumns'));
     $this->setPostArray($postData);
     $this->runControllerWithExitExceptionAndGetContent('/reports/default/save');
     ForgetAllCacheUtil::forgetAllCaches();
     $savedReports = SavedReport::getAll();
     $this->assertCount(1, $savedReports);
     $this->assertEquals(Permission::ALL, $savedReports[0]->getEffectivePermissions($super));
     $this->assertEquals(Permission::NONE, $savedReports[0]->getEffectivePermissions($everyoneGroup));
     $this->assertEquals(Permission::NONE, $savedReports[0]->getEffectivePermissions($jim));
     $this->assertEquals(Permission::READ_WRITE_CHANGE_PERMISSIONS_CHANGE_OWNER, $savedReports[0]->getEffectivePermissions($johnGroup));
     $this->assertEquals(Permission::READ_WRITE_CHANGE_PERMISSIONS_CHANGE_OWNER, $savedReports[0]->getEffectivePermissions($john));
     // ensure john can access it.
     $this->logoutCurrentUserLoginNewUserAndGetByUsername('john');
     $this->resetPostArray();
     $this->resetGetArray();
     $content = $this->runControllerWithNoExceptionsAndGetContent('/reports/default/list');
     $this->assertContains($postData['RowsAndColumnsReportWizardForm']['name'], $content);
     $this->assertEquals(substr_count($content, $postData['RowsAndColumnsReportWizardForm']['name']), 1);
     $this->setGetArray(array('id' => $savedReports[0]->id));
     $content = $this->runControllerWithNoExceptionsAndGetContent('/reports/default/details');
     $this->assertContains($postData['RowsAndColumnsReportWizardForm']['name'], $content);
     $this->assertEquals(substr_count($content, $postData['RowsAndColumnsReportWizardForm']['name']), 3);
     // ensure jim can not access it.
     $this->logoutCurrentUserLoginNewUserAndGetByUsername('jim');
     $this->resetGetArray();
     $content = $this->runControllerWithNoExceptionsAndGetContent('/reports/default/list');
     $this->assertNotContains($postData['RowsAndColumnsReportWizardForm']['name'], $content);
     $this->setGetArray(array('id' => $savedReports[0]->id));
     $this->runControllerWithAccessDeniedSecurityExceptionAndGetContent('/reports/default/details');
     // clone the report.
     $this->logoutCurrentUserLoginNewUserAndGetByUsername('super');
     $this->setGetArray(array('type' => 'RowsAndColumns', 'id' => $savedReports[0]->id, 'isBeingCopied' => '1'));
     $postData['RowsAndColumnsReportWizardForm']['name'] = 'Cloned ' . $postData['RowsAndColumnsReportWizardForm']['name'];
     $this->setPostArray($postData);
     $this->runControllerWithExitExceptionAndGetContent('/reports/default/save');
     ForgetAllCacheUtil::forgetAllCaches();
     $savedReports = SavedReport::getAll();
     $this->assertCount(2, $savedReports);
     $sourcePermissions = ExplicitReadWriteModelPermissionsUtil::makeBySecurableItem($savedReports[0]);
     $clonePermissions = ExplicitReadWriteModelPermissionsUtil::makeBySecurableItem($savedReports[1]);
     $this->assertEquals($sourcePermissions, $clonePermissions);
     $this->assertEquals(Permission::ALL, $savedReports[1]->getEffectivePermissions($super));
     $this->assertEquals(Permission::NONE, $savedReports[1]->getEffectivePermissions($everyoneGroup));
     $this->assertEquals(Permission::NONE, $savedReports[1]->getEffectivePermissions($jim));
     $this->assertEquals(Permission::READ_WRITE_CHANGE_PERMISSIONS_CHANGE_OWNER, $savedReports[1]->getEffectivePermissions($johnGroup));
     $this->assertEquals(Permission::READ_WRITE_CHANGE_PERMISSIONS_CHANGE_OWNER, $savedReports[1]->getEffectivePermissions($john));
     // ensure john can access it.
     $this->logoutCurrentUserLoginNewUserAndGetByUsername('john');
     $this->resetPostArray();
     $this->resetGetArray();
     $content = $this->runControllerWithNoExceptionsAndGetContent('/reports/default/list');
     $this->assertContains($postData['RowsAndColumnsReportWizardForm']['name'], $content);
     $this->assertEquals(substr_count($content, $postData['RowsAndColumnsReportWizardForm']['name']), 1);
     $this->setGetArray(array('id' => $savedReports[1]->id));
     $content = $this->runControllerWithNoExceptionsAndGetContent('/reports/default/details');
     $this->assertContains($postData['RowsAndColumnsReportWizardForm']['name'], $content);
     $this->assertEquals(substr_count($content, $postData['RowsAndColumnsReportWizardForm']['name']), 3);
     // ensure jim can not access it.
     $this->logoutCurrentUserLoginNewUserAndGetByUsername('jim');
     $this->resetGetArray();
     $content = $this->runControllerWithNoExceptionsAndGetContent('/reports/default/list');
     $this->assertNotContains($postData['RowsAndColumnsReportWizardForm']['name'], $content);
     $this->setGetArray(array('id' => $savedReports[0]->id));
     $this->runControllerWithAccessDeniedSecurityExceptionAndGetContent('/reports/default/details');
 }