Added test case for #587, and models to support that test case.
This commit is contained in:
parent
175d3307c2
commit
11ee3cf9ad
9
models/Bookmark.php
Normal file
9
models/Bookmark.php
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
<?php
|
||||||
|
class Bookmark extends Doctrine_Record
|
||||||
|
{
|
||||||
|
public function setTableDefinition()
|
||||||
|
{
|
||||||
|
$this->hasColumn('user_id', 'integer', null, array('primary' => true));
|
||||||
|
$this->hasColumn('page_id', 'integer', null, array('primary' => true));
|
||||||
|
}
|
||||||
|
}
|
14
models/BookmarkUser.php
Normal file
14
models/BookmarkUser.php
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
<?php
|
||||||
|
class BookmarkUser extends Doctrine_Record
|
||||||
|
{
|
||||||
|
public function setUp()
|
||||||
|
{
|
||||||
|
$this->hasMany('Bookmark as Bookmarks',
|
||||||
|
array('local' => 'id',
|
||||||
|
'foreign' => 'user_id'));
|
||||||
|
}
|
||||||
|
public function setTableDefinition()
|
||||||
|
{
|
||||||
|
$this->hasColumn('name', 'string', 30);
|
||||||
|
}
|
||||||
|
}
|
17
models/Page.php
Normal file
17
models/Page.php
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
<?php
|
||||||
|
class Page extends Doctrine_Record
|
||||||
|
{
|
||||||
|
|
||||||
|
public function setUp()
|
||||||
|
{
|
||||||
|
$this->hasMany('Bookmark as Bookmarks',
|
||||||
|
array('local' => 'id',
|
||||||
|
'foreign' => 'page_id'));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setTableDefinition()
|
||||||
|
{
|
||||||
|
$this->hasColumn('name', 'string', 30);
|
||||||
|
$this->hasColumn('url', 'string', 100);
|
||||||
|
}
|
||||||
|
}
|
106
tests/Ticket/587TestCase.php
Normal file
106
tests/Ticket/587TestCase.php
Normal file
@ -0,0 +1,106 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Doctrine_Ticket_587_TestCase
|
||||||
|
*
|
||||||
|
* @package Doctrine
|
||||||
|
* @author David Brewer <dbrewer@secondstory.com>
|
||||||
|
* @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_Ticket_587_TestCase extends Doctrine_UnitTestCase
|
||||||
|
{
|
||||||
|
public function prepareTables()
|
||||||
|
{
|
||||||
|
$this->tables = array_merge($this->tables, array('BookmarkUser', 'Bookmark', 'Page'));
|
||||||
|
parent::prepareTables();
|
||||||
|
}
|
||||||
|
public function prepareData()
|
||||||
|
{
|
||||||
|
parent::prepareData();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testInit()
|
||||||
|
{
|
||||||
|
$user = new BookmarkUser();
|
||||||
|
$user['name'] = 'Anonymous';
|
||||||
|
$user->save();
|
||||||
|
|
||||||
|
$pages = new Doctrine_Collection('Page');
|
||||||
|
$pages[0]['name'] = 'Yahoo';
|
||||||
|
$pages[0]['url'] = 'http://www.yahoo.com';
|
||||||
|
$pages->save();
|
||||||
|
|
||||||
|
$this->assertEqual(count($pages), 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This test case demonstrates an issue with the identity case in the
|
||||||
|
* Doctrine_Table class. The brief summary is that if you create a
|
||||||
|
* record, then delete it, then create another record with the same
|
||||||
|
* primary keys, the record can get into a state where it is in the
|
||||||
|
* database but may appear to be marked as TCLEAN under certain
|
||||||
|
* circumstances (such as when it comes back as part of a collection).
|
||||||
|
* This makes the $record->exists() method return false, which prevents
|
||||||
|
* the record from being deleted among other things.
|
||||||
|
*/
|
||||||
|
public function testIdentityMapAndRecordStatus()
|
||||||
|
{
|
||||||
|
// load our user and our collection of pages
|
||||||
|
$user = Doctrine_Query::create()->query(
|
||||||
|
'SELECT * FROM BookmarkUser u WHERE u.name=?', array('Anonymous')
|
||||||
|
)->getFirst();
|
||||||
|
$pages = Doctrine_Query::create()->query('SELECT * FROM Page');
|
||||||
|
|
||||||
|
// bookmark the pages (manually)
|
||||||
|
foreach ($pages as $page) {
|
||||||
|
$bookmark = new Bookmark();
|
||||||
|
$bookmark['page_id'] = $page['id'];
|
||||||
|
$bookmark['user_id'] = $user['id'];
|
||||||
|
$bookmark->save();
|
||||||
|
}
|
||||||
|
|
||||||
|
// select all bookmarks
|
||||||
|
$bookmarks = Doctrine_Manager::connection()->query(
|
||||||
|
'SELECT * FROM Bookmark b'
|
||||||
|
);
|
||||||
|
$this->assertEqual(count($bookmarks), 1);
|
||||||
|
|
||||||
|
// verify that they all exist
|
||||||
|
foreach ($bookmarks as $bookmark) {
|
||||||
|
$this->assertTrue($bookmark->exists());
|
||||||
|
}
|
||||||
|
|
||||||
|
// now delete them all.
|
||||||
|
$user['Bookmarks']->delete();
|
||||||
|
|
||||||
|
// verify count when accessed directly from database
|
||||||
|
$bookmarks = Doctrine_Query::create()->query(
|
||||||
|
'SELECT * FROM Bookmark'
|
||||||
|
);
|
||||||
|
$this->assertEqual(count($bookmarks), 0);
|
||||||
|
|
||||||
|
// now recreate bookmarks and verify they exist:
|
||||||
|
foreach ($pages as $page) {
|
||||||
|
$bookmark = new Bookmark();
|
||||||
|
$bookmark['page_id'] = $page['id'];
|
||||||
|
$bookmark['user_id'] = $user['id'];
|
||||||
|
$bookmark->save();
|
||||||
|
}
|
||||||
|
|
||||||
|
// select all bookmarks for the user
|
||||||
|
$bookmarks = Doctrine_Manager::connection()->query(
|
||||||
|
'SELECT * FROM Bookmark b'
|
||||||
|
);
|
||||||
|
$this->assertEqual(count($bookmarks), 1);
|
||||||
|
|
||||||
|
// verify that they all exist
|
||||||
|
foreach ($bookmarks as $bookmark) {
|
||||||
|
$this->assertTrue($bookmark->exists());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -13,6 +13,7 @@ $test = new DoctrineTest();
|
|||||||
$tickets = new GroupTest('Tickets tests', 'tickets');
|
$tickets = new GroupTest('Tickets tests', 'tickets');
|
||||||
$tickets->addTestCase(new Doctrine_Ticket_Njero_TestCase());
|
$tickets->addTestCase(new Doctrine_Ticket_Njero_TestCase());
|
||||||
$tickets->addTestCase(new Doctrine_Ticket_428_TestCase());
|
$tickets->addTestCase(new Doctrine_Ticket_428_TestCase());
|
||||||
|
$tickets->addTestCase(new Doctrine_Ticket_587_TestCase());
|
||||||
//If you write a ticket testcase add it here like shown above!
|
//If you write a ticket testcase add it here like shown above!
|
||||||
$test->addTestCase($tickets);
|
$test->addTestCase($tickets);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user