MDL-36206 - Unit Test - Create unit test for pagination bar
authorJason Fowler <phalacee@gmail.com>
Mon, 26 Nov 2012 02:07:31 +0000 (10:07 +0800)
committerDamyon Wiese <damyon@moodle.com>
Tue, 5 Feb 2013 06:14:19 +0000 (14:14 +0800)
lib/tests/outputcomponents_test.php

index 684d299..dbac8c4 100644 (file)
@@ -32,7 +32,7 @@ require_once($CFG->libdir . '/outputcomponents.php');
 /**
  * Unit tests for the user_picture class
  */
 /**
  * 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();
 
     public function test_fields_aliasing() {
         $fields = user_picture::fields();
@@ -275,13 +275,6 @@ class user_picture_testcase extends advanced_testcase {
         $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));
     }
         $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();
 
     public function test_empty_menu() {
         $emptymenu = new custom_menu();
@@ -392,4 +385,33 @@ EOF;
         $infomenu = array_pop( $children);
         $this->assertFalse($infomenu->has_children());
     }
         $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);
+    }
 }
 }