Commit f510dc14 authored by Erick Hitter's avatar Erick Hitter
Browse files

Add tests for admin callbacks

parent de2b2f76
Pipeline #842 passed with stages
in 10 minutes and 19 seconds
<?php
/**
* Class AdminCallbacks
*
* @package External_Permalinks_Redux
*/
/**
* Test admin callbacks
*/
class AdminCallbacks extends WP_UnitTestCase {
/**
* Redirect destination.
*/
const DESTINATION = 'https://w.org/';
/**
* Redirect type.
*/
const TYPE = 302;
/**
* Test post ID.
*
* @var int
*/
protected $post_id;
/**
* Plugin instance.
*
* @var external_permalinks_redux
*/
protected $plugin;
/**
* Metabox nonce.
*
* @var string
*/
protected $nonce;
/**
* Create some objects with redirects.
*/
public function setUp() {
parent::setUp();
$this->plugin = external_permalinks_redux::get_instance();
$this->post_id = $this->factory->post->create(
[
'post_type' => 'post',
]
);
$this->nonce = wp_create_nonce( 'external-permalinks-redux' );
}
/**
* Test metabox rendering.
*/
public function test_meta_box() {
ob_start();
$this->plugin->meta_box( get_post( $this->post_id ) );
$meta_box_contents = ob_get_clean();
$this->assertContains( 'value="' . $this->nonce . '"', $meta_box_contents );
foreach ( array_keys( $this->plugin->status_codes ) as $code ) {
$this->assertContains( 'value="' . $code . '"', $meta_box_contents );
}
}
/**
* Test metabox save.
*/
public function test_save_callback() {
$_POST[ $this->plugin->meta_key_target . '_nonce' ] = $this->nonce;
$_POST[ $this->plugin->meta_key_target . '_url' ] = static::DESTINATION;
$_POST[ $this->plugin->meta_key_target . '_type' ] = static::TYPE;
$this->plugin->action_save_post( $this->post_id );
$this->assertEquals( static::DESTINATION, get_post_meta( $this->post_id, $this->plugin->meta_key_target, true ) );
$this->assertEquals( static::TYPE, get_post_meta( $this->post_id, $this->plugin->meta_key_type, true ) );
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment