/** * Method to test getList(). * * @return void * * @covers Windwalker\Model\ListModel::getList */ public function testGetList() { $query = \JFactory::getDbo()->getQuery(true); $query->select('`foo`')->from('#__test_table')->where('`type` = "fruit"'); $expected = array((object) array('foo' => 'bad'), (object) array('foo' => 'bak'), (object) array('foo' => 'bal'), (object) array('foo' => 'bat'), (object) array('foo' => 'bay'), (object) array('foo' => 'baz')); $listModel = new ListModel(); $testQuery = clone $query; $this->assertEquals($expected, $listModel->getList($testQuery)); $expected3 = array_slice($expected, 2, 3); $testQuery = clone $query; $this->assertEquals($expected3, $listModel->getList($testQuery, 2, 3)); $testQuery = clone $query; $this->assertEquals(array(), $listModel->getList($testQuery, 2)); }
/** * getList * * @param string $query * @param int $limitstart * @param int $limit * * @return array */ public function getList($query, $limitstart = 0, $limit = 0) { $plugins = parent::getList($query, 0, 0); $total = count($plugins); $this->cache[$this->getStoreId('getTotal')] = $total; $searches = $this->state->get('search'); if (!empty($searches['plugin.name'])) { foreach ($plugins as $i => $item) { if (!preg_match("/{$searches['plugin.name']}/i", $item->name)) { unset($plugins[$i]); } } } if ($total < $limitstart) { $limitstart = 0; $this->state->set('list.start', 0); } return array_slice($plugins, $limitstart, $limit ? $limit : null); }