1
|
|
|
<?php |
2
|
|
|
require_once 'Intraface/modules/contact/Contact.php'; |
3
|
|
|
require_once 'ContactStubs.php'; |
4
|
|
|
|
5
|
|
|
class ContactTest extends PHPUnit_Framework_TestCase |
6
|
|
|
{ |
7
|
|
|
|
8
|
|
|
private $kernel; |
|
|
|
|
9
|
|
|
|
10
|
|
|
function setUp() |
11
|
|
|
{ |
12
|
|
|
$db = MDB2::singleton(DB_DSN); |
13
|
|
|
$db->query('TRUNCATE address'); |
14
|
|
|
$db->query('TRUNCATE contact'); |
15
|
|
|
} |
16
|
|
|
|
17
|
|
|
function getKernel() |
18
|
|
|
{ |
19
|
|
|
$kernel = new Stub_Kernel; |
20
|
|
|
return $kernel; |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
///////////////////////////////////////////////////////// |
24
|
|
|
|
25
|
|
|
function testConstruction() |
26
|
|
|
{ |
27
|
|
|
$contact = new Contact($this->getKernel()); |
28
|
|
|
$this->assertTrue(is_object($contact)); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
function testNeedOptin() |
32
|
|
|
{ |
33
|
|
|
$contact = new Contact($this->getKernel(), 7); |
34
|
|
|
$array = $contact->needNewsletterOptin(); |
35
|
|
|
$this->assertTrue(is_array($array)); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
function testSave() |
39
|
|
|
{ |
40
|
|
|
$contact = new Contact($this->getKernel(), 7); |
41
|
|
|
$data = array('name' => 'Test', 'email' => '[email protected]', 'phone' => '98468269'); |
42
|
|
|
$this->assertTrue($contact->save($data) > 0); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
function testGetSimilarContacts() |
46
|
|
|
{ |
47
|
|
|
$contact = new Contact($this->getKernel()); |
48
|
|
|
$data = array('name' => 'Test', 'email' => '[email protected]', 'phone' => '98468269'); |
49
|
|
|
$contact->save($data); |
50
|
|
|
|
51
|
|
|
$contact = new Contact($this->getKernel()); |
52
|
|
|
$data = array('name' => 'Tester 1', 'email' => '[email protected]', 'phone' => '26176860'); |
53
|
|
|
$contact->save($data); |
54
|
|
|
|
55
|
|
|
$this->assertTrue($contact->hasSimilarContacts()); |
56
|
|
|
|
57
|
|
|
$similar_contacts = $contact->getSimilarContacts(); |
58
|
|
|
|
59
|
|
|
$this->assertEquals(1, count($similar_contacts)); |
60
|
|
|
} |
61
|
|
|
} |
62
|
|
|
|
This check marks private properties in classes that are never used. Those properties can be removed.