ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
ilMailTemplateServiceTest.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
26 {
30  public function testDefaultTemplateCanBeSetByContext(): void
31  {
32  $repo = $this->getMockBuilder(ilMailTemplateRepository::class)->disableOriginalConstructor()->getMock();
33 
34  $template = new ilMailTemplate();
35  $template->setTplId(1);
36  $template->setAsDefault(false);
37  $template->setContext('phpunit');
38 
39  $otherTemplate = clone $template;
40  $otherTemplate->setTplId(2);
41  $otherTemplate->setAsDefault(false);
42 
43  $yetAnotherTemplate = clone $template;
44  $yetAnotherTemplate->setTplId(3);
45  $yetAnotherTemplate->setAsDefault(true);
46 
47  $all = [
48  $template,
49  $otherTemplate,
50  $yetAnotherTemplate,
51  ];
52 
53  $repo->expects($this->once())->method('findByContextId')->with($template->getContext())->willReturn($all);
54  $repo->expects($this->exactly(count($all)))->method('store');
55  $mustache_factory = $this->getMockBuilder(ilMustacheFactory::class)->getMock();
56  $service = new ilMailTemplateService($repo, $mustache_factory);
57 
58  $service->setAsContextDefault($template);
59 
60  $this->assertTrue($template->isDefault());
61  $this->assertFalse($otherTemplate->isDefault());
62  $this->assertFalse($yetAnotherTemplate->isDefault());
63  }
64 
69  {
70  $repo = $this->getMockBuilder(ilMailTemplateRepository::class)->disableOriginalConstructor()->getMock();
71 
72  $template = new ilMailTemplate();
73  $template->setTplId(1);
74  $template->setAsDefault(true);
75  $template->setContext('phpunit');
76 
77  $repo->expects($this->once())->method('store')->with($template);
78  $mustache_factory = $this->getMockBuilder(ilMustacheFactory::class)->getMock();
79  $service = new ilMailTemplateService($repo, $mustache_factory);
80 
81  $service->unsetAsContextDefault($template);
82 
83  $this->assertFalse($template->isDefault());
84  }
85 }
Class ilMailTemplateServiceTest.
Class ilMailTemplate.
Class ilMailBaseTest.
$service
Definition: ltiservices.php:43