ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
ilAwarenessUserProviderContactRequestsTestCase.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
23use PHPUnit\Framework\MockObject\MockObject;
24
26{
27 private ilObjUser|MockObject $user;
28 private ilLanguage|MockObject $language;
29
30 public function testConstruct(): void
31 {
32 $this->assertInstanceOf(Contacts::class, $this->create());
33 }
34
35 public function testGetProviderId(): void
36 {
37 $this->assertSame('contact_approved', $this->create()->getProviderId());
38 }
39
40 public function testGetTitle(): void
41 {
42 $this->expectTranslation('getTitle', 'contact_awrn_req_contacts');
43 }
44
45 public function testGetInfo(): void
46 {
47 $this->expectTranslation('getInfo', 'contact_awrn_req_contacts_info');
48 }
49
50 public function testGetInitialUserSet(): void
51 {
52 $instance = $this->create();
53
54 $this->user->expects($this->once())->method('isAnonymous')->willReturn(true);
55
56 $this->assertEquals([], $instance->getInitialUserSet());
57 }
58
59 public function testIsHighlighted(): void
60 {
61 $this->assertTrue($this->create()->isHighlighted());
62 }
63
64 private function expectTranslation(string $method, string $languageKey): void
65 {
66 $expected = 'translated: ' . $languageKey;
67
68 $instance = $this->create();
69
70 $this->language->expects($this->once())->method('loadLanguageModule')->with('contact');
71 $this->language->expects($this->once())->method('txt')->with($languageKey)->willReturn($expected);
72
73 $this->assertSame($expected, $instance->$method());
74 }
75
76 private function create(): Contacts
77 {
78 $this->user = $this->getMockBuilder(ilObjUser::class)->disableOriginalConstructor()->getMock();
79 $this->language = $this->getMockBuilder(ilLanguage::class)->disableOriginalConstructor()->getMock();
80
81 $container = $this->getMockBuilder(Container::class)->disableOriginalConstructor()->getMock();
82 $container->expects($this->once())->method('user')->willReturn($this->user);
83 $container->expects($this->once())->method('language')->willReturn($this->language);
84
85 return new Contacts($container);
86 }
87}
Customizing of pimple-DIC for ILIAS.
Definition: Container.php:36
language handling
User class.
$container
@noRector
Definition: wac.php:37