ILIAS  trunk Revision v11.0_alpha-1689-g66c127b4ae8
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
ilCertificateUserForObjectPreloaderTest.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
25 {
27  {
28  $userCertificateRepository = $this->getMockBuilder(ilUserCertificateRepository::class)
29  ->disableOriginalConstructor()
30  ->getMock();
31 
32  $userCertificateRepository->method('fetchUserIdsWithCertificateForObject')
33  ->willReturn([1, 2, 3]);
34 
35  $activeValidator = $this->getMockBuilder(ilCertificateActiveValidator::class)
36  ->disableOriginalConstructor()
37  ->getMock();
38 
39  $activeValidator->method('validate')
40  ->willReturn(true);
41 
42  $preloader = new ilCertificateUserForObjectPreloader($userCertificateRepository, $activeValidator);
43 
44  $preloader->preLoadDownloadableCertificates(100);
45 
46  $result = $preloader->isPreloaded(100, 1);
47 
48  $this->assertTrue($result);
49  }
50 
51  public function testUserWithCertificateIsNotPreloaded(): void
52  {
53  $userCertificateRepository = $this->getMockBuilder(ilUserCertificateRepository::class)
54  ->disableOriginalConstructor()
55  ->getMock();
56 
57  $userCertificateRepository->method('fetchUserIdsWithCertificateForObject')
58  ->willReturn([1, 2, 3]);
59 
60  $activeValidator = $this->getMockBuilder(ilCertificateActiveValidator::class)
61  ->disableOriginalConstructor()
62  ->getMock();
63 
64  $activeValidator->method('validate')
65  ->willReturn(true);
66 
67  $preloader = new ilCertificateUserForObjectPreloader($userCertificateRepository, $activeValidator);
68 
69  $preloader->preLoadDownloadableCertificates(100);
70 
71  $result = $preloader->isPreloaded(100, 5);
72 
73  $this->assertFalse($result);
74  }
75 
76  public function testUserIsNoProloaded(): void
77  {
78  $userCertificateRepository = $this->getMockBuilder(ilUserCertificateRepository::class)
79  ->disableOriginalConstructor()
80  ->getMock();
81 
82  $userCertificateRepository->method('fetchUserIdsWithCertificateForObject')
83  ->willReturn([1, 2, 3]);
84 
85  $activeValidator = $this->getMockBuilder(ilCertificateActiveValidator::class)
86  ->disableOriginalConstructor()
87  ->getMock();
88 
89  $activeValidator->method('validate')
90  ->willReturn(true);
91 
92  $preloader = new ilCertificateUserForObjectPreloader($userCertificateRepository, $activeValidator);
93 
94  $preloader->preLoadDownloadableCertificates(100);
95 
96  $result = $preloader->isPreloaded(200, 1);
97 
98  $this->assertFalse($result);
99  }
100 
102  {
103  $userCertificateRepository = $this->getMockBuilder(ilUserCertificateRepository::class)
104  ->disableOriginalConstructor()
105  ->getMock();
106 
107  $userCertificateRepository
108  ->expects($this->never())
109  ->method('fetchUserIdsWithCertificateForObject');
110 
111  $activeValidator = $this->getMockBuilder(ilCertificateActiveValidator::class)
112  ->disableOriginalConstructor()
113  ->getMock();
114 
115  $activeValidator->method('validate')
116  ->willReturn(false);
117 
118  $preloader = new ilCertificateUserForObjectPreloader($userCertificateRepository, $activeValidator);
119 
120  $preloader->preLoadDownloadableCertificates(100);
121 
122  $result = $preloader->isPreloaded(100, 5);
123 
124  $this->assertFalse($result);
125  }
126 }
Class ilCertificateBaseTestCase.