$nprice = $old_price * 2; $oname = $product['name']; $nname = $oname . " I edited it"; $product['name'] = $nname; $product['price'] = $nprice; $products['proc'] = 'set_products'; $products['payload'][0] = $product; $result = curl_post($url, $products); //echo $result; // Now do the load a second time: $result = curl_post($url, $data); $products = json_decode($result, true); $product = $products['payload'][0]; notEqual($oname, $product['name'], 'old name does not equal new name'); equal($nname, $product['name'], 'new name is equal to product name'); notEqual(round($old_price, 2), round($product['price'], 2), "{$old_price} should not equal {$product['price']}"); equal(round($nprice, 2), round($product['price'], 2), 'new price should equal product price'); $product['name'] = $oname; $product['price'] = $old_price; $products['proc'] = 'set_products'; $products['payload'][0] = $product; $result = curl_post($url, $products); $products = json_decode($result, true); $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));
<?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("Reading Orders"); $data = array('action' => 'woocommerce_json_api', 'proc' => 'get_orders', 'arguments' => array('token' => $token)); $result = curl_post($url, $data); echo "Result is: " . $result; $orders = json_decode($result, true); $has_notes = false; $has_ois = false; $note_count = 0; foreach ($orders['payload'] as $order) { if (isset($order['notes']) && is_array($order['notes']) && count($order['notes']) > 0) { $note_count++; $has_notes = true; } if (isset($order['order_items']) && is_array($order['order_items']) && count($order['order_items']) > 0) { $has_ois = true; } } //equal($has_notes,true,'Has Notes?'); //equal($has_ois,true,'Has OrderItems'); foreach ($orders['payload'] as $order) { notEqual($order['status'], 'pending', "Order status `{$order['status']}` should not == pending"); }
// Now we want to edit the first variation $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"; $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']);
$orders['payload'] = array($order); $orders['proc'] = 'set_orders'; $result = curl_post($url, $orders); $result = curl_post($url, $data); $orders = json_decode($result, true); $note_count2 = 0; 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';
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');
public function testNotEqual() { $expr = notEqual('id', 1); $this->assertExpr('`id` <> "1"', $expr); }