本文整理汇总了PHP中WPSEO_Frontend::robots方法的典型用法代码示例。如果您正苦于以下问题:PHP WPSEO_Frontend::robots方法的具体用法?PHP WPSEO_Frontend::robots怎么用?PHP WPSEO_Frontend::robots使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WPSEO_Frontend
的用法示例。
在下文中一共展示了WPSEO_Frontend::robots方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: test_robots
/**
* @covers WPSEO_Frontend::robots
*
* @todo test post type archives
* @todo test with noodp and noydir option set
* @todo test with page_for_posts option
* @todo test date archives
* @todo test search results
*/
public function test_robots()
{
// go to home
$this->go_to_home();
// test home page with no special options
$expected = '';
$this->assertEquals($expected, self::$class_instance->robots());
$expected = 'noindex,follow';
// test WP visibility setting
update_option('blog_public', '0');
$this->assertEquals($expected, self::$class_instance->robots());
// clean-up
update_option('blog_public', '1');
// test replytocom
$_GET['replytocom'] = '1';
$this->assertEquals($expected, self::$class_instance->robots());
// clean-up
unset($_GET['replytocom']);
// test 'paged' query var
set_query_var('paged', 2);
$expected = '';
$this->assertEquals($expected, self::$class_instance->robots());
// test 'paged' query var (2)
$expected = 'noindex,follow';
self::$class_instance->options['noindex-subpages-wpseo'] = true;
$this->assertEquals($expected, self::$class_instance->robots());
// clean-up
self::$class_instance->options['noindex-subpages-wpseo'] = false;
set_query_var('paged', 0);
// create and go to post
$post_id = $this->factory->post->create();
$this->go_to(get_permalink($post_id));
// test regular post with no special options
$expected = '';
$this->assertEquals($expected, self::$class_instance->robots());
// test noindex-post option
$expected = 'noindex,follow';
self::$class_instance->options['noindex-post'] = true;
$this->assertEquals($expected, self::$class_instance->robots());
// clean-up
self::$class_instance->options['noindex-post'] = false;
// test post_status private
$expected = 'noindex,follow';
// test private posts
global $post;
$post->post_status = 'private';
$this->assertEquals($expected, self::$class_instance->robots());
// go to category page
$category_id = wp_create_category('Category Name');
// add posts to category
$this->factory->post->create_many(6, array('post_category' => array($category_id)));
$category_link = get_category_link($category_id);
$this->go_to($category_link);
// test regular category with no special options
$expected = '';
$this->assertEquals($expected, self::$class_instance->robots());
// test category with noindex-tax-category option
// TODO fix test for multisite (or code?)
if (false === is_multisite()) {
$expected = 'noindex,follow';
self::$class_instance->options['noindex-tax-category'] = true;
$this->assertEquals($expected, self::$class_instance->robots());
// clean-up
self::$class_instance->options['noindex-tax-category'] = false;
// test subpages of category archives
update_site_option('posts_per_page', 1);
self::$class_instance->options['noindex-subpages-wpseo'] = true;
$this->go_to(add_query_arg(array('paged' => 2), $category_link));
$expected = 'noindex,follow';
$this->assertEquals($expected, self::$class_instance->robots());
}
// go to author page
$user_id = $this->factory->user->create();
$this->go_to(get_author_posts_url($user_id));
// test author archive with no special options
$expected = '';
$this->assertEquals($expected, self::$class_instance->robots());
// test author archive with 'noindex-author-wpseo'
$expected = 'noindex,follow';
self::$class_instance->options['noindex-author-wpseo'] = true;
$this->assertEquals($expected, self::$class_instance->robots());
// clean-up
self::$class_instance->options['noindex-author-wpseo'] = false;
}