本文整理汇总了PHP中Account::getById方法的典型用法代码示例。如果您正苦于以下问题:PHP Account::getById方法的具体用法?PHP Account::getById怎么用?PHP Account::getById使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Account
的用法示例。
在下文中一共展示了Account::getById方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: updateTestAccountsWithBillingAddress
public static function updateTestAccountsWithBillingAddress($accountid, $address, $owner)
{
$account = Account::getById($accountid);
$account->owner = $owner;
foreach ($address as $key => $value) {
$account->billingAddress->{$key} = $value;
}
$account->save();
}
示例2: testSuperUserAllDefaultControllerActions
public function testSuperUserAllDefaultControllerActions()
{
$super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super');
$superAccountId = self::getModelIdByModelNameAndName('Account', 'superAccount');
$superAccountId2 = self::getModelIdByModelNameAndName('Account', 'superAccount2');
$superContactId = self::getModelIdByModelNameAndName('Contact', 'superContact superContactson');
$account = Account::getById($superAccountId);
$account2 = Account::getById($superAccountId2);
$contact = Contact::getById($superContactId);
//confirm no existing activities exist
$activities = Activity::getAll();
$this->assertEquals(0, count($activities));
//Test just going to the create from relation view.
$this->setGetArray(array('relationAttributeName' => 'Account', 'relationModelId' => $superAccountId, 'relationModuleId' => 'accounts', 'redirectUrl' => 'someRedirect'));
$this->runControllerWithNoExceptionsAndGetContent('tasks/default/modalCreateFromRelation');
//add related task for account using createFromRelation action
$activityItemPostData = array('Account' => array('id' => $superAccountId));
$this->setGetArray(array('relationAttributeName' => 'Account', 'relationModelId' => $superAccountId, 'relationModuleId' => 'accounts', 'redirectUrl' => 'someRedirect'));
$this->setPostArray(array('ActivityItemForm' => $activityItemPostData, 'Task' => array('name' => 'myTask')));
$this->runControllerWithNoExceptionsAndGetContent('tasks/default/modalSaveFromRelation');
//now test that the new task exists, and is related to the account.
$tasks = Task::getAll();
$this->assertEquals(1, count($tasks));
$this->assertEquals('myTask', $tasks[0]->name);
$this->assertEquals(1, $tasks[0]->activityItems->count());
$activityItem1 = $tasks[0]->activityItems->offsetGet(0);
$this->assertEquals($account, $activityItem1);
//test viewing the existing task in a details view
$this->setGetArray(array('id' => $tasks[0]->id));
$this->resetPostArray();
$this->runControllerWithNoExceptionsAndGetContent('tasks/default/modalDetails');
//test submitting the task on change
$this->setGetArray(array('id' => $tasks[0]->id));
$this->setPostArray(array('Task' => array('name' => 'myTask', 'status' => Task::STATUS_IN_PROGRESS)));
$this->runControllerWithNoExceptionsAndGetContent('tasks/default/modalDetails');
//Test just going to the copy from relation
$this->setGetArray(array('relationAttributeName' => 'Account', 'relationModelId' => $superAccountId, 'relationModuleId' => 'accounts', 'id' => $tasks[0]->id));
$this->runControllerWithNoExceptionsAndGetContent('tasks/default/modalCopyFromRelation');
$tasks = Task::getAll();
$this->assertEquals(2, count($tasks));
$this->assertEquals('myTask', $tasks[1]->name);
$this->assertEquals(1, $tasks[1]->activityItems->count());
//test removing a task.
$this->setGetArray(array('id' => $tasks[0]->id));
$this->resetPostArray();
$this->runControllerWithNoExceptionsAndGetContent('tasks/default/delete', true);
//Confirm no more tasks exist.
$tasks = Task::getAll();
$this->assertEquals(1, count($tasks));
}
示例3: testCopy
public function testCopy()
{
Yii::app()->user->userModel = User::getByUsername('super');
$user = Yii::app()->user->userModel;
$project = new Project();
$project->name = 'Project 1';
$project->owner = $user;
$project->description = 'Description';
$user = UserTestHelper::createBasicUser('Steven');
$account = new Account();
$account->owner = $user;
$account->name = DataUtil::purifyHtml("Tom & Jerry's Account");
$this->assertTrue($account->save());
$id = $account->id;
unset($account);
$account = Account::getById($id);
$this->assertEquals("Tom & Jerry's Account", $account->name);
$contact = ContactTestHelper::createContactByNameForOwner('Jerry', $user);
$opportunity = OpportunityTestHelper::createOpportunityByNameForOwner('Jerry Opp', $user);
$this->assertTrue($project->save());
$this->assertEquals(1, count($project->auditEvents));
$id = $project->id;
$project->forget();
unset($project);
$project = Project::getById($id);
ProjectZurmoControllerUtil::resolveProjectManyManyAccountsFromPost($project, array('accountIds' => $account->id));
ProjectZurmoControllerUtil::resolveProjectManyManyContactsFromPost($project, array('contactIds' => $contact->id));
ProjectZurmoControllerUtil::resolveProjectManyManyOpportunitiesFromPost($project, array('opportunityIds' => $opportunity->id));
$this->assertEquals('Project 1', $project->name);
$this->assertEquals('Description', $project->description);
$this->assertEquals(1, $project->accounts->count());
$this->assertEquals(1, $project->contacts->count());
$this->assertEquals(1, $project->opportunities->count());
$task = TaskTestHelper::createTaskByNameWithProjectAndStatus('MyFirstKanbanTask', Yii::app()->user->userModel, $project, Task::STATUS_IN_PROGRESS);
$kanbanItem1 = KanbanItem::getByTask($task->id);
$this->assertEquals(KanbanItem::TYPE_IN_PROGRESS, $kanbanItem1->type);
$this->assertEquals($task->project->id, $kanbanItem1->kanbanRelatedItem->id);
$copyToProject = new Project();
ProjectZurmoCopyModelUtil::copy($project, $copyToProject);
ProjectZurmoCopyModelUtil::processAfterCopy($project, $copyToProject);
$this->assertTrue($copyToProject->save());
$this->assertEquals($copyToProject->name, $project->name);
$this->assertEquals($copyToProject->description, $project->description);
$this->assertEquals($copyToProject->status, $project->status);
$project = Project::getByName('Project 1');
$this->assertEquals(2, count($project));
$tasks = Task::getAll();
$this->assertEquals(2, count($tasks));
}
示例4: testCreateAndGetProjectById
public function testCreateAndGetProjectById()
{
Yii::app()->user->userModel = User::getByUsername('super');
$user = Yii::app()->user->userModel;
$project = new Project();
$project->name = 'Project 1';
$project->owner = $user;
$project->description = 'Description';
$user = UserTestHelper::createBasicUser('Steven');
$account = new Account();
$account->owner = $user;
$account->name = DataUtil::purifyHtml("Tom & Jerry's Account");
$this->assertTrue($account->save());
$id = $account->id;
unset($account);
$account = Account::getById($id);
$this->assertEquals("Tom & Jerry's Account", $account->name);
//$project->accounts->add($account);
$contact = ContactTestHelper::createContactByNameForOwner('Jerry', $user);
//$project->contacts->add($contact);
$opportunity = OpportunityTestHelper::createOpportunityByNameForOwner('Jerry Opp', $user);
//$project->opportunities->add($opportunity);
$this->assertTrue($project->save());
$this->assertEquals(1, count($project->auditEvents));
$id = $project->id;
$project->forget();
unset($project);
$project = Project::getById($id);
ProjectZurmoControllerUtil::resolveProjectManyManyAccountsFromPost($project, array('accountIds' => $account->id));
ProjectZurmoControllerUtil::resolveProjectManyManyContactsFromPost($project, array('contactIds' => $contact->id));
ProjectZurmoControllerUtil::resolveProjectManyManyOpportunitiesFromPost($project, array('opportunityIds' => $opportunity->id));
$this->assertEquals('Project 1', $project->name);
$this->assertEquals('Description', $project->description);
$this->assertEquals(1, $project->accounts->count());
$this->assertEquals(1, $project->contacts->count());
$this->assertEquals(1, $project->opportunities->count());
//Try saving a second project
$project = new Project();
$project->name = 'Project 2';
$project->owner = $user;
$project->description = 'Description';
$this->assertTrue($project->save());
$this->assertEquals(1, count($project->auditEvents));
}
示例5: resolveProjectManyManyAccountsFromPost
/**
* Resolves the accounts sent via post request
* @param Project $project
* @param array $postData
* @return array containing accounts
*/
public static function resolveProjectManyManyAccountsFromPost(Project $project, $postData)
{
assert('$project instanceof Project');
$newAccount = array();
if (isset($postData['accountIds']) && strlen($postData['accountIds']) > 0) {
$accountIds = explode(",", $postData['accountIds']);
// Not Coding Standard
foreach ($accountIds as $accountId) {
$newAccount[$accountId] = Account::getById((int) $accountId);
}
if ($project->accounts->count() > 0) {
$project->accounts->removeAll();
}
//Now add missing accounts
foreach ($newAccount as $account) {
$project->accounts->add($account);
}
} else {
//remove all accounts
$project->accounts->removeAll();
}
return $newAccount;
}
示例6: testWebsiteCanBeSavedWithoutUrlScheme
/**
* @depends testCreatingACustomDropDownAfterAnAccountExists
*/
public function testWebsiteCanBeSavedWithoutUrlScheme()
{
$user = User::getByUsername('steven');
$account = new Account();
$account->owner = $user;
$account->name = 'AccountForURLSchemeTest';
$account->website = 'www.zurmo.com';
$this->assertTrue($account->save());
$id = $account->id;
unset($account);
$account = Account::getById($id);
$this->assertEquals('AccountForURLSchemeTest', $account->name);
$this->assertEquals('http://www.zurmo.com', $account->website);
$account->setAttributes(array('website' => 'https://www.zurmo.com'));
$this->assertTrue($account->save());
$account->forget();
$account = Account::getById($id);
$this->assertEquals('https://www.zurmo.com', $account->website);
}
示例7: testResolveElementForNonEditableRender
/**
* @depends testResolveElementForEditableRender
*/
public function testResolveElementForNonEditableRender()
{
$betty = User::getByUsername('betty');
$billy = User::getByUsername('billy');
$contactForBetty = ContactTestHelper::createContactByNameForOwner("betty's contact2", $betty);
$contactForBetty->account = AccountTestHelper::createAccountByNameForOwner('BillyCompany', $billy);
$this->assertTrue($contactForBetty->save());
$accountId = $contactForBetty->account->id;
$nullElementInformation = array('attributeName' => null, 'type' => 'Null');
//test non ModelElement, should pass through without modification.
$elementInformation = array('attributeName' => 'something', 'type' => 'Text');
$referenceElementInformation = $elementInformation;
FormLayoutSecurityUtil::resolveElementForNonEditableRender($contactForBetty, $referenceElementInformation, $betty);
$this->assertEquals($elementInformation, $referenceElementInformation);
//test Acc ModelElement
//Betty will see a nullified Element because Betty cannot access read the related account
$elementInformation = array('attributeName' => 'account', 'type' => 'Account');
$noLinkElementInformation = array('attributeName' => 'account', 'type' => 'Account', 'noLink' => true);
$referenceElementInformation = $elementInformation;
FormLayoutSecurityUtil::resolveElementForNonEditableRender($contactForBetty, $referenceElementInformation, $betty);
$this->assertEquals($nullElementInformation, $referenceElementInformation);
$this->assertEquals(Right::ALLOW, $betty->getEffectiveRight('AccountsModule', AccountsModule::RIGHT_ACCESS_ACCOUNTS));
//Betty can see the account with a link, because she has been added for Permission::READ on the account.
//and she has access to the accounts tab.
$account = Account::getById($accountId);
$account->addPermissions($betty, Permission::READ);
$this->assertTrue($account->save());
$referenceElementInformation = $elementInformation;
FormLayoutSecurityUtil::resolveElementForNonEditableRender($contactForBetty, $referenceElementInformation, $betty);
$this->assertEquals($elementInformation, $referenceElementInformation);
//Removing Betty's access to the accounts tab means she will see the element, but without a link
$betty->setRight('AccountsModule', AccountsModule::RIGHT_ACCESS_ACCOUNTS, Right::DENY);
$this->assertTrue($betty->save());
$referenceElementInformation = $elementInformation;
FormLayoutSecurityUtil::resolveElementForNonEditableRender($contactForBetty, $referenceElementInformation, $betty);
$this->assertEquals($noLinkElementInformation, $referenceElementInformation);
//Testing UserElement
$elementInformation = array('attributeName' => 'owner', 'type' => 'User');
$noLinkElementInformation = array('attributeName' => 'owner', 'type' => 'User', 'noLink' => true);
//Super can see related user picker link without a problem.
$referenceElementInformation = $elementInformation;
FormLayoutSecurityUtil::resolveElementForNonEditableRender($contactForBetty, $referenceElementInformation, User::getByUsername('super'));
$this->assertEquals($elementInformation, $referenceElementInformation);
//Betty can also see related user name, but not a link.
$referenceElementInformation = $elementInformation;
$this->assertEquals(Right::DENY, $betty->getEffectiveRight('UsersModule', UsersModule::RIGHT_ACCESS_USERS));
FormLayoutSecurityUtil::resolveElementForNonEditableRender($contactForBetty, $referenceElementInformation, $betty);
$this->assertEquals($noLinkElementInformation, $referenceElementInformation);
}
示例8: testRegularUserChangingOwnershipToEveryoneOnNonCreatedAccount
/**
* Testing when a user who is not a super user, has a model owned by themselves but not created by themselves.
* Then that user tries to change the owner to someone else and at the same time change the read/write from
* owner only to everyone.
*/
public function testRegularUserChangingOwnershipToEveryoneOnNonCreatedAccount()
{
$super = User::getByUsername('super');
Yii::app()->user->userModel = $super;
$nobody = User::getByUsername('nobody');
$account = AccountTestHelper::createAccountByNameForOwner('superAccountReadableByNobody', $nobody);
$nobody = $this->logoutCurrentUserLoginNewUserAndGetByUsername('nobody');
//First set the read/write as owner only.
$this->setGetArray(array('id' => $account->id));
$postData = array('type' => '');
$this->setPostArray(array('Account' => array('owner' => array('id' => $nobody->id), 'explicitReadWriteModelPermissions' => $postData)));
//Make sure the redirect is to the details view and not the list view.
$this->runControllerWithRedirectExceptionAndGetContent('accounts/default/edit');
// Not Coding Standard
$accountId = $account->id;
$account->forget();
$account = Account::getById($accountId);
$this->setGetArray(array('id' => $account->id));
$postData = array('type' => ExplicitReadWriteModelPermissionsUtil::MIXED_TYPE_EVERYONE_GROUP);
$this->setPostArray(array('Account' => array('owner' => array('id' => $super->id), 'explicitReadWriteModelPermissions' => $postData)));
//Make sure the redirect is to the details view and not the list view.
$this->runControllerWithRedirectExceptionAndGetContent('accounts/default/edit');
// Not Coding Standard
//Make sure user can still go to details view
$this->setGetArray(array('id' => $account->id));
$this->resetPostArray();
$content = $this->runControllerWithNoExceptionsAndGetContent('accounts/default/details');
}
示例9: testABitOfEverythingAsAnExample
//.........这里部分代码省略.........
$this->assertEquals(Permission::READ, $account->getEffectivePermissions($adminDudes));
$this->assertEquals(Permission::ALL, $account->getEffectivePermissions($accountOwner));
$this->assertEquals(Permission::READ_WRITE, $account->getEffectivePermissions($salesDude1));
$this->assertEquals(Permission::READ_WRITE, $account->getEffectivePermissions($salesDude2));
$this->assertEquals(Permission::NONE, $account->getEffectivePermissions($managementDudette));
$this->assertEquals(Permission::READ_WRITE, $account->getEffectivePermissions($salesDudes));
$this->assertEquals(Permission::NONE, $account->getEffectivePermissions($managementDudes));
$this->assertEquals(Permission::NONE, $account->getEffectivePermissions($supportDude));
$this->assertEquals(Permission::READ, $account->getEffectivePermissions($everyone));
// We'll give Management Dudes back their permissions.
$account->removePermissions($managementDudes, Permission::ALL, Permission::DENY);
// And give management dudette change permissions.
$account->addPermissions($managementDudette, Permission::CHANGE_PERMISSIONS);
$account->save();
$this->assertEquals(Permission::READ, $account->getEffectivePermissions($adminDude));
$this->assertEquals(Permission::READ, $account->getEffectivePermissions($adminDudes));
$this->assertEquals(Permission::ALL, $account->getEffectivePermissions($accountOwner));
$this->assertEquals(Permission::READ_WRITE, $account->getEffectivePermissions($salesDude1));
$this->assertEquals(Permission::READ_WRITE, $account->getEffectivePermissions($salesDude2));
$this->assertEquals(Permission::READ | Permission::CHANGE_PERMISSIONS | Permission::CHANGE_OWNER, $account->getEffectivePermissions($managementDudette));
$this->assertEquals(Permission::READ_WRITE, $account->getEffectivePermissions($salesDudes));
$this->assertEquals(Permission::READ | Permission::CHANGE_OWNER, $account->getEffectivePermissions($managementDudes));
$this->assertEquals(Permission::NONE, $account->getEffectivePermissions($supportDude));
$this->assertEquals(Permission::READ, $account->getEffectivePermissions($everyone));
// Then we'll just nuke eveyone's permissions. If you use this it is for
// the kind of scenario where an admin wants to re-setup permissions from scratch
// so you'd put a Do You Really Want To Do This???? kind of message.
Permission::deleteAll();
// Removing all permissions is done directly on the database,
// so we need to forget our account and get it back again.
$accountId = $account->id;
$account->forget();
unset($account);
$account = Account::getById($accountId);
// Nobody else has permissions again.
$this->assertEquals(Permission::NONE, $account->getEffectivePermissions($adminDude));
$this->assertEquals(Permission::NONE, $account->getEffectivePermissions($adminDudes));
$this->assertEquals(Permission::NONE, $account->getEffectivePermissions($salesDude1));
$this->assertEquals(Permission::NONE, $account->getEffectivePermissions($salesDude2));
$this->assertEquals(Permission::NONE, $account->getEffectivePermissions($managementDudette));
$this->assertEquals(Permission::NONE, $account->getEffectivePermissions($salesDudes));
$this->assertEquals(Permission::NONE, $account->getEffectivePermissions($managementDudes));
$this->assertEquals(Permission::NONE, $account->getEffectivePermissions($supportDude));
// TODO
// - Permissions on modules.
// - Permissions on types.
// - Permissions on fields.
// All users have the right to login via the web, because the Everyone group was granted that right.
$this->assertEquals(Right::ALLOW, $adminDude->getEffectiveRight('UsersModule', UsersModule::RIGHT_LOGIN_VIA_WEB));
$this->assertEquals(Right::ALLOW, $adminDudes->getEffectiveRight('UsersModule', UsersModule::RIGHT_LOGIN_VIA_WEB));
$this->assertEquals(Right::ALLOW, $salesDude1->getEffectiveRight('UsersModule', UsersModule::RIGHT_LOGIN_VIA_WEB));
$this->assertEquals(Right::ALLOW, $salesDude2->getEffectiveRight('UsersModule', UsersModule::RIGHT_LOGIN_VIA_WEB));
$this->assertEquals(Right::ALLOW, $managementDudette->getEffectiveRight('UsersModule', UsersModule::RIGHT_LOGIN_VIA_WEB));
$this->assertEquals(Right::ALLOW, $salesDudes->getEffectiveRight('UsersModule', UsersModule::RIGHT_LOGIN_VIA_WEB));
$this->assertEquals(Right::ALLOW, $managementDudes->getEffectiveRight('UsersModule', UsersModule::RIGHT_LOGIN_VIA_WEB));
$this->assertEquals(Right::ALLOW, $supportDude->getEffectiveRight('UsersModule', UsersModule::RIGHT_LOGIN_VIA_WEB));
$this->assertEquals(Right::ALLOW, $everyone->getEffectiveRight('UsersModule', UsersModule::RIGHT_LOGIN_VIA_WEB));
$this->assertEquals(Right::ALLOW, $adminDude->getEffectiveRight('UsersModule', UsersModule::RIGHT_CHANGE_USER_PASSWORDS));
$this->assertEquals(Right::ALLOW, $adminDudes->getEffectiveRight('UsersModule', UsersModule::RIGHT_CHANGE_USER_PASSWORDS));
$this->assertEquals(Right::DENY, $salesDude1->getEffectiveRight('UsersModule', UsersModule::RIGHT_CHANGE_USER_PASSWORDS));
$this->assertEquals(Right::DENY, $salesDude2->getEffectiveRight('UsersModule', UsersModule::RIGHT_CHANGE_USER_PASSWORDS));
$this->assertEquals(Right::DENY, $managementDudette->getEffectiveRight('UsersModule', UsersModule::RIGHT_CHANGE_USER_PASSWORDS));
$this->assertEquals(Right::DENY, $salesDudes->getEffectiveRight('UsersModule', UsersModule::RIGHT_CHANGE_USER_PASSWORDS));
$this->assertEquals(Right::DENY, $managementDudes->getEffectiveRight('UsersModule', UsersModule::RIGHT_CHANGE_USER_PASSWORDS));
$this->assertEquals(Right::DENY, $supportDude->getEffectiveRight('UsersModule', UsersModule::RIGHT_CHANGE_USER_PASSWORDS));
$this->assertEquals(Right::DENY, $everyone->getEffectiveRight('UsersModule', UsersModule::RIGHT_CHANGE_USER_PASSWORDS));
示例10: testUpdateLatestActivityDateTimeWhenAnEmailIsSentOrArchived
public function testUpdateLatestActivityDateTimeWhenAnEmailIsSentOrArchived()
{
$emailMessage = EmailMessageTestHelper::createDraftSystemEmail('subject 1', Yii::app()->user->userModel);
$account3 = AccountTestHelper::createAccountByNameForOwner('account3', Yii::app()->user->userModel);
$account4 = AccountTestHelper::createAccountByNameForOwner('account4', Yii::app()->user->userModel);
$account5 = AccountTestHelper::createAccountByNameForOwner('account4', Yii::app()->user->userModel);
$dateTime = DateTimeUtil::convertTimestampToDbFormatDateTime(time());
$account5->setLatestActivityDateTime($dateTime);
$this->assertTrue($account5->save());
$account3Id = $account3->id;
$account4Id = $account4->id;
$account5Id = $account5->id;
$this->assertNull($account3->latestActivityDateTime);
$this->assertNull($account4->latestActivityDateTime);
$this->assertEquals($dateTime, $account5->latestActivityDateTime);
$emailMessage->sender->personsOrAccounts->add($account3);
$emailMessage->recipients[0]->personsOrAccounts->add($account4);
$emailMessage->recipients[0]->personsOrAccounts->add($account5);
$this->assertTrue($emailMessage->save());
$this->assertNull($account3->latestActivityDateTime);
$this->assertNull($account4->latestActivityDateTime);
$this->assertEquals($dateTime, $account5->latestActivityDateTime);
$emailMessageId = $emailMessage->id;
$emailMessage->forget();
$account3->forget();
$account4->forget();
$account5->forget();
//Retrieve email message and set sentDateTime, at this point the accounts should update with this value
$sentDateTime = DateTimeUtil::convertTimestampToDbFormatDateTime(time() - 86400);
$emailMessage = EmailMessage::getById($emailMessageId);
$emailMessage->sentDateTime = $sentDateTime;
$this->assertTrue($emailMessage->save());
$account3 = Account::getById($account3Id);
$account4 = Account::getById($account4Id);
$account5 = Account::getById($account5Id);
$this->assertEquals($sentDateTime, $account3->latestActivityDateTime);
$this->assertEquals($sentDateTime, $account4->latestActivityDateTime);
$this->assertEquals($dateTime, $account5->latestActivityDateTime);
}
开发者ID:RamaKavanan,项目名称:InitialVersion,代码行数:39,代码来源:AccountLatestActivityDateTimeDocumentationTest.php
示例11: testOnCreateOwnerChangeAndDeleteAccountModel
//.........这里部分代码省略.........
$this->assertNotEquals($rows[0]['modifieddatetime'], $rows2[0]['modifieddatetime']);
$this->assertEquals($billy->id, $rows2[1]['userid']);
$this->assertEquals($account1->id, $rows2[1]['modelid']);
$this->assertEquals(ReadPermissionsSubscriptionUtil::TYPE_DELETE, $rows2[1]['subscriptiontype']);
$this->assertNotEquals($rows[1]['modifieddatetime'], $rows2[1]['modifieddatetime']);
// Test owner change, but when both users have permissions to access the account
$sql = "DELETE FROM account_read_subscription";
ZurmoRedBean::exec($sql);
$sql = "SELECT * FROM account_read_subscription";
$rows = ZurmoRedBean::getAll($sql);
$this->assertTrue(empty($rows));
$account2 = AccountTestHelper::createAccountByNameForOwner('Second Account', $super);
sleep(1);
$queuedJobs = Yii::app()->jobQueue->getAll();
$this->assertEquals(1, count($queuedJobs[5]));
$this->assertEquals('ReadPermissionSubscriptionUpdateForAccountFromBuildTable', $queuedJobs[5][0]['jobType']);
Yii::app()->jobQueue->deleteAll();
$this->assertTrue($job->run());
$sql = "SELECT * FROM account_read_subscription order by userid";
$rows = ZurmoRedBean::getAll($sql);
$this->assertEquals(2, count($rows));
$this->assertEquals($super->id, $rows[0]['userid']);
$this->assertEquals($account2->id, $rows[0]['modelid']);
$this->assertEquals(ReadPermissionsSubscriptionUtil::TYPE_ADD, $rows[0]['subscriptiontype']);
$this->assertEquals($billy->id, $rows[1]['userid']);
$this->assertEquals($account2->id, $rows[1]['modelid']);
$this->assertEquals(ReadPermissionsSubscriptionUtil::TYPE_ADD, $rows[1]['subscriptiontype']);
sleep(1);
$account2->owner = self::$billy;
$this->assertTrue($account2->save());
sleep(1);
$queuedJobs = Yii::app()->jobQueue->getAll();
$this->assertEquals(1, count($queuedJobs[5]));
$this->assertEquals('ReadPermissionSubscriptionUpdateForAccountFromBuildTable', $queuedJobs[5][0]['jobType']);
Yii::app()->jobQueue->deleteAll();
$this->assertTrue($job->run());
$sql = "SELECT * FROM account_read_subscription order by userid";
$rows = ZurmoRedBean::getAll($sql);
$this->assertEquals(2, count($rows));
$this->assertEquals($super->id, $rows[0]['userid']);
$this->assertEquals($account2->id, $rows[0]['modelid']);
$this->assertEquals(ReadPermissionsSubscriptionUtil::TYPE_ADD, $rows[0]['subscriptiontype']);
$this->assertEquals(self::$billy->id, $rows[1]['userid']);
$this->assertEquals($account2->id, $rows[1]['modelid']);
$this->assertEquals(ReadPermissionsSubscriptionUtil::TYPE_ADD, $rows[1]['subscriptiontype']);
// Clean account table
$accounts = Account::getAll();
foreach ($accounts as $account) {
$account->delete();
}
$sql = "DELETE FROM account_read_subscription";
ZurmoRedBean::exec($sql);
$johnny = self::$johnny;
$account3 = AccountTestHelper::createAccountByNameForOwner('Third Account', $johnny);
sleep(1);
$queuedJobs = Yii::app()->jobQueue->getAll();
$this->assertEquals(1, count($queuedJobs[5]));
$this->assertEquals('ReadPermissionSubscriptionUpdateForAccountFromBuildTable', $queuedJobs[5][0]['jobType']);
Yii::app()->jobQueue->deleteAll();
$this->assertTrue($job->run());
$sql = "SELECT * FROM account_read_subscription order by userid";
$rows = ZurmoRedBean::getAll($sql);
$this->assertEquals(3, count($rows));
$this->assertEquals($super->id, $rows[0]['userid']);
$this->assertEquals($account3->id, $rows[0]['modelid']);
$this->assertEquals(ReadPermissionsSubscriptionUtil::TYPE_ADD, $rows[0]['subscriptiontype']);
$this->assertEquals($billy->id, $rows[1]['userid']);
$this->assertEquals($account3->id, $rows[1]['modelid']);
$this->assertEquals(ReadPermissionsSubscriptionUtil::TYPE_ADD, $rows[1]['subscriptiontype']);
$this->assertEquals($johnny->id, $rows[2]['userid']);
$this->assertEquals($account3->id, $rows[2]['modelid']);
$this->assertEquals(ReadPermissionsSubscriptionUtil::TYPE_ADD, $rows[2]['subscriptiontype']);
$account3Id = $account3->id;
$account3->forgetAll();
$account3 = Account::getById($account3Id);
$this->assertTrue($account3->save());
$account3->forgetAll();
PermissionsCache::forgetAll();
$account3 = Account::getById($account3Id);
$account3->owner = $super;
$this->assertTrue($account3->save());
sleep(1);
$queuedJobs = Yii::app()->jobQueue->getAll();
$this->assertEquals(1, count($queuedJobs[5]));
$this->assertEquals('ReadPermissionSubscriptionUpdateForAccountFromBuildTable', $queuedJobs[5][0]['jobType']);
Yii::app()->jobQueue->deleteAll();
$this->assertTrue($job->run());
$sql = "SELECT * FROM account_read_subscription order by userid";
$rows = ZurmoRedBean::getAll($sql);
$this->assertEquals(3, count($rows));
$this->assertEquals($super->id, $rows[0]['userid']);
$this->assertEquals($account3->id, $rows[0]['modelid']);
$this->assertEquals(ReadPermissionsSubscriptionUtil::TYPE_ADD, $rows[0]['subscriptiontype']);
$this->assertEquals($billy->id, $rows[1]['userid']);
$this->assertEquals($account3->id, $rows[1]['modelid']);
$this->assertEquals(ReadPermissionsSubscriptionUtil::TYPE_ADD, $rows[1]['subscriptiontype']);
$this->assertEquals($johnny->id, $rows[2]['userid']);
$this->assertEquals($account3->id, $rows[2]['modelid']);
$this->assertEquals(ReadPermissionsSubscriptionUtil::TYPE_DELETE, $rows[2]['subscriptiontype']);
}
示例12: testTriggerBeforeSaveModifiedByUser
/**
* @depends testTriggerBeforeSaveCreatedByUser
*/
public function testTriggerBeforeSaveModifiedByUser()
{
Yii::app()->user->userModel = User::getByUsername('super');
//First test equals
$workflow = self::makeOnSaveWorkflowAndTriggerWithoutValueType('modifiedByUser', 'equals', self::$superUserId);
$model = new Account();
$model->name = 'name';
$model->owner = User::getByUsername('bobby');
$this->assertTrue(WorkflowTriggersUtil::areTriggersTrueBeforeSave($workflow, $model));
$this->assertTrue($model->save());
$modelId = $model->id;
$model->forget();
Yii::app()->user->userModel = User::getByUsername('bobby');
$model = Account::getById($modelId);
$model->name = 'name2';
$this->assertFalse(WorkflowTriggersUtil::areTriggersTrueBeforeSave($workflow, $model));
}
示例13: testAddingActivityItemThatShouldCastDownAndThrowException
/**
* @depends testCreateAndGetTaskById
*/
public function testAddingActivityItemThatShouldCastDownAndThrowException()
{
Yii::app()->user->userModel = User::getByUsername('super');
$accounts = Account::getByName('anAccount');
$accountId = $accounts[0]->id;
$accounts[0]->forget();
$task = new Task();
$task->activityItems->add(Account::getById($accountId));
foreach ($task->activityItems as $existingItem) {
try {
$castedDownModel = $existingItem->castDown(array(array('SecurableItem', 'OwnedSecurableItem', 'Account')));
//this should not fail
} catch (NotFoundException $e) {
$this->fail();
}
}
foreach ($task->activityItems as $existingItem) {
try {
$castedDownModel = $existingItem->castDown(array(array('SecurableItem', 'OwnedSecurableItem', 'Person', 'Contact')));
//this should fail
$this->fail();
} catch (NotFoundException $e) {
}
}
}
示例14: actionEdit
public function actionEdit($id, $redirectUrl = null)
{
$contract = Contract::getById(intval($id));
$sql = "select * from contract_opportunity where contract_id=" . $id;
$rec = Yii::app()->db->createCommand($sql)->queryRow();
$rec_t['value'] = $rec_c['value'] = '';
if (!empty($rec) && !empty($rec['opportunity_id'])) {
$getopportunity = Opportunity::getById(intval($rec['opportunity_id']));
$sql1 = "select * from opportunity where id=" . $rec['opportunity_id'];
$rec1 = Yii::app()->db->createCommand($sql1)->queryRow();
}
if (isset($rec1['totalbulkpricstm_currencyvalue_id']) && !empty($rec1['totalbulkpricstm_currencyvalue_id'])) {
//get totalbuilprice
$sql_t = "select * from currencyvalue where id=" . $rec1['totalbulkpricstm_currencyvalue_id'];
$rec_t = Yii::app()->db->createCommand($sql_t)->queryRow();
}
if (isset($rec1['constructcoscstm_currencyvalue_id']) && !empty($rec1['constructcoscstm_currencyvalue_id'])) {
$sql_c = "select * from currencyvalue where id=" . $rec1['constructcoscstm_currencyvalue_id'];
$rec_c = Yii::app()->db->createCommand($sql_c)->queryRow();
}
$getaccount = Account::getById(intval($getopportunity->account->id));
$_SESSION['unitsCstmCstm'] = !empty($getaccount->unitsCstmCstm) ? $getaccount->unitsCstmCstm : 1;
$_SESSION['totalbulkpricstm'] = !empty($rec_t['value']) ? $rec_t['value'] : 1;
$_SESSION['totalcostprccstm'] = !empty($rec_c['value']) ? $_SESSION['unitsCstmCstm'] * $rec_c['value'] : $_SESSION['unitsCstmCstm'] * 1;
ControllerSecurityUtil::resolveAccessCanCurrentUserWriteModel($contract);
$this->processEdit($contract, $redirectUrl);
}
示例15: testUpdateWithRelations
/**
* @depends testCreateWithRelations
*/
public function testUpdateWithRelations()
{
$super = User::getByUsername('super');
Yii::app()->user->userModel = $super;
$authenticationData = $this->login();
$headers = array('Accept: application/xml', 'ZURMO_SESSION_ID: ' . $authenticationData['sessionId'], 'ZURMO_TOKEN: ' . $authenticationData['token'], 'ZURMO_API_REQUEST_TYPE: REST');
$account = AccountTestHelper::createAccountByNameForOwner('Factor X', $super);
$account1 = AccountTestHelper::createAccountByNameForOwner('Miko', $super);
$account2 = AccountTestHelper::createAccountByNameForOwner('Troter', $super);
$contact = ContactTestHelper::createContactByNameForOwner('Simon', $super);
$redBeanModelToApiDataUtil = new RedBeanModelToApiDataUtil($account);
$compareData = $redBeanModelToApiDataUtil->getData();
$account->forget();
$data['modelRelations'] = array('accounts' => array(array('action' => 'add', 'modelId' => $account1->id, 'modelClassName' => 'Account'), array('action' => 'add', 'modelId' => $account2->id, 'modelClassName' => 'Account')), 'contacts' => array(array('action' => 'add', 'modelId' => $contact->id, 'modelClassName' => 'Contact')));
$data['name'] = 'Zurmo Inc.';
$response = ApiRestTestHelper::createXmlApiCall($this->serverUrl . '/test.php/accounts/account/api/update/' . $compareData['id'], 'PUT', $headers, array('data' => $data));
$response = XML2Array::createArray($response);
unset($response['data']['modifiedDateTime']);
unset($compareData['modifiedDateTime']);
$compareData['name'] = 'Zurmo Inc.';
$this->assertEquals(ApiResponse::STATUS_SUCCESS, $response['status']);
$this->assertEquals($compareData, $response['data']);
RedBeanModel::forgetAll();
$account = Account::getById($compareData['id']);
$this->assertEquals(2, count($account->accounts));
$this->assertEquals($account1->id, $account->accounts[0]->id);
$this->assertEquals($account2->id, $account->accounts[1]->id);
$this->assertEquals(1, count($account->contacts));
$this->assertEquals($contact->id, $account->contacts[0]->id);
$account1 = Account::getById($account1->id);
$this->assertEquals($account->id, $account1->account->id);
$account2 = Account::getById($account2->id);
$this->assertEquals($account->id, $account2->account->id);
$contact = Contact::getById($contact->id);
$this->assertEquals($account->id, $contact->account->id);
// Now test remove relations
$data['modelRelations'] = array('accounts' => array(array('action' => 'remove', 'modelId' => $account1->id, 'modelClassName' => 'Account'), array('action' => 'remove', 'modelId' => $account2->id, 'modelClassName' => 'Account')), 'contacts' => array(array('action' => 'remove', 'modelId' => $contact->id, 'modelClassName' => 'Contact')));
$response = ApiRestTestHelper::createXmlApiCall($this->serverUrl . '/test.php/accounts/account/api/update/' . $compareData['id'], 'PUT', $headers, array('data' => $data));
$response = XML2Array::createArray($response);
$this->assertEquals(ApiResponse::STATUS_SUCCESS, $response['status']);
RedBeanModel::forgetAll();
$updatedModel = Account::getById($compareData['id']);
$this->assertEquals(0, count($updatedModel->accounts));
$this->assertEquals(0, count($updatedModel->contacts));
$account1 = Account::getById($account1->id);
$this->assertLessThanOrEqual(0, $account1->account->id);
$account2 = Account::getById($account2->id);
$this->assertLessThanOrEqual(0, $account2->account->id);
$contact = Contact::getById($contact->id);
$this->assertLessThanOrEqual(0, $contact->account->id);
}