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.doctrine-project.org>. 20 */ 21 22/** 23 * Doctrine_Ticket_1860_TestCase 24 * 25 * @package Doctrine 26 * @license http://www.opensource.org/licenses/lgpl-license.php LGPL 27 * @category Object Relational Mapping 28 * @link www.doctrine-project.org 29 * @since 1.0 30 * @version $Revision$ 31 */ 32class Doctrine_Ticket_1860_TestCase extends Doctrine_UnitTestCase 33{ 34 public function prepareData() 35 { 36 // Create 10 users and mark them as deleted. 37 for ($i=0; $i<10; $i++) { 38 $user = new Ticket_1860_User; 39 $user->username = 'user' . $i; 40 $user->password = md5('user' . $i); 41 $user->save(); 42 $user->delete(); 43 } 44 } 45 46 public function prepareTables() 47 { 48 $this->tables = array('Ticket_1860_User'); 49 parent::prepareTables(); 50 } 51 52 public function testTicket() 53 { 54 Doctrine_Manager::getInstance()->setAttribute(Doctrine_Core::ATTR_USE_DQL_CALLBACKS, true); 55 56 $query1 = Doctrine_Query::create() 57 ->select('u.*') 58 ->from('Ticket_1860_User u'); 59 60 $this->assertEqual(count($query1->fetchArray()), 0); 61 62 $query2 = Doctrine_Query::create() 63 ->select('u.*') 64 ->from('Ticket_1860_User u'); 65 66 // Defining initial variables 67 $currentPage = 1; 68 $resultsPerPage = 5; 69 70 // Creating pager object 71 $pager = new Doctrine_Pager($query2, $currentPage, $resultsPerPage); 72 73 $this->assertEqual(count($pager->execute()->toArray()), 0); 74 $this->assertEqual($pager->getQuery()->getSqlQuery(), 'SELECT t.id AS t__id, t.username AS t__username, t.password AS t__password, t.deleted_at AS t__deleted_at FROM ticket_1860_users t WHERE (t.deleted_at IS NULL) LIMIT 5'); 75 76 Doctrine_Manager::getInstance()->setAttribute(Doctrine_Core::ATTR_USE_DQL_CALLBACKS, false); 77 } 78} 79 80class Ticket_1860_User extends Doctrine_Record 81{ 82 public function setTableDefinition() 83 { 84 $this->setTableName('ticket_1860_users'); 85 86 $this->hasColumn('id', 'integer', 4, array('type' => 'integer', 'unsigned' => '1', 'primary' => true, 'autoincrement' => true, 'length' => '4')); 87 $this->hasColumn('username', 'string', 45, array('type' => 'string', 'notnull' => true, 'unique' => true, 'length' => '45')); 88 $this->hasColumn('password', 'string', 45, array('type' => 'string', 'notnull' => true, 'length' => '45')); 89 } 90 91 public function setUp() 92 { 93 $softdelete0 = new Doctrine_Template_SoftDelete(); 94 $this->actAs($softdelete0); 95 } 96} 97