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 | $controller = new \atoum\mock\controller(); |
---|
27 | $controller->__construct = function() {}; |
---|
28 | |
---|
29 | $class_name = sprintf('\mock\%sConnection',$driver); |
---|
30 | $con = new $class_name($driver,$controller); |
---|
31 | $this->calling($con)->driver = $driver; |
---|
32 | $this->calling($con)->escape = function($s) { // just for order, so don't care |
---|
33 | return $s; |
---|
34 | }; |
---|
35 | $this->calling($con)->select = function($sql) { |
---|
36 | return new \staticRecord(array(),array()); |
---|
37 | }; |
---|
38 | |
---|
39 | return $con; |
---|
40 | } |
---|
41 | |
---|
42 | public function testGetUsers($driver) { |
---|
43 | $con = $this->getConnection($driver); |
---|
44 | |
---|
45 | $controller = new \atoum\mock\controller(); |
---|
46 | $controller->__construct = function() {}; |
---|
47 | |
---|
48 | $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 '; |
---|
49 | |
---|
50 | $core = new \mock\dcCore(null,null,null,null,null,null,null,$controller); |
---|
51 | $core->con = $con; |
---|
52 | $this |
---|
53 | ->if($core->getUsers()) |
---|
54 | ->then() |
---|
55 | ->mock($con)->call('select') |
---|
56 | ->withIdenticalArguments($query) |
---|
57 | ->once(); |
---|
58 | } |
---|
59 | |
---|
60 | public function testGetUsersWithParams($driver,$params,$query) { |
---|
61 | $con = $this->getConnection($driver); |
---|
62 | |
---|
63 | $controller = new \atoum\mock\controller(); |
---|
64 | $controller->__construct = function() {}; |
---|
65 | |
---|
66 | $core = new \mock\dcCore(null,null,null,null,null,null,null,$controller); |
---|
67 | $core->con = $con; |
---|
68 | |
---|
69 | $this |
---|
70 | ->if($core->getUsers($params)) |
---|
71 | ->then() |
---|
72 | ->mock($con)->call('select') |
---|
73 | ->withIdenticalArguments($query) |
---|
74 | ->once(); |
---|
75 | } |
---|
76 | |
---|
77 | /* |
---|
78 | * DataProviders |
---|
79 | **/ |
---|
80 | protected function testGetUsersDataProvider() { |
---|
81 | $query = array(); |
---|
82 | |
---|
83 | return array( |
---|
84 | array('pgsql'), |
---|
85 | array('sqlite'), |
---|
86 | array('mysql'), |
---|
87 | array('mysqli'), |
---|
88 | ); |
---|
89 | } |
---|
90 | |
---|
91 | protected function testGetUsersWithParamsDataProvider() { |
---|
92 | $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 '; |
---|
93 | |
---|
94 | return array( |
---|
95 | array('pgsql',array('order' => 'user_id asc'),$base_query.'U.user_id asc '), |
---|
96 | array('pgsql',array('order' => 'U.user_id asc'),$base_query.'U.user_id asc '), |
---|
97 | array('mysql',array('order' => 'user_id asc'),$base_query.'U.user_id asc '), |
---|
98 | array('mysql',array('order' => 'U.user_id asc'),$base_query.'U.user_id asc '), |
---|
99 | array('mysqli',array('order' => 'user_id asc'),$base_query.'U.user_id asc '), |
---|
100 | array('mysqli',array('order' => 'U.user_id asc'),$base_query.'U.user_id asc '), |
---|
101 | array('sqlite',array('order' => 'user_id asc'),$base_query.'U.user_id asc '), |
---|
102 | array('sqlite',array('order' => 'U.user_id asc'),$base_query.'U.user_id asc '), |
---|
103 | |
---|
104 | array('pgsql',array('order' => 'nb_post desc'),$base_query.'P.nb_post desc '), |
---|
105 | array('pgsql',array('order' => 'P.nb_post desc'),$base_query.'P.nb_post desc '), |
---|
106 | array('mysql',array('order' => 'nb_post desc'),$base_query.'P.nb_post desc '), |
---|
107 | array('mysql',array('order' => 'P.nb_post desc'),$base_query.'P.nb_post desc '), |
---|
108 | array('mysqli',array('order' => 'nb_post desc'),$base_query.'P.nb_post desc '), |
---|
109 | array('mysqli',array('order' => 'P.nb_post desc'),$base_query.'P.nb_post desc '), |
---|
110 | array('sqlite',array('order' => 'nb_post desc'),$base_query.'P.nb_post desc '), |
---|
111 | array('sqlite',array('order' => 'P.nb_post desc'),$base_query.'P.nb_post desc '), |
---|
112 | ); |
---|
113 | } |
---|
114 | } |
---|