'strong', 'beans' => 'Arabica', 'preparation' => 'Kettle' ); $coffee = R::dispense('coffee'); $changelist = $coffee->getMeta('changelist'); asrt( count( $changelist), 3 ); $coffee->preparation = 'Espresso'; $changelist = $coffee->getMeta('changelist'); asrt( count( $changelist), 4 ); $id = R::store( $coffee ); $coffee = R::load( 'coffee', $id ); $changelist = $coffee->getMeta('changelist'); asrt( count( $changelist), 0 ); } /** * Github Issue #754. * The importRow() function should clear the changeList. * * @return void */ public function testChangeListImportRow() { R::usePartialBeans( TRUE ); $bean = R::dispense( 'bean' ); asrt( count( $bean->getMeta('changelist') ), 0 ); $bean->property = 'abc'; asrt( count( $bean->getMeta('changelist') ), 1 ); $bean->importRow( array( 'property' => 123 ) ); asrt( count( $bean->getMeta('changelist') ), 0 ); } /** * Tests the basic scenarios for Partial Beans. * * @return void */ public function testPartialBeans() { R::nuke(); R::usePartialBeans( FALSE ); $book = R::dispense( 'book' ); $book->title = 'A book about half beans'; $book->price = 99; $book->pages = 60; $id = R::store( $book ); /* test baseline condition */ $book = R::load( 'book', $id ); asrt( $book->title, 'A book about half beans' ); asrt( (integer) $book->pages, 60 ); $book->pages++; R::exec( 'UPDATE book SET title = ? ', array( 'Another Title' ) ); $id = R::store( $book ); $book = R::load( 'book', $id ); asrt( $book->title, 'A book about half beans' ); asrt( (integer) $book->pages, 61 ); /* now test partial beans mode */ R::usePartialBeans( TRUE ); $book->pages++; R::exec( 'UPDATE book SET title = ? ', array( 'Another Title' ) ); $id = R::store( $book ); $book = R::load( 'book', $id ); asrt( $book->title, 'Another Title' ); asrt( (integer) $book->pages, 62 ); /* mask should be cleared... */ R::exec( 'UPDATE book SET pages = ? ', array( 64 ) ); $book->price = 92; $id = R::store( $book ); $book = R::load( 'book', $id ); asrt( (integer) $book->pages, 64 ); asrt( $book->title, 'Another Title' ); asrt( (integer) $book->price, 92 ); R::usePartialBeans( FALSE ); } /** * Tests whether we can pass a list of specific bean types * to apply partial saving to. * * @return void */ public function testPartialBeansTypeList() { R::nuke(); R::usePartialBeans( array( 'notbook' ) ); $book = R::dispense( 'book' ); $book->title = 'A book about half beans'; $book->price = 99; $book->pages = 60; $id = R::store( $book ); /* test baseline condition */ $book = R::load( 'book', $id ); asrt( $book->title, 'A book about half beans' ); asrt( (integer) $book->pages, 60 ); $book->pages++; R::exec( 'UPDATE book SET title = ? ', array( 'Another Title' ) ); $id = R::store( $book ); $book = R::load( 'book', $id ); asrt( $book->title, 'A book about half beans' ); asrt( (integer) $book->pages, 61 ); /* now test partial beans mode */ R::usePartialBeans( array( 'book', 'more' ) ); $book->pages++; R::exec( 'UPDATE book SET title = ? ', array( 'Another Title' ) ); $id = R::store( $book ); $book = R::load( 'book', $id ); asrt( $book->title, 'Another Title' ); asrt( (integer) $book->pages, 62 ); /* mask should be cleared... */ R::exec( 'UPDATE book SET pages = ? ', array( 64 ) ); $book->price = 92; $id = R::store( $book ); $book = R::load( 'book', $id ); asrt( (integer) $book->pages, 64 ); asrt( $book->title, 'Another Title' ); asrt( (integer) $book->price, 92 ); R::usePartialBeans( FALSE ); } /** * Tests the basic scenarios for Partial Beans. * Frozen. * * @return void */ public function testPartialBeansFrozen() { R::nuke(); R::usePartialBeans( FALSE ); $book = R::dispense( 'book' ); $book->title = 'A book about half beans'; $book->price = 99; $book->pages = 60; $id = R::store( $book ); /* test baseline condition */ $book = R::load( 'book', $id ); asrt( $book->title, 'A book about half beans' ); asrt( (integer) $book->pages, 60 ); $book->pages++; R::exec( 'UPDATE book SET title = ? ', array( 'Another Title' ) ); $id = R::store( $book ); $book = R::load( 'book', $id ); asrt( $book->title, 'A book about half beans' ); asrt( (integer) $book->pages, 61 ); /* now test partial beans mode */ R::freeze( TRUE ); R::usePartialBeans( TRUE ); $book->pages++; R::exec( 'UPDATE book SET title = ? ', array( 'Another Title' ) ); $id = R::store( $book ); $book = R::load( 'book', $id ); asrt( $book->title, 'Another Title' ); asrt( (integer) $book->pages, 62 ); /* mask should be cleared... */ R::exec( 'UPDATE book SET pages = ? ', array( 64 ) ); $book->price = 92; $id = R::store( $book ); $book = R::load( 'book', $id ); asrt( (integer) $book->pages, 64 ); asrt( $book->title, 'Another Title' ); asrt( (integer) $book->price, 92 ); R::usePartialBeans( FALSE ); R::freeze( FALSE ); } /** * Tests whether we can pass a list of specific bean types * to apply partial saving to. * Frozen. * * @return void */ public function testPartialBeansTypeListFrozen() { R::nuke(); R::usePartialBeans( array( 'notbook' ) ); $book = R::dispense( 'book' ); $book->title = 'A book about half beans'; $book->price = 99; $book->pages = 60; $id = R::store( $book ); /* test baseline condition */ $book = R::load( 'book', $id ); asrt( $book->title, 'A book about half beans' ); asrt( (integer) $book->pages, 60 ); $book->pages++; R::exec( 'UPDATE book SET title = ? ', array( 'Another Title' ) ); $id = R::store( $book ); $book = R::load( 'book', $id ); asrt( $book->title, 'A book about half beans' ); asrt( (integer) $book->pages, 61 ); /* now test partial beans mode */ R::freeze( TRUE ); R::usePartialBeans( array( 'book', 'more' ) ); $book->pages++; R::exec( 'UPDATE book SET title = ? ', array( 'Another Title' ) ); $id = R::store( $book ); $book = R::load( 'book', $id ); asrt( $book->title, 'Another Title' ); asrt( (integer) $book->pages, 62 ); /* mask should be cleared... */ R::exec( 'UPDATE book SET pages = ? ', array( 64 ) ); $book->price = 92; $id = R::store( $book ); $book = R::load( 'book', $id ); asrt( (integer) $book->pages, 64 ); asrt( $book->title, 'Another Title' ); asrt( (integer) $book->price, 92 ); R::usePartialBeans( FALSE ); R::freeze( FALSE ); } }