1 | <?php |
---|
2 | # -- BEGIN LICENSE BLOCK --------------------------------------- |
---|
3 | # |
---|
4 | # This file is part of Dotclear 2. |
---|
5 | # |
---|
6 | # Copyright (c) 2003-2014 Olivier Meunier & Association Dotclear |
---|
7 | # Licensed under the GPL version 2.0 license. |
---|
8 | # See LICENSE file or |
---|
9 | # http://www.gnu.org/licenses/old-licenses/gpl-2.0.html |
---|
10 | # |
---|
11 | # -- END LICENSE BLOCK ----------------------------------------- |
---|
12 | |
---|
13 | namespace tests\unit; |
---|
14 | |
---|
15 | use atoum; |
---|
16 | |
---|
17 | require_once __DIR__ . '/../../bootstrap.php'; |
---|
18 | $f = str_replace('\\', '/', __FILE__); |
---|
19 | require_once str_replace('tests/unit/', '', $f); |
---|
20 | |
---|
21 | class dcCore extends atoum |
---|
22 | { |
---|
23 | private $prefix = 'dc_'; |
---|
24 | |
---|
25 | private function getConnection($driver) |
---|
26 | { |
---|
27 | $controller = new \atoum\mock\controller(); |
---|
28 | $controller->__construct = function () {}; |
---|
29 | |
---|
30 | $class_name = sprintf('\mock\%sConnection', $driver); |
---|
31 | $con = new $class_name($driver, $controller); |
---|
32 | $this->calling($con)->driver = $driver; |
---|
33 | $this->calling($con)->escape = function ($s) { |
---|
34 | // just for order, so don't care |
---|
35 | return $s; |
---|
36 | }; |
---|
37 | $this->calling($con)->select = function ($sql) { |
---|
38 | return new \staticRecord([], []); |
---|
39 | }; |
---|
40 | |
---|
41 | return $con; |
---|
42 | } |
---|
43 | |
---|
44 | public function testGetUsers($driver) |
---|
45 | { |
---|
46 | $con = $this->getConnection($driver); |
---|
47 | |
---|
48 | $controller = new \atoum\mock\controller(); |
---|
49 | $controller->__construct = function () {}; |
---|
50 | |
---|
51 | $query = 'SELECT U.user_id,user_super,user_status,user_pwd,user_change_pwd,user_name,user_firstname,user_displayname,user_email,user_url,user_desc, user_lang,user_tz, user_post_status,user_options, count(P.post_id) AS nb_post FROM user U LEFT JOIN post P ON U.user_id = P.user_id WHERE NULL IS NULL GROUP BY U.user_id,user_super,user_status,user_pwd,user_change_pwd,user_name,user_firstname,user_displayname,user_email,user_url,user_desc, user_lang,user_tz,user_post_status,user_options ORDER BY U.user_id ASC '; |
---|
52 | |
---|
53 | $core = new \mock\dcCore(null, null, null, null, null, null, null, $controller); |
---|
54 | $core->con = $con; |
---|
55 | $this |
---|
56 | ->if($core->getUsers()) |
---|
57 | ->then() |
---|
58 | ->mock($con)->call('select') |
---|
59 | ->withIdenticalArguments($query) |
---|
60 | ->once(); |
---|
61 | } |
---|
62 | |
---|
63 | public function testGetUsersWithParams($driver, $params, $query) |
---|
64 | { |
---|
65 | $con = $this->getConnection($driver); |
---|
66 | |
---|
67 | $controller = new \atoum\mock\controller(); |
---|
68 | $controller->__construct = function () {}; |
---|
69 | |
---|
70 | $core = new \mock\dcCore(null, null, null, null, null, null, null, $controller); |
---|
71 | $core->con = $con; |
---|
72 | |
---|
73 | $this |
---|
74 | ->if($core->getUsers($params)) |
---|
75 | ->then() |
---|
76 | ->mock($con)->call('select') |
---|
77 | ->withIdenticalArguments($query) |
---|
78 | ->once(); |
---|
79 | } |
---|
80 | |
---|
81 | /* |
---|
82 | * DataProviders |
---|
83 | **/ |
---|
84 | protected function testGetUsersDataProvider() |
---|
85 | { |
---|
86 | $query = []; |
---|
87 | |
---|
88 | return [ |
---|
89 | ['pgsql'], |
---|
90 | ['sqlite'], |
---|
91 | ['mysql'], |
---|
92 | ['mysqli'] |
---|
93 | ]; |
---|
94 | } |
---|
95 | |
---|
96 | protected function testGetUsersWithParamsDataProvider() |
---|
97 | { |
---|
98 | $base_query = 'SELECT U.user_id,user_super,user_status,user_pwd,user_change_pwd,user_name,user_firstname,user_displayname,user_email,user_url,user_desc, user_lang,user_tz, user_post_status,user_options, count(P.post_id) AS nb_post FROM user U LEFT JOIN post P ON U.user_id = P.user_id WHERE NULL IS NULL GROUP BY U.user_id,user_super,user_status,user_pwd,user_change_pwd,user_name,user_firstname,user_displayname,user_email,user_url,user_desc, user_lang,user_tz,user_post_status,user_options ORDER BY '; |
---|
99 | |
---|
100 | return [ |
---|
101 | ['pgsql', ['order' => 'user_id asc'], $base_query . 'U.user_id asc '], |
---|
102 | ['pgsql', ['order' => 'U.user_id asc'], $base_query . 'U.user_id asc '], |
---|
103 | ['mysql', ['order' => 'user_id asc'], $base_query . 'U.user_id asc '], |
---|
104 | ['mysql', ['order' => 'U.user_id asc'], $base_query . 'U.user_id asc '], |
---|
105 | ['mysqli', ['order' => 'user_id asc'], $base_query . 'U.user_id asc '], |
---|
106 | ['mysqli', ['order' => 'U.user_id asc'], $base_query . 'U.user_id asc '], |
---|
107 | ['sqlite', ['order' => 'user_id asc'], $base_query . 'U.user_id asc '], |
---|
108 | ['sqlite', ['order' => 'U.user_id asc'], $base_query . 'U.user_id asc '], |
---|
109 | |
---|
110 | ['pgsql', ['order' => 'nb_post desc'], $base_query . 'P.nb_post desc '], |
---|
111 | ['pgsql', ['order' => 'P.nb_post desc'], $base_query . 'P.nb_post desc '], |
---|
112 | ['mysql', ['order' => 'nb_post desc'], $base_query . 'P.nb_post desc '], |
---|
113 | ['mysql', ['order' => 'P.nb_post desc'], $base_query . 'P.nb_post desc '], |
---|
114 | ['mysqli', ['order' => 'nb_post desc'], $base_query . 'P.nb_post desc '], |
---|
115 | ['mysqli', ['order' => 'P.nb_post desc'], $base_query . 'P.nb_post desc '], |
---|
116 | ['sqlite', ['order' => 'nb_post desc'], $base_query . 'P.nb_post desc '], |
---|
117 | ['sqlite', ['order' => 'P.nb_post desc'], $base_query . 'P.nb_post desc '] |
---|
118 | ]; |
---|
119 | } |
---|
120 | } |
---|