Browse files

MDL-36206 - Unit Test - Create unit test for pagination bar

  • Loading branch information...
1 parent b3778a0 commit 0dbae598d718f672a8de68230c295634b66a0d3e @jsnfwlr jsnfwlr committed Nov 26, 2012
Showing with 31 additions and 9 deletions.
  1. +31 −9 lib/tests/outputcomponents_test.php
View
40 lib/tests/outputcomponents_test.php
@@ -32,7 +32,7 @@
/**
* Unit tests for the user_picture class
*/
-class user_picture_testcase extends advanced_testcase {
+class outputcomponents_testcase extends advanced_testcase {
public function test_fields_aliasing() {
$fields = user_picture::fields();
@@ -278,13 +278,6 @@ public function test_get_url() {
$up3 = new user_picture($user3);
$this->assertEquals($CFG->wwwroot.'/theme/image.php?theme=standard&component=core&rev=1&image=u%2Ff2', $up3->get_url($page, $renderer)->out(false));
}
-}
-
-
-/**
- * Unit tests for the custom_menu class
- */
-class custom_menu_testcase extends basic_testcase {
public function test_empty_menu() {
$emptymenu = new custom_menu();
@@ -395,4 +388,33 @@ public function test_multilang_support() {
$infomenu = array_pop( $children);
$this->assertFalse($infomenu->has_children());
}
-}
+
+ public function test_prepare() {
+ $expecteda = array('1',
+ '<a href="index.php?page=1">2</a>',
+ '<a href="index.php?page=2">3</a>',
+ '<a href="index.php?page=3">4</a>',
+ '<a href="index.php?page=4">5</a>',
+ '<a href="index.php?page=5">6</a>',
+ '<a href="index.php?page=6">7</a>',
+ '<a href="index.php?page=7">8</a>',
+ );
+ $expectedb = array('<a href="page?page=3">4</a>',
+ '<a href="page?page=4">5</a>',
+ '6',
+ '<a href="page?page=6">7</a>',
+ '<a href="page?page=7">8</a>',
+ );
+
+ $mpage = new moodle_page();
+ $rbase = new renderer_base($mpage, "/");
+ $pbara = new paging_bar(40, 0, 5, 'index.php');
+ $pbara->prepare($rbase,$mpage, "/");
+ $pbarb = new paging_bar(100, 5, 5, 'page');
+ $pbarb->maxdisplay = 5;
+ $pbarb->prepare($rbase,$mpage,"/");
+
+ $this->assertEquals($pbara->pagelinks, $expecteda);
+ $this->assertEquals($pbarb->pagelinks, $expectedb);
+ }
+}

0 comments on commit 0dbae59

Please sign in to comment.