當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。