ILIAS  Release_5_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
ilTermsOfServiceAgreementsByLanguageTableDataProviderTest.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2013 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
9 {
13  protected $backupGlobals = false;
14 
18  private function isVsfStreamInstalled()
19  {
20  return @include_once('vfsStream.php');
21  }
22 
26  private function skipIfvfsStreamNotSupported()
27  {
28  if(!$this->isVsfStreamInstalled())
29  {
30  $this->markTestSkipped('Requires vfsStream (http://vfs.bovigo.org)');
31  }
32  }
33 
37  public function setUp()
38  {
39  if($this->isVsfStreamInstalled())
40  {
41  vfsStreamWrapper::register();
42  }
43  }
44 
49  {
50  require_once 'Services/TermsOfService/classes/class.ilTermsOfServiceTableDataProviderFactory.php';
52  $factory->setLanguageAdapter($this->getMockBuilder('ilLanguage')->disableOriginalConstructor()->getMock());
54 
55  $this->assertInstanceOf('ilTermsOfServiceAgreementByLanguageProvider', $provider);
56  $this->assertInstanceOf('ilTermsOfServiceTableDataProvider', $provider);
57 
58  return $provider;
59  }
60 
66  {
68 
69  $client_rel_path = implode('/', array('clients', 'default', 'agreement'));
70  $global_rel_path = implode('/', array('global', 'agreement'));
71 
72  $root = vfsStreamWrapper::setRoot(new vfsStreamDirectory('root'));
73  $customizing_dir = vfsStream::newDirectory('Customizing')->at($root);
74 
75  $client_dir = vfsStream::newDirectory($client_rel_path)->at($customizing_dir);
76  vfsStream::newFile('agreement_de.html', 0777)->at($client_dir);
77  file_put_contents(vfsStream::url('root/Customizing/' . $client_rel_path . '/agreement_de.html'), 'phpunit');
78 
79  $global_dir = vfsStream::newDirectory($global_rel_path)->at($customizing_dir);
80  vfsStream::newFile('agreement_en.html', 0777)->at($global_dir);
81  file_put_contents(vfsStream::url('root/Customizing/' . $global_rel_path . '/agreement_en.html'), 'phpunit');
82 
83  $provider->setSourceDirectories(array(
84  vfsStream::url('root/Customizing/' . $client_rel_path),
85  vfsStream::url('root/Customizing/' . $global_rel_path)
86  ));
87 
88  $lng = $this->getMockBuilder('ilLanguage')->disableOriginalConstructor()->getMock();
89  $installed_languages = array('en', 'de', 'fr');
90  $lng->expects($this->once())->method('getInstalledLanguages')->will($this->onConsecutiveCalls($installed_languages));
91  $provider->setLanguageAdapter($lng);
92 
93  $data = $provider->getList(array(), array());
94  $this->assertArrayHasKey('items', $data);
95  $this->assertArrayHasKey('cnt', $data);
96  $this->assertCount(count($installed_languages), $data['items']);
97  $this->assertEquals(count($installed_languages), $data['cnt']);
98 
99  for($i = 0; $i < count($installed_languages); $i++)
100  {
101  $this->assertArrayHasKey('language', $data['items'][$i]);
102  $this->assertArrayHasKey('agreement', $data['items'][$i]);
103  $this->assertArrayHasKey('agreement_document', $data['items'][$i]);
104  $this->assertArrayHasKey('agreement_document_modification_ts', $data['items'][$i]);
105 
106  if($installed_languages[$i] == 'fr')
107  {
108  $this->assertFalse(file_exists($data['items'][$i]['agreement_document']));
109  }
110  else
111  {
112  $this->assertTrue(file_exists($data['items'][$i]['agreement_document']));
113  }
114  }
115  }
116 
122  {
123  $expected = $this->getMockBuilder('ilLanguage')->disableOriginalConstructor()->getMock();
124 
125  $provider->setLanguageAdapter($expected);
126  $this->assertEquals($expected, $provider->getLanguageAdapter());
127  }
128 
134  {
135  $expected = array('/phpunit', '/ilias');
136 
137  $provider->setSourceDirectories($expected);
138  $this->assertEquals($expected, $provider->getSourceDirectories());
139  }
140 }