Delivery setup
This commit is contained in:
141
backend/app/plugins/wiaas/tests/bin/setup.sh
Executable file
141
backend/app/plugins/wiaas/tests/bin/setup.sh
Executable file
@@ -0,0 +1,141 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
if [ $# -lt 2 ]; then
|
||||
echo "usage: $0 <db-user> <db-pass>"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
DB_USER=$1
|
||||
DB_PASS=$2
|
||||
WP_TESTS_TAG="tags/4.9.7"
|
||||
|
||||
# Get temp directory
|
||||
TMPDIR=${TMPDIR-/tmp}
|
||||
TMPDIR=$(echo $TMPDIR | sed -e "s/\/$//")
|
||||
|
||||
# Evaluate current directory
|
||||
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||
|
||||
# Evaluate application root directory
|
||||
WEB_ROOT_DIR="$( dirname "$( dirname "$( dirname "$( dirname "$( dirname "$DIR" )" )" )" )" )"
|
||||
WP_CORE_DIR="$WEB_ROOT_DIR"/wp
|
||||
|
||||
# Location where wordpress testing suite will be installed
|
||||
WP_TESTS_DIR=${WP_TESTS_DIR-$TMPDIR/wordpress-tests-lib}
|
||||
WP_TEST_APPLICATION_DIR=${WP_TEST_APPLICATION_DIR-$TMPDIR/wiaas-backend-test}
|
||||
|
||||
download() {
|
||||
if [ `which curl` ]; then
|
||||
curl -s "$1" > "$2";
|
||||
elif [ `which wget` ]; then
|
||||
wget -nv -O "$2" "$1"
|
||||
fi
|
||||
}
|
||||
|
||||
set -ex
|
||||
|
||||
# Since test enviroment needs to start with fresh setup
|
||||
# we will install application in /tmp/ folder and execute all migrations
|
||||
setup_test_application() {
|
||||
rm -rf "$WP_TEST_APPLICATION_DIR"
|
||||
|
||||
mkdir "$WP_TEST_APPLICATION_DIR"
|
||||
|
||||
mkdir "$WP_TEST_APPLICATION_DIR"/app
|
||||
|
||||
cp -r "$WEB_ROOT_DIR/app/mu-plugins" "$WP_TEST_APPLICATION_DIR/app/mu-plugins"
|
||||
|
||||
mkdir "$WP_TEST_APPLICATION_DIR"/app/plugins
|
||||
cp -r "$WEB_ROOT_DIR"/app/plugins/wiaas "$WP_TEST_APPLICATION_DIR"/app/plugins/wiaas
|
||||
|
||||
cp -r "$WEB_ROOT_DIR"/app/plugins/gravityflow "$WP_TEST_APPLICATION_DIR"/app/plugins/gravityflow
|
||||
cp -r "$WEB_ROOT_DIR"/app/plugins/gravityforms "$WP_TEST_APPLICATION_DIR"/app/plugins/gravityforms
|
||||
|
||||
mkdir "$WP_TEST_APPLICATION_DIR"/app/themes
|
||||
|
||||
mkdir "$WP_TEST_APPLICATION_DIR"/app/uploads
|
||||
|
||||
cp -r "$WEB_ROOT_DIR"/config "$WP_TEST_APPLICATION_DIR"/config
|
||||
sed -i "s|define('WP_ENV', env('WP_ENV') ?: 'development');|define('WP_ENV', 'test');|" "$WP_TEST_APPLICATION_DIR"/config/application.php
|
||||
|
||||
cp "$WEB_ROOT_DIR/composer.json" "$WP_TEST_APPLICATION_DIR/composer.json"
|
||||
cp "$WEB_ROOT_DIR/composer.lock" "$WP_TEST_APPLICATION_DIR/composer.lock"
|
||||
cp "$WEB_ROOT_DIR/index.php" "$WP_TEST_APPLICATION_DIR/index.php"
|
||||
cp "$WEB_ROOT_DIR/wp-config.php" "$WP_TEST_APPLICATION_DIR/wp-config.php"
|
||||
cp "$WEB_ROOT_DIR/wp-cli.yml" "$WP_TEST_APPLICATION_DIR/wp-cli.yml"
|
||||
|
||||
{
|
||||
echo "MYSQL_DATABASE=wordpress_test"
|
||||
echo "MYSQL_USER=wp_admin_test"
|
||||
echo "MYSQL_PASSWORD=wp_admin_test_password"
|
||||
echo "WP_AUTH_KEY=test"
|
||||
echo "WP_SECURE_AUTH_KEY=test"
|
||||
echo "WP_LOGGED_IN_KEY=test"
|
||||
echo "WP_NONCE_KEY=test"
|
||||
echo "WP_AUTH_SALT=test"
|
||||
echo "WP_SECURE_AUTH_SALT=test"
|
||||
echo "WP_LOGGED_IN_SALT=test"
|
||||
echo "WP_NONCE_SALT=test"
|
||||
echo "WP_JWT_AUTH_SECRET_KEY=test"
|
||||
} >> "$WP_TEST_APPLICATION_DIR/.env"
|
||||
|
||||
}
|
||||
|
||||
|
||||
install_test_suite() {
|
||||
# set up testing suite if it doesn't yet exist
|
||||
if [ ! -d $WP_TESTS_DIR ]; then
|
||||
# set up testing suite
|
||||
mkdir -p $WP_TESTS_DIR
|
||||
svn co --quiet https://develop.svn.wordpress.org/${WP_TESTS_TAG}/tests/phpunit/includes/ $WP_TESTS_DIR/includes
|
||||
svn co --quiet https://develop.svn.wordpress.org/${WP_TESTS_TAG}/tests/phpunit/data/ $WP_TESTS_DIR/data
|
||||
fi
|
||||
# set up testing environment wp-config entry point file if it does not exist
|
||||
if [ ! -f "$WP_TESTS_DIR"/wp-tests-config.php ]; then
|
||||
# init testing suite entry point settings file
|
||||
{
|
||||
echo "<?php"
|
||||
echo ""
|
||||
echo "require_once('$WP_TEST_APPLICATION_DIR/vendor/autoload.php');"
|
||||
echo "require_once('$WP_TEST_APPLICATION_DIR/config/application.php');"
|
||||
echo "require_once(ABSPATH . 'wp-settings.php');"
|
||||
echo ""
|
||||
echo "define( 'WP_TESTS_DOMAIN', 'example.org' );"
|
||||
echo "define( 'WP_TESTS_EMAIL', 'admin@example.org' );"
|
||||
echo "define( 'WP_TESTS_TITLE', 'Test Blog' );"
|
||||
echo ""
|
||||
echo "define( 'WP_PHP_BINARY', 'php' );"
|
||||
echo ""
|
||||
echo "define( 'WPLANG', '' );"
|
||||
} >> "$WP_TESTS_DIR"/wp-tests-config.php
|
||||
|
||||
fi
|
||||
}
|
||||
|
||||
setup_test_db() {
|
||||
# create db user if not exists
|
||||
mysql -u "$DB_USER" -p"$DB_PASS" --execute="CREATE USER IF NOT EXISTS wp_admin_test@localhost IDENTIFIED BY 'wp_admin_test_password';"
|
||||
# delete database if it exists
|
||||
mysql -u "$DB_USER" -p"$DB_PASS" --execute="DROP DATABASE IF EXISTS wordpress_test;"
|
||||
# create database
|
||||
mysql -u "$DB_USER" -p"$DB_PASS" --execute="CREATE DATABASE wordpress_test;GRANT ALL PRIVILEGES ON wordpress_test.* TO wp_admin_test@localhost;"
|
||||
# seed database
|
||||
mysql -u "$DB_USER" -p"$DB_PASS" wordpress_test < "$WEB_ROOT_DIR/../database/clean-dump.sql"
|
||||
}
|
||||
|
||||
migrate_test_db() {
|
||||
cd "$WP_TEST_APPLICATION_DIR"
|
||||
|
||||
composer install
|
||||
|
||||
# Run this so ony pending database schema can be loaded
|
||||
composer update-db
|
||||
}
|
||||
|
||||
setup_test_application
|
||||
|
||||
install_test_suite
|
||||
|
||||
setup_test_db
|
||||
|
||||
migrate_test_db
|
||||
43
backend/app/plugins/wiaas/tests/bootstrap.php
Normal file
43
backend/app/plugins/wiaas/tests/bootstrap.php
Normal file
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
/**
|
||||
* PHPUnit bootstrap file for Wiaas plugin
|
||||
*
|
||||
* @package Wiaas
|
||||
*/
|
||||
|
||||
|
||||
# Folder where wordpress testing library is installed
|
||||
$_tests_dir = '/tmp/wordpress-tests-lib';
|
||||
|
||||
if ( ! file_exists( $_tests_dir . '/includes/functions.php' ) ) {
|
||||
echo "Could not find $_tests_dir/includes/functions.php, have you run bin/setup.sh ?" . PHP_EOL;
|
||||
exit( 1 );
|
||||
}
|
||||
|
||||
# Give access to tests_add_filter() function.
|
||||
require_once $_tests_dir . '/includes/functions.php';
|
||||
|
||||
#load setup
|
||||
tests_add_filter( 'muplugins_loaded', 'load_wiaas_test_setup' );
|
||||
|
||||
# Start up the WP testing environment.
|
||||
require $_tests_dir . '/includes/bootstrap.php';
|
||||
|
||||
# Require Wiaas Unit Test case class
|
||||
require_once '/tmp/wiaas-backend-test/app/plugins/wiaas/tests/wiaas-unit-test-case.php';
|
||||
|
||||
function load_wiaas_test_setup() {
|
||||
|
||||
# Activate plugins needed for testing
|
||||
require_once '/tmp/wiaas-backend-test/app/plugins/woocommerce/woocommerce.php';
|
||||
|
||||
require_once '/tmp/wiaas-backend-test/app/plugins/gravityforms/gravityforms.php';
|
||||
|
||||
require_once '/tmp/wiaas-backend-test/app/plugins/gravityflow/gravityflow.php';
|
||||
|
||||
require_once '/tmp/wiaas-backend-test/app/plugins/wiaas/wiaas.php';
|
||||
|
||||
# Require classes needed for db updates
|
||||
require_once '/tmp/wiaas-backend-test/app/plugins/wiaas/includes/class-wiaas-db-update.php';
|
||||
require_once '/tmp/wiaas-backend-test/app/plugins/wiaas/includes/db-updates/wiaas-db-update-functions.php';
|
||||
}
|
||||
@@ -0,0 +1,170 @@
|
||||
<?php
|
||||
/**
|
||||
* Wiaas_Delivery_Process_Step_Test
|
||||
*
|
||||
* @package Wiaas
|
||||
*/
|
||||
|
||||
class Wiaas_Delivery_Process_Step_Test extends Wiaas_Unit_Test_Case {
|
||||
|
||||
var $step, $form_id, $target_form_id;
|
||||
|
||||
function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$this->form_id = GFAPI::add_form(array(
|
||||
'title' => 'Delivery Process Step Test Form',
|
||||
));
|
||||
$form_entry_id = GFAPI::add_entry(array(
|
||||
'form_id' => $this->form_id,
|
||||
));
|
||||
|
||||
$this->target_form_id = GFFormsModel::search_forms(
|
||||
'DELIVERY ACTION TYPE: Manual',
|
||||
true)[0]->id;
|
||||
|
||||
|
||||
$this->step = Gravity_Flow_Steps::create( array(
|
||||
'form_id'=> $this->form_id,
|
||||
'is_active'=> '1',
|
||||
'meta' => array(
|
||||
'step_name' => 'Test Wiaas Delivery Process Step',
|
||||
'description' => 'Test Wiaas Delivery Process Step',
|
||||
'step_type' => 'wiaas_delivery_step',
|
||||
'target_form_id' => $this->target_form_id
|
||||
)
|
||||
), GFAPI::get_entry($form_entry_id));
|
||||
}
|
||||
|
||||
private function _get_target_entry_meta_key() {
|
||||
return 'wiaas_delivery_step_' . $this->step->get_id() .'_entry_id';
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Wiaas_Delivery_Process_Step::get_settings
|
||||
*/
|
||||
function test_settings_options_are_valid() {
|
||||
|
||||
$this->assertEquals(get_class($this->step), 'Wiaas_Delivery_Process_Step');
|
||||
|
||||
$this->assertEquals($this->step->is_active(), true);
|
||||
|
||||
$this->assertEquals($this->step->get_name(), 'Test Wiaas Delivery Process Step');
|
||||
|
||||
$this->assertEquals($this->step->description, 'Test Wiaas Delivery Process Step');
|
||||
|
||||
$this->assertEquals($this->step->target_form_id, $this->target_form_id);
|
||||
|
||||
$this->assertEquals($this->step->get_label(), 'Wiaas Delivery Step');
|
||||
|
||||
#$this->assertEquals($step->is_visible_to_customer, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Wiaas_Delivery_Process_Step::get_target_forms_choices
|
||||
*/
|
||||
function test_target_forms_choices_are_valid() {
|
||||
|
||||
$target_forms_choices = $this->step->get_target_forms_choices();
|
||||
|
||||
$available_action_types = Wiaas_Delivery_Process_Step::get_delivery_action_types();
|
||||
|
||||
$this->assertEquals(sizeof($target_forms_choices), sizeof($available_action_types));
|
||||
|
||||
foreach ($target_forms_choices as $target_forms_choice) {
|
||||
$this->assertTrue(in_array($target_forms_choice->title, $available_action_types));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Wiaas_Delivery_Process_Step::get_entry_meta
|
||||
*/
|
||||
function test_entry_meta_skipped_for_non_parent_form() {
|
||||
$meta = array(
|
||||
'test' => 'test'
|
||||
);
|
||||
|
||||
# Since this is not parent form id function should return unchanged meta
|
||||
$this->assertEquals($meta, $this->step->get_entry_meta($meta, 55));
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Wiaas_Delivery_Process_Step::get_entry_meta
|
||||
*/
|
||||
function test_entry_meta_added_for_parent_form() {
|
||||
$meta = array(
|
||||
'test' => 'test'
|
||||
);
|
||||
$expected_meta = array(
|
||||
'test' => 'test',
|
||||
'wiaas_delivery_step_' . $this->step->get_id() .'_entry_id' => null
|
||||
);
|
||||
|
||||
$this->assertEquals($expected_meta, $this->step->get_entry_meta($meta, $this->step->get_form_id()));
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Wiaas_Delivery_Process_Step::process
|
||||
*/
|
||||
function test_process_with_no_target_form() {
|
||||
$this->step->target_form_id = '';
|
||||
|
||||
$this->assertTrue($this->step->process());
|
||||
|
||||
# check that entry metadata is not updated
|
||||
$target_entry_meta_key = $this->_get_target_entry_meta_key();
|
||||
$value = gform_get_meta($this->step->get_entry_id(), $target_entry_meta_key);
|
||||
$this->assertFalse($value);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Wiaas_Delivery_Process_Step::process
|
||||
*/
|
||||
function test_process_with_target_form() {
|
||||
# check that processing step returns false since it will wait for target form entry workflow to complete
|
||||
$this->assertFalse($this->step->process());
|
||||
|
||||
# check that entry metadata is updated with correct target entry value
|
||||
$target_entry_meta_key = $this->_get_target_entry_meta_key();
|
||||
$value = gform_get_meta($this->step->get_entry_id(), $target_entry_meta_key);
|
||||
$target_entry_id = absint($value);
|
||||
$this->assertGreaterThan(0, $target_entry_id);
|
||||
|
||||
# check that entry metadata key for target entry id points to valid entry
|
||||
$entry = GFAPI::get_entry($target_entry_id);
|
||||
$this->assertFalse(is_wp_error($entry));
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Wiaas_Delivery_Process_Step::status_evaluation
|
||||
*/
|
||||
function test_status_evaluation_with_no_target_form() {
|
||||
$this->step->target_form_id = '';
|
||||
|
||||
$this->step->process();
|
||||
|
||||
$this->assertEquals($this->step->status_evaluation(), 'complete');
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Wiaas_Delivery_Process_Step::status_evaluation
|
||||
*/
|
||||
function test_status_evaluation_with_target_form() {
|
||||
$this->step->process();
|
||||
|
||||
# check that step status is now pending
|
||||
$this->assertEquals($this->step->status_evaluation(), 'pending');
|
||||
|
||||
# complete target entry workflow
|
||||
$api = new Gravity_Flow_API( $this->step->target_form_id );
|
||||
$target_form_entry = $this->step->get_target_form_entry();
|
||||
$this->assertEquals($api->get_status($target_form_entry), 'pending');
|
||||
|
||||
gform_update_meta($target_form_entry['id'], 'workflow_role_administrator', 'approved');
|
||||
$target_entry_current_step = $api->get_current_step($target_form_entry);
|
||||
$target_entry_current_step->refresh_entry();
|
||||
|
||||
# check that step status is now complete
|
||||
$this->assertEquals($this->step->status_evaluation(), 'complete');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,156 @@
|
||||
<?php
|
||||
/**
|
||||
* Wiaas_Delivery_Process_Test
|
||||
*
|
||||
* @package Wiaas
|
||||
*/
|
||||
|
||||
class Wiaas_Delivery_Process_Test extends Wiaas_Unit_Test_Case {
|
||||
|
||||
var $process_form, $step_form, $process_form_instance, $process_step, $process_form_workflow_api;
|
||||
|
||||
function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$this->process_form = GFFormsModel::search_forms(
|
||||
'DELIVERY PROCESS: Normal Delivery',
|
||||
true)[0];
|
||||
|
||||
$this->step_form = GFFormsModel::search_forms(
|
||||
'DELIVERY ACTION TYPE: Manual',
|
||||
true)[0];
|
||||
|
||||
$process_form_instance_id = GFAPI::add_entry(array(
|
||||
'form_id' => $this->process_form->id,
|
||||
));
|
||||
|
||||
$this->process_form_instance = GFAPI::get_entry($process_form_instance_id);
|
||||
|
||||
$this->process_form_workflow_api = new Gravity_Flow_API( $this->process_form->id );
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Wiaas_Delivery_Process::create_delivery_process_for_order
|
||||
*/
|
||||
function test_delivery_process_for_order_created() {
|
||||
$order = wc_create_order();
|
||||
$order_id = $order->get_id();
|
||||
|
||||
Wiaas_Delivery_Process::create_delivery_process_for_order($order_id);
|
||||
|
||||
$order_process_id = absint(get_post_meta($order_id, 'wiaas_delivery_process_id'));
|
||||
$order_process_instance_id = absint(get_post_meta($order_id, 'wiaas_delivery_process_entry_id'));
|
||||
|
||||
# check field populated
|
||||
$this->assertGreaterThan(0, $order_process_id);
|
||||
$this->assertGreaterThan(0, $order_process_instance_id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Wiaas_Delivery_Process::extend_gravity_form_entry_meta
|
||||
*/
|
||||
function test_gravity_form_entry_meta_extended() {
|
||||
# create test entry with additional metadata
|
||||
$entry = array(
|
||||
'form_id' => $this->step_form->id,
|
||||
'wiaas_delivery_process_id' => false,
|
||||
);
|
||||
|
||||
$result = GFAPI::add_entry($entry);
|
||||
|
||||
# test that entry was successfully created
|
||||
$this->assertFalse(is_wp_error($result));
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Wiaas_Delivery_Process::maybe_complete_parent_process_step
|
||||
*/
|
||||
function test_do_nothing_if_completed_workflow_has_no_parent() {
|
||||
# Test there is no exception if entry has no parent process
|
||||
$entry_id = GFAPI::add_entry(array(
|
||||
'form_id' => $this->step_form->id
|
||||
));
|
||||
|
||||
$this->assertFalse(
|
||||
Wiaas_Delivery_Process::maybe_complete_parent_process_step(
|
||||
$entry_id,
|
||||
$this->step_form)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Wiaas_Delivery_Process::maybe_complete_parent_process_step
|
||||
*/
|
||||
function test_process_parent_process_step_on_workflow_completion() {
|
||||
# get process current step
|
||||
$process_form_instance = GFAPI::get_entry($this->process_form_instance['id']);
|
||||
|
||||
# retrieve process steps
|
||||
$process_steps = $this->process_form_workflow_api->get_steps($this->process_form);
|
||||
$first_process_step = $process_steps[0];
|
||||
$second_process_step = $process_steps[1];
|
||||
|
||||
# Check that current step is first step of corresponding process
|
||||
$process_instance_current_step = $this->process_form_workflow_api->get_current_step($process_form_instance);
|
||||
$this->assertEquals(
|
||||
$process_instance_current_step->get_id(),
|
||||
$first_process_step->get_id());
|
||||
|
||||
# Update step form entry to complete its workflow
|
||||
$step_form_entry = $process_instance_current_step->get_target_form_entry();
|
||||
gform_update_meta($step_form_entry['id'], 'workflow_role_administrator', 'approved');
|
||||
|
||||
# execute callback
|
||||
Wiaas_Delivery_Process::maybe_complete_parent_process_step($step_form_entry['id'], null);
|
||||
|
||||
# refresh process instance and check we moved to next step
|
||||
$process_form_instance = GFAPI::get_entry($this->process_form_instance['id']);
|
||||
$this->assertEquals(
|
||||
$this->process_form_workflow_api->get_current_step($process_form_instance)->get_id(),
|
||||
$second_process_step->get_id());
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @covers Wiaas_Delivery_Process::get_order_delivery_process()
|
||||
*/
|
||||
function test_get_order_delivery_process() {
|
||||
|
||||
$order = wc_create_order();
|
||||
$order_id = $order->get_id();
|
||||
|
||||
$delivery_process = Wiaas_Delivery_Process::get_order_delivery_process($order_id);
|
||||
|
||||
$this->assertNotNull($delivery_process);
|
||||
|
||||
$steps = $delivery_process['steps'];
|
||||
|
||||
$this->assertNotNull($steps);
|
||||
$this->assertTrue(is_array($steps));
|
||||
|
||||
foreach ($steps as $step) {
|
||||
|
||||
# test returned step is array
|
||||
$this->assertTrue(is_array($step));
|
||||
|
||||
# test returned step properties
|
||||
$this->assertArrayHasKey('step_id', $step);
|
||||
$this->assertArrayHasKey('step_form_entry_id', $step);
|
||||
$this->assertArrayHasKey('short_desc', $step);
|
||||
$this->assertArrayHasKey('full_desc', $step);
|
||||
$this->assertArrayHasKey('action_code', $step);
|
||||
$this->assertArrayHasKey('step_type', $step);
|
||||
$this->assertArrayHasKey('status', $step);
|
||||
$this->assertArrayHasKey('order_id', $step);
|
||||
|
||||
$this->assertEquals($step['order_id'], $order_id);
|
||||
|
||||
# test that started steps have valid form entry
|
||||
if ($step['status'] !== 'inactive') {
|
||||
$process_instance = GFAPI::get_entry($step['step_form_entry_id']);
|
||||
$this->assertFalse(is_wp_error($process_instance));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
/**
|
||||
* Wiaas_Delivery_Process_Step_Test
|
||||
*
|
||||
* @package Wiaas
|
||||
*/
|
||||
|
||||
class Wiass_REST_Delivery_Process_Api_Test extends Wiaas_Unit_Test_Case {
|
||||
|
||||
var $order_id, $api;
|
||||
|
||||
function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$order = wc_create_order();
|
||||
|
||||
$this->order_id = $order->get_id();
|
||||
|
||||
wp_set_current_user(1);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Wiass_REST_Delivery_Process_API::get_next_actions_for_user
|
||||
*/
|
||||
function test_get_next_actions_for_user() {
|
||||
wp_set_current_user(1);
|
||||
|
||||
$response = Wiass_REST_Delivery_Process_API::get_next_actions_for_user();
|
||||
|
||||
$this->assertNotNull($response);
|
||||
$this->assertInstanceOf('WP_REST_Response', $response);
|
||||
|
||||
$next_steps = $response->get_data();
|
||||
|
||||
$this->assertNotNull($next_steps);
|
||||
$this->assertTrue(is_array($next_steps));
|
||||
|
||||
# check that administrator has one action pending
|
||||
$this->assertEquals(sizeof($next_steps), 1);
|
||||
|
||||
$pending_step = $next_steps[0];
|
||||
|
||||
$this->assertTrue(is_array($pending_step));
|
||||
|
||||
$this->assertArrayHasKey('idOrder', $pending_step);
|
||||
$this->assertArrayHasKey('orderNumber', $pending_step);
|
||||
$this->assertArrayHasKey('status', $pending_step);
|
||||
$this->assertArrayHasKey('stepAction', $pending_step);
|
||||
|
||||
$this->assertEquals($pending_step['idOrder'], $this->order_id);
|
||||
$this->assertEquals($pending_step['orderNumber'], $this->order_id);
|
||||
$this->assertEquals($pending_step['status'], 'pending');
|
||||
$this->assertNotEmpty($pending_step['stepAction']);
|
||||
}
|
||||
}
|
||||
17
backend/app/plugins/wiaas/tests/wiaas-unit-test-case.php
Normal file
17
backend/app/plugins/wiaas/tests/wiaas-unit-test-case.php
Normal file
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
class Wiaas_Unit_Test_Case extends WP_UnitTestCase {
|
||||
|
||||
/**
|
||||
* Executes any db migrations that are done to
|
||||
* `wp_options` table since it is deleted on every execution
|
||||
*/
|
||||
function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
# Setup Gravity info since options table is deleted after each test
|
||||
gf_upgrade()->install();
|
||||
|
||||
wiaas_db_update_setup_gravity();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user