ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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';
5require_once 'Services/TermsOfService/test/ilTermsOfServiceBaseTest.php';
6
7use org\bovigo\vfs;
8
14{
18 protected $backupGlobals = false;
19
23 protected $client_dir;
24
28 protected $global_dir;
29
33 protected $lng;
34
38 protected $source_files = array();
39
43 public function setUp()
44 {
45 $this->lng = $this->getMockBuilder('ilLanguage')->setMethods(array('toJSON', 'getInstalledLanguages', 'getLangKey', 'getDefaultLanguage'))->disableOriginalConstructor()->getMock();
46 $this->lng->expects($this->any())
47 ->method('getLangKey')
48 ->will($this->returnValue('de'));
49 $this->lng->expects($this->any())
50 ->method('getDefaultLanguage')
51 ->will($this->returnValue('fr'));
52
53 vfs\vfsStreamWrapper::register();
54 $root = vfs\vfsStreamWrapper::setRoot(new vfs\vfsStreamDirectory('root'));
55 $customizing_dir = vfs\vfsStream::newDirectory('Customizing')->at($root);
56 $this->client_dir = vfs\vfsStream::newDirectory('clients/default/agreement')->at($customizing_dir);
57 $this->global_dir = vfs\vfsStream::newDirectory('global/agreement')->at($customizing_dir);
58 $this->source_files = array(
59 vfs\vfsStream::url(implode('/', array('root', 'Customizing', 'clients', 'default', 'agreement', 'agreement_' . $this->lng->getLangKey() . '.html'))) => $this->lng->getLangKey(),
60 vfs\vfsStream::url(implode('/', array('root', 'Customizing', 'clients', 'default', 'agreement', 'agreement_' . $this->lng->getDefaultLanguage() . '.html'))) => $this->lng->getDefaultLanguage(),
61 vfs\vfsStream::url(implode('/', array('root', 'Customizing', 'clients', 'default', 'agreement', 'agreement_en.html'))) => 'en',
62 vfs\vfsStream::url(implode('/', array('root', 'Customizing', 'global', 'agreement', 'agreement_' . $this->lng->getLangKey() . '.html'))) => $this->lng->getLangKey(),
63 vfs\vfsStream::url(implode('/', array('root', 'Customizing', 'global', 'agreement', 'agreement_' . $this->lng->getDefaultLanguage() . '.html'))) => $this->lng->getDefaultLanguage(),
64 vfs\vfsStream::url(implode('/', array('root', 'Customizing', 'global', 'agreement', 'agreement_en.html'))) => 'en'
65 );
66 }
67
71 public function testInstanceCanBeCreated()
72 {
73 $document = new ilTermsOfServiceFileSystemDocument($this->lng);
74 $this->assertInstanceOf('ilTermsOfServiceSignableDocument', $document);
75 $this->assertTrue($document->exists());
76 $document->setSourceFiles($this->source_files);
77 return $document;
78 }
79
84 {
85 $this->assertException(ilTermsOfServiceNoSignableDocumentFoundException::class);
86 $document = new ilTermsOfServiceFileSystemDocument($this->getMockBuilder('ilLanguage')->setMethods(array('getLangKey', 'getDefaultLanguage', 'toJSON', 'getInstalledLanguages'))->disableOriginalConstructor()->getMock());
87 $document->setSourceFiles(array());
88 $document->determine();
89 }
90
96 {
97 vfs\vfsStream::newFile('agreement_de.html', 0777)->withContent('phpunit')->at($this->client_dir);
98 file_put_contents(vfs\vfsStream::url('root/Customizing/clients/default/agreement/agreement_de.html'), 'phpunit');
99
100 $document->determine();
101 $this->assertEquals('de', $document->getIso2LanguageCode());
102 $this->assertTrue($document->hasContent());
103 $this->assertEquals('phpunit', $document->getContent());
105 $this->assertEquals(vfs\vfsStream::url('root/Customizing/clients/default/agreement/agreement_de.html'), $document->getSource());
106 }
107
113 {
114 vfs\vfsStream::newFile('agreement_fr.html', 0777)->withContent('phpunit')->at($this->client_dir);
115 file_put_contents(vfs\vfsStream::url('root/Customizing/clients/default/agreement/agreement_fr.html'), 'phpunit');
116
117 $document->determine();
118 $this->assertEquals('fr', $document->getIso2LanguageCode());
119 $this->assertTrue($document->hasContent());
120 $this->assertEquals('phpunit', $document->getContent());
122 $this->assertEquals(vfs\vfsStream::url('root/Customizing/clients/default/agreement/agreement_fr.html'), $document->getSource());
123 }
124
130 {
131 vfs\vfsStream::newFile('agreement_en.html', 0777)->withContent('phpunit')->at($this->client_dir);
132 file_put_contents(vfs\vfsStream::url('root/Customizing/clients/default/agreement/agreement_en.html'), 'phpunit');
133
134 $document->determine();
135 $this->assertEquals('en', $document->getIso2LanguageCode());
136 $this->assertTrue($document->hasContent());
137 $this->assertEquals('phpunit', $document->getContent());
139 $this->assertEquals(vfs\vfsStream::url('root/Customizing/clients/default/agreement/agreement_en.html'), $document->getSource());
140 }
141
147 {
148 vfs\vfsStream::newFile('agreement_de.html', 0777)->withContent('phpunit')->at($this->client_dir);
149 file_put_contents(vfs\vfsStream::url('root/Customizing/global/agreement/agreement_de.html'), 'phpunit');
150
151 $document->determine();
152 $this->assertEquals('de', $document->getIso2LanguageCode());
153 $this->assertTrue($document->hasContent());
154 $this->assertEquals('phpunit', $document->getContent());
156 $this->assertEquals(vfs\vfsStream::url('root/Customizing/global/agreement/agreement_de.html'), $document->getSource());
157 }
158
164 {
165 vfs\vfsStream::newFile('agreement_fr.html', 0777)->withContent('phpunit')->at($this->client_dir);
166 file_put_contents(vfs\vfsStream::url('root/Customizing/global/agreement/agreement_fr.html'), 'phpunit');
167
168 $document->determine();
169 $this->assertEquals('fr', $document->getIso2LanguageCode());
170 $this->assertTrue($document->hasContent());
171 $this->assertEquals('phpunit', $document->getContent());
173 $this->assertEquals(vfs\vfsStream::url('root/Customizing/global/agreement/agreement_fr.html'), $document->getSource());
174 }
175
181 {
182 vfs\vfsStream::newFile('agreement_en.html', 0777)->withContent('phpunit')->at($this->client_dir);
183 file_put_contents(vfs\vfsStream::url('root/Customizing/global/agreement/agreement_en.html'), 'phpunit');
184
185 $document->determine();
186 $this->assertEquals('en', $document->getIso2LanguageCode());
187 $this->assertTrue($document->hasContent());
188 $this->assertEquals('phpunit', $document->getContent());
190 $this->assertEquals(vfs\vfsStream::url('root/Customizing/global/agreement/agreement_en.html'), $document->getSource());
191 }
192}
An exception for terminatinating execution or to throw for unit testing.
testClientDocumentCouldBeRetrievedByCurrentLanguage(ilTermsOfServiceFileSystemDocument $document)
testClientDocumentCouldBeRetrievedByEnglishLanguage(ilTermsOfServiceFileSystemDocument $document)
testGlobalDocumentCouldBeRetrievedByCurrentLanguage(ilTermsOfServiceFileSystemDocument $document)
testExceptionIsRaisedWhenNoSingableDocumentCouldBeFoundForCurrentLanguage()
@expectedException ilTermsOfServiceNoSignableDocumentFoundException
testClientDocumentCouldBeRetrievedByDefaultLanguage(ilTermsOfServiceFileSystemDocument $document)
testGlobalDocumentCouldBeRetrievedByEnglishLanguage(ilTermsOfServiceFileSystemDocument $document)
testGlobalDocumentCouldBeRetrievedByDefaultLanguage(ilTermsOfServiceFileSystemDocument $document)