ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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
4require_once 'Services/TermsOfService/classes/class.ilTermsOfServiceTableDataProviderFactory.php';
5require_once 'Services/TermsOfService/classes/class.ilTermsOfServiceTableDatabaseDataProvider.php';
6require_once 'Services/TermsOfService/test/ilTermsOfServiceBaseTest.php';
7
13{
17 protected $backupGlobals = false;
18
22 public function setUp()
23 {
24 }
25
30 {
32 $factory->setDatabaseAdapter($this->getMockBuilder('ilDBInterface')->getMock());
34
35 $this->assertInstanceOf('ilTermsOfServiceAcceptanceHistoryProvider', $provider);
36 $this->assertInstanceOf('ilTermsOfServiceTableDatabaseDataProvider', $provider);
37 $this->assertInstanceOf('ilTermsOfServiceTableDataProvider', $provider);
38
39 return $provider;
40 }
41
45 public function testListCanBeRetrieved()
46 {
47 $database = $this->getMockBuilder('ilDBInterface')->getMock();
48 $result = $this->getMockBuilder('ilDBStatement')->getMock();
49
51 $factory->setDatabaseAdapter($database);
53
54 $database->expects($this->exactly(2))->method('query')->with($this->stringContains('SELECT'))->will($this->returnValue($result));
55 $database->expects($this->exactly(4))->method('fetchAssoc')->will($this->onConsecutiveCalls(array('phpunit'), array('phpunit'), array(), array('cnt' => 2)));
56 $database->expects($this->any())->method('like')->with(
57 $this->isType('string'),
58 $this->isType('string'),
59 $this->isType('string')
60 )->will($this->returnArgument(2));
61 $database->expects($this->any())->method('quote')->with($this->anything(), $this->isType('string'))->will($this->returnArgument(0));
62
63 $data = $provider->getList(
64 array(
65 'limit' => 5,
66 'order_field' => 'ts'
67 ),
68 array(
69 'query' => 'phpunit',
70 'lng' => 'en',
71 'period' => array(
72 'start' => time(),
73 'end' => time()
74 )
75 )
76 );
77 $this->assertArrayHasKey('items', $data);
78 $this->assertArrayHasKey('cnt', $data);
79 $this->assertCount(2, $data['items']);
80 $this->assertEquals(2, $data['cnt']);
81 }
82
87 {
88 $database = $this->getMockBuilder('ilDBInterface')->getMock();
90 $factory->setDatabaseAdapter($database);
92
93 try {
94 $provider->getList(array('limit' => 'phpunit'), array());
95 $this->fail('An expected exception has not been raised.');
96 } catch (InvalidArgumentException $e) {
97 }
98
99 try {
100 $provider->getList(array('limit' => 5, 'offset' => 'phpunit'), array());
101 $this->fail('An expected exception has not been raised.');
102 } catch (InvalidArgumentException $e) {
103 }
104
105 try {
106 $provider->getList(array('order_field' => 'phpunit'), array());
107 $this->fail('An expected exception has not been raised.');
108 } catch (InvalidArgumentException $e) {
109 }
110
111 try {
112 $provider->getList(array('order_field' => 5), array());
113 $this->fail('An expected exception has not been raised.');
114 } catch (InvalidArgumentException $e) {
115 }
116
117 try {
118 $provider->getList(array('order_field' => 'ts', 'order_direction' => 'phpunit'), array());
119 $this->fail('An expected exception has not been raised.');
120 } catch (InvalidArgumentException $e) {
121 }
122 }
123}
$result
$factory
Definition: metadata.php:47
An exception for terminatinating execution or to throw for unit testing.