tests
[m6w6/pq-gateway] / tests / lib / pq / Gateway / RowTest.php
diff --git a/tests/lib/pq/Gateway/RowTest.php b/tests/lib/pq/Gateway/RowTest.php
new file mode 100644 (file)
index 0000000..28d2728
--- /dev/null
@@ -0,0 +1,53 @@
+<?php
+
+namespace pq\Gateway;
+
+include_once __DIR__."/../../../setup.inc";
+
+class RowTest extends \PHPUnit_Framework_TestCase {
+
+       /**
+        * @var \pq\Connection
+        */
+       protected $conn;
+       
+       /**
+        * @var \pq\Gateway\Table
+        */
+       protected $table;
+
+       protected function setUp() {
+               $this->conn = new \pq\Connection(PQ_DSN);
+               $this->conn->exec(PQ_TEST_DROP_TABLE);
+               $this->conn->exec(PQ_TEST_CREATE_TABLE);
+               $this->conn->exec(PQ_TEST_CREATE_DATA);
+               
+               $this->table = new Table(PQ_TEST_TABLE_NAME, $this->conn);
+       }
+
+       protected function tearDown() {
+               $this->conn->exec(PQ_TEST_DROP_TABLE);
+       }
+
+       function testBasic() {
+               $row = new Row($this->table, array("id" => 3), true);
+               $this->assertTrue($row->isDirty());
+               $row->refresh();
+               $this->assertSame(
+                       array(
+                               "id" => "3",
+                               "created" => date("Y-m-d H:i:s", strtotime("tomorrow")),
+                               "counter" => "1",
+                               "number" => "1.1",
+                               "data" => "tomorrow"
+                       ),
+                       $row->getData()
+               );
+               $this->assertFalse($row->isDirty());
+       }
+       
+       function testGetTable() {
+               $row = new Row($this->table);
+               $this->assertSame($this->table, $row->getTable());
+       }
+}