| 1 | <?php |
|---|
| 2 | /* |
|---|
| 3 | * $Id$ |
|---|
| 4 | * |
|---|
| 5 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
|---|
| 6 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
|---|
| 7 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
|---|
| 8 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
|---|
| 9 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
|---|
| 10 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
|---|
| 11 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
|---|
| 12 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
|---|
| 13 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
|---|
| 14 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
|---|
| 15 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|---|
| 16 | * |
|---|
| 17 | * This software consists of voluntary contributions made by many individuals |
|---|
| 18 | * and is licensed under the LGPL. For more information, see |
|---|
| 19 | * <http://www.phpdoctrine.com>. |
|---|
| 20 | */ |
|---|
| 21 | |
|---|
| 22 | /** |
|---|
| 23 | * Doctrine_AuditLog_TestCase |
|---|
| 24 | * |
|---|
| 25 | * @package Doctrine |
|---|
| 26 | * @author Konsta Vesterinen <kvesteri@cc.hut.fi> |
|---|
| 27 | * @license http://www.opensource.org/licenses/lgpl-license.php LGPL |
|---|
| 28 | * @category Object Relational Mapping |
|---|
| 29 | * @link www.phpdoctrine.com |
|---|
| 30 | * @since 1.0 |
|---|
| 31 | * @version $Revision$ |
|---|
| 32 | */ |
|---|
| 33 | class Doctrine_AuditLog_TestCase extends Doctrine_UnitTestCase |
|---|
| 34 | { |
|---|
| 35 | |
|---|
| 36 | public function prepareData() |
|---|
| 37 | { } |
|---|
| 38 | |
|---|
| 39 | public function prepareTables() |
|---|
| 40 | { |
|---|
| 41 | $this->profiler = new Doctrine_Connection_Profiler(); |
|---|
| 42 | $this->conn->addListener($this->profiler); |
|---|
| 43 | $this->tables = array('VersioningTest', 'VersioningTestVersion'); |
|---|
| 44 | |
|---|
| 45 | parent::prepareTables(); |
|---|
| 46 | } |
|---|
| 47 | |
|---|
| 48 | public function testVersioningListenerListensAllManipulationOperations() |
|---|
| 49 | { |
|---|
| 50 | $entity = new VersioningTest(); |
|---|
| 51 | |
|---|
| 52 | $entity->name = 'zYne'; |
|---|
| 53 | $entity->save(); |
|---|
| 54 | $this->assertEqual($entity->version, 1); |
|---|
| 55 | |
|---|
| 56 | $entity->name = 'zYne 2'; |
|---|
| 57 | $entity->save(); |
|---|
| 58 | $this->assertEqual($entity->name, 'zYne 2'); |
|---|
| 59 | |
|---|
| 60 | $this->conn->clear(); |
|---|
| 61 | |
|---|
| 62 | $entity = $this->conn->getTable('VersioningTest')->find(1); |
|---|
| 63 | |
|---|
| 64 | $this->assertEqual($entity->name, 'zYne 2'); |
|---|
| 65 | $this->assertEqual($entity->version, 2); |
|---|
| 66 | |
|---|
| 67 | $entity->delete(); |
|---|
| 68 | $this->assertEqual($entity->version, 3); |
|---|
| 69 | |
|---|
| 70 | $entity->revert(2); |
|---|
| 71 | |
|---|
| 72 | $this->assertEqual($entity->name, 'zYne 2'); |
|---|
| 73 | $this->assertEqual($entity->version, 2); |
|---|
| 74 | |
|---|
| 75 | $entity->revert(1); |
|---|
| 76 | |
|---|
| 77 | $this->assertEqual($entity->name, 'zYne'); |
|---|
| 78 | $this->assertEqual($entity->version, 1); |
|---|
| 79 | |
|---|
| 80 | } |
|---|
| 81 | |
|---|
| 82 | public function testRevertThrowsExceptionForTransientRecords() |
|---|
| 83 | { |
|---|
| 84 | $entity = new VersioningTest(); |
|---|
| 85 | |
|---|
| 86 | try { |
|---|
| 87 | $entity->revert(1); |
|---|
| 88 | $this->fail(); |
|---|
| 89 | } catch (Doctrine_Record_Exception $e) { |
|---|
| 90 | $this->pass(); |
|---|
| 91 | } |
|---|
| 92 | } |
|---|
| 93 | |
|---|
| 94 | public function testReturnFalseIfVersionTableExists() |
|---|
| 95 | { |
|---|
| 96 | //$entity = new VersioningTest(); |
|---|
| 97 | //$entity_table = $entity->getTable(); |
|---|
| 98 | //$auditLog = new Doctrine_AuditLog(array("table" => $entity_table)); |
|---|
| 99 | //$this->assertFalse($auditLog->buildDefinition($entity_table)); |
|---|
| 100 | } |
|---|
| 101 | } |
|---|