Skip to content

Commit

Permalink
Registry tests
Browse files Browse the repository at this point in the history
  • Loading branch information
swissspidy committed Feb 19, 2017
1 parent a911b97 commit eb767ef
Showing 1 changed file with 76 additions and 0 deletions.
76 changes: 76 additions & 0 deletions tests/phpunit/tests/Registry.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<?php

namespace Required\Digest\Tests;

use Required\Digest\Event\RegistryInterface;
use \WP_UnitTestCase;
use \Required\Digest\Event\Registry as EventRegistry;

class Registry extends WP_UnitTestCase {
/**
* @var RegistryInterface
*/
protected $registry;

public function setUp() {
$this->registry = new EventRegistry();
}

public function test_register_event() {
$this->registry->register_event( 'foo' );

$this->assertSame( array( 'foo' ), $this->registry->get_registered_events() );
}

public function test_register_event_twice() {
$this->registry->register_event( 'foo' );
$this->registry->register_event( 'foo' );

$this->assertSame( array( 'foo' ), $this->registry->get_registered_events() );
}

public function test_register_event_adds_filter_with_callback() {
$this->registry->register_event( 'foo', 'bar' );

$this->assertSame( 10, has_filter( 'digest_message_section_foo', 'bar' ) );
}

public function test_is_registered_event() {
$before = $this->registry->is_registered_event( 'foo' );
$this->registry->register_event( 'foo' );
$after = $this->registry->is_registered_event( 'foo' );

$this->assertFalse( $before );
$this->assertTrue( $after );
}

public function get_registered_events_empty() {
$this->assertEmpty( $this->registry->get_registered_events() );
}

public function test_register_default_events( ) {
$this->registry->register_default_events();

$this->assertEqualSets( array(
'comment_moderation',
'comment_notification',
'core_update_failure',
'core_update_success',
'new_user_notification',
'password_change_notification'
), $this->registry->get_registered_events() );
}

public function test_register_default_events_without_pluggable( ) {
update_option( 'digest_hooks', array(), false );

$this->registry->register_default_events();

$this->assertEqualSets( array(
'comment_moderation',
'comment_notification',
'core_update_failure',
'core_update_success',
), $this->registry->get_registered_events() );
}
}

0 comments on commit eb767ef

Please sign in to comment.