mail = new ezcMail(); } public function testProperties() { $this->assertSetPropertyFails( $this->mail, "does_not_exist", array( 42 ) ); $this->assertSetProperty( $this->mail, "to", array( array( 'email' => 'fh@ez.no' ) ) ); try { $this->mail->timestamp = 0; $this->fail( 'Expected exception not thrown' ); } catch ( ezcBasePropertyPermissionException $e ) { $this->assertEquals( "The property 'timestamp' is read-only.", $e->getMessage() ); } try { $this->mail->headers = null; $this->fail( 'Expected exception not thrown' ); } catch ( ezcBasePropertyPermissionException $e ) { $this->assertEquals( "The property 'headers' is read-only.", $e->getMessage() ); } } public function testAddAddresses() { $this->mail->addTo( new ezcMailAddress( 'fh@ez.no', 'Frederik Holljen' ) ); $this->mail->addTo( new ezcMailAddress( 'bh@ez.no' ) ); $this->assertEquals( array( new ezcMailAddress( 'fh@ez.no', 'Frederik Holljen' ), new ezcMailAddress( 'bh@ez.no' ) ), $this->mail->to ); $this->mail->addCc( new ezcMailAddress( 'fh@ez.no', 'Frederik Holljen' ) ); $this->mail->addCc( new ezcMailAddress( 'bh@ez.no' ) ); $this->assertEquals( array( new ezcMailAddress( 'fh@ez.no', 'Frederik Holljen' ), new ezcMailAddress( 'bh@ez.no' ) ), $this->mail->cc ); $this->mail->addBcc( new ezcMailAddress( 'fh@ez.no', 'Frederik Holljen' ) ); $this->mail->addBcc( new ezcMailAddress( 'bh@ez.no' ) ); $this->assertEquals( array( new ezcMailAddress( 'fh@ez.no', 'Frederik Holljen' ), new ezcMailAddress( 'bh@ez.no' ) ), $this->mail->bcc ); } public function testAddAddresses2() { $this->mail->from = new ezcMailAddress( 'from@ez.no' ); $this->mail->addTo( new ezcMailAddress( 'fh@ez.no', 'Frederik Holljen' ) ); $this->mail->addTo( new ezcMailAddress( 'bh@ez.no' ) ); $this->mail->addCc( new ezcMailAddress( 'dr@ez.no', 'Derick Rethans' ) ); $this->mail->addBcc( new ezcMailAddress( 'amos@ez.no' ) ); $expected = "From: from@ez.no" . ezcMailTools::lineBreak() . "To: Frederik Holljen , bh@ez.no" . ezcMailTools::lineBreak() . "Cc: Derick Rethans " . ezcMailTools::lineBreak() . "Bcc: amos@ez.no" . ezcMailTools::lineBreak() . "Subject: " . ezcMailTools::lineBreak() . "MIME-Version: 1.0" . ezcMailTools::lineBreak() . "User-Agent: eZ components"; $return = $this->mail->generate(); // cut away the Date and Message-ID headers as there is no way to predict what they will be $return = join( ezcMailTools::lineBreak(), array_slice( explode( ezcMailTools::lineBreak(), $return ), 0, 7 ) ); $this->assertEquals( $expected, $return ); } public function testSubjectWithCharset() { $this->mail->from = new ezcMailAddress( 'from@ez.no' ); $this->mail->addTo( new ezcMailAddress( 'fh@ez.no', 'Frederik Holljen' ) ); $this->mail->subject = "Døtte er en test"; $this->mail->subjectCharset = 'ISO-8859-1'; $expected = "From: from@ez.no" . ezcMailTools::lineBreak() . "To: Frederik Holljen " . ezcMailTools::lineBreak() . "Subject: =?ISO-8859-1?B?RPh0dGUgZXIgZW4gdGVzdA==?=" . ezcMailTools::lineBreak() . "MIME-Version: 1.0" . ezcMailTools::lineBreak() . "User-Agent: eZ components"; $return = $this->mail->generate(); // cut away the Date and Message-ID headers as there is no way to predict what they will be $return = join( ezcMailTools::lineBreak(), array_slice( explode( ezcMailTools::lineBreak(), $return ), 0, 5 ) ); $this->assertEquals( $expected, $return ); } public function testHeadersWithCharset() { $this->mail->from = new ezcMailAddress( 'fh@ez.no', 'Fræderik Hølljen', 'ISO-8859-1' ); $this->mail->addTo( new ezcMailAddress( 'fh@ez.no', 'Fræderik Hølljen','ISO-8859-1' ) ); $this->mail->addCc( new ezcMailAddress( 'fh@ez.no', 'Fræderik Hølljen','ISO-8859-1' ) ); $this->mail->addBcc( new ezcMailAddress( 'fh@ez.no', 'Fræderik Hølljen','ISO-8859-1' ) ); $this->mail->subject = "Døtte er en test"; $this->mail->subjectCharset = 'ISO-8859-1'; $expected = "From: =?ISO-8859-1?B?RnLmZGVyaWsgSPhsbGplbg==?= " . ezcMailTools::lineBreak() . "To: =?ISO-8859-1?B?RnLmZGVyaWsgSPhsbGplbg==?= " . ezcMailTools::lineBreak() . "Cc: =?ISO-8859-1?B?RnLmZGVyaWsgSPhsbGplbg==?= " . ezcMailTools::lineBreak() . "Bcc: =?ISO-8859-1?B?RnLmZGVyaWsgSPhsbGplbg==?= " . ezcMailTools::lineBreak() . "Subject: =?ISO-8859-1?B?RPh0dGUgZXIgZW4gdGVzdA==?=" . ezcMailTools::lineBreak() . "MIME-Version: 1.0" . ezcMailTools::lineBreak() . "User-Agent: eZ components"; $return = $this->mail->generate(); // cut away the Date and Message-ID headers as there is no way to predict what they will be $return = join( ezcMailTools::lineBreak(), array_slice( explode( ezcMailTools::lineBreak(), $return ), 0, 7 ) ); $this->assertEquals( $expected, $return ); } public function testSubjectWithCharsetUtf8() { $this->mail->from = new ezcMailAddress( 'from@ez.no' ); $this->mail->addTo( new ezcMailAddress( 'fh@ez.no', 'Frederik Holljen' ) ); $this->mail->subject = "Døtte er en test"; $this->mail->subjectCharset = 'ISO-8859-1'; $expected = "From: from@ez.no" . ezcMailTools::lineBreak() . "To: Frederik Holljen " . ezcMailTools::lineBreak() . "Subject: =?ISO-8859-1?B?RPh0dGUgZXIgZW4gdGVzdA==?=" . ezcMailTools::lineBreak() . "MIME-Version: 1.0" . ezcMailTools::lineBreak() . "User-Agent: eZ components"; $return = $this->mail->generate(); // cut away the Date and Message-ID headers as there is no way to predict what they will be $return = join( ezcMailTools::lineBreak(), array_slice( explode( ezcMailTools::lineBreak(), $return ), 0, 5 ) ); $this->assertEquals( $expected, $return ); } public function testHeadersWithCharsetUtf8() { $this->mail->from = new ezcMailAddress( 'fh@ez.no', 'Fræderik Hølljen', 'UTF-8' ); $this->mail->addTo( new ezcMailAddress( 'fh@ez.no', 'Fræderik Hølljen','UTF-8' ) ); $this->mail->addCc( new ezcMailAddress( 'fh@ez.no', 'Fræderik Hølljen','UTF-8' ) ); $this->mail->addBcc( new ezcMailAddress( 'fh@ez.no', 'Fræderik Hølljen','UTF-8' ) ); $this->mail->subject = "Dätte er en test"; $this->mail->subjectCharset = 'UTF-8'; $expected = "From: =?UTF-8?B?RnLDpmRlcmlrIEjDuGxsamVu?= " . ezcMailTools::lineBreak() . "To: =?UTF-8?B?RnLDpmRlcmlrIEjDuGxsamVu?= " . ezcMailTools::lineBreak() . "Cc: =?UTF-8?B?RnLDpmRlcmlrIEjDuGxsamVu?= " . ezcMailTools::lineBreak() . "Bcc: =?UTF-8?B?RnLDpmRlcmlrIEjDuGxsamVu?= " . ezcMailTools::lineBreak() . "Subject: =?UTF-8?B?RMOkdHRlIGVyIGVuIHRlc3Q=?=" . ezcMailTools::lineBreak() . "MIME-Version: 1.0" . ezcMailTools::lineBreak() . "User-Agent: eZ components"; $return = $this->mail->generate(); // cut away the Date and Message-ID headers as there is no way to predict what they will be $return = join( ezcMailTools::lineBreak(), array_slice( explode( ezcMailTools::lineBreak(), $return ), 0, 7 ) ); $this->assertEquals( $expected, $return ); } public function testFullMail() { $this->mail->from = new ezcMailAddress( 'fh@ez.no', 'Frederik Holljen' ); $this->mail->addTo( new ezcMailAddress( 'fh@ez.no', 'Frederik Holljen' ) ); $this->mail->subject = "æøå"; $this->mail->body = new ezcMailText( "Dette er body ßßæøååå" ); // echo "\n---------------\n"; // echo $this->mail->generate(); // echo "---------------\n"; // let's try to send the thing $transport = new ezcMailTransportMta(); // $transport->send( $this->mail ); } public function testFullMailMultipart() { $this->mail->from = new ezcMailAddress( 'fh@ez.no', 'Fræderik Hølljen', "iso-8859-1" ); $this->mail->addTo( new ezcMailAddress( 'fh@ez.no', 'Fræderik Hølljeñ', "iso-8859-1" ) ); $this->mail->subject = "æøå"; $this->mail->subjectCharset = 'iso-8859-1'; $this->mail->body = new ezcMailMultipartAlternative( new ezcMailText( "Dette er body ßßæøååå", "iso-8859-1" ), $html = new ezcMailText( "Hello" ) ); $html->subType = "html"; // echo "\n---------------\n"; // echo $this->mail->generate(); // echo "---------------\n"; // let's try to send the thing // $transport = new ezcMailTransportSmtp( "smtp.ez.no" ); // $transport->send( $this->mail ); } public function testFullMailDigest() { $digest = new ezcMail(); $digest->from = new ezcMailAddress( 'fh@ez.no', 'Frederik Holljen' ); $digest->addTo( new ezcMailAddress( 'fh@ez.no', 'Frederik Holljen' ) ); $digest->subject = "æøå"; $digest->body = new ezcMailText( "Dette er body ßßæøååå" ); $this->mail->from = new ezcMailAddress( 'fh@ez.no', 'Frederik Holljen' ); $this->mail->addTo( new ezcMailAddress( 'fh@ez.no', 'Frederik Holljen' ) ); $this->mail->subject = "æøå"; $this->mail->subjectCharset = 'iso-8859-1'; $this->mail->body = new ezcMailMultipartMixed( new ezcMailText( "Dette er body ßßæøååå", "iso-8859-1" ), new ezcMailRfc822Digest( $digest ) ); // $transport = new ezcMailTransportSmtp( "smtp.ez.no" ); // $transport->send( $this->mail ); } public function testFullMailDigest2() { $digest = new ezcMail(); $digest->from = new ezcMailAddress( 'fh@ez.no', 'Frederik Holljen' ); $digest->addTo( new ezcMailAddress( 'fh@ez.no', 'Frederik Holljen' ) ); $digest->subject = "æøå"; $digest->body = new ezcMailText( "Dette er body ßßæøååå" ); $this->mail->from = new ezcMailAddress( 'fh@ez.no', 'Frederik Holljen' ); $this->mail->addTo( new ezcMailAddress( 'fh@ez.no', 'Frederik Holljen' ) ); $this->mail->subject = "æøå"; $this->mail->subjectCharset = 'iso-8859-1'; $this->mail->body = new ezcMailMultipartMixed( new ezcMailText( "Dette er body ßßæøååå", "iso-8859-1" ), new ezcMailMultipartDigest( new ezcMailRfc822Digest( $digest ) ) ); // $transport = new ezcMailTransportSmtp( "smtp.ez.no" ); // $transport->send( $this->mail ); } public function testFullMailDigestArray() { $digest = new ezcMail(); $digest->from = new ezcMailAddress( 'fh@ez.no', 'Frederik Holljen' ); $digest->addTo( new ezcMailAddress( 'fh@ez.no', 'Frederik Holljen' ) ); $digest->subject = "æøå"; $digest->body = new ezcMailText( "Dette er body ßßæøååå" ); $this->mail->from = new ezcMailAddress( 'fh@ez.no', 'Frederik Holljen' ); $this->mail->addTo( new ezcMailAddress( 'fh@ez.no', 'Frederik Holljen' ) ); $this->mail->subject = "æøå"; $this->mail->subjectCharset = 'iso-8859-1'; $this->mail->body = new ezcMailMultipartMixed( new ezcMailText( "Dette er body ßßæøååå", "iso-8859-1" ), new ezcMailMultipartDigest( array( new ezcMailRfc822Digest( $digest ) ) ) ); // $transport = new ezcMailTransportSmtp( "smtp.ez.no" ); // $transport->send( $this->mail ); } public function testMessageID1() { $this->mail->from = new ezcMailAddress( 'fh@ez.no', 'Frederik Holljen' ); $this->mail->addTo( new ezcMailAddress( 'fh@ez.no', 'Frederik Holljen' ) ); $this->mail->subject = "æøå"; $this->mail->body = new ezcMailText( "Dette er body ßßæøååå" ); $this->mail->generateHeaders(); $expected = '<'. date( 'YmdGHjs' ) . '.' . getmypid() . '.5@ez.no>'; $this->assertEquals( $expected, $this->mail->getHeader( 'Message-Id' ) ); } public function testMessageID2() { $this->mail->from = new ezcMailAddress( 'fh@ez.no', 'Frederik Holljen' ); $this->mail->addTo( new ezcMailAddress( 'fh@ez.no', 'Frederik Holljen' ) ); $this->mail->subject = "æøå"; $this->mail->body = new ezcMailText( "Dette er body ßßæøååå" ); $this->mail->messageID = ""; $this->mail->generateHeaders(); $this->assertEquals( '', $this->mail->getHeader( 'Message-Id' ) ); } public function testMailAddressToString() { $addr = new ezcMailAddress( "test@example.com", "John Doe" ); $this->assertEquals( "John Doe ", $addr->__toString(), "Address not correctly serialized." ); } public function testGenerateEmpty() { $return = $this->mail->generate(); } public function testIsSet() { $mail = new ezcMail(); $mail->generateBody(); $mail->generateHeaders(); $this->assertEquals( true, isset( $mail->headers ) ); $this->assertEquals( false, isset( $mail->contentDisposition ) ); $this->assertEquals( true, isset( $mail->to ) ); $this->assertEquals( true, isset( $mail->cc ) ); $this->assertEquals( true, isset( $mail->bcc ) ); $this->assertEquals( false, isset( $mail->from ) ); $this->assertEquals( false, isset( $mail->subject ) ); $this->assertEquals( true, isset( $mail->subjectCharset ) ); $this->assertEquals( false, isset( $mail->body ) ); $this->assertEquals( false, isset( $mail->messageId ) ); $this->assertEquals( false, isset( $mail->messageID ) ); $this->assertEquals( true, isset( $mail->timestamp ) ); $this->assertEquals( false, isset( $mail->no_such_property ) ); } public static function suite() { return new PHPUnit_Framework_TestSuite( "ezcMailTest" ); } } ?>