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