icingaweb2/test/php/library/Icinga/Web/Paginator/Adapter/QueryAdapterTest.php

73 lines
1.9 KiB
PHP
Raw Normal View History

<?php
// {{{ICINGA_LICENSE_HEADER}}}
// {{{ICINGA_LICENSE_HEADER}}}
namespace Tests\Icinga\Web\Paginator\Adapter;
use \Zend_Config;
use Icinga\Test\BaseTestCase;
use Icinga\Protocol\Statusdat\Reader;
2013-10-07 10:46:20 -04:00
use Icinga\Module\Monitoring\Backend;
use Icinga\Web\Paginator\Adapter\QueryAdapter;
class QueryAdapterTest extends BaseTestCase
{
private $cacheDir;
2013-10-07 10:46:20 -04:00
private $backendConfig;
private $resourceConfig;
public function setUp()
{
parent::setUp();
$this->cacheDir = '/tmp'. Reader::STATUSDAT_DEFAULT_CACHE_PATH;
if (!file_exists($this->cacheDir)) {
mkdir($this->cacheDir);
}
$statusdatFile = BaseTestCase::$testDir . '/res/status/icinga.status.dat';
$cacheFile = BaseTestCase::$testDir . '/res/status/icinga.objects.cache';
2013-10-07 10:46:20 -04:00
$this->backendConfig = new Zend_Config(
array(
'type' => 'statusdat'
)
);
$this->resourceConfig = new Zend_Config(
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'
)
);
}
public function testLimit1()
{
2013-10-07 10:46:20 -04:00
$backend = new Backend($this->backendConfig, $this->resourceConfig);
$query = $backend->select()->from('status');
$adapter = new QueryAdapter($query);
$this->assertEquals(30, $adapter->count());
$data = $adapter->getItems(0, 10);
$this->assertCount(10, $data);
$data = $adapter->getItems(10, 20);
$this->assertCount(10, $data);
}
public function testLimit2()
{
2013-10-07 10:46:20 -04:00
$backend = new Backend($this->backendConfig, $this->resourceConfig);
$query = $backend->select()->from('status');
$adapter = new QueryAdapter($query);
$this->assertEquals(30, $adapter->count());
}
}