ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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 'Services/TermsOfService/test/ilTermsOfServiceBaseTest.php';
5 
7 
13 {
17  protected $backupGlobals = false;
18 
22  public function setUp()
23  {
24  if(!defined('CLIENT_ID'))
25  {
26  define('CLIENT_ID', 'phpunit');
27  }
28 
29  vfs\vfsStreamWrapper::register();
30 
31  parent::setUp();
32  }
33 
38  {
39  require_once 'Services/TermsOfService/classes/class.ilTermsOfServiceTableDataProviderFactory.php';
41  $factory->setLanguageAdapter($this->getMockBuilder('ilLanguage')->setMethods(array('toJSON', 'getInstalledLanguages'))->disableOriginalConstructor()->getMock());
43 
44  $this->assertInstanceOf('ilTermsOfServiceAgreementByLanguageProvider', $provider);
45  $this->assertInstanceOf('ilTermsOfServiceTableDataProvider', $provider);
46 
47  return $provider;
48  }
49 
55  {
56  $client_rel_path = implode('/', array('clients', 'default', 'agreement'));
57  $global_rel_path = implode('/', array('global', 'agreement'));
58 
59  $root = vfs\vfsStreamWrapper::setRoot(new vfs\vfsStreamDirectory('root'));
60  $customizing_dir = vfs\vfsStream::newDirectory('Customizing')->at($root);
61 
62  $client_dir = vfs\vfsStream::newDirectory($client_rel_path)->at($customizing_dir);
63  vfs\vfsStream::newFile('agreement_de.html', 0777)->at($client_dir);
64  file_put_contents(vfs\vfsStream::url('root/Customizing/' . $client_rel_path . '/agreement_de.html'), 'phpunit');
65 
66  $global_dir = vfs\vfsStream::newDirectory($global_rel_path)->at($customizing_dir);
67  vfs\vfsStream::newFile('agreement_en.html', 0777)->at($global_dir);
68  file_put_contents(vfs\vfsStream::url('root/Customizing/' . $global_rel_path . '/agreement_en.html'), 'phpunit');
69 
70  $provider->setSourceDirectories(array(
71  vfs\vfsStream::url('root/Customizing/' . $client_rel_path),
72  vfs\vfsStream::url('root/Customizing/' . $global_rel_path)
73  ));
74 
75  $lng = $this->getMockBuilder('ilLanguage')->setMethods(array('toJSON', 'getInstalledLanguages'))->disableOriginalConstructor()->getMock();
76  $installed_languages = array('en', 'de', 'fr');
77  $lng->expects($this->once())->method('getInstalledLanguages')->will($this->onConsecutiveCalls($installed_languages));
78  $provider->setLanguageAdapter($lng);
79 
80  $data = $provider->getList(array(), array());
81  $this->assertArrayHasKey('items', $data);
82  $this->assertArrayHasKey('cnt', $data);
83  $this->assertCount(count($installed_languages), $data['items']);
84  $this->assertEquals(count($installed_languages), $data['cnt']);
85 
86  for($i = 0; $i < count($installed_languages); $i++)
87  {
88  $this->assertArrayHasKey('language', $data['items'][$i]);
89  $this->assertArrayHasKey('agreement', $data['items'][$i]);
90  $this->assertArrayHasKey('agreement_document', $data['items'][$i]);
91  $this->assertArrayHasKey('agreement_document_modification_ts', $data['items'][$i]);
92 
93  if($installed_languages[$i] == 'fr')
94  {
95  $this->assertFalse(file_exists($data['items'][$i]['agreement_document']));
96  }
97  else
98  {
99  $this->assertTrue(file_exists($data['items'][$i]['agreement_document']));
100  }
101  }
102  }
103 
109  {
110  $expected = $this->getMockBuilder('ilLanguage')->setMethods(array('toJSON', 'getInstalledLanguages'))->disableOriginalConstructor()->getMock();
111 
112  $provider->setLanguageAdapter($expected);
113  $this->assertEquals($expected, $provider->getLanguageAdapter());
114  }
115 
121  {
122  $expected = array('/phpunit', '/ilias');
123 
124  $provider->setSourceDirectories($expected);
125  $this->assertEquals($expected, $provider->getSourceDirectories());
126  }
127 }
getList(array $params, array $filter)
{Table paramaters like limit or order Filter settings array}
testProviderShouldReturnSourceDirectoriesWhenSourceDirectoriesAreSet(ilTermsOfServiceAgreementByLanguageProvider $provider)
testProviderShouldReturnLanguageAdapterWhenLanguageAdapterIsSet(ilTermsOfServiceAgreementByLanguageProvider $provider)
testProviderReturnsAResultForEveryInstalledLanguage(ilTermsOfServiceAgreementByLanguageProvider $provider)
Create styles array
The data for the language used.
global $lng
Definition: privfeed.php:17
defined( 'APPLICATION_ENV')||define( 'APPLICATION_ENV'
Definition: bootstrap.php:27