Beispiel #1
0
 /**
  * Test basic UI operations with Activities.
  *
  * Create a contact.
  * Add activity of every type to contact.
  * Assert activities listed on Activities tab listing page.
  * Edit every activity. Assert activities changed from listing page.
  * Delete every activity. Assert they disappeared from listing page.
  */
 public function testActivityOperations()
 {
     // Create and login user. User should be able to create contacts and
     // activities.
     $user = $this->drupalCreateUser(array('administer crm_core_contact entities', 'view any crm_core_contact entity', 'administer crm_core_activity entities'));
     $this->drupalLogin($user);
     // Create Household contact.
     $household = Contact::create(array('name' => 'Fam. Smith', 'type' => 'household'));
     $household->save();
     $this->drupalGet('crm-core/activity');
     $this->assertText(t('There are no activities available.'), 'No activities available.');
     $this->assertLink(t('Add an activity'));
     $this->drupalGet('crm-core/activity/add');
     $this->assertLink(t('Add Meeting'));
     $this->assertLink(t('Add Phone call'));
     // Create Meeting activity. Ensure it it listed.
     $meeting_activity = array('title[0][value]' => 'Pellentesque', 'activity_date[0][value][date]' => $this->randomDate(), 'activity_date[0][value][time]' => $this->randomTime(), 'activity_notes[0][value]' => $this->randomString(), 'activity_participants[0][target_id]' => $household->label() . ' (' . $household->id() . ')');
     $this->drupalPostForm('crm-core/activity/add/meeting', $meeting_activity, 'Save Activity');
     $this->assertText('Activity Pellentesque created.', 'No errors after adding new activity.');
     // Create Meeting activity. Ensure it it listed.
     $phonecall_activity = array('title[0][value]' => 'Mollis', 'activity_date[0][value][date]' => $this->randomDate(), 'activity_date[0][value][time]' => $this->randomTime(), 'activity_notes[0][value]' => $this->randomString(), 'activity_participants[0][target_id]' => $household->label() . ' (' . $household->id() . ')');
     $this->drupalPostForm('crm-core/activity/add/phone_call', $phonecall_activity, 'Save Activity');
     $this->assertText('Activity Mollis created.', 'No errors after adding new activity.');
     // Update activity and assert its title changed on the list.
     $meeting_activity = array('title[0][value]' => 'Vestibulum');
     $this->drupalPostForm('crm-core/activity/1/edit', $meeting_activity, 'Save Activity');
     $this->assertText('Vestibulum', 'Activity updated.');
     $this->drupalGet('crm-core/activity');
     $this->assertLink('Vestibulum', 0, 'Updated activity listed properly.');
     // Update phone call activity and assert its title changed on the list.
     $phonecall_activity = array('title[0][value]' => 'Commodo');
     $this->drupalPostForm('crm-core/activity/2/edit', $phonecall_activity, 'Save Activity');
     $this->assertText('Commodo', 'Activity updated.');
     $this->drupalGet('crm-core/activity');
     $this->assertLink('Commodo', 0, 'Updated activity listed properly.');
     // Delete Meeting activity.
     $this->drupalPostForm('crm-core/activity/1/delete', array(), 'Delete');
     $this->assertText('Meeting Vestibulum has been deleted.', 'No errors after deleting activity.');
     $this->drupalGet('crm-core/activity');
     $this->assertNoLink('Vestibulum', 'Deleted activity is no more listed.');
     // Delete Phone call activity.
     $this->drupalPostForm('crm-core/activity/2/delete', array(), 'Delete');
     $this->assertText('Phone call Commodo has been deleted.', 'No errors after deleting activity.');
     $this->drupalGet('crm-core/activity');
     $this->assertNoLink('Commodo', 'Deleted activity is no more listed.');
     // Assert there is no activities left.
     $this->drupalGet('crm-core/activity');
     $this->assertText(t('There are no activities available.'), 'No activities listed.');
 }
 /**
  * Test the email field.
  */
 public function testEmail()
 {
     FieldStorageConfig::create(array('entity_type' => 'crm_core_contact', 'type' => 'email', 'field_name' => 'contact_mail'))->save();
     FieldConfig::create(array('field_name' => 'contact_mail', 'entity_type' => 'crm_core_contact', 'bundle' => 'individual', 'label' => t('Email'), 'required' => FALSE))->save();
     $config = array('value' => array('operator' => '=', 'score' => 42));
     $contact_needle = Contact::create(array('type' => 'individual'));
     $contact_needle->set('contact_mail', '*****@*****.**');
     $contact_needle->save();
     $contact_match = Contact::create(array('type' => 'individual'));
     $contact_match->set('contact_mail', '*****@*****.**');
     $contact_match->save();
     $config['field'] = $contact_needle->getFieldDefinition('contact_mail');
     /* @var \Drupal\crm_core_match\Plugin\crm_core_match\field\FieldHandlerInterface $text */
     $text = $this->pluginManager->createInstance('email', $config);
     $ids = $text->match($contact_needle);
     $this->assertTrue(array_key_exists($contact_match->id(), $ids), 'Text match returns expected match');
     $this->assertEqual(42, $ids[$contact_match->id()]['contact_mail.value'], 'Got expected match score');
 }
 /**
  * Tests CRUD of contacts.
  *
  * @todo Check if working once https://drupal.org/node/2239969 got committed.
  */
 public function testContact()
 {
     $this->installEntitySchema('user');
     $type = ContactType::create(array('type' => 'test'));
     $type->primary_fields = [];
     $type->save();
     // Create.
     $contact = Contact::create(array('type' => $type->type));
     $this->assertEqual(SAVED_NEW, $contact->save(), 'Contact saved.');
     // Load.
     $contact_load = Contact::load($contact->id());
     $uuid = $contact_load->uuid();
     $this->assertTrue(!empty($uuid), 'Loaded contact has uuid.');
     // Delete.
     $contact->delete();
     $contact_load = Contact::load($contact->id());
     $this->assertNull($contact_load, 'Contact deleted.');
 }
