Exemple #1
0
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     Eloquent::unguard();
     Contact::deleteAll();
     $this->call('CountriesTableSeeder');
     $this->call('CompaniesTableSeeder');
     $this->call('ContactsTableSeeder');
     $this->call('ContactCompanyTableSeeder');
 }
 public function setUp()
 {
     parent::setUp();
     $this->user = User::getByUsername('super');
     Yii::app()->user->userModel = $this->user;
     Campaign::deleteAll();
     CampaignItem::deleteAll();
     Contact::deleteAll();
     MarketingList::deleteAll();
 }
Exemple #3
0
<?php

require_once __DIR__ . "/../vendor/autoload.php";
require_once __DIR__ . "/../src/Contact.php";
session_start();
//creates 'list_of_contacts' array if SESSION is empty
if (empty($_SESSION['list_of_contacts'])) {
    $_SESSION['list_of_contacts'] = array();
}
$app = new Silex\Application();
$app->register(new Silex\Provider\TwigServiceProvider(), array('twig.path' => __DIR__ . '/../views'));
//root or homepage route
$app->get("/", function () use($app) {
    return $app['twig']->render('contacts.html.twig', array('contacts' => Contact::getAll()));
});
//saves a new contact and routes the user to /create_contact
$app->post("/create_contact", function () use($app) {
    $contact = new Contact($_POST['create_name'], $_POST['create_phone'], $_POST['create_address']);
    $contact->save();
    return $app['twig']->render('create_contact.html.twig', array('contacts' => Contact::getAll()));
});
//deletes ALL contacts and routes user to /delete_contacts
$app->post('/delete_contacts', function () use($app) {
    Contact::deleteAll();
    return $app['twig']->render('delete_contacts.html.twig');
});
return $app;
 public function testArePermissionsFlushedOnRemovingParentFromChildRole()
 {
     Contact::deleteAll();
     try {
         $role = Role::getByName('Parent');
         $role->delete();
     } catch (NotFoundException $e) {
     }
     try {
         $user = User::getByUsername('jim');
         $user->delete();
     } catch (NotFoundException $e) {
     }
     try {
         $user = User::getByUsername('jane');
         $user->delete();
     } catch (NotFoundException $e) {
     }
     // we could have used helpers to do a lot of the following stuff (such as creating users, roles,
     // etc) but we wanted to mimic user's interaction as closely as possible. Hence using walkthroughs
     // for everything
     // create Parent and Child Roles, Create Jim to be member of Child role
     // create parent role
     $this->resetGetArray();
     $this->setPostArray(array('Role' => array('name' => 'Parent')));
     $this->runControllerWithRedirectExceptionAndGetUrl('/zurmo/role/create');
     $parentRole = Role::getByName('Parent');
     $this->assertNotNull($parentRole);
     $this->assertEquals('Parent', strval($parentRole));
     $parentRoleId = $parentRole->id;
     // create child role
     $this->resetGetArray();
     $this->setPostArray(array('Role' => array('name' => 'Child', 'role' => array('id' => $parentRoleId))));
     $this->runControllerWithRedirectExceptionAndGetUrl('/zurmo/role/create');
     $childRole = Role::getByName('Child');
     $this->assertNotNull($childRole);
     $this->assertEquals('Child', strval($childRole));
     $parentRole->forgetAll();
     $parentRole = Role::getById($parentRoleId);
     $childRoleId = $childRole->id;
     $childRole->forgetAll();
     $childRole = Role::getById($childRoleId);
     $this->assertEquals($childRole->id, $parentRole->roles[0]->id);
     // create jim's user
     $this->resetGetArray();
     $this->setPostArray(array('UserPasswordForm' => array('firstName' => 'Some', 'lastName' => 'Body', 'username' => 'jim', 'newPassword' => 'myPassword123', 'newPassword_repeat' => 'myPassword123', 'officePhone' => '456765421', 'userStatus' => 'Active', 'role' => array('id' => $childRoleId))));
     $this->runControllerWithRedirectExceptionAndGetContent('/users/default/create');
     $jim = User::getByUsername('jim');
     $this->assertNotNull($jim);
     $childRole->forgetAll();
     $childRole = Role::getById($childRoleId);
     $this->assertEquals($childRole->id, $jim->role->id);
     // give jim rights to contact's module
     $jim->setRight('ContactsModule', ContactsModule::getAccessRight());
     $jim->setRight('ContactsModule', ContactsModule::getCreateRight());
     $this->assertTrue($jim->save());
     $jim->forgetAll();
     $jim = User::getByUsername('jim');
     // create jane's user
     $this->resetGetArray();
     $this->setPostArray(array('UserPasswordForm' => array('firstName' => 'Some', 'lastName' => 'Body', 'username' => 'jane', 'newPassword' => 'myPassword123', 'newPassword_repeat' => 'myPassword123', 'officePhone' => '456765421', 'userStatus' => 'Active', 'role' => array('id' => $parentRoleId))));
     $this->runControllerWithRedirectExceptionAndGetContent('/users/default/create');
     $jane = User::getByUsername('jane');
     $this->assertNotNull($jane);
     $parentRole->forgetAll();
     $parentRole = Role::getById($parentRoleId);
     $this->assertEquals($parentRole->id, $jane->role->id);
     // give jane rights to contact's module, we need to do this because once the link between parent and child
     // role is broken jane won't be able to access the listview of contacts
     $jane->setRight('ContactsModule', ContactsModule::getAccessRight());
     $this->assertTrue($jane->save());
     $jane->forgetAll();
     $jane = User::getByUsername('jane');
     // create a contact from jim's account
     // create ContactStates
     ContactsModule::loadStartingData();
     // ensure contact states have been created
     $this->assertEquals(6, count(ContactState::GetAll()));
     $this->logoutCurrentUserLoginNewUserAndGetByUsername('jim');
     // go ahead and create contact with parent role given readwrite.
     $startingState = ContactsUtil::getStartingState();
     $this->resetGetArray();
     $this->setPostArray(array('Contact' => array('firstName' => 'Jim', 'lastName' => 'Doe', 'officePhone' => '456765421', 'state' => array('id' => $startingState->id))));
     $url = $this->runControllerWithRedirectExceptionAndGetUrl('/contacts/default/create');
     $jimDoeContactId = intval(substr($url, strpos($url, 'id=') + 3));
     $jimDoeContact = Contact::getById($jimDoeContactId);
     $this->assertNotNull($jimDoeContact);
     $this->resetPostArray();
     $this->setGetArray(array('id' => $jimDoeContactId));
     $content = $this->runControllerWithNoExceptionsAndGetContent('/contacts/default/details');
     $this->assertContains('Who can read and write Owner', $content);
     // create a contact using jane which she would see at all times
     $this->logoutCurrentUserLoginNewUserAndGetByUsername('jane');
     $this->resetGetArray();
     $this->setPostArray(array('Contact' => array('firstName' => 'Jane', 'lastName' => 'Doe', 'officePhone' => '456765421', 'state' => array('id' => $startingState->id))));
     $url = $this->runControllerWithRedirectExceptionAndGetUrl('/contacts/default/create');
     $janeDoeContactId = intval(substr($url, strpos($url, 'id=') + 3));
     $janeDoeContact = Contact::getById($jimDoeContactId);
     $this->assertNotNull($janeDoeContact);
     $this->resetPostArray();
     $this->setGetArray(array('id' => $janeDoeContactId));
     $content = $this->runControllerWithNoExceptionsAndGetContent('/contacts/default/details');
     $this->assertContains('Who can read and write Owner', $content);
     // ensure jim can see that contact everywhere
     // jim should have access to see contact on list view
     $this->logoutCurrentUserLoginNewUserAndGetByUsername('jim');
     $this->resetGetArray();
     // get the page, ensure the name of contact does show up there.
     $content = $this->runControllerWithNoExceptionsAndGetContent('/contacts/default');
     $this->assertContains('Jim Doe</a></td><td>', $content);
     $this->assertNotContains('Jane Doe</a></td><td>', $content);
     // jim should have access to jimDoeContact's detail view
     $this->setGetArray(array('id' => $jimDoeContactId));
     $this->runControllerWithNoExceptionsAndGetContent('/contacts/default/details');
     // jim should have access to jimDoeContact's edit view
     $this->runControllerWithNoExceptionsAndGetContent('/contacts/default/edit');
     // jim should not have access to janeDoeContact's detail view
     $this->setGetArray(array('id' => $janeDoeContactId));
     try {
         $this->runControllerWithNoExceptionsAndGetContent('/contacts/default/details');
         $this->fail('Accessing details action should have thrown ExitException');
     } catch (ExitException $e) {
         // just cleanup buffer
         $this->endAndGetOutputBuffer();
     }
     // jim should have access to janeDoeContact's edit view
     try {
         $this->runControllerWithNoExceptionsAndGetContent('/contacts/default/edit');
         $this->fail('Accessing edit action should have thrown ExitException');
     } catch (ExitException $e) {
         // just cleanup buffer
         $this->endAndGetOutputBuffer();
     }
     // ensure jane can see that contact everywhere
     // jane should have access to see contact on list view
     $this->logoutCurrentUserLoginNewUserAndGetByUsername('jane');
     $this->resetGetArray();
     // get the page, ensure the name of contact does show up there.
     $content = $this->runControllerWithNoExceptionsAndGetContent('/contacts/default');
     $this->assertContains('Jim Doe</a></td><td>', $content);
     $this->assertContains('Jane Doe</a></td><td>', $content);
     // jane should have access to jimDoeContact's detail view
     $this->setGetArray(array('id' => $jimDoeContactId));
     $this->runControllerWithNoExceptionsAndGetContent('/contacts/default/details');
     // jane should have access to jimDoeContact's edit view
     $this->runControllerWithNoExceptionsAndGetContent('/contacts/default/edit');
     // jane should have access to janeDoeContact's detail view
     $this->setGetArray(array('id' => $janeDoeContactId));
     $this->runControllerWithNoExceptionsAndGetContent('/contacts/default/details');
     // jane should have access to janeDoeContact's edit view
     $this->runControllerWithNoExceptionsAndGetContent('/contacts/default/edit');
     // unlink Parent role from child
     $this->logoutCurrentUserLoginNewUserAndGetByUsername('super');
     $this->setGetArray(array('id' => $childRoleId));
     $this->setPostArray(array('Role' => array('name' => 'Child', 'role' => array('id' => ''))));
     $this->runControllerWithRedirectExceptionAndGetUrl('/zurmo/role/edit');
     $childRole = Role::getByName('Child');
     $this->assertNotNull($childRole);
     $this->assertEquals('Child', strval($childRole));
     $parentRole->forgetAll();
     $parentRole = Role::getById($parentRoleId);
     $this->assertNotNull($parentRole);
     $this->assertCount(0, $parentRole->roles);
     // ensure jim can still see that contact everywhere
     // jim should have access to see contact on list view
     $this->logoutCurrentUserLoginNewUserAndGetByUsername('jim');
     $this->resetGetArray();
     // get the page, ensure the name of contact does show up there.
     $content = $this->runControllerWithNoExceptionsAndGetContent('/contacts/default');
     $this->assertContains('Jim Doe</a></td><td>', $content);
     $this->assertNotContains('Jane Doe</a></td><td>', $content);
     // jim should have access to jimDoeContact's detail view
     $this->setGetArray(array('id' => $jimDoeContactId));
     $this->runControllerWithNoExceptionsAndGetContent('/contacts/default/details');
     // jim should have access to jimDoeContact's edit view
     $this->runControllerWithNoExceptionsAndGetContent('/contacts/default/edit');
     // jim should not have access to janeDoeContact's detail view
     $this->setGetArray(array('id' => $janeDoeContactId));
     try {
         $this->runControllerWithNoExceptionsAndGetContent('/contacts/default/details');
         $this->fail('Accessing details action should have thrown ExitException');
     } catch (ExitException $e) {
         // just cleanup buffer
         $this->endAndGetOutputBuffer();
     }
     // jim should have access to janeDoeContact's edit view
     try {
         $this->runControllerWithNoExceptionsAndGetContent('/contacts/default/edit');
         $this->fail('Accessing edit action should have thrown ExitException');
     } catch (ExitException $e) {
         // just cleanup buffer
         $this->endAndGetOutputBuffer();
     }
     // ensure jane can not see that contact anywhere
     // jane should have access to see contact on list view
     $this->logoutCurrentUserLoginNewUserAndGetByUsername('jane');
     $this->resetGetArray();
     // get the page, ensure the name of contact does not show up there.
     $content = $this->runControllerWithNoExceptionsAndGetContent('/contacts/default');
     $this->assertNotContains('Jim Doe</a></td><td>', $content);
     $this->assertContains('Jane Doe</a></td><td>', $content);
     // jane should have access to janeDoeContact's detail view
     $this->setGetArray(array('id' => $janeDoeContactId));
     $this->runControllerWithNoExceptionsAndGetContent('/contacts/default/details');
     // jane should have access to janeDoeContact's edit view
     $this->runControllerWithNoExceptionsAndGetContent('/contacts/default/edit');
     // jane should not have access to jimDoeContact's detail view
     $this->setGetArray(array('id' => $jimDoeContactId));
     try {
         $this->runControllerWithNoExceptionsAndGetContent('/contacts/default/details');
         $this->fail('Accessing details action should have thrown ExitException');
     } catch (ExitException $e) {
         // just cleanup buffer
         $this->endAndGetOutputBuffer();
     }
     // jane should not have access to jimDoeContact's edit view
     try {
         $this->runControllerWithNoExceptionsAndGetContent('/contacts/default/edit');
         $this->fail('Accessing edit action should have thrown ExitException');
     } catch (ExitException $e) {
         // just cleanup buffer
         $this->endAndGetOutputBuffer();
     }
 }
 public function testRunWithCampaignPausedAfterAllItemsGeneratedAndThenUnpaused()
 {
     // Cleanup
     Campaign::deleteAll();
     $this->assertEquals(0, Campaign::getCount());
     $this->assertEquals(0, CampaignItem::getCount());
     $this->assertEquals(0, CampaignItemActivity::getCount());
     MarketingList::deleteAll();
     $this->assertEquals(0, MarketingList::getCount());
     $this->assertEquals(0, MarketingListMember::getCount());
     EmailMessage::deleteAll();
     $this->assertEquals(0, EmailMessage::getCount());
     $this->assertEquals(0, EmailMessageContent::getCount());
     $this->assertEquals(0, EmailMessageSender::getCount());
     $this->assertEquals(0, EmailMessageRecipient::getCount());
     Contact::deleteAll();
     $this->assertEquals(0, Contact::getCount());
     // setup an email address for contacts
     $email = new Email();
     $email->emailAddress = '*****@*****.**';
     // create a marketing list with 5 members
     $marketingList = MarketingListTestHelper::createMarketingListByName('marketingList 05');
     $marketingListId = $marketingList->id;
     for ($i = 1; $i <= 5; $i++) {
         $contact = ContactTestHelper::createContactByNameForOwner('campaignContact 0' . $i, $this->user);
         $contact->primaryEmail = $email;
         $this->assertTrue($contact->save());
         MarketingListMemberTestHelper::createMarketingListMember(0, $marketingList, $contact);
     }
     $marketingList->forgetAll();
     // create a due campaign with that marketing list
     $campaign = CampaignTestHelper::createCampaign('campaign 04', 'subject', 'text Content', 'Html Content', null, null, null, null, null, null, MarketingList::getById($marketingListId));
     $campaignId = $campaign->id;
     /*
      * Run 1:
      * CampaignGenerateDueCampaignItemsJob
      * status == processing
      * items generated but unprocessed
      *
      * CampaignQueueMessagesInOutboxJob
      * status == processing
      * items processed with email messages generated and queued
      *
      * ProcessOutboundEmailJob
      * status == processing
      * email items attempted to be sent
      *
      * Run 2:
      * Pause the campaign
      * items are processed and still present
      *
      * Unpause the campaign
      * status == active
      * items are processed and still present
      *
      * CampaignGenerateDueCampaignItemsJob
      * status == processing
      * ensure all items are present and processed
      *
      * CampaignQueueMessagesInOutboxJob
      * status == processing
      * ensure all items are present and processed
      * ensure all email messages are present with correct folder type
      *
      * ProcessOutboundEmailJob
      * ensure all email messages are present with correct folder type
      * status == processing
      *
      *
      * Run 3:
      * Mark Campaign as Completed
      * status == completed
      */
     // we have to do this to ensure when we retrieve the data status is updated from db.
     $campaign->forgetAll();
     $this->assertEmpty(CampaignItem::getAll());
     // Run 1 starts here
     // Run CampaignGenerateDueCampaignItemsJob
     $job = new CampaignGenerateDueCampaignItemsJob();
     $this->assertTrue($job->run());
     $campaign = Campaign::getById($campaignId);
     // ensure status is processing
     $this->assertEquals(Campaign::STATUS_PROCESSING, $campaign->status);
     // ensure 5 campaign items have been generated
     $this->assertEquals(5, CampaignItem::getCount());
     // ensure all 5 campaign items are unprocessed
     $campaignItems = CampaignItem::getByProcessedAndCampaignId(0, $campaignId);
     $this->assertNotEmpty($campaignItems);
     $this->assertCount(5, $campaignItems);
     // Run CampaignQueueMessagesInOutboxJob
     $job = new CampaignQueueMessagesInOutboxJob();
     $this->assertTrue($job->run());
     // Ensure campaign status
     $campaign = Campaign::getById($campaignId);
     $this->assertEquals(Campaign::STATUS_PROCESSING, $campaign->status);
     // ensure all 5 campaign items are processed
     $campaignItems = CampaignItem::getByProcessedAndCampaignId(1, $campaignId);
     $this->assertNotEmpty($campaignItems);
     $this->assertCount(5, $campaignItems);
     // Ensure 5 new email messages
     $this->assertEquals(5, EmailMessage::getCount());
     $this->assertEquals(5, EmailHelper::getQueuedCount());
     // Run ProcessOutboundEmail
     $job = new ProcessOutboundEmailJob();
     $this->assertTrue($job->run());
     // Ensure all email were sent
     $this->assertEquals(5, EmailMessage::getCount());
     $this->assertEquals(0, EmailHelper::getQueuedCount());
     foreach (EmailMessage::getAll() as $emailMessage) {
         $this->assertEquals($emailMessage->folder->type, EmailFolder::TYPE_SENT);
     }
     // Ensure campaign status
     $campaign = Campaign::getById($campaignId);
     $this->assertEquals(Campaign::STATUS_PROCESSING, $campaign->status);
     // end of Run 1
     // Run 2 starts here
     // Pause the campaign
     $campaign->status = Campaign::STATUS_PAUSED;
     $this->assertTrue($campaign->save());
     // ensure campaign items are still there
     $campaignItems = CampaignItem::getByProcessedAndCampaignId(1, $campaignId);
     $this->assertCount(5, $campaignItems);
     $this->assertNotEmpty($campaignItems);
     // Unpause campaign
     $campaign = Campaign::getById($campaignId);
     $this->assertEquals(Campaign::STATUS_PAUSED, $campaign->status);
     $campaign->status = Campaign::STATUS_ACTIVE;
     $this->assertTrue($campaign->save());
     // ensure campaign items are still there
     $campaignItems = CampaignItem::getByProcessedAndCampaignId(1, $campaignId);
     $this->assertCount(5, $campaignItems);
     $this->assertNotEmpty($campaignItems);
     // Ensure status change
     $campaign = Campaign::getById($campaignId);
     $this->assertEquals(Campaign::STATUS_ACTIVE, $campaign->status);
     // Run CampaignGenerateDueCampaignItemsJob
     $job = new CampaignGenerateDueCampaignItemsJob();
     $this->assertTrue($job->run());
     // Ensure campaign status change
     $campaign = Campaign::getById($campaignId);
     $this->assertEquals(Campaign::STATUS_PROCESSING, $campaign->status);
     // ensure all 5 (previously created in run1) campaign items are still processed
     $campaignItems = CampaignItem::getByProcessedAndCampaignId(1, $campaignId);
     $this->assertNotEmpty($campaignItems);
     $this->assertCount(5, $campaignItems);
     // Run CampaignQueueMessagesInOutboxJob
     $job = new CampaignQueueMessagesInOutboxJob();
     $this->assertTrue($job->run());
     // Ensure campaign status
     $campaign = Campaign::getById($campaignId);
     $this->assertEquals(Campaign::STATUS_PROCESSING, $campaign->status);
     // ensure all 5 (previously created in run1) campaign items are still processed
     $campaignItems = CampaignItem::getByProcessedAndCampaignId(1, $campaignId);
     $this->assertNotEmpty($campaignItems);
     $this->assertCount(5, $campaignItems);
     // Ensure all 5 (previously created and sent in run1) emails are sent.
     $this->assertEquals(5, EmailMessage::getCount());
     foreach (EmailMessage::getAll() as $emailMessage) {
         $this->assertEquals($emailMessage->folder->type, EmailFolder::TYPE_SENT);
     }
     // Run ProcessOutboundEmail
     $job = new ProcessOutboundEmailJob();
     $this->assertTrue($job->run());
     // Ensure all 5 (previously created and sent in run1) emails are sent.
     $this->assertEquals(5, EmailMessage::getCount());
     foreach (EmailMessage::getAll() as $emailMessage) {
         $this->assertEquals($emailMessage->folder->type, EmailFolder::TYPE_SENT);
     }
     // Ensure campaign status
     $campaign = Campaign::getById($campaignId);
     $this->assertEquals(Campaign::STATUS_PROCESSING, $campaign->status);
     // end of Run 2
     // Run 3 starts here
     // Run CampaignMarkCompleted
     $job = new CampaignMarkCompletedJob();
     $this->assertTrue($job->run());
     // Ensure campaign status change
     $campaign = Campaign::getById($campaignId);
     $this->assertEquals(Campaign::STATUS_COMPLETED, $campaign->status);
     // end of Run 3
 }
 public function setup()
 {
     $this->logoutCurrentUserLoginNewUserAndGetByUsername('super');
     Contact::deleteAll();
     $this->clearAllCaches();
 }
 /**
  * @depends testUnprivilegedUserViewUpdateDeleteContacts
  */
 public function testBasicSearchContacts()
 {
     $super = User::getByUsername('super');
     Yii::app()->user->userModel = $super;
     Contact::deleteAll();
     $authenticationData = $this->login();
     $headers = array('Accept: application/json', 'ZURMO_SESSION_ID: ' . $authenticationData['sessionId'], 'ZURMO_TOKEN: ' . $authenticationData['token'], 'ZURMO_API_REQUEST_TYPE: REST');
     //Setup test data owned by the super user.
     $account = AccountTestHelper::createAccountByNameForOwner('superAccount', $super);
     $account2 = AccountTestHelper::createAccountByNameForOwner('superAccount2', $super);
     ContactTestHelper::createContactWithAccountByNameForOwner('First Contact', $super, $account);
     ContactTestHelper::createContactWithAccountByNameForOwner('Second Contact', $super, $account);
     ContactTestHelper::createContactWithAccountByNameForOwner('Third Contact', $super, $account);
     ContactTestHelper::createContactWithAccountByNameForOwner('Forth Contact', $super, $account2);
     ContactTestHelper::createContactWithAccountByNameForOwner('Fifth Contact', $super, $account2);
     LeadTestHelper::createLeadWithAccountByNameForOwner('First Lead', $super, $account);
     LeadTestHelper::createLeadWithAccountByNameForOwner('Second Lead', $super, $account2);
     $searchParams = array('pagination' => array('page' => 1, 'pageSize' => 3), 'search' => array('firstName' => ''), 'sort' => 'firstName');
     $searchParamsQuery = http_build_query($searchParams);
     $response = $this->createApiCallWithRelativeUrl('list/filter/' . $searchParamsQuery, 'GET', $headers);
     $response = json_decode($response, true);
     $this->assertEquals(ApiResponse::STATUS_SUCCESS, $response['status']);
     $this->assertEquals(3, count($response['data']['items']));
     $this->assertEquals(5, $response['data']['totalCount']);
     $this->assertEquals(1, $response['data']['currentPage']);
     $this->assertEquals('Fifth Contact', $response['data']['items'][0]['firstName']);
     $this->assertEquals('First Contact', $response['data']['items'][1]['firstName']);
     $this->assertEquals('Forth Contact', $response['data']['items'][2]['firstName']);
     // Second page
     $searchParams['pagination']['page'] = 2;
     $searchParamsQuery = http_build_query($searchParams);
     $response = $this->createApiCallWithRelativeUrl('list/filter/' . $searchParamsQuery, 'GET', $headers);
     $response = json_decode($response, true);
     $this->assertEquals(ApiResponse::STATUS_SUCCESS, $response['status']);
     $this->assertEquals(2, count($response['data']['items']));
     $this->assertEquals(5, $response['data']['totalCount']);
     $this->assertEquals(2, $response['data']['currentPage']);
     $this->assertEquals('Second Contact', $response['data']['items'][0]['firstName']);
     $this->assertEquals('Third Contact', $response['data']['items'][1]['firstName']);
     // Search by name
     $searchParams['pagination']['page'] = 1;
     $searchParams['search']['firstName'] = 'First Contact';
     $searchParamsQuery = http_build_query($searchParams);
     $response = $this->createApiCallWithRelativeUrl('list/filter/' . $searchParamsQuery, 'GET', $headers);
     $response = json_decode($response, true);
     $this->assertEquals(ApiResponse::STATUS_SUCCESS, $response['status']);
     $this->assertEquals(1, count($response['data']['items']));
     $this->assertEquals(1, $response['data']['totalCount']);
     $this->assertEquals(1, $response['data']['currentPage']);
     $this->assertEquals('First Contact', $response['data']['items'][0]['firstName']);
     // No results
     $searchParams['pagination']['page'] = 1;
     $searchParams['search']['firstName'] = 'First Contact 2';
     $searchParamsQuery = http_build_query($searchParams);
     $response = $this->createApiCallWithRelativeUrl('list/filter/' . $searchParamsQuery, 'GET', $headers);
     $response = json_decode($response, true);
     $this->assertEquals(ApiResponse::STATUS_SUCCESS, $response['status']);
     $this->assertEquals(0, $response['data']['totalCount']);
     $this->assertFalse(isset($response['data']['items']));
     // Search by name desc.
     $searchParams = array('pagination' => array('page' => 1, 'pageSize' => 3), 'search' => array('firstName' => ''), 'sort' => 'firstName.desc');
     $searchParamsQuery = http_build_query($searchParams);
     $response = $this->createApiCallWithRelativeUrl('list/filter/' . $searchParamsQuery, 'GET', $headers);
     $response = json_decode($response, true);
     $this->assertEquals(ApiResponse::STATUS_SUCCESS, $response['status']);
     $this->assertEquals(3, count($response['data']['items']));
     $this->assertEquals(5, $response['data']['totalCount']);
     $this->assertEquals(1, $response['data']['currentPage']);
     $this->assertEquals('Third Contact', $response['data']['items'][0]['firstName']);
     $this->assertEquals('Second Contact', $response['data']['items'][1]['firstName']);
     $this->assertEquals('Forth Contact', $response['data']['items'][2]['firstName']);
     // Second page
     $searchParams['pagination']['page'] = 2;
     $searchParamsQuery = http_build_query($searchParams);
     $response = $this->createApiCallWithRelativeUrl('list/filter/' . $searchParamsQuery, 'GET', $headers);
     $response = json_decode($response, true);
     $this->assertEquals(ApiResponse::STATUS_SUCCESS, $response['status']);
     $this->assertEquals(2, count($response['data']['items']));
     $this->assertEquals(5, $response['data']['totalCount']);
     $this->assertEquals(2, $response['data']['currentPage']);
     $this->assertEquals('First Contact', $response['data']['items'][0]['firstName']);
     $this->assertEquals('Fifth Contact', $response['data']['items'][1]['firstName']);
     // Search by custom fields, order by name desc
     $searchParams = array('pagination' => array('page' => 1, 'pageSize' => 3), 'search' => array('account' => array('id' => $account2->id), 'owner' => array('id' => $super->id)), 'sort' => 'firstName.desc');
     $searchParamsQuery = http_build_query($searchParams);
     $response = $this->createApiCallWithRelativeUrl('list/filter/' . $searchParamsQuery, 'GET', $headers);
     $response = json_decode($response, true);
     $this->assertEquals(ApiResponse::STATUS_SUCCESS, $response['status']);
     $this->assertEquals(2, $response['data']['totalCount']);
     $this->assertEquals(2, count($response['data']['items']));
     $this->assertEquals(1, $response['data']['currentPage']);
     $this->assertEquals('Forth Contact', $response['data']['items'][0]['firstName']);
     $this->assertEquals('Fifth Contact', $response['data']['items'][1]['firstName']);
 }
 protected function tearDown()
 {
     Category::deleteAll();
     Contact::deleteAll();
 }
