summaryrefslogtreecommitdiff
path: root/tests/unit/Data/TableGateway/TableGatewayPgsqlTest.php
blob: fae1f394535126494c62431f4bf445f500d3303f (plain)
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
59
60
61
62
63
64
65
66
<?php
require_once(dirname(__FILE__).'/BaseGateway.php');

/**
 * @package System.Data.TableGateway
 */
class TableGatewayPgsqlTest extends BaseGateway
{
    public function setUp()
    {
        if (!extension_loaded('pgsql')) {
            $this->markTestSkipped(
              'The pgsql extension is not available.'
            );
        }
    }

	function test_update()
	{
		$this->add_record1();
		$address = array('username' => 'tester 1', 'field5_text'=>null);
		$result = $this->getGateway()->update($address, 'username = ?', 'Username');
		$this->assertTrue($result);

		$test = $this->getGateway()->find('username = ?', 'tester 1');
		unset($test['id']);
		$expect = $this->get_record1();
		$expect['username'] = 'tester 1';
		$expect['field5_text'] = null;
		unset($expect['field7_timestamp']); unset($test['field7_timestamp']);
		$this->assertEquals($expect, $test);

		$this->assertTrue($this->getGateway()->deleteAll('username = ?', 'tester 1'));
	}

	function test_update_named()
	{
		$this->add_record1();
		$address = array('username' => 'tester 1', 'field5_text'=>null);
		$result = $this->getGateway()->update($address, 'username = :name', array(':name'=>'Username'));
		$this->assertTrue($result);

		$test = $this->getGateway()->find('username = :name', array(':name'=>'tester 1'));
		unset($test['id']);
		$expect = $this->get_record1();
		$expect['username'] = 'tester 1';
		$expect['field5_text'] = null;
		unset($expect['field7_timestamp']); unset($test['field7_timestamp']);
		$this->assertEquals($expect, $test);

		$this->assertTrue($this->getGateway()->deleteAll('username = :name', array(':name'=>'tester 1')));
	}

	function test_find_all()
	{
		$this->add_record1();
		$this->add_record2();

		$results = $this->getGateway()->findAll('true')->readAll();
		$this->assertEquals(count($results), 2);

		$result = $this->getGateway()->findAllBySql('SELECT username FROM address WHERE phone = ?', '45233')->read();
		$this->assertEquals($result['username'], 'record2');
	}

}