1
|
|
|
<?php |
2
|
|
|
require_once 'Intraface/Error.php'; |
3
|
|
|
require_once 'Intraface/Validator.php'; |
4
|
|
|
require_once 'Intraface/Address.php'; |
5
|
|
|
|
6
|
|
|
class AddressTest extends PHPUnit_Framework_TestCase |
7
|
|
|
{ |
8
|
|
|
|
9
|
|
|
private $kernel; |
|
|
|
|
10
|
|
|
|
11
|
|
|
function setUp() |
12
|
|
|
{ |
13
|
|
|
$db = MDB2::singleton(DB_DSN); |
14
|
|
|
$db->query('TRUNCATE address'); |
15
|
|
|
} |
16
|
|
|
|
17
|
|
|
function getValidAddress() |
18
|
|
|
{ |
19
|
|
|
return array('name' => 'test', 'address' => 'road 1', 'postcode' => '0123', 'city' => 'Mycity', 'country' => '', 'email' => '[email protected]', 'cvr' => '', 'website' => '', 'phone' => '', 'ean' => ''); |
20
|
|
|
} |
21
|
|
|
|
22
|
|
|
function testValidateWithValidAddress() |
23
|
|
|
{ |
24
|
|
|
|
25
|
|
|
$address = Intraface_Address::factory('intranet', 1); |
|
|
|
|
26
|
|
|
$this->assertTrue($address->validate($this->getValidAddress())); |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
function testValidateWithInvalidAddress() |
30
|
|
|
{ |
31
|
|
|
$address = Intraface_Address::factory('intranet', 1); |
|
|
|
|
32
|
|
|
$this->assertFalse($address->validate(array())); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
function testSaveOnEmptyDB() |
36
|
|
|
{ |
37
|
|
|
$address = Intraface_Address::factory('intranet', 1); |
|
|
|
|
38
|
|
|
$this->assertTrue($address->save($this->getValidAddress())); |
39
|
|
|
$this->assertEquals(1, $address->get('address_id')); // on empty database this must be 1 |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
function testSaveWithSaveTwoTimeWithSameData() |
43
|
|
|
{ |
44
|
|
|
$address = Intraface_Address::factory('intranet', 1); |
|
|
|
|
45
|
|
|
$address->save($this->getValidAddress()); |
46
|
|
|
|
47
|
|
|
|
48
|
|
|
// we repeat the save, this should automatically determine that nothing should be done. Can we determine whether this is true? |
49
|
|
|
$this->assertTrue($address->save($this->getValidAddress())); |
50
|
|
|
$this->assertEquals(1, $address->get('address_id')); // on empty database this must be 1 |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
function testSaveWithChangeInName() |
54
|
|
|
{ |
55
|
|
|
$address = Intraface_Address::factory('intranet', 1); |
|
|
|
|
56
|
|
|
|
57
|
|
|
$address_array = $this->getValidAddress(); |
58
|
|
|
|
59
|
|
|
$address = Intraface_Address::factory('intranet', 1); |
|
|
|
|
60
|
|
|
$address->save($address_array); |
61
|
|
|
|
62
|
|
|
$address_array['name'] = 'test 2'; |
63
|
|
|
$this->assertTrue($address->save($address_array)); |
64
|
|
|
$this->assertEquals(2, $address->get('address_id')); // on empty database this must be 1 |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
function testUpdate() |
68
|
|
|
{ |
69
|
|
|
/* |
|
|
|
|
70
|
|
|
Da metoden er fjernet fra klassen er testen ogs� fjernet. |
71
|
|
|
$address = Address::factory('intranet', 1); |
72
|
|
|
$address->save($this->getValidAddress()); |
73
|
|
|
$this->assertTrue($address->update($this->getValidAddress())); |
74
|
|
|
$this->assertEquals(1, $address->get('address_id')); // on empty database this must be 1 |
75
|
|
|
*/ |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
function testLoad() |
79
|
|
|
{ |
80
|
|
|
$address = Intraface_Address::factory('intranet', 1); |
|
|
|
|
81
|
|
|
$address->save($this->getValidAddress()); |
82
|
|
|
|
83
|
|
|
$address = new Intraface_Address(1); |
84
|
|
|
$this->assertEquals(1, $address->get('address_id')); |
85
|
|
|
} |
86
|
|
|
} |
87
|
|
|
|
This check marks private properties in classes that are never used. Those properties can be removed.