|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Tests util file. |
| 4 | + * |
| 5 | + * @package WordPress_Custom_Fields_Permalink |
| 6 | + */ |
| 7 | + |
| 8 | +/** |
| 9 | + * Class NavigationAsserter contains utility methods to assert conditions related to navigation. |
| 10 | + */ |
| 11 | +class NavigationAsserter { |
| 12 | + |
| 13 | + /** |
| 14 | + * Parent unit test case. |
| 15 | + * |
| 16 | + * @var WP_UnitTestCase |
| 17 | + */ |
| 18 | + private $unit_test_case; |
| 19 | + |
| 20 | + /** |
| 21 | + * NavigationAsserter constructor. |
| 22 | + * |
| 23 | + * @param WP_UnitTestCase $unit_test_case Parent unit test case. |
| 24 | + */ |
| 25 | + public function __construct( WP_UnitTestCase $unit_test_case ) { |
| 26 | + $this->unit_test_case = $unit_test_case; |
| 27 | + } |
| 28 | + |
| 29 | + /** |
| 30 | + * Checks if post is displayed |
| 31 | + * |
| 32 | + * @param WP_Post|int $post The post or id. |
| 33 | + * |
| 34 | + * @return NavigationAsserter Fluent interface. |
| 35 | + */ |
| 36 | + public function then_displayed_post( $post ) { |
| 37 | + $this->unit_test_case->assertTrue( is_single( $post ) ); |
| 38 | + return $this; |
| 39 | + } |
| 40 | + |
| 41 | + /** |
| 42 | + * Checks if post is not displayed |
| 43 | + * |
| 44 | + * @param WP_Post|int $post The post or id. |
| 45 | + * |
| 46 | + * @return NavigationAsserter Fluent interface. |
| 47 | + */ |
| 48 | + public function then_not_displayed_post( $post ) { |
| 49 | + $this->unit_test_case->assertFalse( is_single( $post ) ); |
| 50 | + return $this; |
| 51 | + } |
| 52 | + |
| 53 | + /** |
| 54 | + * Checks if page is displayed |
| 55 | + * |
| 56 | + * @param WP_Post|int $post The post or id. |
| 57 | + * |
| 58 | + * @return NavigationAsserter Fluent interface. |
| 59 | + */ |
| 60 | + public function then_displayed_page( $post ) { |
| 61 | + $this->unit_test_case->assertTrue( is_page( $post ) ); |
| 62 | + return $this; |
| 63 | + } |
| 64 | + |
| 65 | + /** |
| 66 | + * Checks if page is not displayed |
| 67 | + * |
| 68 | + * @param WP_Post|int $post The post or id. |
| 69 | + * |
| 70 | + * @return NavigationAsserter Fluent interface. |
| 71 | + */ |
| 72 | + public function then_not_displayed_page( $post ) { |
| 73 | + $this->unit_test_case->assertFalse( is_page( $post ) ); |
| 74 | + return $this; |
| 75 | + } |
| 76 | + |
| 77 | + /** |
| 78 | + * Checks if 404 page is reached |
| 79 | + * |
| 80 | + * @return NavigationAsserter Fluent interface. |
| 81 | + */ |
| 82 | + public function then_is_404() { |
| 83 | + $this->unit_test_case->assertTrue( is_404() ); |
| 84 | + return $this; |
| 85 | + } |
| 86 | + |
| 87 | + /** |
| 88 | + * Fluent interface. |
| 89 | + * |
| 90 | + * @return NavigationAsserter Fluent interface. |
| 91 | + */ |
| 92 | + public function and_also() { |
| 93 | + return $this; |
| 94 | + } |
| 95 | + |
| 96 | +} |
0 commit comments