Exemple #9
0
 static function deleteAll()
 {
     Contact::deleteAll();
 }
 public function testArePermissionsFlushedOnRemovingParentFromChildGroup()
 {
     // cleanup
     Contact::deleteAll();
     try {
         $group = Group::getByName('Child');
         $group->delete();
     } catch (NotFoundException $e) {
     }
     try {
         $user = User::getByUsername('jim');
         $user->delete();
     } catch (NotFoundException $e) {
     }
     // we could have used helpers to do a lot of the following stuff (such as creating users, groups,
     // etc) but we wanted to mimic user's interaction as closely as possible. Hence using walkthroughs
     // for everything
     // create Parent and Child Groups, Create Jim to be member of Child group
     // create parent group
     $this->resetGetArray();
     $this->setPostArray(array('Group' => array('name' => 'Parent')));
     $this->runControllerWithRedirectExceptionAndGetUrl('/zurmo/group/create');
     $parentGroup = Group::getByName('Parent');
     $this->assertNotNull($parentGroup);
     $this->assertEquals('Parent', strval($parentGroup));
     $parentGroupId = $parentGroup->id;
     // create child group
     $this->resetGetArray();
     $this->setPostArray(array('Group' => array('name' => 'Child', 'group' => array('id' => $parentGroupId))));
     $this->runControllerWithRedirectExceptionAndGetUrl('/zurmo/group/create');
     $childGroup = Group::getByName('Child');
     $this->assertNotNull($childGroup);
     $this->assertEquals('Child', strval($childGroup));
     $parentGroup->forgetAll();
     $parentGroup = Group::getById($parentGroupId);
     // give child rights for contacts module
     $childGroup->setRight('ContactsModule', ContactsModule::getAccessRight());
     $childGroup->setRight('ContactsModule', ContactsModule::getCreateRight());
     $this->assertTrue($childGroup->save());
     $childGroupId = $childGroup->id;
     $childGroup->forgetAll();
     $childGroup = Group::getById($childGroupId);
     $this->assertContains($childGroup, $parentGroup->groups);
     // create jim's user
     $this->resetGetArray();
     $this->setPostArray(array('UserPasswordForm' => array('firstName' => 'Some', 'lastName' => 'Body', 'username' => 'jim', 'newPassword' => 'myPassword123', 'newPassword_repeat' => 'myPassword123', 'officePhone' => '456765421', 'userStatus' => 'Active')));
     $this->runControllerWithRedirectExceptionAndGetContent('/users/default/create');
     $jim = User::getByUsername('jim');
     $this->assertNotNull($jim);
     // set jim's group to child group
     $this->setGetArray(array('id' => $childGroup->id));
     $this->setPostArray(array('GroupUserMembershipForm' => array('userMembershipData' => array($jim->id))));
     $this->runControllerWithRedirectExceptionAndGetUrl('/zurmo/group/editUserMembership');
     $jim->forgetAll();
     $jim = User::getByUsername('jim');
     $this->assertNotNull($jim);
     $childGroup->forgetAll();
     $childGroup = Group::getById($childGroupId);
     $this->assertContains($childGroup, $jim->groups);
     // create a contact with permissions to Parent group
     // create ContactStates
     ContactsModule::loadStartingData();
     // ensure contact states have been created
     $this->assertEquals(6, count(ContactState::GetAll()));
     // go ahead and create contact with parent group given readwrite.
     $startingState = ContactsUtil::getStartingState();
     $this->resetGetArray();
     $this->setPostArray(array('Contact' => array('firstName' => 'John', 'lastName' => 'Doe', 'officePhone' => '456765421', 'state' => array('id' => $startingState->id), 'explicitReadWriteModelPermissions' => array('type' => ExplicitReadWriteModelPermissionsUtil::MIXED_TYPE_NONEVERYONE_GROUP, 'nonEveryoneGroup' => $parentGroupId))));
     $url = $this->runControllerWithRedirectExceptionAndGetUrl('/contacts/default/create');
     $johnDoeContactId = intval(substr($url, strpos($url, 'id=') + 3));
     $johnDoeContact = Contact::getById($johnDoeContactId);
     $this->assertNotNull($johnDoeContact);
     $this->resetPostArray();
     $this->setGetArray(array('id' => $johnDoeContactId));
     $content = $this->runControllerWithNoExceptionsAndGetContent('/contacts/default/details');
     $this->assertContains('Who can read and write Parent', $content);
     // create a contact using jim which he would see at all times
     $this->logoutCurrentUserLoginNewUserAndGetByUsername('jim');
     $this->resetGetArray();
     $this->setPostArray(array('Contact' => array('firstName' => 'Jim', 'lastName' => 'Doe', 'officePhone' => '456765421', 'state' => array('id' => $startingState->id))));
     $url = $this->runControllerWithRedirectExceptionAndGetUrl('/contacts/default/create');
     $jimDoeContactId = intval(substr($url, strpos($url, 'id=') + 3));
     $jimDoeContact = Contact::getById($jimDoeContactId);
     $this->assertNotNull($jimDoeContact);
     $this->resetPostArray();
     $this->setGetArray(array('id' => $jimDoeContactId));
     $this->runControllerWithNoExceptionsAndGetContent('/contacts/default/details');
     // ensure jim can see that contact everywhere
     // jim should have access to see contact on list view
     $this->resetGetArray();
     // get the page, ensure the name of contact does show up there.
     $content = $this->runControllerWithNoExceptionsAndGetContent('/contacts/default');
     $this->assertContains('John Doe</a></td><td>', $content);
     $this->assertContains('Jim Doe</a></td><td>', $content);
     // jim should have access to jimDoeContact's detail view
     $this->setGetArray(array('id' => $jimDoeContactId));
     $this->runControllerWithNoExceptionsAndGetContent('/contacts/default/details');
     // jim should have access to jimDoeContact's edit view
     $this->runControllerWithNoExceptionsAndGetContent('/contacts/default/edit');
     // jim should have access to johnDoeContact's detail view
     $this->setGetArray(array('id' => $johnDoeContactId));
     $this->runControllerWithNoExceptionsAndGetContent('/contacts/default/details');
     // jim should have access to johnDoeContact's edit view
     $this->runControllerWithNoExceptionsAndGetContent('/contacts/default/edit');
     // unlink Parent group from child
     $this->logoutCurrentUserLoginNewUserAndGetByUsername('super');
     $this->setGetArray(array('id' => $childGroupId));
     $this->setPostArray(array('Group' => array('name' => 'Child', 'group' => array('id' => ''))));
     $this->runControllerWithRedirectExceptionAndGetUrl('/zurmo/group/edit');
     $childGroup = Group::getByName('Child');
     $this->assertNotNull($childGroup);
     $this->assertEquals('Child', strval($childGroup));
     $parentGroup->forgetAll();
     $parentGroup = Group::getById($parentGroupId);
     $this->assertNotContains($childGroup, $parentGroup->groups);
     // ensure jim can not see that contact anywhere
     // jim should not have access to see contact on list view
     $this->logoutCurrentUserLoginNewUserAndGetByUsername('jim');
     $this->resetGetArray();
     // get the page, ensure the name of contact does not show up there.
     $content = $this->runControllerWithNoExceptionsAndGetContent('/contacts/default');
     $this->assertNotContains('John Doe</a></td><td>', $content);
     $this->assertContains('Jim Doe</a></td><td>', $content);
     // jim should have access to jimDoeContact's detail view
     $this->setGetArray(array('id' => $jimDoeContactId));
     $this->runControllerWithNoExceptionsAndGetContent('/contacts/default/details');
     // jim should have access to jimDoeContact's edit view
     $this->runControllerWithNoExceptionsAndGetContent('/contacts/default/edit');
     // jim should not have access to johnDoeContact's detail view
     $this->setGetArray(array('id' => $johnDoeContactId));
     try {
         $this->runControllerWithNoExceptionsAndGetContent('/contacts/default/details');
         $this->fail('Accessing details action should have thrown ExitException');
     } catch (ExitException $e) {
         // just cleanup buffer
         $this->endAndGetOutputBuffer();
     }
     // jim should not have access to johnDoeContact's edit view
     try {
         $this->runControllerWithNoExceptionsAndGetContent('/contacts/default/edit');
         $this->fail('Accessing edit action should have thrown ExitException');
     } catch (ExitException $e) {
         // just cleanup buffer
         $this->endAndGetOutputBuffer();
     }
 }
 public function testImportWithLatestActivityDateTime()
 {
     Yii::app()->user->userModel = User::getByUsername('super');
     $contacts = Contact::deleteAll();
     $import = new Import();
     $serializedData['importRulesType'] = 'Contacts';
     $serializedData['firstRowIsHeaderRow'] = true;
     $import->serializedData = serialize($serializedData);
     $this->assertTrue($import->save());
     ImportTestHelper::createTempTableByFileNameAndTableName('importWithLatestActivityDateTimeTest.csv', $import->getTempTableName(), true, Yii::getPathOfAlias('application.modules.contacts.tests.unit.files'));
     $mappingData = array('column_0' => ImportMappingUtil::makeStringColumnMappingData('lastName'), 'column_1' => ContactImportTestHelper::makeStateColumnMappingData(), 'column_2' => ImportMappingUtil::makeDateTimeColumnMappingData('latestActivityDateTime'));
     $importRules = ImportRulesUtil::makeImportRulesByType('Contacts');
     $page = 0;
     $config = array('pagination' => array('pageSize' => 50));
     //This way all rows are processed.
     $dataProvider = new ImportDataProvider($import->getTempTableName(), true, $config);
     $dataProvider->getPagination()->setCurrentPage($page);
     $importResultsUtil = new ImportResultsUtil($import);
     $messageLogger = new ImportMessageLogger();
     ImportUtil::importByDataProvider($dataProvider, $importRules, $mappingData, $importResultsUtil, new ExplicitReadWriteModelPermissions(), $messageLogger);
     $importResultsUtil->processStatusAndMessagesForEachRow();
     //Confirm that 2 models where created.
     $contacts = Contact::getAll();
     $this->assertCount(2, $contacts);
     $this->assertEquals('2011-12-22 05:03', substr($contacts[0]->latestActivityDateTime, 0, -3));
     $this->assertNull($contacts[1]->latestActivityDateTime);
     //Confirm 2 rows were processed as 'created'.
     $this->assertEquals(2, ImportDatabaseUtil::getCount($import->getTempTableName(), "status = " . ImportRowDataResultsUtil::CREATED));
     //Confirm that 0 rows were processed as 'updated'.
     $this->assertEquals(0, ImportDatabaseUtil::getCount($import->getTempTableName(), "status = " . ImportRowDataResultsUtil::UPDATED));
     //Confirm 0 rows were processed as 'errors'.
     $this->assertEquals(0, ImportDatabaseUtil::getCount($import->getTempTableName(), "status = " . ImportRowDataResultsUtil::ERROR));
     $beansWithErrors = ImportDatabaseUtil::getSubset($import->getTempTableName(), "status = " . ImportRowDataResultsUtil::ERROR);
     $this->assertEquals(0, count($beansWithErrors));
 }
 /**
  * Walkthrough test for synchronous download
  */
 public function testAsynchronousDownloadDefaultControllerActions()
 {
     $super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super');
     $account = AccountTestHelper::createAccountByNameForOwner('superAccount2', $super);
     $notificationsBeforeCount = Notification::getCount();
     $notificationMessagesBeforeCount = NotificationMessage::getCount();
     Contact::deleteAll();
     $leads = array();
     for ($i = 0; $i <= ExportModule::$asynchronousThreshold + 1; $i++) {
         $leads[] = LeadTestHelper::createLeadWithAccountByNameForOwner('superContact' . $i, $super, $account);
     }
     $this->setGetArray(array('Contact_page' => '1', 'export' => '', 'ajax' => '', 'selectAll' => '1', 'selectedIds' => ''));
     $this->runControllerWithRedirectExceptionAndGetUrl('leads/default/export');
     // Start background job
     $job = new ExportJob();
     $this->assertTrue($job->run());
     $exportItems = ExportItem::getAll();
     $this->assertEquals(1, count($exportItems));
     $fileModel = $exportItems[0]->exportFileModel;
     $this->assertEquals(1, $exportItems[0]->isCompleted);
     $this->assertEquals('csv', $exportItems[0]->exportFileType);
     $this->assertEquals('leads', $exportItems[0]->exportFileName);
     $this->assertTrue($fileModel instanceof ExportFileModel);
     $this->assertEquals($notificationsBeforeCount + 1, Notification::getCount());
     $this->assertEquals($notificationMessagesBeforeCount + 1, NotificationMessage::getCount());
     // Check export job, when many ids are selected.
     // This will probably never happen, but we need test for this case too.
     $notificationsBeforeCount = Notification::getCount();
     $notificationMessagesBeforeCount = NotificationMessage::getCount();
     // Now test case when multiple ids are selected
     ExportItem::deleteAll();
     $selectedIds = "";
     foreach ($leads as $lead) {
         $selectedIds .= $lead->id . ",";
         // Not Coding Standard
     }
     $this->setGetArray(array('LeadsSearchForm' => array('anyMixedAttributesScope' => array(0 => 'All'), 'anyMixedAttributes' => '', 'fullName' => '', 'officePhone' => ''), 'multiselect_ContactsSearchForm_anyMixedAttributesScope' => 'All', 'Contact_page' => '1', 'export' => '', 'ajax' => '', 'selectAll' => '', 'selectedIds' => "{$selectedIds}"));
     $this->runControllerWithRedirectExceptionAndGetUrl('leads/default/export');
     // Start background job
     $job = new ExportJob();
     $this->assertTrue($job->run());
     $exportItems = ExportItem::getAll();
     $this->assertEquals(1, count($exportItems));
     $fileModel = $exportItems[0]->exportFileModel;
     $this->assertEquals(1, $exportItems[0]->isCompleted);
     $this->assertEquals('csv', $exportItems[0]->exportFileType);
     $this->assertEquals('leads', $exportItems[0]->exportFileName);
     $this->assertTrue($fileModel instanceof ExportFileModel);
     $this->assertEquals($notificationsBeforeCount + 1, Notification::getCount());
     $this->assertEquals($notificationMessagesBeforeCount + 1, NotificationMessage::getCount());
 }
