ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
Monolog\Handler\NativeMailerHandlerTest Class Reference
+ Inheritance diagram for Monolog\Handler\NativeMailerHandlerTest:
+ Collaboration diagram for Monolog\Handler\NativeMailerHandlerTest:

Public Member Functions

 testConstructorHeaderInjection ()
 InvalidArgumentException More...
 
 testSetterHeaderInjection ()
 InvalidArgumentException More...
 
 testSetterArrayHeaderInjection ()
 InvalidArgumentException More...
 
 testSetterContentTypeInjection ()
 InvalidArgumentException More...
 
 testSetterEncodingInjection ()
 InvalidArgumentException More...
 
 testSend ()
 
 testMessageSubjectFormatting ()
 

Protected Member Functions

 setUp ()
 
- Protected Member Functions inherited from Monolog\TestCase
 getRecord ($level=Logger::WARNING, $message='test', $context=array())
 
 getMultipleRecords ()
 
 getIdentityFormatter ()
 

Detailed Description

Definition at line 23 of file NativeMailerHandlerTest.php.

Member Function Documentation

◆ setUp()

Monolog\Handler\NativeMailerHandlerTest::setUp ( )
protected

Definition at line 25 of file NativeMailerHandlerTest.php.

References $GLOBALS, and array.

26  {
27  $GLOBALS['mail'] = array();
28  }
$GLOBALS['loaded']
Global hash that tracks already loaded includes.
Create styles array
The data for the language used.

◆ testConstructorHeaderInjection()

Monolog\Handler\NativeMailerHandlerTest::testConstructorHeaderInjection ( )

InvalidArgumentException

Definition at line 33 of file NativeMailerHandlerTest.php.

34  {
35  $mailer = new NativeMailerHandler('spammer@example.org', 'dear victim', "receiver@example.org\r\nFrom: faked@attacker.org");
36  }

◆ testMessageSubjectFormatting()

Monolog\Handler\NativeMailerHandlerTest::testMessageSubjectFormatting ( )

Definition at line 100 of file NativeMailerHandlerTest.php.

References $GLOBALS, $params, Monolog\Logger\ERROR, and Monolog\TestCase\getRecord().

101  {
102  $mailer = new NativeMailerHandler('to@example.org', 'Alert: %level_name% %message%', 'from@example.org');
103  $mailer->handle($this->getRecord(Logger::ERROR, "Foo\nBar\r\n\r\nBaz"));
104  $this->assertNotEmpty($GLOBALS['mail']);
105  $this->assertInternalType('array', $GLOBALS['mail']);
106  $this->assertArrayHasKey('0', $GLOBALS['mail']);
107  $params = $GLOBALS['mail'][0];
108  $this->assertCount(5, $params);
109  $this->assertSame('Alert: ERROR Foo Bar Baz', $params[1]);
110  }
const ERROR
Runtime errors.
Definition: Logger.php:57
$GLOBALS['loaded']
Global hash that tracks already loaded includes.
getRecord($level=Logger::WARNING, $message='test', $context=array())
Definition: TestCase.php:19
$params
Definition: example_049.php:96
+ Here is the call graph for this function:

◆ testSend()

Monolog\Handler\NativeMailerHandlerTest::testSend ( )

Definition at line 74 of file NativeMailerHandlerTest.php.

References $GLOBALS, $params, array, Monolog\Logger\ERROR, and Monolog\TestCase\getRecord().

75  {
76  $to = 'spammer@example.org';
77  $subject = 'dear victim';
78  $from = 'receiver@example.org';
79 
80  $mailer = new NativeMailerHandler($to, $subject, $from);
81  $mailer->handleBatch(array());
82 
83  // batch is empty, nothing sent
84  $this->assertEmpty($GLOBALS['mail']);
85 
86  // non-empty batch
87  $mailer->handle($this->getRecord(Logger::ERROR, "Foo\nBar\r\n\r\nBaz"));
88  $this->assertNotEmpty($GLOBALS['mail']);
89  $this->assertInternalType('array', $GLOBALS['mail']);
90  $this->assertArrayHasKey('0', $GLOBALS['mail']);
91  $params = $GLOBALS['mail'][0];
92  $this->assertCount(5, $params);
93  $this->assertSame($to, $params[0]);
94  $this->assertSame($subject, $params[1]);
95  $this->assertStringEndsWith(" test.ERROR: Foo Bar Baz [] []\n", $params[2]);
96  $this->assertSame("From: $from\r\nContent-type: text/plain; charset=utf-8\r\n", $params[3]);
97  $this->assertSame('', $params[4]);
98  }
const ERROR
Runtime errors.
Definition: Logger.php:57
$GLOBALS['loaded']
Global hash that tracks already loaded includes.
getRecord($level=Logger::WARNING, $message='test', $context=array())
Definition: TestCase.php:19
Create styles array
The data for the language used.
$params
Definition: example_049.php:96
+ Here is the call graph for this function:

◆ testSetterArrayHeaderInjection()

Monolog\Handler\NativeMailerHandlerTest::testSetterArrayHeaderInjection ( )

InvalidArgumentException

Definition at line 50 of file NativeMailerHandlerTest.php.

References array.

51  {
52  $mailer = new NativeMailerHandler('spammer@example.org', 'dear victim', 'receiver@example.org');
53  $mailer->addHeader(array("Content-Type: text/html\r\nFrom: faked@attacker.org"));
54  }
Create styles array
The data for the language used.

◆ testSetterContentTypeInjection()

Monolog\Handler\NativeMailerHandlerTest::testSetterContentTypeInjection ( )

InvalidArgumentException

Definition at line 59 of file NativeMailerHandlerTest.php.

60  {
61  $mailer = new NativeMailerHandler('spammer@example.org', 'dear victim', 'receiver@example.org');
62  $mailer->setContentType("text/html\r\nFrom: faked@attacker.org");
63  }

◆ testSetterEncodingInjection()

Monolog\Handler\NativeMailerHandlerTest::testSetterEncodingInjection ( )

InvalidArgumentException

Definition at line 68 of file NativeMailerHandlerTest.php.

69  {
70  $mailer = new NativeMailerHandler('spammer@example.org', 'dear victim', 'receiver@example.org');
71  $mailer->setEncoding("utf-8\r\nFrom: faked@attacker.org");
72  }

◆ testSetterHeaderInjection()

Monolog\Handler\NativeMailerHandlerTest::testSetterHeaderInjection ( )

InvalidArgumentException

Definition at line 41 of file NativeMailerHandlerTest.php.

42  {
43  $mailer = new NativeMailerHandler('spammer@example.org', 'dear victim', 'receiver@example.org');
44  $mailer->addHeader("Content-Type: text/html\r\nFrom: faked@attacker.org");
45  }

The documentation for this class was generated from the following file: