Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pfefferle committed Feb 23, 2025
1 parent b075cf3 commit 30f97a0
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
13 changes: 13 additions & 0 deletions includes/class-webmention.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@ class Webmention {
*/
private $default_post_types = array( 'post', 'page' );

/**
* Whether the class has been initialized.
*
* @var boolean
*/
private $initialized = false;

/**
* Get the instance of the class.
*
Expand All @@ -58,6 +65,10 @@ private function __construct() {
* Initialize the plugin.
*/
public function init() {
if ( $this->initialized ) {
return;
}

$this->register_constants();

$this->register_hooks();
Expand All @@ -67,6 +78,8 @@ public function init() {

// Load language files.
load_plugin_textdomain( self::TEXT_DOMAIN, false, dirname( plugin_basename( __FILE__ ) ) . '/languages' );

$this->initialized = true;
}

/**
Expand Down
17 changes: 17 additions & 0 deletions tests/test-webmention.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,21 @@
<?php
class Webmention_Test extends WP_UnitTestCase {
public function test_register_constants() {
\Webmention\Webmention::get_instance()->init();

$this->assertEquals( WEBMENTION_ALWAYS_SHOW_HEADERS, 0 );
$this->assertEquals( WEBMENTION_COMMENT_APPROVE, 0 );
$this->assertEquals( WEBMENTION_COMMENT_TYPE, 'webmention' );
$this->assertEquals( WEBMENTION_GRAVATAR_CACHE_TIME, WEEK_IN_SECONDS );
}

public function test_register_hooks() {
\Webmention\Webmention::get_instance()->init();

// test if some hooks are registered
$this->assertEquals( has_action( 'init', array( \Webmention\Comment::class, 'init' ) ), 10 );
$this->assertEquals( has_action( 'admin_menu', array( \Webmention\Admin::class, 'admin_menu' ) ), 10 );
$this->assertEquals( has_action( 'admin_init', array( \Webmention\Admin::class, 'admin_init' ) ), 10 );
}

}

0 comments on commit 30f97a0

Please sign in to comment.