Changeset 7785
- Timestamp:
- 10/04/2026 08:08:18 AM (3 weeks ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/testcases/search/template/search.php
r5754 r7785 11 11 /** 12 12 * @covers ::bbp_has_search_results 13 * @todo Implement test_bbp_has_search_results().14 13 */ 15 14 public function test_bbp_has_search_results() { 16 // Remove the following lines when you implement this test. 17 $this->markTestIncomplete( 18 'This test has not been implemented yet.' 19 ); 15 $topic_id = $this->factory->topic->create( array( 'post_title' => 'UniqueSearchNeedle' ) ); 16 17 $this->assertTrue( bbp_has_search_results( array( 's' => 'UniqueSearchNeedle', 'post_type' => bbp_get_topic_post_type() ) ) ); 18 $this->assertSame( $topic_id, bbpress()->search_query->posts[0]->ID ); 19 $this->assertFalse( bbp_has_search_results( array( 's' => 'NoMatchingSearchNeedle', 'post_type' => bbp_get_topic_post_type() ) ) ); 20 20 } 21 21 22 22 /** 23 23 * @covers ::bbp_search_results 24 * @todo Implement test_bbp_search_results().25 24 */ 26 25 public function test_bbp_search_results() { 27 // Remove the following lines when you implement this test. 28 $this->markTestIncomplete( 29 'This test has not been implemented yet.' 30 ); 26 $this->factory->topic->create( array( 'post_title' => 'UniqueSearchNeedle' ) ); 27 bbp_has_search_results( array( 's' => 'UniqueSearchNeedle', 'post_type' => bbp_get_topic_post_type() ) ); 28 29 $this->assertTrue( bbp_search_results() ); 30 bbp_the_search_result(); 31 $this->assertFalse( bbp_search_results() ); 31 32 } 32 33 33 34 /** 34 35 * @covers ::bbp_the_search_result 35 * @todo Implement test_bbp_the_search_result().36 36 */ 37 37 public function test_bbp_the_search_result() { 38 // Remove the following lines when you implement this test. 39 $this->markTestIncomplete( 40 'This test has not been implemented yet.' 41 ); 38 $topic_id = $this->factory->topic->create( array( 'post_title' => 'UniqueSearchNeedle' ) ); 39 bbp_has_search_results( array( 's' => 'UniqueSearchNeedle', 'post_type' => bbp_get_topic_post_type() ) ); 40 41 $this->assertTrue( bbp_search_results() ); 42 bbp_the_search_result(); 43 $this->assertSame( $topic_id, get_the_ID() ); 44 $this->assertSame( $topic_id, bbpress()->current_topic_id ); 45 $this->assertFalse( bbp_search_results() ); 42 46 } 43 47 … … 45 49 * @covers ::bbp_search_title 46 50 * @covers ::bbp_get_search_title 47 * @todo Implement test_bbp_get_search_title().48 51 */ 49 52 public function test_bbp_get_search_title() { 50 // Remove the following lines when you implement this test. 51 $this->markTestIncomplete( 52 'This test has not been implemented yet.' 53 ); 53 $this->assertSame( 'Search', bbp_get_search_title() ); 54 $filter = static function() { 55 return 'sample query'; 56 }; 57 add_filter( 'bbp_get_search_terms', $filter ); 58 try { 59 $title = bbp_get_search_title(); 60 $this->assertStringContainsString( 'sample query', $title ); 61 $this->expectOutputString( $title ); 62 bbp_search_title(); 63 } finally { 64 remove_filter( 'bbp_get_search_terms', $filter ); 65 } 54 66 } 55 67 … … 57 69 * @covers ::bbp_search_url 58 70 * @covers ::bbp_get_search_url 59 * @todo Implement test_bbp_get_search_url().60 71 */ 61 72 public function test_bbp_get_search_url() { 62 // Remove the following lines when you implement this test. 63 $this->markTestIncomplete( 64 'This test has not been implemented yet.' 65 ); 73 $url = bbp_get_search_url(); 74 75 $this->assertStringContainsString( bbp_get_search_rewrite_id(), $url ); 76 $this->expectOutputString( esc_url( $url ) ); 77 bbp_search_url(); 66 78 } 67 79 … … 69 81 * @covers ::bbp_search_results_url 70 82 * @covers ::bbp_get_search_results_url 71 * @todo Implement test_bbp_get_search_results_url().72 83 */ 73 84 public function test_bbp_get_search_results_url() { 74 // Remove the following lines when you implement this test. 75 $this->markTestIncomplete( 76 'This test has not been implemented yet.' 77 ); 85 $filter = static function() { 86 return 'sample query'; 87 }; 88 add_filter( 'bbp_get_search_terms', $filter ); 89 try { 90 $url = bbp_get_search_results_url(); 91 $this->assertStringContainsString( 'sample', $url ); 92 $this->expectOutputString( esc_url( $url ) ); 93 bbp_search_results_url(); 94 } finally { 95 remove_filter( 'bbp_get_search_terms', $filter ); 96 } 78 97 } 79 98 … … 81 100 * @covers ::bbp_search_terms 82 101 * @covers ::bbp_get_search_terms 83 * @todo Implement test_bbp_get_search_terms().84 102 */ 85 103 public function test_bbp_get_search_terms() { 86 // Remove the following lines when you implement this test.87 $this-> markTestIncomplete(88 'This test has not been implemented yet.'89 );104 $this->assertFalse( bbp_get_search_terms() ); 105 $this->assertSame( 'sample-query', bbp_get_search_terms( 'Sample Query' ) ); 106 $this->expectOutputString( 'sample-query' ); 107 bbp_search_terms( 'Sample Query' ); 90 108 } 91 109 … … 93 111 * @covers ::bbp_search_pagination_count 94 112 * @covers ::bbp_get_search_pagination_count 95 * @todo Implement test_bbp_get_search_pagination_count().96 113 */ 97 114 public function test_bbp_get_search_pagination_count() { 98 // Remove the following lines when you implement this test. 99 $this->markTestIncomplete( 100 'This test has not been implemented yet.' 101 ); 115 $this->factory->topic->create_many( 2, array( 'post_title' => 'SearchPageNeedle' ) ); 116 bbp_has_search_results( array( 117 's' => 'SearchPageNeedle', 118 'post_type' => bbp_get_topic_post_type(), 119 'posts_per_page' => 1, 120 ) ); 121 $count = bbp_get_search_pagination_count(); 122 123 $this->assertStringContainsString( 'Viewing', $count ); 124 $this->assertStringContainsString( '2 total', $count ); 125 $this->expectOutputString( $count ); 126 bbp_search_pagination_count(); 102 127 } 103 128 … … 105 130 * @covers ::bbp_search_pagination_links 106 131 * @covers ::bbp_get_search_pagination_links 107 * @todo Implement test_bbp_get_search_pagination_links().108 132 */ 109 133 public function test_bbp_get_search_pagination_links() { 110 // Remove the following lines when you implement this test. 111 $this->markTestIncomplete( 112 'This test has not been implemented yet.' 113 ); 134 $this->factory->topic->create_many( 2, array( 'post_title' => 'SearchPageNeedle' ) ); 135 bbp_has_search_results( array( 136 's' => 'SearchPageNeedle', 137 'post_type' => bbp_get_topic_post_type(), 138 'posts_per_page' => 1, 139 ) ); 140 $links = bbp_get_search_pagination_links(); 141 142 $this->assertNotEmpty( $links ); 143 $this->assertStringContainsString( 'page-numbers', $links ); 144 $this->expectOutputString( $links ); 145 bbp_search_pagination_links(); 114 146 } 115 147 }
Note:
See TracChangeset
for help on using the changeset viewer.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)