Пример #1
0
 /**
  * Test exporting with filters.
  * 
  * @return void
  */
 public function ExportWithFilters()
 {
     testpack('Export with filters');
     $book = R::dispense('book');
     $pages = R::dispense('page', 2);
     $texts = R::dispense('text', 2);
     $images = R::dispense('image', 2);
     $author = R::dispense('author');
     $pub = R::dispense('publisher');
     $bookmarks = R::dispense('bookmark', 2);
     $pages[0]->ownText = array($texts[0]);
     $pages[0]->ownImage = array($images[0]);
     $pages[1]->ownText = array($texts[1]);
     $pages[1]->ownImage = array($images[1]);
     $pages[0]->sharedBookmark[] = $bookmarks[0];
     $pages[1]->sharedBookmark[] = $bookmarks[1];
     $bookmarks[0]->ownNote[] = R::dispense('note')->setAttr('text', 'a note');
     $bookmarks[1]->ownNote[] = R::dispense('note')->setAttr('text', 'a note');
     $book->ownPage = $pages;
     $book->author = $author;
     $author->publisher = $pub;
     $bookID = R::store($book);
     R::$duplicationManager->setTables(R::$writer->getTables());
     $objects = R::exportAll(array($book), TRUE, array());
     asrt(isset($objects[0]['ownPage']), TRUE);
     asrt(count($objects[0]['ownPage']), 2);
     asrt(isset($objects[0]['author']), TRUE);
     asrt(isset($objects[0]['ownPage'][0]['ownText']), TRUE);
     asrt(count($objects[0]['ownPage'][0]['ownText']), 1);
     asrt(isset($objects[0]['ownPage'][0]['ownImage']), TRUE);
     asrt(count($objects[0]['ownPage'][0]['ownImage']), 1);
     $objects = R::exportAll(array($book), TRUE, array('page', 'author', 'text', 'image'));
     asrt(isset($objects[0]['ownPage']), TRUE);
     asrt(count($objects[0]['ownPage']), 2);
     asrt(isset($objects[0]['author']), TRUE);
     asrt(isset($objects[0]['ownPage'][0]['ownText']), TRUE);
     asrt(count($objects[0]['ownPage'][0]['ownText']), 1);
     asrt(isset($objects[0]['ownPage'][0]['ownImage']), TRUE);
     asrt(count($objects[0]['ownPage'][0]['ownImage']), 1);
     $objects = R::exportAll(array($book), TRUE, 'author');
     asrt(isset($objects[0]['ownPage']), FALSE);
     asrt(isset($objects[0]['ownPage'][0]['ownText']), FALSE);
     $objects = R::exportAll(array($book), TRUE, array('page'));
     asrt(isset($objects[0]['author']), FALSE);
     asrt(isset($objects[0]['ownPage'][0]['ownText']), FALSE);
     $objects = R::exportAll(array($book), TRUE, array('page', 'text'));
     asrt(isset($objects[0]['author']), FALSE);
     asrt(isset($objects[0]['ownPage']), TRUE);
     asrt(isset($objects[0]['ownPage'][0]['ownText']), TRUE);
     asrt(count($objects[0]['ownPage'][0]['ownText']), 1);
     asrt(isset($objects[0]['ownPage'][0]['ownImage']), FALSE);
     $objects = R::exportAll(array($book), TRUE, array('none'));
     asrt(isset($objects[0]['author']), FALSE);
     asrt(isset($objects[0]['ownPage']), FALSE);
     $texts = R::find('text');
     R::preload($texts, 'page,*.book,*.author');
     $objects = R::exportAll($texts, TRUE);
     asrt(isset($objects[0]['page']['book']['author']['publisher']), TRUE);
     asrt(isset($objects[0]['page']['sharedBookmark']), FALSE);
     $texts = R::find('text');
     R::preload($texts, array('page', 'page.sharedBookmark' => 'bookmark'));
     $objects = R::exportAll($texts, TRUE);
     asrt(isset($objects[0]['page']['book']['author']['publisher']), TRUE);
     asrt(isset($objects[0]['page']['sharedBookmark']), TRUE);
     asrt(isset($objects[0]['page']['sharedBookmark'][0]['ownNote']), FALSE);
     $texts = R::find('text');
     R::preload($texts, array('page', 'page.sharedBookmark' => 'bookmark', 'page.sharedBookmark.ownNote' => 'note'));
     $objects = R::exportAll($texts, TRUE);
     asrt(isset($objects[0]['page']['book']['author']['publisher']), TRUE);
     asrt(isset($objects[0]['page']['sharedBookmark']), TRUE);
     asrt(isset($objects[0]['page']['sharedBookmark'][0]['ownNote']), TRUE);
     R::$duplicationManager->setCacheTables(FALSE);
     testpack('Keyless export');
     $book = R::load('book', $bookID);
     $book->ownPage;
     $export = $book->export();
     asrt(isset($export['ownPage'][0]), TRUE);
     RedBean_OODBBean::setFlagKeyedExport(TRUE);
     $export = $book->export();
     asrt(isset($export['ownPage'][1]), TRUE);
     RedBean_OODBBean::setFlagKeyedExport(FALSE);
     $export = $book->export();
     asrt(isset($export['ownPage'][0]), TRUE);
 }