ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
ilMailTemplateServiceTest.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2018 ILIAS open source, Extended GPL, see docs/LICENSE */
3
8{
12 protected function setUp()
13 {
14 parent::setUp();
15 }
16
21 {
22 $repo = $this->getMockbuilder(\ilMailTemplateRepository::class)->disableOriginalConstructor()->getMock();
23
24 $template = new \ilMailTemplate();
25 $template->setTplId(1);
26 $template->setAsDefault(false);
27 $template->setContext('phpunit');
28
29 $otherTemplate = clone $template;
30 $otherTemplate->setTplId(2);
31 $otherTemplate->setAsDefault(false);
32
33 $yetAnotherTemplate = clone $template;
34 $yetAnotherTemplate->setTplId(3);
35 $yetAnotherTemplate->setAsDefault(true);
36
37 $all = [
39 $otherTemplate,
40 $yetAnotherTemplate,
41 ];
42
43 $repo->expects($this->once())->method('findByContextId')->with($template->getContext())->willReturn($all);
44 $repo->expects($this->exactly(count($all)))->method('store');
45 $service = new \ilMailTemplateService($repo);
46
47 $service->setAsContextDefault($template);
48
49 $this->assertTrue($template->isDefault());
50 $this->assertFalse($otherTemplate->isDefault());
51 $this->assertFalse($yetAnotherTemplate->isDefault());
52 }
53
58 {
59 $repo = $this->getMockbuilder(\ilMailTemplateRepository::class)->disableOriginalConstructor()->getMock();
60
61 $template = new \ilMailTemplate();
62 $template->setTplId(1);
63 $template->setAsDefault(true);
64 $template->setContext('phpunit');
65
66 $repo->expects($this->once())->method('store')->with($template);
67 $service = new \ilMailTemplateService($repo);
68
69 $service->unsetAsContextDefault($template);
70
71 $this->assertFalse($template->isDefault());
72 }
73}
An exception for terminatinating execution or to throw for unit testing.
Class ilMailBaseTest.
Class ilMailTemplateServiceTest.
$template
once($eventName, callable $callBack, $priority=100)
Subscribe to an event exactly once.