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