2013-06-03 15:34:57 +02:00
|
|
|
<?php
|
|
|
|
namespace Tests\Icinga\Protocol\Ldap;
|
2013-06-03 16:56:08 +02:00
|
|
|
require_once '../../library/Icinga/Protocol/Ldap/Query.php';
|
|
|
|
require_once '../../library/Icinga/Protocol/Ldap/Connection.php';
|
|
|
|
require_once '../../library/Icinga/Protocol/Ldap/LdapUtils.php';
|
2013-10-22 16:24:49 +02:00
|
|
|
require_once('Zend/Config.php');
|
2013-06-03 15:34:57 +02:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* Test class for Query
|
2013-09-04 18:27:16 +02:00
|
|
|
* Created Wed, 13 Mar 2013 12:57:11 +0000
|
2013-06-03 15:34:57 +02:00
|
|
|
*
|
|
|
|
**/
|
|
|
|
class QueryTest extends \PHPUnit_Framework_TestCase
|
|
|
|
{
|
|
|
|
private function emptySelect()
|
|
|
|
{
|
2013-10-22 16:24:49 +02:00
|
|
|
$config = new \Zend_Config(
|
|
|
|
array(
|
|
|
|
'hostname' => 'localhost',
|
|
|
|
'root_dn' => 'dc=example,dc=com',
|
|
|
|
'bind_dn' => 'cn=user,ou=users,dc=example,dc=com',
|
|
|
|
'bind_pw' => '***'
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
$connection = new \Icinga\Protocol\Ldap\Connection($config);
|
2013-06-03 15:34:57 +02:00
|
|
|
return $connection->select();
|
|
|
|
}
|
|
|
|
|
|
|
|
private function prepareSelect()
|
|
|
|
{
|
|
|
|
$select = $this->emptySelect();
|
|
|
|
$select->from('dummyClass', array('testIntColumn', 'testStringColumn'))
|
|
|
|
->where('testIntColumn', 1)
|
|
|
|
->where('testStringColumn', 'test')
|
|
|
|
->where('testWildcard', 'abc*')
|
|
|
|
->order('testIntColumn')
|
|
|
|
->limit(10, 4);
|
|
|
|
return $select;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test for Query::Count() - shall be tested with connection
|
|
|
|
*
|
|
|
|
**/
|
|
|
|
public function testCount()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2013-09-04 18:27:16 +02:00
|
|
|
* Test for Query::Limit()
|
2013-06-03 15:34:57 +02:00
|
|
|
*
|
|
|
|
**/
|
|
|
|
public function testLimit()
|
|
|
|
{
|
|
|
|
$select = $this->prepareSelect();
|
|
|
|
$this->assertEquals(10, $select->getLimit());
|
|
|
|
$this->assertEquals(4, $select->getOffset());
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2013-09-04 18:27:16 +02:00
|
|
|
* Test for Query::HasLimit()
|
2013-06-03 15:34:57 +02:00
|
|
|
*
|
|
|
|
**/
|
|
|
|
public function testHasLimit()
|
|
|
|
{
|
|
|
|
$select = $this->emptySelect();
|
|
|
|
$this->assertFalse($select->hasLimit());
|
|
|
|
$select = $this->prepareSelect();
|
|
|
|
$this->assertTrue($select->hasLimit());
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2013-09-04 18:27:16 +02:00
|
|
|
* Test for Query::HasOffset()
|
2013-06-03 15:34:57 +02:00
|
|
|
*
|
|
|
|
**/
|
|
|
|
public function testHasOffset()
|
|
|
|
{
|
|
|
|
$select = $this->emptySelect();
|
|
|
|
$this->assertFalse($select->hasOffset());
|
|
|
|
$select = $this->prepareSelect();
|
|
|
|
$this->assertTrue($select->hasOffset());
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2013-09-04 18:27:16 +02:00
|
|
|
* Test for Query::GetLimit()
|
2013-06-03 15:34:57 +02:00
|
|
|
*
|
|
|
|
**/
|
|
|
|
public function testGetLimit()
|
|
|
|
{
|
|
|
|
$select = $this->prepareSelect();
|
|
|
|
$this->assertEquals(10, $select->getLimit());
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2013-09-04 18:27:16 +02:00
|
|
|
* Test for Query::GetOffset()
|
2013-06-03 15:34:57 +02:00
|
|
|
*
|
|
|
|
**/
|
|
|
|
public function testGetOffset()
|
|
|
|
{
|
|
|
|
$select = $this->prepareSelect();
|
|
|
|
$this->assertEquals(10, $select->getLimit());
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2013-09-04 18:27:16 +02:00
|
|
|
* Test for Query::FetchTree()
|
2013-06-03 15:34:57 +02:00
|
|
|
*
|
|
|
|
**/
|
|
|
|
public function testFetchTree()
|
|
|
|
{
|
|
|
|
$this->markTestIncomplete('testFetchTree is not implemented yet - requires real LDAP');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test for Query::FetchAll() - shall be tested with connection
|
|
|
|
*
|
|
|
|
**/
|
|
|
|
public function testFetchAll()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test for Query::FetchRow() - shall be tested with connection
|
|
|
|
*
|
|
|
|
**/
|
|
|
|
public function testFetchRow()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2013-09-04 18:27:16 +02:00
|
|
|
* Test for Query::FetchOne()
|
2013-06-03 15:34:57 +02:00
|
|
|
*
|
|
|
|
**/
|
|
|
|
public function testFetchOne()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2013-09-04 18:27:16 +02:00
|
|
|
* Test for Query::FetchPairs()
|
2013-06-03 15:34:57 +02:00
|
|
|
*
|
|
|
|
**/
|
|
|
|
public function testFetchPairs()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2013-09-04 18:27:16 +02:00
|
|
|
* Test for Query::From()
|
2013-06-03 15:34:57 +02:00
|
|
|
*
|
|
|
|
**/
|
|
|
|
public function testFrom()
|
|
|
|
{
|
|
|
|
return $this->testListFields();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2013-09-04 18:27:16 +02:00
|
|
|
* Test for Query::Where()
|
2013-06-03 15:34:57 +02:00
|
|
|
*
|
|
|
|
**/
|
|
|
|
public function testWhere()
|
|
|
|
{
|
|
|
|
$this->markTestIncomplete('testWhere is not implemented yet');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2013-09-04 18:27:16 +02:00
|
|
|
* Test for Query::Order()
|
2013-06-03 15:34:57 +02:00
|
|
|
*
|
|
|
|
**/
|
|
|
|
public function testOrder()
|
|
|
|
{
|
|
|
|
$select = $this->emptySelect()->order('bla');
|
|
|
|
// tested by testGetSortColumns
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2013-09-04 18:27:16 +02:00
|
|
|
* Test for Query::ListFields()
|
2013-06-03 15:34:57 +02:00
|
|
|
*
|
|
|
|
**/
|
|
|
|
public function testListFields()
|
|
|
|
{
|
|
|
|
$select = $this->prepareSelect();
|
|
|
|
$this->assertEquals(
|
|
|
|
array('testIntColumn', 'testStringColumn'),
|
|
|
|
$select->listFields()
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2013-09-04 18:27:16 +02:00
|
|
|
* Test for Query::GetSortColumns()
|
2013-06-03 15:34:57 +02:00
|
|
|
*
|
|
|
|
**/
|
|
|
|
public function testGetSortColumns()
|
|
|
|
{
|
|
|
|
$select = $this->prepareSelect();
|
|
|
|
$cols = $select->getSortColumns();
|
|
|
|
$this->assertEquals('testIntColumn', $cols[0][0]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test for Query::Paginate() - requires real result
|
|
|
|
*
|
|
|
|
**/
|
|
|
|
public function testPaginate()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2013-09-04 18:27:16 +02:00
|
|
|
* Test for Query::__toString()
|
2013-06-03 15:34:57 +02:00
|
|
|
*
|
|
|
|
**/
|
|
|
|
public function test__toString()
|
|
|
|
{
|
|
|
|
$select = $this->prepareSelect();
|
|
|
|
$res = '(&(objectClass=dummyClass)(testIntColumn=1)(testStringColumn=test)(testWildcard=abc*))';
|
|
|
|
$this->assertEquals($res, (string) $select);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2013-09-04 18:27:16 +02:00
|
|
|
* Test for Query::__destruct()
|
2013-06-03 15:34:57 +02:00
|
|
|
*
|
|
|
|
**/
|
|
|
|
public function test__destruct()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|