ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
ilMailTemplateRepositoryTest.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
21use PHPUnit\Framework\Attributes\Depends;
22
24{
26 {
27 $db = $this->getMockBuilder(ilDBInterface::class)->getMock();
28
29 $repository = new ilMailTemplateRepository($db);
30
31 $template_id = 666;
32
33 $template = new ilMailTemplate();
34 $template->setTitle('phpunit');
35 $template->setSubject('FooBar');
36 $template->setMessage('FooBar');
37 $template->setLang('de');
38 $template->setContext('4711');
39 $template->setAsDefault(true);
40
41 $db->expects($this->once())->method('nextId')->willReturn($template_id);
42 $db->expects($this->once())->method('insert');
43
44 $repository->store($template);
45
46 $this->assertSame($template_id, $template->getTplId());
47
48 return $template;
49 }
50
51 #[Depends('testEntityCanBeSaved')]
53 {
54 $db = $this->getMockBuilder(ilDBInterface::class)->getMock();
55
56 $repository = new ilMailTemplateRepository($db);
57
58 $db->expects($this->once())->method('update');
59
60 $repository->store($template);
61
62 return $template;
63 }
64
65 #[Depends('testEntityCanBeModified')]
66 public function testEntityCanBeDeleted(ilMailTemplate $template): void
67 {
68 $db = $this->getMockBuilder(ilDBInterface::class)->getMock();
69
70 $repository = new ilMailTemplateRepository($db);
71
72 $db->expects($this->once())->method('manipulate');
73
74 $repository->deleteByIds([$template->getTplId()]);
75 }
76
77 public function testTemplateCanBeFoundById(): void
78 {
79 $db = $this->getMockBuilder(ilDBInterface::class)->getMock();
80 $statement = $this->getMockBuilder(ilDBStatement::class)->getMock();
81
82 $template_id = 666;
83
84 $empty_template = new ilMailTemplate();
85 $empty_template->setTplId($template_id);
86
87 $db->expects($this->once())->method('queryF')->willReturn($statement);
88 $db->expects($this->once())->method('numRows')->willReturn(1);
89 $db->expects($this->once())->method('fetchAssoc')->willReturn($empty_template->toArray());
90
91 $repository = new ilMailTemplateRepository($db);
92 $template = $repository->findById(4711);
93
94 $this->assertSame($template_id, $template->getTplId());
95 }
96
98 {
99 $this->expectException(OutOfBoundsException::class);
100
101 $db = $this->getMockBuilder(ilDBInterface::class)->getMock();
102 $statement = $this->getMockBuilder(ilDBStatement::class)->getMock();
103
104 $db->expects($this->once())->method('queryF')->willReturn($statement);
105 $db->expects($this->once())->method('numRows')->willReturn(0);
106 $db->expects($this->never())->method('fetchAssoc');
107
108 $repository = new ilMailTemplateRepository($db);
109 $repository->findById(4711);
110 }
111}
testEntityCanBeModified(ilMailTemplate $template)
testEntityCanBeDeleted(ilMailTemplate $template)