Test Failed
Branch master (9acec7)
by Agel_Nash
02:58
created

getChildrenListTest   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 267
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 9
c 0
b 0
f 0
dl 0
loc 267
rs 10

9 Methods

Rating   Name   Duplication   Size   Complexity  
B testHideParentAndDocsAndWhere() 0 29 1
B testIgnoreParentAndDocsAndWhere() 0 29 1
B testShowParent() 0 26 1
B testIgnoreParentAndDocs() 0 27 1
B testHideParent() 0 27 1
B testShowParentAndDocsAndWhere() 0 29 1
B testHideParentAndDocs() 0 28 1
B testIgnoreParent() 0 26 1
B testShowParentAndDocs() 0 27 1
1
<?php namespace DocLister\Tests\DL\Controller\SiteContent;
2
3
use DocLister\Tests\DL\DLAbstract;
4
5
class getChildrenListTest extends DLAbstract
6
{
7
    public function testShowParent()
8
    {
9
        $out = array(
10
            "SELECT count(*) FROM (SELECT count(*) FROM site_content as `c`  WHERE c.deleted=0 AND c.published=1 AND (c.parent IN ('5') OR c.id IN('5')) GROUP BY c.id) as `tmp`",
11
            "SELECT c.* FROM site_content as `c`  WHERE (c.parent IN ('5') OR c.id IN('5')) AND c.deleted=0 AND c.published=1 GROUP BY c.id ORDER BY if(c.pub_date=0,c.createdon,c.pub_date) DESC LIMIT 0,10"
12
        );
13
        $DL = $this->mockDocLister('site_content', array(
14
            'debug'      => 1,
15
            'idType'     => 'parents',
16
            'parents'    => 5,
17
            'showParent' => 1,
18
            'paginate'   => 'pages',
19
            'display'    => 10,
20
        ));
21
22
        $DL->debug->clearLog();
0 ignored issues
show
Bug introduced by
The method clearLog() does not exist on xNop. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

22
        $DL->debug->/** @scrutinizer ignore-call */ clearLog();
Loading history...
23
        $DL->getChildrenCount();
24
        $this->getMethod($DL, "getChildrenList")->invoke($DL);
25
26
        $debug = new \Helpers\Collection($DL->debug->getLog());
0 ignored issues
show
Bug introduced by
The method getLog() does not exist on xNop. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

26
        $debug = new \Helpers\Collection($DL->debug->/** @scrutinizer ignore-call */ getLog());
Loading history...
27
28
        $getChildrenCount = $debug->get(0);
29
        $getChildrenList = $debug->get(1);
30
31
        $this->assertEquals($out[0], trim($getChildrenCount['msg']));
32
        $this->assertEquals($out[1], trim($getChildrenList['msg']));
33
34
    }
35
36
    public function testHideParent()
37
    {
38
        $out = array(
39
            "SELECT count(*) FROM (SELECT count(*) FROM site_content as `c`  WHERE c.deleted=0 AND c.published=1 AND c.parent IN ('5') AND c.id NOT IN('5') GROUP BY c.id) as `tmp`",
40
            "SELECT c.* FROM site_content as `c`  WHERE c.parent IN ('5') AND c.id NOT IN('5') AND c.deleted=0 AND c.published=1 GROUP BY c.id ORDER BY if(c.pub_date=0,c.createdon,c.pub_date) DESC LIMIT 0,10"
41
        );
42
43
        $DL = $this->mockDocLister('site_content', array(
44
            'debug'      => 1,
45
            'idType'     => 'parents',
46
            'parents'    => 5,
47
            'showParent' => 0,
48
            'paginate'   => 'pages',
49
            'display'    => 10,
50
        ));
51
52
        $DL->debug->clearLog();
53
        $DL->getChildrenCount();
54
        $this->getMethod($DL, "getChildrenList")->invoke($DL);
55
56
        $debug = new \Helpers\Collection($DL->debug->getLog());
57
58
        $getChildrenCount = $debug->get(0);
59
        $getChildrenList = $debug->get(1);
60
61
        $this->assertEquals($out[0], trim($getChildrenCount['msg']));
62
        $this->assertEquals($out[1], trim($getChildrenList['msg']));
63
    }
64
65
    public function testIgnoreParent()
66
    {
67
        $out = array(
68
            "SELECT count(*) FROM (SELECT count(*) FROM site_content as `c`  WHERE c.deleted=0 AND c.published=1 AND c.parent IN ('5') GROUP BY c.id) as `tmp`",
69
            "SELECT c.* FROM site_content as `c`  WHERE c.parent IN ('5') AND c.deleted=0 AND c.published=1 GROUP BY c.id ORDER BY if(c.pub_date=0,c.createdon,c.pub_date) DESC LIMIT 0,10"
70
        );
71
        $DL = $this->mockDocLister('site_content', array(
72
            'debug'      => 1,
73
            'idType'     => 'parents',
74
            'parents'    => 5,
75
            'showParent' => "-1",
76
            'paginate'   => 'pages',
77
            'display'    => 10,
78
        ));
79
80
        $DL->debug->clearLog();
81
        $DL->getChildrenCount();
82
        $this->getMethod($DL, "getChildrenList")->invoke($DL);
83
84
        $debug = new \Helpers\Collection($DL->debug->getLog());
85
86
        $getChildrenCount = $debug->get(0);
87
        $getChildrenList = $debug->get(1);
88
89
        $this->assertEquals($out[0], trim($getChildrenCount['msg']));
90
        $this->assertEquals($out[1], trim($getChildrenList['msg']));
91
    }
92
93
    public function testShowParentAndDocs()
94
    {
95
        $out = array(
96
            "SELECT count(*) FROM (SELECT count(*) FROM site_content as `c`  WHERE c.deleted=0 AND c.published=1 AND (((c.parent IN ('5') OR c.id IN('5'))) OR c.id IN('10','12')) GROUP BY c.id) as `tmp`",
97
            "SELECT c.* FROM site_content as `c`  WHERE (((c.parent IN ('5') OR c.id IN('5'))) OR c.id IN('10','12')) AND c.deleted=0 AND c.published=1 GROUP BY c.id ORDER BY if(c.pub_date=0,c.createdon,c.pub_date) DESC LIMIT 0,10"
98
        );
99
        $DL = $this->mockDocLister('site_content', array(
100
            'debug'      => 1,
101
            'idType'     => 'parents',
102
            'parents'    => 5,
103
            'documents'  => '10,12',
104
            'showParent' => 1,
105
            'paginate'   => 'pages',
106
            'display'    => 10,
107
        ));
108
109
        $DL->debug->clearLog();
110
        $DL->getChildrenCount();
111
        $this->getMethod($DL, "getChildrenList")->invoke($DL);
112
113
        $debug = new \Helpers\Collection($DL->debug->getLog());
114
115
        $getChildrenCount = $debug->get(0);
116
        $getChildrenList = $debug->get(1);
117
118
        $this->assertEquals($out[0], trim($getChildrenCount['msg']));
119
        $this->assertEquals($out[1], trim($getChildrenList['msg']));
120
    }
121
122
    public function testHideParentAndDocs()
123
    {
124
        $out = array(
125
            "SELECT count(*) FROM (SELECT count(*) FROM site_content as `c`  WHERE c.deleted=0 AND c.published=1 AND ((c.parent IN ('5') AND c.id NOT IN('5')) OR c.id IN('10','12')) GROUP BY c.id) as `tmp`",
126
            "SELECT c.* FROM site_content as `c`  WHERE ((c.parent IN ('5') AND c.id NOT IN('5')) OR c.id IN('10','12')) AND c.deleted=0 AND c.published=1 GROUP BY c.id ORDER BY if(c.pub_date=0,c.createdon,c.pub_date) DESC LIMIT 0,10"
127
        );
128
129
        $DL = $this->mockDocLister('site_content', array(
130
            'debug'      => 1,
131
            'idType'     => 'parents',
132
            'parents'    => 5,
133
            'documents'  => '10,12',
134
            'showParent' => 0,
135
            'paginate'   => 'pages',
136
            'display'    => 10,
137
        ));
138
139
        $DL->debug->clearLog();
140
        $DL->getChildrenCount();
141
        $this->getMethod($DL, "getChildrenList")->invoke($DL);
142
143
        $debug = new \Helpers\Collection($DL->debug->getLog());
144
145
        $getChildrenCount = $debug->get(0);
146
        $getChildrenList = $debug->get(1);
147
148
        $this->assertEquals($out[0], trim($getChildrenCount['msg']));
149
        $this->assertEquals($out[1], trim($getChildrenList['msg']));
150
    }
151
152
    public function testIgnoreParentAndDocs()
153
    {
154
        $out = array(
155
            "SELECT count(*) FROM (SELECT count(*) FROM site_content as `c`  WHERE c.deleted=0 AND c.published=1 AND ((c.parent IN ('5')) OR c.id IN('10','12')) GROUP BY c.id) as `tmp`",
156
            "SELECT c.* FROM site_content as `c`  WHERE ((c.parent IN ('5')) OR c.id IN('10','12')) AND c.deleted=0 AND c.published=1 GROUP BY c.id ORDER BY if(c.pub_date=0,c.createdon,c.pub_date) DESC LIMIT 0,10"
157
        );
158
        $DL = $this->mockDocLister('site_content', array(
159
            'debug'      => 1,
160
            'idType'     => 'parents',
161
            'parents'    => 5,
162
            'documents'  => '10,12',
163
            'showParent' => "-1",
164
            'paginate'   => 'pages',
165
            'display'    => 10,
166
        ));
167
168
        $DL->debug->clearLog();
169
        $DL->getChildrenCount();
170
        $this->getMethod($DL, "getChildrenList")->invoke($DL);
171
172
        $debug = new \Helpers\Collection($DL->debug->getLog());
173
174
        $getChildrenCount = $debug->get(0);
175
        $getChildrenList = $debug->get(1);
176
177
        $this->assertEquals($out[0], trim($getChildrenCount['msg']));
178
        $this->assertEquals($out[1], trim($getChildrenList['msg']));
179
    }
180
181
    public function testShowParentAndDocsAndWhere()
182
    {
183
        $out = array(
184
            "SELECT count(*) FROM (SELECT count(*) FROM site_content as `c`  WHERE `price`>0 AND c.deleted=0 AND c.published=1 AND (((c.parent IN ('5') OR c.id IN('5'))) OR c.id IN('10','12')) GROUP BY c.id) as `tmp`",
185
            "SELECT c.* FROM site_content as `c`  WHERE `price`>0 AND (((c.parent IN ('5') OR c.id IN('5'))) OR c.id IN('10','12')) AND c.deleted=0 AND c.published=1 GROUP BY c.id ORDER BY if(c.pub_date=0,c.createdon,c.pub_date) DESC LIMIT 0,10"
186
        );
187
188
        $DL = $this->mockDocLister('site_content', array(
189
            'debug'        => 1,
190
            'idType'       => 'parents',
191
            'parents'      => 5,
192
            'documents'    => '10,12',
193
            'showParent'   => 1,
194
            'addWhereList' => '`price`>0',
195
            'paginate'     => 'pages',
196
            'display'      => 10,
197
        ));
198
199
        $DL->debug->clearLog();
200
        $DL->getChildrenCount();
201
        $this->getMethod($DL, "getChildrenList")->invoke($DL);
202
203
        $debug = new \Helpers\Collection($DL->debug->getLog());
204
205
        $getChildrenCount = $debug->get(0);
206
        $getChildrenList = $debug->get(1);
207
208
        $this->assertEquals($out[0], trim($getChildrenCount['msg']));
209
        $this->assertEquals($out[1], trim($getChildrenList['msg']));
210
    }
211
212
    public function testHideParentAndDocsAndWhere()
213
    {
214
        $out = array(
215
            "SELECT count(*) FROM (SELECT count(*) FROM site_content as `c`  WHERE `price`>0 AND c.deleted=0 AND c.published=1 AND ((c.parent IN ('5') AND c.id NOT IN('5')) OR c.id IN('10','12')) GROUP BY c.id) as `tmp`",
216
            "SELECT c.* FROM site_content as `c`  WHERE `price`>0 AND ((c.parent IN ('5') AND c.id NOT IN('5')) OR c.id IN('10','12')) AND c.deleted=0 AND c.published=1 GROUP BY c.id ORDER BY if(c.pub_date=0,c.createdon,c.pub_date) DESC LIMIT 0,10"
217
        );
218
219
        $DL = $this->mockDocLister('site_content', array(
220
            'debug'        => 1,
221
            'idType'       => 'parents',
222
            'parents'      => 5,
223
            'documents'    => '10,12',
224
            'showParent'   => 0,
225
            'addWhereList' => '`price`>0',
226
            'paginate'     => 'pages',
227
            'display'      => 10,
228
        ));
229
230
        $DL->debug->clearLog();
231
        $DL->getChildrenCount();
232
        $this->getMethod($DL, "getChildrenList")->invoke($DL);
233
234
        $debug = new \Helpers\Collection($DL->debug->getLog());
235
236
        $getChildrenCount = $debug->get(0);
237
        $getChildrenList = $debug->get(1);
238
239
        $this->assertEquals($out[0], trim($getChildrenCount['msg']));
240
        $this->assertEquals($out[1], trim($getChildrenList['msg']));
241
    }
242
243
    public function testIgnoreParentAndDocsAndWhere()
244
    {
245
        $out = array(
246
            "SELECT count(*) FROM (SELECT count(*) FROM site_content as `c`  WHERE `price`>0 AND c.deleted=0 AND c.published=1 AND ((c.parent IN ('5')) OR c.id IN('10','12')) GROUP BY c.id) as `tmp`",
247
            "SELECT c.* FROM site_content as `c`  WHERE `price`>0 AND ((c.parent IN ('5')) OR c.id IN('10','12')) AND c.deleted=0 AND c.published=1 GROUP BY c.id ORDER BY if(c.pub_date=0,c.createdon,c.pub_date) DESC LIMIT 0,10"
248
        );
249
250
        $DL = $this->mockDocLister('site_content', array(
251
            'debug'        => 1,
252
            'idType'       => 'parents',
253
            'parents'      => 5,
254
            'documents'    => '10,12',
255
            'showParent'   => "-1",
256
            'addWhereList' => '`price`>0',
257
            'paginate'     => 'pages',
258
            'display'      => 10,
259
        ));
260
261
        $DL->debug->clearLog();
262
        $DL->getChildrenCount();
263
        $this->getMethod($DL, "getChildrenList")->invoke($DL);
264
265
        $debug = new \Helpers\Collection($DL->debug->getLog());
266
267
        $getChildrenCount = $debug->get(0);
268
        $getChildrenList = $debug->get(1);
269
270
        $this->assertEquals($out[0], trim($getChildrenCount['msg']));
271
        $this->assertEquals($out[1], trim($getChildrenList['msg']));
272
    }
273
}