-
Notifications
You must be signed in to change notification settings - Fork 0
/
contact_tests.php
58 lines (51 loc) · 1.41 KB
/
contact_tests.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<?PHP
require_once("AbstractModel.php");
require_once("Contact.php");
error_reporting(E_ERROR | E_WARNING);
$contact = new Contact();
$contact->load(1);
print_r($contact->getData());
// Should print:
// id => 1,
// name => John Doe
// email => [email protected]
echo '<br/><br/>';
echo $contact->getData('name');
//Should print:
// John Doe
$contact->setData('name', 'John Walker')->save(); //Should run an UPDATE query
echo '<br/><br/>';
print_r($contact->load(1)->getData());
//Should print
// id => 1,
// name => John Walker
// email => [email protected]
$contact->setData(array(
"id" => 1,
"name" => "John Doe the 2nd",
"email" => "[email protected]"
))->save();
echo '<br/><br/>';
print_r($contact->load(1)->getData());
//Should print
// id => 1,
// name => John Doe the 2nd
// email => [email protected]
$newContact = new Contact();
$newContact->setData(array(
"name" => "Gilbert Barber",
"email" => "[email protected]"
));
$newContact->save(); //Should run an INSERT query as there is no predefined id
print_r($newContact->getData());
//Should print
// id => ? some auto increment number,
// name => Gilbert Barber
// email => [email protected]
$newContact->delete(); //Should delete him Gilbert Barber from the database
// Added this line to reset row for testing.
$contact->setData(array(
"id" => 1,
"name" => "John Doe",
"email" => "[email protected]"
))->save();