diff --git a/tests/CustomResultSetOrderTestCase.php b/tests/CustomResultSetOrderTestCase.php new file mode 100644 index 000000000..7c83ee08d --- /dev/null +++ b/tests/CustomResultSetOrderTestCase.php @@ -0,0 +1,110 @@ +position = 0; + $cat1->name = "First"; + + $cat2 = new CategoryWithPosition(); + $cat2->position = 0; // same 'priority' as the first + $cat2->name = "Second"; + + $cat3 = new CategoryWithPosition(); + $cat3->position = 1; + $cat3->name = "Third"; + + $board1 = new BoardWithPosition(); + $board1->position = 0; + + $board2 = new BoardWithPosition(); + $board2->position = 1; + + $board3 = new BoardWithPosition(); + $board3->position = 2; + + // The first category gets 3 boards! + $cat1->Boards[0] = $board1; + $cat1->Boards[1] = $board2; + $cat1->Boards[2] = $board3; + + $board4 = new BoardWithPosition(); + $board4->position = 0; + + // The second category gets 1 board! + $cat2->Boards[0] = $board4; + + $this->connection->flush(); + } + + /** + * Prepares the tables. + */ + public function prepareTables() { + $this->tables[] = "CategoryWithPosition"; + $this->tables[] = "BoardWithPosition"; + parent::prepareTables(); + } + + /** + * Checks whether the boards are correctly assigned to the categories. + * + * The 'evil' result set that confuses the object population is displayed below. + * + * catId | catPos | catName | boardPos | board.category_id + * 1 | 0 | First | 0 | 1 + * 2 | 0 | Second | 0 | 2 <-- The split that confuses the object population + * 1 | 0 | First | 1 | 1 + * 1 | 0 | First | 2 | 1 + * 3 | 2 | Third | NULL + */ + public function testQueryWithOrdering() { + $categories = $this->connection->query("FROM CategoryWithPosition.Boards + ORDER BY CategoryWithPosition.position ASC, CategoryWithPosition.Boards.position ASC"); + + // Check each category + foreach ($categories as $category) { + + switch ($category->name) { + case "First": + // The first category should have 3 boards, right? + // It has only 1! The other two slipped to the 2nd category! + $this->assertEqual(3, $category->Boards->count()); + break; + case "Second": + // The second category should have 1 board, but it got 3 now + $this->assertEqual(1, $category->Boards->count()); + break; + case "Third": + // The third has no boards as expected. + $this->assertEqual(0, $category->Boards->count()); + break; + } + + } + } + +} + + + + + + + + + + + + + + +?> \ No newline at end of file diff --git a/tests/classes.php b/tests/classes.php index 97001b59c..39c6d08fd 100644 --- a/tests/classes.php +++ b/tests/classes.php @@ -1,525 +1,543 @@ -ownsOne("Email","Entity.email_id"); - $this->ownsMany("Phonenumber","Phonenumber.entity_id"); - $this->ownsOne("Account","Account.entity_id"); - $this->hasMany("Entity","EntityReference.entity1-entity2"); - } - public function setTableDefinition() { - $this->hasColumn("id","integer",20,"autoincrement|primary"); - $this->hasColumn("name","string",50); - $this->hasColumn("loginname","string",20,"unique"); - $this->hasColumn("password","string",16); - $this->hasColumn("type","integer",1); - $this->hasColumn("created","integer",11); - $this->hasColumn("updated","integer",11); - $this->hasColumn("email_id","integer"); - } -} -class FieldNameTest extends Doctrine_Record { - public function setTableDefinition() { - $this->hasColumn("someColumn", "string", 200, array('default' => 'some string')); - $this->hasColumn("someEnum", "enum", 4, array('default' => 'php')); - $this->hasColumn("someArray", "array", 100, array('default' => array())); - $this->hasColumn("someObject", "object", 200, array('default' => new stdClass)); - $this->hasColumn("someInt", "integer", 20, array('default' => 11)); - - - $this->setEnumValues("someEnum", array('php', 'java', 'python')); - } -} -class EntityReference extends Doctrine_Record { - public function setTableDefinition() { - $this->hasColumn("entity1","integer"); - $this->hasColumn("entity2","integer"); - $this->setPrimaryKey(array("entity1","entity2")); - } -} -class Account extends Doctrine_Record { - public function setTableDefinition() { - $this->hasColumn("entity_id","integer"); - $this->hasColumn("amount","integer"); - } -} - -class EntityAddress extends Doctrine_Record { - public function setTableDefinition() { - $this->hasColumn("entity_id","integer"); - $this->hasColumn("address_id","integer"); - } -} - -class Address extends Doctrine_Record { - public function setUp() { - $this->hasMany("User","Entityaddress.entity_id"); - } - public function setTableDefinition() { - $this->hasColumn("address","string",200); - } -} - -// grouptable doesn't extend Doctrine_Table -> Doctrine_Connection -// won't initialize grouptable when Doctrine_Connection->getTable("Group") is called - -class GroupTable { } -class Group extends Entity { - public function setUp() { - parent::setUp(); - $this->hasMany("User","Groupuser.user_id"); - $this->setInheritanceMap(array("type"=>1)); - - } -} -class Error extends Doctrine_Record { - public function setUp() { - $this->ownsMany("Description","Description.file_md5","file_md5"); - } - public function setTableDefinition() { - $this->hasColumn("message","string",200); - $this->hasColumn("code","integer",11); - $this->hasColumn("file_md5","string",32,"primary"); - } -} -class Description extends Doctrine_Record { - public function setTableDefinition() { - $this->hasColumn("description","string",3000); - $this->hasColumn("file_md5","string",32); - } -} -class UserTable extends Doctrine_Table { } -class User extends Entity { - public function setUp() { - parent::setUp(); - $this->hasMany("Address","Entityaddress.address_id"); - $this->ownsMany("Album","Album.user_id"); - $this->ownsMany("Book", "Book.user_id"); - $this->hasMany("Group","Groupuser.group_id"); - $this->setInheritanceMap(array("type"=>0)); - } -} -class Groupuser extends Doctrine_Record { - public function setTableDefinition() { - $this->hasColumn("added","integer"); - $this->hasColumn("group_id","integer"); - $this->hasColumn("user_id","integer"); - } -} -class Phonenumber extends Doctrine_Record { - public function setTableDefinition() { - $this->hasColumn("phonenumber","string",20); - $this->hasColumn("entity_id","integer"); - } - public function setUp() { - $this->hasOne("Entity", "Phonenumber.entity_id"); - } -} - -class Element extends Doctrine_Record { - public function setTableDefinition() { - $this->hasColumn("name", "string", 100); - $this->hasColumn("parent_id", "integer"); - } - public function setUp() { - $this->hasMany("Element as Child","Child.parent_id"); - $this->hasOne("Element as Parent","Element.parent_id"); - } -} -class Email extends Doctrine_Record { - public function setTableDefinition() { - $this->hasColumn("address","string",150,"email|unique"); - } -} -class Book extends Doctrine_Record { - public function setUp() { - $this->ownsMany("Author","Author.book_id"); - } - public function setTableDefinition() { - $this->hasColumn("user_id","integer"); - $this->hasColumn("name","string",20); - } -} -class Author extends Doctrine_Record { - public function setTableDefinition() { - $this->hasColumn("book_id","integer"); - $this->hasColumn("name","string",20); - } -} -class Album extends Doctrine_Record { - public function setUp() { - $this->ownsMany("Song","Song.album_id"); - } - public function setTableDefinition() { - $this->hasColumn("user_id","integer"); - $this->hasColumn("name","string",20); - } -} -class Song extends Doctrine_Record { - public function setTableDefinition() { - $this->hasColumn("album_id","integer"); - $this->hasColumn("genre","string",20); - $this->hasColumn("title","string",30); - } -} - -class Task extends Doctrine_Record { - public function setUp() { - $this->hasMany("Resource as ResourceAlias","Assignment.resource_id"); - $this->hasMany("Task as Subtask","Subtask.parent_id"); - } - public function setTableDefinition() { - $this->hasColumn("name","string",100); - $this->hasColumn("parent_id","integer"); - } -} - -class Resource extends Doctrine_Record { - public function setUp() { - $this->hasMany("Task as TaskAlias", "Assignment.task_id"); - $this->hasMany("ResourceType as Type", "ResourceReference.type_id"); - } - public function setTableDefinition() { - $this->hasColumn("name","string",100); - } -} -class ResourceReference extends Doctrine_Record { - public function setTableDefinition() { - $this->hasColumn("type_id","integer"); - $this->hasColumn("resource_id","integer"); - } -} -class ResourceType extends Doctrine_Record { - public function setUp() { - $this->hasMany("Resource as ResourceAlias", "ResourceReference.resource_id"); - } - public function setTableDefinition() { - $this->hasColumn("type","string",100); - } -} -class Assignment extends Doctrine_Record { - public function setTableDefinition() { - $this->hasColumn("task_id","integer"); - $this->hasColumn("resource_id","integer"); - } -} -class Forum_Category extends Doctrine_Record { - public function setTableDefinition() { - $this->hasColumn("root_category_id", "integer", 10); - $this->hasColumn("parent_category_id", "integer", 10); - $this->hasColumn("name", "string", 50); - $this->hasColumn("description", "string", 99999); - } - public function setUp() { - $this->hasMany("Forum_Category as Subcategory", "Subcategory.parent_category_id"); - $this->hasOne("Forum_Category as Parent", "Forum_Category.parent_category_id"); - $this->hasOne("Forum_Category as Rootcategory", "Forum_Category.root_category_id"); - } -} -class Forum_Board extends Doctrine_Record { - public function setTableDefinition() { - $this->hasColumn("category_id", "integer", 10); - $this->hasColumn("name", "string", 100); - $this->hasColumn("description", "string", 5000); - } - public function setUp() { - $this->hasOne("Forum_Category as Category", "Forum_Board.category_id"); - $this->ownsMany("Forum_Thread as Threads", "Forum_Thread.board_id"); - } -} - -class Forum_Entry extends Doctrine_Record { - public function setTableDefinition() { - $this->hasColumn("author", "string", 50); - $this->hasColumn("topic", "string", 100); - $this->hasColumn("message", "string", 99999); - $this->hasColumn("parent_entry_id", "integer", 10); - $this->hasColumn("thread_id", "integer", 10); - $this->hasColumn("date", "integer", 10); - } - public function setUp() { - $this->hasOne("Forum_Entry as Parent", "Forum_Entry.parent_entry_id"); - $this->hasOne("Forum_Thread as Thread", "Forum_Entry.thread_id"); - } -} - -class Forum_Thread extends Doctrine_Record { - public function setTableDefinition() { - $this->hasColumn("board_id", "integer", 10); - $this->hasColumn("updated", "integer", 10); - $this->hasColumn("closed", "integer", 1); - } - public function setUp() { - $this->hasOne("Forum_Board as Board", "Forum_Thread.board_id"); - $this->ownsMany("Forum_Entry as Entries", "Forum_Entry.thread_id"); - } -} -class App extends Doctrine_Record { - public function setTableDefinition() { - $this->hasColumn("name", "string", 32); - $this->hasColumn("user_id", "integer", 11); - $this->hasColumn("app_category_id", "integer", 11); - } - public function setUp() { - $this->hasOne("User","User.id"); - $this->hasMany("App_Category as Category","App_Category.id"); - } -} - -class App_User extends Doctrine_Record { - public function setTableDefinition() { - $this->hasColumn("first_name", "string", 32); - $this->hasColumn("last_name", "string", 32); - $this->hasColumn("email", "string", 128, "email"); - $this->hasColumn("username", "string", 16, "unique, nospace"); - $this->hasColumn("password", "string", 128, "notblank"); - $this->hasColumn("country", "string", 2, "country"); - $this->hasColumn("zipcode", "string", 9, "nospace"); - } - public function setUp() { - $this->hasMany("App","App.user_id"); - } -} - -class App_Category extends Doctrine_Record { - public function setTableDefinition() { - $this->hasColumn("name", "string", 32); - $this->hasColumn("parent_id","integer"); - } - public function setUp() { - $this->hasMany("App","App.app_category_id"); - $this->hasMany("App_Category as Parent","App_Category.parent_id"); - } -} - -class ORM_TestEntry extends Doctrine_Record { - public function setTableDefinition() { - $this->setTableName('test_entries'); - $this->hasColumn("id", "integer", 11, "autoincrement|primary"); - $this->hasColumn("name", "string", 255); - $this->hasColumn("stamp", "timestamp"); - $this->hasColumn("amount", "float"); - $this->hasColumn("itemID", "integer"); - } - - public function setUp() { - $this->hasOne("ORM_TestItem", "ORM_TestEntry.itemID"); - } -} - -class ORM_TestItem extends Doctrine_Record { - public function setTableDefinition() { - $this->setTableName('test_items'); - $this->hasColumn("id", "integer", 11, "autoincrement|primary"); - $this->hasColumn("name", "string", 255); - } - - public function setUp() { - - $this->hasOne("ORM_TestEntry", "ORM_TestEntry.itemID"); - } -} -class ORM_AccessControl extends Doctrine_Record { - public function setTableDefinition() { - $this->hasColumn("name", "string", 255); - } - public function setUp() { - $this->hasMany("ORM_AccessGroup as accessGroups", "ORM_AccessControlsGroups.accessGroupID"); - } -} - -class ORM_AccessGroup extends Doctrine_Record { - public function setTableDefinition() { - $this->hasColumn("name", "string", 255); - } - public function setUp() { - $this->hasMany("ORM_AccessControl as accessControls", "ORM_AccessControlsGroups.accessControlID"); - } -} - -class ORM_AccessControlsGroups extends Doctrine_Record { - public function setTableDefinition() { - $this->hasColumn("accessControlID", "integer", 11); - $this->hasColumn("accessGroupID", "integer", 11); - - $this->setPrimaryKey(array("accessControlID", "accessGroupID")); - } -} -class EnumTest extends Doctrine_Record { - public function setTableDefinition() { - $this->hasColumn("status","enum",11); - $this->setEnumValues("status", array("open","verified","closed")); - } -} -class FilterTest extends Doctrine_Record { - public function setTableDefinition() { - $this->hasColumn("name","string",100); - } - public function setUp() { - $this->ownsMany("FilterTest2 as filtered", "FilterTest2.test1_id"); - } -} -class FilterTest2 extends Doctrine_Record { - public function setTableDefinition() { - $this->hasColumn("name","string",100); - $this->hasColumn("test1_id","integer"); - } -} -class CustomPK extends Doctrine_Record { - public function setTableDefinition() { - $this->hasColumn("uid","integer",11,"autoincrement|primary"); - $this->hasColumn("name","string",255); - } -} -class Log_Entry extends Doctrine_Record { - public function setTableDefinition() { - $this->hasColumn("stamp", "timestamp"); - $this->hasColumn("status_id", "integer"); - } - public function setUp() { - $this->hasOne("Log_Status", "Log_Entry.status_id"); - } -} -class CPK_Test extends Doctrine_Record { - public function setTableDefinition() { - $this->hasColumn("name", "string", 255); - } - public function setUp() { - $this->hasMany("CPK_Test2 as Test","CPK_Association.test2_id"); - } -} -class CPK_Test2 extends Doctrine_Record { - public function setTableDefinition() { - $this->hasColumn("name", "string", 255); - } - public function setUp() { - $this->hasMany("CPK_Test as Test","CPK_Association.test1_id"); - } -} -class CPK_Association extends Doctrine_Record { - public function setTableDefinition() { - $this->hasColumn("test1_id", "integer", 11, "primary"); - $this->hasColumn("test2_id", "integer", 11, "primary"); - } -} -class Log_Status extends Doctrine_Record { - public function setTableDefinition() { - $this->hasColumn("name", "string", 255); - } -} -class ValidatorTest extends Doctrine_Record { - public function setTableDefinition() { - $this->hasColumn("mymixed","string", 100); - $this->hasColumn("mystring","string", 100, "notnull|unique"); - $this->hasColumn("myarray", "array", 1000); - $this->hasColumn("myobject", "object", 1000); - $this->hasColumn("myinteger", "integer", 11); - $this->hasColumn("myrange", "integer", 11, array('range' => array(4,123))); - $this->hasColumn("myregexp", "string", 5, array('regexp' => '^[0-9]+$')); - - $this->hasColumn("myemail", "string", 100, "email"); - $this->hasColumn("myemail2", "string", 100, "email|notblank"); - } -} -class DateTest extends Doctrine_Record { - public function setTableDefinition() { - $this->hasColumn("date", "date", 20); - } -} -class GzipTest extends Doctrine_Record { - public function setTableDefinition() { - $this->hasColumn("gzip", "gzip", 100000); - } -} - -class Tag extends Doctrine_Record { - public function setUp() { - $this->hasMany("Photo", "Phototag.photo_id"); - } - public function setTableDefinition() { - $this->hasColumn("tag", "string", 100); - } -} -class Photo extends Doctrine_Record { - public function setUp() { - $this->hasMany("Tag", "Phototag.tag_id"); - } - public function setTableDefinition() { - $this->hasColumn("name", "string", 100); - } -} - -class Phototag extends Doctrine_Record { - public function setTableDefinition() { - $this->hasColumn("photo_id", "integer"); - $this->hasColumn("tag_id", "integer"); - } -} - -class BooleanTest extends Doctrine_Record { - public function setTableDefinition() { - $this->hasColumn('is_working', 'boolean'); - } -} -class Data_File extends Doctrine_Record { - public function setTableDefinition() { - $this->hasColumn("filename", "string"); - $this->hasColumn("file_owner_id", "integer"); - } - public function setUp() { - $this->hasOne("File_Owner", "Data_File.file_owner_id"); - } -} -class NotNullTest extends Doctrine_Record { - public function setTableDefinition() { - $this->hasColumn("name", "string", 100, "notnull"); - $this->hasColumn("type", "integer", 11); - } -} -class File_Owner extends Doctrine_Record { - public function setTableDefinition() { - $this->hasColumn("name", "string", 255); - } - public function setUp() { - $this->hasOne("Data_File", "Data_File.file_owner_id"); - } -} -class MyUser extends Doctrine_Record { - public function setTableDefinition() { - $this->hasColumn("name", "string"); - } - public function setUp() { - $this->hasMany("MyOneThing", "MyOneThing.user_id"); - $this->hasMany("MyOtherThing", "MyOtherThing.user_id"); - } -} -class MyOneThing extends Doctrine_Record { - public function setTableDefinition() { - $this->hasColumn("name", "string"); - $this->hasColumn("user_id", "integer"); - } - public function setUp() { - $this->hasMany("MyUserOneThing", "MyUserOneThing.one_thing_id"); - } -} -class MyOtherThing extends Doctrine_Record { - public function setTableDefinition() { - $this->hasColumn("name", "string"); - $this->hasColumn("user_id", "integer"); - } - public function setUp() { - $this->hasMany("MyUserOtherThing", "MyUserOtherThing.other_thing_id"); - } -} -class MyUserOneThing extends Doctrine_Record { - public function setTableDefinition() { - $this->hasColumn("user_id", "integer"); - $this->hasColumn("one_thing_id", "integer"); - } -} -class MyUserOtherThing extends Doctrine_Record { - public function setTableDefinition() { - $this->hasColumn("user_id", "integer"); - $this->hasColumn("other_thing_id", "integer"); - } -} -?> +ownsOne("Email","Entity.email_id"); + $this->ownsMany("Phonenumber","Phonenumber.entity_id"); + $this->ownsOne("Account","Account.entity_id"); + $this->hasMany("Entity","EntityReference.entity1-entity2"); + } + public function setTableDefinition() { + $this->hasColumn("id","integer",20,"autoincrement|primary"); + $this->hasColumn("name","string",50); + $this->hasColumn("loginname","string",20,"unique"); + $this->hasColumn("password","string",16); + $this->hasColumn("type","integer",1); + $this->hasColumn("created","integer",11); + $this->hasColumn("updated","integer",11); + $this->hasColumn("email_id","integer"); + } +} +class FieldNameTest extends Doctrine_Record { + public function setTableDefinition() { + $this->hasColumn("someColumn", "string", 200, array('default' => 'some string')); + $this->hasColumn("someEnum", "enum", 4, array('default' => 'php')); + $this->hasColumn("someArray", "array", 100, array('default' => array())); + $this->hasColumn("someObject", "object", 200, array('default' => new stdClass)); + $this->hasColumn("someInt", "integer", 20, array('default' => 11)); + + + $this->setEnumValues("someEnum", array('php', 'java', 'python')); + } +} +class EntityReference extends Doctrine_Record { + public function setTableDefinition() { + $this->hasColumn("entity1","integer"); + $this->hasColumn("entity2","integer"); + $this->setPrimaryKey(array("entity1","entity2")); + } +} +class Account extends Doctrine_Record { + public function setTableDefinition() { + $this->hasColumn("entity_id","integer"); + $this->hasColumn("amount","integer"); + } +} + +class EntityAddress extends Doctrine_Record { + public function setTableDefinition() { + $this->hasColumn("entity_id","integer"); + $this->hasColumn("address_id","integer"); + } +} + +class Address extends Doctrine_Record { + public function setUp() { + $this->hasMany("User","Entityaddress.entity_id"); + } + public function setTableDefinition() { + $this->hasColumn("address","string",200); + } +} + +// grouptable doesn't extend Doctrine_Table -> Doctrine_Connection +// won't initialize grouptable when Doctrine_Connection->getTable("Group") is called + +class GroupTable { } +class Group extends Entity { + public function setUp() { + parent::setUp(); + $this->hasMany("User","Groupuser.user_id"); + $this->setInheritanceMap(array("type"=>1)); + + } +} +class Error extends Doctrine_Record { + public function setUp() { + $this->ownsMany("Description","Description.file_md5","file_md5"); + } + public function setTableDefinition() { + $this->hasColumn("message","string",200); + $this->hasColumn("code","integer",11); + $this->hasColumn("file_md5","string",32,"primary"); + } +} +class Description extends Doctrine_Record { + public function setTableDefinition() { + $this->hasColumn("description","string",3000); + $this->hasColumn("file_md5","string",32); + } +} +class UserTable extends Doctrine_Table { } +class User extends Entity { + public function setUp() { + parent::setUp(); + $this->hasMany("Address","Entityaddress.address_id"); + $this->ownsMany("Album","Album.user_id"); + $this->ownsMany("Book", "Book.user_id"); + $this->hasMany("Group","Groupuser.group_id"); + $this->setInheritanceMap(array("type"=>0)); + } +} +class Groupuser extends Doctrine_Record { + public function setTableDefinition() { + $this->hasColumn("added","integer"); + $this->hasColumn("group_id","integer"); + $this->hasColumn("user_id","integer"); + } +} +class Phonenumber extends Doctrine_Record { + public function setTableDefinition() { + $this->hasColumn("phonenumber","string",20); + $this->hasColumn("entity_id","integer"); + } + public function setUp() { + $this->hasOne("Entity", "Phonenumber.entity_id"); + } +} + +class Element extends Doctrine_Record { + public function setTableDefinition() { + $this->hasColumn("name", "string", 100); + $this->hasColumn("parent_id", "integer"); + } + public function setUp() { + $this->hasMany("Element as Child","Child.parent_id"); + $this->hasOne("Element as Parent","Element.parent_id"); + } +} +class Email extends Doctrine_Record { + public function setTableDefinition() { + $this->hasColumn("address","string",150,"email|unique"); + } +} +class Book extends Doctrine_Record { + public function setUp() { + $this->ownsMany("Author","Author.book_id"); + } + public function setTableDefinition() { + $this->hasColumn("user_id","integer"); + $this->hasColumn("name","string",20); + } +} +class Author extends Doctrine_Record { + public function setTableDefinition() { + $this->hasColumn("book_id","integer"); + $this->hasColumn("name","string",20); + } +} +class Album extends Doctrine_Record { + public function setUp() { + $this->ownsMany("Song","Song.album_id"); + } + public function setTableDefinition() { + $this->hasColumn("user_id","integer"); + $this->hasColumn("name","string",20); + } +} +class Song extends Doctrine_Record { + public function setTableDefinition() { + $this->hasColumn("album_id","integer"); + $this->hasColumn("genre","string",20); + $this->hasColumn("title","string",30); + } +} + +class Task extends Doctrine_Record { + public function setUp() { + $this->hasMany("Resource as ResourceAlias","Assignment.resource_id"); + $this->hasMany("Task as Subtask","Subtask.parent_id"); + } + public function setTableDefinition() { + $this->hasColumn("name","string",100); + $this->hasColumn("parent_id","integer"); + } +} + +class Resource extends Doctrine_Record { + public function setUp() { + $this->hasMany("Task as TaskAlias", "Assignment.task_id"); + $this->hasMany("ResourceType as Type", "ResourceReference.type_id"); + } + public function setTableDefinition() { + $this->hasColumn("name","string",100); + } +} +class ResourceReference extends Doctrine_Record { + public function setTableDefinition() { + $this->hasColumn("type_id","integer"); + $this->hasColumn("resource_id","integer"); + } +} +class ResourceType extends Doctrine_Record { + public function setUp() { + $this->hasMany("Resource as ResourceAlias", "ResourceReference.resource_id"); + } + public function setTableDefinition() { + $this->hasColumn("type","string",100); + } +} +class Assignment extends Doctrine_Record { + public function setTableDefinition() { + $this->hasColumn("task_id","integer"); + $this->hasColumn("resource_id","integer"); + } +} +class Forum_Category extends Doctrine_Record { + public function setTableDefinition() { + $this->hasColumn("root_category_id", "integer", 10); + $this->hasColumn("parent_category_id", "integer", 10); + $this->hasColumn("name", "string", 50); + $this->hasColumn("description", "string", 99999); + } + public function setUp() { + $this->hasMany("Forum_Category as Subcategory", "Subcategory.parent_category_id"); + $this->hasOne("Forum_Category as Parent", "Forum_Category.parent_category_id"); + $this->hasOne("Forum_Category as Rootcategory", "Forum_Category.root_category_id"); + } +} +class Forum_Board extends Doctrine_Record { + public function setTableDefinition() { + $this->hasColumn("category_id", "integer", 10); + $this->hasColumn("name", "string", 100); + $this->hasColumn("description", "string", 5000); + } + public function setUp() { + $this->hasOne("Forum_Category as Category", "Forum_Board.category_id"); + $this->ownsMany("Forum_Thread as Threads", "Forum_Thread.board_id"); + } +} + +class Forum_Entry extends Doctrine_Record { + public function setTableDefinition() { + $this->hasColumn("author", "string", 50); + $this->hasColumn("topic", "string", 100); + $this->hasColumn("message", "string", 99999); + $this->hasColumn("parent_entry_id", "integer", 10); + $this->hasColumn("thread_id", "integer", 10); + $this->hasColumn("date", "integer", 10); + } + public function setUp() { + $this->hasOne("Forum_Entry as Parent", "Forum_Entry.parent_entry_id"); + $this->hasOne("Forum_Thread as Thread", "Forum_Entry.thread_id"); + } +} + +class Forum_Thread extends Doctrine_Record { + public function setTableDefinition() { + $this->hasColumn("board_id", "integer", 10); + $this->hasColumn("updated", "integer", 10); + $this->hasColumn("closed", "integer", 1); + } + public function setUp() { + $this->hasOne("Forum_Board as Board", "Forum_Thread.board_id"); + $this->ownsMany("Forum_Entry as Entries", "Forum_Entry.thread_id"); + } +} +class App extends Doctrine_Record { + public function setTableDefinition() { + $this->hasColumn("name", "string", 32); + $this->hasColumn("user_id", "integer", 11); + $this->hasColumn("app_category_id", "integer", 11); + } + public function setUp() { + $this->hasOne("User","User.id"); + $this->hasMany("App_Category as Category","App_Category.id"); + } +} + +class App_User extends Doctrine_Record { + public function setTableDefinition() { + $this->hasColumn("first_name", "string", 32); + $this->hasColumn("last_name", "string", 32); + $this->hasColumn("email", "string", 128, "email"); + $this->hasColumn("username", "string", 16, "unique, nospace"); + $this->hasColumn("password", "string", 128, "notblank"); + $this->hasColumn("country", "string", 2, "country"); + $this->hasColumn("zipcode", "string", 9, "nospace"); + } + public function setUp() { + $this->hasMany("App","App.user_id"); + } +} + +class App_Category extends Doctrine_Record { + public function setTableDefinition() { + $this->hasColumn("name", "string", 32); + $this->hasColumn("parent_id","integer"); + } + public function setUp() { + $this->hasMany("App","App.app_category_id"); + $this->hasMany("App_Category as Parent","App_Category.parent_id"); + } +} + +class ORM_TestEntry extends Doctrine_Record { + public function setTableDefinition() { + $this->setTableName('test_entries'); + $this->hasColumn("id", "integer", 11, "autoincrement|primary"); + $this->hasColumn("name", "string", 255); + $this->hasColumn("stamp", "timestamp"); + $this->hasColumn("amount", "float"); + $this->hasColumn("itemID", "integer"); + } + + public function setUp() { + $this->hasOne("ORM_TestItem", "ORM_TestEntry.itemID"); + } +} + +class ORM_TestItem extends Doctrine_Record { + public function setTableDefinition() { + $this->setTableName('test_items'); + $this->hasColumn("id", "integer", 11, "autoincrement|primary"); + $this->hasColumn("name", "string", 255); + } + + public function setUp() { + + $this->hasOne("ORM_TestEntry", "ORM_TestEntry.itemID"); + } +} +class ORM_AccessControl extends Doctrine_Record { + public function setTableDefinition() { + $this->hasColumn("name", "string", 255); + } + public function setUp() { + $this->hasMany("ORM_AccessGroup as accessGroups", "ORM_AccessControlsGroups.accessGroupID"); + } +} + +class ORM_AccessGroup extends Doctrine_Record { + public function setTableDefinition() { + $this->hasColumn("name", "string", 255); + } + public function setUp() { + $this->hasMany("ORM_AccessControl as accessControls", "ORM_AccessControlsGroups.accessControlID"); + } +} + +class ORM_AccessControlsGroups extends Doctrine_Record { + public function setTableDefinition() { + $this->hasColumn("accessControlID", "integer", 11); + $this->hasColumn("accessGroupID", "integer", 11); + + $this->setPrimaryKey(array("accessControlID", "accessGroupID")); + } +} +class EnumTest extends Doctrine_Record { + public function setTableDefinition() { + $this->hasColumn("status","enum",11); + $this->setEnumValues("status", array("open","verified","closed")); + } +} +class FilterTest extends Doctrine_Record { + public function setTableDefinition() { + $this->hasColumn("name","string",100); + } + public function setUp() { + $this->ownsMany("FilterTest2 as filtered", "FilterTest2.test1_id"); + } +} +class FilterTest2 extends Doctrine_Record { + public function setTableDefinition() { + $this->hasColumn("name","string",100); + $this->hasColumn("test1_id","integer"); + } +} +class CustomPK extends Doctrine_Record { + public function setTableDefinition() { + $this->hasColumn("uid","integer",11,"autoincrement|primary"); + $this->hasColumn("name","string",255); + } +} +class Log_Entry extends Doctrine_Record { + public function setTableDefinition() { + $this->hasColumn("stamp", "timestamp"); + $this->hasColumn("status_id", "integer"); + } + public function setUp() { + $this->hasOne("Log_Status", "Log_Entry.status_id"); + } +} +class CPK_Test extends Doctrine_Record { + public function setTableDefinition() { + $this->hasColumn("name", "string", 255); + } + public function setUp() { + $this->hasMany("CPK_Test2 as Test","CPK_Association.test2_id"); + } +} +class CPK_Test2 extends Doctrine_Record { + public function setTableDefinition() { + $this->hasColumn("name", "string", 255); + } + public function setUp() { + $this->hasMany("CPK_Test as Test","CPK_Association.test1_id"); + } +} +class CPK_Association extends Doctrine_Record { + public function setTableDefinition() { + $this->hasColumn("test1_id", "integer", 11, "primary"); + $this->hasColumn("test2_id", "integer", 11, "primary"); + } +} +class Log_Status extends Doctrine_Record { + public function setTableDefinition() { + $this->hasColumn("name", "string", 255); + } +} +class ValidatorTest extends Doctrine_Record { + public function setTableDefinition() { + $this->hasColumn("mymixed","string", 100); + $this->hasColumn("mystring","string", 100, "notnull|unique"); + $this->hasColumn("myarray", "array", 1000); + $this->hasColumn("myobject", "object", 1000); + $this->hasColumn("myinteger", "integer", 11); + $this->hasColumn("myrange", "integer", 11, array('range' => array(4,123))); + $this->hasColumn("myregexp", "string", 5, array('regexp' => '^[0-9]+$')); + + $this->hasColumn("myemail", "string", 100, "email"); + $this->hasColumn("myemail2", "string", 100, "email|notblank"); + } +} +class DateTest extends Doctrine_Record { + public function setTableDefinition() { + $this->hasColumn("date", "date", 20); + } +} +class GzipTest extends Doctrine_Record { + public function setTableDefinition() { + $this->hasColumn("gzip", "gzip", 100000); + } +} + +class Tag extends Doctrine_Record { + public function setUp() { + $this->hasMany("Photo", "Phototag.photo_id"); + } + public function setTableDefinition() { + $this->hasColumn("tag", "string", 100); + } +} +class Photo extends Doctrine_Record { + public function setUp() { + $this->hasMany("Tag", "Phototag.tag_id"); + } + public function setTableDefinition() { + $this->hasColumn("name", "string", 100); + } +} + +class Phototag extends Doctrine_Record { + public function setTableDefinition() { + $this->hasColumn("photo_id", "integer"); + $this->hasColumn("tag_id", "integer"); + } +} + +class BooleanTest extends Doctrine_Record { + public function setTableDefinition() { + $this->hasColumn('is_working', 'boolean'); + } +} +class Data_File extends Doctrine_Record { + public function setTableDefinition() { + $this->hasColumn("filename", "string"); + $this->hasColumn("file_owner_id", "integer"); + } + public function setUp() { + $this->hasOne("File_Owner", "Data_File.file_owner_id"); + } +} +class NotNullTest extends Doctrine_Record { + public function setTableDefinition() { + $this->hasColumn("name", "string", 100, "notnull"); + $this->hasColumn("type", "integer", 11); + } +} +class File_Owner extends Doctrine_Record { + public function setTableDefinition() { + $this->hasColumn("name", "string", 255); + } + public function setUp() { + $this->hasOne("Data_File", "Data_File.file_owner_id"); + } +} +class MyUser extends Doctrine_Record { + public function setTableDefinition() { + $this->hasColumn("name", "string"); + } + public function setUp() { + $this->hasMany("MyOneThing", "MyOneThing.user_id"); + $this->hasMany("MyOtherThing", "MyOtherThing.user_id"); + } +} +class MyOneThing extends Doctrine_Record { + public function setTableDefinition() { + $this->hasColumn("name", "string"); + $this->hasColumn("user_id", "integer"); + } + public function setUp() { + $this->hasMany("MyUserOneThing", "MyUserOneThing.one_thing_id"); + } +} +class MyOtherThing extends Doctrine_Record { + public function setTableDefinition() { + $this->hasColumn("name", "string"); + $this->hasColumn("user_id", "integer"); + } + public function setUp() { + $this->hasMany("MyUserOtherThing", "MyUserOtherThing.other_thing_id"); + } +} +class MyUserOneThing extends Doctrine_Record { + public function setTableDefinition() { + $this->hasColumn("user_id", "integer"); + $this->hasColumn("one_thing_id", "integer"); + } +} +class MyUserOtherThing extends Doctrine_Record { + public function setTableDefinition() { + $this->hasColumn("user_id", "integer"); + $this->hasColumn("other_thing_id", "integer"); + } +} +class CategoryWithPosition extends Doctrine_Record { + public function setTableDefinition() { + $this->hasColumn("position", "integer"); + $this->hasColumn("name", "string", 255); + } + public function setUp() { + $this->ownsMany("BoardWithPosition as Boards", "BoardWithPosition.category_id"); + } +} +class BoardWithPosition extends Doctrine_Record { + public function setTableDefinition() { + $this->hasColumn("position", "integer"); + $this->hasColumn("category_id", "integer"); + } + public function setUp() { + $this->hasOne("CategoryWithPosition as Category", "BoardWithPosition.category_id"); + } +} +?> diff --git a/tests/run.php b/tests/run.php index fbee51771..605ef72de 100644 --- a/tests/run.php +++ b/tests/run.php @@ -1,211 +1,214 @@ -addTestCase(new Doctrine_Relation_TestCase()); - -$test->addTestCase(new Doctrine_Query_MultiJoin_TestCase()); - -$test->addTestCase(new Doctrine_EventListenerTestCase()); - -$test->addTestCase(new Doctrine_RecordTestCase()); - -$test->addTestCase(new Doctrine_Connection_Transaction_TestCase()); - -$test->addTestCase(new Doctrine_ConnectionTestCase()); - -$test->addTestCase(new Doctrine_DB_TestCase()); - -$test->addTestCase(new Doctrine_AccessTestCase()); - -$test->addTestCase(new Doctrine_TableTestCase()); - -$test->addTestCase(new Doctrine_ManagerTestCase()); - -$test->addTestCase(new Doctrine_BatchIteratorTestCase()); - -$test->addTestCase(new Doctrine_ConfigurableTestCase()); - -$test->addTestCase(new Doctrine_ValidatorTestCase()); - -$test->addTestCase(new Doctrine_Collection_OffsetTestCase()); - -$test->addTestCase(new Doctrine_PessimisticLockingTestCase()); - -$test->addTestCase(new Doctrine_ViewTestCase()); - -$test->addTestCase(new Doctrine_Cache_Query_SqliteTestCase()); - -$test->addTestCase(new Doctrine_CustomPrimaryKeyTestCase()); - -$test->addTestCase(new Doctrine_Filter_TestCase()); - -$test->addTestCase(new Doctrine_ValueHolder_TestCase()); - -$test->addTestCase(new Doctrine_RawSql_TestCase()); - -$test->addTestCase(new Doctrine_Query_Limit_TestCase()); - -//$test->addTestCase(new Doctrine_SchemaTestCase()); - -//$test->addTestCase(new Doctrine_ImportTestCase()); - -$test->addTestCase(new Doctrine_CollectionTestCase()); - -$test->addTestCase(new Doctrine_Query_ReferenceModel_TestCase()); - -$test->addTestCase(new Doctrine_EnumTestCase()); - -$test->addTestCase(new Doctrine_RelationAccessTestCase()); - -$test->addTestCase(new Doctrine_DataDict_Sqlite_TestCase()); - -$test->addTestCase(new Doctrine_BooleanTestCase()); - -$test->addTestCase(new Doctrine_QueryTestCase()); - -$test->addTestCase(new Doctrine_EventListener_Chain_TestCase()); - -//$test->addTestCase(new Doctrine_Cache_FileTestCase()); -//$test->addTestCase(new Doctrine_Cache_SqliteTestCase()); - -class MyReporter extends HtmlReporter { - public function paintHeader() {} - public function paintFooter() - { - $colour = ($this->getFailCount() + $this->getExceptionCount() > 0 ? "red" : "green"); - print "
"; - print $this->getTestCaseProgress() . "/" . $this->getTestCaseCount(); - print " test cases complete:\n"; - print "" . $this->getPassCount() . " passes, "; - print "" . $this->getFailCount() . " fails and "; - print "" . $this->getExceptionCount() . " exceptions."; - print "
\n"; - } -} - -if (TextReporter::inCli()) { - if ($argc == 4) - { - $dsn = $argv[1]; - $username = $argv[2]; - $password = $argv[3]; - } - exit ($test->run(new TextReporter()) ? 0 : 1); -} else { - if (isset($_POST)) - { - $dsn = isset($_POST['dsn'])?$_POST['dsn']:null; - $username = isset($_POST['username'])?$_POST['username']:null; - $password = isset($_POST['password'])?$_POST['password']:null; - } - $test->run(new MyReporter()); - $output = ob_get_clean(); -} -/** -$cache = Doctrine_Manager::getInstance()->getCurrentConnection()->getCacheHandler(); -if(isset($cache)) { - $a = $cache->getQueries(); - print "Executed cache queries: ".count($a)."\n"; - - foreach($a as $query) { - print $query."\n"; - } - -} -*/ -?> - - - - Doctrine Unit Tests - - - - - -

