当前位置: 首页>>代码示例>>PHP>>正文


PHP WPSEO_Frontend::robots方法代码示例

本文整理汇总了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;
 }
开发者ID:michalvittek,项目名称:wordpress-seo,代码行数:93,代码来源:test-class-wpseo-frontend.php


注:本文中的WPSEO_Frontend::robots方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。