Changeset 1086
- Timestamp:
- 11/29/07 15:47:21 (9 months ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/src/main/php/net/stubbles/util/log/stubBaseLogData.php
r1084 r1086 8 8 */ 9 9 stubClassLoader::load('net.stubbles.util.log.stubLogData', 10 'net.stubbles.util.log.stubLogger' 10 'net.stubbles.util.log.stubLogger', 11 'net.stubbles.ipo.session.stubSession' 11 12 ); 12 13 /** … … 52 53 * log appender will not mess up the log data. 53 54 * 54 * @param st ring $target target where the log data should go to55 * @param int $level optional log level of the log data56 * @param string $sessionId optional session id of current user55 * @param stubSession $session the session of the current user 56 * @param string $target target where the log data should go to 57 * @param int $level optional log level of the log data 57 58 */ 58 public function __construct( $target, $level = stubLogger::LEVEL_INFO, $sessionId = null)59 public function __construct(stubSession $session, $target, $level = stubLogger::LEVEL_INFO) 59 60 { 60 61 $this->target = $target; 61 62 $this->level = $level; 62 63 $this->logData = array(date('Y-m-d H:i:s'), 63 (string) $sessionId64 $session->getId() 64 65 ); 65 66 } trunk/src/main/php/net/stubbles/util/log/stubLogDataFactory.php
r1084 r1086 33 33 $fqClassName = stubRegistry::getConfig('net.stubbles.util.log.class', 'net.stubbles.util.log.stubBaseLogData'); 34 34 $nqClassName = stubClassLoader::getNonQualifiedClassName($fqClassName); 35 if (class_exists($nqClassName, false) == =false) {35 if (class_exists($nqClassName, false) == false) { 36 36 stubClassLoader::load($fqClassName); 37 37 } 38 38 39 $logData = new $nqClassName($ target, $level, $session->getId());40 if (($logData instanceof stubLogData) == =false) {39 $logData = new $nqClassName($session, $target, $level); 40 if (($logData instanceof stubLogData) == false) { 41 41 throw new stubRuntimeException('Configured net.stubbles.util.log.class is not an instance of stubLogData.'); 42 42 } trunk/src/test/php/net/stubbles/util/log/stubBaseLogDataTestCase.php
r1084 r1086 1 1 <?php 2 2 /** 3 * Test for net ::stubbles::util::log::stubBaseLogData.3 * Test for net.stubbles.util.log.stubBaseLogData. 4 4 * 5 5 * @author Frank Kleine <mikey@stubbles.net> … … 8 8 */ 9 9 stubClassLoader::load('net.stubbles.util.log.stubBaseLogData'); 10 Mock::generate('stubSession'); 10 11 /** 11 * Test for net ::stubbles::util::log::stubBaseLogData.12 * Test for net.stubbles.util.log.stubBaseLogData. 12 13 * 13 14 * @package stubbles … … 17 18 { 18 19 /** 19 * assure that data is handles as expected 20 * instance to test 21 * 22 * @var stubBaseLogData 20 23 */ 21 public function testWithSessionId() 24 protected $baseLogData; 25 26 /** 27 * set up the test environment 28 */ 29 public function setUp() 22 30 { 23 $baseLogData = new stubBaseLogData('bar', stubLogger::LEVEL_INFO, 'foo'); 24 $this->assertEqual($baseLogData->getLevel(), stubLogger::LEVEL_INFO); 25 $this->assertEqual($baseLogData->getTarget(), 'bar'); 26 $baseLogData->addData("ba\r\nz" . stubLogData::SEPERATOR . 'vvv'); 27 $data = explode(stubLogData::SEPERATOR, $baseLogData->get()); 28 $this->assertEqual($data[1], 'foo'); 29 $this->assertEqual($data[2], 'ba<nl>zvvv'); 31 $mockSession = new MockstubSession(); 32 $mockSession->setReturnValue('getId', 'foo'); 33 $this->baseLogData = new stubBaseLogData($mockSession, 'bar'); 30 34 } 31 35 32 36 /** 33 37 * assure that data is handles as expected 34 38 */ 35 public function test WithoutSessionId()39 public function testData() 36 40 { 37 $baseLogData = new stubBaseLogData('bar'); 38 $this->assertEqual($baseLogData->getLevel(), stubLogger::LEVEL_INFO); 39 $this->assertEqual($baseLogData->getTarget(), 'bar'); 40 $baseLogData->addData("ba\r\nz" . stubLogData::SEPERATOR . 'vvv'); 41 $data = explode(stubLogData::SEPERATOR, $baseLogData->get()); 42 $this->assertEqual($data[1], ''); 41 $this->assertEqual($this->baseLogData->getLevel(), stubLogger::LEVEL_INFO); 42 $this->assertEqual($this->baseLogData->getTarget(), 'bar'); 43 $this->baseLogData->addData("ba\r\nz" . stubLogData::SEPERATOR . 'vvv'); 44 $data = explode(stubLogData::SEPERATOR, $this->baseLogData->get()); 45 $this->assertEqual($data[1], 'foo'); 43 46 $this->assertEqual($data[2], 'ba<nl>zvvv'); 44 47 }
