PageRenderTime 55ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/tests/query/conditionals.php

https://gitlab.com/Blueprint-Marketing/wordpress-unit-tests
PHP | 632 lines | 423 code | 97 blank | 112 comment | 7 complexity | b00dccfd85d7abe33810219c13581998 MD5 | raw file
  1. <?php
  2. /**
  3. * Test the is_*() functions in query.php across the URL structure
  4. *
  5. * This exercises both query.php and rewrite.php: urls are fed through the rewrite code,
  6. * then we test the effects of each url on the wp_query object.
  7. *
  8. * @group query
  9. * @group rewrite
  10. */
  11. class Tests_Query_Conditionals extends WP_UnitTestCase {
  12. protected $page_ids;
  13. protected $post_ids;
  14. function setUp() {
  15. parent::setUp();
  16. update_option( 'comments_per_page', 5 );
  17. update_option( 'posts_per_page', 5 );
  18. global $wp_rewrite;
  19. update_option( 'permalink_structure', '/%year%/%monthnum%/%day%/%postname%/' );
  20. create_initial_taxonomies();
  21. $GLOBALS['wp_rewrite']->init();
  22. flush_rewrite_rules();
  23. }
  24. function tearDown() {
  25. parent::tearDown();
  26. $GLOBALS['wp_rewrite']->init();
  27. }
  28. /**
  29. * Check each of the WP_Query is_* functions/properties against expected boolean value.
  30. *
  31. * Any properties that are listed by name as parameters will be expected to be true; any others are
  32. * expected to be false. For example, assertQueryTrue('is_single', 'is_feed') means is_single()
  33. * and is_feed() must be true and everything else must be false to pass.
  34. *
  35. * @param string $prop,... Any number of WP_Query properties that are expected to be true for the current request.
  36. */
  37. function assertQueryTrue(/* ... */) {
  38. global $wp_query;
  39. $all = array(
  40. 'is_single', 'is_preview', 'is_page', 'is_archive', 'is_date', 'is_year', 'is_month', 'is_day', 'is_time',
  41. 'is_author', 'is_category', 'is_tag', 'is_tax', 'is_search', 'is_feed', 'is_comment_feed', 'is_trackback',
  42. 'is_home', 'is_404', 'is_comments_popup', 'is_paged', 'is_admin', 'is_attachment', 'is_singular', 'is_robots',
  43. 'is_posts_page', 'is_post_type_archive',
  44. );
  45. $true = func_get_args();
  46. $passed = true;
  47. $not_false = $not_true = array(); // properties that were not set to expected values
  48. foreach ( $all as $query_thing ) {
  49. $result = is_callable( $query_thing ) ? call_user_func( $query_thing ) : $wp_query->$query_thing;
  50. if ( in_array( $query_thing, $true ) ) {
  51. if ( ! $result ) {
  52. array_push( $not_true, $query_thing );
  53. $passed = false;
  54. }
  55. } else if ( $result ) {
  56. array_push( $not_false, $query_thing );
  57. $passed = false;
  58. }
  59. }
  60. $message = '';
  61. if ( count($not_true) )
  62. $message .= implode( $not_true, ', ' ) . ' should be true. ';
  63. if ( count($not_false) )
  64. $message .= implode( $not_false, ', ' ) . ' should be false.';
  65. $this->assertTrue( $passed, $message );
  66. }
  67. function test_home() {
  68. $this->go_to('/');
  69. $this->assertQueryTrue('is_home');
  70. }
  71. function test_404() {
  72. $this->go_to('/'.rand_str());
  73. $this->assertQueryTrue('is_404');
  74. }
  75. function test_permalink() {
  76. $post_id = $this->factory->post->create( array( 'post_title' => 'hello-world' ) );
  77. $this->go_to( get_permalink( $post_id ) );
  78. $this->assertQueryTrue('is_single', 'is_singular');
  79. }
  80. function test_post_comments_feed() {
  81. $post_id = $this->factory->post->create( array( 'post_title' => 'hello-world' ) );
  82. $this->factory->comment->create_post_comments( $post_id, 2 );
  83. $this->go_to( get_post_comments_feed_link( $post_id ) );
  84. $this->assertQueryTrue('is_feed', 'is_single', 'is_singular', 'is_comment_feed');
  85. }
  86. function test_post_comments_feed_with_no_comments() {
  87. $post_id = $this->factory->post->create( array( 'post_title' => 'hello-world' ) );
  88. $this->go_to( get_post_comments_feed_link( $post_id ) );
  89. $this->assertQueryTrue('is_feed', 'is_single', 'is_singular', 'is_comment_feed');
  90. }
  91. function test_page() {
  92. $page_id = $this->factory->post->create( array( 'post_type' => 'page', 'post_title' => 'about' ) );
  93. $this->go_to( get_permalink( $page_id ) );
  94. $this->assertQueryTrue('is_page','is_singular');
  95. }
  96. function test_parent_page() {
  97. $page_id = $this->factory->post->create( array( 'post_type' => 'page', 'post_title' => 'parent-page' ) );
  98. $this->go_to( get_permalink( $page_id ) );
  99. $this->assertQueryTrue('is_page','is_singular');
  100. }
  101. function test_child_page_1() {
  102. $page_id = $this->factory->post->create( array( 'post_type' => 'page', 'post_title' => 'parent-page' ) );
  103. $page_id = $this->factory->post->create( array( 'post_type' => 'page', 'post_title' => 'child-page-1', 'post_parent' => $page_id ) );
  104. $this->go_to( get_permalink( $page_id ) );
  105. $this->assertQueryTrue('is_page','is_singular');
  106. }
  107. function test_child_page_2() {
  108. $page_id = $this->factory->post->create( array( 'post_type' => 'page', 'post_title' => 'parent-page' ) );
  109. $page_id = $this->factory->post->create( array( 'post_type' => 'page', 'post_title' => 'child-page-1', 'post_parent' => $page_id ) );
  110. $page_id = $this->factory->post->create( array( 'post_type' => 'page', 'post_title' => 'child-page-2', 'post_parent' => $page_id ) );
  111. $this->go_to( get_permalink( $page_id ) );
  112. $this->assertQueryTrue('is_page','is_singular');
  113. }
  114. // '(about)/trackback/?$' => 'index.php?pagename=$matches[1]&tb=1'
  115. function test_page_trackback() {
  116. $page_ids = array();
  117. $page_ids[] = $page_id = $this->factory->post->create( array( 'post_type' => 'page', 'post_title' => 'parent-page' ) );
  118. $page_ids[] = $page_id = $this->factory->post->create( array( 'post_type' => 'page', 'post_title' => 'child-page-1', 'post_parent' => $page_id ) );
  119. $page_ids[] = $page_id = $this->factory->post->create( array( 'post_type' => 'page', 'post_title' => 'child-page-2', 'post_parent' => $page_id ) );
  120. foreach ( $page_ids as $page_id ) {
  121. $url = get_permalink( $page_id );
  122. $this->go_to("{$url}trackback/");
  123. // make sure the correct wp_query flags are set
  124. $this->assertQueryTrue('is_page','is_singular','is_trackback');
  125. // make sure the correct page was fetched
  126. global $wp_query;
  127. $this->assertEquals( $page_id, $wp_query->get_queried_object()->ID );
  128. }
  129. }
  130. //'(about)/feed/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?pagename=$matches[1]&feed=$matches[2]'
  131. function test_page_feed() {
  132. $page_ids = array();
  133. $page_ids[] = $page_id = $this->factory->post->create( array( 'post_type' => 'page', 'post_title' => 'parent-page' ) );
  134. $page_ids[] = $page_id = $this->factory->post->create( array( 'post_type' => 'page', 'post_title' => 'child-page-1', 'post_parent' => $page_id ) );
  135. $page_ids[] = $page_id = $this->factory->post->create( array( 'post_type' => 'page', 'post_title' => 'child-page-2', 'post_parent' => $page_id ) );
  136. foreach ( $page_ids as $page_id ) {
  137. $this->factory->comment->create_post_comments( $page_id, 2 );
  138. $url = get_permalink( $page_id );
  139. $this->go_to("{$url}feed/");
  140. // make sure the correct wp_query flags are set
  141. $this->assertQueryTrue('is_page', 'is_singular', 'is_feed', 'is_comment_feed');
  142. // make sure the correct page was fetched
  143. global $wp_query;
  144. $this->assertEquals( $page_id, $wp_query->get_queried_object()->ID );
  145. }
  146. }
  147. function test_page_feed_with_no_comments() {
  148. $page_ids = array();
  149. $page_ids[] = $page_id = $this->factory->post->create( array( 'post_type' => 'page', 'post_title' => 'parent-page' ) );
  150. $page_ids[] = $page_id = $this->factory->post->create( array( 'post_type' => 'page', 'post_title' => 'child-page-1', 'post_parent' => $page_id ) );
  151. $page_ids[] = $page_id = $this->factory->post->create( array( 'post_type' => 'page', 'post_title' => 'child-page-2', 'post_parent' => $page_id ) );
  152. foreach ( $page_ids as $page_id ) {
  153. $url = get_permalink( $page_id );
  154. $this->go_to("{$url}feed/");
  155. // make sure the correct wp_query flags are set
  156. $this->assertQueryTrue('is_page', 'is_singular', 'is_feed', 'is_comment_feed');
  157. // make sure the correct page was fetched
  158. global $wp_query;
  159. $this->assertEquals( $page_id, $wp_query->get_queried_object()->ID );
  160. }
  161. }
  162. // '(about)/feed/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?pagename=$matches[1]&feed=$matches[2]'
  163. function test_page_feed_atom() {
  164. $page_ids = array();
  165. $page_ids[] = $page_id = $this->factory->post->create( array( 'post_type' => 'page', 'post_title' => 'parent-page' ) );
  166. $page_ids[] = $page_id = $this->factory->post->create( array( 'post_type' => 'page', 'post_title' => 'child-page-1', 'post_parent' => $page_id ) );
  167. $page_ids[] = $page_id = $this->factory->post->create( array( 'post_type' => 'page', 'post_title' => 'child-page-2', 'post_parent' => $page_id ) );
  168. foreach ( $page_ids as $page_id ) {
  169. $this->factory->comment->create_post_comments( $page_id, 2 );
  170. $url = get_permalink( $page_id );
  171. $this->go_to("{$url}feed/atom/");
  172. // make sure the correct wp_query flags are set
  173. $this->assertQueryTrue('is_page', 'is_singular', 'is_feed', 'is_comment_feed');
  174. // make sure the correct page was fetched
  175. global $wp_query;
  176. $this->assertEquals( $page_id, $wp_query->get_queried_object()->ID );
  177. }
  178. }
  179. // '(about)/page/?([0-9]{1,})/?$' => 'index.php?pagename=$matches[1]&paged=$matches[2]'
  180. function test_page_page_2() {
  181. $page_id = $this->factory->post->create( array( 'post_type' => 'page', 'post_title' => 'about', 'post_content' => 'Page 1 <!--nextpage--> Page 2' ) );
  182. $this->go_to("/about/page/2/");
  183. // make sure the correct wp_query flags are set
  184. $this->assertQueryTrue('is_page', 'is_singular', 'is_paged');
  185. // make sure the correct page was fetched
  186. global $wp_query;
  187. $this->assertEquals( $page_id, $wp_query->get_queried_object()->ID );
  188. }
  189. // '(about)/page/?([0-9]{1,})/?$' => 'index.php?pagename=$matches[1]&paged=$matches[2]'
  190. function test_page_page_2_no_slash() {
  191. $page_id = $this->factory->post->create( array( 'post_type' => 'page', 'post_title' => 'about', 'post_content' => 'Page 1 <!--nextpage--> Page 2' ) );
  192. $this->go_to("/about/page2/");
  193. // make sure the correct wp_query flags are set
  194. $this->assertQueryTrue('is_page', 'is_singular', 'is_paged');
  195. // make sure the correct page was fetched
  196. global $wp_query;
  197. $this->assertEquals( $page_id, $wp_query->get_queried_object()->ID );
  198. }
  199. // FIXME: what is this for?
  200. // '(about)(/[0-9]+)?/?$' => 'index.php?pagename=$matches[1]&page=$matches[2]'
  201. function test_pagination_of_posts_page() {
  202. $page_id = $this->factory->post->create( array( 'post_type' => 'page', 'post_title' => 'about', 'post_content' => 'Page 1 <!--nextpage--> Page 2' ) );
  203. update_option( 'show_on_front', 'page' );
  204. update_option( 'page_for_posts', $page_id );
  205. $this->go_to('/about/2/');
  206. $this->assertQueryTrue( 'is_home', 'is_posts_page' );
  207. // make sure the correct page was fetched
  208. global $wp_query;
  209. $this->assertEquals( $page_id, $wp_query->get_queried_object()->ID );
  210. }
  211. // FIXME: no tests for these yet
  212. // 'about/attachment/([^/]+)/?$' => 'index.php?attachment=$matches[1]',
  213. // 'about/attachment/([^/]+)/trackback/?$' => 'index.php?attachment=$matches[1]&tb=1',
  214. // 'about/attachment/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?attachment=$matches[1]&feed=$matches[2]',
  215. // 'about/attachment/([^/]+)/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?attachment=$matches[1]&feed=$matches[2]',
  216. // 'feed/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?&feed=$matches[1]',
  217. // '(feed|rdf|rss|rss2|atom)/?$' => 'index.php?&feed=$matches[1]',
  218. function test_main_feed_2() {
  219. $this->factory->post->create(); // @test_404
  220. $feeds = array('feed', 'rdf', 'rss', 'rss2', 'atom');
  221. // long version
  222. foreach ($feeds as $feed) {
  223. $this->go_to("/feed/{$feed}/");
  224. $this->assertQueryTrue('is_feed');
  225. }
  226. // short version
  227. foreach ($feeds as $feed) {
  228. $this->go_to("/{$feed}/");
  229. $this->assertQueryTrue('is_feed');
  230. }
  231. }
  232. function test_main_feed() {
  233. $this->factory->post->create(); // @test_404
  234. $types = array('rss2', 'rss', 'atom');
  235. foreach ($types as $type) {
  236. $this->go_to(get_feed_link($type));
  237. $this->assertQueryTrue('is_feed');
  238. }
  239. }
  240. // 'page/?([0-9]{1,})/?$' => 'index.php?&paged=$matches[1]',
  241. function test_paged() {
  242. $this->factory->post->create_many( 15 );
  243. for ( $i = 2; $i <= 3; $i++ ) {
  244. $this->go_to("/page/{$i}/");
  245. $this->assertQueryTrue('is_home', 'is_paged');
  246. }
  247. }
  248. // 'comments/feed/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?&feed=$matches[1]&withcomments=1',
  249. // 'comments/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?&feed=$matches[1]&withcomments=1',
  250. function test_main_comments_feed() {
  251. $post_id = $this->factory->post->create( array( 'post_title' => 'hello-world' ) );
  252. $this->factory->comment->create_post_comments( $post_id, 2 );
  253. // check the url as generated by get_post_comments_feed_link()
  254. $this->go_to( get_post_comments_feed_link( $post_id ) );
  255. $this->assertQueryTrue('is_feed', 'is_single', 'is_singular', 'is_comment_feed');
  256. // check the long form
  257. $types = array('feed', 'rdf', 'rss', 'rss2', 'atom');
  258. foreach ($types as $type) {
  259. $this->go_to("/comments/feed/{$type}");
  260. $this->assertQueryTrue('is_feed', 'is_comment_feed');
  261. }
  262. // check the short form
  263. $types = array('feed', 'rdf', 'rss', 'rss2', 'atom');
  264. foreach ($types as $type) {
  265. $this->go_to("/comments/{$type}");
  266. $this->assertQueryTrue('is_feed', 'is_comment_feed');
  267. }
  268. }
  269. // 'search/(.+)/feed/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?s=$matches[1]&feed=$matches[2]',
  270. // 'search/(.+)/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?s=$matches[1]&feed=$matches[2]',
  271. function test_search_feed() {
  272. // check the long form
  273. $types = array('feed', 'rdf', 'rss', 'rss2', 'atom');
  274. foreach ($types as $type) {
  275. $this->go_to("/search/test/feed/{$type}");
  276. $this->assertQueryTrue('is_feed', 'is_search');
  277. }
  278. // check the short form
  279. $types = array('feed', 'rdf', 'rss', 'rss2', 'atom');
  280. foreach ($types as $type) {
  281. $this->go_to("/search/test/{$type}");
  282. $this->assertQueryTrue('is_feed', 'is_search');
  283. }
  284. }
  285. // 'search/(.+)/page/?([0-9]{1,})/?$' => 'index.php?s=$matches[1]&paged=$matches[2]',
  286. function test_search_paged() {
  287. $this->factory->post->create_many( 10, array( 'post_title' => 'test' ) );
  288. $this->go_to('/search/test/page/2/');
  289. $this->assertQueryTrue('is_search', 'is_paged');
  290. }
  291. // 'search/(.+)/?$' => 'index.php?s=$matches[1]',
  292. function test_search() {
  293. $this->go_to('/search/test/');
  294. $this->assertQueryTrue('is_search');
  295. }
  296. /**
  297. * @ticket 13961
  298. */
  299. function test_search_encoded_chars() {
  300. $this->go_to('/search/F%C3%BCnf%2Bbar/');
  301. $this->assertEquals( get_query_var( 's' ), 'Fünf+bar' );
  302. }
  303. // 'category/(.+?)/feed/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?category_name=$matches[1]&feed=$matches[2]',
  304. // 'category/(.+?)/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?category_name=$matches[1]&feed=$matches[2]',
  305. function test_category_feed() {
  306. $this->factory->term->create( array( 'name' => 'cat-a', 'taxonomy' => 'category' ) );
  307. // check the long form
  308. $types = array('feed', 'rdf', 'rss', 'rss2', 'atom');
  309. foreach ($types as $type) {
  310. $this->go_to("/category/cat-a/feed/{$type}");
  311. $this->assertQueryTrue('is_archive', 'is_feed', 'is_category');
  312. }
  313. // check the short form
  314. $types = array('feed', 'rdf', 'rss', 'rss2', 'atom');
  315. foreach ($types as $type) {
  316. $this->go_to("/category/cat-a/{$type}");
  317. $this->assertQueryTrue('is_archive', 'is_feed', 'is_category');
  318. }
  319. }
  320. // 'category/(.+?)/page/?([0-9]{1,})/?$' => 'index.php?category_name=$matches[1]&paged=$matches[2]',
  321. function test_category_paged() {
  322. $this->factory->post->create_many( 10 );
  323. $this->go_to('/category/uncategorized/page/2/');
  324. $this->assertQueryTrue('is_archive', 'is_category', 'is_paged');
  325. }
  326. // 'category/(.+?)/?$' => 'index.php?category_name=$matches[1]',
  327. function test_category() {
  328. $this->factory->term->create( array( 'name' => 'cat-a', 'taxonomy' => 'category' ) );
  329. $this->go_to('/category/cat-a/');
  330. $this->assertQueryTrue('is_archive', 'is_category');
  331. }
  332. // 'tag/(.+?)/feed/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?tag=$matches[1]&feed=$matches[2]',
  333. // 'tag/(.+?)/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?tag=$matches[1]&feed=$matches[2]',
  334. function test_tag_feed() {
  335. $this->factory->term->create( array( 'name' => 'tag-a', 'taxonomy' => 'post_tag' ) );
  336. // check the long form
  337. $types = array('feed', 'rdf', 'rss', 'rss2', 'atom');
  338. foreach ($types as $type) {
  339. $this->go_to("/tag/tag-a/feed/{$type}");
  340. $this->assertQueryTrue('is_archive', 'is_feed', 'is_tag');
  341. }
  342. // check the short form
  343. $types = array('feed', 'rdf', 'rss', 'rss2', 'atom');
  344. foreach ($types as $type) {
  345. $this->go_to("/tag/tag-a/{$type}");
  346. $this->assertQueryTrue('is_archive', 'is_feed', 'is_tag');
  347. }
  348. }
  349. // 'tag/(.+?)/page/?([0-9]{1,})/?$' => 'index.php?tag=$matches[1]&paged=$matches[2]',
  350. function test_tag_paged() {
  351. $post_ids = $this->factory->post->create_many( 10 );
  352. foreach ( $post_ids as $post_id )
  353. $this->factory->term->add_post_terms( $post_id, 'tag-a', 'post_tag' );
  354. $this->go_to('/tag/tag-a/page/2/');
  355. $this->assertQueryTrue('is_archive', 'is_tag', 'is_paged');
  356. }
  357. // 'tag/(.+?)/?$' => 'index.php?tag=$matches[1]',
  358. function test_tag() {
  359. $this->factory->term->create( array( 'name' => 'tag-a', 'taxonomy' => 'post_tag' ) );
  360. $this->go_to('/tag/tag-a/');
  361. $this->assertQueryTrue('is_archive', 'is_tag');
  362. }
  363. // 'author/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?author_name=$matches[1]&feed=$matches[2]',
  364. // 'author/([^/]+)/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?author_name=$matches[1]&feed=$matches[2]',
  365. function test_author_feed() {
  366. $this->factory->user->create( array( 'user_login' => 'user-a' ) );
  367. // check the long form
  368. $types = array('feed', 'rdf', 'rss', 'rss2', 'atom');
  369. foreach ($types as $type) {
  370. $this->go_to("/author/user-a/feed/{$type}");
  371. $this->assertQueryTrue('is_archive', 'is_feed', 'is_author');
  372. }
  373. // check the short form
  374. $types = array('feed', 'rdf', 'rss', 'rss2', 'atom');
  375. foreach ($types as $type) {
  376. $this->go_to("/author/user-a/{$type}");
  377. $this->assertQueryTrue('is_archive', 'is_feed', 'is_author');
  378. }
  379. }
  380. // 'author/([^/]+)/page/?([0-9]{1,})/?$' => 'index.php?author_name=$matches[1]&paged=$matches[2]',
  381. function test_author_paged() {
  382. $user_id = $this->factory->user->create( array( 'user_login' => 'user-a' ) );
  383. $this->factory->post->create_many( 10, array( 'post_author' => $user_id ) );
  384. $this->go_to('/author/user-a/page/2/');
  385. $this->assertQueryTrue('is_archive', 'is_author', 'is_paged');
  386. }
  387. // 'author/([^/]+)/?$' => 'index.php?author_name=$matches[1]',
  388. function test_author() {
  389. $user_id = $this->factory->user->create( array( 'user_login' => 'user-a' ) );
  390. $this->factory->post->create( array( 'post_author' => $user_id ) );
  391. $this->go_to('/author/user-a/');
  392. $this->assertQueryTrue('is_archive', 'is_author');
  393. }
  394. function test_author_with_no_posts() {
  395. $user_id = $this->factory->user->create( array( 'user_login' => 'user-a' ) );
  396. $this->go_to('/author/user-a/');
  397. $this->assertQueryTrue('is_archive', 'is_author');
  398. }
  399. // '([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})/feed/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?year=$matches[1]&monthnum=$matches[2]&day=$matches[3]&feed=$matches[4]',
  400. // '([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?year=$matches[1]&monthnum=$matches[2]&day=$matches[3]&feed=$matches[4]',
  401. function test_ymd_feed() {
  402. $this->factory->post->create( array( 'post_date' => '2007-09-04 00:00:00' ) );
  403. // check the long form
  404. $types = array('feed', 'rdf', 'rss', 'rss2', 'atom');
  405. foreach ($types as $type) {
  406. $this->go_to("/2007/09/04/feed/{$type}");
  407. $this->assertQueryTrue('is_archive', 'is_feed', 'is_day', 'is_date');
  408. }
  409. // check the short form
  410. $types = array('feed', 'rdf', 'rss', 'rss2', 'atom');
  411. foreach ($types as $type) {
  412. $this->go_to("/2007/09/04/{$type}");
  413. $this->assertQueryTrue('is_archive', 'is_feed', 'is_day', 'is_date');
  414. }
  415. }
  416. // '([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})/page/?([0-9]{1,})/?$' => 'index.php?year=$matches[1]&monthnum=$matches[2]&day=$matches[3]&paged=$matches[4]',
  417. function test_ymd_paged() {
  418. $this->factory->post->create_many( 10, array( 'post_date' => '2007-09-04 00:00:00' ) );
  419. $this->go_to('/2007/09/04/page/2/');
  420. $this->assertQueryTrue('is_archive', 'is_day', 'is_date', 'is_paged');
  421. }
  422. // '([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})/?$' => 'index.php?year=$matches[1]&monthnum=$matches[2]&day=$matches[3]',
  423. function test_ymd() {
  424. $this->factory->post->create( array( 'post_date' => '2007-09-04 00:00:00' ) );
  425. $this->go_to('/2007/09/04/');
  426. $this->assertQueryTrue('is_archive', 'is_day', 'is_date');
  427. }
  428. // '([0-9]{4})/([0-9]{1,2})/feed/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?year=$matches[1]&monthnum=$matches[2]&feed=$matches[3]',
  429. // '([0-9]{4})/([0-9]{1,2})/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?year=$matches[1]&monthnum=$matches[2]&feed=$matches[3]',
  430. function test_ym_feed() {
  431. $this->factory->post->create( array( 'post_date' => '2007-09-04 00:00:00' ) );
  432. // check the long form
  433. $types = array('feed', 'rdf', 'rss', 'rss2', 'atom');
  434. foreach ($types as $type) {
  435. $this->go_to("/2007/09/feed/{$type}");
  436. $this->assertQueryTrue('is_archive', 'is_feed', 'is_month', 'is_date');
  437. }
  438. // check the short form
  439. $types = array('feed', 'rdf', 'rss', 'rss2', 'atom');
  440. foreach ($types as $type) {
  441. $this->go_to("/2007/09/{$type}");
  442. $this->assertQueryTrue('is_archive', 'is_feed', 'is_month', 'is_date');
  443. }
  444. }
  445. // '([0-9]{4})/([0-9]{1,2})/page/?([0-9]{1,})/?$' => 'index.php?year=$matches[1]&monthnum=$matches[2]&paged=$matches[3]',
  446. function test_ym_paged() {
  447. $this->factory->post->create_many( 10, array( 'post_date' => '2007-09-04 00:00:00' ) );
  448. $this->go_to('/2007/09/page/2/');
  449. $this->assertQueryTrue('is_archive', 'is_date', 'is_month', 'is_paged');
  450. }
  451. // '([0-9]{4})/([0-9]{1,2})/?$' => 'index.php?year=$matches[1]&monthnum=$matches[2]',
  452. function test_ym() {
  453. $this->factory->post->create( array( 'post_date' => '2007-09-04 00:00:00' ) );
  454. $this->go_to('/2007/09/');
  455. $this->assertQueryTrue('is_archive', 'is_date', 'is_month');
  456. }
  457. // '([0-9]{4})/feed/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?year=$matches[1]&feed=$matches[2]',
  458. // '([0-9]{4})/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?year=$matches[1]&feed=$matches[2]',
  459. function test_y_feed() {
  460. $this->factory->post->create( array( 'post_date' => '2007-09-04 00:00:00' ) );
  461. // check the long form
  462. $types = array('feed', 'rdf', 'rss', 'rss2', 'atom');
  463. foreach ($types as $type) {
  464. $this->go_to("/2007/feed/{$type}");
  465. $this->assertQueryTrue('is_archive', 'is_feed', 'is_year', 'is_date');
  466. }
  467. // check the short form
  468. $types = array('feed', 'rdf', 'rss', 'rss2', 'atom');
  469. foreach ($types as $type) {
  470. $this->go_to("/2007/{$type}");
  471. $this->assertQueryTrue('is_archive', 'is_feed', 'is_year', 'is_date');
  472. }
  473. }
  474. // '([0-9]{4})/page/?([0-9]{1,})/?$' => 'index.php?year=$matches[1]&paged=$matches[2]',
  475. function test_y_paged() {
  476. $this->factory->post->create_many( 10, array( 'post_date' => '2007-09-04 00:00:00' ) );
  477. $this->go_to('/2007/page/2/');
  478. $this->assertQueryTrue('is_archive', 'is_date', 'is_year', 'is_paged');
  479. }
  480. // '([0-9]{4})/?$' => 'index.php?year=$matches[1]',
  481. function test_y() {
  482. $this->factory->post->create( array( 'post_date' => '2007-09-04 00:00:00' ) );
  483. $this->go_to('/2007/');
  484. $this->assertQueryTrue('is_archive', 'is_date', 'is_year');
  485. }
  486. // '([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})/([^/]+)/trackback/?$' => 'index.php?year=$matches[1]&monthnum=$matches[2]&day=$matches[3]&name=$matches[4]&tb=1',
  487. function test_post_trackback() {
  488. $post_id = $this->factory->post->create();
  489. $permalink = get_permalink( $post_id );
  490. $this->go_to("{$permalink}trackback/");
  491. $this->assertQueryTrue('is_single', 'is_singular', 'is_trackback');
  492. }
  493. // '([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?year=$matches[1]&monthnum=$matches[2]&day=$matches[3]&name=$matches[4]&feed=$matches[5]',
  494. // '([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})/([^/]+)/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?year=$matches[1]&monthnum=$matches[2]&day=$matches[3]&name=$matches[4]&feed=$matches[5]',
  495. function test_post_comment_feed() {
  496. $post_id = $this->factory->post->create();
  497. $permalink = get_permalink( $post_id );
  498. $types = array('feed', 'rdf', 'rss', 'rss2', 'atom');
  499. foreach ($types as $type) {
  500. $this->go_to("{$permalink}feed/{$type}");
  501. $this->assertQueryTrue('is_single', 'is_singular', 'is_feed', 'is_comment_feed');
  502. }
  503. // check the short form
  504. $types = array('feed', 'rdf', 'rss', 'rss2', 'atom');
  505. foreach ($types as $type) {
  506. $this->go_to("{$permalink}{$type}");
  507. $this->assertQueryTrue('is_single', 'is_singular', 'is_feed', 'is_comment_feed');
  508. }
  509. }
  510. // '([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})/([^/]+)(/[0-9]+)?/?$' => 'index.php?year=$matches[1]&monthnum=$matches[2]&day=$matches[3]&name=$matches[4]&page=$matches[5]',
  511. function test_post_paged_short() {
  512. $post_id = $this->factory->post->create( array(
  513. 'post_date' => '2007-09-04 00:00:00',
  514. 'post_title' => 'a-post-with-multiple-pages',
  515. 'post_content' => 'Page 1 <!--nextpage--> Page 2'
  516. ) );
  517. $this->go_to( get_permalink( $post_id ) . '2/' );
  518. // should is_paged be true also?
  519. $this->assertQueryTrue('is_single', 'is_singular');
  520. }
  521. // '[0-9]{4}/[0-9]{1,2}/[0-9]{1,2}/[^/]+/([^/]+)/?$' => 'index.php?attachment=$matches[1]',
  522. function test_post_attachment() {
  523. $post_id = $this->factory->post->create( array( 'post_type' => 'attachment' ) );
  524. $permalink = get_attachment_link( $post_id );
  525. $this->go_to($permalink);
  526. $this->assertQueryTrue('is_single', 'is_attachment', 'is_singular');
  527. }
  528. // '[0-9]{4}/[0-9]{1,2}/[0-9]{1,2}/[^/]+/([^/]+)/trackback/?$' => 'index.php?attachment=$matches[1]&tb=1',
  529. // '[0-9]{4}/[0-9]{1,2}/[0-9]{1,2}/[^/]+/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?attachment=$matches[1]&feed=$matches[2]',
  530. // '[0-9]{4}/[0-9]{1,2}/[0-9]{1,2}/[^/]+/([^/]+)/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?attachment=$matches[1]&feed=$matches[2]',
  531. // '[0-9]{4}/[0-9]{1,2}/[0-9]{1,2}/[^/]+/attachment/([^/]+)/?$' => 'index.php?attachment=$matches[1]',
  532. // '[0-9]{4}/[0-9]{1,2}/[0-9]{1,2}/[^/]+/attachment/([^/]+)/trackback/?$' => 'index.php?attachment=$matches[1]&tb=1',
  533. // '[0-9]{4}/[0-9]{1,2}/[0-9]{1,2}/[^/]+/attachment/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?attachment=$matches[1]&feed=$matches[2]',
  534. // '[0-9]{4}/[0-9]{1,2}/[0-9]{1,2}/[^/]+/attachment/([^/]+)/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?attachment=$matches[1]&feed=$matches[2]',
  535. }