| | 28 | } |
|---|
| | 29 | } |
|---|
| | 30 | |
|---|
| | 31 | protected function _testValidSort() |
|---|
| | 32 | { |
|---|
| | 33 | $this->info('Test valid sort parameter'); |
|---|
| | 34 | |
|---|
| | 35 | $this->get('/users?sort=username'); |
|---|
| | 36 | |
|---|
| | 37 | $matches = 0; |
|---|
| | 38 | foreach ($this->_getQueryExecutionEvents() as $event) |
|---|
| | 39 | { |
|---|
| | 40 | if (false !== strpos($event->getQuery(), 'ORDER BY u.username asc')) |
|---|
| | 41 | { |
|---|
| | 42 | ++$matches; |
|---|
| | 43 | } |
|---|
| | 44 | } |
|---|
| | 45 | |
|---|
| | 46 | $this->test()->is($matches, 1); |
|---|
| | 47 | } |
|---|
| | 48 | |
|---|
| | 49 | protected function _testInvalidSort() |
|---|
| | 50 | { |
|---|
| | 51 | $this->info('Test invalid sort parameter'); |
|---|
| | 52 | |
|---|
| | 53 | $this->get('/users?sort=INVALID'); |
|---|
| | 54 | |
|---|
| | 55 | // there should be no queries that match "INVALID" |
|---|
| | 56 | foreach ($this->_getQueryExecutionEvents() as $event) |
|---|
| | 57 | { |
|---|
| | 58 | $this->test()->unlike($event->getQuery(), '/INVALID/'); |
|---|
| | 59 | } |
|---|
| | 60 | } |
|---|
| | 61 | |
|---|
| | 62 | protected function _testValidSortType() |
|---|
| | 63 | { |
|---|
| | 64 | $this->info('Test valid sort_type parameter'); |
|---|
| | 65 | |
|---|
| | 66 | foreach (array('asc', 'desc', 'ASC', 'DESC') as $sortType) |
|---|
| | 67 | { |
|---|
| | 68 | $this->get('/users?sort=username&sort_type='.$sortType); |
|---|
| | 69 | |
|---|
| | 70 | $matches = 0; |
|---|
| | 71 | foreach ($this->_getQueryExecutionEvents() as $event) |
|---|
| | 72 | { |
|---|
| | 73 | if (false !== strpos($event->getQuery(), 'ORDER BY u.username '.$sortType)) |
|---|
| | 74 | { |
|---|
| | 75 | ++$matches; |
|---|
| | 76 | } |
|---|
| | 77 | } |
|---|
| | 78 | |
|---|
| | 79 | $this->test()->is($matches, 1); |
|---|
| | 80 | } |
|---|
| | 81 | } |
|---|
| | 82 | |
|---|
| | 83 | protected function _testInvalidSortType() |
|---|
| | 84 | { |
|---|
| | 85 | $this->info('Test invalid sort_type parameter'); |
|---|
| | 86 | |
|---|
| | 87 | $this->get('/users?sort=username&sort_type=INVALID'); |
|---|
| | 88 | |
|---|
| | 89 | // there should be no queries that match "INVALID" |
|---|
| | 90 | foreach ($this->_getQueryExecutionEvents() as $event) |
|---|
| | 91 | { |
|---|
| | 92 | $this->test()->unlike($event->getQuery(), '/INVALID/'); |
|---|
| | 270 | protected function _getQueryExecutionEvents() |
|---|
| | 271 | { |
|---|
| | 272 | $events = array(); |
|---|
| | 273 | |
|---|
| | 274 | $databaseManager = $this->browser->getContext()->getDatabaseManager(); |
|---|
| | 275 | foreach ($databaseManager->getNames() as $name) |
|---|
| | 276 | { |
|---|
| | 277 | $database = $databaseManager->getDatabase($name); |
|---|
| | 278 | if ($database instanceof sfDoctrineDatabase && $profiler = $database->getProfiler()) |
|---|
| | 279 | { |
|---|
| | 280 | foreach ($profiler->getQueryExecutionEvents() as $event) |
|---|
| | 281 | { |
|---|
| | 282 | $events[$event->getSequence()] = $event; |
|---|
| | 283 | } |
|---|
| | 284 | } |
|---|
| | 285 | } |
|---|
| | 286 | |
|---|
| | 287 | ksort($events); |
|---|
| | 288 | |
|---|
| | 289 | return array_values($events); |
|---|
| | 290 | } |
|---|
| | 291 | |
|---|