scratch – Blame information for rev

Subversion Repositories:
Rev:
Rev Author Line No. Line
115 office 1 <?php
2  
3 /*
4 * This file is part of the Monolog package.
5 *
6 * (c) Jordi Boggiano <j.boggiano@seld.be>
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
11  
12 namespace Monolog\Processor;
13  
14 use Monolog\TestCase;
15  
16 class WebProcessorTest extends TestCase
17 {
18 public function testProcessor()
19 {
20 $server = array(
21 'REQUEST_URI' => 'A',
22 'REMOTE_ADDR' => 'B',
23 'REQUEST_METHOD' => 'C',
24 'HTTP_REFERER' => 'D',
25 'SERVER_NAME' => 'F',
26 'UNIQUE_ID' => 'G',
27 );
28  
29 $processor = new WebProcessor($server);
30 $record = $processor($this->getRecord());
31 $this->assertEquals($server['REQUEST_URI'], $record['extra']['url']);
32 $this->assertEquals($server['REMOTE_ADDR'], $record['extra']['ip']);
33 $this->assertEquals($server['REQUEST_METHOD'], $record['extra']['http_method']);
34 $this->assertEquals($server['HTTP_REFERER'], $record['extra']['referrer']);
35 $this->assertEquals($server['SERVER_NAME'], $record['extra']['server']);
36 $this->assertEquals($server['UNIQUE_ID'], $record['extra']['unique_id']);
37 }
38  
39 public function testProcessorDoNothingIfNoRequestUri()
40 {
41 $server = array(
42 'REMOTE_ADDR' => 'B',
43 'REQUEST_METHOD' => 'C',
44 );
45 $processor = new WebProcessor($server);
46 $record = $processor($this->getRecord());
47 $this->assertEmpty($record['extra']);
48 }
49  
50 public function testProcessorReturnNullIfNoHttpReferer()
51 {
52 $server = array(
53 'REQUEST_URI' => 'A',
54 'REMOTE_ADDR' => 'B',
55 'REQUEST_METHOD' => 'C',
56 'SERVER_NAME' => 'F',
57 );
58 $processor = new WebProcessor($server);
59 $record = $processor($this->getRecord());
60 $this->assertNull($record['extra']['referrer']);
61 }
62  
63 public function testProcessorDoesNotAddUniqueIdIfNotPresent()
64 {
65 $server = array(
66 'REQUEST_URI' => 'A',
67 'REMOTE_ADDR' => 'B',
68 'REQUEST_METHOD' => 'C',
69 'SERVER_NAME' => 'F',
70 );
71 $processor = new WebProcessor($server);
72 $record = $processor($this->getRecord());
73 $this->assertFalse(isset($record['extra']['unique_id']));
74 }
75  
76 public function testProcessorAddsOnlyRequestedExtraFields()
77 {
78 $server = array(
79 'REQUEST_URI' => 'A',
80 'REMOTE_ADDR' => 'B',
81 'REQUEST_METHOD' => 'C',
82 'SERVER_NAME' => 'F',
83 );
84  
85 $processor = new WebProcessor($server, array('url', 'http_method'));
86 $record = $processor($this->getRecord());
87  
88 $this->assertSame(array('url' => 'A', 'http_method' => 'C'), $record['extra']);
89 }
90  
91 public function testProcessorConfiguringOfExtraFields()
92 {
93 $server = array(
94 'REQUEST_URI' => 'A',
95 'REMOTE_ADDR' => 'B',
96 'REQUEST_METHOD' => 'C',
97 'SERVER_NAME' => 'F',
98 );
99  
100 $processor = new WebProcessor($server, array('url' => 'REMOTE_ADDR'));
101 $record = $processor($this->getRecord());
102  
103 $this->assertSame(array('url' => 'B'), $record['extra']);
104 }
105  
106 /**
107 * @expectedException UnexpectedValueException
108 */
109 public function testInvalidData()
110 {
111 new WebProcessor(new \stdClass);
112 }
113 }