Changeset 878 in tests
- Timestamp:
- 07/03/2012 07:14:58 PM (13 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/phpunit.xml
r875 r878 9 9 <directory suffix=".php">tests</directory> 10 10 <file phpVersion="5.3.0">tests/test_actions_closures.php</file> 11 <exclude>tests/test_query_results.php</exclude>12 11 </testsuite> 13 12 </testsuites> -
trunk/tests/test_query_results.php
r828 r878 4 4 // We're testing against a known data set, so we can check that specific posts are included in the output. 5 5 6 class TestWPQueryPosts extends _WPDataset1 { 6 class TestWPQueryPosts extends WP_UnitTestCase { 7 protected $q; 8 7 9 function setUp() { 8 10 parent::setUp(); 11 12 $cat_a = $this->factory->term->create( array( 'taxonomy' => 'category', 'name' => 'cat-a' ) ); 13 $cat_b = $this->factory->term->create( array( 'taxonomy' => 'category', 'name' => 'cat-b' ) ); 14 $cat_c = $this->factory->term->create( array( 'taxonomy' => 'category', 'name' => 'cat-c' ) ); 15 16 $this->factory->post->create( array( 'post_title' => 'cats-a-b-c', 'post_date' => '2008-12-01 00:00:00', 'post_category' => array( $cat_a, $cat_b, $cat_c ) ) ); 17 $this->factory->post->create( array( 'post_title' => 'cats-a-and-b', 'post_date' => '2009-01-01 00:00:00', 'post_category' => array( $cat_a, $cat_b ) ) ); 18 $this->factory->post->create( array( 'post_title' => 'cats-b-and-c', 'post_date' => '2009-02-01 00:00:00', 'post_category' => array( $cat_b, $cat_c ) ) ); 19 $this->factory->post->create( array( 'post_title' => 'cats-a-and-c', 'post_date' => '2009-03-01 00:00:00', 'post_category' => array( $cat_a, $cat_c ) ) ); 20 $this->factory->post->create( array( 'post_title' => 'cat-a', 'post_date' => '2009-04-01 00:00:00', 'post_category' => array( $cat_a ) ) ); 21 $this->factory->post->create( array( 'post_title' => 'cat-b', 'post_date' => '2009-05-01 00:00:00', 'post_category' => array( $cat_b ) ) ); 22 $this->factory->post->create( array( 'post_title' => 'cat-c', 'post_date' => '2009-06-01 00:00:00', 'post_category' => array( $cat_c ) ) ); 23 $this->factory->post->create( array( 'post_title' => 'lorem-ipsum', 'post_date' => '2009-07-01 00:00:00' ) ); 24 $this->factory->post->create( array( 'post_title' => 'comment-test', 'post_date' => '2009-08-01 00:00:00' ) ); 25 $this->factory->post->create( array( 'post_title' => 'one-trackback', 'post_date' => '2009-09-01 00:00:00' ) ); 26 $this->factory->post->create( array( 'post_title' => 'many-trackbacks', 'post_date' => '2009-10-01 00:00:00' ) ); 27 $this->factory->post->create( array( 'post_title' => 'no-comments', 'post_date' => '2009-10-01 00:00:00' ) ); 28 $this->factory->post->create( array( 'post_title' => 'one-comment', 'post_date' => '2009-11-01 00:00:00' ) ); 29 $this->factory->post->create( array( 'post_title' => 'contributor-post-approved', 'post_date' => '2009-12-01 00:00:00' ) ); 30 $this->factory->post->create( array( 'post_title' => 'embedded-video', 'post_date' => '2010-01-01 00:00:00' ) ); 31 $this->factory->post->create( array( 'post_title' => 'simple-markup-test', 'post_date' => '2010-02-01 00:00:00' ) ); 32 $this->factory->post->create( array( 'post_title' => 'raw-html-code', 'post_date' => '2010-03-01 00:00:00' ) ); 33 $this->factory->post->create( array( 'post_title' => 'tags-a-b-c', 'tags_input' => array( 'tag-a', 'tag-b', 'tag-c' ), 'post_date' => '2010-04-01 00:00:00' ) ); 34 $this->factory->post->create( array( 'post_title' => 'tag-a', 'tags_input' => array( 'tag-a' ), 'post_date' => '2010-05-01 00:00:00' ) ); 35 $this->factory->post->create( array( 'post_title' => 'tag-b', 'tags_input' => array( 'tag-b' ), 'post_date' => '2010-06-01 00:00:00' ) ); 36 $this->factory->post->create( array( 'post_title' => 'tag-c', 'tags_input' => array( 'tag-c' ), 'post_date' => '2010-07-01 00:00:00' ) ); 37 $this->factory->post->create( array( 'post_title' => 'tags-a-and-b', 'tags_input' => array( 'tag-a', 'tag-b' ), 'post_date' => '2010-08-01 00:00:00' ) ); 38 $this->factory->post->create( array( 'post_title' => 'tags-b-and-c', 'tags_input' => array( 'tag-b', 'tag-c' ), 'post_date' => '2010-09-01 00:00:00' ) ); 39 $this->factory->post->create( array( 'post_title' => 'tags-a-and-c', 'tags_input' => array( 'tag-a', 'tag-c' ), 'post_date' => '2010-10-01 00:00:00' ) ); 40 41 unset( $this->q ); 9 42 $this->q = new WP_Query(); 10 }11 12 function tearDown() {13 parent::tearDown();14 unset($this->q);15 }16 17 function post_slugs($posts) {18 $out = array();19 foreach ($posts as $post)20 $out[] = $post->post_name;21 return $out;22 43 } 23 44 … … 26 47 27 48 // the output should be the most recent 10 posts as listed here 28 $expected = array 49 $expected = array( 29 50 0 => 'tags-a-and-c', 30 51 1 => 'tags-b-and-c', … … 39 60 ); 40 61 41 $this->assertEquals( $expected, $this->post_slugs($posts) );62 $this->assertEquals( $expected, wp_list_pluck( $posts, 'post_name' ) ); 42 63 } 43 64 … … 46 67 47 68 // there are 4 posts with Tag A 48 $this->assert Equals( 4, count($posts));69 $this->assertCount( 4, $posts ); 49 70 $this->assertEquals( 'tags-a-and-c', $posts[0]->post_name ); 50 71 $this->assertEquals( 'tags-a-and-b', $posts[1]->post_name ); … … 57 78 58 79 // there are 4 posts with Tag A 59 $this->assert Equals( 4, count($posts));80 $this->assertCount( 4, $posts ); 60 81 $this->assertEquals( 'tags-b-and-c', $posts[0]->post_name ); 61 82 $this->assertEquals( 'tags-a-and-b', $posts[1]->post_name ); … … 69 90 70 91 // there are 4 posts with Tag A 71 $this->assert Equals( 4, count($posts));92 $this->assertCount( 4, $posts ); 72 93 $this->assertEquals( 'tags-a-and-c', $posts[0]->post_name ); 73 94 $this->assertEquals( 'tags-a-and-b', $posts[1]->post_name ); … … 80 101 81 102 // there are 4 posts with either Tag B or Tag C 82 $this->assert Equals( 6, count($posts));103 $this->assertCount( 6, $posts ); 83 104 $this->assertEquals( 'tags-a-and-c', $posts[0]->post_name ); 84 105 $this->assertEquals( 'tags-b-and-c', $posts[1]->post_name ); … … 96 117 97 118 // there are 6 posts with either Tag A or Tag B 98 $this->assert Equals( 6, count($posts));119 $this->assertCount( 6, $posts ); 99 120 $this->assertEquals( 'tags-a-and-c', $posts[0]->post_name ); 100 121 $this->assertEquals( 'tags-b-and-c', $posts[1]->post_name ); … … 124 145 ); 125 146 126 $this->assertEquals( $expected, $this->post_slugs($posts) );147 $this->assertEquals( $expected, wp_list_pluck( $posts, 'post_name' ) ); 127 148 } 128 149 … … 133 154 134 155 // there are 4 posts with Tag A, only 2 when we exclude Tag B 135 $this->assert Equals( 2, count($posts));156 $this->assertCount( 2, $posts ); 136 157 $this->assertEquals( 'tags-a-and-c', $posts[0]->post_name ); 137 158 $this->assertEquals( 'tag-a', $posts[1]->post_name ); … … 144 165 145 166 // there are 4 posts with Cat A, we'll check for them by name 146 $this->assert Equals( 4, count($posts));167 $this->assertCount( 4, $posts ); 147 168 $this->assertEquals( 'cat-a', $posts[0]->post_name ); 148 169 $this->assertEquals( 'cats-a-and-c', $posts[1]->post_name ); … … 156 177 157 178 // there are 4 posts with Cat B 158 $this->assert Equals( 4, count($posts));179 $this->assertCount( 4, $posts ); 159 180 $this->assertEquals( 'cat-b', $posts[0]->post_name ); 160 181 $this->assertEquals( 'cats-b-and-c', $posts[1]->post_name ); … … 174 195 ); 175 196 176 $this->assert Equals( 5, count($posts));177 $this->assertEquals( $expected, $this->post_slugs($posts) );197 $this->assertCount( 5, $posts ); 198 $this->assertEquals( $expected, wp_list_pluck( $posts, 'post_name' ) ); 178 199 } 179 200 … … 194 215 ); 195 216 196 $this->assert Equals( 10, count($posts));197 $this->assertEquals( $expected, $this->post_slugs($posts) );217 $this->assertCount( 10, $posts ); 218 $this->assertEquals( $expected, wp_list_pluck( $posts, 'post_name' ) ); 198 219 } 199 220 … … 214 235 ); 215 236 216 $this->assert Equals( 10, count($posts));237 $this->assertCount( 10, $posts ); 217 238 $this->assertTrue( $this->q->is_paged() ); 218 $this->assertEquals( $expected, $this->post_slugs($posts) );239 $this->assertEquals( $expected, wp_list_pluck( $posts, 'post_name' ) ); 219 240 } 220 241 … … 229 250 ); 230 251 231 $this->assert Equals( 4, count($posts));252 $this->assertCount( 4, $posts ); 232 253 $this->assertTrue( $this->q->is_paged() ); 233 $this->assertEquals( $expected, $this->post_slugs($posts) );254 $this->assertEquals( $expected, wp_list_pluck( $posts, 'post_name' ) ); 234 255 } 235 256 … … 252 273 ); 253 274 254 $this->assert Equals( 10, count($posts));275 $this->assertCount( 10, $posts ); 255 276 $this->assertTrue( $this->q->is_paged() ); 256 $this->assertEquals( $expected, $this->post_slugs($posts) );277 $this->assertEquals( $expected, wp_list_pluck( $posts, 'post_name' ) ); 257 278 } 258 279
Note: See TracChangeset
for help on using the changeset viewer.