summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorknut <>2007-06-04 21:35:25 +0000
committerknut <>2007-06-04 21:35:25 +0000
commitb7d5fc392611f0cb7f1ff6d87b758cb9572c7806 (patch)
treedd17d0cc3fa64b146d9fc4c6c3f32023120fa0ec /tests
parentb66bf6ee73875c326923a5a3d6d1444bcb8014b9 (diff)
implemented unit tests for TPagedList
Diffstat (limited to 'tests')
-rw-r--r--tests/unit/Collections/TPagedListTest.php173
1 files changed, 151 insertions, 22 deletions
diff --git a/tests/unit/Collections/TPagedListTest.php b/tests/unit/Collections/TPagedListTest.php
index f7c3bb63..e5f2036e 100644
--- a/tests/unit/Collections/TPagedListTest.php
+++ b/tests/unit/Collections/TPagedListTest.php
@@ -3,6 +3,29 @@ require_once dirname(__FILE__).'/../phpunit.php';
Prado::using('System.Collections.TPagedList');
+class MyPagedList extends TPagedList {
+
+ private $_isPageIndexChanged = false;
+ private $_hasFetchedData = false;
+
+ public function pageIndexChanged($sender, $param) {
+ $this->_isPageIndexChanged = true;
+ }
+
+ public function fetchData($sender, $param) {
+ $this->_hasFetchedData = true;
+ }
+
+ public function isPageIndexChanged() {
+ return $this->_isPageIndexChanged;
+ }
+
+ public function hasFetchedData() {
+ return $this->_hasFetchedData;
+ }
+
+}
+
/**
* @package System.Collections
*/
@@ -16,83 +39,189 @@ class TPagedListTest extends PHPUnit_Framework_TestCase {
public function testConstruct() {
$list = new TPagedList();
- self::assertEquals(true, $list->getReadOnly());
- self::assertEquals(-1, $list->getVirtualCount());
+ self::assertEquals(true, $list->ReadOnly);
+ self::assertEquals(-1, $list->VirtualCount);
$list = new TPagedList(array(1, 2, 3));
- $list->setPageSize(3);
- self::assertEquals(3, $list->getCount());
+ $list->PageSize = 3;
+ self::assertEquals(3, $list->Count);
}
public function testCustomPaging() {
- throw new PHPUnit_Framework_IncompleteTestError();
+ $list = new TPagedList();
+ $list->CustomPaging = true;
+ self::assertEquals(true, $list->CustomPaging);
+ $list->CustomPaging = false;
+ self::assertEquals(false, $list->CustomPaging);
}
public function testPageSize() {
- throw new PHPUnit_Framework_IncompleteTestError();
+ $list = new TPagedList();
+ $list->PageSize = 5;
+ self::assertEquals(5, $list->PageSize);
+ }
+
+ public function testCanNotSetInvalidPageSize() {
+ $list = new TPagedList();
+ try {
+ $list->PageSize = 0;
+ } catch(TInvalidDataValueException $e) {
+ return;
+ }
+ self::fail('An expected TInvalidDataValueException was not raised');
}
public function testCurrentPageIndex() {
- throw new PHPUnit_Framework_IncompleteTestError();
+ $list = new TPagedList(array(1, 2, 3));
+ $list->PageSize = 1;
+ $list->CurrentPageIndex = 2;
+ self::assertEquals(2, $list->CurrentPageIndex);
}
public function testOnPageIndexChanged() {
- throw new PHPUnit_Framework_IncompleteTestError();
+ $list = new TPagedList(array(1, 2, 3, 4, 5));
+ $list->PageSize = 1;
+ $list->CurrentPageIndex = 1;
+ $oldPage = $list->CurrentPageIndex;
+ $myList = new MyPagedList();
+ $list->attachEventHandler('OnPageIndexChanged', array($myList, 'pageIndexChanged'));
+ self::assertEquals(false, $myList->isPageIndexChanged());
+ $list->onPageIndexChanged(new TPagedListPageChangedEventParameter($oldPage));
+ self::assertEquals(true, $myList->isPageIndexChanged());
}
public function testOnFetchData() {
- throw new PHPUnit_Framework_IncompleteTestError();
+ $list = new TPagedList(array(1, 2, 3, 4));
+ $list->CustomPaging = true;
+ $list->PageSize = 2;
+ $list->gotoPage(0);
+ $myList = new MyPagedList();
+ $list->attachEventHandler('OnFetchData', array($myList, 'fetchData'));
+ self::assertEquals(false, $myList->hasFetchedData());
+ $list->onFetchData(new TPagedListFetchDataEventParameter($list->CurrentPageIndex, $this->PageSize*$this->CurrentPageIndex, $list->PageSize));
+ self::assertEquals(true, $myList->hasFetchedData());
}
public function testGotoPage() {
- throw new PHPUnit_Framework_IncompleteTestError();
+ $list = new TPagedList(array(1, 2, 3));
+ $list->PageSize = 1;
+ self::assertEquals(2, $list->gotoPage(2));
+ self::assertEquals(false, $list->gotoPage(4));
}
public function testNextPage() {
- throw new PHPUnit_Framework_IncompleteTestError();
+ $list = new TPagedList(array(1, 2));
+ $list->PageSize = 1;
+ $list->gotoPage(0);
+ self::assertEquals(1, $list->nextPage());
+ self::assertEquals(false, $list->nextPage());
}
public function testPreviousPage() {
- throw new PHPUnit_Framework_IncompleteTestError();
+ $list = new TPagedList(array(1, 2));
+ $list->PageSize = 1;
+ $list->gotoPage(1);
+ self::assertEquals(0, $list->previousPage());
+ self::assertEquals(false, $list->previousPage());
}
public function testVirtualCount() {
- throw new PHPUnit_Framework_IncompleteTestError();
+ $list = new TPagedList(array(1, 2));
+ $list->VirtualCount = -10;
+ self::assertEquals(-1, $list->VirtualCount);
+ $list->VirtualCount = 5;
+ self::assertEquals(5, $list->VirtualCount);
+ }
+
+ public function testPageCount() {
+ $list = new TPagedList(array(1, 2, 3));
+ $list->PageSize = 1;
+ $list->CustomPaging = true;
+ self::assertEquals(-1, $list->PageCount);
+ $list->VirtualCount = 3;
+ self::assertEquals(3, $list->PageCount);
+ $list->CustomPaging = false;
+ self::assertEquals(3, $list->PageCount);
}
public function testIsFirstPage() {
- throw new PHPUnit_Framework_IncompleteTestError();
+ $list = new TPagedList(array(1, 2, 3));
+ $list->PageSize = 1;
+ $list->gotoPage(0);
+ self::assertEquals(true, $list->IsFirstPage);
+ $list->gotoPage(1);
+ self::assertEquals(false, $list->IsFirstPage);
}
public function testIsLastPage() {
- throw new PHPUnit_Framework_IncompleteTestError();
+ $list = new TPagedList(array(1, 2, 3));
+ $list->PageSize = 1;
+ $list->gotoPage(0);
+ self::assertEquals(false, $list->IsLastPage);
+ $list->gotoPage(2);
+ self::assertEquals(true, $list->IsLastPage);
}
public function testGetCount() {
- throw new PHPUnit_Framework_IncompleteTestError();
+ $list = new TPagedList(array(1, 2, 3));
+ $list->PageSize = 1;
+ self::assertEquals(1, $list->Count);
+ $list->CustomPaging = true;
+ self::assertEquals(3, $list->Count);
}
public function testGetIterator() {
- throw new PHPUnit_Framework_IncompleteTestError();
+ $list = new TPagedList(array(1, 2));
+ $list->CustomPaging = true;
+ self::assertType('TListIterator', $list->getIterator());
+ $n = 0;
+ $found = 0;
+ foreach($list as $index => $item) {
+ foreach($list as $a => $b); // test of iterator
+ $n++;
+ if($index === 0 && $item === 1) {
+ $found++;
+ }
+ if($index === 1 && $item === 2) {
+ $found++;
+ }
+ }
+ self::assertTrue($n == 2 && $found == 2);
}
public function testItemAt() {
- throw new PHPUnit_Framework_IncompleteTestError();
+ $list = new TPagedList(array(1, 2, 3));
+ $list->CustomPaging = true;
+ self::assertEquals(1, $list[0]);
+ $list->CustomPaging = false;
+ $list->PageSize = 1;
+ $list->CurrentPageIndex = 0;
+ self::assertEquals(1, $list[0]);
}
public function testIndexOf() {
- throw new PHPUnit_Framework_IncompleteTestError();
+ $list = new TPagedList(array(1, 2, 3));
+ $list->CustomPaging = true;
+ self::assertEquals(0, $list->indexOf(1));
+ self::assertEquals(-1, $list->indexOf(0));
}
public function testOffsetExists() {
- throw new PHPUnit_Framework_IncompleteTestError();
+ $list = new TPagedList(array(1, 2, 3));
+ $list->CustomPaging = true;
+ self::assertEquals(true, isset($list[0]));
+ self::assertEquals(false, isset($list[4]));
}
public function testOffsetGet() {
- throw new PHPUnit_Framework_IncompleteTestError();
+ $list = new TPagedList(array(1, 2, 3));
+ $list->CustomPaging = true;
+ self::assertEquals(2, $list[1]);
}
public function testToArray() {
- throw new PHPUnit_Framework_IncompleteTestError();
+ $list = new TPagedList(array(1, 2, 3));
+ $list->CustomPaging = true;
+ self::assertEquals(array(1, 2, 3), $list->toArray());
}
}