|
38 | 38 | use const MYSQLI_TYPE_DECIMAL; |
39 | 39 | use const MYSQLI_TYPE_LONG; |
40 | 40 | use const MYSQLI_TYPE_STRING; |
| 41 | +use const MYSQLI_TYPE_TIME; |
41 | 42 | use const MYSQLI_TYPE_TIMESTAMP; |
42 | 43 |
|
43 | 44 | /** |
@@ -1804,4 +1805,167 @@ public function testGetTable2(): void |
1804 | 1805 |
|
1805 | 1806 | $this->assertEquals($tableTemplate, $actual); |
1806 | 1807 | } |
| 1808 | + |
| 1809 | + /** |
| 1810 | + * @return array[] |
| 1811 | + */ |
| 1812 | + public function dataProviderSortOrder(): array |
| 1813 | + { |
| 1814 | + return [ |
| 1815 | + 'Default date' => [ |
| 1816 | + 'SMART', |
| 1817 | + 'DESC',// date types are DESC in SMART mode |
| 1818 | + MYSQLI_TYPE_DATE, |
| 1819 | + ], |
| 1820 | + 'ASC date' => [ |
| 1821 | + 'ASC', |
| 1822 | + 'ASC',// do as config says |
| 1823 | + MYSQLI_TYPE_DATE, |
| 1824 | + ], |
| 1825 | + 'DESC date' => [ |
| 1826 | + 'DESC', |
| 1827 | + 'DESC',// do as config says |
| 1828 | + MYSQLI_TYPE_DATE, |
| 1829 | + ], |
| 1830 | + 'Default date-time' => [ |
| 1831 | + 'SMART', |
| 1832 | + 'DESC',// date time types are DESC in SMART mode |
| 1833 | + MYSQLI_TYPE_DATETIME, |
| 1834 | + ], |
| 1835 | + 'ASC date-time' => [ |
| 1836 | + 'ASC', |
| 1837 | + 'ASC',// do as config says |
| 1838 | + MYSQLI_TYPE_DATETIME, |
| 1839 | + ], |
| 1840 | + 'DESC date-time' => [ |
| 1841 | + 'DESC', |
| 1842 | + 'DESC',// do as config says |
| 1843 | + MYSQLI_TYPE_DATETIME, |
| 1844 | + ], |
| 1845 | + 'Default time' => [ |
| 1846 | + 'SMART', |
| 1847 | + 'DESC',// time types are DESC in SMART mode |
| 1848 | + MYSQLI_TYPE_TIME, |
| 1849 | + ], |
| 1850 | + 'ASC time' => [ |
| 1851 | + 'ASC', |
| 1852 | + 'ASC',// do as config says |
| 1853 | + MYSQLI_TYPE_TIME, |
| 1854 | + ], |
| 1855 | + 'DESC time' => [ |
| 1856 | + 'DESC', |
| 1857 | + 'DESC',// do as config says |
| 1858 | + MYSQLI_TYPE_TIME, |
| 1859 | + ], |
| 1860 | + 'Default timestamp' => [ |
| 1861 | + 'SMART', |
| 1862 | + 'DESC',// timestamp types are DESC in SMART mode |
| 1863 | + MYSQLI_TYPE_TIMESTAMP, |
| 1864 | + ], |
| 1865 | + 'ASC timestamp' => [ |
| 1866 | + 'ASC', |
| 1867 | + 'ASC',// do as config says |
| 1868 | + MYSQLI_TYPE_TIMESTAMP, |
| 1869 | + ], |
| 1870 | + 'DESC timestamp' => [ |
| 1871 | + 'DESC', |
| 1872 | + 'DESC',// do as config says |
| 1873 | + MYSQLI_TYPE_TIMESTAMP, |
| 1874 | + ], |
| 1875 | + 'Default string' => [ |
| 1876 | + 'SMART', |
| 1877 | + 'ASC',// string types are ASC in SMART mode |
| 1878 | + MYSQLI_TYPE_STRING, |
| 1879 | + ], |
| 1880 | + 'ASC string' => [ |
| 1881 | + 'ASC', |
| 1882 | + 'ASC',// do as config says |
| 1883 | + MYSQLI_TYPE_STRING, |
| 1884 | + ], |
| 1885 | + 'DESC string' => [ |
| 1886 | + 'DESC', |
| 1887 | + 'DESC',// do as config says |
| 1888 | + MYSQLI_TYPE_STRING, |
| 1889 | + ], |
| 1890 | + ]; |
| 1891 | + } |
| 1892 | + |
| 1893 | + /** |
| 1894 | + * @dataProvider dataProviderSortOrder |
| 1895 | + */ |
| 1896 | + public function testGetSingleAndMultiSortUrls( |
| 1897 | + string $orderSetting, |
| 1898 | + string $querySortDirection, |
| 1899 | + int $metaType |
| 1900 | + ): void { |
| 1901 | + $GLOBALS['cfg']['Order'] = $orderSetting; |
| 1902 | + |
| 1903 | + $data = $this->callFunction( |
| 1904 | + $this->object, |
| 1905 | + DisplayResults::class, |
| 1906 | + 'getSingleAndMultiSortUrls', |
| 1907 | + [ |
| 1908 | + ['`Country`.`Code` ASC'], // sortExpression, |
| 1909 | + ['`Country`.`Code`'], // sortExpressionNoDirection, |
| 1910 | + '`Country`.', |
| 1911 | + 'FoundedIn', |
| 1912 | + ['ASC'], // sortDirection, |
| 1913 | + new FieldMetadata($metaType, 0, (object) []), |
| 1914 | + ] |
| 1915 | + ); |
| 1916 | + |
| 1917 | + $this->assertSame([ |
| 1918 | + "\n" . 'ORDER BY `Country`.`FoundedIn` ' . $querySortDirection, // singleSortOrder |
| 1919 | + "\n" . 'ORDER BY `Country`.`Code` ASC, `Country`.`FoundedIn` ' . $querySortDirection, // sortOrderColumns |
| 1920 | + '', // orderImg |
| 1921 | + ], $data); |
| 1922 | + |
| 1923 | + $data = $this->callFunction( |
| 1924 | + $this->object, |
| 1925 | + DisplayResults::class, |
| 1926 | + 'getSingleAndMultiSortUrls', |
| 1927 | + [ |
| 1928 | + ['`Country`.`Code` ASC'], // sortExpression, |
| 1929 | + ['`Country`.`Code`'], // sortExpressionNoDirection, |
| 1930 | + '`Country`.', |
| 1931 | + 'Code2', |
| 1932 | + ['ASC'], // sortDirection, |
| 1933 | + new FieldMetadata($metaType, 0, (object) []), |
| 1934 | + ] |
| 1935 | + ); |
| 1936 | + |
| 1937 | + $this->assertSame([ |
| 1938 | + "\n" . 'ORDER BY `Country`.`Code2` ' . $querySortDirection, // singleSortOrder |
| 1939 | + "\n" . 'ORDER BY `Country`.`Code` ASC, `Country`.`Code2` ' . $querySortDirection, // sortOrderColumns |
| 1940 | + '', // orderImg |
| 1941 | + ], $data); |
| 1942 | + |
| 1943 | + $data = $this->callFunction( |
| 1944 | + $this->object, |
| 1945 | + DisplayResults::class, |
| 1946 | + 'getSingleAndMultiSortUrls', |
| 1947 | + [ |
| 1948 | + [ |
| 1949 | + '`Country`.`Continent` DESC","`Country`.`Region` ASC', |
| 1950 | + '`Country`.`Population` ASC', |
| 1951 | + ], // sortExpression, |
| 1952 | + [ |
| 1953 | + '`Country`.`Continent`', |
| 1954 | + '`Country`.`Region`', |
| 1955 | + '`Country`.`Population`', |
| 1956 | + ], // sortExpressionNoDirection, |
| 1957 | + '`Country`.', |
| 1958 | + 'Code2', |
| 1959 | + ['DESC', 'ASC', 'ASC'], // sortDirection, |
| 1960 | + new FieldMetadata($metaType, 0, (object) []), |
| 1961 | + ] |
| 1962 | + ); |
| 1963 | + |
| 1964 | + $this->assertSame([ |
| 1965 | + "\n" . 'ORDER BY `Country`.`Code2` ' . $querySortDirection, // singleSortOrder |
| 1966 | + "\n" . 'ORDER BY `Country`.`Continent` DESC, `Country`.`Region` ASC' |
| 1967 | + . ', `Country`.`Population` ASC, `Country`.`Code2` ' . $querySortDirection, // sortOrderColumns |
| 1968 | + '', // orderImg |
| 1969 | + ], $data); |
| 1970 | + } |
1807 | 1971 | } |
0 commit comments