You are here

class PartyTestCase in Party 8.2

Same name and namespace in other branches
  1. 7 tests/party.test \PartyTestCase

Test Core Party functionality

Hierarchy

Expanded class hierarchy of PartyTestCase

File

tests/party.test, line 66
Tests for the Party module.

View source
class PartyTestCase extends PartyBaseTestCase {
  protected $privileged_user;
  public static function getInfo() {
    return array(
      'name' => 'Party',
      'description' => 'Party CRUD test.',
      'group' => 'Party',
    );
  }
  public function setUp() {
    parent::setUp('party');

    // Enable any modules required for the test
    $this->privileged_user = $this
      ->drupalCreateUser(array(
      'administer crm settings',
      'administer parties',
      'create parties',
      'view parties',
    ));
    $this
      ->drupalLogin($this->privileged_user);
  }

  /**
   * Test CRUD on the Party Entities
   */
  public function testPartyCRUD() {

    // Test Party Creation.
    $this
      ->drupalGet('admin/community');
    $this
      ->clickLink('Add party');

    // Assert that the add party page exists and is accessible.
    $this
      ->assertRaw(t('Add party'), t('Add Party page found'));
    $this
      ->drupalPost(null, array(), t('Save'));

    // Test Reading Parties.
    $this
      ->drupalGet('admin/community');

    // Assert that the created party appears on the Party List page.
    $this
      ->assertRaw('Party 1', t('Test Party found'));

    // Assert that there is a party with pid 1 in the database.
    $this
      ->assertNotNull(db_query("SELECT pid FROM {party} WHERE pid = 1"), 'Party with pid = 1 found in db');

    // Test Updating Parties.
    // @TODO Need to add field to main profile and make sure it works with Party?
    // @TODO Also change the Party label?
    // Test Party Deletion.
    $this
      ->drupalGet('admin/community');
    $this
      ->clickLink('delete');
    $this
      ->drupalPost(null, array(), t('Confirm'));
    $this
      ->drupalGet('admin/community');

    // Assert that Party no longer appears on the Party List page (admin/community).
    $this
      ->assertNoRaw('Party 1', t('Test Party not found (delete worked)'));

    ///////////////////////////////////////////////////////////////////////////

    //                   Party CRUD Programmatically

    ///////////////////////////////////////////////////////////////////////////

    // Test Party Creation.
    $party = party_create();
    $party
      ->save();

    // Assert the Party Object was Created and Saved.
    $this
      ->assertNotNull($party);

    // Assert that a pid has been set.
    $this
      ->assertNotNull($party->pid);

    // Assert that the Party Label has been generated correctly.
    $this
      ->assertEqual($party->label, 'Party ' . $party->pid);

    // Test Reading Parties.
    $pid = $party->pid;
    unset($party);
    $party = party_load($pid);

    // Assert that party_load has returned an object (and not FALSE).
    $this
      ->assertTrue(is_object($party));

    // Asset that correct party has been loaded.
    $this
      ->assertEqual($pid, $party->pid);

    // Test Updating Parties
    // @TODO Need to do some sort of update.
    // Test Party Deletion
    party_delete($party);

    // Assert that the Party can no longer be loaded.
    $this
      ->assertFalse(party_load($pid));

    // Make sure there is no party with the deleted party's pid in database.
    $result = db_query("SELECT pid FROM {party} WHERE pid = :pid", array(
      ':pid' => $pid,
    ))
      ->fetchField();

    // Assert that no Party was found with this pid.
    $this
      ->assertFalse($result, 'Party with pid = ' . $pid . ' not found in db (delete worked)');
  }

}

Members

Namesort descending Modifiers Type Description Overrides
PartyBaseTestCase::createTestProfile2 public function Create a test profile2 type and return the profile2 type machine name.
PartyTestCase::$privileged_user protected property
PartyTestCase::getInfo public static function
PartyTestCase::setUp public function
PartyTestCase::testPartyCRUD public function Test CRUD on the Party Entities