Setup code quality and tests
This commit is contained in:
26
tests/Gateway_Functions_Test.php
Normal file
26
tests/Gateway_Functions_Test.php
Normal file
@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace WP_Ultimo\Tests;
|
||||
|
||||
use WP_Ultimo\Gateways\Manual_Gateway;
|
||||
use WP_Ultimo\Managers\Gateway_Manager;
|
||||
|
||||
class Gateway_Functions_Test extends \WP_UnitTestCase {
|
||||
|
||||
public function test_wu_get_gateway_returns_false_for_invalid_id() {
|
||||
$invalid_gateway_id = 'non_existent_gateway';
|
||||
|
||||
$result = wu_get_gateway($invalid_gateway_id);
|
||||
|
||||
$this->assertFalse($result);
|
||||
}
|
||||
|
||||
public function test_wu_get_gateway_returns_instance_for_valid_id() {
|
||||
$valid_gateway_id = 'manual';
|
||||
|
||||
$gateway = wu_get_gateway($valid_gateway_id);
|
||||
|
||||
$this->assertInstanceOf(Manual_Gateway::class, $gateway);
|
||||
}
|
||||
|
||||
}
|
36
tests/WP_Ultimo_Test.php
Normal file
36
tests/WP_Ultimo_Test.php
Normal file
@ -0,0 +1,36 @@
|
||||
<?php
|
||||
namespace WP_Ultimo;
|
||||
|
||||
class WP_Ultimo_Test extends \WP_UnitTestCase {
|
||||
/**
|
||||
* Test if all helper functions are loaded correctly.
|
||||
*
|
||||
* This test case creates an instance of the WP_Ultimo class and calls the load_public_apis method.
|
||||
* It then asserts that the helper functions wu_to_float, wu_replace_dashes, and wu_get_initials are
|
||||
* correctly loaded. Additional assertions can be added for other helper functions.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testLoadAllHelperFunctionsCorrectly() {
|
||||
// Assert that all helper functions are loaded correctly.
|
||||
// This is all done in the bootstrap.
|
||||
$this->assertTrue(function_exists('wu_to_float'));
|
||||
$this->assertTrue(function_exists('wu_replace_dashes'));
|
||||
$this->assertTrue(function_exists('wu_get_initials'));
|
||||
}
|
||||
|
||||
public function testLoaded() {
|
||||
$wpUltimo = \WP_Ultimo();
|
||||
$this->assertTrue($wpUltimo->version === \WP_Ultimo::VERSION);
|
||||
$this->assertTrue($wpUltimo->is_loaded());
|
||||
}
|
||||
|
||||
public function testPublicProperties() {
|
||||
$wpUltimo = \WP_Ultimo();
|
||||
$this->assertTrue($wpUltimo->settings instanceof Settings);
|
||||
$this->assertTrue($wpUltimo->helper instanceof Helper);
|
||||
$this->assertTrue($wpUltimo->notices instanceof Admin_Notices);
|
||||
$this->assertTrue($wpUltimo->scripts instanceof Scripts);
|
||||
$this->assertTrue($wpUltimo->currents instanceof Current);
|
||||
}
|
||||
}
|
38
tests/bootstrap.php
Normal file
38
tests/bootstrap.php
Normal file
@ -0,0 +1,38 @@
|
||||
<?php
|
||||
/**
|
||||
* PHPUnit bootstrap file.
|
||||
*
|
||||
* @package Wp_Multisite_Waas
|
||||
*/
|
||||
|
||||
$_tests_dir = getenv( 'WP_TESTS_DIR' );
|
||||
require 'vendor/yoast/phpunit-polyfills/phpunitpolyfills-autoload.php';
|
||||
if ( ! $_tests_dir ) {
|
||||
$_tests_dir = rtrim( sys_get_temp_dir(), '/\\' ) . '/wordpress-tests-lib';
|
||||
}
|
||||
|
||||
// Forward custom PHPUnit Polyfills configuration to PHPUnit bootstrap file.
|
||||
$_phpunit_polyfills_path = getenv( 'WP_TESTS_PHPUNIT_POLYFILLS_PATH' );
|
||||
if ( false !== $_phpunit_polyfills_path ) {
|
||||
define( 'WP_TESTS_PHPUNIT_POLYFILLS_PATH', $_phpunit_polyfills_path );
|
||||
}
|
||||
|
||||
if ( ! file_exists( "{$_tests_dir}/includes/functions.php" ) ) {
|
||||
echo "Could not find {$_tests_dir}/includes/functions.php, have you run bin/install-wp-tests.sh ?" . PHP_EOL; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||
exit( 1 );
|
||||
}
|
||||
|
||||
// Give access to tests_add_filter() function.
|
||||
require_once "{$_tests_dir}/includes/functions.php";
|
||||
|
||||
/**
|
||||
* Manually load the plugin being tested.
|
||||
*/
|
||||
function _manually_load_plugin() {
|
||||
require dirname( dirname( __FILE__ ) ) . '/wp-multisite-waas.php';
|
||||
}
|
||||
|
||||
tests_add_filter( 'muplugins_loaded', '_manually_load_plugin' );
|
||||
|
||||
// Start up the WP testing environment.
|
||||
require "{$_tests_dir}/includes/bootstrap.php";
|
Reference in New Issue
Block a user