|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Tests case. |
| 4 | + * |
| 5 | + * @package WordPress_Custom_Fields_Permalink |
| 6 | + */ |
| 7 | + |
| 8 | +namespace CustomFieldsPermalink\Tests\Integration\MetaKeyPermalinkStructure; |
| 9 | + |
| 10 | +use BaseTestCase; |
| 11 | + |
| 12 | +/** |
| 13 | + * Class PrivatePostWithMetaKey |
| 14 | + */ |
| 15 | +class PrivatePostWithMetaKey extends BaseTestCase { |
| 16 | + |
| 17 | + /** |
| 18 | + * Test case. |
| 19 | + */ |
| 20 | + function test_generates_permalink_to_private_post() { |
| 21 | + // given. |
| 22 | + $this->permalink_steps->given_permalink_structure( '/%field_some_meta_key%/%postname%/' ); |
| 23 | + |
| 24 | + $post_params = array( |
| 25 | + 'post_title' => 'Some post title', |
| 26 | + 'post_status' => 'private', |
| 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, '/some-meta-value/some-post-title/' ); |
| 36 | + } |
| 37 | + |
| 38 | + /** |
| 39 | + * Test case. |
| 40 | + */ |
| 41 | + function test_not_go_to_private_post_using_meta_key_permalink_structure_as_anonymous_user() { |
| 42 | + // given. |
| 43 | + $this->permalink_steps->given_permalink_structure( '/%field_some_meta_key%/%postname%/' ); |
| 44 | + |
| 45 | + $post_params = array( |
| 46 | + 'post_title' => 'Some post title', |
| 47 | + 'post_status' => 'private', |
| 48 | + 'meta_input' => array( |
| 49 | + 'some_meta_key' => 'Some meta value', |
| 50 | + 'some_other_meta_key' => 'Some other meta value', |
| 51 | + ), |
| 52 | + ); |
| 53 | + $created_post_id = $this->factory()->post->create( $post_params ); |
| 54 | + |
| 55 | + // when. |
| 56 | + $this->go_to( '/some-meta-value/some-post-title/' ); |
| 57 | + |
| 58 | + // then. |
| 59 | + $this->navigation_asserter->then_not_displayed_post( $created_post_id ) |
| 60 | + ->and_also() |
| 61 | + ->then_is_404(); |
| 62 | + } |
| 63 | + |
| 64 | + /** |
| 65 | + * Test case. |
| 66 | + */ |
| 67 | + function test_go_to_private_post_using_meta_key_permalink_structure_as_admin_user() { |
| 68 | + // given. |
| 69 | + $this->auth_steps->given_logged_as_admin(); |
| 70 | + $this->permalink_steps->given_permalink_structure( '/%field_some_meta_key%/%postname%/' ); |
| 71 | + |
| 72 | + $post_params = array( |
| 73 | + 'post_title' => 'Some post title', |
| 74 | + 'post_status' => 'private', |
| 75 | + 'meta_input' => array( |
| 76 | + 'some_meta_key' => 'Some meta value', |
| 77 | + 'some_other_meta_key' => 'Some other meta value', |
| 78 | + ), |
| 79 | + ); |
| 80 | + $created_post_id = $this->factory()->post->create( $post_params ); |
| 81 | + |
| 82 | + // when. |
| 83 | + $this->go_to( '/some-meta-value/some-post-title/' ); |
| 84 | + |
| 85 | + // then. |
| 86 | + $this->navigation_asserter->then_displayed_post( $created_post_id ); |
| 87 | + } |
| 88 | +} |
0 commit comments