ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
ilStudyProgrammeDashGUITest.php
Go to the documentation of this file.
1<?php declare(strict_types=1);
2
3/* Copyright (c) 2020 Nils Haagen <nils.haagen@concepts-and-training.de> Extended GPL, see docs/LICENSE */
4
5use PHPUnit\Framework\TestCase;
6
11{
12 public function __construct()
13 {
14 }
15
16 public function mockCalculatePercent($prg, int $current_points)
17 {
18 return $this->calculatePercent($prg, $current_points);
19 }
20}
21
25class ilStudyProgrammeDashGUITest extends TestCase
26{
27 protected function setUp() : void
28 {
29 $this->gui = new mockSPRGDashGUI();
30 $this->prg = $this->getMockBuilder(ilObjStudyProgramme::class)
31 ->disableOriginalConstructor()
32 ->setMethods([
33 'hasLPChildren',
34 'getAllPrgChildren',
35 'getPoints'
36 ])
37 ->getMock();
38 }
39
40 public function userPointsDataProvider()
41 {
42 return [
43 'zero' => [0, 0],
44 'one' => [1, 0.63],
45 'ten' => [10, 6.25],
46 'fiftyfive' => [55, 34.38],
47 'hundred' => [100, 62.5],
48 'oneOone' => [101, 63.13],
49 'onesixty' => [160, 100]
50 ];
51 }
52
56 public function testPercentageWithoutChildren(int $current_user_points)
57 {
58 $this->prg->method('hasLPChildren')
59 ->willReturn(false);
60 $this->prg->method('getAllPrgChildren')
61 ->willReturn([]);
62
63 list($minimum_percents, $current_percents)
64 = $this->gui->mockCalculatePercent($this->prg, $current_user_points);
65
66 $this->assertEquals(0, $minimum_percents);
67 $this->assertEquals(0, $current_percents);
68 }
69
73 public function testPercentageWithCoursesAtTopLevel(int $current_user_points)
74 {
75 $this->prg->method('hasLPChildren')
76 ->willReturn(true);
77
78 list($minimum_percents, $current_percents)
79 = $this->gui->mockCalculatePercent($this->prg, $current_user_points);
80
81 $this->assertEquals(100, $minimum_percents);
82 if ($current_user_points == 0) {
83 $this->assertEquals(0, $current_percents);
84 }
85 if ($current_user_points > 0) {
86 $this->assertEquals(100, $current_percents);
87 }
88 }
89
93 public function testPercentageWithPrograms(int $current_user_points, float $expected)
94 {
95 $node = $this->getMockBuilder(ilObjStudyProgramme::class)
96 ->disableOriginalConstructor()
97 ->setMethods(['getPoints'])
98 ->getMock();
99
100 $node1 = clone $node;
101 $node1->method('getPoints')->willReturn(100);
102 $node2 = clone $node;
103 $node2->method('getPoints')->willReturn(50);
104 $node3 = clone $node;
105 $node3->method('getPoints')->willReturn(5);
106 $node4 = clone $node;
107 $node4->method('getPoints')->willReturn(5);
108
109 $this->prg->method('hasLPChildren')
110 ->willReturn(false);
111 $this->prg->method('getAllPrgChildren')
112 ->willReturn([$node1, $node2, $node3, $node4]);
113
114 $this->prg->method('getPoints')->willReturn(60);
115
116 list($minimum_percents, $current_percents)
117 = $this->gui->mockCalculatePercent($this->prg, $current_user_points);
118
119 $this->assertEquals(37.5, $minimum_percents); //37.5 = (160 max points / 60 root-prg points) * 100
120 $this->assertEquals($expected, $current_percents);
121 }
122}
An exception for terminatinating execution or to throw for unit testing.
TestCase for SPRG-Section of dashboard.
testPercentageWithoutChildren(int $current_user_points)
@dataProvider userPointsDataProvider
testPercentageWithCoursesAtTopLevel(int $current_user_points)
@dataProvider userPointsDataProvider
testPercentageWithPrograms(int $current_user_points, float $expected)
@dataProvider userPointsDataProvider
calculatePercent(ilObjStudyProgramme $prg, int $current_points)
Encapsulation of GUI.
mockCalculatePercent($prg, int $current_points)