ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
ilMailTemplateServiceTest.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22{
24 {
25 $repo = $this->getMockBuilder(ilMailTemplateRepository::class)->disableOriginalConstructor()->getMock();
26
27 $template = new ilMailTemplate();
28 $template->setTplId(1);
29 $template->setAsDefault(false);
30 $template->setContext('phpunit');
31
32 $other_template = clone $template;
33 $other_template->setTplId(2);
34 $other_template->setAsDefault(false);
35
36 $yet_another_template = clone $template;
37 $yet_another_template->setTplId(3);
38 $yet_another_template->setAsDefault(true);
39
40 $all = [
41 $template,
42 $other_template,
43 $yet_another_template,
44 ];
45
46 $repo->expects($this->once())->method('findByContextId')->with($template->getContext())->willReturn($all);
47 $repo->expects($this->exactly(count($all)))->method('store');
48 $mustache_factory = $this->getMockBuilder(ilMustacheFactory::class)->getMock();
49 $service = new ilMailTemplateService($repo, $mustache_factory);
50
51 $service->setAsContextDefault($template);
52
53 $this->assertTrue($template->isDefault());
54 $this->assertFalse($other_template->isDefault());
55 $this->assertFalse($yet_another_template->isDefault());
56 }
57
59 {
60 $repo = $this->getMockBuilder(ilMailTemplateRepository::class)->disableOriginalConstructor()->getMock();
61
62 $template = new ilMailTemplate();
63 $template->setTplId(1);
64 $template->setAsDefault(true);
65 $template->setContext('phpunit');
66
67 $repo->expects($this->once())->method('store')->with($template);
68 $mustache_factory = $this->getMockBuilder(ilMustacheFactory::class)->getMock();
69 $service = new ilMailTemplateService($repo, $mustache_factory);
70
71 $service->unsetAsContextDefault($template);
72
73 $this->assertFalse($template->isDefault());
74 }
75}
$service
Definition: ltiresult.php:36