Beispiel #4
0
 /**
  * Tests the contact type operations.
  *
  * User with permissions 'administer contact types' should be able to
  * create/edit/delete contact types.
  */
 public function testContactTypeOperations()
 {
     // Given I am logged in as a user with permission 'administer contact types'
     $user = $this->drupalCreateUser(array('administer contact types'));
     $this->drupalLogin($user);
     // When I visit the contact type admin page.
     $this->drupalGet('admin/structure/crm-core/contact-types');
     // Then I should see edit, enable, delete but no enable links for existing
     // contacts.
     $this->assertContactTypeLink('household', 'Edit link for household.');
     $this->assertContactTypeLink('household/disable', 'Disable link for household.');
     $this->assertNoContactTypeLink('household/enable', 'No enable link for household.');
     $this->assertContactTypeLink('household/delete', 'Delete link for household.');
     $this->assertcontacttypelink('individual', 'Edit link for individual.');
     $this->assertcontacttypelink('individual/disable', 'Disable link for individual.');
     $this->assertNoContacttypelink('individual/enable', 'No enable link for individual.');
     $this->assertcontacttypelink('individual/delete', 'Delete link for individual.');
     $this->assertcontacttypelink('organization', 'Edit link for organization.');
     $this->assertcontacttypelink('organization/disable', 'Disable link for organization.');
     $this->assertNoContacttypelink('organization/enable', 'No enable link for organization.');
     $this->assertcontacttypelink('organization/delete', 'Delete link for organization.');
     // Given the 'household' contact type is disabled.
     $this->drupalPostForm('admin/structure/crm-core/contact-types/household/disable', array(), 'Disable');
     // When I visit the contact type admin page.
     $this->drupalGet('admin/structure/crm-core/contact-types');
     // Then I should see an enable link.
     $this->assertContactTypeLink('household/enable', 'Enable link for household.');
     // And I should not see a disable link.
     $this->assertNoContactTypeLink('household/disable', 'No disable link for household.');
     // When I enable 'household'
     $this->drupalPostForm('admin/structure/crm-core/contact-types/household/enable', array(), 'Enable');
     // Then I should see a disable link.
     $this->assertContactTypeLink('household/disable', 'Disable link for household.');
     // Given there is a contact of type 'individual.'.
     Contact::create(array('type' => 'individual'))->save();
     // When I visit the contact type admin page.
     $this->drupalGet('admin/structure/crm-core/contact-types');
     // Then I should not see a delete link.
     $this->assertNoContactTypeLink('individual/delete', 'No delete link for individual.');
     // When I edit the organization type.
     $this->drupalGet('admin/structure/crm-core/contact-types/organization');
     // Then I should see a delete link.
     $this->assertContactTypeLink('organization/delete', 'Delete link on organization type form.');
     // When I edit the individual type.
     $this->drupalGet('admin/structure/crm-core/contact-types/individual');
     // @todo Assert for a positive fact to ensure being on the correct page.
     // Then I should not see a delete link.
     $this->assertNoContactTypeLink('individual/delete', 'No delete link on individual type form.');
 }