| 881 | * @ticket 36624 |
| 882 | */ |
| 883 | public function test_nicename_returns_user_with_nicename() { |
| 884 | wp_update_user( array( |
| 885 | 'ID' => self::$author_ids[0], |
| 886 | 'user_nicename' => 'peter' |
| 887 | ) ); |
| 888 | |
| 889 | $q = new WP_User_Query( array ( |
| 890 | 'nicename' => 'peter' |
| 891 | ) ); |
| 892 | |
| 893 | $found = wp_list_pluck( $q->get_results(), 'ID' ); |
| 894 | $expected = array( self::$author_ids[0] ); |
| 895 | |
| 896 | $this->assertContains( "AND user_nicename = 'peter'", $q->query_where); |
| 897 | $this->assertEqualSets( $expected, $found); |
| 898 | } |
| 899 | |
| 900 | /** |
| 901 | * @ticket 36624 |
| 902 | */ |
| 903 | public function test_nicename__in_returns_users_with_included_nicenames() { |
| 904 | wp_update_user( array( |
| 905 | 'ID' => self::$author_ids[0], |
| 906 | 'user_nicename' => 'peter' |
| 907 | ) ); |
| 908 | |
| 909 | wp_update_user( array( |
| 910 | 'ID' => self::$author_ids[1], |
| 911 | 'user_nicename' => 'paul' |
| 912 | ) ); |
| 913 | |
| 914 | wp_update_user( array( |
| 915 | 'ID' => self::$author_ids[2], |
| 916 | 'user_nicename' => 'mary' |
| 917 | ) ); |
| 918 | |
| 919 | $q = new WP_User_Query( array ( |
| 920 | 'nicename__in' => array( 'peter', 'paul', 'mary' ) |
| 921 | ) ); |
| 922 | |
| 923 | $found = wp_list_pluck( $q->get_results(), 'ID' ); |
| 924 | $expected = array( self::$author_ids[0], self::$author_ids[1], self::$author_ids[2] ); |
| 925 | |
| 926 | $this->assertContains( "AND user_nicename IN ( 'peter','paul','mary' )", $q->query_where); |
| 927 | $this->assertEqualSets( $expected, $found ); |
| 928 | } |
| 929 | |
| 930 | /** |
| 931 | * @ticket 36624 |
| 932 | */ |
| 933 | public function test_nicename__not_in_returns_users_without_included_nicenames() { |
| 934 | wp_update_user( array( |
| 935 | 'ID' => self::$author_ids[0], |
| 936 | 'user_nicename' => 'peter' |
| 937 | ) ); |
| 938 | |
| 939 | wp_update_user( array( |
| 940 | 'ID' => self::$author_ids[1], |
| 941 | 'user_nicename' => 'paul' |
| 942 | ) ); |
| 943 | |
| 944 | wp_update_user( array( |
| 945 | 'ID' => self::$author_ids[2], |
| 946 | 'user_nicename' => 'mary' |
| 947 | ) ); |
| 948 | |
| 949 | $q = new WP_User_Query( array ( |
| 950 | 'nicename__not_in' => array( 'peter', 'paul', 'mary' ) |
| 951 | ) ); |
| 952 | |
| 953 | $foundCount = count($q->get_results()); |
| 954 | $expectedCount = 10; // 13 total users minus 3 from query |
| 955 | |
| 956 | $this->assertContains( "AND user_nicename NOT IN ( 'peter','paul','mary' )", $q->query_where); |
| 957 | $this->assertEquals( $expectedCount, $foundCount ); |
| 958 | } |
| 959 | |
| 960 | /** |
| 961 | * @ticket 36624 |
| 962 | */ |
| 963 | public function test_orderby_nicename__in() { |
| 964 | wp_update_user( array( |
| 965 | 'ID' => self::$author_ids[0], |
| 966 | 'user_nicename' => 'peter' |
| 967 | ) ); |
| 968 | |
| 969 | wp_update_user( array( |
| 970 | 'ID' => self::$author_ids[1], |
| 971 | 'user_nicename' => 'paul' |
| 972 | ) ); |
| 973 | |
| 974 | wp_update_user( array( |
| 975 | 'ID' => self::$author_ids[2], |
| 976 | 'user_nicename' => 'mary' |
| 977 | ) ); |
| 978 | |
| 979 | $q = new WP_User_Query( array ( |
| 980 | 'nicename__in' => array( 'mary', 'peter', 'paul' ), |
| 981 | 'orderby' => 'nicename__in' |
| 982 | ) ); |
| 983 | |
| 984 | $found = wp_list_pluck( $q->get_results(), 'ID' ); |
| 985 | $expected = array( self::$author_ids[2], self::$author_ids[0], self::$author_ids[1] ); |
| 986 | |
| 987 | $this->assertContains( "FIELD( user_nicename, 'mary','peter','paul' )", $q->query_orderby); |
| 988 | $this->assertSame( $expected, $found ); |
| 989 | } |
| 990 | |
| 991 | /** |
| 992 | * @ticket 36624 |
| 993 | */ |
| 994 | public function test_login_returns_user_with_login() { |
| 995 | |
| 996 | $user_login = get_userdata( self::$author_ids[0] )->user_login; |
| 997 | |
| 998 | $q = new WP_User_Query( array ( |
| 999 | 'login' => $user_login |
| 1000 | ) ); |
| 1001 | |
| 1002 | $found = wp_list_pluck( $q->get_results(), 'ID' ); |
| 1003 | $expected = array( self::$author_ids[0] ); |
| 1004 | |
| 1005 | $this->assertContains( "AND user_login = '$user_login'", $q->query_where); |
| 1006 | $this->assertEqualSets( $expected, $found); |
| 1007 | } |
| 1008 | |
| 1009 | /** |
| 1010 | * @ticket 36624 |
| 1011 | */ |
| 1012 | public function test_login__in_returns_users_with_included_logins() { |
| 1013 | $user_login1 = get_userdata( self::$author_ids[0] )->user_login; |
| 1014 | $user_login2 = get_userdata( self::$author_ids[1] )->user_login; |
| 1015 | $user_login3 = get_userdata( self::$author_ids[2] )->user_login; |
| 1016 | |
| 1017 | $q = new WP_User_Query( array ( |
| 1018 | 'login__in' => array( $user_login1, $user_login2, $user_login3 ) |
| 1019 | ) ); |
| 1020 | |
| 1021 | $found = wp_list_pluck( $q->get_results(), 'ID' ); |
| 1022 | $expected = array( self::$author_ids[0], self::$author_ids[1], self::$author_ids[2] ); |
| 1023 | |
| 1024 | $this->assertContains( "AND user_login IN ( '$user_login1','$user_login2','$user_login3' )", $q->query_where); |
| 1025 | $this->assertEqualSets( $expected, $found ); |
| 1026 | } |
| 1027 | |
| 1028 | /** |
| 1029 | * @ticket 36624 |
| 1030 | */ |
| 1031 | public function test_login__not_in_returns_users_without_included_logins() { |
| 1032 | $user_login1 = get_userdata( self::$author_ids[0] )->user_login; |
| 1033 | $user_login2 = get_userdata( self::$author_ids[1] )->user_login; |
| 1034 | $user_login3 = get_userdata( self::$author_ids[2] )->user_login; |
| 1035 | |
| 1036 | $q = new WP_User_Query( array ( |
| 1037 | 'login__not_in' => array( $user_login1, $user_login2, $user_login3 ) |
| 1038 | ) ); |
| 1039 | |
| 1040 | $foundCount = count($q->get_results()); |
| 1041 | $expectedCount = 10; // 13 total users minus 3 from query |
| 1042 | |
| 1043 | $this->assertContains( "AND user_login NOT IN ( '$user_login1','$user_login2','$user_login3' )", $q->query_where); |
| 1044 | $this->assertEquals( $expectedCount, $foundCount ); |
| 1045 | } |
| 1046 | |
| 1047 | /** |
| 1048 | * @ticket 36624 |
| 1049 | */ |
| 1050 | public function test_orderby_login__in() { |
| 1051 | $user_login1 = get_userdata( self::$author_ids[0] )->user_login; |
| 1052 | $user_login2 = get_userdata( self::$author_ids[1] )->user_login; |
| 1053 | $user_login3 = get_userdata( self::$author_ids[2] )->user_login; |
| 1054 | |
| 1055 | $q = new WP_User_Query( array ( |
| 1056 | 'login__in' => array( $user_login2, $user_login3, $user_login1 ), |
| 1057 | 'orderby' => 'login__in' |
| 1058 | ) ); |
| 1059 | |
| 1060 | $found = wp_list_pluck( $q->get_results(), 'ID' ); |
| 1061 | $expected = array( self::$author_ids[1], self::$author_ids[2], self::$author_ids[0] ); |
| 1062 | |
| 1063 | $this->assertContains( "FIELD( user_login, '$user_login2','$user_login3','$user_login1' )", $q->query_orderby); |
| 1064 | $this->assertSame( $expected, $found ); |
| 1065 | } |
| 1066 | |
| 1067 | /** |