TYPO3 CMS  TYPO3_6-2
DatabaseWriterTest.php
Go to the documentation of this file.
1 <?php
3 
19 
26 
30  public function getTableReturnsPreviouslySetTable() {
31  $logTable = $this->getUniqueId('logtable_');
33  $subject = $this->getMock('TYPO3\\CMS\Core\Log\\Writer\\DatabaseWriter', array('dummy'), array(), '', FALSE);
34  $subject->setLogTable($logTable);
35  $this->assertSame($logTable, $subject->getLogTable());
36  }
37 
42  public function writeLogThrowsExceptionIfDatabaseInsertFailed() {
43  $GLOBALS['TYPO3_DB'] = $this->getMock('TYPO3\\CMS\\Core\\Database\\DatabaseConnection', array(), array(), '', FALSE);
44  $GLOBALS['TYPO3_DB']->expects($this->once())->method('exec_INSERTquery')->will($this->returnValue(FALSE));
46  $logRecordMock = $this->getMock('TYPO3\\CMS\\Core\\Log\\LogRecord', array(), array(), '', FALSE);
48  $subject = $this->getMock('TYPO3\\CMS\Core\Log\\Writer\\DatabaseWriter', array('dummy'), array(), '', FALSE);
49  $subject->writeLog($logRecordMock);
50  }
51 
55  public function writeLogInsertsToSpecifiedTable() {
56  $logTable = $this->getUniqueId('logtable_');
57  $GLOBALS['TYPO3_DB'] = $this->getMock('TYPO3\\CMS\\Core\\Database\\DatabaseConnection', array(), array(), '', FALSE);
58  $GLOBALS['TYPO3_DB']->expects($this->once())->method('exec_INSERTquery')->with($logTable, $this->anything());
60  $logRecordMock = $this->getMock('TYPO3\\CMS\\Core\\Log\\LogRecord', array(), array(), '', FALSE);
62  $subject = $this->getMock('TYPO3\\CMS\Core\Log\\Writer\\DatabaseWriter', array('dummy'), array(), '', FALSE);
63  $subject->setLogTable($logTable);
64  $subject->writeLog($logRecordMock);
65  }
66 
70  public function writeLogInsertsLogRecordWithGivenProperties() {
71  $logRecordData = array(
72  'request_id' => $this->getUniqueId('request_id'),
73  'time_micro' => $this->getUniqueId('time_micro'),
74  'component' => $this->getUniqueId('component'),
75  'level' => $this->getUniqueId('level'),
76  'message' => $this->getUniqueId('message'),
77  'data' => '',
78  );
80  $logRecordFixture = $this->getMock('TYPO3\\CMS\\Core\\Log\\LogRecord', array(), array(), '', FALSE);
81  $logRecordFixture->expects($this->any())->method('getRequestId')->will($this->returnValue($logRecordData['request_id']));
82  $logRecordFixture->expects($this->any())->method('getCreated')->will($this->returnValue($logRecordData['time_micro']));
83  $logRecordFixture->expects($this->any())->method('getComponent')->will($this->returnValue($logRecordData['component']));
84  $logRecordFixture->expects($this->any())->method('getLevel')->will($this->returnValue($logRecordData['level']));
85  $logRecordFixture->expects($this->any())->method('getMessage')->will($this->returnValue($logRecordData['message']));
86  $logRecordFixture->expects($this->any())->method('getData')->will($this->returnValue(array()));
87 
89  $subject = new DatabaseWriter();
90 
91  $GLOBALS['TYPO3_DB'] = $this->getMock('TYPO3\\CMS\\Core\\Database\\DatabaseConnection', array(), array(), '', FALSE);
92  $GLOBALS['TYPO3_DB']->expects($this->once())->method('exec_INSERTquery')->with($this->anything(), $logRecordData);
93 
94  $subject->writeLog($logRecordFixture);
95  }
96 }
if(!defined('TYPO3_MODE')) $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_userauth.php']['logoff_pre_processing'][]