php RedBeanPHP-Facade类(方法)实例源码

下面列出了php RedBeanPHP-Facade 类(方法)源码代码实例,从而了解它的用法。

作者:AsemKhati    项目:MyPoll-OOP-PHP-Poll-syste   
/**
  * @return array
  */
 public function getResults()
 {
     if ($this->storedNumber > $this->maxResults) {
         $startFrom = $this->maxResults * $this->startPage;
         $extraSQL = 'ORDER BY id ASC LIMIT ' . $startFrom . ',' . $this->maxResults;
         return Facade::findAll($this->DBTable, $extraSQL);
     } else {
         return Facade::findAll($this->DBTable);
     }
 }

作者:AntonyAntoni    项目:phpbac   
public function testDatabaseInstallation()
 {
     $this->url('index.php');
     //All Fields initially with empty
     $this->fillFields(array('hostname' => 'localhost', 'username' => 'root', 'password' => '', 'database' => 'phpback_test', 'adminemail' => 'admin@phpback.org', 'adminname' => 'admin', 'adminpass' => 'admin', 'adminrpass' => 'admin'));
     //Submit form
     $this->byName('install-form')->submit();
     //Should delete first intallation files
     $this->assertFileNotExists('install/index.php');
     $this->assertFileNotExists('install/install1.php');
     $this->assertFileNotExists('install/database_tables.sql');
     //Should create configuration file
     $this->assertFileExists('application/config/database.php');
     include 'application/config/database.php';
     $this->assertEquals($db['default']['username'], 'root');
     $this->assertEquals($db['default']['password'], '');
     $this->assertEquals($db['default']['database'], 'phpback_test');
     $this->assertEquals($db['default']['username'], 'root');
     $this->assertEquals($db['default']['dbdriver'], 'mysqli');
     //Should have updated database with new tables
     $this->assertEquals(RedBean::inspect(), array('_sessions', 'categories', 'comments', 'flags', 'ideas', 'logs', 'settings', 'users', 'votes'));
     //Should have created the admin user
     $adminUser = RedBean::load('users', 1);
     $this->assertEquals($adminUser->name, 'admin');
     $this->assertEquals($adminUser->email, 'admin@phpback.org');
     $this->assertEquals($adminUser->isadmin, '3');
     $this->assertEquals($adminUser->votes, '20');
 }

作者:AntonyAntoni    项目:phpbac   
/**
  * Tests R::getInsertID convenience method.
  *
  * @return void
  */
 public function testGetInsertID()
 {
     R::nuke();
     $id = R::store(R::dispense('book'));
     $id2 = R::getInsertID();
     asrt($id, $id2);
 }

作者:gabordemooi    项目:redbea   
/**
  * Test SQLite table rebuilding.
  *
  * @return void
  */
 public function testRebuilder()
 {
     $toolbox = R::getToolBox();
     $adapter = $toolbox->getDatabaseAdapter();
     $writer = $toolbox->getWriter();
     $redbean = $toolbox->getRedBean();
     $pdo = $adapter->getDatabase();
     $book = R::dispense('book');
     $page = R::dispense('page');
     $book->xownPage[] = $page;
     $id = R::store($book);
     $book = R::load('book', $id);
     asrt(count($book->xownPage), 1);
     asrt((int) R::getCell('SELECT COUNT(*) FROM page'), 1);
     R::trash($book);
     asrt((int) R::getCell('SELECT COUNT(*) FROM page'), 0);
     $book = R::dispense('book');
     $page = R::dispense('page');
     $book->xownPage[] = $page;
     $id = R::store($book);
     $book = R::load('book', $id);
     asrt(count($book->xownPage), 1);
     asrt((int) R::getCell('SELECT COUNT(*) FROM page'), 1);
     $book->added = 2;
     R::store($book);
     $book->added = 'added';
     R::store($book);
     R::trash($book);
     asrt((int) R::getCell('SELECT COUNT(*) FROM page'), 0);
 }

作者:diego-vieir    项目:redbea   
/**
  * Test integration with pre-existing schemas.
  *
  * @return void
  */
 public function testPlaysNiceWithPreExitsingSchema()
 {
     $toolbox = R::getToolBox();
     $adapter = $toolbox->getDatabaseAdapter();
     $writer = $toolbox->getWriter();
     $redbean = $toolbox->getRedBean();
     $pdo = $adapter->getDatabase();
     $a = new AssociationManager($toolbox);
     $page = $redbean->dispense("page");
     $page->name = "John's page";
     $idpage = $redbean->store($page);
     $page2 = $redbean->dispense("page");
     $page2->name = "John's second page";
     $idpage2 = $redbean->store($page2);
     $a->associate($page, $page2);
     $adapter->exec("ALTER TABLE " . $writer->esc('page') . "\n\t\tCHANGE " . $writer->esc('name') . " " . $writer->esc('name') . "\n\t\tVARCHAR( 254 ) CHARACTER SET utf8 COLLATE utf8_unicode_ci NULL DEFAULT NULL ");
     $page = $redbean->dispense("page");
     $page->name = "Just Another Page In a Table";
     $cols = $writer->getColumns("page");
     asrt($cols["name"], "varchar(254)");
     //$pdo->SethMode(1);
     $redbean->store($page);
     pass();
     // No crash?
     $cols = $writer->getColumns("page");
     asrt($cols["name"], "varchar(254)");
     //must still be same
 }

作者:skullyframewor    项目:skull   
/**
  * Does the toolbox contain the necessary tools ?
  * 
  * @return void
  */
 public function testDoesToolboxContainTheTools()
 {
     $toolbox = R::getToolBox();
     asrt($toolbox->getDatabaseAdapter() instanceof Adapter, TRUE);
     asrt($toolbox->getRedBean() instanceof OODB, TRUE);
     asrt($toolbox->getWriter() instanceof QueryWriter, TRUE);
 }

作者:cesium14    项目:redbea   
/**
  * 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');
 }

作者:skullyframewor    项目:skully-admi   
public function logout()
 {
     $adminId = $this->app->getSession()->get('adminId');
     $sql = "delete from `adminsession` where `admin_id` = '" . $adminId . "'";
     R::exec($sql);
     $this->app->getSession()->remove('adminId');
 }

作者:AntonyAntoni    项目:phpbac   
/**
  * Test varchar 191 condition.
  *
  * @return void
  */
 public function testInnoDBIndexLimit()
 {
     R::nuke();
     $book = R::dispense('book');
     $book->text = 'abcd';
     R::store($book);
     $columns = R::inspect('book');
     asrt(isset($columns['text']), TRUE);
     asrt($columns['text'], 'varchar(191)');
     $book = $book->fresh();
     $book->text = str_repeat('x', 190);
     R::store($book);
     $columns = R::inspect('book');
     asrt(isset($columns['text']), TRUE);
     asrt($columns['text'], 'varchar(191)');
     $book = $book->fresh();
     $book->text = str_repeat('x', 191);
     R::store($book);
     $columns = R::inspect('book');
     asrt(isset($columns['text']), TRUE);
     asrt($columns['text'], 'varchar(191)');
     $book = $book->fresh();
     $book->text = str_repeat('x', 192);
     R::store($book);
     $columns = R::inspect('book');
     asrt(isset($columns['text']), TRUE);
     asrt($columns['text'], 'varchar(255)');
 }

作者:skullyframewor    项目:skully-admi   
public function uploadImage()
 {
     $error = '';
     $uploadedImages = array();
     if (isset($_POST) and $_SERVER['REQUEST_METHOD'] == "POST") {
         // Find instance
         $id = $this->getParam($this->instanceName . '_id');
         if (!empty($id)) {
             /** @var \RedbeanPHP\SimpleModel $instanceBean */
             $instanceBean = R::findOne($this->model(), 'id = ?', array($id));
             /** @var \Skully\App\Models\Setting $instance */
             $instance = $instanceBean->box();
         } else {
             $instance = null;
         }
         try {
             $uploadedImages = $this->processUploadedImage($instance, $this->getParam('settingName'));
         } catch (\Exception $e) {
             $error = $e->getMessage();
         }
     }
     if (!empty($error)) {
         echo json_encode(array('error' => $error));
     } else {
         echo json_encode($uploadedImages);
     }
 }

作者:cesium14    项目:redbea   
/**
  * Test dump().
  *
  * @return void
  */
 public function testDump()
 {
     $beans = R::dispense('bean', 2);
     $beans[0]->name = 'hello';
     $beans[1]->name = 'world';
     $array = R::dump($beans);
     asrt(is_array($array), TRUE);
     foreach ($array as $item) {
         asrt(is_string($item), TRUE);
     }
     $beans[1]->name = 'world, and a very long string that should be shortened';
     $array = R::dump($beans);
     asrt(is_array($array), TRUE);
     asrt(strpos($array[1], '...'), 35);
     //just to get 100% test cov, we dont need to test this
     dmp($beans);
     pass();
     //test wrong input
     asrt(is_array(R::dump(NULL)), TRUE);
     asrt(count(R::dump(NULL)), 0);
     asrt(is_array(R::dump('')), TRUE);
     asrt(count(R::dump('')), 0);
     asrt(is_array(R::dump(1)), TRUE);
     asrt(count(R::dump(1)), 0);
     asrt(is_array(R::dump(TRUE)), TRUE);
     asrt(count(R::dump(FALSE)), 0);
 }

作者:AntonyAntoni    项目:phpbac   
public function testDisableVoteIdea()
 {
     Scripts::LoginUser('newemail2@phpback.org', 'Gates123');
     $this->url('home/profile/4');
     $this->byLinkText('Delete votes')->click();
     $voteidea = RedBean::load('ideas', 3);
     $this->assertEquals($voteidea->votes, '0');
 }

作者:diego-vieir    项目:redbea   
/**
  * Test boxing.
  *
  * @return void
  */
 public function testBasicBox()
 {
     $soup = R::dispense('soup');
     $soup->flavour = 'tomato';
     $this->giveMeSoup($soup->box());
     $this->giveMeBean($soup->box()->unbox());
     $this->giveMeBean($soup);
 }

作者:skullyframewor    项目:projec   
/**
  * Cant have underscored beans
  * @expectedException \RedBeanPHP\RedException
  */
 public function testTwoWordsUnderscoredBean()
 {
     R::freeze(false);
     $testName = R::dispense('test_name');
     $id = R::store($testName);
     R::load('test_name', $id);
     R::freeze($this->frozen);
 }

作者:skullyframewor    项目:skully-admi   
public function testCreateAdmin()
 {
     $this->migrate();
     $admin = $this->app->createModel('admin', array('name' => 'Admin', 'email' => 'admin@skullyframework.com', 'password' => 'lepass', 'password_confirmation' => 'lepass', 'status' => Admin::STATUS_ACTIVE));
     R::store($admin);
     $bean = R::findOne('admin', 'name = ?', array('Admin'));
     $this->assertEquals($bean->name, $admin->get('name'));
 }

作者:AntonyAntoni    项目:phpbac   
public function getSettings()
 {
     $settings = array();
     $result = RedBean::findAll('settings');
     foreach ($result as $setting) {
         $settings[$setting->name] = $setting->value;
     }
     return $settings;
 }

作者:diego-vieir    项目:redbea   
/**
  * Test usage of named parameters in SQL snippets.
  * Issue #299 on Github.
  *
  * @return void
  */
 public function testNamedParamsInSnippets()
 {
     testpack('Test whether we can use named parameters in SQL snippets.');
     R::nuke();
     $book = R::dispense('book');
     $page = R::dispense('page');
     $book->title = 'book';
     $book->sharedPage[] = $page;
     R::store($book);
     //should not give error like: Uncaught [HY093] - SQLSTATE[HY093]: Invalid parameter number: mixed named and positional parameters
     $books = $page->withCondition(' title = :title ', array(':title' => 'book'))->sharedBook;
     asrt(count($books), 1);
     //should not give error...
     $books = $page->withCondition(' title = :title ', array(':title' => 'book'))->sharedBook;
     asrt(count($books), 1);
     R::nuke();
     $book = R::dispense('book');
     $page = R::dispense('page');
     $book->title = 'book';
     $book->comment = 'comment';
     $page->title = 'page';
     $book->ownPage[] = $page;
     R::store($book);
     //should also not give error..
     $count = $book->countOwn('page');
     asrt($count, 1);
     $book = $book->fresh();
     //should also not give error..
     $count = $book->withCondition(' title = ? ', array('page'))->countOwn('page');
     asrt($count, 1);
     $book = $book->fresh();
     //should also not give error..
     $count = $book->withCondition(' title = :title ', array(':title' => 'page'))->countOwn('page');
     asrt($count, 1);
     $book = $book->fresh();
     $pages = $book->withCondition(' title = :title ', array(':title' => 'page'))->ownPage;
     asrt(count($pages), 1);
     //test with duplicate slots...
     $page = reset($pages);
     $page2 = R::dispense('page');
     $page2->ownPage[] = $page;
     R::store($page2);
     $page2 = $page2->fresh();
     $pages = $page2->withCondition(' title = :title ', array(':title' => 'page'))->ownPage;
     asrt(count($pages), 1);
     //test with find()
     $books = R::getRedBean()->find('book', array('title' => array('book')), ' AND title = :title ', array(':title' => 'book'));
     asrt(count($books), 1);
     $books = R::getRedBean()->find('book', array('title' => array('book', 'book2'), 'comment' => array('comment', 'comment2')), ' AND title = :title ', array(':title' => 'book'));
     asrt(count($books), 1);
     //just check numeric works as well...
     $books = R::getRedBean()->find('book', array('title' => array('book', 'book2'), 'comment' => array('comment', 'comment2')), ' AND title = ? ', array('book'));
     asrt(count($books), 1);
     //just extra check to verify glue works
     $books = R::getRedBean()->find('book', array('title' => array('book', 'book2'), 'comment' => array('comment', 'comment2')), ' ORDER BY id ');
     asrt(count($books), 1);
 }

作者:skullyframewor    项目:skull   
/**
  * Test meta column type.
  * 
  * @return void
  */
 public function TypeColumn()
 {
     $book = R::dispense('book');
     $page = R::dispense('page');
     $page->book = $book;
     R::store($page);
     pass();
     asrt($page->getMeta('cast.book_id'), 'id');
 }

作者:gabordemooi    项目:redbea   
/**
  * Test fix for issue #512 - thanks for reporting Bernhard H.
  * OODBBean::__toString() implementation only works with C_ERR_IGNORE
  *
  * @return void
  */
 public function testToStringIssue512()
 {
     R::setErrorHandlingFUSE(\RedBeanPHP\OODBBean::C_ERR_FATAL);
     $boxedBean = R::dispense('boxedbean');
     $str = (string) $boxedBean;
     asrt($str, '{"id":0}');
     //no fatal error
     R::setErrorHandlingFUSE(FALSE);
 }

作者:gabordemooi    项目:redbea   
/**
  * You cant access meta data using the array accessors.
  *
  * @return void
  */
 public function testNoArrayMetaAccess()
 {
     $bean = R::dispense('bean');
     $bean->setMeta('greet', 'hello');
     asrt(isset($bean['greet']), FALSE);
     asrt(isset($bean['__info']['greet']), FALSE);
     asrt(isset($bean['__info']), FALSE);
     asrt(isset($bean['meta']), FALSE);
     asrt(count($bean), 1);
 }


问题


面经


文章

微信
公众号

扫码关注公众号