This commit is contained in:
parent
b036987973
commit
dcc3bd8c7d
@ -31,8 +31,46 @@
|
||||
*/
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
59
tests/AuditLogTestCase.php
Normal file
59
tests/AuditLogTestCase.php
Normal file
@ -0,0 +1,59 @@
|
||||
<?php
|
||||
/*
|
||||
* $Id$
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the LGPL. For more information, see
|
||||
* <http://www.phpdoctrine.com>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Doctrine_AuditLog_TestCase
|
||||
*
|
||||
* @package Doctrine
|
||||
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
|
||||
* @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;');
|
||||
}
|
||||
}
|
@ -99,7 +99,7 @@ class Doctrine_CustomResultSetOrder_TestCase extends Doctrine_UnitTestCase {
|
||||
|
||||
public function testQueryWithOrdering2() {
|
||||
$q = new Doctrine_Query($this->connection);
|
||||
print '<pre>';
|
||||
|
||||
$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':
|
||||
|
@ -102,9 +102,6 @@ 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 "<pre>";
|
||||
//var_dump($categories);
|
||||
//echo "</pre>";
|
||||
$this->pass();
|
||||
} catch (Doctrine_Exception $e) {
|
||||
$this->fail();
|
||||
|
Loading…
x
Reference in New Issue
Block a user