ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
ilTermsOfServiceFileSystemDocumentTest.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2013 ILIAS open source, Extended GPL, see docs/LICENSE */
3
4require_once 'Services/TermsOfService/classes/class.ilTermsOfServiceFileSystemDocument.php';
5
11{
15 protected $backupGlobals = false;
16
20 protected $client_dir;
21
25 protected $global_dir;
26
30 protected $lng;
31
35 protected $source_files = array();
36
40 private function isVsfStreamInstalled()
41 {
42 return @include_once('vfsStream.php');
43 }
44
48 private function skipIfvfsStreamNotSupported()
49 {
50 if(!$this->isVsfStreamInstalled())
51 {
52 $this->markTestSkipped('Requires vfsStream (http://vfs.bovigo.org)');
53 }
54 }
55
59 public function setUp()
60 {
61 $this->lng = $this->getMockBuilder('ilLanguage')->setMethods(array('toJSON'))->disableOriginalConstructor()->getMock();
62 $this->lng->expects($this->any())
63 ->method('getLangKey')
64 ->will($this->returnValue('de'));
65 $this->lng->expects($this->any())
66 ->method('getDefaultLanguage')
67 ->will($this->returnValue('fr'));
68
69 if($this->isVsfStreamInstalled())
70 {
71 vfsStreamWrapper::register();
72 $root = vfsStreamWrapper::setRoot(new vfsStreamDirectory('root'));
73 $customizing_dir = vfsStream::newDirectory('Customizing')->at($root);
74 $this->client_dir = vfsStream::newDirectory('clients/default/agreement')->at($customizing_dir);
75 $this->global_dir = vfsStream::newDirectory('global/agreement')->at($customizing_dir);
76 $this->source_files = array(
77 vfsStream::url(implode('/', array('root', 'Customizing', 'clients', 'default', 'agreement', 'agreement_' . $this->lng->getLangKey() . '.html'))) => $this->lng->getLangKey(),
78 vfsStream::url(implode('/', array('root', 'Customizing', 'clients', 'default', 'agreement', 'agreement_' . $this->lng->getDefaultLanguage() . '.html'))) => $this->lng->getDefaultLanguage(),
79 vfsStream::url(implode('/', array('root', 'Customizing', 'clients', 'default', 'agreement', 'agreement_en.html'))) => 'en',
80 vfsStream::url(implode('/', array('root', 'Customizing', 'global', 'agreement', 'agreement_' . $this->lng->getLangKey() . '.html'))) => $this->lng->getLangKey(),
81 vfsStream::url(implode('/', array('root', 'Customizing', 'global', 'agreement', 'agreement_' . $this->lng->getDefaultLanguage() . '.html'))) => $this->lng->getDefaultLanguage(),
82 vfsStream::url(implode('/', array('root', 'Customizing', 'global', 'agreement', 'agreement_en.html'))) => 'en'
83 );
84 }
85 }
86
90 public function testInstanceCanBeCreated()
91 {
92 $document = new ilTermsOfServiceFileSystemDocument($this->lng);
93 $this->assertInstanceOf('ilTermsOfServiceSignableDocument', $document);
94 $document->setSourceFiles($this->source_files);
95 return $document;
96 }
97
102 {
103 $document = new ilTermsOfServiceFileSystemDocument($this->getMockBuilder('ilLanguage')->setMethods(array('toJSON'))->disableOriginalConstructor()->getMock());
104 $document->setSourceFiles(array());
105 $document->determine();
106 }
107
113 {
115
116 vfsStream::newFile('agreement_de.html', 0777)->withContent('phpunit')->at($this->client_dir);
117 file_put_contents(vfsStream::url('root/Customizing/clients/default/agreement/agreement_de.html'), 'phpunit');
118
119 $document->determine();
120 $this->assertEquals('de', $document->getIso2LanguageCode());
121 $this->assertTrue($document->hasContent());
122 $this->assertEquals('phpunit', $document->getContent());
124 $this->assertEquals(vfsStream::url('root/Customizing/clients/default/agreement/agreement_de.html'), $document->getSource());
125 }
126
132 {
134
135 vfsStream::newFile('agreement_fr.html', 0777)->withContent('phpunit')->at($this->client_dir);
136 file_put_contents(vfsStream::url('root/Customizing/clients/default/agreement/agreement_fr.html'), 'phpunit');
137
138 $document->determine();
139 $this->assertEquals('fr', $document->getIso2LanguageCode());
140 $this->assertTrue($document->hasContent());
141 $this->assertEquals('phpunit', $document->getContent());
143 $this->assertEquals(vfsStream::url('root/Customizing/clients/default/agreement/agreement_fr.html'), $document->getSource());
144 }
145
151 {
153
154 vfsStream::newFile('agreement_en.html', 0777)->withContent('phpunit')->at($this->client_dir);
155 file_put_contents(vfsStream::url('root/Customizing/clients/default/agreement/agreement_en.html'), 'phpunit');
156
157 $document->determine();
158 $this->assertEquals('en', $document->getIso2LanguageCode());
159 $this->assertTrue($document->hasContent());
160 $this->assertEquals('phpunit', $document->getContent());
162 $this->assertEquals(vfsStream::url('root/Customizing/clients/default/agreement/agreement_en.html'), $document->getSource());
163 }
164
170 {
172
173 vfsStream::newFile('agreement_de.html', 0777)->withContent('phpunit')->at($this->client_dir);
174 file_put_contents(vfsStream::url('root/Customizing/global/agreement/agreement_de.html'), 'phpunit');
175
176 $document->determine();
177 $this->assertEquals('de', $document->getIso2LanguageCode());
178 $this->assertTrue($document->hasContent());
179 $this->assertEquals('phpunit', $document->getContent());
181 $this->assertEquals(vfsStream::url('root/Customizing/global/agreement/agreement_de.html'), $document->getSource());
182 }
183
189 {
191
192 vfsStream::newFile('agreement_fr.html', 0777)->withContent('phpunit')->at($this->client_dir);
193 file_put_contents(vfsStream::url('root/Customizing/global/agreement/agreement_fr.html'), 'phpunit');
194
195 $document->determine();
196 $this->assertEquals('fr', $document->getIso2LanguageCode());
197 $this->assertTrue($document->hasContent());
198 $this->assertEquals('phpunit', $document->getContent());
200 $this->assertEquals(vfsStream::url('root/Customizing/global/agreement/agreement_fr.html'), $document->getSource());
201 }
202
208 {
210
211 vfsStream::newFile('agreement_en.html', 0777)->withContent('phpunit')->at($this->client_dir);
212 file_put_contents(vfsStream::url('root/Customizing/global/agreement/agreement_en.html'), 'phpunit');
213
214 $document->determine();
215 $this->assertEquals('en', $document->getIso2LanguageCode());
216 $this->assertTrue($document->hasContent());
217 $this->assertEquals('phpunit', $document->getContent());
219 $this->assertEquals(vfsStream::url('root/Customizing/global/agreement/agreement_en.html'), $document->getSource());
220 }
221}
testClientDocumentCouldBeRetrievedByCurrentLanguage(ilTermsOfServiceFileSystemDocument $document)
testClientDocumentCouldBeRetrievedByEnglishLanguage(ilTermsOfServiceFileSystemDocument $document)
testGlobalDocumentCouldBeRetrievedByCurrentLanguage(ilTermsOfServiceFileSystemDocument $document)
testExceptionIsRaisedWhenNoSingableDocumentCouldBeFoundForCurrentLanguage()
@expectedException ilTermsOfServiceNoSignableDocumentFoundException
testClientDocumentCouldBeRetrievedByDefaultLanguage(ilTermsOfServiceFileSystemDocument $document)
testGlobalDocumentCouldBeRetrievedByEnglishLanguage(ilTermsOfServiceFileSystemDocument $document)
testGlobalDocumentCouldBeRetrievedByDefaultLanguage(ilTermsOfServiceFileSystemDocument $document)