You are here

public function PartyAcquisitionTestCase::testPartyAcquisition in Party 7

Test Acquisition on Party Entities.

File

tests/party_acquisition.test, line 39
Acquisition Tests for the Party module.

Class

PartyAcquisitionTestCase
Test Core Party functionality

Code

public function testPartyAcquisition() {

  // Test the party_acquire function when there is no party with that email.
  $values['email'] = $this
    ->randomName() . '@example2.com';
  $context = array(
    'name' => 'test_acquisition',
    'behavior' => PartyAcquisitionInterface::BEHAVIOR_NOTHING,
  );
  $acquired_party = party_acquire($values, $context);
  $this
    ->assertFalse($acquired_party, t('party_acquire returned false when no match was found and the behavior was set to BEHAVIOR_NOTHING'));
  $context['behavior'] = PartyAcquisitionInterface::BEHAVIOR_CREATE;
  $acquired_party2 = party_acquire($values, $context, $method);
  $created_new_party = $acquired_party2 instanceof Party && empty($acquired_party2->pid);
  $this
    ->assertTrue($created_new_party, 'party_acquire returned a new Party when no match was found and the behavior was set to BEHAVIOR_CREATE');
  $this
    ->assertTrue($method == 'create', 'The method flag was set to create when a Party is created.');
  unset($method);

  // Test that the party acquire function returns the party with the right
  // email address.
  $values['email'] = $this->party->email;
  $acquired_party3 = party_acquire($values, $context, $method);
  $found_party = $acquired_party3->pid == $this->party->pid;
  $this
    ->assertTrue($found_party, 'party_aquire returned the correct party when a match was found.');
  $this
    ->assertTrue($method == 'acquire', 'The method flag was set to acquire when a Party is found.');
}