88
99use Tx \Mailer \SMTP ;
1010use Tx \Mailer \Message ;
11- use ERB \ Testing \ Tools \ TestHelper ;
11+ use \ Monolog \ Logger ;
1212
1313/**
1414 * Class SMTPTest
@@ -26,89 +26,79 @@ class SMTPTest extends TestCase
2626 protected $ smtp ;
2727
2828 /**
29- * @var TestHelper
29+ * @var Message
3030 */
31- protected $ testHelper ;
32-
33- /** @var Message */
3431 protected $ message ;
3532
36-
3733 public function setup ()
3834 {
39- $ this ->smtp = new SMTP ();
40- $ this ->testHelper = new TestHelper ();
4135 $ this ->message = new Message ();
42- $ this ->message ->setFrom ('You ' , 'nobody@nowhere.no ' )
43- ->addTo ('Them ' , 'them@nowhere.no ' )
44- ->setSubject ('This is a test ' )
45- ->setBody ('This is a test part two ' );
46- usleep (self ::DELAY );
47- }
48-
49- public function testSetServer ()
50- {
51- $ result = $ this ->smtp ->setServer ('localhost ' , '25 ' , null );
52- $ this ->assertEquals ('localhost ' , $ this ->testHelper ->getPropertyValue ($ this ->smtp , 'host ' ));
53- $ this ->assertEquals ('25 ' , $ this ->testHelper ->getPropertyValue ($ this ->smtp , 'port ' ));
54- $ this ->assertSame ($ this ->smtp , $ result );
55- usleep (self ::DELAY );
56- }
57-
58- public function testSetAuth ()
59- {
60- $ result = $ this ->smtp ->setAuth ('none ' , 'none ' );
61-
62- $ this ->assertEquals ('none ' , $ this ->testHelper ->getPropertyValue ($ this ->smtp , 'username ' ));
63- $ this ->assertEquals ('none ' , $ this ->testHelper ->getPropertyValue ($ this ->smtp , 'password ' ));
64- $ this ->assertSame ($ this ->smtp , $ result );
36+ $ this ->message
37+ ->setFrom (self ::FROM_NAME , self ::FROM_EMAIL ) // your name, your email
38+ //->setFakeFrom('Hello', 'bot@fakeemail.com') // a fake name, a fake email
39+ ->addTo (self ::TO_NAME , self ::TO_EMAIL )
40+ ->addCc (self ::CC_NAME , self ::CC_EMAIL )
41+ ->addBcc (self ::BCC_NAME , self ::BCC_EMAIL )
42+ ->setSubject ('Test SMTP ' . time ())
43+ ->setBody ('<h1>for test</h1> ' )
44+ ->addAttachment ('test ' , __FILE__ );
6545 usleep (self ::DELAY );
6646 }
6747
68- public function testMessage ()
48+ public function testSend ()
6949 {
70- $ this ->smtp ->setServer (self ::SERVER , self ::PORT , null )
50+ $ this ->smtp = new SMTP (new Logger ('SMTP ' ));
51+ $ this ->smtp
52+ ->setServer (self ::SERVER , self ::PORT )
7153 ->setAuth (self ::USER , self ::PASS );
7254
7355 $ status = $ this ->smtp ->send ($ this ->message );
7456 $ this ->assertTrue ($ status );
7557 usleep (self ::DELAY );
7658 }
7759
78- public function testTLSMessage ()
60+ public function testTLSSend ()
7961 {
80- $ this ->smtp ->setServer (self ::SERVER , self ::PORT , 'tls ' )
81- ->setAuth (self ::USER , self ::PASS );
62+ $ this ->smtp = new SMTP (new Logger ('SMTP.tls ' ));
63+ $ this ->smtp
64+ ->setServer (self ::SERVER , self ::PORT_TLS , 'tls ' )
65+ ->setAuth (self ::USER , self ::PASS );
8266
8367 $ status = $ this ->smtp ->send ($ this ->message );
8468 $ this ->assertTrue ($ status );
8569 usleep (self ::DELAY );
8670 }
8771
88- public function testTLSv10Message ()
72+ public function testTLSv10Send ()
8973 {
90- $ this ->smtp ->setServer (self ::SERVER , self ::PORT , 'tlsv1.0 ' )
91- ->setAuth (self ::USER , self ::PASS );
74+ $ this ->smtp = new SMTP (new Logger ('SMTP.tlsv1.0 ' ));
75+ $ this ->smtp
76+ ->setServer (self ::SERVER , self ::PORT_TLS , 'tlsv1.0 ' )
77+ ->setAuth (self ::USER , self ::PASS );
9278
9379 $ status = $ this ->smtp ->send ($ this ->message );
9480 $ this ->assertTrue ($ status );
9581 usleep (self ::DELAY );
9682 }
9783
98- public function testTLSv11Message ()
84+ public function testTLSv11Send ()
9985 {
100- $ this ->smtp ->setServer (self ::SERVER , self ::PORT , 'tlsv1.1 ' )
101- ->setAuth (self ::USER , self ::PASS );
86+ $ this ->smtp = new SMTP (new Logger ('SMTP.tlsv1.1 ' ));
87+ $ this ->smtp
88+ ->setServer (self ::SERVER , self ::PORT_TLS , 'tlsv1.1 ' )
89+ ->setAuth (self ::USER , self ::PASS );
10290
10391 $ status = $ this ->smtp ->send ($ this ->message );
10492 $ this ->assertTrue ($ status );
10593 usleep (self ::DELAY );
10694 }
10795
108- public function testTLSv12Message ()
96+ public function testTLSv12Send ()
10997 {
110- $ this ->smtp ->setServer (self ::SERVER , self ::PORT , 'tlsv1.2 ' )
111- ->setAuth (self ::USER , self ::PASS );
98+ $ this ->smtp = new SMTP (new Logger ('SMTP.tlsv1.2 ' ));
99+ $ this ->smtp
100+ ->setServer (self ::SERVER , self ::PORT_TLS , 'tlsv1.2 ' )
101+ ->setAuth (self ::USER , self ::PASS );
112102
113103 $ status = $ this ->smtp ->send ($ this ->message );
114104 $ this ->assertTrue ($ status );
@@ -120,17 +110,13 @@ public function testTLSv12Message()
120110 */
121111 public function testConnectSMTPException ()
122112 {
123- $ this ->smtp ->setServer ('localhost ' , "99999 " , null )
113+ $ this ->smtp = new SMTP (new Logger ('SMTP.FakePort ' ));
114+ $ this ->smtp
115+ ->setServer ('localhost ' , "99999 " , null )
124116 ->setAuth ('none ' , 'none ' );
125- $ message = new Message ();
126- $ message ->setFrom ('You ' , 'nobody@nowhere.no ' )
127- ->addTo ('Them ' , 'them@nowhere.no ' )
128- ->setSubject ('This is a test ' )
129- ->setBody ('This is a test part two ' );
130117
131- $ this ->smtp ->send ($ message );
118+ $ this ->smtp ->send ($ this -> message );
132119 usleep (self ::DELAY );
133120 }
134121
135-
136122}
0 commit comments