| 1 |
<?php |
|---|
| 2 |
|
|---|
| 3 |
use bookstore::Model as PropelModel; |
|---|
| 4 |
use bookstore::Peer as PropelPeer; |
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
|
|---|
| 20 |
|
|---|
| 21 |
|
|---|
| 22 |
|
|---|
| 23 |
|
|---|
| 24 |
|
|---|
| 25 |
|
|---|
| 26 |
require_once 'bookstore/BookstoreTestBase.php'; |
|---|
| 27 |
|
|---|
| 28 |
|
|---|
| 29 |
|
|---|
| 30 |
|
|---|
| 31 |
|
|---|
| 32 |
|
|---|
| 33 |
|
|---|
| 34 |
|
|---|
| 35 |
|
|---|
| 36 |
|
|---|
| 37 |
|
|---|
| 38 |
|
|---|
| 39 |
|
|---|
| 40 |
|
|---|
| 41 |
|
|---|
| 42 |
|
|---|
| 43 |
class GeneratedObjectRelTest extends BookstoreTestBase { |
|---|
| 44 |
|
|---|
| 45 |
|
|---|
| 46 |
* Tests one side of a bi-directional setting of many-to-many relationships. |
|---|
| 47 |
*/ |
|---|
| 48 |
public function testManyToMany_Dir1() |
|---|
| 49 |
{ |
|---|
| 50 |
$list = new PropelModel::BookClubList(); |
|---|
| 51 |
$list->setGroupLeader('Archimedes Q. Porter'); |
|---|
| 52 |
|
|---|
| 53 |
|
|---|
| 54 |
$book = new PropelModel::Book(); |
|---|
| 55 |
$book->setTitle( "Jungle Expedition Handbook" ); |
|---|
| 56 |
$book->setISBN('TEST'); |
|---|
| 57 |
|
|---|
| 58 |
|
|---|
| 59 |
$this->assertEquals(0, count($list->getBookListRels()) ); |
|---|
| 60 |
$this->assertEquals(0, count($book->getBookListRels()) ); |
|---|
| 61 |
$this->assertEquals(0, count(PropelPeer::BookListRelPeer::doSelect(new ::Criteria())) ); |
|---|
| 62 |
|
|---|
| 63 |
$xref = new PropelModel::BookListRel(); |
|---|
| 64 |
$xref->setBook($book); |
|---|
| 65 |
$list->addBookListRel($xref); |
|---|
| 66 |
|
|---|
| 67 |
$this->assertEquals(1, count($list->getBookListRels())); |
|---|
| 68 |
$this->assertEquals(1, count($book->getBookListRels()) ); |
|---|
| 69 |
$this->assertEquals(0, count(PropelPeer::BookListRelPeer::doSelect(new ::Criteria())) ); |
|---|
| 70 |
|
|---|
| 71 |
$list->save(); |
|---|
| 72 |
|
|---|
| 73 |
$this->assertEquals(1, count($list->getBookListRels()) ); |
|---|
| 74 |
$this->assertEquals(1, count($book->getBookListRels()) ); |
|---|
| 75 |
$this->assertEquals(1, count(PropelPeer::BookListRelPeer::doSelect(new ::Criteria())) ); |
|---|
| 76 |
|
|---|
| 77 |
} |
|---|
| 78 |
|
|---|
| 79 |
|
|---|
| 80 |
* Tests reverse setting of one of many-to-many relationship, with all saves cascaded. |
|---|
| 81 |
*/ |
|---|
| 82 |
public function testManyToMany_Dir2_Unsaved() |
|---|
| 83 |
{ |
|---|
| 84 |
$list = new PropelModel::BookClubList(); |
|---|
| 85 |
$list->setGroupLeader('Archimedes Q. Porter'); |
|---|
| 86 |
|
|---|
| 87 |
|
|---|
| 88 |
$book = new PropelModel::Book(); |
|---|
| 89 |
$book->setTitle( "Jungle Expedition Handbook" ); |
|---|
| 90 |
$book->setISBN('TEST'); |
|---|
| 91 |
|
|---|
| 92 |
|
|---|
| 93 |
$this->assertEquals(0, count($list->getBookListRels()) ); |
|---|
| 94 |
$this->assertEquals(0, count($book->getBookListRels()) ); |
|---|
| 95 |
$this->assertEquals(0, count(PropelPeer::BookListRelPeer::doSelect(new ::Criteria())) ); |
|---|
| 96 |
|
|---|
| 97 |
$xref = new PropelModel::BookListRel(); |
|---|
| 98 |
$xref->setBookClubList($list); |
|---|
| 99 |
$book->addBookListRel($xref); |
|---|
| 100 |
|
|---|
| 101 |
$this->assertEquals(1, count($list->getBookListRels()) ); |
|---|
| 102 |
$this->assertEquals(1, count($book->getBookListRels()) ); |
|---|
| 103 |
$this->assertEquals(0, count(PropelPeer::BookListRelPeer::doSelect(new ::Criteria())) ); |
|---|
| 104 |
$book->save(); |
|---|
| 105 |
|
|---|
| 106 |
$this->assertEquals(1, count($list->getBookListRels()) ); |
|---|
| 107 |
$this->assertEquals(1, count($book->getBookListRels()) ); |
|---|
| 108 |
$this->assertEquals(1, count(PropelPeer::BookListRelPeer::doSelect(new ::Criteria())) ); |
|---|
| 109 |
|
|---|
| 110 |
} |
|---|
| 111 |
|
|---|
| 112 |
|
|---|
| 113 |
* Tests reverse setting of relationships, saving one of the objects first. |
|---|
| 114 |
* @link http://propel.phpdb.org/trac/ticket/508 |
|---|
| 115 |
*/ |
|---|
| 116 |
public function testManyToMany_Dir2_Saved() |
|---|
| 117 |
{ |
|---|
| 118 |
$list = new PropelModel::BookClubList(); |
|---|
| 119 |
$list->setGroupLeader('Archimedes Q. Porter'); |
|---|
| 120 |
$list->save(); |
|---|
| 121 |
|
|---|
| 122 |
$book = new PropelModel::Book(); |
|---|
| 123 |
$book->setTitle( "Jungle Expedition Handbook" ); |
|---|
| 124 |
$book->setISBN('TEST'); |
|---|
| 125 |
|
|---|
| 126 |
|
|---|
| 127 |
$this->assertEquals(0, count($list->getBookListRels()) ); |
|---|
| 128 |
$this->assertEquals(0, count($book->getBookListRels()) ); |
|---|
| 129 |
$this->assertEquals(0, count(PropelPeer::BookListRelPeer::doSelect(new ::Criteria())) ); |
|---|
| 130 |
|
|---|
| 131 |
|
|---|
| 132 |
|
|---|
| 133 |
$xref = new PropelModel::BookListRel(); |
|---|
| 134 |
$xref->setBookClubList($list); |
|---|
| 135 |
$book->addBookListRel($xref); |
|---|
| 136 |
|
|---|
| 137 |
$this->assertEquals(1, count($list->getBookListRels()) ); |
|---|
| 138 |
$this->assertEquals(1, count($book->getBookListRels()) ); |
|---|
| 139 |
$this->assertEquals(0, count(PropelPeer::BookListRelPeer::doSelect(new ::Criteria())) ); |
|---|
| 140 |
$book->save(); |
|---|
| 141 |
|
|---|
| 142 |
$this->assertEquals(1, count($list->getBookListRels()) ); |
|---|
| 143 |
$this->assertEquals(1, count($book->getBookListRels()) ); |
|---|
| 144 |
$this->assertEquals(1, count(PropelPeer::BookListRelPeer::doSelect(new ::Criteria())) ); |
|---|
| 145 |
|
|---|
| 146 |
} |
|---|
| 147 |
|
|---|
| 148 |
|
|---|
| 149 |
* Test behavior of columns that are implicated in multiple foreign keys. |
|---|
| 150 |
* @link http://propel.phpdb.org/trac/ticket/228 |
|---|
| 151 |
*/ |
|---|
| 152 |
public function testMultiFkImplication() |
|---|
| 153 |
{ |
|---|
| 154 |
|
|---|
| 155 |
$b = new PropelModel::Bookstore(); |
|---|
| 156 |
$b->setStoreName("Foo!"); |
|---|
| 157 |
$b->save(); |
|---|
| 158 |
|
|---|
| 159 |
$c = new PropelModel::Contest(); |
|---|
| 160 |
$c->setName("Bookathon Contest"); |
|---|
| 161 |
$c->save(); |
|---|
| 162 |
|
|---|
| 163 |
$bc = new PropelModel::BookstoreContest(); |
|---|
| 164 |
$bc->setBookstore($b); |
|---|
| 165 |
$bc->setContest($c); |
|---|
| 166 |
$bc->save(); |
|---|
| 167 |
|
|---|
| 168 |
$c = new PropelModel::Customer(); |
|---|
| 169 |
$c->setName("Happy Customer"); |
|---|
| 170 |
$c->save(); |
|---|
| 171 |
|
|---|
| 172 |
$bce = new PropelModel::BookstoreContestEntry(); |
|---|
| 173 |
$bce->setBookstore($b); |
|---|
| 174 |
$bce->setBookstoreContest($bc); |
|---|
| 175 |
$bce->setCustomer($c); |
|---|
| 176 |
$bce->save(); |
|---|
| 177 |
|
|---|
| 178 |
$bce->setBookstoreId(null); |
|---|
| 179 |
|
|---|
| 180 |
$this->assertNull($bce->getBookstoreContest()); |
|---|
| 181 |
$this->assertNull($bce->getBookstore()); |
|---|
| 182 |
} |
|---|
| 183 |
|
|---|
| 184 |
|
|---|
| 185 |
* Test the clearing of related object collection. |
|---|
| 186 |
* @link http://propel.phpdb.org/trac/ticket/529 |
|---|
| 187 |
*/ |
|---|
| 188 |
public function testClearRefFk() |
|---|
| 189 |
{ |
|---|
| 190 |
$book = new PropelModel::Book(); |
|---|
| 191 |
$book->setISBN("Foo-bar-baz"); |
|---|
| 192 |
$book->setTitle("The book title"); |
|---|
| 193 |
|
|---|
| 194 |
|
|---|
| 195 |
|
|---|
| 196 |
$r = new PropelModel::Review(); |
|---|
| 197 |
$r->setReviewedBy('Me'); |
|---|
| 198 |
$r->setReviewDate(new DateTime("now")); |
|---|
| 199 |
|
|---|
| 200 |
$book->addReview($r); |
|---|
| 201 |
|
|---|
| 202 |
|
|---|
| 203 |
|
|---|
| 204 |
$this->assertEquals(1, count($book->getReviews()) ); |
|---|
| 205 |
$book->clearReviews(); |
|---|
| 206 |
$this->assertEquals(0, count($book->getReviews())); |
|---|
| 207 |
} |
|---|
| 208 |
|
|---|
| 209 |
|
|---|
| 210 |
* This tests to see whether modified objects are being silently overwritten by calls to fk accessor methods. |
|---|
| 211 |
* @link http://propel.phpdb.org/trac/ticket/509#comment:5 |
|---|
| 212 |
*/ |
|---|
| 213 |
public function testModifiedObjectOverwrite() |
|---|
| 214 |
{ |
|---|
| 215 |
$author = new PropelModel::Author(); |
|---|
| 216 |
$author->setFirstName("John"); |
|---|
| 217 |
$author->setLastName("Public"); |
|---|
| 218 |
|
|---|
| 219 |
$books = $author->getBooks(); |
|---|
| 220 |
$this->assertEquals(array(), $books, "Expected empty array."); |
|---|
| 221 |
|
|---|
| 222 |
$book = new PropelModel::Book(); |
|---|
| 223 |
$book->setTitle("A sample book"); |
|---|
| 224 |
$book->setISBN("INITIAL ISBN"); |
|---|
| 225 |
|
|---|
| 226 |
$author->addBook($book); |
|---|
| 227 |
|
|---|
| 228 |
$author->save(); |
|---|
| 229 |
|
|---|
| 230 |
$book->setISBN("MODIFIED ISBN"); |
|---|
| 231 |
|
|---|
| 232 |
$books = $author->getBooks(); |
|---|
| 233 |
$this->assertEquals(1, count($books), "Expected 1 book."); |
|---|
| 234 |
$this->assertSame($book, $books[0], "Expected the same object to be returned by fk accessor."); |
|---|
| 235 |
$this->assertEquals("MODIFIED ISBN", $books[0]->getISBN(), "Expected the modified value NOT to have been overwritten."); |
|---|
| 236 |
} |
|---|
| 237 |
} |
|---|
| 238 |
|
|---|