X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=vendor%2Fgabordemooij%2Fredbean%2Ftesting%2FRedUNIT%2FBlackhole%2FTainted.php;fp=vendor%2Fgabordemooij%2Fredbean%2Ftesting%2FRedUNIT%2FBlackhole%2FTainted.php;h=3069492276357936af84eb5ffae5ff22a2de70a1;hp=0000000000000000000000000000000000000000;hb=eba34333e3c89f208d2f72fa91351ad019a71583;hpb=a2bd1bf0c2c1f1a17d188f4dc0726a45494cefae diff --git a/vendor/gabordemooij/redbean/testing/RedUNIT/Blackhole/Tainted.php b/vendor/gabordemooij/redbean/testing/RedUNIT/Blackhole/Tainted.php new file mode 100644 index 000000000..306949227 --- /dev/null +++ b/vendor/gabordemooij/redbean/testing/RedUNIT/Blackhole/Tainted.php @@ -0,0 +1,131 @@ +hasListChanged( 'ownPage' ), FALSE ); + $book->ownPage[] = $page; + asrt( $book->hasListChanged( 'ownPage' ), TRUE ); + R::store( $book ); + $book = $book->fresh(); + asrt( $book->hasListChanged( 'ownPage' ), FALSE ); + $page = R::dispense( 'page' ); + $book->ownPageList[] = $page; + asrt( $book->hasListChanged( 'ownPage' ), TRUE ); + R::store( $book ); + $book = $book->fresh(); + asrt( $book->hasListChanged( 'ownPage' ), FALSE ); + asrt( count( $book->ownPageList ), 2 ); + array_pop( $book->ownPageList ); + asrt( count( $book->ownPageList ), 1 ); + asrt( $book->hasListChanged( 'ownPage' ), TRUE ); + array_pop( $book->ownPageList ); + asrt( count( $book->ownPageList ), 0 ); + asrt( $book->hasListChanged( 'ownPage' ), TRUE ); + $book = $book->fresh(); + asrt( $book->hasListChanged( 'ownPage' ), FALSE ); + asrt( count( $book->ownPageList ), 2 ); + $otherPage = R::dispense( 'page' ); + array_pop( $book->ownPageList ); + $book->ownPageList[] = $otherPage; + asrt( count( $book->ownPageList ), 2 ); + asrt( $book->hasListChanged( 'ownPage' ), TRUE ); + $book = $book->fresh(); + $firstPage = reset( $book->ownPageList ); + $firstPage->content = 'abc'; + asrt( $book->hasListChanged( 'ownPage' ), FALSE ); + $book = $book->fresh(); + asrt( $book->hasListChanged( 'ownPage' ), FALSE ); + $lastPage = end( $book->ownPageList ); + $lastPage->ownText[] = R::dispense( 'text' ); + asrt( $book->hasListChanged( 'ownPage' ), FALSE ); + } + + /** + * Tests whether we can clear the history of a bean. + * + * @return void + */ + public function testClearHist() + { + R::nuke(); + $book = R::dispense( 'book' ); + asrt( $book->hasChanged( 'title' ), FALSE ); + $book->title = 'book'; + asrt( $book->hasChanged( 'title' ), TRUE ); + R::store( $book ); + asrt( $book->hasChanged( 'title' ), TRUE ); + $book->clearHistory(); + asrt( $book->hasChanged( 'title' ), FALSE ); + } + + /** + * Test tainted. + * + * @return void + */ + public function testTainted() + { + testpack( 'Original Tainted Tests' ); + $redbean = R::getRedBean(); + $spoon = $redbean->dispense( "spoon" ); + asrt( $spoon->getMeta( "tainted" ), TRUE ); + $spoon->dirty = "yes"; + asrt( $spoon->getMeta( "tainted" ), TRUE ); + testpack( 'Tainted List test' ); + $note = R::dispense( 'note' ); + $note->text = 'abc'; + $note->ownNote[] = R::dispense( 'note' )->setAttr( 'text', 'def' ); + $id = R::store( $note ); + $note = R::load( 'note', $id ); + asrt( $note->isTainted(), FALSE ); + // Shouldn't affect tainted + $note->text; + asrt( $note->isTainted(), FALSE ); + $note->ownNote; + asrt( $note->isTainted(), TRUE ); + testpack( 'Tainted Test Old Value' ); + $text = $note->old( 'text' ); + asrt( $text, 'abc' ); + asrt( $note->hasChanged( 'text' ), FALSE ); + $note->text = 'xxx'; + asrt( $note->hasChanged( 'text' ), TRUE ); + $text = $note->old( 'text' ); + asrt( $text, 'abc' ); + testpack( 'Tainted Non-exist' ); + asrt( $note->hasChanged( 'text2' ), FALSE ); + testpack( 'Misc Tainted Tests' ); + $bean = R::dispense( 'bean' ); + $bean->hasChanged( 'prop' ); + $bean->old( 'prop' ); + } +}