ILIAS  release_7 Revision v7.30-3-g800a261c036
All Data Structures Namespaces Files Functions Variables Modules Pages
ilMailTemplateRepositoryTest.php
Go to the documentation of this file.
1 <?php declare(strict_types=1);
2 
3 /* Copyright (c) 1998-2018 ILIAS open source, Extended GPL, see docs/LICENSE */
4 
10 {
16  {
17  $db = $this->getMockbuilder(ilDBInterface::class)->getMock();
18 
19  $repository = new ilMailTemplateRepository($db);
20 
21  $templateId = 666;
22 
23  $template = new ilMailTemplate();
24  $template->setTitle('phpunit');
25  $template->setSubject('FooBar');
26  $template->setMessage('FooBar');
27  $template->setLang('de');
28  $template->setContext('4711');
29  $template->setAsDefault(true);
30 
31  $db->expects($this->once())->method('nextId')->willReturn($templateId);
32  $db->expects($this->once())->method('insert');
33 
34  $repository->store($template);
35 
36  $this->assertEquals($templateId, $template->getTplId());
37 
38  return $template;
39  }
40 
48  {
49  $db = $this->getMockbuilder(ilDBInterface::class)->getMock();
50 
51  $repository = new ilMailTemplateRepository($db);
52 
53  $db->expects($this->once())->method('update');
54 
55  $repository->store($template);
56 
57  return $template;
58  }
59 
65  public function testEntityCanBeDeleted(ilMailTemplate $template) : void
66  {
67  $db = $this->getMockbuilder(ilDBInterface::class)->getMock();
68 
69  $repository = new ilMailTemplateRepository($db);
70 
71  $db->expects($this->once())->method('manipulate');
72 
73  $repository->deleteByIds([$template->getTplId()]);
74  }
75 
79  public function testTemplateCanBeFoundById() : void
80  {
81  $db = $this->getMockbuilder(ilDBInterface::class)->getMock();
82  $statement = $this->getMockbuilder(ilDBStatement::class)->getMock();
83 
84  $templateId = 666;
85 
86  $emptyTemplate = new ilMailTemplate();
87  $emptyTemplate->setTplId($templateId);
88 
89  $db->expects($this->once())->method('queryF')->willReturn($statement);
90  $db->expects($this->once())->method('numRows')->willReturn(1);
91  $db->expects($this->once())->method('fetchAssoc')->willReturn($emptyTemplate->toArray());
92 
93  $repository = new ilMailTemplateRepository($db);
94  $template = $repository->findById(4711);
95 
96  $this->assertEquals($templateId, $template->getTplId());
97  }
98 
103  {
104  $this->expectException(OutOfBoundsException::class);
105 
106  $db = $this->getMockbuilder(ilDBInterface::class)->getMock();
107  $statement = $this->getMockbuilder(ilDBStatement::class)->getMock();
108 
109  $db->expects($this->once())->method('queryF')->willReturn($statement);
110  $db->expects($this->once())->method('numRows')->willReturn(0);
111  $db->expects($this->never())->method('fetchAssoc');
112 
113  $repository = new ilMailTemplateRepository($db);
114  $repository->findById(4711);
115  }
116 }
testEntityCanBeDeleted(ilMailTemplate $template)
testEntityCanBeModified
Class ilMailTemplateRepository.
Class ilMailTemplate.
Class ilMailBaseTest.
testEntityCanBeModified(ilMailTemplate $template)
testEntityCanBeSaved
Class ilMailTemplateRepository.