Skip to content

Commit

Permalink
Adds tests for the main plugin class
Browse files Browse the repository at this point in the history
  • Loading branch information
mattyza committed Dec 25, 2023
1 parent a12ccdd commit 08469e8
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 21 deletions.
2 changes: 1 addition & 1 deletion phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
</php>
<testsuites>
<testsuite name="default">
<directory prefix="test_" suffix=".php">tests/</directory>
<directory prefix="test-" suffix=".php">tests/</directory>
</testsuite>
</testsuites>
</phpunit>
55 changes: 55 additions & 0 deletions tests/test-starter-plugin.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php
/**
* Class Test_Starter_Plugin
*
* @package Starter_Plugin
*/

/**
* Sample test case.
*/
class Test_Starter_Plugin extends WP_UnitTestCase {
public function set_up() {
parent::set_up();

// Mock that we're in WP Admin context.
// See https://wordpress.stackexchange.com/questions/207358/unit-testing-in-the-wordpress-backend-is-admin-is-true
set_current_screen( 'edit-post' );

$this->starter_plugin = new Starter_Plugin();
}

public function tear_down() {
parent::tear_down();
}

public function test_has_correct_token() {
$has_correct_token = ( 'starter-plugin' === $this->starter_plugin->token );

$this->assertTrue( $has_correct_token );
}

public function test_has_admin_interface() {
$has_admin_interface = ( is_a( $this->starter_plugin->admin, 'Starter_Plugin_Admin' ) );

$this->assertTrue( $has_admin_interface );
}

public function test_has_settings_interface() {
$has_settings_interface = ( is_a( $this->starter_plugin->settings, 'Starter_Plugin_Settings' ) );

$this->assertTrue( $has_settings_interface );
}

public function test_has_post_types() {
$has_post_types = ( 0 < count( $this->starter_plugin->post_types ) );

$this->assertTrue( $has_post_types );
}

public function test_has_load_plugin_textdomain() {
$has_load_plugin_textdomain = ( is_int( has_action( 'init', [ $this->starter_plugin, 'load_plugin_textdomain' ] ) ) );

$this->assertTrue( $has_load_plugin_textdomain );
}
}
20 changes: 0 additions & 20 deletions tests/test_starter_plugin.php

This file was deleted.

0 comments on commit 08469e8

Please sign in to comment.