2013-06-10 11:45:13 -04:00
|
|
|
<?php
|
2014-04-10 04:32:50 -04:00
|
|
|
// {{{ICINGA_LICENSE_HEADER}}}
|
|
|
|
|
// {{{ICINGA_LICENSE_HEADER}}}
|
2013-06-10 11:45:13 -04:00
|
|
|
|
2014-04-09 08:18:14 -04:00
|
|
|
namespace Tests\Icinga\Web\Paginator\Adapter;
|
2013-06-10 11:45:13 -04:00
|
|
|
|
2014-04-09 08:18:14 -04:00
|
|
|
use \Zend_Config;
|
2014-04-10 04:32:50 -04:00
|
|
|
use Icinga\Test\BaseTestCase;
|
2013-06-10 11:45:13 -04:00
|
|
|
use Icinga\Protocol\Statusdat\Reader;
|
2013-10-07 10:46:20 -04:00
|
|
|
use Icinga\Module\Monitoring\Backend;
|
2014-04-09 08:18:14 -04:00
|
|
|
use Icinga\Web\Paginator\Adapter\QueryAdapter;
|
2013-06-10 11:45:13 -04:00
|
|
|
|
2014-04-10 04:32:50 -04:00
|
|
|
class QueryAdapterTest extends BaseTestCase
|
2013-06-10 11:45:13 -04:00
|
|
|
{
|
|
|
|
|
private $cacheDir;
|
|
|
|
|
|
2013-10-07 10:46:20 -04:00
|
|
|
private $backendConfig;
|
|
|
|
|
|
|
|
|
|
private $resourceConfig;
|
2013-06-10 11:45:13 -04:00
|
|
|
|
2014-04-11 09:31:29 -04:00
|
|
|
public function setUp()
|
2013-06-10 11:45:13 -04:00
|
|
|
{
|
2014-04-11 09:31:29 -04:00
|
|
|
parent::setUp();
|
2013-06-10 11:45:13 -04:00
|
|
|
$this->cacheDir = '/tmp'. Reader::STATUSDAT_DEFAULT_CACHE_PATH;
|
|
|
|
|
|
|
|
|
|
if (!file_exists($this->cacheDir)) {
|
|
|
|
|
mkdir($this->cacheDir);
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-10 04:32:50 -04:00
|
|
|
$statusdatFile = BaseTestCase::$testDir . '/res/status/icinga.status.dat';
|
|
|
|
|
$cacheFile = BaseTestCase::$testDir . '/res/status/icinga.objects.cache';
|
2013-06-10 11:45:13 -04:00
|
|
|
|
2013-10-07 10:46:20 -04:00
|
|
|
$this->backendConfig = new Zend_Config(
|
|
|
|
|
array(
|
|
|
|
|
'type' => 'statusdat'
|
|
|
|
|
)
|
|
|
|
|
);
|
|
|
|
|
$this->resourceConfig = new Zend_Config(
|
2013-06-10 11:45:13 -04:00
|
|
|
array(
|
2013-10-07 10:46:20 -04:00
|
|
|
'status_file' => $statusdatFile,
|
2013-10-19 14:09:17 -04:00
|
|
|
'object_file' => $cacheFile,
|
2013-10-07 10:46:20 -04:00
|
|
|
'type' => 'statusdat'
|
2013-06-10 11:45:13 -04:00
|
|
|
)
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testLimit1()
|
|
|
|
|
{
|
2013-10-07 10:46:20 -04:00
|
|
|
$backend = new Backend($this->backendConfig, $this->resourceConfig);
|
2013-07-19 05:32:36 -04:00
|
|
|
$query = $backend->select()->from('status');
|
2013-06-10 11:45:13 -04:00
|
|
|
|
2013-06-11 05:09:28 -04:00
|
|
|
$adapter = new QueryAdapter($query);
|
2013-06-10 11:45:13 -04:00
|
|
|
|
2013-06-11 05:09:28 -04:00
|
|
|
$this->assertEquals(30, $adapter->count());
|
2013-06-10 11:45:13 -04:00
|
|
|
|
2013-06-11 05:09:28 -04:00
|
|
|
$data = $adapter->getItems(0, 10);
|
2013-06-10 11:45:13 -04:00
|
|
|
|
|
|
|
|
$this->assertCount(10, $data);
|
|
|
|
|
|
2013-06-11 05:09:28 -04:00
|
|
|
$data = $adapter->getItems(10, 20);
|
2013-06-10 11:45:13 -04:00
|
|
|
$this->assertCount(10, $data);
|
|
|
|
|
}
|
2013-06-11 05:09:28 -04:00
|
|
|
|
|
|
|
|
public function testLimit2()
|
|
|
|
|
{
|
2013-10-07 10:46:20 -04:00
|
|
|
$backend = new Backend($this->backendConfig, $this->resourceConfig);
|
2013-07-19 05:32:36 -04:00
|
|
|
$query = $backend->select()->from('status');
|
2013-06-11 05:09:28 -04:00
|
|
|
|
|
|
|
|
$adapter = new QueryAdapter($query);
|
|
|
|
|
$this->assertEquals(30, $adapter->count());
|
|
|
|
|
}
|
2013-09-04 12:28:35 -04:00
|
|
|
}
|