| | 1 | <?php |
| | 2 | |
| | 3 | /** |
| | 4 | * @group taxonomy |
| | 5 | * @covers ::get_category_link |
| | 6 | */ |
| | 7 | class Tests_Category_GetCategoryLink extends WP_UnitTestCase { |
| | 8 | public function test_success() { |
| | 9 | $c = self::factory()->category->create(); |
| | 10 | |
| | 11 | $found = get_category_link( $c ); |
| | 12 | $expected = home_url( '?cat=' . $c ); |
| | 13 | |
| | 14 | $this->assertSame( $expected, $found ); |
| | 15 | } |
| | 16 | |
| | 17 | public function test_should_return_link_for_term_from_another_category_on_primed_cache() { |
| | 18 | register_taxonomy( 'wptests_tax', 'post' ); |
| | 19 | |
| | 20 | $t = self::factory()->term->create( array( |
| | 21 | 'taxonomy' => 'wptests_tax', |
| | 22 | 'slug' => 'test-term', |
| | 23 | ) ); |
| | 24 | |
| | 25 | $term = get_term( $t ); |
| | 26 | |
| | 27 | $found = get_category_link( $t ); |
| | 28 | $expected = home_url( '?wptests_tax=test-term' ); |
| | 29 | |
| | 30 | $this->assertSame( $expected, $found ); |
| | 31 | } |
| | 32 | |
| | 33 | public function test_should_return_link_for_term_from_another_category_on_empty_cache() { |
| | 34 | register_taxonomy( 'wptests_tax', 'post' ); |
| | 35 | |
| | 36 | $t = self::factory()->term->create( array( |
| | 37 | 'taxonomy' => 'wptests_tax', |
| | 38 | 'slug' => 'test-term', |
| | 39 | ) ); |
| | 40 | |
| | 41 | clean_term_cache( $t ); |
| | 42 | |
| | 43 | $found = get_category_link( $t ); |
| | 44 | $expected = home_url( '?wptests_tax=test-term' ); |
| | 45 | |
| | 46 | $this->assertSame( $expected, $found ); |
| | 47 | } |
| | 48 | } |