parent
a844d33735
commit
1df4d9022b
|
@ -4,6 +4,7 @@
|
|||
|
||||
namespace Tests\Icinga\Web;
|
||||
|
||||
use \Mockery;
|
||||
use Icinga\Web\Hook;
|
||||
use Icinga\Test\BaseTestCase;
|
||||
|
||||
|
@ -27,26 +28,6 @@ class ErrorProneHookImplementation
|
|||
}
|
||||
}
|
||||
|
||||
class ObjectHookImplementation
|
||||
{
|
||||
private $test;
|
||||
|
||||
public function setTest($test)
|
||||
{
|
||||
$this->test = $test;
|
||||
}
|
||||
|
||||
public function getTest()
|
||||
{
|
||||
return $this->test;
|
||||
}
|
||||
|
||||
public function __toString()
|
||||
{
|
||||
return $this->getTest();
|
||||
}
|
||||
}
|
||||
|
||||
class HookTest extends BaseTestCase
|
||||
{
|
||||
public function setUp()
|
||||
|
@ -127,22 +108,20 @@ class HookTest extends BaseTestCase
|
|||
|
||||
public function testRegisterObject()
|
||||
{
|
||||
$o1 = new ObjectHookImplementation();
|
||||
$o1->setTest('$123123');
|
||||
$o1 = Mockery::mock('Some\\Name\\Space\\ObjectHook');
|
||||
$o1->test = '$123123';
|
||||
$o2 = Mockery::mock('Some\\Name\\Space\\ObjectHook');
|
||||
$o2->test = '#456456';
|
||||
|
||||
Hook::registerObject('Test', 'o1', $o1);
|
||||
|
||||
$o2 = new ObjectHookImplementation();
|
||||
$o2->setTest('#456456');
|
||||
|
||||
Hook::registerObject('Test', 'o2', $o2);
|
||||
|
||||
$this->assertInstanceOf('Tests\\Icinga\\Web\\ObjectHookImplementation', Hook::createInstance('Test', 'o1'));
|
||||
$this->assertInstanceOf('Tests\\Icinga\\Web\\ObjectHookImplementation', Hook::createInstance('Test', 'o2'));
|
||||
$this->assertInstanceOf('Some\\Name\\Space\\ObjectHook', Hook::createInstance('Test', 'o1'));
|
||||
$this->assertInstanceOf('Some\\Name\\Space\\ObjectHook', Hook::createInstance('Test', 'o2'));
|
||||
|
||||
$string = "";
|
||||
foreach (Hook::all('Test') as $hook) {
|
||||
$string .= (string)$hook;
|
||||
$string .= $hook->test;
|
||||
}
|
||||
$this->assertEquals('$123123#456456', $string);
|
||||
}
|
||||
|
@ -156,7 +135,7 @@ class HookTest extends BaseTestCase
|
|||
Hook::registerObject('Test', 'e1', 'STRING');
|
||||
}
|
||||
|
||||
public function testGetNullHooks()
|
||||
public function testGetZeroHooks()
|
||||
{
|
||||
$nh = Hook::all('DOES_NOT_EXIST');
|
||||
$this->assertInternalType('array', $nh);
|
||||
|
|
|
@ -8,55 +8,14 @@ namespace Tests\Icinga\Web\Paginator\ScrollingStyle;
|
|||
require_once realpath(ICINGA_LIBDIR . '/Icinga/Web/Paginator/ScrollingStyle/SlidingWithBorder.php');
|
||||
// @codingStandardsIgnoreEnd
|
||||
|
||||
use \Mockery;
|
||||
use \Zend_Config;
|
||||
use \Zend_Paginator_Adapter_Interface;
|
||||
use \Zend_Paginator;
|
||||
use Icinga\Test\BaseTestCase;
|
||||
use Icinga\Protocol\Statusdat\Reader;
|
||||
use Icinga\Web\Paginator\Adapter\QueryAdapter;
|
||||
use Icinga\Module\Monitoring\Backend;
|
||||
|
||||
class TestPaginatorAdapter implements Zend_Paginator_Adapter_Interface
|
||||
{
|
||||
private $items = array();
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
for ($i=0; $i<1000; $i++) {
|
||||
$this->items[] = array(
|
||||
'a' => mt_rand(0, 100),
|
||||
'b' => mt_rand(0, 100)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an collection of items for a page.
|
||||
*
|
||||
* @param integer $offset Page offset
|
||||
* @param integer $itemCountPerPage Number of items per page
|
||||
* @return array
|
||||
*/
|
||||
public function getItems($offset, $itemCountPerPage)
|
||||
{
|
||||
$out = array_slice($this->items, $offset, $itemCountPerPage, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* (PHP 5 >= 5.1.0)<br/>
|
||||
* Count elements of an object
|
||||
* @link http://php.net/manual/en/countable.count.php
|
||||
* @return int The custom count as an integer.
|
||||
* </p>
|
||||
* <p>
|
||||
* The return value is cast to an integer.
|
||||
*/
|
||||
public function count()
|
||||
{
|
||||
return count($this->items);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class SlidingwithborderTest extends BaseTestCase
|
||||
{
|
||||
private $cacheDir;
|
||||
|
@ -85,7 +44,7 @@ class SlidingwithborderTest extends BaseTestCase
|
|||
$this->resourceConfig = new Zend_Config(
|
||||
array(
|
||||
'status_file' => $statusdatFile,
|
||||
'object_file' => $cacheFile,
|
||||
'object_file' => $cacheFile,
|
||||
'type' => 'statusdat'
|
||||
)
|
||||
);
|
||||
|
@ -94,53 +53,44 @@ class SlidingwithborderTest extends BaseTestCase
|
|||
public function testGetPages1()
|
||||
{
|
||||
$backend = new Backend($this->backendConfig, $this->resourceConfig);
|
||||
$query = $backend->select()->from('status');
|
||||
|
||||
$adapter = new QueryAdapter($query);
|
||||
$adapter = new QueryAdapter($backend->select()->from('status'));
|
||||
|
||||
$this->assertEquals(30, $adapter->count());
|
||||
|
||||
$scrolingStyle = new \Icinga_Web_Paginator_ScrollingStyle_SlidingWithBorder();
|
||||
|
||||
$paginator = new \Zend_Paginator($adapter);
|
||||
|
||||
$pages = $scrolingStyle->getPages($paginator);
|
||||
$scrollingStyle = new \Icinga_Web_Paginator_ScrollingStyle_SlidingWithBorder();
|
||||
$paginator = new Zend_Paginator($adapter);
|
||||
|
||||
$pages = $scrollingStyle->getPages($paginator);
|
||||
$this->assertInternalType('array', $pages);
|
||||
$this->assertCount(3, $pages);
|
||||
}
|
||||
|
||||
public function testGetPages2()
|
||||
{
|
||||
$scrolingStyle = new \Icinga_Web_Paginator_ScrollingStyle_SlidingWithBorder();
|
||||
|
||||
$adapter = new TestPaginatorAdapter();
|
||||
|
||||
$paginator = new \Zend_Paginator($adapter);
|
||||
|
||||
$pages = $scrolingStyle->getPages($paginator);
|
||||
$scrollingStyle = new \Icinga_Web_Paginator_ScrollingStyle_SlidingWithBorder();
|
||||
$paginator = new Zend_Paginator($this->getPaginatorAdapter());
|
||||
|
||||
$pages = $scrollingStyle->getPages($paginator);
|
||||
$this->assertInternalType('array', $pages);
|
||||
|
||||
$this->assertCount(13, $pages);
|
||||
$this->assertEquals('...', $pages[11]);
|
||||
}
|
||||
|
||||
public function testGetPages3()
|
||||
{
|
||||
$scrolingStyle = new \Icinga_Web_Paginator_ScrollingStyle_SlidingWithBorder();
|
||||
|
||||
$adapter = new TestPaginatorAdapter();
|
||||
|
||||
$paginator = new \Zend_Paginator($adapter);
|
||||
$scrollingStyle = new \Icinga_Web_Paginator_ScrollingStyle_SlidingWithBorder();
|
||||
$paginator = new Zend_Paginator($this->getPaginatorAdapter());
|
||||
$paginator->setCurrentPageNumber(9);
|
||||
|
||||
$pages = $scrolingStyle->getPages($paginator);
|
||||
|
||||
$pages = $scrollingStyle->getPages($paginator);
|
||||
$this->assertInternalType('array', $pages);
|
||||
|
||||
$this->assertCount(16, $pages);
|
||||
$this->assertEquals('...', $pages[3]);
|
||||
$this->assertEquals('...', $pages[14]);
|
||||
}
|
||||
|
||||
protected function getPaginatorAdapter()
|
||||
{
|
||||
return Mockery::mock('\Zend_Paginator_Adapter_Interface')->shouldReceive('count')->andReturn(1000)->getMock();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue