ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
ConsumerTest.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
23 use ilCtrl;
25 use ilSetting;
33 
34 require_once __DIR__ . '/bootstrap.php';
35 
36 class ConsumerTest extends TestCase
37 {
38  use ContainerMock;
39 
40  public function testConstruct(): void
41  {
42  $this->assertInstanceOf(Consumer::class, new Consumer($this->mock(Container::class)));
43  }
44 
45  public function testId(): void
46  {
47  $this->assertSame(Consumer::ID, (new Consumer($this->mock(Container::class)))->id());
48  }
49 
50  public function testDisabledUses(): void
51  {
52  $by_trying = $this->mockTree(ByTrying::class, ['transform' => false]);
53  $settings = $this->mockMethod(ilSetting::class, 'get', ['dpro_enabled', ''], 'false');
54 
55  $container = $this->mockTree(Container::class, [
56  'settings' => $settings,
57  'refinery' => ['byTrying' => $by_trying],
58  ]);
59  $container->method('offsetGet')->with('ilObjDataCache')->willReturn($this->mock(ilObjectDataCache::class));
60 
61  $slot = $this->mock(UseSlot::class);
62  $slot->expects(self::once())->method('hasDocuments')->willReturn($slot);
63  $slot->expects(self::once())->method('hasHistory')->willReturn($slot);
64  $slot->expects(self::once())->method('hasPublicApi')->willReturn($slot);
65  $slot->expects(self::once())->method('hasPublicPage')->willReturn($slot);
66 
67  $instance = new Consumer($container);
68 
69  $this->assertSame($slot, $instance->uses($slot, $this->mock(LazyProvide::class)));
70  }
71 
72  public function testUsesWithoutAcceptance(): void
73  {
74  $by_trying = $this->mockTree(ByTrying::class, ['transform' => true]);
75  $settings = $this->mock(ilSetting::class);
76  $settings->method('get')->withConsecutive(['dpro_enabled', ''], ['dpro_no_acceptance', ''])->willReturn('true');
77 
78  $container = $this->mockTree(Container::class, [
79  'settings' => $settings,
80  'refinery' => ['byTrying' => $by_trying],
81  'ctrl' => $this->mock(ilCtrl::class),
82  ]);
83  $container->method('offsetGet')->with('ilObjDataCache')->willReturn($this->mock(ilObjectDataCache::class));
84 
85  $slot = $this->mock(UseSlot::class);
86  $slot->expects(self::once())->method('hasDocuments')->willReturn($slot);
87  $slot->expects(self::once())->method('hasHistory')->willReturn($slot);
88  $slot->expects(self::once())->method('showOnLoginPage')->willReturn($slot);
89  $slot->expects(self::once())->method('showInFooter')->willReturn($slot);
90  $slot->expects(self::once())->method('hasPublicPage')->willReturn($slot);
91  $slot->expects(self::once())->method('hasPublicApi')->willReturn($slot);
92 
93  $instance = new Consumer($container);
94 
95  $this->assertSame($slot, $instance->uses($slot, $this->mock(LazyProvide::class)));
96  }
97 
98  public function testUses(): void
99  {
100  $by_trying = $this->mock(ByTrying::class);
101  $by_trying->method('transform')->willReturnOnConsecutiveCalls(true, false);
102 
103  $settings = $this->mock(ilSetting::class);
104  $settings->method('get')->withConsecutive(['dpro_enabled', ''], ['dpro_no_acceptance', ''])->willReturnOnConsecutiveCalls('true', 'false');
105 
106  $container = $this->mockTree(Container::class, [
107  'settings' => $settings,
108  'refinery' => ['byTrying' => $by_trying],
109  'ctrl' => $this->mock(ilCtrl::class),
110  ]);
111  $container->method('offsetGet')->with('ilObjDataCache')->willReturn($this->mock(ilObjectDataCache::class));
112 
113  $slot = $this->mock(UseSlot::class);
114  $slot->expects(self::once())->method('hasDocuments')->willReturn($slot);
115  $slot->expects(self::once())->method('hasHistory')->willReturn($slot);
116  $slot->expects(self::once())->method('showOnLoginPage')->willReturn($slot);
117  $slot->expects(self::once())->method('canWithdraw')->willReturn($slot);
118  $slot->expects(self::once())->method('hasAgreement')->willReturn($slot);
119  $slot->expects(self::once())->method('showInFooter')->willReturn($slot);
120  $slot->expects(self::once())->method('onSelfRegistration')->willReturn($slot);
121  $slot->expects(self::once())->method('hasOnlineStatusFilter')->willReturn($slot);
122  $slot->expects(self::once())->method('hasUserManagementFields')->willReturn($slot);
123  $slot->expects(self::once())->method('hasPublicApi')->willReturn($slot);
124  $slot->expects(self::once())->method('canReadInternalMails')->willReturn($slot);
125  $slot->expects(self::once())->method('canUseSoapApi')->willReturn($slot);
126 
127  $instance = new Consumer($container);
128 
129  $this->assertSame($slot, $instance->uses($slot, $this->mock(LazyProvide::class)));
130  }
131 }
array $settings
Setting values (LTI parameters, custom parameters and local parameters).
Definition: System.php:200
$container
Definition: wac.php:14