X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=vendor%2Fgabordemooij%2Fredbean%2Ftesting%2FRedUNIT%2FBlackhole%2FExport.php;fp=vendor%2Fgabordemooij%2Fredbean%2Ftesting%2FRedUNIT%2FBlackhole%2FExport.php;h=73674b2d8e1595475c8e3baef3ff07f7f4b4eec2;hp=0000000000000000000000000000000000000000;hb=eba34333e3c89f208d2f72fa91351ad019a71583;hpb=a2bd1bf0c2c1f1a17d188f4dc0726a45494cefae diff --git a/vendor/gabordemooij/redbean/testing/RedUNIT/Blackhole/Export.php b/vendor/gabordemooij/redbean/testing/RedUNIT/Blackhole/Export.php new file mode 100644 index 000000000..73674b2d8 --- /dev/null +++ b/vendor/gabordemooij/redbean/testing/RedUNIT/Blackhole/Export.php @@ -0,0 +1,130 @@ +import( array( 'a' => 1, 'b' => 2 ) ); + $bean->setMeta( 'justametaproperty', 'hellothere' ); + $arr = $bean->export(); + asrt( is_array( $arr ), TRUE ); + asrt( isset( $arr["a"] ), TRUE ); + asrt( isset( $arr["b"] ), TRUE ); + asrt( $arr["a"], 1 ); + asrt( $arr["b"], 2 ); + asrt( isset( $arr["__info"] ), FALSE ); + $arr = $bean->export( TRUE ); + asrt( isset( $arr["__info"] ), TRUE ); + asrt( $arr["a"], 1 ); + asrt( $arr["b"], 2 ); + $exportBean = $redbean->dispense( 'abean' ); + $exportBean->setMeta( 'metaitem.bla', 1 ); + $exportedBean = $exportBean->export( TRUE ); + asrt( $exportedBean["__info"]["metaitem.bla"], 1 ); + asrt( $exportedBean["__info"]["type"], "abean" ); + // Can we determine whether a bean is empty? + testpack( 'test $bean->isEmpty() function' ); + $bean = R::dispense( 'bean' ); + asrt( $bean->isEmpty(), TRUE ); + asrt( ( count( $bean ) > 0 ), TRUE ); + $bean->property = 1; + asrt( $bean->isEmpty(), FALSE ); + asrt( ( count( $bean ) > 0 ), TRUE ); + $bean->property = 0; + asrt( $bean->isEmpty(), TRUE ); + asrt( ( count( $bean ) > 0 ), TRUE ); + $bean->property = FALSE; + asrt( $bean->isEmpty(), TRUE ); + asrt( ( count( $bean ) > 0 ), TRUE ); + $bean->property = NULL; + asrt( $bean->isEmpty(), TRUE ); + asrt( ( count( $bean ) > 0 ), TRUE ); + unset( $bean->property ); + asrt( $bean->isEmpty(), TRUE ); + asrt( ( count( $bean ) > 0 ), TRUE ); + // Export bug I found + $bandmember = R::dispense( 'bandmember' ); + $bandmember->name = 'Duke'; + $instrument = R::dispense( 'instrument' ); + $instrument->name = 'Piano'; + $bandmember->ownInstrument[] = $instrument; + $a = R::exportAll( $bandmember ); + pass(); + asrt( isset( $a[0] ), TRUE ); + asrt( (int) $a[0]['id'], 0 ); + asrt( $a[0]['name'], 'Duke' ); + asrt( $a[0]['ownInstrument'][0]['name'], 'Piano' ); + R::nuke(); + $v = R::dispense( 'village' ); + $b = R::dispense( 'building' ); + $v->name = 'a'; + $b->name = 'b'; + $v->ownBuilding[] = $b; + $id = R::store( $v ); + $a = R::exportAll( $v ); + asrt( $a[0]['name'], 'a' ); + asrt( $a[0]['ownBuilding'][0]['name'], 'b' ); + $v = R::load( 'village', $id ); + $b2 = R::dispense( 'building' ); + $b2->name = 'c'; + $v->ownBuilding[] = $b2; + $a = R::exportAll( $v ); + asrt( $a[0]['name'], 'a' ); + asrt( $a[0]['ownBuilding'][0]['name'], 'b' ); + asrt( count( $a[0]['ownBuilding'] ), 2 ); + list( $r1, $r2 ) = R::dispense( 'army', 2 ); + $r1->name = '1'; + $r2->name = '2'; + $v->sharedArmy[] = $r2; + $a = R::exportAll( $v ); + asrt( count( $a[0]['sharedArmy'] ), 1 ); + R::store( $v ); + $v = R::load( 'village', $id ); + $a = R::exportAll( $v ); + asrt( count( $a[0]['sharedArmy'] ), 1 ); + asrt( $a[0]['name'], 'a' ); + asrt( $a[0]['ownBuilding'][0]['name'], 'b' ); + asrt( count( $a[0]['ownBuilding'] ), 2 ); + $v->sharedArmy[] = $r1; + $a = R::exportAll( $v ); + asrt( count( $a[0]['sharedArmy'] ), 2 ); + $v = R::load( 'village', $id ); + $a = R::exportAll( $v ); + asrt( count( $a[0]['sharedArmy'] ), 1 ); + $v->sharedArmy[] = $r1; + R::store( $v ); + $v = R::load( 'village', $id ); + $a = R::exportAll( $v ); + asrt( count( $a[0]['sharedArmy'] ), 2 ); + } +}