Skip to content

Instantly share code, notes, and snippets.

@hellofromtonya
Created February 3, 2018 23:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hellofromtonya/945ad401cd073d943ad2bf509fd82aab to your computer and use it in GitHub Desktop.
Save hellofromtonya/945ad401cd073d943ad2bf509fd82aab to your computer and use it in GitHub Desktop.
Tests for beans_replace_action_hook
<?php
// code left out for brevity
/**
* Test beans_replace_action_hook() should replace the registered action's hook.
*/
public function test_should_replace_the_action_hook() {
// Set up what will get stored in Beans.
$replaced_action = array(
'hook' => 'beans_foo',
);
$this->go_to_post();
foreach ( static::$test_actions as $beans_id => $action_config ) {
$original_action = _beans_get_action( $beans_id, 'added' );
// Make sure the callback is what we think before we get rolling.
$this->assertEquals( $action_config['hook'], $original_action['hook'] );
// Test that the original action is registered in WordPress.
$this->assertTrue( has_action( $original_action['hook'], $original_action['callback'], $original_action['priority'] ) !== false );
// Run the replace.
$this->assertTrue( beans_replace_action_hook( $beans_id, $replaced_action['hook'] ) );
// Check that the original action's hook is no longer registered in WordPress.
$this->assertFalse( has_action( $original_action['hook'], $original_action['callback'], $original_action['priority'] ) );
// Check if it replaced only the hook.
$new_action = _beans_get_action( $beans_id, 'added' );
$this->assertEquals( $replaced_action['hook'], $new_action['hook'] );
$this->assertEquals( $original_action['callback'], $new_action['callback'] );
$this->assertEquals( $original_action['priority'], $new_action['priority'] );
$this->assertEquals( $original_action['args'], $new_action['args'] );
// Check that the "replaced" action has been stored in Beans and WordPress.
$this->check_stored_in_beans( $beans_id, $replaced_action );
$this->check_registered_in_wp( $new_action['hook'], $new_action );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment