/** * Test Transactions. * * @return void */ public function testTransactions() { testpack('transactions'); R::begin(); $bean = R::dispense('bean'); R::store($bean); R::commit(); asrt(R::count('bean'), 1); R::wipe('bean'); R::freeze(1); R::begin(); $bean = R::dispense('bean'); R::store($bean); R::rollback(); asrt(R::count('bean'), 0); R::freeze(FALSE); testpack('genSlots'); asrt(R::genSlots(array('a', 'b')), '?,?'); asrt(R::genSlots(array('a')), '?'); asrt(R::genSlots(array()), ''); }
function genslots($slots, $tpl = NULL) { return \RedBeanPHP\Facade::genSlots($slots, $tpl); }
/** * Test forming IN-clause using genSlots and flat. * * @return void */ public function testINClause() { list($flowers, $shop) = R::dispenseAll('flower*4,shop'); $flowers[0]->color = 'red'; $flowers[1]->color = 'yellow'; $flowers[2]->color = 'blue'; $flowers[3]->color = 'purple'; $flowers[0]->price = 10; $flowers[1]->price = 15; $flowers[2]->price = 20; $flowers[3]->price = 25; $shop->xownFlowerList = $flowers; R::store($shop); $colors = array('red', 'yellow'); $result = $this->getColors(R::find('flower', ' color IN (' . R::genSlots($colors) . ' ) AND price < ?', R::flat(array($colors, 100)))); asrt($result, 'red,yellow'); $colors = array('red', 'yellow'); $result = $this->getColors(R::find('flower', ' color IN (' . R::genSlots($colors) . ' ) AND price < ?', R::flat(array($colors, 10)))); asrt($result, ''); $colors = array('red', 'yellow'); $result = $this->getColors(R::find('flower', ' color IN (' . R::genSlots($colors) . ' ) AND price < ?', R::flat(array($colors, 15)))); asrt($result, 'red'); asrt(json_encode(R::flat(array('a', 'b', 'c'))), '["a","b","c"]'); asrt(json_encode(R::flat(array('a', array('b'), 'c'))), '["a","b","c"]'); asrt(json_encode(R::flat(array('a', array('b', array('c'))))), '["a","b","c"]'); asrt(json_encode(R::flat(array(array('a', array('b', array(array('c'))))))), '["a","b","c"]'); asrt(json_encode(R::flat(array('a', 'b', 'c', array()))), '["a","b","c"]'); asrt(genslots(array(1, 2)), '?,?'); asrt(json_encode(array_flatten(array(array('a', array('b', array(array('c'))))))), '["a","b","c"]'); asrt(genslots(array(1, 2), 'IN (%s) AND'), 'IN (?,?) AND'); asrt(genslots(array(), ' IN (%s) AND '), ''); $colors = array('blue', 'purple', 'red'); $flowers = R::find('flower', genslots($colors, ' color IN (%s) AND ') . ' price > ? ', array_flatten(array($colors, 11))); asrt($this->getColors($flowers), 'blue,purple'); $flowers = R::find('flower', genslots(array(), ' color IN (%s) AND ') . ' price > ? ', array_flatten(array(array(), 11))); asrt($this->getColors($flowers), 'blue,purple,yellow'); $flowers = R::find('flower', ' id > 0 AND ' . genslots($colors, ' color IN (%s) AND ') . ' price > ? ', array_flatten(array($colors, 11))); asrt($this->getColors($flowers), 'blue,purple'); $flowers = R::find('flower', ' id > 0 AND ' . genslots(array(), ' color IN (%s) AND ') . ' price > ? ', array_flatten(array(array(), 11))); asrt($this->getColors($flowers), 'blue,purple,yellow'); }