Skip to content

Commit

Permalink
Added more tests to person class
Browse files Browse the repository at this point in the history
Issue #20
Issue #29
  • Loading branch information
jeroenrnl committed Jan 26, 2015
1 parent 4f74db4 commit 8da34df
Showing 1 changed file with 181 additions and 0 deletions.
181 changes: 181 additions & 0 deletions UnitTests/personTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,191 @@ public function testCreatePerson($id, $first, $last, $user_id) {
}
}

/**
* Test adding a person to a photo
* @dataProvider getPersonAndPhotos();
*/
public function testAddRemovePhoto($id, $photo_id) {
$photo=new photo($photo_id);
$photo->lookup();

$people=$photo->getPeople();
$people_ids=array();
foreach($people as $p) {
$people_ids[]=$p->getId();
}

$this->assertNotContains($id, $people_ids);

$person=new person($id);

unset($photo);
$photo=new photo($photo_id);
$photo->lookup();
$person->addPhoto($photo);

$people=$photo->getPeople();
$people_ids=array();
foreach($people as $p) {
$people_ids[]=$p->getId();
}

$this->assertContains($id, $people_ids);

unset($person);
unset($people);
unset($people_ids);
unset($photo);
$photo=new photo($photo_id);

$person=new person($id);

$person->removePhoto($photo);

$people=$photo->getPeople();
$people_ids=array();
foreach($people as $p) {
$people_ids[]=$p->getId();
}

$this->assertNotContains($id, $people_ids);
}

/**
* Test adding a person to a photo
* @dataProvider getPersonAndPlaces();
*/
public function testLookupPlaces($id, $home_id, $work_id) {
$person=new person($id);

$person->set("home_id", $home_id);
$person->set("work_id", $work_id);

$person->update();

unset($person);
$person=new person($id);
$person->lookup();

$home=new place($home_id);
$home->lookup();

$work=new place($work_id);
$work->lookup();

$this->assertEquals($home, $person->home);
$this->assertEquals($work, $person->work);

}

public function testGetPhotoGrapher() {
$person=new person(3);

$photographer=$person->getPhotographer();

$this->assertInstanceOf("photographer", $photographer);
$this->assertEquals(3, $photographer->getId());
}

public function testDelete() {
$person=new person();
$person->insert();
$id=$person->getId();

$photo=new photo();
$photo->insert();
$photo->setPhotographer($person->getPhotographer());
$photo->addTo($person);
$photo->update();

$son1=new person();
$son1->set("father_id", $person->getId());
$son1->insert();

$son2=new person();
$son2->set("mother_id", $person->getId());
$son2->insert();

$spouse=new person();
$spouse->set("spouse_id", $person->getId());
$spouse->insert();

$person->delete();

$son1->lookup();
$son2->lookup();
$spouse->lookup();
$this->assertEmpty($son1->get("father_id"));
$this->assertEmpty($son2->get("mother_id"));
$this->assertEmpty($spouse->get("spouse_id"));
$this->assertEquals(array(), $photo->getPeople());

$person=new person($id);
$person->lookup();
$this->assertCount(1,$person->fields);
}

public function testGetDisplayArray() {
$person=new person();
$person->setName("Test Person");
$person->set("called", "Tester");
$person->set("dob", "1970-01-01");
$person->set("gender", 1);

$father=new person();
$father->setName("Father of Test");
$father->insert();
$f_id=$father->getId();

$mother=new person();
$mother->setName("Mother of Test");
$mother->insert();
$m_id=$mother->getId();

$spouse=new person();
$spouse->setName("Spouse of Test");
$spouse->insert();
$s_id=$spouse->getId();

$person->set("father_id", $f_id);
$person->set("mother_id", $m_id);
$person->set("spouse_id", $s_id);
$person->insert();

$exp=array(
"called" => "Tester",
"date of birth" => "<a href=\"calendar.php?date=1970-01-01&amp;search_field=date\">01-01-1970</a>",
"date of death" => null,
"gender" => "male",
"mother" => "<a href=\"person.php?person_id=" . $m_id . "\">Mother Test</a>",
"father" => "<a href=\"person.php?person_id=" . $f_id . "\">Father Test</a>",
"spouse" => "<a href=\"person.php?person_id=" . $s_id . "\">Spouse Test</a>"
);

$this->assertEquals($exp, $person->getDisplayArray());
}


public function getPeople() {
return array(
array(11, "First", "Last", null),
array(11, "First2", "Last2", 4)
);
}

public function getPersonAndPhotos() {
return array(
array(1,3),
array(2,4),
array(8,2)
);
}

public function getPersonAndPlaces() {
return array(
array(1,2,3),
array(2,1,1),
array(8,3,6)
);
}
}

0 comments on commit 8da34df

Please sign in to comment.