|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Tests case. |
| 4 | + * |
| 5 | + * @package WordPress_Custom_Fields_Permalink |
| 6 | + */ |
| 7 | + |
| 8 | +/** |
| 9 | + * Class CustomPostTypeWithMetaKey |
| 10 | + */ |
| 11 | +class CustomPostTypeWithMetaKey extends BaseTestCase { |
| 12 | + |
| 13 | + /** |
| 14 | + * Test case. |
| 15 | + */ |
| 16 | + function test_generates_permalink_to_post_using_meta_key() { |
| 17 | + // given. |
| 18 | + $this->permalink_steps->given_permalink_structure( '/%field_some_meta_key%/%postname%/' ); |
| 19 | + |
| 20 | + $this->custom_post_type_steps->given_custom_post_type( 'custom_post_type' ) |
| 21 | + ->with_rewrite_slug( 'custom/%field_some_meta_key%' ) |
| 22 | + ->end(); |
| 23 | + |
| 24 | + $post_params = array( |
| 25 | + 'post_title' => 'Some post title', |
| 26 | + 'post_type' => 'custom_post_type', |
| 27 | + 'meta_input' => array( |
| 28 | + 'some_meta_key' => 'Some meta value', |
| 29 | + 'some_other_meta_key' => 'Some other meta value', |
| 30 | + ), |
| 31 | + ); |
| 32 | + $created_post_id = $this->factory()->post->create( $post_params ); |
| 33 | + |
| 34 | + // when & then. |
| 35 | + $this->permalink_asserter->has_permalink( $created_post_id, '/custom/some-meta-value/some-post-title/' ); |
| 36 | + } |
| 37 | + |
| 38 | + /** |
| 39 | + * Test case. |
| 40 | + */ |
| 41 | + function test_go_to_post_using_meta_key_permalink_structure() { |
| 42 | + // given. |
| 43 | + $this->permalink_steps->given_permalink_structure( '/%field_some_meta_key%/%postname%/' ); |
| 44 | + |
| 45 | + $this->custom_post_type_steps->given_custom_post_type( 'custom_post_type' ) |
| 46 | + ->with_rewrite_slug( 'custom/%field_some_meta_key%' ) |
| 47 | + ->end(); |
| 48 | + |
| 49 | + $post_params = array( |
| 50 | + 'post_title' => 'Some post title', |
| 51 | + 'post_type' => 'custom_post_type', |
| 52 | + 'meta_input' => array( |
| 53 | + 'some_meta_key' => 'Some meta value', |
| 54 | + 'some_other_meta_key' => 'Some other meta value', |
| 55 | + ), |
| 56 | + ); |
| 57 | + $created_post_id = $this->factory()->post->create( $post_params ); |
| 58 | + |
| 59 | + // when. |
| 60 | + $this->go_to( '/custom/some-meta-value/some-post-title/' ); |
| 61 | + |
| 62 | + // then. |
| 63 | + $this->navigation_asserter->then_displayed_post( $created_post_id ); |
| 64 | + } |
| 65 | + |
| 66 | + /** |
| 67 | + * Test case. |
| 68 | + */ |
| 69 | + function test_not_go_to_the_post_when_invalid_value_of_meta_key_part_in_url() { |
| 70 | + // given. |
| 71 | + $this->permalink_steps->given_permalink_structure( '/%field_some_meta_key%/%postname%/' ); |
| 72 | + |
| 73 | + $this->custom_post_type_steps->given_custom_post_type( 'custom_post_type' ) |
| 74 | + ->with_rewrite_slug( '%field_some_meta_key%' ) |
| 75 | + ->end(); |
| 76 | + |
| 77 | + $post_params = array( |
| 78 | + 'post_title' => 'Some post title', |
| 79 | + 'post_type' => 'custom_post_type', |
| 80 | + 'meta_input' => array( |
| 81 | + 'some_meta_key' => 'Some meta value', |
| 82 | + ), |
| 83 | + ); |
| 84 | + $created_post_id = $this->factory()->post->create( $post_params ); |
| 85 | + |
| 86 | + // when. |
| 87 | + $this->go_to( '/custom/some-different-meta-value/some-post-title/' ); |
| 88 | + |
| 89 | + // then. |
| 90 | + $this->navigation_asserter->then_not_displayed_post( $created_post_id ); |
| 91 | + } |
| 92 | +} |
0 commit comments