tests
[m6w6/pq-gateway] / tests / lib / pq / Gateway / CellTest.php
diff --git a/tests/lib/pq/Gateway/CellTest.php b/tests/lib/pq/Gateway/CellTest.php
new file mode 100644 (file)
index 0000000..0afd0e3
--- /dev/null
@@ -0,0 +1,53 @@
+<?php
+
+namespace pq\Gateway;
+
+include __DIR__."/../../../setup.inc";
+
+class CellTest 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);
+       }
+
+       /**
+        * This is very bad test…
+        */
+       public function testBasic() {
+               $row = $this->table->find(null, "id desc", 1)->current();
+               foreach ($row->getData() as $key => $val) {
+                       $this->assertEquals($val, (string) $row->$key);
+                       $this->assertFalse($row->$key->isExpr());
+                       $this->assertFalse($row->$key->isDirty());
+                       $this->assertSame($val, $row->$key->get());
+                       $row->$key->mod(123);
+                       $this->assertNotEquals($val, (string) $row->$key);
+                       $this->assertTrue($row->$key->isExpr());
+                       $this->assertTrue($row->$key->isDirty());
+                       $this->assertNotSame($val, $row->$key->get());
+                       $this->assertEquals("$key + 123", (string) $row->$key->get());
+                       $row->$key->mod("foobar");
+                       $this->assertEquals("$key + 123 || 'foobar'", (string) $row->$key);
+                       $row->$key->mod(new \pq\Query\Expr(" - %s()", "now"));
+                       $this->assertEquals("$key + 123 || 'foobar' - now()", (string) $row->$key);
+               }
+       }
+}