Add PHPUnit testing framework and error checking documentation
This commit is contained in:
22
tests/phpunit/bootstrap.php
Normal file
22
tests/phpunit/bootstrap.php
Normal file
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
/**
|
||||
* PHPUnit bootstrap file.
|
||||
*
|
||||
* @package WP_Plugin_Starter_Template_For_AI_Coding
|
||||
*/
|
||||
|
||||
// Composer autoloader must be loaded before WP_PHPUNIT__DIR will be available.
|
||||
require_once dirname( dirname( __DIR__ ) ) . '/vendor/autoload.php';
|
||||
|
||||
// Give access to tests_add_filter() function.
|
||||
require_once getenv( 'WP_PHPUNIT__DIR' ) . '/includes/functions.php';
|
||||
|
||||
/**
|
||||
* Manually load the plugin being tested.
|
||||
*/
|
||||
function _manually_load_plugin() {
|
||||
require dirname( dirname( __DIR__ ) ) . '/plugin-toggle.php';
|
||||
}
|
||||
|
||||
// Start up the WP testing environment.
|
||||
require getenv( 'WP_PHPUNIT__DIR' ) . '/includes/bootstrap.php';
|
||||
56
tests/phpunit/test-multisite.php
Normal file
56
tests/phpunit/test-multisite.php
Normal file
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
/**
|
||||
* Class MultisiteTest
|
||||
*
|
||||
* @package WP_Plugin_Starter_Template_For_AI_Coding
|
||||
*/
|
||||
|
||||
/**
|
||||
* Sample test case for the Multisite class.
|
||||
*/
|
||||
class MultisiteTest extends WP_UnitTestCase {
|
||||
|
||||
/**
|
||||
* Test instance creation.
|
||||
*/
|
||||
public function test_instance() {
|
||||
$multisite = new WP_Plugin_Starter_Template_For_AI_Coding\Multisite\Multisite();
|
||||
$this->assertInstanceOf( 'WP_Plugin_Starter_Template_For_AI_Coding\Multisite\Multisite', $multisite );
|
||||
}
|
||||
|
||||
/**
|
||||
* Test is_multisite_compatible method.
|
||||
*/
|
||||
public function test_is_multisite_compatible() {
|
||||
$multisite = new WP_Plugin_Starter_Template_For_AI_Coding\Multisite\Multisite();
|
||||
$this->assertTrue( $multisite->is_multisite_compatible() );
|
||||
}
|
||||
|
||||
/**
|
||||
* Test get_network_sites method.
|
||||
*/
|
||||
public function test_get_network_sites() {
|
||||
$multisite = new WP_Plugin_Starter_Template_For_AI_Coding\Multisite\Multisite();
|
||||
|
||||
// Mock the get_sites function if we're not in a multisite environment.
|
||||
if ( ! function_exists( 'get_sites' ) ) {
|
||||
$this->assertEquals( array(), $multisite->get_network_sites() );
|
||||
} else {
|
||||
$sites = $multisite->get_network_sites();
|
||||
$this->assertIsArray( $sites );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test initialize_hooks method.
|
||||
*/
|
||||
public function test_initialize_hooks() {
|
||||
$multisite = new WP_Plugin_Starter_Template_For_AI_Coding\Multisite\Multisite();
|
||||
|
||||
// Call the method.
|
||||
$multisite->initialize_hooks();
|
||||
|
||||
// Check if the action was added.
|
||||
$this->assertEquals( 10, has_action( 'network_admin_menu', array( $multisite, 'add_network_menu' ) ) );
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user