Changeset 46188 for trunk/tests/phpunit/tests/query/metaQuery.php
- Timestamp:
- 09/19/2019 03:02:20 PM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/query/metaQuery.php
r43571 r46188 1923 1923 1924 1924 } 1925 1926 /** 1927 * @ticket 43446 1928 */ 1929 public function test_compare_key_not_equals() { 1930 $posts = self::factory()->post->create_many( 3 ); 1931 1932 add_post_meta( $posts[0], 'aaa_foo_aaa', 'abc' ); 1933 add_post_meta( $posts[1], 'aaa_bar_aaa', 'abc' ); 1934 add_post_meta( $posts[2], 'aaa_foo_bbb', 'abc' ); 1935 add_post_meta( $posts[2], 'aaa_foo_ccc', 'abc' ); 1936 1937 $q = new WP_Query( 1938 array( 1939 'meta_query' => array( 1940 array( 1941 'compare_key' => '!=', 1942 'key' => 'aaa_foo_bbb', 1943 'value' => 'abc', 1944 ), 1945 ), 1946 'fields' => 'ids', 1947 ) 1948 ); 1949 1950 $this->assertEqualSets( array( $posts[0], $posts[1] ), $q->posts ); 1951 } 1952 1953 /** 1954 * @ticket 43446 1955 */ 1956 public function test_compare_key_not_like() { 1957 $posts = self::factory()->post->create_many( 3 ); 1958 1959 add_post_meta( $posts[0], 'aaa_foo_aaa', 'abc' ); 1960 add_post_meta( $posts[1], 'aaa_bar_aaa', 'abc' ); 1961 add_post_meta( $posts[1], 'aaa_bar_ccc', 'abc' ); 1962 add_post_meta( $posts[2], 'aaa_foo_bbb', 'abc' ); 1963 1964 $q = new WP_Query( 1965 array( 1966 'meta_query' => array( 1967 array( 1968 'compare_key' => 'NOT LIKE', 1969 'key' => 'aaa_bar', 1970 'value' => 'abc', 1971 ), 1972 ), 1973 'fields' => 'ids', 1974 ) 1975 ); 1976 1977 $this->assertEqualSets( array( $posts[0], $posts[2] ), $q->posts ); 1978 } 1979 1980 /** 1981 * @ticket 43446 1982 */ 1983 public function test_compare_key_in() { 1984 $posts = self::factory()->post->create_many( 3 ); 1985 1986 add_post_meta( $posts[0], 'aaa_foo_aaa', 'abc' ); 1987 add_post_meta( $posts[1], 'aaa_bar_aaa', 'abc' ); 1988 add_post_meta( $posts[2], 'aaa_foo_bbb', 'abc' ); 1989 1990 $q = new WP_Query( 1991 array( 1992 'meta_query' => array( 1993 array( 1994 'compare_key' => 'IN', 1995 'key' => array( 'aaa_foo_bbb', 'aaa_bar_aaa' ), 1996 ), 1997 ), 1998 'fields' => 'ids', 1999 ) 2000 ); 2001 2002 $this->assertEqualSets( array( $posts[1], $posts[2] ), $q->posts ); 2003 } 2004 2005 /** 2006 * @ticket 43446 2007 */ 2008 public function test_compare_key_not_in() { 2009 $posts = self::factory()->post->create_many( 3 ); 2010 2011 add_post_meta( $posts[0], 'aaa_foo_aaa', 'abc' ); 2012 add_post_meta( $posts[0], 'aaa_foo_ddd', 'abc' ); 2013 add_post_meta( $posts[1], 'aaa_bar_aaa', 'abc' ); 2014 add_post_meta( $posts[2], 'aaa_foo_bbb', 'abc' ); 2015 add_post_meta( $posts[2], 'aaa_foo_ccc', 'abc' ); 2016 2017 $q = new WP_Query( 2018 array( 2019 'meta_query' => array( 2020 array( 2021 'compare_key' => 'NOT IN', 2022 'key' => array( 'aaa_foo_bbb', 'aaa_foo_ddd' ), 2023 ), 2024 ), 2025 'fields' => 'ids', 2026 ) 2027 ); 2028 2029 $this->assertEqualSets( array( $posts[1] ), $q->posts ); 2030 } 2031 2032 /** 2033 * @ticket 43446 2034 */ 2035 public function test_compare_key_not_exists() { 2036 $posts = self::factory()->post->create_many( 3 ); 2037 2038 add_post_meta( $posts[0], 'aaa_foo_aaa', 'abc' ); 2039 add_post_meta( $posts[1], 'aaa_bar_aaa', 'abc' ); 2040 add_post_meta( $posts[2], 'aaa_foo_bbb', 'abc' ); 2041 add_post_meta( $posts[2], 'aaa_foo_ccc', 'abc' ); 2042 2043 $q = new WP_Query( 2044 array( 2045 'meta_query' => array( 2046 array( 2047 'compare_key' => 'NOT EXISTS', 2048 'key' => 'aaa_foo_bbb', 2049 'value' => 'abc', 2050 ), 2051 ), 2052 'fields' => 'ids', 2053 ) 2054 ); 2055 2056 $this->assertEqualSets( array( $posts[0], $posts[1] ), $q->posts ); 2057 } 2058 2059 /** 2060 * @ticket 43446 2061 */ 2062 public function test_compare_key_exists() { 2063 $posts = self::factory()->post->create_many( 3 ); 2064 2065 add_post_meta( $posts[0], 'aaa_foo_aaa', 'abc' ); 2066 add_post_meta( $posts[1], 'aaa_bar_aaa', 'abc' ); 2067 add_post_meta( $posts[2], 'aaa_foo_bbb', 'abc' ); 2068 add_post_meta( $posts[2], 'aaa_foo_ccc', 'abc' ); 2069 2070 $q = new WP_Query( 2071 array( 2072 'meta_query' => array( 2073 array( 2074 'compare_key' => 'EXISTS', 2075 'key' => 'aaa_foo_bbb', 2076 'value' => 'abc', 2077 ), 2078 ), 2079 'fields' => 'ids', 2080 ) 2081 ); 2082 2083 $this->assertEqualSets( array( $posts[2] ), $q->posts ); 2084 } 2085 2086 /** 2087 * @ticket 43446 2088 */ 2089 public function test_compare_key_regexp_rlike() { 2090 $posts = self::factory()->post->create_many( 3 ); 2091 2092 add_post_meta( $posts[0], 'AAA_FOO_AAA', 'abc' ); 2093 add_post_meta( $posts[1], 'aaa_bar_aaa', 'abc' ); 2094 add_post_meta( $posts[2], 'aaa_foo_bbb', 'abc' ); 2095 add_post_meta( $posts[2], 'aaa_foo_aaa', 'abc' ); 2096 2097 $q = new WP_Query( 2098 array( 2099 'meta_query' => array( 2100 array( 2101 'compare_key' => 'REGEXP', 2102 'key' => 'AAA_foo_.*', 2103 ), 2104 ), 2105 'fields' => 'ids', 2106 ) 2107 ); 2108 2109 $this->assertEqualSets( array( $posts[0], $posts[2] ), $q->posts ); 2110 2111 $q = new WP_Query( 2112 array( 2113 'meta_query' => array( 2114 array( 2115 'compare_key' => 'RLIKE', 2116 'key' => 'AAA_FOO_.*', 2117 'type_key' => 'BINARY', 2118 ), 2119 ), 2120 'fields' => 'ids', 2121 ) 2122 ); 2123 2124 $this->assertEqualSets( array( $posts[0] ), $q->posts ); 2125 } 2126 2127 /** 2128 * @ticket 43446 2129 */ 2130 public function test_compare_key_not_regexp() { 2131 $posts = self::factory()->post->create_many( 3 ); 2132 2133 add_post_meta( $posts[0], 'AAA_FOO_AAA', 'abc' ); 2134 add_post_meta( $posts[0], 'AAA_foo_AAA', 'abc' ); 2135 add_post_meta( $posts[1], 'aaa_bar_aaa', 'abc' ); 2136 add_post_meta( $posts[2], 'aaa_foo_bbb', 'abc' ); 2137 add_post_meta( $posts[2], 'aaa_foo_aaa', 'abc' ); 2138 2139 $q = new WP_Query( 2140 array( 2141 'meta_query' => array( 2142 array( 2143 'compare_key' => 'NOT REGEXP', 2144 'key' => 'AAA_foo_.*', 2145 ), 2146 ), 2147 'fields' => 'ids', 2148 ) 2149 ); 2150 2151 $this->assertEqualSets( array( $posts[1] ), $q->posts ); 2152 2153 $q = new WP_Query( 2154 array( 2155 'meta_query' => array( 2156 array( 2157 'compare_key' => 'NOT REGEXP', 2158 'key' => 'AAA_FOO_.*', 2159 'type_key' => 'BINARY', 2160 ), 2161 ), 2162 'fields' => 'ids', 2163 ) 2164 ); 2165 2166 $this->assertEqualSets( array( $posts[1], $posts[2] ), $q->posts ); 2167 } 1925 2168 }
Note: See TracChangeset
for help on using the changeset viewer.