- Timestamp:
- 02/07/2023 08:53:01 AM (22 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/rest-api/rest-posts-controller.php
r55104 r55248 205 205 'per_page', 206 206 'search', 207 'search_columns', 207 208 'slug', 208 209 'status', … … 1526 1527 1527 1528 $this->assertPostsWhere( " AND {posts}.ID NOT IN ($id3) AND {posts}.post_type = 'post' AND (({posts}.post_status = 'publish'))" ); 1529 } 1530 1531 /** 1532 * Tests that Rest Post controller supports search columns. 1533 * 1534 * @ticket 43867 1535 * @covers WP_REST_Posts_Controller::get_items 1536 */ 1537 public function test_get_items_with_custom_search_columns() { 1538 $id1 = self::factory()->post->create( 1539 array( 1540 'post_title' => 'Title contain foo and bar', 1541 'post_content' => 'Content contain bar', 1542 'post_excerpt' => 'Excerpt contain baz', 1543 ) 1544 ); 1545 $id2 = self::factory()->post->create( 1546 array( 1547 'post_title' => 'Title contain baz', 1548 'post_content' => 'Content contain foo and bar', 1549 'post_excerpt' => 'Excerpt contain foo, bar and baz', 1550 ) 1551 ); 1552 1553 $request = new WP_REST_Request( 'GET', '/wp/v2/posts' ); 1554 $request->set_param( 'search', 'foo bar' ); 1555 $request->set_param( 'search_columns', array( 'post_title' ) ); 1556 $response = rest_get_server()->dispatch( $request ); 1557 $this->assertSame( 200, $response->get_status(), 'Response should have a status code 200.' ); 1558 $data = $response->get_data(); 1559 $this->assertCount( 1, $data, 'Response should contain one result.' ); 1560 $this->assertSame( $id1, $data[0]['id'], 'Result should match expected value.' ); 1528 1561 } 1529 1562
Note: See TracChangeset
for help on using the changeset viewer.