Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/issue 130/finish migrating tests to new format #135

Open
wants to merge 4 commits into
base: v2.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions tests/Feature/AdminFunctionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
namespace Alley\WP\WP_SEO\Tests\Feature;

use Alley\WP\WP_SEO\Tests\TestCase;
use Mantle\Testing\Utils;

class AdminFunctionTest extends TestCase {
/**
Expand All @@ -17,11 +18,7 @@ class AdminFunctionTest extends TestCase {
*/
function test_admin_functions_contain( $function, $should, $contain, $args ) {
// Capture the output of the function.
ob_start();
$function( ...$args );
$output = ob_get_clean();

self::assertStringContainsString( $contain, $output, $should );
self::assertStringContainsString( $contain, Utils::get_echo( $function, $args ), $should );
}

/**
Expand Down
21 changes: 6 additions & 15 deletions tests/Feature/MetaboxesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
namespace Alley\WP\WP_SEO\Tests\Feature;

use Alley\WP\WP_SEO\Tests\TestCase;
use Mantle\Testing\Utils;
use WP_SEO_Settings;
use WP_SEO;

Expand Down Expand Up @@ -72,9 +73,7 @@ function test_post_meta_fields() {

$post = get_post( $post_ID );
// Capture the output of the function.
ob_start();
WP_SEO()->post_meta_fields( $post );
$html = ob_get_clean();
$html = Utils::get_echo( [ WP_SEO(), 'post_meta_fields' ], [ $post ] );

self::assertStringContainsString( 'name="seo_meta[title]" value="' . $title . '" size="96"', $html );
self::assertMatchesRegularExpression( '/<input[^>]+type="hidden"[^>]+name="wp-seo-nonce"/', $html );
Expand All @@ -92,9 +91,7 @@ function test_save_post_fields() {
$post = get_post( $post_ID );

// Capture the output of the function.
ob_start();
WP_SEO()->post_meta_fields( $post );
$html = ob_get_clean();
$html = Utils::get_echo( [ WP_SEO(), 'post_meta_fields' ], [ $post ] );

// No $_POST.
$this->assertNull( WP_SEO()->save_post_fields( $post_ID ) );
Expand Down Expand Up @@ -181,9 +178,7 @@ function test_add_term_boxes() {
*/
function test_add_term_meta_fields() {
// Capture the output of the function.
ob_start();
WP_SEO()->add_term_meta_fields( 'category' );
$html = ob_get_clean();
$html = Utils::get_echo( [ WP_SEO(), 'add_term_meta_fields' ], [ 'category' ] );

self::assertMatchesRegularExpression( '/<input[^>]+type="hidden"[^>]+name="wp-seo-nonce"/', $html );
self::assertStringContainsString( 'name="seo_meta[title]"', $html );
Expand All @@ -209,9 +204,7 @@ function test_edit_term_meta_fields() {
);

// Capture the output of the function.
ob_start();
WP_SEO()->edit_term_meta_fields( $category, 'category' );
$html = ob_get_clean();
$html = Utils::get_echo( [ WP_SEO(), 'edit_term_meta_fields' ], [ $category, 'category' ] );

self::assertMatchesRegularExpression( '/<input[^>]+type="hidden"[^>]+name="wp-seo-nonce"/', $html );
self::assertMatchesRegularExpression( "/<textarea.*?>{$description}<\/textarea>/", $html );
Expand All @@ -226,9 +219,7 @@ function test_save_term_fields() {
$category = get_term( $category_ID, 'category' );

// Capture the output of the function.
ob_start();
WP_SEO()->edit_term_meta_fields( $category, 'category' );
$html = ob_get_clean();
$html = Utils::get_echo( [ WP_SEO(), 'add_term_meta_fields' ], [ $category, 'category' ] );

// No $_POST.
$this->assertNull( WP_SEO()->save_term_fields( $category_ID, $category->term_taxonomy_id, 'category' ) );
Expand Down
52 changes: 52 additions & 0 deletions tests/Feature/PropertiesTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php
/**
* WP SEO Tests: Test that properties in WP_SEO include only allowed values after set_properties().
*
* @package wp-seo
*/

namespace Alley\WP\WP_SEO\Tests\Feature;

use Alley\WP\WP_SEO\Tests\TestCase;
use WP_SEO;

class PropertiesTest extends TestCase {

function setUp(): void {
parent::setUp();
add_filter( 'wp_seo_formatting_tags', [ $this, '_add_mock' ] );
add_filter( 'wp_seo_formatting_tags', [ $this, '_add_illegals' ] );
WP_SEO()->set_properties();
}

function tearDown(): void {
parent::tearDown();
// Leave the place as we found it.
remove_filter( 'wp_seo_formatting_tags', [ $this, '_add_mock' ] );
remove_filter( 'wp_seo_formatting_tags', [ $this, '_add_illegals' ] );
WP_SEO()->set_properties();
}

function _add_mock( $tags ) {
$tags['is_a_tag'] = $this->getMockForAbstractClass( 'WP_SEO_Formatting_Tag' );

return $tags;
}

function _add_illegals( $tags ) {
$tags['is_non_object'] = true;
$tags['is_wrong_object'] = new \stdClass;

return $tags;
}

function test_legal_tag() {
$this->assertArrayHasKey( 'is_a_tag', WP_SEO()->formatting_tags );
}

function test_illegal_tags() {
$this->assertArrayNotHasKey( 'is_non_object', WP_SEO()->formatting_tags );
$this->assertArrayNotHasKey( 'is_wrong_object', WP_SEO()->formatting_tags );
}

}
Loading
Loading