ILIAS  Release_4_4_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
ilTermsOfServiceAcceptanceHistoryProviderTest.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/classes/class.ilTermsOfServiceTableDataProviderFactory.php';
5 require_once 'Services/TermsOfService/classes/class.ilTermsOfServiceTableDatabaseDataProvider.php';
6 
12 {
16  protected $backupGlobals = false;
17 
21  public function setUp()
22  {
23  }
24 
29  {
31  $factory->setDatabaseAdapter($this->getMockBuilder('ilDB')->disableOriginalConstructor()->getMock());
33 
34  $this->assertInstanceOf('ilTermsOfServiceAcceptanceHistoryProvider', $provider);
35  $this->assertInstanceOf('ilTermsOfServiceTableDatabaseDataProvider', $provider);
36  $this->assertInstanceOf('ilTermsOfServiceTableDataProvider', $provider);
37 
38  return $provider;
39  }
40 
44  public function testListCanBeRetrieved()
45  {
46  $database = $this->getMockBuilder('ilDB')->disableOriginalConstructor()->getMock();
47  $result = $this->getMockBuilder('MDB2_BufferedResult_mysqli')->disableOriginalConstructor()->getMock();
48 
50  $factory->setDatabaseAdapter($database);
52 
53  $database->expects($this->exactly(2))->method('query')->with($this->stringContains('SELECT'))->will($this->returnValue($result));
54  $database->expects($this->exactly(4))->method('fetchAssoc')->will($this->onConsecutiveCalls(array('phpunit'), array('phpunit'), array(), array('cnt' => 2)));
55  $database->expects($this->any())->method('like')->with(
56  $this->isType('string'),
57  $this->isType('string'),
58  $this->isType('string')
59  )->will($this->returnArgument(2));
60  $database->expects($this->any())->method('quote')->with($this->anything(), $this->isType('string'))->will($this->returnArgument(0));
61 
62  $data = $provider->getList(
63  array(
64  'limit' => 5,
65  'order_field' => 'ts'
66  ),
67  array(
68  'query' => 'phpunit',
69  'lng' => 'en',
70  'period' => array(
71  'start' => time(),
72  'end' => time()
73  )
74  )
75  );
76  $this->assertArrayHasKey('items', $data);
77  $this->assertArrayHasKey('cnt', $data);
78  $this->assertCount(2, $data['items']);
79  $this->assertEquals(2, $data['cnt']);
80  }
81 
86  {
87  $database = $this->getMockBuilder('ilDB')->disableOriginalConstructor()->getMock();
89  $factory->setDatabaseAdapter($database);
91 
92  try
93  {
94  $provider->getList(array('limit' => 'phpunit'), array());
95  $this->fail('An expected exception has not been raised.');
96  }
97  catch(InvalidArgumentException $e)
98  {
99  }
100 
101  try
102  {
103  $provider->getList(array('limit' => 5, 'offset' => 'phpunit'), array());
104  $this->fail('An expected exception has not been raised.');
105  }
106  catch(InvalidArgumentException $e)
107  {
108  }
109 
110  try
111  {
112  $provider->getList(array('order_field' => 'phpunit'), array());
113  $this->fail('An expected exception has not been raised.');
114  }
115  catch(InvalidArgumentException $e)
116  {
117  }
118 
119  try
120  {
121  $provider->getList(array('order_field' => 5), array());
122  $this->fail('An expected exception has not been raised.');
123  }
124  catch(InvalidArgumentException $e)
125  {
126  }
127 
128  try
129  {
130  $provider->getList(array('order_field' => 'ts', 'order_direction' => 'phpunit'), array());
131  $this->fail('An expected exception has not been raised.');
132  }
133  catch(InvalidArgumentException $e)
134  {
135  }
136  }
137 }