mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2025-10-16 12:05:38 +00:00
WPCS 1.0.0 includes a bunch of new auto-fixers, which drops the number of coding standards issues across WordPress significantly. Prior to running the auto-fixers, there were 15,312 issues detected. With this commit, we now drop to 4,769 issues. This change includes three notable additions: - Multiline function calls must now put each parameter on a new line. - Auto-formatting files is now part of the `grunt precommit` script. - Auto-fixable coding standards issues will now cause Travis failures. Fixes #44600. git-svn-id: https://develop.svn.wordpress.org/trunk@43571 602fd350-edb4-49c9-b593-d223f7449a82
103 lines
2.4 KiB
PHP
103 lines
2.4 KiB
PHP
<?php
|
|
|
|
/**
|
|
* @group taxonomy
|
|
*/
|
|
class Tests_WP_Taxonomy extends WP_UnitTestCase {
|
|
public function test_instances() {
|
|
global $wp_taxonomies;
|
|
|
|
foreach ( $wp_taxonomies as $taxonomy ) {
|
|
$this->assertInstanceOf( 'WP_Taxonomy', $taxonomy );
|
|
}
|
|
}
|
|
|
|
public function test_does_not_add_query_var_if_not_public() {
|
|
$this->set_permalink_structure( '/%postname%' );
|
|
|
|
/* @var WP $wp */
|
|
global $wp;
|
|
|
|
$taxonomy = rand_str();
|
|
$taxonomy_object = new WP_Taxonomy( $taxonomy, 'post' );
|
|
|
|
$taxonomy_object->add_rewrite_rules();
|
|
$this->assertFalse( in_array( 'foobar', $wp->public_query_vars ) );
|
|
}
|
|
|
|
public function test_adds_query_var_if_public() {
|
|
$this->set_permalink_structure( '/%postname%' );
|
|
|
|
/* @var WP $wp */
|
|
global $wp;
|
|
|
|
$taxonomy = rand_str();
|
|
$taxonomy_object = new WP_Taxonomy(
|
|
$taxonomy,
|
|
'post',
|
|
array(
|
|
'public' => true,
|
|
'rewrite' => false,
|
|
'query_var' => 'foobar',
|
|
)
|
|
);
|
|
|
|
$taxonomy_object->add_rewrite_rules();
|
|
$in_array = in_array( 'foobar', $wp->public_query_vars );
|
|
|
|
$taxonomy_object->remove_rewrite_rules();
|
|
$in_array_after = in_array( 'foobar', $wp->public_query_vars );
|
|
|
|
$this->assertTrue( $in_array );
|
|
$this->assertFalse( $in_array_after );
|
|
}
|
|
|
|
public function test_adds_rewrite_rules() {
|
|
$this->set_permalink_structure( '/%postname%' );
|
|
|
|
/* @var WP_Rewrite $wp_rewrite */
|
|
global $wp_rewrite;
|
|
|
|
$taxonomy = rand_str();
|
|
$taxonomy_object = new WP_Taxonomy(
|
|
$taxonomy,
|
|
'post',
|
|
array(
|
|
'public' => true,
|
|
'rewrite' => true,
|
|
)
|
|
);
|
|
|
|
$taxonomy_object->add_rewrite_rules();
|
|
$rewrite_tags = $wp_rewrite->rewritecode;
|
|
|
|
$taxonomy_object->remove_rewrite_rules();
|
|
$rewrite_tags_after = $wp_rewrite->rewritecode;
|
|
|
|
$this->assertNotFalse( array_search( "%$taxonomy%", $rewrite_tags ) );
|
|
$this->assertFalse( array_search( "%$taxonomy%", $rewrite_tags_after ) );
|
|
}
|
|
|
|
public function test_adds_ajax_callback() {
|
|
$taxonomy = rand_str();
|
|
$taxonomy_object = new WP_Taxonomy(
|
|
$taxonomy,
|
|
'post',
|
|
array(
|
|
'public' => true,
|
|
'rewrite' => true,
|
|
)
|
|
);
|
|
|
|
$taxonomy_object->add_hooks();
|
|
$has_action = has_action( "wp_ajax_add-$taxonomy", '_wp_ajax_add_hierarchical_term' );
|
|
|
|
$taxonomy_object->remove_hooks();
|
|
$has_action_after = has_action( "wp_ajax_add-$taxonomy", '_wp_ajax_add_hierarchical_term' );
|
|
|
|
$this->assertSame( 10, $has_action );
|
|
$this->assertFalse( $has_action_after );
|
|
|
|
}
|
|
}
|