/** * 检测注册是否唯一,主要为用户名、手机号、邮箱 */ public function checkunique_get() { $checktype = I('get.type'); $checkvalue = I('get.value'); $userInfo = M('userInfo'); $user; if ($checktype . equal('username')) { $user = $userInfo->where('username="******"')->find(); } else { if ($checktype . equal('telephone')) { $user = $userInfo->where('telephone="' . $checkvalue . '"')->find(); } else { if ($checktype . equal('email')) { $user = $userInfo->where('email="' . $checkvalue . '"')->find(); } } } $result; if (isset($user)) { $result['result'] = 'ok'; } else { $result['result'] = 'error'; } $this->response($result, json); }
/** * @param string $selector_ * * @return string */ function equalWidth($selector_) { return equal('width', $selector_); }
$product = $products['payload'][0]; equal($oname, $product['name'], 'old name is equal to product name'); equal(round($old_price, 2), round($product['price'], 2), 'old price should equal product price'); /* * Now let's look at creating a completely new product. */ //Step 1, let's find out what the supported attributes are: $data = array('action' => 'woocommerce_json_api', 'proc' => 'get_supported_attributes', 'arguments' => array('token' => $token)); $result = curl_post($url, $data); $result = json_decode($result, true); equal($result['status'], true, 'Get supported attributes?'); $supported_attributes = $result['payload'][0]; keyExists('Product', $supported_attributes, 'Do we have attributes for Product?'); $r = rand(1, 9999999); $sr = rand(1, 5); $p = $sr * 1.25; // This is the minimum info to get a sellable product $new_product_data = array('name' => "An API Created Product {$r}", 'price' => $p, 'sku' => "API{$r}", 'visibility' => 'visible', 'product_type' => 'simple', 'type' => 'product', 'status' => 'instock'); $data = array('action' => 'woocommerce_json_api', 'proc' => 'set_products', 'arguments' => array('token' => $token), 'payload' => array($new_product_data)); $result = curl_post($url, $data); $result = json_decode($result, true); equal($result['status'], true, 'Get supported attributes?'); $product = $result['payload'][0]; keyExists('id', $product, 'Was the id set?'); // Try uploading an image $new_product_data = array('name' => "An API Created Product {$r}", 'price' => $p, 'sku' => "API{$r}", 'visibility' => 'visible', 'product_type' => 'simple', 'type' => 'product', 'status' => 'instock', 'images' => array(array('name' => 'fractal.png')), 'featured_image' => array(array('name' => 'fractal3.png'))); $data = array('action' => 'woocommerce_json_api', 'proc' => 'set_products', 'arguments' => array('token' => $token), 'payload' => array($new_product_data), 'images[0]' => "@" . dirname(__FILE__) . "/fractal.png", 'images[1]' => "@" . dirname(__FILE__) . "/fractal3.png"); $result = curl_post($url, $data); $result = json_decode($result, true); $product = $result['payload'][0]; keyExists('id', $product['images'][0], 'Was the id of the image set?');
$new_status = 'completed'; } echo "Current Order Status is: {$order['status']}\n"; $order['status'] = $new_status; $result['proc'] = 'set_orders'; $result['payload'] = array($order); $result = curl_post($url, $result); echo "Result is" . $result; $result = json_decode($result, true); print_r($result['payload']); $order = $result['payload'][0]; echo "After update it is: {$order['status']}\n"; equal($new_status, $order['status'], "Order status should eql {$new_status} on return"); $data = array('action' => 'woocommerce_json_api', 'proc' => 'get_orders', 'arguments' => array('username' => $username, 'password' => $password, 'per_page' => 1, 'page' => 1)); $result = curl_post($url, $data); $result = json_decode($result, true); $order = $result['payload'][0]; equal($new_status, $order['status'], "Order status should eql {$new_status} on get_orders"); $order['status'] = $old_status; $result['proc'] = 'set_orders'; $result['payload'] = array($order); $result = curl_post($url, $result); $result = json_decode($result, true); $order = $result['payload'][0]; equal($old_status, $order['status'], "Order status should equal {$old_status} on return"); $data = array('action' => 'woocommerce_json_api', 'proc' => 'get_orders', 'arguments' => array('username' => $username, 'password' => $password, 'per_page' => 1, 'page' => 1)); $result = curl_post($url, $data); $result = json_decode($result, true); $order = $result['payload'][0]; equal($old_status, $order['status'], "Order status should eql {$old_status} on get_orders");
function osv_row($userid, $lastname, $firstname, &$results) { global $conf; //$from=$_REQUEST['from']; //$to=$_REQUEST['to']; mysql_connect($conf['dbhost'], $conf['dbuser'], $conf['dbpassword']) or die(mysql_error()); mysql_select_db($conf['dbase']) or die(mysql_error()); $result[0] = $lastname . ' ' . $firstname; $res = mysql_query("select id,name from mdl_problemstatement order by id"); //where course=... if (!$res) { print mysql_error(); } while ($problemstatementrow = mysql_fetch_assoc($res)) { $problemstatementid = $problemstatementrow['id']; $res1 = mysql_query("select submissions.processed,submissions.succeeded from mdl_user user join mdl_problemstatement_submissions submissions on (submissions.userid=user.id) where (submissions.problemstatement={$problemstatementid} and user.id={$userid}) order by submissions.timemodified"); if (!$res1) { print mysql_error(); } $result[$problemstatementid] = ''; $oldprocessed = null; $oldsucceeded = null; $count = 0; $succ = FALSE; while ($row = mysql_fetch_assoc($res1)) { $processed = $row['processed']; $succeeded = $row['succeeded']; if ($processed == 1 && $succeeded == 1) { $succ = TRUE; } if ($count > 0 && !equal($processed, $succeeded, $oldprocessed, $oldsucceeded)) { $result[$problemstatementid] .= get_colored_status($oldprocessed, $oldsucceeded, $count); $count = 1; } else { ++$count; } $oldprocessed = $processed; $oldsucceeded = $succeeded; } if ($count > 0) { $result[$problemstatementid] .= get_colored_status($oldprocessed, $oldsucceeded, $count); } $results[$problemstatementid] = $succ; } // count max index $res = mysql_query("select max(id) from mdl_problemstatement"); // where course=... if (!$res) { print mysql_error(); } $maxindex = mysql_fetch_row($res); $maxindex = $maxindex[0]; $res = mysql_query("select id from mdl_problemstatement"); // where course=... if (!$res) { print mysql_error(); } $i = 0; while ($problemstatementrow = mysql_fetch_assoc($res)) { $problemstatementid = $problemstatementrow['id']; $res1 = mysql_query("select count(submissions.succeeded) from mdl_problemstatement_submissions submissions where (submissions.problemstatement={$problemstatementid}) and (submissions.userid={$userid}) and (submissions.succeeded=1) and (submissions.processed=1)"); if (!$res1) { print mysql_error(); } $count = mysql_fetch_row($res1); $count = $count[0]; if ($count > 0) { ++$i; } } $result[$maxindex + 1] = $i; return $result; }
$old_name = $product['variations'][0]['name']; $new_name = $old_name . " Edited"; echo " First variation name is: {$old_name}\n"; $product['variations'][0]['name'] = $new_name; $result['payload'] = array($product); $result['proc'] = 'set_products'; $result = curl_post($url, $result); $result = json_decode($result, true); $product = $result['payload'][0]; // We make sure we get the product fresh from the db $data = array('action' => 'woocommerce_json_api', 'proc' => 'get_products', 'arguments' => array('token' => $token, 'ids' => array($product['id']))); $result = curl_post($url, $data); $result = json_decode($result, true); $product = $result['payload'][0]; notEqual($old_name, $product['variations'][0]['name'], "Was the variation name edited?"); // Now we edit it back $product['variations'][0]['name'] = $old_name; $result['payload'] = array($product); $result['proc'] = 'set_products'; $result = curl_post($url, $result); $result = json_decode($result, true); $product = $result['payload'][0]; // We make sure we get the product fresh from the db $data = array('action' => 'woocommerce_json_api', 'proc' => 'get_products', 'arguments' => array('token' => $token, 'ids' => array($product['id'])), 'model_filters' => array('WCAPI_product_meta_attributes_table' => array('size_attribute' => array('name' => 'attribute_size', 'type' => 'string', 'values' => array('small', 'medium', 'large'), 'sizehint' => 2)))); $result = curl_post($url, $data); $result = json_decode($result, true); $product = $result['payload'][0]; $v1 = $product['variations'][0]; equal($v1['size_attribute'], 'small', "Is the size_attribute set?"); equal($old_name, $product['variations'][0]['name'], "Did we restore the variation name?");
<?php require_once "functions.php"; include "config.php"; include dirname(__FILE__) . "/../../../../wp-config.php"; require_once dirname(__FILE__) . "/../classes/WCAPI/includes.php"; $db = new mysqli(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME); $db->set_charset(DB_CHARSET); $mapper = new Mapper($db); $Header("General Mapper Setup"); notEqual($mapper->connection, null); shouldBeTypeOf($mapper->errors, 'array'); hasAtMost($mapper->details, 0); equal($mapper->table_prefix, ''); $mapper->table_prefix = $table_prefix; equal($mapper->table_prefix, $table_prefix); equal($mapper->self, $mapper, '$self should equal $this'); $Header("Testing Create Functionality"); $old_self = $mapper; $mock = new Mock(); $mock->whenAttr('table_prefix', 'mock_'); $mapper->setSelf($mock); $model = new \WCAPI\Product(); $mapper->create($model, array()); $mock->hasReceived('table_prefix');
<?php require_once "functions.php"; include "config.php"; $Header("Setting Customers Passwords"); $data = array('action' => 'woocommerce_json_api', 'proc' => 'get_customers', 'arguments' => array('token' => $token, 'per_page' => 2, 'page' => 1)); $result = curl_post($url, $data); verifySuccess("Get Customers", $result); verifyNonZeroPayload("Get Customers", $result); $result = json_decode($result, true); $user_id = $result['payload'][0]['id']; $new_pass = '******' . rand(0, 10); $result['payload'] = array(array('id' => 1, 'password' => $new_pass)); $result['proc'] = 'set_customers_passwords'; $result = curl_post($url, $result); echo $result; verifySuccess("did we set it?", $result); $result = json_decode($result, true); equal('[FILTERED]', $result['payload'][0]['password'], "New password is: {$new_pass}");
<?php require_once "functions.php"; include "config.php"; $Header("Writing Store Settings"); $data = array('action' => 'woocommerce_json_api', 'proc' => 'get_store_settings', 'arguments' => array('token' => $token)); $result = curl_post($url, $data); verifySuccess("Get Store Settings", $result); $result = json_decode($result, true); $old_value = $result['payload']['force_ssl_checkout']; $new_value = $old_value == 'no' ? 'yes' : 'no'; notEqual($old_value, $new_value); $result['payload']['force_ssl_checkout'] = $new_value; $result['proc'] = 'set_store_settings'; $result = curl_post($url, $result); verifySuccess("Set Store Settings", $result); $result = json_decode($result, true); equal($result['payload']['force_ssl_checkout'], $new_value); $result['payload']['force_ssl_checkout'] = $old_value; $result = curl_post($url, $result); verifySuccess("Set Store Settings 2", $result); $result = json_decode($result, true); equal($result['payload']['force_ssl_checkout'], $old_value); // Test filtering $data = array('action' => 'woocommerce_json_api', 'proc' => 'get_store_settings', 'arguments' => array('token' => $token, 'filter' => 'force')); $result = curl_post($url, $data); verifySuccess("Get Store Filtered Settings", $result); $result = json_decode($result, true); keyExists('force_ssl_checkout', $result['payload']);
foreach ($orders['payload'] as $order) { if (isset($order['notes']) && is_array($order['notes']) && count($order['notes']) > 0) { $note_count2 += count($order['notes']); $has_notes = true; } if (isset($order['order_items']) && is_array($order['order_items']) && count($order['order_items']) > 0) { $has_ois = true; } } notEqual($note_count2, $note_count); $Header("Creating a new Order"); $data = array('action' => 'woocommerce_json_api', 'proc' => 'get_orders', 'arguments' => array('token' => $token, 'per_page' => 2, 'page' => 1)); $result = curl_post($url, $data); $result = json_decode($result, true); $new_order = $result['payload'][0]; unset($new_order['id']); unset($new_order['notes']); $relations = array('order_items', 'tax_items', 'coupon_items'); foreach ($relations as $relation) { foreach ($new_order[$relation] as &$item) { unset($item['id']); } } $new_order['name'] = "From the API"; $new_order['status'] = 'processing'; $result['payload'] = array($new_order); $result['proc'] = 'set_orders'; $new_result = curl_post($url, $result); $new_result = json_decode($new_result, true); equal($new_result['status'], true); keyExists('id', $new_result['payload'][0]);
require_once "functions.php"; include "config.php"; $Header("Writing Products"); $data = array('action' => 'woocommerce_json_api', 'proc' => 'get_products', 'arguments' => array('token' => $token, 'per_page' => 2, 'page' => 1, 'include' => array('variations' => false, 'images' => false, 'featured_image' => false, 'categories' => false, 'tags' => false, 'reviews' => false, 'variations_in_products' => false))); $result = curl_post($url, $data); $products = json_decode($result, true); $product = $products['payload'][0]; $chosen_sku = $product['sku']; $old_quantity = $product['quantity']; $nqty = $old_quantity + 5; equal(1, 1, "old_quantity: {$old_quantity} and nqty: {$nqty}"); $product['quantity'] = $nqty; $products['proc'] = 'set_products_quantities'; $products['payload'] = array($product); $result = curl_post($url, $products); // Now do the load a second time: equal(1, 1, "Now reloading"); $data['arguments']['skus'] = array($chosen_sku); $result = curl_post($url, $data); $products = json_decode($result, true); $product = $products['payload'][0]; notEqual(round($old_quantity, 2), round($product['quantity'], 2), "{$old_quantity} should not equal {$product['quantity']}"); equal(round($nqty, 2), round($product['quantity'], 2), 'new quantity should equal product quantity'); $product['quantity'] = $old_quantity; $products['proc'] = 'set_products_quantities'; $products['payload'][0] = $product; $result = curl_post($url, $products); $products = json_decode($result, true); $product = $products['payload'][0]; equal(round($old_quantity, 2), round($product['quantity'], 2), 'old quantity should equal product quantity');
<?php require_once "functions.php"; include "config.php"; $Header("Writing User Meta"); $data = array('action' => 'woocommerce_json_api', 'proc' => 'set_user_meta', 'arguments' => array('token' => $token), 'payload' => array(array('key' => 'just_a_test', 'value' => array('Hello World', 2, 3)))); $result = curl_post($url, $data); $result = json_decode($result, true); equal($result['status'], true, 'Call succeeded?'); $Header("Getting User Meta"); $data2 = array('action' => 'woocommerce_json_api', 'proc' => 'get_user_meta', 'arguments' => array('token' => $token), 'payload' => array(array('key' => 'just_a_test', 'value' => null))); $result = curl_post($url, $data2); $result = json_decode($result, true); equal($result['status'], true, 'Call succeeded?'); equal($result['payload'][0]['value'][0], 'Hello World', "Did we get the value back out?");
// STEP 1: Get available categories. $data = array('action' => 'woocommerce_json_api', 'proc' => 'get_categories', 'arguments' => array('token' => $token)); $json = curl_post($url, $data); $result = json_decode($json, true); $categories = $result['payload']; // STEP 2: Get a product $data = array('action' => 'woocommerce_json_api', 'proc' => 'get_products', 'arguments' => array('token' => $token, 'per_page' => 2, 'page' => 1, 'order_by' => 'ID', 'order' => 'desc', 'include' => array('variations' => false, 'images' => false, 'featured_image' => false, 'reviews' => false))); $json = curl_post($url, $data); $result = json_decode($json, true); $products = $result['payload']; // STEP 3: Assign a category to the product you want $category_count = count($products[0]['categories']); $products[0]['categories'][] = $categories[0]; // STEP 4: Send it back to the server: $result['payload'] = array($products[0]); $result['proc'] = 'set_products'; $json = curl_post($url, $result); $result = json_decode($json, true); $products = $result['payload']; hasAtLeast($products[0]['categories'], $category_count + 1, "Was the category connected?"); /////////////////////////////////////////////////////// // Disconnecting a Category from a Product // ////////////////////////////////////////////////////// $products[0]['categories'][0]['__disconnect__'] = true; $result['payload'] = array($products[0]); $result['proc'] = 'set_products'; $json = curl_post($url, $result); $result = json_decode($json, true); $products = $result['payload']; equal(true, $products[0]['categories'][0]['__disconnected__'], 'Was the category disconnected?');
public function testOrWhere() { $expr = orWhere(equal('foo', 1), equal('bar', 2)); $this->assertExpr('(`foo` = "1" OR `bar` = "2")', $expr); }