Doctrine Unit Tests

-

DSN Settings

-
- - - - - - - - - - - - - - - - - -
DSN
Username
Password
 
-
-

Tests

-
-
-
-

Queries

-
-getCurrentConnection()->getDBH();
-$a   = $dbh->getQueries();
-
-print "Executed queries: ".count($a)."\n";
-
-foreach($a as $query) {
-    print $query."\n";
-}
-?>
-
- - - +addTestCase(new Doctrine_Relation_TestCase()); + +$test->addTestCase(new Doctrine_Query_MultiJoin_TestCase()); + +$test->addTestCase(new Doctrine_EventListenerTestCase()); + +$test->addTestCase(new Doctrine_RecordTestCase()); + +$test->addTestCase(new Doctrine_Connection_Transaction_TestCase()); + +$test->addTestCase(new Doctrine_ConnectionTestCase()); + +$test->addTestCase(new Doctrine_DB_TestCase()); + +$test->addTestCase(new Doctrine_AccessTestCase()); + +$test->addTestCase(new Doctrine_TableTestCase()); + +$test->addTestCase(new Doctrine_ManagerTestCase()); + +$test->addTestCase(new Doctrine_BatchIteratorTestCase()); + +$test->addTestCase(new Doctrine_ConfigurableTestCase()); + +$test->addTestCase(new Doctrine_ValidatorTestCase()); + +$test->addTestCase(new Doctrine_Collection_OffsetTestCase()); + +$test->addTestCase(new Doctrine_PessimisticLockingTestCase()); + +$test->addTestCase(new Doctrine_ViewTestCase()); + +$test->addTestCase(new Doctrine_Cache_Query_SqliteTestCase()); + +$test->addTestCase(new Doctrine_CustomPrimaryKeyTestCase()); + +$test->addTestCase(new Doctrine_Filter_TestCase()); + +$test->addTestCase(new Doctrine_ValueHolder_TestCase()); + +$test->addTestCase(new Doctrine_RawSql_TestCase()); + +$test->addTestCase(new Doctrine_Query_Limit_TestCase()); + +//$test->addTestCase(new Doctrine_SchemaTestCase()); + +//$test->addTestCase(new Doctrine_ImportTestCase()); + +$test->addTestCase(new Doctrine_CollectionTestCase()); + +$test->addTestCase(new Doctrine_Query_ReferenceModel_TestCase()); + +$test->addTestCase(new Doctrine_EnumTestCase()); + +$test->addTestCase(new Doctrine_RelationAccessTestCase()); + +$test->addTestCase(new Doctrine_DataDict_Sqlite_TestCase()); + +$test->addTestCase(new Doctrine_BooleanTestCase()); + +$test->addTestCase(new Doctrine_QueryTestCase()); + +$test->addTestCase(new Doctrine_EventListener_Chain_TestCase()); + +$test->addTestCase(new Doctrine_CustomResultSetOrderTestCase()); + +//$test->addTestCase(new Doctrine_Cache_FileTestCase()); +//$test->addTestCase(new Doctrine_Cache_SqliteTestCase()); + +class MyReporter extends HtmlReporter { + public function paintHeader() {} + public function paintFooter() + { + $colour = ($this->getFailCount() + $this->getExceptionCount() > 0 ? "red" : "green"); + print "
"; + print $this->getTestCaseProgress() . "/" . $this->getTestCaseCount(); + print " test cases complete:\n"; + print "" . $this->getPassCount() . " passes, "; + print "" . $this->getFailCount() . " fails and "; + print "" . $this->getExceptionCount() . " exceptions."; + print "
\n"; + } +} + +if (TextReporter::inCli()) { + if ($argc == 4) + { + $dsn = $argv[1]; + $username = $argv[2]; + $password = $argv[3]; + } + exit ($test->run(new TextReporter()) ? 0 : 1); +} else { + if (isset($_POST)) + { + $dsn = isset($_POST['dsn'])?$_POST['dsn']:null; + $username = isset($_POST['username'])?$_POST['username']:null; + $password = isset($_POST['password'])?$_POST['password']:null; + } + $test->run(new MyReporter()); + $output = ob_get_clean(); +} +/** +$cache = Doctrine_Manager::getInstance()->getCurrentConnection()->getCacheHandler(); +if(isset($cache)) { + $a = $cache->getQueries(); + print "Executed cache queries: ".count($a)."\n"; + + foreach($a as $query) { + print $query."\n"; + } + +} +*/ +?> + + + + Doctrine Unit Tests + + + + + +

Doctrine Unit Tests

+

DSN Settings

+
+ + + + + + + + + + + + + + + + + +
DSN
Username
Password
 
+
+

Tests

+
+
+
+

Queries

+
+getCurrentConnection()->getDBH();
+$a   = $dbh->getQueries();
+
+print "Executed queries: ".count($a)."\n";
+
+foreach($a as $query) {
+    print $query."\n";
+}
+?>
+
+ + +