| @@ 61-108 (lines=48) @@ | ||
| 58 | * @covers Mado\QueryBundle\Repositories\BaseRepository::setQueryOptionsFromRequest |
|
| 59 | * @covers Mado\QueryBundle\Repositories\BaseRepository::setRequest |
|
| 60 | */ |
|
| 61 | public function testBuildOptionsViaRequest() |
|
| 62 | { |
|
| 63 | $this->attributeParameterBag = $this |
|
| 64 | ->getMockBuilder('Symfony\Component\HttpFoundation\ParameterBag') |
|
| 65 | ->setMethods(['all']) |
|
| 66 | ->disableOriginalConstructor() |
|
| 67 | ->getMock(); |
|
| 68 | $this->attributeParameterBag->expects($this->once()) |
|
| 69 | ->method('all') |
|
| 70 | ->will($this->returnValue([ |
|
| 71 | // the collection of attributesd |
|
| 72 | ])); |
|
| 73 | ||
| 74 | $this->queryParameterBag = $this |
|
| 75 | ->getMockBuilder('Symfony\Component\HttpFoundation\ParameterBag') |
|
| 76 | ->setMethods(['get']) |
|
| 77 | ->disableOriginalConstructor() |
|
| 78 | ->getMock(); |
|
| 79 | $this->queryParameterBag->method('get') |
|
| 80 | ->will($this->returnValue([ |
|
| 81 | // the collection of attributesd |
|
| 82 | ])); |
|
| 83 | ||
| 84 | $this->request = $this |
|
| 85 | ->getMockBuilder('Symfony\Component\HttpFoundation\Request') |
|
| 86 | ->disableOriginalConstructor() |
|
| 87 | ->getMock(); |
|
| 88 | $this->request->attributes = $this->attributeParameterBag; |
|
| 89 | $this->request->query = $this->queryParameterBag; |
|
| 90 | ||
| 91 | $this->repository->setRequest($this->request); |
|
| 92 | ||
| 93 | $this->assertEquals( |
|
| 94 | QueryBuilderOptions::fromArray([ |
|
| 95 | 'filtering' => [], |
|
| 96 | 'orFiltering' => [], |
|
| 97 | 'limit' => [], |
|
| 98 | 'page' => [], |
|
| 99 | 'filters' => [], |
|
| 100 | 'orFilters' => [], |
|
| 101 | 'sorting' => [], |
|
| 102 | 'rel' => [], |
|
| 103 | 'printing' => [], |
|
| 104 | 'select' => [], |
|
| 105 | ]), |
|
| 106 | $this->repository->getQueryBuilderOptions() |
|
| 107 | ); |
|
| 108 | } |
|
| 109 | ||
| 110 | /** |
|
| 111 | * @covers Mado\QueryBundle\Queries\AbstractQuery::__construct |
|
| @@ 119-168 (lines=50) @@ | ||
| 116 | * @covers Mado\QueryBundle\Repositories\BaseRepository::setQueryOptionsFromRequest |
|
| 117 | * @covers Mado\QueryBundle\Repositories\BaseRepository::getQueryBuilderOptions |
|
| 118 | */ |
|
| 119 | public function testBuildQueryOptionsFromRequest() |
|
| 120 | { |
|
| 121 | $this->attributeParameterBag = $this |
|
| 122 | ->getMockBuilder('Symfony\Component\HttpFoundation\ParameterBag') |
|
| 123 | ->setMethods(['all']) |
|
| 124 | ->disableOriginalConstructor() |
|
| 125 | ->getMock(); |
|
| 126 | $this->attributeParameterBag->expects($this->once()) |
|
| 127 | ->method('all') |
|
| 128 | ->will($this->returnValue([ |
|
| 129 | // the collection of attributesd |
|
| 130 | ])); |
|
| 131 | ||
| 132 | $this->queryParameterBag = $this |
|
| 133 | ->getMockBuilder('Symfony\Component\HttpFoundation\ParameterBag') |
|
| 134 | ->setMethods([ |
|
| 135 | 'get', |
|
| 136 | ]) |
|
| 137 | ->disableOriginalConstructor() |
|
| 138 | ->getMock(); |
|
| 139 | $this->queryParameterBag->method('get') |
|
| 140 | ->will($this->returnValue([ |
|
| 141 | // the collection of attributesd |
|
| 142 | ])); |
|
| 143 | ||
| 144 | $this->request = $this |
|
| 145 | ->getMockBuilder('Symfony\Component\HttpFoundation\Request') |
|
| 146 | ->disableOriginalConstructor() |
|
| 147 | ->getMock(); |
|
| 148 | $this->request->attributes = $this->attributeParameterBag; |
|
| 149 | $this->request->query = $this->queryParameterBag; |
|
| 150 | ||
| 151 | $this->repository->setQueryOptionsFromRequest($this->request); |
|
| 152 | ||
| 153 | $this->assertEquals( |
|
| 154 | QueryBuilderOptions::fromArray([ |
|
| 155 | 'filtering' => [], |
|
| 156 | 'orFiltering' => [], |
|
| 157 | 'limit' => [], |
|
| 158 | 'page' => [], |
|
| 159 | 'filters' => [], |
|
| 160 | 'orFilters' => [], |
|
| 161 | 'sorting' => [], |
|
| 162 | 'rel' => [], |
|
| 163 | 'printing' => [], |
|
| 164 | 'select' => [], |
|
| 165 | ]), |
|
| 166 | $this->repository->getQueryBuilderOptions() |
|
| 167 | ); |
|
| 168 | } |
|
| 169 | ||
| 170 | /** |
|
| 171 | * @covers Mado\QueryBundle\Queries\AbstractQuery::__construct |
|
| @@ 179-228 (lines=50) @@ | ||
| 176 | * @covers Mado\QueryBundle\Repositories\BaseRepository::setQueryOptionsFromRequest |
|
| 177 | * @covers Mado\QueryBundle\Repositories\BaseRepository::getQueryBuilderOptions |
|
| 178 | */ |
|
| 179 | public function testBuildQueryOptionsFromRequestWithCustomFilter() |
|
| 180 | { |
|
| 181 | $this->attributeParameterBag = $this |
|
| 182 | ->getMockBuilder('Symfony\Component\HttpFoundation\ParameterBag') |
|
| 183 | ->setMethods(['all']) |
|
| 184 | ->disableOriginalConstructor() |
|
| 185 | ->getMock(); |
|
| 186 | $this->attributeParameterBag->expects($this->once()) |
|
| 187 | ->method('all') |
|
| 188 | ->will($this->returnValue([ |
|
| 189 | // the collection of attributesd |
|
| 190 | ])); |
|
| 191 | ||
| 192 | $this->queryParameterBag = $this |
|
| 193 | ->getMockBuilder('Symfony\Component\HttpFoundation\ParameterBag') |
|
| 194 | ->setMethods([ |
|
| 195 | 'get', |
|
| 196 | ]) |
|
| 197 | ->disableOriginalConstructor() |
|
| 198 | ->getMock(); |
|
| 199 | $this->queryParameterBag->method('get') |
|
| 200 | ->will($this->returnValue([ |
|
| 201 | // the collection of attributesd |
|
| 202 | ])); |
|
| 203 | ||
| 204 | $this->request = $this |
|
| 205 | ->getMockBuilder('Symfony\Component\HttpFoundation\Request') |
|
| 206 | ->disableOriginalConstructor() |
|
| 207 | ->getMock(); |
|
| 208 | $this->request->attributes = $this->attributeParameterBag; |
|
| 209 | $this->request->query = $this->queryParameterBag; |
|
| 210 | ||
| 211 | $this->repository->setQueryOptionsFromRequest($this->request); |
|
| 212 | ||
| 213 | $this->assertEquals( |
|
| 214 | QueryBuilderOptions::fromArray([ |
|
| 215 | 'filtering' => [], |
|
| 216 | 'orFiltering' => [], |
|
| 217 | 'limit' => [], |
|
| 218 | 'page' => [], |
|
| 219 | 'filters' => [], |
|
| 220 | 'orFilters' => [], |
|
| 221 | 'sorting' => [], |
|
| 222 | 'rel' => [], |
|
| 223 | 'printing' => [], |
|
| 224 | 'select' => [], |
|
| 225 | ]), |
|
| 226 | $this->repository->getQueryBuilderOptions() |
|
| 227 | ); |
|
| 228 | } |
|
| 229 | ||
| 230 | /** |
|
| 231 | * @covers Mado\QueryBundle\Queries\AbstractQuery::__construct |
|