From dcc3bd8c7d10ba04cfff92d018b395e83c631af5 Mon Sep 17 00:00:00 2001 From: zYne Date: Tue, 5 Jun 2007 18:38:00 +0000 Subject: [PATCH] --- lib/Doctrine/AuditLog.php | 44 +++++++++++++++++-- tests/AuditLogTestCase.php | 59 ++++++++++++++++++++++++++ tests/ColumnAliasTestCase.php | 10 ++--- tests/CustomResultSetOrderTestCase.php | 6 +-- tests/Query/MultiJoin2TestCase.php | 5 +-- tests/classes.php | 4 +- 6 files changed, 111 insertions(+), 17 deletions(-) create mode 100644 tests/AuditLogTestCase.php diff --git a/lib/Doctrine/AuditLog.php b/lib/Doctrine/AuditLog.php index 7befc7e01..f79686ee8 100644 --- a/lib/Doctrine/AuditLog.php +++ b/lib/Doctrine/AuditLog.php @@ -29,10 +29,48 @@ * @version $Revision$ * @author Konsta Vesterinen */ -class Doctrine_AuditLog +class Doctrine_AuditLog { - public function audit(Doctrine_Table $table) + public function audit() { - + + } + public function deleteTriggerSql(Doctrine_Table $table) + { + $conn = $table->getConnection(); + $columnNames = $table->getColumnNames(); + $oldColumns = array_map(array($this, 'formatOld'), $columnNames); + $sql = 'CREATE TRIGGER ' + . $conn->quoteIdentifier($table->getTableName()) . '_ddt' . ' DELETE ON ' + . $conn->quoteIdentifier($table->getTableName()) + . ' BEGIN' + . ' INSERT INTO ' . $table->getTableName() . '_dvt (' + . implode(', ', array_map(array($conn, 'quoteIdentifier'), $columnNames)) + . ') VALUES (' + . implode(', ', array_map(array($conn, 'quoteIdentifier'), $oldColumns)) + . ');' + . ' END;'; + return $sql; + } + public function updateTriggerSql(Doctrine_Table $table) + { + $conn = $table->getConnection(); + $columnNames = $table->getColumnNames(); + $oldColumns = array_map(array($this, 'formatOld'), $columnNames); + $sql = 'CREATE TRIGGER ' + . $conn->quoteIdentifier($table->getTableName()) . '_dut' . ' UPDATE ON ' + . $conn->quoteIdentifier($table->getTableName()) + . ' BEGIN' + . ' INSERT INTO ' . $table->getTableName() . '_dvt (' + . implode(', ', array_map(array($conn, 'quoteIdentifier'), $columnNames)) + . ') VALUES (' + . implode(', ', array_map(array($conn, 'quoteIdentifier'), $oldColumns)) + . ');' + . ' END;'; + return $sql; + } + public function formatOld($column) + { + return 'old.' . $column; } } diff --git a/tests/AuditLogTestCase.php b/tests/AuditLogTestCase.php new file mode 100644 index 000000000..5e2243e16 --- /dev/null +++ b/tests/AuditLogTestCase.php @@ -0,0 +1,59 @@ +. + */ + +/** + * Doctrine_AuditLog_TestCase + * + * @package Doctrine + * @author Konsta Vesterinen + * @license http://www.opensource.org/licenses/lgpl-license.php LGPL + * @category Object Relational Mapping + * @link www.phpdoctrine.com + * @since 1.0 + * @version $Revision$ + */ +class Doctrine_AuditLog_TestCase extends Doctrine_UnitTestCase +{ + public function prepareData() + { } + public function prepareTables() + { } + public function testUpdateTriggerSqlReturnsProperQuery() + { + $table = $this->conn->getTable('User'); + + $auditLog = new Doctrine_AuditLog(); + + $sql = $auditLog->updateTriggerSql($table); + + $this->assertEqual($sql, 'CREATE TRIGGER entity_dut UPDATE ON entity BEGIN INSERT INTO entity_dvt (id, name, loginname, password, type, created, updated, email_id) VALUES (old.id, old.name, old.loginname, old.password, old.type, old.created, old.updated, old.email_id); END;'); + } + public function testDeleteTriggerSqlReturnsProperQuery() + { + $table = $this->conn->getTable('User'); + + $auditLog = new Doctrine_AuditLog(); + + $sql = $auditLog->deleteTriggerSql($table); + + $this->assertEqual($sql, 'CREATE TRIGGER entity_ddt DELETE ON entity BEGIN INSERT INTO entity_dvt (id, name, loginname, password, type, created, updated, email_id) VALUES (old.id, old.name, old.loginname, old.password, old.type, old.created, old.updated, old.email_id); END;'); + } +} diff --git a/tests/ColumnAliasTestCase.php b/tests/ColumnAliasTestCase.php index 78bf4d1aa..ce46e9194 100644 --- a/tests/ColumnAliasTestCase.php +++ b/tests/ColumnAliasTestCase.php @@ -56,9 +56,9 @@ class Doctrine_ColumnAlias_TestCase extends Doctrine_UnitTestCase $q = new Doctrine_Query(); $q->select('c.alias1, c.alias2')->from('ColumnAliasTest c'); - + $coll = $q->execute(); - + $this->assertEqual($coll[0]->alias1, 'someone'); $this->assertEqual($coll[0]->alias2, 187); } @@ -71,10 +71,10 @@ class Doctrine_ColumnAlias_TestCase extends Doctrine_UnitTestCase ->where('c.alias1 = ?'); $coll = $q->execute(array('someone')); - + $this->assertEqual($coll[0]->alias1, 'someone'); $this->assertEqual($coll[0]->alias2, 187); - } + } public function testAliasesAreSupportedForDqlAggregateFunctions() { $q = new Doctrine_Query(); @@ -83,7 +83,7 @@ class Doctrine_ColumnAlias_TestCase extends Doctrine_UnitTestCase ->from('ColumnAliasTest c'); $coll = $q->execute(); - + $this->assertEqual($coll[0]->max, 'someone'); } public function testAliasesAreSupportedForDqlHavingPart() diff --git a/tests/CustomResultSetOrderTestCase.php b/tests/CustomResultSetOrderTestCase.php index 73e4d3c74..917fca2dc 100644 --- a/tests/CustomResultSetOrderTestCase.php +++ b/tests/CustomResultSetOrderTestCase.php @@ -99,7 +99,7 @@ class Doctrine_CustomResultSetOrder_TestCase extends Doctrine_UnitTestCase { public function testQueryWithOrdering2() { $q = new Doctrine_Query($this->connection); - print '
';
+
         $categories = $q->select('c.*, b.*')
                 ->from('CategoryWithPosition c')
                 ->leftJoin('c.Boards b')
@@ -160,12 +160,12 @@ class Doctrine_CustomResultSetOrder_TestCase extends Doctrine_UnitTestCase {
                 case 'First':
                     // The first category should have 3 boards, right?
                     // It has only 1! The other two slipped to the 2nd category!
-                    print $category->Boards->count();
+
                     $this->assertEqual(3, $category->Boards->count());
                 break;
                 case 'Second':
                     // The second category should have 1 board, but it got 3 now
-                    print $category->Boards->count();
+
                     $this->assertEqual(1, $category->Boards->count());
                 break;
                 case 'Third':
diff --git a/tests/Query/MultiJoin2TestCase.php b/tests/Query/MultiJoin2TestCase.php
index d3916480c..0f9e7dc54 100644
--- a/tests/Query/MultiJoin2TestCase.php
+++ b/tests/Query/MultiJoin2TestCase.php
@@ -102,12 +102,9 @@ class Doctrine_Query_MultiJoin2_TestCase extends Doctrine_UnitTestCase
                     ->where('c.parentCategoryId = 0')
                     ->orderBy('c.position ASC, subCats.position ASC, b.position ASC')
                     ->execute(array(), Doctrine::FETCH_ARRAY);
-            //echo "
";
-            //var_dump($categories);
-            //echo "
"; $this->pass(); } catch (Doctrine_Exception $e) { - $this->fail(); + $this->fail(); } } } diff --git a/tests/classes.php b/tests/classes.php index 5246b1554..cf8f3ae9f 100644 --- a/tests/classes.php +++ b/tests/classes.php @@ -655,8 +655,8 @@ class QueryTest_Category extends Doctrine_Record */ public function setUp() { - $this->ownsMany('QueryTest_Category as subCategories','subCategories.parentCategoryId'); - $this->hasOne('QueryTest_Category as rootCategory','QueryTest_Category.rootCategoryId'); + $this->ownsMany('QueryTest_Category as subCategories', 'subCategories.parentCategoryId'); + $this->hasOne('QueryTest_Category as rootCategory', 'QueryTest_Category.rootCategoryId'); $this->ownsMany('QueryTest_Board as boards', 'QueryTest_Board.categoryId'); } }