public function PartyTestCase::testPartyCRUD in Party 7
Same name and namespace in other branches
- 8.2 tests/party.test \PartyTestCase::testPartyCRUD()
Test CRUD on the Party Entities
File
- tests/
party.test, line 125 - Tests for the Party module.
Class
- PartyTestCase
- Test Core Party functionality
Code
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'), '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', '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', '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);
// 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)');
}