Exemple #13
0
		</ul>

		<?php 
        break;
        // Delete account
    // Delete account
    case 'delete':
        if (!Config::get('auth.delete_account')) {
            redirect_to('?p=account');
        }
        if (isset($_POST['submit']) && csrf_filter()) {
            $id = Auth::user()->id;
            User::where('id', $id)->limit(1)->delete();
            Usermeta::delete($id);
            Message::newQuery()->where('to_user', $id)->orWhere('from_user', $id)->delete();
            Contact::deleteAll($id);
            Comments::deleteUserComments($id);
            Auth::logout();
            redirect_to(App::url());
        }
        ?>
		<h3 class="page-header"><?php 
        echo _e('main.delete_account');
        ?>
</h3>
		<?php 
        _e('main.delete_account_message');
        ?>
		<form action="" method="POST">
			<?php 
        csrf_input();
Exemple #14
0
function ajax_delete_user()
{
    if (!Auth::userCan('delete_users')) {
        json_message(trans('errors.permission'), false);
    }
    $id = isset($_POST['user_id']) ? (int) $_POST['user_id'] : 0;
    if (Auth::user()->id != $id) {
        User::where('id', $id)->limit(1)->delete();
        Usermeta::newQuery()->where('user_id', $id)->delete();
        Message::newQuery()->where('to_user', $id)->orWhere('from_user', $id)->delete();
        Contact::deleteAll($id);
        Comments::deleteUserComments($id);
    }
    json_message();
}