forked from inetprocess/libsugarcrm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSugarQueryIteratorTest.php
85 lines (71 loc) · 2.3 KB
/
SugarQueryIteratorTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
<?php
namespace Inet\SugarCRM\Tests;
use Inet\SugarCRM\SugarQueryIterator;
class SugarQueryIteratorTest extends SugarTestCase
{
protected $query;
public function setUp()
{
// Load sugar clases
$this->getEntryPointInstance()->setCurrentUser('1');
$this->query = new \SugarQuery();
$this->query->from(\BeanFactory::newBean('Accounts'));
}
public function testRewindValid()
{
$iter = new SugarQueryIterator($this->query);
$iter->rewind();
$this->assertTrue($iter->valid());
}
public function testFetchAllAccounts()
{
$this->query->limit(10);
$results = $this->query->execute();
$iter = new SugarQueryIterator($this->query);
$iter->setPaginationSize(5);
$i = 0;
foreach ($iter as $id => $bean) {
$i++;
$this->assertEquals($i, $iter->getIterationCounter());
$this->assertInternalType('string', $id);
$this->assertInstanceOf('Account', $bean);
$this->assertEquals($id, $bean->id);
if ($iter->getIterationCounter() >= 10) {
break;
}
}
$this->assertGreaterThan(0, $i);
$this->assertEquals(count($results), $i);
}
public function testStartOffset()
{
$this->query->limit(10);
$this->query->select(array('id'));
$results = $this->query->execute();
$iter = new SugarQueryIterator($this->query);
$iter->setPaginationSize(5);
$iter->setStartOffset(5);
$iter_results = array();
foreach ($iter as $key => $bean) {
$iter_results[] = array('id' => $key);
if ($iter->getIterationCounter() >= 5) {
break;
}
}
$this->assertEquals(array_slice($results, 5), $iter_results);
}
public function testFixedOffset()
{
$iter = new SugarQueryIterator($this->query);
$iter->useFixedOffset(true);
$iter->setCleanMemoryOnFetch(false);
$iter->setPaginationSize(1);
$iter->rewind();
$this->assertTrue($iter->valid());
$bean_id = $iter->key();
$iter->next();
$this->assertTrue($iter->valid());
$bean2_id = $iter->key();
$this->assertEquals($bean_id, $bean2_id);
}
}