1: <?php
2: 3: 4: 5:
6:
7: if(!class_exists('TypeTest')){
8: require_once __INCLUDES__ .'/model/TypeTest.class.php';
9: }
10:
11: class QQFuncTests extends QUnitTestCaseBase {
12: protected function setUp()
13: {
14: TypeTest::DeleteAll();
15: }
16:
17: public function testFunc() {
18: $objTest = new TypeTest();
19: $objTest->TestFloat = -1.0;
20: $objTest->Save();
21:
22: $objTest2 = new TypeTest();
23: $objTest2->TestFloat = -2.0;
24: $objTest2->Save();
25:
26: $objResArray = TypeTest::QueryArray(QQ::GreaterThan(QQ::Func('ABS', QQN::TypeTest()->TestFloat), 1.0));
27: $this->assertEquals(1, count($objResArray));
28: if (count($objResArray) > 0) {
29: $objRes = $objResArray[0];
30: $this->assertNotNull($objRes);
31: if ($objRes) {
32: $this->assertEquals(-2.0, $objRes->TestFloat);
33: }
34: }
35:
36: $objTest->Delete();
37: $objTest2->Delete();
38: }
39:
40: public function testAbs() {
41: $objTest = new TypeTest();
42: $objTest->TestFloat = -1.0;
43: $objTest->Save();
44:
45: $objTest2 = new TypeTest();
46: $objTest2->TestFloat = -2.0;
47: $objTest2->Save();
48:
49: $objResArray = TypeTest::QueryArray(QQ::GreaterThan(QQ::Abs(QQN::TypeTest()->TestFloat), 1.0));
50: $this->assertEquals(1, count($objResArray));
51: if (count($objResArray) > 0) {
52: $objRes = $objResArray[0];
53: $this->assertNotNull($objRes);
54: if ($objRes) {
55: $this->assertEquals(-2.0, $objRes->TestFloat);
56: }
57: }
58:
59: $objTest->Delete();
60: $objTest2->Delete();
61: }
62:
63: public function testCeil() {
64: $objTest = new TypeTest();
65: $objTest->TestFloat = 1.1;
66: $objTest->Save();
67:
68: $objTest2 = new TypeTest();
69: $objTest2->TestFloat = 2.1;
70: $objTest2->Save();
71:
72: $objResArray = TypeTest::QueryArray(QQ::Equal(QQ::Ceil(QQN::TypeTest()->TestFloat), 2.0));
73: $this->assertEquals(1, count($objResArray));
74: if (count($objResArray) > 0) {
75: $objRes = $objResArray[0];
76: $this->assertNotNull($objRes);
77: if ($objRes) {
78: $this->assertEquals(1.1, $objRes->TestFloat);
79: }
80: }
81:
82: $objTest->Delete();
83: $objTest2->Delete();
84: }
85:
86: public function testFloor() {
87: $objTest = new TypeTest();
88: $objTest->TestFloat = 1.1;
89: $objTest->Save();
90:
91: $objTest2 = new TypeTest();
92: $objTest2->TestFloat = 2.1;
93: $objTest2->Save();
94:
95: $objResArray = TypeTest::QueryArray(QQ::Equal(QQ::Floor(QQN::TypeTest()->TestFloat), 2.0));
96: $this->assertEquals(1, count($objResArray));
97: if (count($objResArray) > 0) {
98: $objRes = $objResArray[0];
99: $this->assertNotNull($objRes);
100: if ($objRes) {
101: $this->assertEquals(2.1, $objRes->TestFloat);
102: }
103: }
104:
105: $objTest->Delete();
106: $objTest2->Delete();
107: }
108:
109: public function testMod() {
110: $objTest = new TypeTest();
111: $objTest->TestInt = 11;
112: $objTest->Save();
113:
114: $objTest2 = new TypeTest();
115: $objTest2->TestInt = 12;
116: $objTest2->Save();
117:
118: $objResArray = TypeTest::QueryArray(QQ::Equal(QQ::Mod(QQN::TypeTest()->TestInt, 10), 2));
119: $this->assertEquals(1, count($objResArray));
120: if (count($objResArray) > 0) {
121: $objRes = $objResArray[0];
122: $this->assertNotNull($objRes);
123: if ($objRes) {
124: $this->assertEquals(12, $objRes->TestInt);
125: }
126: }
127:
128: $objResArray = TypeTest::QueryArray(QQ::Equal(QQ::Mod(QQN::TypeTest()->TestInt, 10), 1));
129: $this->assertEquals(1, count($objResArray));
130: if (count($objResArray) > 0) {
131: $objRes = $objResArray[0];
132: $this->assertNotNull($objRes);
133: if ($objRes) {
134: $this->assertEquals(11, $objRes->TestInt);
135: }
136: }
137:
138: $objTest->Delete();
139: $objTest2->Delete();
140: }
141:
142: public function testPower() {
143: $objTest = new TypeTest();
144: $objTest->TestFloat = 2.0;
145: $objTest->Save();
146:
147: $objTest2 = new TypeTest();
148: $objTest2->TestFloat = 3.0;
149: $objTest2->Save();
150:
151: $objResArray = TypeTest::QueryArray(QQ::Equal(QQ::Power(QQN::TypeTest()->TestFloat, 2), 9.0));
152: $this->assertEquals(1, count($objResArray));
153: if (count($objResArray) > 0) {
154: $objRes = $objResArray[0];
155: $this->assertNotNull($objRes);
156: if ($objRes) {
157: $this->assertEquals(3.0, $objRes->TestFloat);
158: }
159: }
160:
161: $objTest->Delete();
162: $objTest2->Delete();
163: }
164:
165: public function testSqrt() {
166: $objTest = new TypeTest();
167: $objTest->TestFloat = 4.0;
168: $objTest->Save();
169:
170: $objTest2 = new TypeTest();
171: $objTest2->TestFloat = 9.0;
172: $objTest2->Save();
173:
174: $objResArray = TypeTest::QueryArray(QQ::Equal(QQ::Sqrt(QQN::TypeTest()->TestFloat), 3.0));
175: $this->assertEquals(1, count($objResArray));
176: if (count($objResArray) > 0) {
177: $objRes = $objResArray[0];
178: $this->assertNotNull($objRes);
179: if ($objRes) {
180: $this->assertEquals(9.0, $objRes->TestFloat);
181: }
182: }
183:
184: $objTest->Delete();
185: $objTest2->Delete();
186: }
187:
188: public function testOrderBy() {
189: $objTest = new TypeTest();
190: $objTest->TestFloat = 2.0;
191: $objTest->Save();
192:
193: $objTest2 = new TypeTest();
194: $objTest2->TestFloat = 3.0;
195: $objTest2->Save();
196:
197: $objResArray = TypeTest::QueryArray(QQ::GreaterThan(
198: QQ::Virtual('power2', QQ::Power(QQN::TypeTest()->TestFloat, 2.0))
199: , 1.0
200: ),
201: QQ::Clause(
202: QQ::OrderBy(QQ::Virtual('power2'))
203: , QQ::Expand(QQ::Virtual('power2'))
204: ));
205: $this->assertEquals(2, count($objResArray));
206: if (2 == count($objResArray)) {
207: $objRes = $objResArray[0];
208: $this->assertNotNull($objRes);
209: if ($objRes) {
210: $this->assertEquals(2.0, $objRes->TestFloat);
211: $this->assertEquals(4.0, $objRes->GetVirtualAttribute('power2'));
212: }
213: $objRes = $objResArray[1];
214: $this->assertNotNull($objRes);
215: if ($objRes) {
216: $this->assertEquals(3.0, $objRes->TestFloat);
217: $this->assertEquals(9.0, $objRes->GetVirtualAttribute('power2'));
218: }
219: }
220:
221: $objTest->Delete();
222: $objTest2->Delete();
223: }
224:
225: public function testOrderByDesc() {
226: $objTest = new TypeTest();
227: $objTest->TestFloat = 2.0;
228: $objTest->Save();
229:
230: $objTest2 = new TypeTest();
231: $objTest2->TestFloat = 3.0;
232: $objTest2->Save();
233:
234: $objResArray = TypeTest::QueryArray(QQ::GreaterThan(
235: QQ::Virtual('power2', QQ::Power(QQN::TypeTest()->TestFloat, 2.0))
236: , 1.0
237: ),
238: QQ::Clause(
239: QQ::OrderBy(QQ::Virtual('power2'), false)
240: , QQ::Expand(QQ::Virtual('power2'))
241: ));
242: $this->assertEquals(2, count($objResArray));
243: if (2 == count($objResArray)) {
244: $objRes = $objResArray[0];
245: $this->assertNotNull($objRes);
246: if ($objRes) {
247: $this->assertEquals(3.0, $objRes->TestFloat);
248: $this->assertEquals(9.0, $objRes->GetVirtualAttribute('power2'));
249: }
250: $objRes = $objResArray[1];
251: $this->assertNotNull($objRes);
252: if ($objRes) {
253: $this->assertEquals(2.0, $objRes->TestFloat);
254: $this->assertEquals(4.0, $objRes->GetVirtualAttribute('power2'));
255: }
256: }
257:
258: $objTest->Delete();
259: $objTest2->Delete();
260: }
261:
262: public function testSelect() {
263: $objTest = new TypeTest();
264: $objTest->TestFloat = 2.0;
265: $objTest->Save();
266:
267: $objTest2 = new TypeTest();
268: $objTest2->TestFloat = 3.0;
269: $objTest2->Save();
270:
271: $objResArray = TypeTest::QueryArray(QQ::GreaterThan(
272: QQ::Virtual('power2', QQ::Power(QQN::TypeTest()->TestFloat, 2.0))
273: , 1.0
274: ),
275: QQ::Clause(
276: QQ::OrderBy(QQ::Virtual('power2'))
277: , QQ::Expand(QQ::Virtual('power2'))
278: , QQ::Select(QQ::Virtual('power2'))
279: ));
280: $this->assertEquals(2, count($objResArray));
281: if (2 == count($objResArray)) {
282: $objRes = $objResArray[0];
283: $this->assertNotNull($objRes);
284: if ($objRes) {
285: $this->assertNull($objRes->TestFloat);
286: $this->assertEquals(4.0, $objRes->GetVirtualAttribute('power2'));
287: }
288: $objRes = $objResArray[1];
289: $this->assertNotNull($objRes);
290: if ($objRes) {
291: $this->assertNull($objRes->TestFloat);
292: $this->assertEquals(9.0, $objRes->GetVirtualAttribute('power2'));
293: }
294: }
295:
296: $objTest->Delete();
297: $objTest2->Delete();
298: }
299: }