X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=vendor%2Fgabordemooij%2Fredbean%2Ftesting%2FRedUNIT%2FBase%2FThreeway.php;fp=vendor%2Fgabordemooij%2Fredbean%2Ftesting%2FRedUNIT%2FBase%2FThreeway.php;h=d2fc1d4520134c0117f8004e1e239d1f4b869325;hp=0000000000000000000000000000000000000000;hb=eba34333e3c89f208d2f72fa91351ad019a71583;hpb=a2bd1bf0c2c1f1a17d188f4dc0726a45494cefae diff --git a/vendor/gabordemooij/redbean/testing/RedUNIT/Base/Threeway.php b/vendor/gabordemooij/redbean/testing/RedUNIT/Base/Threeway.php new file mode 100644 index 000000000..d2fc1d452 --- /dev/null +++ b/vendor/gabordemooij/redbean/testing/RedUNIT/Base/Threeway.php @@ -0,0 +1,129 @@ +sharedRole[] = $role; + R::store( $person ); + $person->link( 'person_role', array( + 'unit' => R::dispense('unit') + ))->role = $role; + //Can we add a duplicate role now? - No because we started with a simple N-M table + //and unique constraint has been applied accordingly, manually change database. + asrt( R::count( 'person_role' ), 1 ); + R::nuke(); + $person = R::dispense( 'person' ); + $role = R::dispense( 'role' ); + $person->via('participant')->sharedRole[] = $role; + R::store( $person ); + $person->link( 'participant', array( + 'unit' => R::dispense('unit') + ))->role = $role; + //Can we add a duplicate role now? - No because we started with a simple N-M table + //and unique constraint has been applied accordingly, manually change database. + asrt( R::count( 'participant' ), 1 ); + R::nuke(); + $participant = R::dispense( 'participant' ); + $person = R::dispense( 'person' ); + $role = R::dispense( 'role' ); + $unit = R::dispense( 'unit' ); + $participant->person = $person; + $participant->role = $role; + $participant->unit = $unit; + R::store( $participant ); + $person->link( 'participant', array( + 'unit' => R::dispense('unit') + ))->role = $role; + R::store( $person ); + //Can we add a duplicate role now? + asrt( R::count( 'participant' ), 2 ); + AQueryWriter::clearRenames(); + } + + /** + * Test whether a duplicate bean in the list isnt saved. + * This was an issue with Postgres while testing the threeway tables. + * Postgres returned the ID as a string while other drivers returned + * a numeric value causing different outcome in array_diff when + * calculating the shared additions. + * + * @return void + */ + public function testIssueWithDriverReturnID() + { + AQueryWriter::clearRenames(); + R::nuke(); + $book = R::dispense( 'book' ); + $page = R::dispense( 'page' ); + $book->sharedPageList[] = $page; + R::store( $book ); + asrt( R::count( 'page' ), 1 ); + $book = $book->fresh(); + $book->sharedPageList[] = $page; + R::store( $book ); + //don't save the duplicate bean! + asrt( R::count( 'page' ), 1 ); + $book = $book->fresh(); + $page->item = 2; //even if we change a property ? + $book->sharedPageList[] = $page; + R::store( $book ); + foreach( $book->sharedPageList as $listItem) { + asrt( is_string( $listItem->id ), TRUE ); + } + //same test but for own-list + R::nuke(); + $book = R::dispense( 'book' ); + $page = R::dispense( 'page' ); + $book->ownPageList[] = $page; + R::store( $book ); + asrt( R::count( 'page' ), 1 ); + $book = $book->fresh(); + $book->ownPageList[] = $page; + R::store( $book ); + //don't save the duplicate bean! + asrt( R::count( 'page' ), 1 ); + $book = $book->fresh(); + $book->ownPageList[] = $page; + $page->item = 3; + R::store( $book ); + //don't save the duplicate bean! + asrt( R::count( 'page' ), 1 ); + foreach( $book->ownPageList as $listItem) { + asrt( is_string( $listItem->id ), TRUE ); + } + AQueryWriter::clearRenames(); + } +}