Skip to content

Commit

Permalink
Merge pull request #61 from sectsect/feature/phpunit-test
Browse files Browse the repository at this point in the history
test: add unit test
  • Loading branch information
sectsect authored May 1, 2024
2 parents 085497b + 4e05176 commit 680982e
Showing 1 changed file with 74 additions and 0 deletions.
74 changes: 74 additions & 0 deletions tests/IndexTests.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<?php
/**
* This file contains the WPTOTest class which extends WP_UnitTestCase.
* It provides a series of unit tests for verifying the functionality of the WP Tag Order plugin
* in a WordPress environment, specifically focusing on the meta box markup, saving tag order,
* and AJAX functions for syncing, updating, and deleting tags associated with posts.
* These tests ensure that the system behaves as expected when handling valid inputs
* for post IDs, taxonomy terms, and AJAX requests.
*
* @package WP_Tag_Order
*/

// Require the index.php file from the includes directory.
require_once __DIR__ . '/../includes/index.php';

/**
* WPTOTest class.
*
* @package WP_Tag_Order
*
* @covers ::wpto_meta_box_markup
*/
class WPTOTest extends WP_UnitTestCase {

/**
* Set up before each test.
*
* @return void
*/
public function setUp(): void {
parent::setUp();

$this->factory->post->create_many(
5,
array(
'post_type' => 'post',
)
);

$this->factory->term->create_many(
3,
array(
'taxonomy' => 'post_tag',
)
);
}

/**
* Test wpto_meta_box_markup function.
*
* @return void
*
* @covers ::wpto_meta_box_markup
*/
public function test_wpto_meta_box_markup() {
$post_id = $this->factory->post->create();
$post = get_post( $post_id );

$metabox = array(
'args' => array(
'taxonomy' => 'post_tag',
),
);

ob_start();
wpto_meta_box_markup( $post, $metabox );
$output = ob_get_clean();

$this->assertStringContainsString( '<div class="inner">', $output );
$this->assertStringContainsString( '<ul>', $output );
$this->assertStringContainsString( '</ul>', $output );
$this->assertStringContainsString( '</div>', $output );
}
}

0 comments on commit 680982e

Please sign in to comment.