ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
ilCertificateCloneActionTest.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{
9 public function testCloneCertificate()
10 {
11 $database = $this->getMockBuilder('ilDBInterface')
12 ->disableOriginalConstructor()
13 ->getMock();
14
15 $database
16 ->expects($this->once())
17 ->method('query');
18
19 $database
20 ->expects($this->once())
21 ->method('numRows')
22 ->willReturn(1);
23
24 $database
25 ->expects($this->once())
26 ->method('replace');
27
28 $certificateFactory = $this->getMockBuilder('ilCertificateFactory')
29 ->getMock();
30
31 $oldCertficate = $this->getMockBuilder('ilCertificate')
32 ->disableOriginalConstructor()
33 ->getMock();
34
35 $oldCertficate->method('getBackgroundImageThumbPath')
36 ->willReturn('/some/where/background.jpg');
37
38
39 $newCertficate = $this->getMockBuilder('ilCertificate')
40 ->disableOriginalConstructor()
41 ->getMock();
42
43 $newCertficate->method('getBackgroundImageThumbPath')
44 ->willReturn('/some/where/background.jpg');
45
46 $certificateFactory->method('create')
47 ->willReturnOnConsecutiveCalls(
48 $oldCertficate,
49 $newCertficate
50 );
51
52 $templateRepository = $this->getMockBuilder('ilCertificateTemplateRepository')
53 ->disableOriginalConstructor()
54 ->getMock();
55
56 $templateRepository->method('fetchCertificateTemplatesByObjId')
57 ->willReturn(
58 array(
60 10,
61 'crs',
62 '<xml> Some Content </xml>',
63 md5('<xml> Some Content </xml>'),
64 '[]',
65 '3',
66 'v5.3.0',
67 123456789,
68 true,
69 '/some/where/background.jpg',
70 '/some/where/card_thumb.jpg',
71 $id = null
72 ),
74 20,
75 'crs',
76 '<xml> Some Content </xml>',
77 md5('<xml> Some Content </xml>'),
78 '[]',
79 '3',
80 'v5.3.0',
81 123456789,
82 true,
83 '/some/where/background.jpg',
84 '/some/where/card_thumb.jpg',
85 $id = null
86 )
87 )
88 );
89
90 $templateRepository
91 ->expects($this->exactly(2))
92 ->method('save');
93
94 $fileSystem = $this->getMockBuilder('\ILIAS\Filesystem\Filesystem')
95 ->getMock();
96
97 $fileSystem->method('has')
98 ->willReturn(true);
99
100 $fileSystem
101 ->expects($this->exactly(6))
102 ->method('copy');
103
104 $logger = $this->getMockBuilder('ilLogger')
105 ->disableOriginalConstructor()
106 ->getMock();
107
108 $objectHelper = $this->getMockBuilder('ilCertificateObjectHelper')
109 ->getMock();
110
111 $objectHelper->method('lookupObjId')
112 ->willReturn(1000);
113
114 $cloneAction = new ilCertificateCloneAction(
115 $database,
116 $certificateFactory,
117 $templateRepository,
118 $fileSystem,
119 $logger,
120 $objectHelper
121 );
122
123 $oldObject = $this->getMockBuilder('ilObject')
124 ->disableOriginalConstructor()
125 ->getMock();
126
127 $oldObject->method('getType')
128 ->willReturn('crs');
129
130 $oldObject->method('getId')
131 ->willReturn(10);
132
133 $newObject = $this->getMockBuilder('ilObject')
134 ->disableOriginalConstructor()
135 ->getMock();
136
137 $newObject->method('getType')
138 ->willReturn('crs');
139
140 $newObject->method('getId')
141 ->willReturn(10);
142
143 $cloneAction->cloneCertificate($oldObject, $newObject, 'v5.4.0', '/some/web/dir');
144 }
145}
An exception for terminatinating execution or to throw for unit testing.
if(!array_key_exists('StateId', $_REQUEST)) $id
once($eventName, callable $callBack, $priority=100)
Subscribe to an event exactly once.