ILIAS  Release_4_4_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 
4 require_once 'vfsStream/vfsStream.php';
5 
11 {
15  protected $backupGlobals = false;
16 
20  public function setUp()
21  {
22  vfsStreamWrapper::register();
23  }
24 
29  {
30  require_once 'Services/TermsOfService/classes/class.ilTermsOfServiceTableDataProviderFactory.php';
32  $factory->setLanguageAdapter($this->getMockBuilder('ilLanguage')->disableOriginalConstructor()->getMock());
34 
35  $this->assertInstanceOf('ilTermsOfServiceAgreementByLanguageProvider', $provider);
36  $this->assertInstanceOf('ilTermsOfServiceTableDataProvider', $provider);
37 
38  return $provider;
39  }
40 
46  {
47  $client_rel_path = implode('/', array('clients', 'default', 'agreement'));
48  $global_rel_path = implode('/', array('global', 'agreement'));
49 
50  $root = vfsStreamWrapper::setRoot(new vfsStreamDirectory('root'));
51  $customizing_dir = vfsStream::newDirectory('Customizing')->at($root);
52 
53  $client_dir = vfsStream::newDirectory($client_rel_path)->at($customizing_dir);
54  vfsStream::newFile('agreement_de.html', 0777)->at($client_dir);
55  file_put_contents(vfsStream::url('root/Customizing/' . $client_rel_path . '/agreement_de.html'), 'phpunit');
56 
57  $global_dir = vfsStream::newDirectory($global_rel_path)->at($customizing_dir);
58  vfsStream::newFile('agreement_en.html', 0777)->at($global_dir);
59  file_put_contents(vfsStream::url('root/Customizing/' . $global_rel_path . '/agreement_en.html'), 'phpunit');
60 
61  $provider->setSourceDirectories(array(
62  vfsStream::url('root/Customizing/' . $client_rel_path),
63  vfsStream::url('root/Customizing/' . $global_rel_path)
64  ));
65 
66  $lng = $this->getMockBuilder('ilLanguage')->disableOriginalConstructor()->getMock();
67  $installed_languages = array('en', 'de', 'fr');
68  $lng->expects($this->once())->method('getInstalledLanguages')->will($this->onConsecutiveCalls($installed_languages));
69  $provider->setLanguageAdapter($lng);
70 
71  $data = $provider->getList(array(), array());
72  $this->assertArrayHasKey('items', $data);
73  $this->assertArrayHasKey('cnt', $data);
74  $this->assertCount(count($installed_languages), $data['items']);
75  $this->assertEquals(count($installed_languages), $data['cnt']);
76 
77  for($i = 0; $i < count($installed_languages); $i++)
78  {
79  $this->assertArrayHasKey('language', $data['items'][$i]);
80  $this->assertArrayHasKey('agreement', $data['items'][$i]);
81  $this->assertArrayHasKey('agreement_document', $data['items'][$i]);
82  $this->assertArrayHasKey('agreement_document_modification_ts', $data['items'][$i]);
83 
84  if($installed_languages[$i] == 'fr')
85  {
86  $this->assertFalse(file_exists($data['items'][$i]['agreement_document']));
87  }
88  else
89  {
90  $this->assertTrue(file_exists($data['items'][$i]['agreement_document']));
91  }
92  }
93  }
94 
100  {
101  $expected = $this->getMockBuilder('ilLanguage')->disableOriginalConstructor()->getMock();
102 
103  $provider->setLanguageAdapter($expected);
104  $this->assertEquals($expected, $provider->getLanguageAdapter());
105  }
106 
112  {
113  $expected = array('/phpunit', '/ilias');
114 
115  $provider->setSourceDirectories($expected);
116  $this->assertEquals($expected, $provider->getSourceDirectories());
117  }
118 }