Changeset 42343 for trunk/tests/phpunit/tests/post/getPostsByAuthorSql.php
- Timestamp:
- 11/30/2017 11:09:33 PM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/post/getPostsByAuthorSql.php
r36050 r42343 6 6 class Tests_Post_GetPostsByAuthorSql extends WP_UnitTestCase { 7 7 8 public function test_post_type_post() {8 public function test_post_type_post() { 9 9 $maybe_string = get_posts_by_author_sql( 'post' ); 10 10 $this->assertContains( "post_type = 'post'", $maybe_string ); 11 11 } 12 12 13 public function test_post_type_page() {13 public function test_post_type_page() { 14 14 $maybe_string = get_posts_by_author_sql( 'page' ); 15 15 $this->assertContains( "post_type = 'page'", $maybe_string ); 16 16 } 17 17 18 public function test_non_existent_post_type() {18 public function test_non_existent_post_type() { 19 19 $maybe_string = get_posts_by_author_sql( 'non_existent_post_type' ); 20 20 $this->assertContains( '1 = 0', $maybe_string ); 21 21 } 22 22 23 public function test_multiple_post_types() {23 public function test_multiple_post_types() { 24 24 register_post_type( 'foo' ); 25 25 register_post_type( 'bar' ); … … 33 33 } 34 34 35 public function test_full_true() {35 public function test_full_true() { 36 36 $maybe_string = get_posts_by_author_sql( 'post', true ); 37 37 $this->assertRegExp( '/^WHERE /', $maybe_string ); 38 38 } 39 39 40 public function test_full_false() {40 public function test_full_false() { 41 41 $maybe_string = get_posts_by_author_sql( 'post', false ); 42 42 $this->assertNotRegExp( '/^WHERE /', $maybe_string ); 43 43 } 44 44 45 public function test_post_type_clause_should_be_included_when_full_is_true() {45 public function test_post_type_clause_should_be_included_when_full_is_true() { 46 46 $maybe_string = get_posts_by_author_sql( 'post', true ); 47 47 $this->assertContains( "post_type = 'post'", $maybe_string ); 48 48 } 49 49 50 public function test_post_type_clause_should_be_included_when_full_is_false() {50 public function test_post_type_clause_should_be_included_when_full_is_false() { 51 51 $maybe_string = get_posts_by_author_sql( 'post', false ); 52 52 $this->assertContains( "post_type = 'post'", $maybe_string ); 53 53 } 54 54 55 public function test_post_author_should_create_post_author_clause() {56 $maybe_string = get_posts_by_author_sql( 'post', true, 1 55 public function test_post_author_should_create_post_author_clause() { 56 $maybe_string = get_posts_by_author_sql( 'post', true, 1 ); 57 57 $this->assertContains( 'post_author = 1', $maybe_string ); 58 58 } 59 59 60 public function test_public_only_true_should_not_allow_any_private_posts_for_loggedin_user() {60 public function test_public_only_true_should_not_allow_any_private_posts_for_loggedin_user() { 61 61 $current_user = get_current_user_id(); 62 $u = self::factory()->user->create();62 $u = self::factory()->user->create(); 63 63 wp_set_current_user( $u ); 64 64 … … 69 69 } 70 70 71 public function test_public_only_should_default_to_false() {71 public function test_public_only_should_default_to_false() { 72 72 $current_user = get_current_user_id(); 73 $u = self::factory()->user->create();73 $u = self::factory()->user->create(); 74 74 wp_set_current_user( $u ); 75 75 … … 79 79 } 80 80 81 public function test_public_only_false_should_allow_current_user_access_to_own_private_posts_when_current_user_matches_post_author() {81 public function test_public_only_false_should_allow_current_user_access_to_own_private_posts_when_current_user_matches_post_author() { 82 82 $current_user = get_current_user_id(); 83 $u = self::factory()->user->create();83 $u = self::factory()->user->create(); 84 84 wp_set_current_user( $u ); 85 85 … … 90 90 } 91 91 92 public function test_public_only_false_should_not_allow_access_to_private_posts_if_current_user_is_not_post_author() {92 public function test_public_only_false_should_not_allow_access_to_private_posts_if_current_user_is_not_post_author() { 93 93 $current_user = get_current_user_id(); 94 $u1 = self::factory()->user->create();95 $u2 = self::factory()->user->create();94 $u1 = self::factory()->user->create(); 95 $u2 = self::factory()->user->create(); 96 96 wp_set_current_user( $u1 ); 97 97 … … 102 102 } 103 103 104 public function test_public_only_false_should_allow_current_user_access_to_own_private_posts_when_post_author_is_not_provided() {104 public function test_public_only_false_should_allow_current_user_access_to_own_private_posts_when_post_author_is_not_provided() { 105 105 $current_user = get_current_user_id(); 106 $u = self::factory()->user->create();106 $u = self::factory()->user->create(); 107 107 wp_set_current_user( $u ); 108 108 … … 114 114 } 115 115 116 public function test_administrator_should_have_access_to_private_posts_when_public_only_is_false() {116 public function test_administrator_should_have_access_to_private_posts_when_public_only_is_false() { 117 117 $current_user = get_current_user_id(); 118 $u = self::factory()->user->create( array( 'role' => 'administrator' ) );118 $u = self::factory()->user->create( array( 'role' => 'administrator' ) ); 119 119 wp_set_current_user( $u ); 120 120 … … 126 126 } 127 127 128 public function test_user_has_access_only_to_private_posts_for_certain_post_types() {129 register_post_type( 'foo', array( 'capabilities' => array( 'read_private_posts' => 'read_private_foo' ) ) 128 public function test_user_has_access_only_to_private_posts_for_certain_post_types() { 129 register_post_type( 'foo', array( 'capabilities' => array( 'read_private_posts' => 'read_private_foo' ) ) ); 130 130 register_post_type( 'bar', array( 'capabilities' => array( 'read_private_posts' => 'read_private_bar' ) ) ); 131 131 register_post_type( 'baz', array( 'capabilities' => array( 'read_private_posts' => 'read_private_baz' ) ) ); 132 132 $current_user = get_current_user_id(); 133 $u = self::factory()->user->create( array( 'role' => 'editor' ) );134 $editor_role = get_role('editor');133 $u = self::factory()->user->create( array( 'role' => 'editor' ) ); 134 $editor_role = get_role( 'editor' ); 135 135 $editor_role->add_cap( 'read_private_baz' ); 136 136 wp_set_current_user( $u );
Note: See TracChangeset
for help on using the changeset viewer.