Skip to content

Commit 30f97a0

Browse files
committed
Add tests
1 parent b075cf3 commit 30f97a0

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

includes/class-webmention.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,13 @@ class Webmention {
3434
*/
3535
private $default_post_types = array( 'post', 'page' );
3636

37+
/**
38+
* Whether the class has been initialized.
39+
*
40+
* @var boolean
41+
*/
42+
private $initialized = false;
43+
3744
/**
3845
* Get the instance of the class.
3946
*
@@ -58,6 +65,10 @@ private function __construct() {
5865
* Initialize the plugin.
5966
*/
6067
public function init() {
68+
if ( $this->initialized ) {
69+
return;
70+
}
71+
6172
$this->register_constants();
6273

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

6879
// Load language files.
6980
load_plugin_textdomain( self::TEXT_DOMAIN, false, dirname( plugin_basename( __FILE__ ) ) . '/languages' );
81+
82+
$this->initialized = true;
7083
}
7184

7285
/**

tests/test-webmention.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,21 @@
11
<?php
22
class Webmention_Test extends WP_UnitTestCase {
3+
public function test_register_constants() {
4+
\Webmention\Webmention::get_instance()->init();
5+
6+
$this->assertEquals( WEBMENTION_ALWAYS_SHOW_HEADERS, 0 );
7+
$this->assertEquals( WEBMENTION_COMMENT_APPROVE, 0 );
8+
$this->assertEquals( WEBMENTION_COMMENT_TYPE, 'webmention' );
9+
$this->assertEquals( WEBMENTION_GRAVATAR_CACHE_TIME, WEEK_IN_SECONDS );
10+
}
11+
12+
public function test_register_hooks() {
13+
\Webmention\Webmention::get_instance()->init();
14+
15+
// test if some hooks are registered
16+
$this->assertEquals( has_action( 'init', array( \Webmention\Comment::class, 'init' ) ), 10 );
17+
$this->assertEquals( has_action( 'admin_menu', array( \Webmention\Admin::class, 'admin_menu' ) ), 10 );
18+
$this->assertEquals( has_action( 'admin_init', array( \Webmention\Admin::class, 'admin_init' ) ), 10 );
19+
}
320

421
}

0 commit comments

Comments
 (0)