ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
ilMailTemplateRepositoryTest.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 
20  public function testEntityCanBeSaved() : \ilMailTemplate
21  {
22  $db = $this->getMockbuilder(\ilDBInterface::class)->getMock();
23 
24  $repository = new \ilMailTemplateRepository($db);
25 
26  $templateId = 666;
27 
28  $template = new \ilMailTemplate();
29  $template->setTitle('phpunit');
30  $template->setSubject('FooBar');
31  $template->setMessage('FooBar');
32  $template->setLang('de');
33  $template->setContext('4711');
34  $template->setAsDefault(true);
35 
36  $db->expects($this->once())->method('nextId')->willReturn($templateId);
37  $db->expects($this->once())->method('insert');
38 
39  $repository->store($template);
40 
41  $this->assertEquals($templateId, $template->getTplId());
42 
43  return $template;
44  }
45 
52  {
53  $db = $this->getMockbuilder(\ilDBInterface::class)->getMock();
54 
55  $repository = new \ilMailTemplateRepository($db);
56 
57  $db->expects($this->once())->method('update');
58 
59  $repository->store($template);
60 
61  return $template;
62  }
63 
69  {
70  $db = $this->getMockbuilder(\ilDBInterface::class)->getMock();
71 
72  $repository = new \ilMailTemplateRepository($db);
73 
74  $db->expects($this->once())->method('manipulate');
75 
76  $repository->deleteByIds([$template->getTplId()]);
77  }
78 
82  public function testTemplateCanBeFoundById()
83  {
84  $db = $this->getMockbuilder(\ilDBInterface::class)->getMock();
85  $statement = $this->getMockbuilder(\ilDBStatement::class)->getMock();
86 
87  $templateId = 666;
88 
89  $emptyTemplate = new \ilMailTemplate();
90  $emptyTemplate->setTplId($templateId);
91 
92  $db->expects($this->once())->method('queryF')->willReturn($statement);
93  $db->expects($this->once())->method('numRows')->willReturn(1);
94  $db->expects($this->once())->method('fetchAssoc')->willReturn($emptyTemplate->toArray());
95 
96  $repository = new \ilMailTemplateRepository($db);
97  $template = $repository->findById(4711);
98 
99  $this->assertEquals($templateId, $template->getTplId());
100  }
101 
106  {
107  $this->assertException(\OutOfBoundsException::class);
108 
109  $db = $this->getMockbuilder(\ilDBInterface::class)->getMock();
110  $statement = $this->getMockbuilder(\ilDBStatement::class)->getMock();
111 
112  $db->expects($this->once())->method('queryF')->willReturn($statement);
113  $db->expects($this->once())->method('numRows')->willReturn(0);
114  $db->expects($this->never())->method('fetchAssoc');
115 
116  $repository = new \ilMailTemplateRepository($db);
117  $repository->findById(4711);
118  }
119 }
$template
Class ilMailTemplateRepository.
testEntityCanBeModified(\ilMailTemplate $template)
testEntityCanBeSaved
Class ilMailTemplate.
testEntityCanBeDeleted(\ilMailTemplate $template)
testEntityCanBeModified
assertException($exception_class)
Class ilMailBaseTest.
once($eventName, callable $callBack, $priority=100)
Subscribe to an event exactly once.