Commit 11ee3cf9 authored by dbrewer's avatar dbrewer

Added test case for #587, and models to support that test case.

parent 175d3307
<?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));
}
}
<?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);
}
}
<?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);
}
}
<?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());
}
}
}
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment