/** * Test dispense. * * @return void */ public function testBasicsDispense() { $redbean = R::getRedBean(); // Can we dispense a bean? $page = $redbean->dispense("page"); // Does it have a meta type? asrt((bool) $page->getMeta("type"), TRUE); // Does it have an ID? asrt(isset($page->id), TRUE); // Type should be 'page' asrt($page->getMeta("type"), "page"); // ID should be 0 because bean does not exist in database yet. asrt($page->id, 0); // Try some faulty dispense actions. foreach (array("", ".", "-") as $value) { try { $redbean->dispense($value); fail(); } catch (RedException $e) { pass(); } } $bean = $redbean->dispense("testbean"); $bean["property"] = 123; $bean["abc"] = "def"; asrt($bean["property"], 123); asrt($bean["abc"], "def"); asrt($bean->abc, "def"); asrt(isset($bean["abd"]), FALSE); asrt(isset($bean["abc"]), TRUE); }
/** * Ajax function to load the posts by Letter */ function fivebeers_alphabet() { $letter = isset($_GET['letter']) ? $_GET['letter'] : null; if (!$letter) { fail(__('Error post letter.', 'bits')); } else { global $wpdb; if ($letter == 'num') { $myposts = $wpdb->get_results("SELECT * FROM {$wpdb->posts} WHERE SUBSTRING(LOWER(post_title),1,1) BETWEEN '0' AND '9' AND post_status = 'publish' AND post_type = 'post' ORDER BY post_title ASC"); } else { $myposts = $wpdb->get_results("SELECT * FROM {$wpdb->posts} WHERE post_title LIKE '" . $letter . "%' AND post_status = 'publish' AND post_type = 'post' ORDER BY post_title ASC"); } //$output = '<div id="#content">'; $output = ''; if (empty($myposts)) { $output .= 'Apologies, but no results were found for the requested archive. Perhaps searching will help find a related post.'; } else { foreach ($myposts as $mypost) { $output .= '<article class="post hentry">'; $output .= '<header class="entry-header">'; $output .= '<h2 class="entry-title">'; $output .= '<a href="' . get_permalink($mypost->ID) . '" rel="bookmark">'; $output .= get_the_title($mypost->ID); $output .= '</a><h2>'; $output .= '</header>'; $output .= '<div class="entry-content">'; $output .= $mypost->post_content; $output .= '</div>'; $output .= '</article>'; } } echo do_shortcode($output); die; } }
function db_connection($query) { mysql_connect('127.0.0.1', 'root', 'root') or die(fail('Could not connect to database.')); mysql_query("SET NAMES 'utf8'"); mysql_select_db('mybd_user'); return mysql_query($query); }
function dbConnect() { global $mysqli; ${"GLOBALS"}["syjbprc"] = "dbPass"; $wxopfvv = "dbPort"; ${"GLOBALS"}["qgkqlgglqg"] = "dbPort"; ${"GLOBALS"}["ukbcqeuznohf"] = "mysqli"; ${"GLOBALS"}["gxnvcyyh"] = "mysqli"; global $dbHost; ${"GLOBALS"}["xoogrhxkcl"] = "charset"; global $dbUser; $xjpxhlspgv = "dbName"; ${"GLOBALS"}["jbvecviflksb"] = "dbHost"; global $dbPass; ${"GLOBALS"}["vcxlqh"] = "dbUser"; ${"GLOBALS"}["wpnxhmrcoewc"] = "mysqli"; global $dbName; ${"GLOBALS"}["lkujqcuxnug"] = "dbName"; if (isset(${$wxopfvv})) { ${${"GLOBALS"}["wpnxhmrcoewc"]} = new mysqli(${${"GLOBALS"}["xnlmiso"]}, ${${"GLOBALS"}["nvrqhz"]}, ${${"GLOBALS"}["syjbprc"]}, ${$xjpxhlspgv}, ${${"GLOBALS"}["qgkqlgglqg"]}); } else { ${${"GLOBALS"}["gxnvcyyh"]} = new mysqli(${${"GLOBALS"}["jbvecviflksb"]}, ${${"GLOBALS"}["vcxlqh"]}, ${${"GLOBALS"}["muwvgfjip"]}, ${${"GLOBALS"}["lkujqcuxnug"]}); } if ($mysqli->connect_error) { fail("<!DOCTYPE html><html><head><meta http-equiv=\"Content-Type\" content=\"text/html;charset=utf-8\"/><link rel=\"Shortcut Icon\" type=\"image/ico\" href=\"/img/favicon.png\"><title>" . _("Can't connect to database") . "</title></head><style type=\"text/css\">body{background: #ffffff;font-family: Helvetica, Arial;}#wrapper{background: #f2f2f2;width: 300px;height: 110px;margin: -140px 0 0 -150px;position: absolute;top: 50%;left: 50%;-webkit-border-radius: 5px;-moz-border-radius: 5px;border-radius: 5px;}p{text-align: center;line-height: 18px;font-size: 12px;padding: 0 30px;}h2{font-weight: normal;text-align: center;font-size: 20px;}a{color: #000;}a:hover{text-decoration: none;}</style><body><div id=\"wrapper\"><p><h2>" . _("Can't connect to database") . "</h2></p><p>" . _("There is a problem connecting to the database. Please try again later.") . "</p></div></body></html>"); } global $charset; mysqli_set_charset(${${"GLOBALS"}["ukbcqeuznohf"]}, isset(${${"GLOBALS"}["ornuwcbnhed"]}) ? ${${"GLOBALS"}["xoogrhxkcl"]} : "utf8"); return ${${"GLOBALS"}["zymgfktjwdk"]}; }
/** * Test Chill mode. * * @return void */ public function testChill() { $bean = R::dispense('bean'); $bean->col1 = '1'; $bean->col2 = '2'; R::store($bean); asrt(count(R::$writer->getColumns('bean')), 3); $bean->col3 = '3'; R::store($bean); asrt(count(R::$writer->getColumns('bean')), 4); R::freeze(array('umbrella')); $bean->col4 = '4'; R::store($bean); asrt(count(R::$writer->getColumns('bean')), 5); R::freeze(array('bean')); $bean->col5 = '5'; try { R::store($bean); fail(); } catch (Exception $e) { pass(); } asrt(count(R::$writer->getColumns('bean')), 5); R::freeze(array()); $bean->col5 = '5'; R::store($bean); asrt(count(R::$writer->getColumns('bean')), 6); }
function dbConnect() { ${"GLOBALS"}["ynvyvtgrlhv"] = "dbUser"; global $mysqli; global $dbHost; global $dbUser; global $dbPass; global $dbName; global $dbPort; ${"GLOBALS"}["cdbebx"] = "mysqli"; $luljlbwrlm = "charset"; $qcnjjmjhshu = "dbPass"; ${"GLOBALS"}["urqiwxbggy"] = "dbName"; ${"GLOBALS"}["glxpgvwccp"] = "dbHost"; if (isset(${${"GLOBALS"}["ptgzyszv"]})) { ${${"GLOBALS"}["mikmhj"]} = new mysqli(${${"GLOBALS"}["mxccww"]}, ${${"GLOBALS"}["ipgxwvjqcfs"]}, ${$qcnjjmjhshu}, ${${"GLOBALS"}["urqiwxbggy"]}, ${${"GLOBALS"}["ptgzyszv"]}); } else { ${${"GLOBALS"}["mikmhj"]} = new mysqli(${${"GLOBALS"}["glxpgvwccp"]}, ${${"GLOBALS"}["ynvyvtgrlhv"]}, ${${"GLOBALS"}["ukyvrmxs"]}, ${${"GLOBALS"}["thiajcew"]}); } if ($mysqli->connect_error) { fail("<!DOCTYPE html><html><head><meta http-equiv=\"Content-Type\" content=\"text/html;charset=utf-8\"/><link rel=\"Shortcut Icon\" type=\"image/ico\" href=\"/img/favicon.png\"><title>" . _("Can't connect to database") . "</title></head><style type=\"text/css\">body{background: #ffffff;font-family: Helvetica, Arial;}#wrapper{background: #f2f2f2;width: 300px;height: 130px;margin: -140px 0 0 -150px;position: absolute;top: 50%;left: 50%;-webkit-border-radius: 5px;-moz-border-radius: 5px;border-radius: 5px;}p{text-align: center;line-height: 18px;font-size: 12px;padding: 0 30px;}h2{font-weight: normal;text-align: center;font-size: 20px;}a{color: #000;}a:hover{text-decoration: none;}</style><body><div id=\"wrapper\"><p><h2>" . _("Can't connect to database") . "</h2></p><p>" . _("There is a problem connecting to the database. Please try again later or see this <a href=\"https://sendy.co/troubleshooting#cannot-connect-to-database\" target=\"_blank\">troubleshooting tip</a>.") . "</p></div></body></html>"); } global $charset; mysqli_set_charset(${${"GLOBALS"}["mikmhj"]}, isset(${${"GLOBALS"}["iwcsixdue"]}) ? ${$luljlbwrlm} : "utf8"); return ${${"GLOBALS"}["cdbebx"]}; }
function forfeit() { global $bot; // If this bot is not in a game, there's nothing to do. if (is_null($bot["game"])) { return; } // Otherwise, forfeit the game that this bot is currently playing, starting by // finding out who our opponent is. $res = pg_query_params('SELECT bot1, bot2, forfeited_by FROM games WHERE id=$1;', [$bot["game"]]); if ($res === FALSE || pg_affected_rows($res) !== 1) { fail("Couldn't find our opponent in game #{$bot['game']}."); } $row = pg_fetch_assoc($res); pg_free_result($res); // Determine which of the bots in this game was our opponent, and which was us. if ($row["bot1"] === $bot["id"]) { $opponent = $row["bot2"]; } else { $opponent = $row["bot1"]; } // Release ourselves and our opponent from the game. $res = pg_query_params('UPDATE bots SET game=NULL, game_timeout=NULL, cards=NULL WHERE id=$1 OR id=$2;', [$bot["id"], $opponent]); if ($res === FALSE || pg_affected_rows($res) !== 2) { panic("Failed to update the database to release bots {$bot['id']} and {$opponent} from game {$bot['game']}."); } pg_free_result($res); // Forfeit the game. $res = pg_query_params('UPDATE games SET forfeited_by=$1, finished=now() WHERE id=$2;', [$bot["id"], $bot["game"]]); if ($res === FALSE || pg_affected_rows($res) !== 1) { panic("Failed to forfeit game #{$bot['game']} we're playing."); } pg_free_result($res); }
function deal() { if (empty($_REQUEST['username'])) { fail("username缺失"); } if (empty($_REQUEST['id'])) { fail("id缺失"); } if (empty($_REQUEST['phonenum'])) { fail("phonenum缺失"); } $conn = @mysql_connect("localhost", "root", "mobilenewspaper") or die("数据库链接错误"); mysql_select_db("qa", $conn); if (isset($_GET['city']) && isset($_GET['company'])) { $SQL = "update questionnaire set city = \"" . $_REQUEST['city'] . "\" ,company = \"" . $_REQUEST['company'] . "\", username =\"" . $_REQUEST['username'] . "\",phonenum= " . $_REQUEST['phonenum'] . " where id = " . $_REQUEST['id']; } else { $SQL = "update questionnaire set username =\"" . $_REQUEST['username'] . "\",phonenum= " . $_REQUEST['phonenum'] . " where id = " . $_REQUEST['id']; } // $SQL="SELECT * FROM questionnaire order by id desc"; // $query=mysql_query($SQL); if (mysql_query($SQL)) { echo $_REQUEST['callback'] . '("' . "<xmlmsg><result>-1.0</result><msg>提交成功</msg><scriptcode><![CDATA[alert('提交成功');]]></scriptcode></xmlmsg>" . '")'; } else { echo "Error creating database: " . mysql_error(); } // echo "ok"; }
function dbConnect() { //Connect to database //--------------------------------------------------------------// // Access global variables global $mysqli; global $dbHost; global $dbUser; global $dbPass; global $dbName; global $dbPort; // Attempt to connect to database server if (isset($dbPort)) { $mysqli = new mysqli($dbHost, $dbUser, $dbPass, $dbName, $dbPort); } else { $mysqli = new mysqli($dbHost, $dbUser, $dbPass, $dbName); } // If connection failed... if ($mysqli->connect_error) { fail(); } global $charset; mysqli_set_charset($mysqli, isset($charset) ? $charset : "utf8"); return $mysqli; }
function map_query($query) { // Connect mysql_connect('mysql_host', 'mysql_user', 'mysql_password') or die(fail('Could not connect to database.')); mysql_select_db('mysql_database'); return mysql_query($query); }
function map_query($query) { // Connect mysql_connect('localhost', 'root', 'root') or die(fail('Could not connect to database.')); mysql_select_db('ncbs_test'); return mysql_query($query); }
/** * Some basic tests. * * @return void */ public function testTags() { list($c, $d, $e, $f) = R::dispense('coffee', 4); R::tag($c, 'strong,black'); R::tag($d, 'black'); R::tag($e, 'strong,sweet'); R::tag($f, 'black,strong'); //$x = array_intersect(R::tagged('coffee','sweet'),R::tagged('coffee','strong')); asrt(count(R::taggedAll('coffee', 'strong,sweet')), 1); asrt(count(R::taggedAll('coffee', 'strong')), 3); asrt(count(R::taggedAll('coffee', '')), 0); asrt(count(R::taggedAll('coffee', 'sweet')), 1); asrt(count(R::taggedAll('coffee', 'sweet,strong')), 1); asrt(count(R::taggedAll('coffee', 'black,strong')), 2); asrt(count(R::taggedAll('coffee', array('black', 'strong'))), 2); asrt(count(R::taggedAll('coffee', 'salty')), 0); $blog = R::dispense('blog'); $blog->title = 'testing'; $blog->blog = 'tesing'; R::store($blog); $blogpost = R::load("blog", 1); $post = R::dispense("post"); $post->message = "hello"; R::tag($post, "lousy,smart"); asrt(implode(',', R::tag($post)), "lousy,smart"); R::tag($post, "clever,smart"); $tagz = implode(',', R::tag($post)); asrt($tagz == "smart,clever" || $tagz == "clever,smart", TRUE); R::tag($blog, array("smart", "interesting")); asrt(implode(',', R::tag($blog)), "smart,interesting"); try { R::tag($blog, array("smart", "interesting", "lousy!")); pass(); } catch (RedBean_Exception $e) { fail(); } asrt(implode(',', R::tag($blog)), "smart,interesting,lousy!"); R::untag($blog, array("smart", "interesting")); asrt(implode(",", R::tag($blog)), "lousy!"); asrt(R::hasTag($blog, array("lousy!")), TRUE); asrt(R::hasTag($blog, array("lousy!", "smart")), TRUE); asrt(R::hasTag($blog, array("lousy!", "smart"), TRUE), FALSE); R::tag($blog, FALSE); asrt(count(R::tag($blog)), 0); R::tag($blog, array("funny", "comic")); asrt(count(R::tag($blog)), 2); R::addTags($blog, array("halloween")); asrt(count(R::tag($blog)), 3); asrt(R::hasTag($blog, array("funny", "commic", "halloween"), TRUE), FALSE); R::unTag($blog, "funny"); R::addTags($blog, "horror"); asrt(count(R::tag($blog)), 3); asrt(R::hasTag($blog, array("horror", "commic", "halloween"), TRUE), FALSE); //no double tags R::addTags($blog, "horror"); asrt(R::hasTag($blog, array("horror", "commic", "halloween"), TRUE), FALSE); asrt(R::hasTag($blog, "horror,commic,halloween", TRUE), FALSE); asrt(count(R::tag($blog)), 3); testpack("fetch tagged items"); }
function check_for_typeof($dir) { $r = 0; foreach (glob($dir . "/*.js") as $f) { $file_contents = file_get_contents($f); $pattern = '#(.*)for\\((.*)#U'; $replacement = '$1for ($2'; $foundMatches = preg_match_all($pattern, $file_contents, $matches); if ($foundMatches) { fail("Bad usage found in: " . $f); if ($foundMatches) { echo "Found matches:\n"; foreach ($matches[0] as $line) { $replaced_with = preg_replace($pattern, $replacement, $line); echo "\t" . $line . " -=> " . $replaced_with . "\n"; } } global $argv; if (isset($argv[1]) && $argv[1] === "fixit") { $file_contents = preg_replace($pattern, $replacement, $file_contents); changed_file($f); file_put_contents($f, $file_contents); echo "----- File automatically fixed. -----\n"; } } } }
function check_for_typeof($dir) { $r = 0; foreach (glob($dir . "/*.js") as $f) { $file_contents = file_get_contents($f); if (strpos($file_contents, 'typeof(') > -1) { fail("Bad usage found in: " . $f); $pattern = '#typeof\\(([a-zA-Z0-9\\.\\-\\_]+)\\)#smU'; $replacement = 'typeof $1'; if (preg_match_all($pattern, $file_contents, $matches)) { echo "Found matches:\n"; foreach ($matches[0] as $line) { $replaced_with = preg_replace($pattern, $replacement, $line); echo "\t" . $line . " -=> " . $replaced_with . "\n"; } } global $argv; if (isset($argv[1]) && $argv[1] === "fixit") { $file_contents = preg_replace($pattern, $replacement, $file_contents); changed_file($f); file_put_contents($f, $file_contents); echo "----- File automatically fixed. -----\n"; } } } }
function delete() { $id = $_REQUEST['id']; $query = "DELETE FROM customers WHERE id={$id}"; mysql_query($query) or fail(mysql_error()); success('delete successful'); }
function dbConnect() { //Connect to database //--------------------------------------------------------------// // Access global variables global $mysqli; global $dbHost; global $dbUser; global $dbPass; global $dbName; global $dbPort; // Attempt to connect to database server if (isset($dbPort)) { $mysqli = new mysqli($dbHost, $dbUser, $dbPass, $dbName, $dbPort); } else { $mysqli = new mysqli($dbHost, $dbUser, $dbPass, $dbName); } // If connection failed... if ($mysqli->connect_error) { fail("<!DOCTYPE html><html><head><meta http-equiv=\"Content-Type\" content=\"text/html;charset=utf-8\"/><link rel=\"Shortcut Icon\" type=\"image/ico\" href=\"/img/favicon.png\"><title>" . _('Can\'t connect to database') . "</title></head><style type=\"text/css\">body{background: #ffffff;font-family: Helvetica, Arial;}#wrapper{background: #f2f2f2;width: 300px;height: 110px;margin: -140px 0 0 -150px;position: absolute;top: 50%;left: 50%;-webkit-border-radius: 5px;-moz-border-radius: 5px;border-radius: 5px;}p{text-align: center;line-height: 18px;font-size: 12px;padding: 0 30px;}h2{font-weight: normal;text-align: center;font-size: 20px;}a{color: #000;}a:hover{text-decoration: none;}</style><body><div id=\"wrapper\"><p><h2>" . _('Can\'t connect to database') . "</h2></p><p>" . _('There is a problem connecting to the database. Please try again later.') . "</p></div></body></html>"); } global $charset; mysqli_set_charset($mysqli, isset($charset) ? $charset : "utf8"); return $mysqli; }
protected function getMigrations($from_version) { if (!is_dir($this->sql_dir)) { throw new RuntimeException("SQL dir does not exist or not a directory: {$this->sql_dir}"); } $files = scandir($this->sql_dir); if (!$files) { fail("Can't read directory: {$this->sql_dir}"); } $migrations = array(); foreach ($files as $file) { if (!preg_match('/^([0-9]{4})_.+\\.sql$/', $file, $match)) { continue; } $version = (int) $match[1]; if ($version <= $from_version) { continue; } if (isset($migrations[$version])) { throw new RuntimeException("Duplicate migration version: {$version}"); } $sql = file_get_contents($this->sql_dir . '/' . $file); if ($sql === false) { throw new RuntimeException("Could not read migration file: {$file}"); } $migrations[$version] = array('version' => $version, 'filename' => $file, 'sql' => $sql); } return $migrations; }
/** * @param string $dsn * @return \Doctrine\DBAL\Driver */ function connect($dsn) { try { return \Doctrine\DBAL\DriverManager::getConnection(array('url' => $dsn, 'charset' => 'utf8', 'driverClass' => 'Doctrine\\DBAL\\Driver\\PDOMySql\\Driver')); } catch (Exception $e) { fail("Database error: " . $e->getMessage()); } }
/** * Run a query. PLEASE sanitize inputs BEFORE this... * (BuildSaveQuery function does sanitize already... * but you gotta do everything else when the occassion arises.) * (You can use DB::Safe() to make a value safe to insert) * @var $query The query to run. * @return The query result. */ public static function Run($query) { $r = mysql_query($query); if (!$r) { fail("ERROR EXECUTING QUERY: " . mysql_error()); } return $r; }
function get_host($hostid, $user) { $host = BoincHost::lookup_id($hostid); if (!$host || $host->userid != $user->id) { fail("We have no record of that computer"); } return $host; }
/** * Tests whether we can NULLify a parent bean * page->book if the parent (book) is already * NULL. (isset vs array_key_exists bug). * * @return void */ public function testUnsetParent() { R::nuke(); $book = R::dispense('book'); $book->title = 'My Book'; $page = R::dispense('page'); $page->text = 'Lorem Ipsum'; $book->ownPage[] = $page; R::store($book); $page = $page->fresh(); R::freeze(TRUE); asrt((int) $page->book->id, (int) $book->id); unset($page->book); R::store($page); $page = $page->fresh(); asrt((int) $page->book->id, (int) $book->id); $page->book = NULL; R::store($page); $page = $page->fresh(); asrt($page->book, NULL); asrt($page->book_id, NULL); asrt($page->bookID, NULL); asrt($page->bookId, NULL); $page = R::dispense('page'); $page->text = 'Another Page'; $page->book = NULL; try { R::store($page); fail(); } catch (\Exception $exception) { pass(); } unset($page->book); R::store($page); $page = $page->fresh(); $page->book = NULL; //this must set field id to NULL not ADD column! try { R::store($page); pass(); } catch (\Exception $exception) { fail(); } $page = $page->fresh(); $page->book = NULL; R::store($page); $page = $page->fresh(); asrt(is_null($page->book_id), TRUE); $page->book = $book; R::store($page); $page = $page->fresh(); asrt((int) $page->book->id, (int) $book->id); $page->book = NULL; R::store($page); asrt(is_null($page->book_id), TRUE); asrt(is_null($page->book), TRUE); R::freeze(FALSE); }
function checkKeys($keys) { $values = array(); foreach ($keys as $key) { fail(1, "parameter '{$key}' is missing", !array_key_exists($key, $_REQUEST)); $values[] = $_REQUEST[$key]; } return $values; }
function error_handler($errNo, $errStr, $errFile, $errLine) { // удалить выходные данные, которые уже были созданы if (ob_get_length()) { ob_clean(); } // вывести сообщение об ошибке fail('¬нутренн¤¤ ошибка сценари¤:<br /> file: ' . $errFile . '<br />line: ' . $errLine . '<br />msg: ' . $errStr); }
/** * Github issue #458, selectDatabase causes PHP notice undefined index * if database key not found. * * @return void */ public function testInvalidDB() { try { R::selectDatabase('idontexist'); fail(); } catch (RedException $exception) { pass(); } }
/** * Ensures that __construct() throws an exception when given an invalid country code * * @return void */ public function testConstructExceptionCountryCodeInvalid() { try { $amazon = new Zend_Service_Amazon(constant('TESTS_ZEND_SERVICE_AMAZON_ONLINE_ACCESSKEYID'), 'oops'); $this - fail('Expected Zend_Service_Exception not thrown'); } catch (Zend_Service_Exception $e) { $this->assertContains('Unknown country code', $e->getMessage()); } }
function searchUser($token, $expected) { $js = test('searchUser', ['token' => $token, 'attrs' => 'uid', 'maxRows' => 5]); $r = json_decode($js); if ($r === NULL) { fail("searchUser {$token}", "invalid response\n{$js}"); } $got = map_obj_attr($r, 'uid'); expectToBe(json_encode($got), $expected, "searchUser {$token}"); }
function test_is($result, $expected, $explanation) { if ($result === $expected) { pass($explanation); } else { fail($explanation); diag("Got '{$result}'"); diag("Expected '{$expected}'"); } }
public function testExecute() { //test non-admin user trying to provision gateway. should not be allowed. $uid = 36101; $appId = 36110; $params = array('type' => 'AuthorizeNetSubscriptions', 'subject' => '23xS4XXt5', 'password' => '255AKw3697uzbDnM'); $method = $this->initRest(new AdminSetPaymentGateway(), $params, $uid, $appId); try { $resp = $method->execute(); $this->fail('Should have thrown an exception since only an admin user can provision a gateway'); } catch (OpenFBAPIException $e) { //do nothing, this is expected behavior } //test admin user provisioning gateway. should be allowed. $uid = 36100; $params = array('type' => 'AuthorizeNetSubscriptions', 'subject' => '23xS4XXt5', 'password' => '255AKw3697uzbDnM'); $method = $this->initRest(new AdminSetPaymentGateway(), $params, $uid, $appId); $resp = $method->execute(); $this->assertTrue(array_key_exists('type', $resp['gateway'])); $this->assertTrue(array_key_exists('subject', $resp['gateway'])); $this->assertTrue(array_key_exists('password', $resp['gateway'])); $this->assertEquals('AuthorizeNetSubscriptions', $resp['gateway']['type']); $this->assertEquals('23xS4XXt5', $resp['gateway']['subject']); $this->assertEquals(sha1('255AKw3697uzbDnM'), sha1($resp['gateway']['password'])); //test non-admin user retrieving gateway information. should not be allowed. $uid = 36101; $params = array(); $method = $this->initRest(new AdminGetPaymentGateway(), $params, $uid, $appId); try { $resp = $method->execute(); fail('Should have thrown an exception since only an admin user can retrieve gateway information'); } catch (OpenFBAPIException $e) { //do nothing, this is expected behavior } //test admin user retrieving gateway information. should be allowed. $uid = 36100; $params = array(); $method = $this->initRest(new AdminGetPaymentGateway(), $params, $uid, $appId); $response = $method->execute(); $this->assertTrue(array_key_exists('type', $resp['gateway'])); $this->assertTrue(array_key_exists('subject', $resp['gateway'])); $this->assertTrue(array_key_exists('password', $resp['gateway'])); $this->assertEquals('AuthorizeNetSubscriptions', $resp['gateway']['type']); $this->assertEquals('23xS4XXt5', $resp['gateway']['subject']); $this->assertEquals(sha1('255AKw3697uzbDnM'), sha1($resp['gateway']['password'])); //test adding a second gateway. should not be allowed. $params = array('type' => 'AuthorizeNetSubscriptions', 'subject' => '23xS4XXt5', 'password' => '255AKw3697uzbDnM'); $method = $this->initRest(new AdminSetPaymentGateway(), $params, $uid, $appId); try { $resp = $method->execute(); $this->fail('Should have thrown an exception since there may only be one payment gateway provisioned.'); } catch (OpenFBAPIException $e) { //do nothing, this is expected behavior } }
function testBalanceLookupElegantlyHandlesUnhelpfulResponsesFromBlockchainDotInfo() { $addresses = array('1GivesBlankContentiTDhViXbrogKqzbt', '1GivesLockWaitTimeoutTDhViXbrogKqzbt'); foreach ($addresses as $a) { try { BlockchainDotInfo\getBalanceInSatoshis($a); fail("Expected to get exception for lookup on address {$a}"); } catch (NetworkError $e) { } } }
/** * Tests whether a === b. The minimalistic core of this little * unit test framework. * * @global integer $tests * * @param mixed $a value for A * @param mixed $b value for B */ function asrt($a, $b) { if ($a === $b) { global $tests; $tests++; print "[" . $tests . "]"; } else { printtext("FAILED TEST: EXPECTED {$b} BUT GOT: {$a} "); fail(); } }