From ff18c3a5b73b5f27dd9e56158ef1bfc305da0af2 Mon Sep 17 00:00:00 2001
From: Riccardo Magliocchetti <riccardo.magliocchetti@gmail.com>
Date: Fri, 11 Nov 2016 20:24:20 +0100
Subject: [PATCH] tests: call date once per test
So we can run tests around midnight :)
See #38688
diff --git tests/phpunit/tests/post/listPages.php tests/phpunit/tests/post/listPages.php
index d214631..598b59c 100644
|
|
|
2 | 2 | |
3 | 3 | class Tests_List_Pages extends WP_UnitTestCase { |
4 | 4 | var $pages; |
| 5 | var $date; |
5 | 6 | |
6 | 7 | /* |
7 | 8 | $defaults = array( |
… |
… |
class Tests_List_Pages extends WP_UnitTestCase { |
27 | 28 | parent::setUp(); |
28 | 29 | global $wpdb; |
29 | 30 | $wpdb->query( 'TRUNCATE ' . $wpdb->prefix . 'posts' ); |
| 31 | $time = time(); |
30 | 32 | $pages = array(); |
31 | 33 | self::factory()->user->create(); |
32 | | $pages[] = self::factory()->post->create( array( 'post_type' => 'page', 'post_title' => 'Parent 1' ) ); |
33 | | $pages[] = self::factory()->post->create( array( 'post_type' => 'page', 'post_title' => 'Parent 2' ) ); |
34 | | $pages[] = self::factory()->post->create( array( 'post_type' => 'page', 'post_title' => 'Parent 3', 'post_author' => '2' ) ); |
| 34 | $pages[] = self::factory()->post->create( array( 'post_type' => 'page', 'post_title' => 'Parent 1', 'post_date' => $time ) ); |
| 35 | $pages[] = self::factory()->post->create( array( 'post_type' => 'page', 'post_title' => 'Parent 2', 'post_date' => $time ) ); |
| 36 | $pages[] = self::factory()->post->create( array( 'post_type' => 'page', 'post_title' => 'Parent 3', 'post_author' => '2', 'post_date' => $time ) ); |
35 | 37 | |
36 | 38 | foreach ( $pages as $page ) { |
37 | | $this->pages[$page] = self::factory()->post->create( array( 'post_parent' => $page, 'post_type' => 'page', 'post_title' => 'Child 1' ) ); |
38 | | $this->pages[$page] = self::factory()->post->create( array( 'post_parent' => $page, 'post_type' => 'page', 'post_title' => 'Child 2' ) ); |
39 | | $this->pages[$page] = self::factory()->post->create( array( 'post_parent' => $page, 'post_type' => 'page', 'post_title' => 'Child 3' ) ); |
| 39 | $this->pages[$page] = self::factory()->post->create( array( 'post_parent' => $page, 'post_type' => 'page', 'post_title' => 'Child 1', 'post_date' => $time ) ); |
| 40 | $this->pages[$page] = self::factory()->post->create( array( 'post_parent' => $page, 'post_type' => 'page', 'post_title' => 'Child 2', 'post_date' => $time ) ); |
| 41 | $this->pages[$page] = self::factory()->post->create( array( 'post_parent' => $page, 'post_type' => 'page', 'post_title' => 'Child 3', 'post_date' => $time ) ); |
40 | 42 | } |
| 43 | |
| 44 | $date = date( 'F j, Y', $time ); |
41 | 45 | } |
42 | 46 | |
43 | 47 | function test_wp_list_pages_default() { |
… |
… |
class Tests_List_Pages extends WP_UnitTestCase { |
89 | 93 | 'depth' => 1, |
90 | 94 | 'show_date' => true |
91 | 95 | ); |
92 | | $expected['show_date'] = '<li class="pagenav">Pages<ul><li class="page_item page-item-1 page_item_has_children"><a href="' . get_permalink( 1 ) . '">Parent 1</a> ' . date( 'F j, Y' ) . '</li> |
93 | | <li class="page_item page-item-2 page_item_has_children"><a href="' . get_permalink( 2 ) . '">Parent 2</a> ' . date( 'F j, Y' ) . '</li> |
94 | | <li class="page_item page-item-3 page_item_has_children"><a href="' . get_permalink( 3 ) . '">Parent 3</a> ' . date( 'F j, Y' ) . '</li> |
| 96 | $expected['show_date'] = '<li class="pagenav">Pages<ul><li class="page_item page-item-1 page_item_has_children"><a href="' . get_permalink( 1 ) . '">Parent 1</a> ' . $date . '</li> |
| 97 | <li class="page_item page-item-2 page_item_has_children"><a href="' . get_permalink( 2 ) . '">Parent 2</a> ' . $date . '</li> |
| 98 | <li class="page_item page-item-3 page_item_has_children"><a href="' . get_permalink( 3 ) . '">Parent 3</a> ' . $date . '</li> |
95 | 99 | </ul></li>'; |
96 | 100 | $actual = wp_list_pages( $args ); |
97 | 101 | $this->AssertEquals( $expected['show_date'], $actual ); |
… |
… |
class Tests_List_Pages extends WP_UnitTestCase { |
103 | 107 | 'show_date' => true, |
104 | 108 | 'date_format' => 'l, F j, Y' |
105 | 109 | ); |
106 | | $expected['date_format'] = '<li class="pagenav">Pages<ul><li class="page_item page-item-1 page_item_has_children"><a href="' . get_permalink( 1 ) . '">Parent 1</a> ' . date( 'l, F j, Y' ) . ' |
| 110 | $expected['date_format'] = '<li class="pagenav">Pages<ul><li class="page_item page-item-1 page_item_has_children"><a href="' . get_permalink( 1 ) . '">Parent 1</a> ' . $date . ' |
107 | 111 | <ul class=\'children\'> |
108 | | <li class="page_item page-item-4"><a href="' . get_permalink( 4 ) . '">Child 1</a> ' . date( 'l, F j, Y' ) . '</li> |
109 | | <li class="page_item page-item-5"><a href="' . get_permalink( 5 ) . '">Child 2</a> ' . date( 'l, F j, Y' ) . '</li> |
110 | | <li class="page_item page-item-6"><a href="' . get_permalink( 6 ) . '">Child 3</a> ' . date( 'l, F j, Y' ) . '</li> |
| 112 | <li class="page_item page-item-4"><a href="' . get_permalink( 4 ) . '">Child 1</a> ' . $date . '</li> |
| 113 | <li class="page_item page-item-5"><a href="' . get_permalink( 5 ) . '">Child 2</a> ' . $date . '</li> |
| 114 | <li class="page_item page-item-6"><a href="' . get_permalink( 6 ) . '">Child 3</a> ' . $date . '</li> |
111 | 115 | </ul> |
112 | 116 | </li> |
113 | | <li class="page_item page-item-2 page_item_has_children"><a href="' . get_permalink( 2 ) . '">Parent 2</a> ' . date( 'l, F j, Y' ) . ' |
| 117 | <li class="page_item page-item-2 page_item_has_children"><a href="' . get_permalink( 2 ) . '">Parent 2</a> ' . $date . ' |
114 | 118 | <ul class=\'children\'> |
115 | | <li class="page_item page-item-7"><a href="' . get_permalink( 7 ) . '">Child 1</a> ' . date( 'l, F j, Y' ) . '</li> |
116 | | <li class="page_item page-item-8"><a href="' . get_permalink( 8 ) . '">Child 2</a> ' . date( 'l, F j, Y' ) . '</li> |
117 | | <li class="page_item page-item-9"><a href="' . get_permalink( 9 ) . '">Child 3</a> ' . date( 'l, F j, Y' ) . '</li> |
| 119 | <li class="page_item page-item-7"><a href="' . get_permalink( 7 ) . '">Child 1</a> ' . $date . '</li> |
| 120 | <li class="page_item page-item-8"><a href="' . get_permalink( 8 ) . '">Child 2</a> ' . $date . '</li> |
| 121 | <li class="page_item page-item-9"><a href="' . get_permalink( 9 ) . '">Child 3</a> ' . $date . '</li> |
118 | 122 | </ul> |
119 | 123 | </li> |
120 | | <li class="page_item page-item-3 page_item_has_children"><a href="' . get_permalink( 3 ) . '">Parent 3</a> ' . date( 'l, F j, Y' ) . ' |
| 124 | <li class="page_item page-item-3 page_item_has_children"><a href="' . get_permalink( 3 ) . '">Parent 3</a> ' . $date . ' |
121 | 125 | <ul class=\'children\'> |
122 | | <li class="page_item page-item-10"><a href="' . get_permalink( 10 ) . '">Child 1</a> ' . date( 'l, F j, Y' ) . '</li> |
123 | | <li class="page_item page-item-11"><a href="' . get_permalink( 11 ) . '">Child 2</a> ' . date( 'l, F j, Y' ) . '</li> |
124 | | <li class="page_item page-item-12"><a href="' . get_permalink( 12 ) . '">Child 3</a> ' . date( 'l, F j, Y' ) . '</li> |
| 126 | <li class="page_item page-item-10"><a href="' . get_permalink( 10 ) . '">Child 1</a> ' . $date . '</li> |
| 127 | <li class="page_item page-item-11"><a href="' . get_permalink( 11 ) . '">Child 2</a> ' . $date . '</li> |
| 128 | <li class="page_item page-item-12"><a href="' . get_permalink( 12 ) . '">Child 3</a> ' . $date . '</li> |
125 | 129 | </ul> |
126 | 130 | </li> |
127 | 131 | </ul></li>'; |