ILIAS  Release_4_4_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
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 
4 require_once 'vfsStream/vfsStream.php';
5 require_once 'Services/TermsOfService/classes/class.ilTermsOfServiceFileSystemDocument.php';
6 
12 {
16  protected $backupGlobals = false;
17 
21  protected $client_dir;
22 
26  protected $global_dir;
27 
31  protected $lng;
32 
36  protected $source_files = array();
37 
41  public function setUp()
42  {
43  vfsStreamWrapper::register();
44  $root = vfsStreamWrapper::setRoot(new vfsStreamDirectory('root'));
45  $customizing_dir = vfsStream::newDirectory('Customizing')->at($root);
46  $this->client_dir = vfsStream::newDirectory('clients/default/agreement')->at($customizing_dir);
47  $this->global_dir = vfsStream::newDirectory('global/agreement')->at($customizing_dir);
48 
49  $this->lng = $this->getMockBuilder('ilLanguage')->disableOriginalConstructor()->getMock();
50  $this->lng->expects($this->any())
51  ->method('getLangKey')
52  ->will($this->returnValue('de'));
53  $this->lng->expects($this->any())
54  ->method('getDefaultLanguage')
55  ->will($this->returnValue('fr'));
56 
57  $this->source_files = array(
58  vfsStream::url(implode('/', array('root', 'Customizing', 'clients', 'default', 'agreement', 'agreement_' . $this->lng->getLangKey() . '.html'))) => $this->lng->getLangKey(),
59  vfsStream::url(implode('/', array('root', 'Customizing', 'clients', 'default', 'agreement', 'agreement_' . $this->lng->getDefaultLanguage() . '.html'))) => $this->lng->getDefaultLanguage(),
60  vfsStream::url(implode('/', array('root', 'Customizing', 'clients', 'default', 'agreement', 'agreement_en.html'))) => 'en',
61  vfsStream::url(implode('/', array('root', 'Customizing', 'global', 'agreement', 'agreement_' . $this->lng->getLangKey() . '.html'))) => $this->lng->getLangKey(),
62  vfsStream::url(implode('/', array('root', 'Customizing', 'global', 'agreement', 'agreement_' . $this->lng->getDefaultLanguage() . '.html'))) => $this->lng->getDefaultLanguage(),
63  vfsStream::url(implode('/', array('root', 'Customizing', 'global', 'agreement', 'agreement_en.html'))) => 'en'
64  );
65  }
66 
70  public function testInstanceCanBeCreated()
71  {
72  $document = new ilTermsOfServiceFileSystemDocument($this->lng);
73  $this->assertInstanceOf('ilTermsOfServiceSignableDocument', $document);
74  $document->setSourceFiles($this->source_files);
75  return $document;
76  }
77 
83  {
84  $document = new ilTermsOfServiceFileSystemDocument($this->getMockBuilder('ilLanguage')->disableOriginalConstructor()->getMock());
85  $document->determine();
86  }
87 
93  {
94  vfsStream::newFile('agreement_de.html', 0777)->withContent('phpunit')->at($this->client_dir);
95  file_put_contents(vfsStream::url('root/Customizing/clients/default/agreement/agreement_de.html'), 'phpunit');
96 
97  $document->determine();
98  $this->assertEquals('de', $document->getIso2LanguageCode());
99  $this->assertTrue($document->hasContent());
100  $this->assertEquals('phpunit', $document->getContent());
102  $this->assertEquals(vfsStream::url('root/Customizing/clients/default/agreement/agreement_de.html'), $document->getSource());
103  }
104 
110  {
111  vfsStream::newFile('agreement_fr.html', 0777)->withContent('phpunit')->at($this->client_dir);
112  file_put_contents(vfsStream::url('root/Customizing/clients/default/agreement/agreement_fr.html'), 'phpunit');
113 
114  $document->determine();
115  $this->assertEquals('fr', $document->getIso2LanguageCode());
116  $this->assertTrue($document->hasContent());
117  $this->assertEquals('phpunit', $document->getContent());
119  $this->assertEquals(vfsStream::url('root/Customizing/clients/default/agreement/agreement_fr.html'), $document->getSource());
120  }
121 
127  {
128  vfsStream::newFile('agreement_en.html', 0777)->withContent('phpunit')->at($this->client_dir);
129  file_put_contents(vfsStream::url('root/Customizing/clients/default/agreement/agreement_en.html'), 'phpunit');
130 
131  $document->determine();
132  $this->assertEquals('en', $document->getIso2LanguageCode());
133  $this->assertTrue($document->hasContent());
134  $this->assertEquals('phpunit', $document->getContent());
136  $this->assertEquals(vfsStream::url('root/Customizing/clients/default/agreement/agreement_en.html'), $document->getSource());
137  }
138 
144  {
145  vfsStream::newFile('agreement_de.html', 0777)->withContent('phpunit')->at($this->client_dir);
146  file_put_contents(vfsStream::url('root/Customizing/global/agreement/agreement_de.html'), 'phpunit');
147 
148  $document->determine();
149  $this->assertEquals('de', $document->getIso2LanguageCode());
150  $this->assertTrue($document->hasContent());
151  $this->assertEquals('phpunit', $document->getContent());
153  $this->assertEquals(vfsStream::url('root/Customizing/global/agreement/agreement_de.html'), $document->getSource());
154  }
155 
161  {
162  vfsStream::newFile('agreement_fr.html', 0777)->withContent('phpunit')->at($this->client_dir);
163  file_put_contents(vfsStream::url('root/Customizing/global/agreement/agreement_fr.html'), 'phpunit');
164 
165  $document->determine();
166  $this->assertEquals('fr', $document->getIso2LanguageCode());
167  $this->assertTrue($document->hasContent());
168  $this->assertEquals('phpunit', $document->getContent());
170  $this->assertEquals(vfsStream::url('root/Customizing/global/agreement/agreement_fr.html'), $document->getSource());
171  }
172 
178  {
179  vfsStream::newFile('agreement_en.html', 0777)->withContent('phpunit')->at($this->client_dir);
180  file_put_contents(vfsStream::url('root/Customizing/global/agreement/agreement_en.html'), 'phpunit');
181 
182  $document->determine();
183  $this->assertEquals('en', $document->getIso2LanguageCode());
184  $this->assertTrue($document->hasContent());
185  $this->assertEquals('phpunit', $document->getContent());
187  $this->assertEquals(vfsStream::url('root/Customizing/global/agreement/agreement_en.html'), $document->getSource());
188  }
189 }