99use OC \Security \CSP \ContentSecurityPolicyManager ;
1010use OC \Security \CSP \ContentSecurityPolicyNonceManager ;
1111use OCA \NCGoogleAnalytics \AppInfo \Application ;
12+ use OCA \NCGoogleAnalytics \Service \Consent \IConsentService ;
13+ use OCA \NCGoogleAnalytics \Service \Consent \IonosConsentService ;
1214use OCP \AppFramework \Bootstrap \IBootContext ;
15+ use OCP \AppFramework \Bootstrap \IRegistrationContext ;
1316use OCP \AppFramework \Http \ContentSecurityPolicy ;
1417use OCP \IURLGenerator ;
1518use PHPUnit \Framework \MockObject \MockObject ;
@@ -21,12 +24,14 @@ class ApplicationTest extends TestCase {
2124 private ContentSecurityPolicyNonceManager |MockObject $ nonceManager ;
2225 private ContentSecurityPolicyManager |MockObject $ contentSecurityPolicyManager ;
2326 private IBootContext |MockObject $ context ;
27+ private $ registrationContext ;
2428
2529 protected function setUp (): void {
2630 $ this ->urlGenerator = $ this ->createMock (IURLGenerator::class);
2731 $ this ->nonceManager = $ this ->createMock (ContentSecurityPolicyNonceManager::class);
2832 $ this ->contentSecurityPolicyManager = $ this ->createMock (ContentSecurityPolicyManager::class);
2933 $ this ->context = $ this ->createMock (IBootContext::class);
34+ $ this ->registrationContext = $ this ->createMock (IRegistrationContext::class);
3035 $ this ->application = new Application ();
3136 }
3237
@@ -40,6 +45,25 @@ public function testBoot(): void {
4045
4146 $ this ->application ->boot ($ this ->context );
4247 }
48+
49+ public function testRegister (): void {
50+ $ this ->registrationContext ->expects ($ this ->exactly (1 ))
51+ ->method ('registerService ' )
52+ ->with (
53+ IConsentService::class,
54+ $ this ->isInstanceOf (\Closure::class),
55+ true
56+ );
57+
58+ $ this ->application ->register ($ this ->registrationContext );
59+ }
60+
61+ public function testConsentServiceRegistration (): void {
62+ $ consentService = \OC ::$ server ->getRegisteredAppContainer (Application::APP_ID )->get (IConsentService::class);
63+
64+ $ this ->assertInstanceOf (IonosConsentService::class, $ consentService , 'FATAL: IonosConsentService is not registered! ' );
65+ }
66+
4367 public function testTrackingScriptAddition (): void {
4468 $ this ->urlGenerator ->method ('linkToRoute ' )->willReturn ('someUrl ' );
4569 $ this ->nonceManager ->method ('getNonce ' )->willReturn ('someNonce ' );
0 commit comments