How to use Message class

Best Gherkin-php code snippet using Message

SimpleMessageAcceptanceTest.php

Source:SimpleMessageAcceptanceTest.php Github

copy

Full Screen

1<?php2class Swift_Mime_SimpleMessageAcceptanceTest extends \PHPUnit\Framework\TestCase3{4 protected function setUp()5 {6 Swift_Preferences::getInstance()->setCharset(null); //TODO: Test with the charset defined7 }8 public function testBasicHeaders()9 {10 /* -- RFC 2822, 3.6.11 */12 $message = $this->createMessage();13 $id = $message->getId();14 $date = $message->getDate();15 $this->assertEquals(16 'Message-ID: <'.$id.'>'."\r\n".17 'Date: '.$date->format('r')."\r\n".18 'From: '."\r\n".19 'MIME-Version: 1.0'."\r\n".20 'Content-Type: text/plain'."\r\n".21 'Content-Transfer-Encoding: quoted-printable'."\r\n",22 $message->toString(),23 '%s: Only required headers, and non-empty headers should be displayed'24 );25 }26 public function testSubjectIsDisplayedIfSet()27 {28 $message = $this->createMessage();29 $message->setSubject('just a test subject');30 $id = $message->getId();31 $date = $message->getDate();32 $this->assertEquals(33 'Message-ID: <'.$id.'>'."\r\n".34 'Date: '.$date->format('r')."\r\n".35 'Subject: just a test subject'."\r\n".36 'From: '."\r\n".37 'MIME-Version: 1.0'."\r\n".38 'Content-Type: text/plain'."\r\n".39 'Content-Transfer-Encoding: quoted-printable'."\r\n",40 $message->toString()41 );42 }43 public function testDateCanBeSet()44 {45 $message = $this->createMessage();46 $message->setSubject('just a test subject');47 $id = $message->getId();48 $date = new DateTimeImmutable();49 $message->setDate($date);50 $this->assertEquals(51 'Message-ID: <'.$id.'>'."\r\n".52 'Date: '.$date->format('r')."\r\n".53 'Subject: just a test subject'."\r\n".54 'From: '."\r\n".55 'MIME-Version: 1.0'."\r\n".56 'Content-Type: text/plain'."\r\n".57 'Content-Transfer-Encoding: quoted-printable'."\r\n",58 $message->toString()59 );60 }61 public function testMessageIdCanBeSet()62 {63 $message = $this->createMessage();64 $message->setSubject('just a test subject');65 $message->setId('foo@bar');66 $date = $message->getDate();67 $this->assertEquals(68 'Message-ID: <foo@bar>'."\r\n".69 'Date: '.$date->format('r')."\r\n".70 'Subject: just a test subject'."\r\n".71 'From: '."\r\n".72 'MIME-Version: 1.0'."\r\n".73 'Content-Type: text/plain'."\r\n".74 'Content-Transfer-Encoding: quoted-printable'."\r\n",75 $message->toString()76 );77 }78 public function testContentTypeCanBeChanged()79 {80 $message = $this->createMessage();81 $message->setSubject('just a test subject');82 $message->setContentType('text/html');83 $id = $message->getId();84 $date = $message->getDate();85 $this->assertEquals(86 'Message-ID: <'.$id.'>'."\r\n".87 'Date: '.$date->format('r')."\r\n".88 'Subject: just a test subject'."\r\n".89 'From: '."\r\n".90 'MIME-Version: 1.0'."\r\n".91 'Content-Type: text/html'."\r\n".92 'Content-Transfer-Encoding: quoted-printable'."\r\n",93 $message->toString()94 );95 }96 public function testCharsetCanBeSet()97 {98 $message = $this->createMessage();99 $message->setSubject('just a test subject');100 $message->setContentType('text/html');101 $message->setCharset('iso-8859-1');102 $id = $message->getId();103 $date = $message->getDate();104 $this->assertEquals(105 'Message-ID: <'.$id.'>'."\r\n".106 'Date: '.$date->format('r')."\r\n".107 'Subject: just a test subject'."\r\n".108 'From: '."\r\n".109 'MIME-Version: 1.0'."\r\n".110 'Content-Type: text/html; charset=iso-8859-1'."\r\n".111 'Content-Transfer-Encoding: quoted-printable'."\r\n",112 $message->toString()113 );114 }115 public function testFormatCanBeSet()116 {117 $message = $this->createMessage();118 $message->setSubject('just a test subject');119 $message->setFormat('flowed');120 $id = $message->getId();121 $date = $message->getDate();122 $this->assertEquals(123 'Message-ID: <'.$id.'>'."\r\n".124 'Date: '.$date->format('r')."\r\n".125 'Subject: just a test subject'."\r\n".126 'From: '."\r\n".127 'MIME-Version: 1.0'."\r\n".128 'Content-Type: text/plain; format=flowed'."\r\n".129 'Content-Transfer-Encoding: quoted-printable'."\r\n",130 $message->toString()131 );132 }133 public function testEncoderCanBeSet()134 {135 $message = $this->createMessage();136 $message->setSubject('just a test subject');137 $message->setContentType('text/html');138 $message->setEncoder(139 new Swift_Mime_ContentEncoder_PlainContentEncoder('7bit')140 );141 $id = $message->getId();142 $date = $message->getDate();143 $this->assertEquals(144 'Message-ID: <'.$id.'>'."\r\n".145 'Date: '.$date->format('r')."\r\n".146 'Subject: just a test subject'."\r\n".147 'From: '."\r\n".148 'MIME-Version: 1.0'."\r\n".149 'Content-Type: text/html'."\r\n".150 'Content-Transfer-Encoding: 7bit'."\r\n",151 $message->toString()152 );153 }154 public function testFromAddressCanBeSet()155 {156 $message = $this->createMessage();157 $message->setSubject('just a test subject');158 $message->setFrom('chris.corbyn@swiftmailer.org');159 $id = $message->getId();160 $date = $message->getDate();161 $this->assertEquals(162 'Message-ID: <'.$id.'>'."\r\n".163 'Date: '.$date->format('r')."\r\n".164 'Subject: just a test subject'."\r\n".165 'From: chris.corbyn@swiftmailer.org'."\r\n".166 'MIME-Version: 1.0'."\r\n".167 'Content-Type: text/plain'."\r\n".168 'Content-Transfer-Encoding: quoted-printable'."\r\n",169 $message->toString()170 );171 }172 public function testFromAddressCanBeSetWithName()173 {174 $message = $this->createMessage();175 $message->setSubject('just a test subject');176 $message->setFrom(array('chris.corbyn@swiftmailer.org' => 'Chris Corbyn'));177 $id = $message->getId();178 $date = $message->getDate();179 $this->assertEquals(180 'Message-ID: <'.$id.'>'."\r\n".181 'Date: '.$date->format('r')."\r\n".182 'Subject: just a test subject'."\r\n".183 'From: Chris Corbyn <chris.corbyn@swiftmailer.org>'."\r\n".184 'MIME-Version: 1.0'."\r\n".185 'Content-Type: text/plain'."\r\n".186 'Content-Transfer-Encoding: quoted-printable'."\r\n",187 $message->toString()188 );189 }190 public function testMultipleFromAddressesCanBeSet()191 {192 $message = $this->createMessage();193 $message->setSubject('just a test subject');194 $message->setFrom(array(195 'chris.corbyn@swiftmailer.org' => 'Chris Corbyn',196 'mark@swiftmailer.org',197 ));198 $id = $message->getId();199 $date = $message->getDate();200 $this->assertEquals(201 'Message-ID: <'.$id.'>'."\r\n".202 'Date: '.$date->format('r')."\r\n".203 'Subject: just a test subject'."\r\n".204 'From: Chris Corbyn <chris.corbyn@swiftmailer.org>, mark@swiftmailer.org'."\r\n".205 'MIME-Version: 1.0'."\r\n".206 'Content-Type: text/plain'."\r\n".207 'Content-Transfer-Encoding: quoted-printable'."\r\n",208 $message->toString()209 );210 }211 public function testReturnPathAddressCanBeSet()212 {213 $message = $this->createMessage();214 $message->setReturnPath('chris@w3style.co.uk');215 $message->setSubject('just a test subject');216 $message->setFrom(array(217 'chris.corbyn@swiftmailer.org' => 'Chris Corbyn', ));218 $id = $message->getId();219 $date = $message->getDate();220 $this->assertEquals(221 'Return-Path: <chris@w3style.co.uk>'."\r\n".222 'Message-ID: <'.$id.'>'."\r\n".223 'Date: '.$date->format('r')."\r\n".224 'Subject: just a test subject'."\r\n".225 'From: Chris Corbyn <chris.corbyn@swiftmailer.org>'."\r\n".226 'MIME-Version: 1.0'."\r\n".227 'Content-Type: text/plain'."\r\n".228 'Content-Transfer-Encoding: quoted-printable'."\r\n",229 $message->toString()230 );231 }232 public function testEmptyReturnPathHeaderCanBeUsed()233 {234 $message = $this->createMessage();235 $message->setReturnPath('');236 $message->setSubject('just a test subject');237 $message->setFrom(array(238 'chris.corbyn@swiftmailer.org' => 'Chris Corbyn', ));239 $id = $message->getId();240 $date = $message->getDate();241 $this->assertEquals(242 'Return-Path: <>'."\r\n".243 'Message-ID: <'.$id.'>'."\r\n".244 'Date: '.$date->format('r')."\r\n".245 'Subject: just a test subject'."\r\n".246 'From: Chris Corbyn <chris.corbyn@swiftmailer.org>'."\r\n".247 'MIME-Version: 1.0'."\r\n".248 'Content-Type: text/plain'."\r\n".249 'Content-Transfer-Encoding: quoted-printable'."\r\n",250 $message->toString()251 );252 }253 public function testSenderCanBeSet()254 {255 $message = $this->createMessage();256 $message->setSubject('just a test subject');257 $message->setSender('chris.corbyn@swiftmailer.org');258 $id = $message->getId();259 $date = $message->getDate();260 $this->assertEquals(261 'Sender: chris.corbyn@swiftmailer.org'."\r\n".262 'Message-ID: <'.$id.'>'."\r\n".263 'Date: '.$date->format('r')."\r\n".264 'Subject: just a test subject'."\r\n".265 'From: '."\r\n".266 'MIME-Version: 1.0'."\r\n".267 'Content-Type: text/plain'."\r\n".268 'Content-Transfer-Encoding: quoted-printable'."\r\n",269 $message->toString()270 );271 }272 public function testSenderCanBeSetWithName()273 {274 $message = $this->createMessage();275 $message->setSubject('just a test subject');276 $message->setSender(array('chris.corbyn@swiftmailer.org' => 'Chris'));277 $id = $message->getId();278 $date = $message->getDate();279 $this->assertEquals(280 'Sender: Chris <chris.corbyn@swiftmailer.org>'."\r\n".281 'Message-ID: <'.$id.'>'."\r\n".282 'Date: '.$date->format('r')."\r\n".283 'Subject: just a test subject'."\r\n".284 'From: '."\r\n".285 'MIME-Version: 1.0'."\r\n".286 'Content-Type: text/plain'."\r\n".287 'Content-Transfer-Encoding: quoted-printable'."\r\n",288 $message->toString()289 );290 }291 public function testReplyToCanBeSet()292 {293 $message = $this->createMessage();294 $message->setSubject('just a test subject');295 $message->setFrom(array('chris.corbyn@swiftmailer.org' => 'Chris'));296 $message->setReplyTo(array('chris@w3style.co.uk' => 'Myself'));297 $id = $message->getId();298 $date = $message->getDate();299 $this->assertEquals(300 'Message-ID: <'.$id.'>'."\r\n".301 'Date: '.$date->format('r')."\r\n".302 'Subject: just a test subject'."\r\n".303 'From: Chris <chris.corbyn@swiftmailer.org>'."\r\n".304 'Reply-To: Myself <chris@w3style.co.uk>'."\r\n".305 'MIME-Version: 1.0'."\r\n".306 'Content-Type: text/plain'."\r\n".307 'Content-Transfer-Encoding: quoted-printable'."\r\n",308 $message->toString()309 );310 }311 public function testMultipleReplyAddressCanBeUsed()312 {313 $message = $this->createMessage();314 $message->setSubject('just a test subject');315 $message->setFrom(array('chris.corbyn@swiftmailer.org' => 'Chris'));316 $message->setReplyTo(array(317 'chris@w3style.co.uk' => 'Myself',318 'my.other@address.com' => 'Me',319 ));320 $id = $message->getId();321 $date = $message->getDate();322 $this->assertEquals(323 'Message-ID: <'.$id.'>'."\r\n".324 'Date: '.$date->format('r')."\r\n".325 'Subject: just a test subject'."\r\n".326 'From: Chris <chris.corbyn@swiftmailer.org>'."\r\n".327 'Reply-To: Myself <chris@w3style.co.uk>, Me <my.other@address.com>'."\r\n".328 'MIME-Version: 1.0'."\r\n".329 'Content-Type: text/plain'."\r\n".330 'Content-Transfer-Encoding: quoted-printable'."\r\n",331 $message->toString()332 );333 }334 public function testToAddressCanBeSet()335 {336 $message = $this->createMessage();337 $message->setSubject('just a test subject');338 $message->setFrom(array('chris.corbyn@swiftmailer.org' => 'Chris'));339 $message->setReplyTo(array(340 'chris@w3style.co.uk' => 'Myself',341 'my.other@address.com' => 'Me',342 ));343 $message->setTo('mark@swiftmailer.org');344 $id = $message->getId();345 $date = $message->getDate();346 $this->assertEquals(347 'Message-ID: <'.$id.'>'."\r\n".348 'Date: '.$date->format('r')."\r\n".349 'Subject: just a test subject'."\r\n".350 'From: Chris <chris.corbyn@swiftmailer.org>'."\r\n".351 'Reply-To: Myself <chris@w3style.co.uk>, Me <my.other@address.com>'."\r\n".352 'To: mark@swiftmailer.org'."\r\n".353 'MIME-Version: 1.0'."\r\n".354 'Content-Type: text/plain'."\r\n".355 'Content-Transfer-Encoding: quoted-printable'."\r\n",356 $message->toString()357 );358 }359 public function testMultipleToAddressesCanBeSet()360 {361 $message = $this->createMessage();362 $message->setSubject('just a test subject');363 $message->setFrom(array('chris.corbyn@swiftmailer.org' => 'Chris'));364 $message->setReplyTo(array(365 'chris@w3style.co.uk' => 'Myself',366 'my.other@address.com' => 'Me',367 ));368 $message->setTo(array(369 'mark@swiftmailer.org', 'chris@swiftmailer.org' => 'Chris Corbyn',370 ));371 $id = $message->getId();372 $date = $message->getDate();373 $this->assertEquals(374 'Message-ID: <'.$id.'>'."\r\n".375 'Date: '.$date->format('r')."\r\n".376 'Subject: just a test subject'."\r\n".377 'From: Chris <chris.corbyn@swiftmailer.org>'."\r\n".378 'Reply-To: Myself <chris@w3style.co.uk>, Me <my.other@address.com>'."\r\n".379 'To: mark@swiftmailer.org, Chris Corbyn <chris@swiftmailer.org>'."\r\n".380 'MIME-Version: 1.0'."\r\n".381 'Content-Type: text/plain'."\r\n".382 'Content-Transfer-Encoding: quoted-printable'."\r\n",383 $message->toString()384 );385 }386 public function testCcAddressCanBeSet()387 {388 $message = $this->createMessage();389 $message->setSubject('just a test subject');390 $message->setFrom(array('chris.corbyn@swiftmailer.org' => 'Chris'));391 $message->setReplyTo(array(392 'chris@w3style.co.uk' => 'Myself',393 'my.other@address.com' => 'Me',394 ));395 $message->setTo(array(396 'mark@swiftmailer.org', 'chris@swiftmailer.org' => 'Chris Corbyn',397 ));398 $message->setCc('john@some-site.com');399 $id = $message->getId();400 $date = $message->getDate();401 $this->assertEquals(402 'Message-ID: <'.$id.'>'."\r\n".403 'Date: '.$date->format('r')."\r\n".404 'Subject: just a test subject'."\r\n".405 'From: Chris <chris.corbyn@swiftmailer.org>'."\r\n".406 'Reply-To: Myself <chris@w3style.co.uk>, Me <my.other@address.com>'."\r\n".407 'To: mark@swiftmailer.org, Chris Corbyn <chris@swiftmailer.org>'."\r\n".408 'Cc: john@some-site.com'."\r\n".409 'MIME-Version: 1.0'."\r\n".410 'Content-Type: text/plain'."\r\n".411 'Content-Transfer-Encoding: quoted-printable'."\r\n",412 $message->toString()413 );414 }415 public function testMultipleCcAddressesCanBeSet()416 {417 $message = $this->createMessage();418 $message->setSubject('just a test subject');419 $message->setFrom(array('chris.corbyn@swiftmailer.org' => 'Chris'));420 $message->setReplyTo(array(421 'chris@w3style.co.uk' => 'Myself',422 'my.other@address.com' => 'Me',423 ));424 $message->setTo(array(425 'mark@swiftmailer.org', 'chris@swiftmailer.org' => 'Chris Corbyn',426 ));427 $message->setCc(array(428 'john@some-site.com' => 'John West',429 'fred@another-site.co.uk' => 'Big Fred',430 ));431 $id = $message->getId();432 $date = $message->getDate();433 $this->assertEquals(434 'Message-ID: <'.$id.'>'."\r\n".435 'Date: '.$date->format('r')."\r\n".436 'Subject: just a test subject'."\r\n".437 'From: Chris <chris.corbyn@swiftmailer.org>'."\r\n".438 'Reply-To: Myself <chris@w3style.co.uk>, Me <my.other@address.com>'."\r\n".439 'To: mark@swiftmailer.org, Chris Corbyn <chris@swiftmailer.org>'."\r\n".440 'Cc: John West <john@some-site.com>, Big Fred <fred@another-site.co.uk>'."\r\n".441 'MIME-Version: 1.0'."\r\n".442 'Content-Type: text/plain'."\r\n".443 'Content-Transfer-Encoding: quoted-printable'."\r\n",444 $message->toString()445 );446 }447 public function testBccAddressCanBeSet()448 {449 //Obviously Transports need to setBcc(array()) and send to each Bcc recipient450 // separately in accordance with RFC 2822/2821451 $message = $this->createMessage();452 $message->setSubject('just a test subject');453 $message->setFrom(array('chris.corbyn@swiftmailer.org' => 'Chris'));454 $message->setReplyTo(array(455 'chris@w3style.co.uk' => 'Myself',456 'my.other@address.com' => 'Me',457 ));458 $message->setTo(array(459 'mark@swiftmailer.org', 'chris@swiftmailer.org' => 'Chris Corbyn',460 ));461 $message->setCc(array(462 'john@some-site.com' => 'John West',463 'fred@another-site.co.uk' => 'Big Fred',464 ));465 $message->setBcc('x@alphabet.tld');466 $id = $message->getId();467 $date = $message->getDate();468 $this->assertEquals(469 'Message-ID: <'.$id.'>'."\r\n".470 'Date: '.$date->format('r')."\r\n".471 'Subject: just a test subject'."\r\n".472 'From: Chris <chris.corbyn@swiftmailer.org>'."\r\n".473 'Reply-To: Myself <chris@w3style.co.uk>, Me <my.other@address.com>'."\r\n".474 'To: mark@swiftmailer.org, Chris Corbyn <chris@swiftmailer.org>'."\r\n".475 'Cc: John West <john@some-site.com>, Big Fred <fred@another-site.co.uk>'."\r\n".476 'Bcc: x@alphabet.tld'."\r\n".477 'MIME-Version: 1.0'."\r\n".478 'Content-Type: text/plain'."\r\n".479 'Content-Transfer-Encoding: quoted-printable'."\r\n",480 $message->toString()481 );482 }483 public function testMultipleBccAddressesCanBeSet()484 {485 //Obviously Transports need to setBcc(array()) and send to each Bcc recipient486 // separately in accordance with RFC 2822/2821487 $message = $this->createMessage();488 $message->setSubject('just a test subject');489 $message->setFrom(array('chris.corbyn@swiftmailer.org' => 'Chris'));490 $message->setReplyTo(array(491 'chris@w3style.co.uk' => 'Myself',492 'my.other@address.com' => 'Me',493 ));494 $message->setTo(array(495 'mark@swiftmailer.org', 'chris@swiftmailer.org' => 'Chris Corbyn',496 ));497 $message->setCc(array(498 'john@some-site.com' => 'John West',499 'fred@another-site.co.uk' => 'Big Fred',500 ));501 $message->setBcc(array('x@alphabet.tld', 'a@alphabet.tld' => 'A'));502 $id = $message->getId();503 $date = $message->getDate();504 $this->assertEquals(505 'Message-ID: <'.$id.'>'."\r\n".506 'Date: '.$date->format('r')."\r\n".507 'Subject: just a test subject'."\r\n".508 'From: Chris <chris.corbyn@swiftmailer.org>'."\r\n".509 'Reply-To: Myself <chris@w3style.co.uk>, Me <my.other@address.com>'."\r\n".510 'To: mark@swiftmailer.org, Chris Corbyn <chris@swiftmailer.org>'."\r\n".511 'Cc: John West <john@some-site.com>, Big Fred <fred@another-site.co.uk>'."\r\n".512 'Bcc: x@alphabet.tld, A <a@alphabet.tld>'."\r\n".513 'MIME-Version: 1.0'."\r\n".514 'Content-Type: text/plain'."\r\n".515 'Content-Transfer-Encoding: quoted-printable'."\r\n",516 $message->toString()517 );518 }519 public function testStringBodyIsAppended()520 {521 $message = $this->createMessage();522 $message->setReturnPath('chris@w3style.co.uk');523 $message->setSubject('just a test subject');524 $message->setFrom(array(525 'chris.corbyn@swiftmailer.org' => 'Chris Corbyn', ));526 $message->setBody(527 'just a test body'."\r\n".528 'with a new line'529 );530 $id = $message->getId();531 $date = $message->getDate();532 $this->assertEquals(533 'Return-Path: <chris@w3style.co.uk>'."\r\n".534 'Message-ID: <'.$id.'>'."\r\n".535 'Date: '.$date->format('r')."\r\n".536 'Subject: just a test subject'."\r\n".537 'From: Chris Corbyn <chris.corbyn@swiftmailer.org>'."\r\n".538 'MIME-Version: 1.0'."\r\n".539 'Content-Type: text/plain'."\r\n".540 'Content-Transfer-Encoding: quoted-printable'."\r\n".541 "\r\n".542 'just a test body'."\r\n".543 'with a new line',544 $message->toString()545 );546 }547 public function testStringBodyIsEncoded()548 {549 $message = $this->createMessage();550 $message->setReturnPath('chris@w3style.co.uk');551 $message->setSubject('just a test subject');552 $message->setFrom(array(553 'chris.corbyn@swiftmailer.org' => 'Chris Corbyn', ));554 $message->setBody(555 'Just s'.pack('C*', 0xC2, 0x01, 0x01).'me multi-'."\r\n".556 'line message!'557 );558 $id = $message->getId();559 $date = $message->getDate();560 $this->assertEquals(561 'Return-Path: <chris@w3style.co.uk>'."\r\n".562 'Message-ID: <'.$id.'>'."\r\n".563 'Date: '.$date->format('r')."\r\n".564 'Subject: just a test subject'."\r\n".565 'From: Chris Corbyn <chris.corbyn@swiftmailer.org>'."\r\n".566 'MIME-Version: 1.0'."\r\n".567 'Content-Type: text/plain'."\r\n".568 'Content-Transfer-Encoding: quoted-printable'."\r\n".569 "\r\n".570 'Just s=C2=01=01me multi-'."\r\n".571 'line message!',572 $message->toString()573 );574 }575 public function testChildrenCanBeAttached()576 {577 $message = $this->createMessage();578 $message->setReturnPath('chris@w3style.co.uk');579 $message->setSubject('just a test subject');580 $message->setFrom(array(581 'chris.corbyn@swiftmailer.org' => 'Chris Corbyn', ));582 $id = $message->getId();583 $date = $message->getDate();584 $boundary = $message->getBoundary();585 $part1 = $this->createMimePart();586 $part1->setContentType('text/plain');587 $part1->setCharset('iso-8859-1');588 $part1->setBody('foo');589 $message->attach($part1);590 $part2 = $this->createMimePart();591 $part2->setContentType('text/html');592 $part2->setCharset('iso-8859-1');593 $part2->setBody('test <b>foo</b>');594 $message->attach($part2);595 $this->assertEquals(596 'Return-Path: <chris@w3style.co.uk>'."\r\n".597 'Message-ID: <'.$id.'>'."\r\n".598 'Date: '.$date->format('r')."\r\n".599 'Subject: just a test subject'."\r\n".600 'From: Chris Corbyn <chris.corbyn@swiftmailer.org>'."\r\n".601 'MIME-Version: 1.0'."\r\n".602 'Content-Type: multipart/alternative;'."\r\n".603 ' boundary="'.$boundary.'"'."\r\n".604 "\r\n\r\n".605 '--'.$boundary."\r\n".606 'Content-Type: text/plain; charset=iso-8859-1'."\r\n".607 'Content-Transfer-Encoding: quoted-printable'."\r\n".608 "\r\n".609 'foo'.610 "\r\n\r\n".611 '--'.$boundary."\r\n".612 'Content-Type: text/html; charset=iso-8859-1'."\r\n".613 'Content-Transfer-Encoding: quoted-printable'."\r\n".614 "\r\n".615 'test <b>foo</b>'.616 "\r\n\r\n".617 '--'.$boundary.'--'."\r\n",618 $message->toString()619 );620 }621 public function testAttachmentsBeingAttached()622 {623 $message = $this->createMessage();624 $message->setReturnPath('chris@w3style.co.uk');625 $message->setSubject('just a test subject');626 $message->setFrom(array(627 'chris.corbyn@swiftmailer.org' => 'Chris Corbyn', ));628 $id = $message->getId();629 $date = preg_quote($message->getDate()->format('r'), '~');630 $boundary = $message->getBoundary();631 $part = $this->createMimePart();632 $part->setContentType('text/plain');633 $part->setCharset('iso-8859-1');634 $part->setBody('foo');635 $message->attach($part);636 $attachment = $this->createAttachment();637 $attachment->setContentType('application/pdf');638 $attachment->setFilename('foo.pdf');639 $attachment->setBody('<pdf data>');640 $message->attach($attachment);641 $this->assertRegExp(642 '~^'.643 'Return-Path: <chris@w3style.co.uk>'."\r\n".644 'Message-ID: <'.$id.'>'."\r\n".645 'Date: '.$date."\r\n".646 'Subject: just a test subject'."\r\n".647 'From: Chris Corbyn <chris.corbyn@swiftmailer.org>'."\r\n".648 'MIME-Version: 1.0'."\r\n".649 'Content-Type: multipart/mixed;'."\r\n".650 ' boundary="'.$boundary.'"'."\r\n".651 "\r\n\r\n".652 '--'.$boundary."\r\n".653 'Content-Type: multipart/alternative;'."\r\n".654 ' boundary="(.*?)"'."\r\n".655 "\r\n\r\n".656 '--\\1'."\r\n".657 'Content-Type: text/plain; charset=iso-8859-1'."\r\n".658 'Content-Transfer-Encoding: quoted-printable'."\r\n".659 "\r\n".660 'foo'.661 "\r\n\r\n".662 '--\\1--'."\r\n".663 "\r\n\r\n".664 '--'.$boundary."\r\n".665 'Content-Type: application/pdf; name=foo.pdf'."\r\n".666 'Content-Transfer-Encoding: base64'."\r\n".667 'Content-Disposition: attachment; filename=foo.pdf'."\r\n".668 "\r\n".669 preg_quote(base64_encode('<pdf data>'), '~').670 "\r\n\r\n".671 '--'.$boundary.'--'."\r\n".672 '$~D',673 $message->toString()674 );675 }676 public function testAttachmentsAndEmbeddedFilesBeingAttached()677 {678 $message = $this->createMessage();679 $message->setReturnPath('chris@w3style.co.uk');680 $message->setSubject('just a test subject');681 $message->setFrom(array(682 'chris.corbyn@swiftmailer.org' => 'Chris Corbyn', ));683 $id = $message->getId();684 $date = preg_quote($message->getDate()->format('r'), '~');685 $boundary = $message->getBoundary();686 $part = $this->createMimePart();687 $part->setContentType('text/plain');688 $part->setCharset('iso-8859-1');689 $part->setBody('foo');690 $message->attach($part);691 $attachment = $this->createAttachment();692 $attachment->setContentType('application/pdf');693 $attachment->setFilename('foo.pdf');694 $attachment->setBody('<pdf data>');695 $message->attach($attachment);696 $file = $this->createEmbeddedFile();697 $file->setContentType('image/jpeg');698 $file->setFilename('myimage.jpg');699 $file->setBody('<image data>');700 $message->attach($file);701 $cid = $file->getId();702 $this->assertRegExp(703 '~^'.704 'Return-Path: <chris@w3style.co.uk>'."\r\n".705 'Message-ID: <'.$id.'>'."\r\n".706 'Date: '.$date."\r\n".707 'Subject: just a test subject'."\r\n".708 'From: Chris Corbyn <chris.corbyn@swiftmailer.org>'."\r\n".709 'MIME-Version: 1.0'."\r\n".710 'Content-Type: multipart/mixed;'."\r\n".711 ' boundary="'.$boundary.'"'."\r\n".712 "\r\n\r\n".713 '--'.$boundary."\r\n".714 'Content-Type: multipart/alternative;'."\r\n".715 ' boundary="(.*?)"'."\r\n".716 "\r\n\r\n".717 '--\\1'."\r\n".718 'Content-Type: text/plain; charset=iso-8859-1'."\r\n".719 'Content-Transfer-Encoding: quoted-printable'."\r\n".720 "\r\n".721 'foo'.722 "\r\n\r\n".723 '--\\1'."\r\n".724 'Content-Type: multipart/related;'."\r\n".725 ' boundary="(.*?)"'."\r\n".726 "\r\n\r\n".727 '--\\2'."\r\n".728 'Content-Type: image/jpeg; name=myimage.jpg'."\r\n".729 'Content-Transfer-Encoding: base64'."\r\n".730 'Content-ID: <'.$cid.'>'."\r\n".731 'Content-Disposition: inline; filename=myimage.jpg'."\r\n".732 "\r\n".733 preg_quote(base64_encode('<image data>'), '~').734 "\r\n\r\n".735 '--\\2--'."\r\n".736 "\r\n\r\n".737 '--\\1--'."\r\n".738 "\r\n\r\n".739 '--'.$boundary."\r\n".740 'Content-Type: application/pdf; name=foo.pdf'."\r\n".741 'Content-Transfer-Encoding: base64'."\r\n".742 'Content-Disposition: attachment; filename=foo.pdf'."\r\n".743 "\r\n".744 preg_quote(base64_encode('<pdf data>'), '~').745 "\r\n\r\n".746 '--'.$boundary.'--'."\r\n".747 '$~D',748 $message->toString()749 );750 }751 public function testComplexEmbeddingOfContent()752 {753 $message = $this->createMessage();754 $message->setReturnPath('chris@w3style.co.uk');755 $message->setSubject('just a test subject');756 $message->setFrom(array(757 'chris.corbyn@swiftmailer.org' => 'Chris Corbyn', ));758 $id = $message->getId();759 $date = preg_quote($message->getDate()->format('r'), '~');760 $boundary = $message->getBoundary();761 $attachment = $this->createAttachment();762 $attachment->setContentType('application/pdf');763 $attachment->setFilename('foo.pdf');764 $attachment->setBody('<pdf data>');765 $message->attach($attachment);766 $file = $this->createEmbeddedFile();767 $file->setContentType('image/jpeg');768 $file->setFilename('myimage.jpg');769 $file->setBody('<image data>');770 $part = $this->createMimePart();771 $part->setContentType('text/html');772 $part->setCharset('iso-8859-1');773 $part->setBody('foo <img src="'.$message->embed($file).'" />');774 $message->attach($part);775 $cid = $file->getId();776 $this->assertRegExp(777 '~^'.778 'Return-Path: <chris@w3style.co.uk>'."\r\n".779 'Message-ID: <'.$id.'>'."\r\n".780 'Date: '.$date."\r\n".781 'Subject: just a test subject'."\r\n".782 'From: Chris Corbyn <chris.corbyn@swiftmailer.org>'."\r\n".783 'MIME-Version: 1.0'."\r\n".784 'Content-Type: multipart/mixed;'."\r\n".785 ' boundary="'.$boundary.'"'."\r\n".786 "\r\n\r\n".787 '--'.$boundary."\r\n".788 'Content-Type: multipart/related;'."\r\n".789 ' boundary="(.*?)"'."\r\n".790 "\r\n\r\n".791 '--\\1'."\r\n".792 'Content-Type: text/html; charset=iso-8859-1'."\r\n".793 'Content-Transfer-Encoding: quoted-printable'."\r\n".794 "\r\n".795 'foo <img src=3D"cid:'.$cid.'" />'.//=3D is just = in QP796 "\r\n\r\n".797 '--\\1'."\r\n".798 'Content-Type: image/jpeg; name=myimage.jpg'."\r\n".799 'Content-Transfer-Encoding: base64'."\r\n".800 'Content-ID: <'.$cid.'>'."\r\n".801 'Content-Disposition: inline; filename=myimage.jpg'."\r\n".802 "\r\n".803 preg_quote(base64_encode('<image data>'), '~').804 "\r\n\r\n".805 '--\\1--'."\r\n".806 "\r\n\r\n".807 '--'.$boundary."\r\n".808 'Content-Type: application/pdf; name=foo.pdf'."\r\n".809 'Content-Transfer-Encoding: base64'."\r\n".810 'Content-Disposition: attachment; filename=foo.pdf'."\r\n".811 "\r\n".812 preg_quote(base64_encode('<pdf data>'), '~').813 "\r\n\r\n".814 '--'.$boundary.'--'."\r\n".815 '$~D',816 $message->toString()817 );818 }819 public function testAttachingAndDetachingContent()820 {821 $message = $this->createMessage();822 $message->setReturnPath('chris@w3style.co.uk');823 $message->setSubject('just a test subject');824 $message->setFrom(array(825 'chris.corbyn@swiftmailer.org' => 'Chris Corbyn', ));826 $id = $message->getId();827 $date = preg_quote($message->getDate()->format('r'), '~');828 $boundary = $message->getBoundary();829 $part = $this->createMimePart();830 $part->setContentType('text/plain');831 $part->setCharset('iso-8859-1');832 $part->setBody('foo');833 $message->attach($part);834 $attachment = $this->createAttachment();835 $attachment->setContentType('application/pdf');836 $attachment->setFilename('foo.pdf');837 $attachment->setBody('<pdf data>');838 $message->attach($attachment);839 $file = $this->createEmbeddedFile();840 $file->setContentType('image/jpeg');841 $file->setFilename('myimage.jpg');842 $file->setBody('<image data>');843 $message->attach($file);844 $cid = $file->getId();845 $message->detach($attachment);846 $this->assertRegExp(847 '~^'.848 'Return-Path: <chris@w3style.co.uk>'."\r\n".849 'Message-ID: <'.$id.'>'."\r\n".850 'Date: '.$date."\r\n".851 'Subject: just a test subject'."\r\n".852 'From: Chris Corbyn <chris.corbyn@swiftmailer.org>'."\r\n".853 'MIME-Version: 1.0'."\r\n".854 'Content-Type: multipart/alternative;'."\r\n".855 ' boundary="'.$boundary.'"'."\r\n".856 "\r\n\r\n".857 '--'.$boundary."\r\n".858 'Content-Type: text/plain; charset=iso-8859-1'."\r\n".859 'Content-Transfer-Encoding: quoted-printable'."\r\n".860 "\r\n".861 'foo'.862 "\r\n\r\n".863 '--'.$boundary."\r\n".864 'Content-Type: multipart/related;'."\r\n".865 ' boundary="(.*?)"'."\r\n".866 "\r\n\r\n".867 '--\\1'."\r\n".868 'Content-Type: image/jpeg; name=myimage.jpg'."\r\n".869 'Content-Transfer-Encoding: base64'."\r\n".870 'Content-ID: <'.$cid.'>'."\r\n".871 'Content-Disposition: inline; filename=myimage.jpg'."\r\n".872 "\r\n".873 preg_quote(base64_encode('<image data>'), '~').874 "\r\n\r\n".875 '--\\1--'."\r\n".876 "\r\n\r\n".877 '--'.$boundary.'--'."\r\n".878 '$~D',879 $message->toString(),880 '%s: Attachment should have been detached'881 );882 }883 public function testBoundaryDoesNotAppearAfterAllPartsAreDetached()884 {885 $message = $this->createMessage();886 $message->setReturnPath('chris@w3style.co.uk');887 $message->setSubject('just a test subject');888 $message->setFrom(array(889 'chris.corbyn@swiftmailer.org' => 'Chris Corbyn', ));890 $id = $message->getId();891 $date = $message->getDate();892 $boundary = $message->getBoundary();893 $part1 = $this->createMimePart();894 $part1->setContentType('text/plain');895 $part1->setCharset('iso-8859-1');896 $part1->setBody('foo');897 $message->attach($part1);898 $part2 = $this->createMimePart();899 $part2->setContentType('text/html');900 $part2->setCharset('iso-8859-1');901 $part2->setBody('test <b>foo</b>');902 $message->attach($part2);903 $message->detach($part1);904 $message->detach($part2);905 $this->assertEquals(906 'Return-Path: <chris@w3style.co.uk>'."\r\n".907 'Message-ID: <'.$id.'>'."\r\n".908 'Date: '.$date->format('r')."\r\n".909 'Subject: just a test subject'."\r\n".910 'From: Chris Corbyn <chris.corbyn@swiftmailer.org>'."\r\n".911 'MIME-Version: 1.0'."\r\n".912 'Content-Type: text/plain'."\r\n".913 'Content-Transfer-Encoding: quoted-printable'."\r\n",914 $message->toString(),915 '%s: Message should be restored to orignal state after parts are detached'916 );917 }918 public function testCharsetFormatOrDelSpAreNotShownWhenBoundaryIsSet()919 {920 $message = $this->createMessage();921 $message->setReturnPath('chris@w3style.co.uk');922 $message->setSubject('just a test subject');923 $message->setFrom(array(924 'chris.corbyn@swiftmailer.org' => 'Chris Corbyn', ));925 $message->setCharset('utf-8');926 $message->setFormat('flowed');927 $message->setDelSp(true);928 $id = $message->getId();929 $date = $message->getDate();930 $boundary = $message->getBoundary();931 $part1 = $this->createMimePart();932 $part1->setContentType('text/plain');933 $part1->setCharset('iso-8859-1');934 $part1->setBody('foo');935 $message->attach($part1);936 $part2 = $this->createMimePart();937 $part2->setContentType('text/html');938 $part2->setCharset('iso-8859-1');939 $part2->setBody('test <b>foo</b>');940 $message->attach($part2);941 $this->assertEquals(942 'Return-Path: <chris@w3style.co.uk>'."\r\n".943 'Message-ID: <'.$id.'>'."\r\n".944 'Date: '.$date->format('r')."\r\n".945 'Subject: just a test subject'."\r\n".946 'From: Chris Corbyn <chris.corbyn@swiftmailer.org>'."\r\n".947 'MIME-Version: 1.0'."\r\n".948 'Content-Type: multipart/alternative;'."\r\n".949 ' boundary="'.$boundary.'"'."\r\n".950 "\r\n\r\n".951 '--'.$boundary."\r\n".952 'Content-Type: text/plain; charset=iso-8859-1'."\r\n".953 'Content-Transfer-Encoding: quoted-printable'."\r\n".954 "\r\n".955 'foo'.956 "\r\n\r\n".957 '--'.$boundary."\r\n".958 'Content-Type: text/html; charset=iso-8859-1'."\r\n".959 'Content-Transfer-Encoding: quoted-printable'."\r\n".960 "\r\n".961 'test <b>foo</b>'.962 "\r\n\r\n".963 '--'.$boundary.'--'."\r\n",964 $message->toString()965 );966 }967 public function testBodyCanBeSetWithAttachments()968 {969 $message = $this->createMessage();970 $message->setReturnPath('chris@w3style.co.uk');971 $message->setSubject('just a test subject');972 $message->setFrom(array(973 'chris.corbyn@swiftmailer.org' => 'Chris Corbyn', ));974 $message->setContentType('text/html');975 $message->setCharset('iso-8859-1');976 $message->setBody('foo');977 $id = $message->getId();978 $date = $message->getDate()->format('r');979 $boundary = $message->getBoundary();980 $attachment = $this->createAttachment();981 $attachment->setContentType('application/pdf');982 $attachment->setFilename('foo.pdf');983 $attachment->setBody('<pdf data>');984 $message->attach($attachment);985 $this->assertEquals(986 'Return-Path: <chris@w3style.co.uk>'."\r\n".987 'Message-ID: <'.$id.'>'."\r\n".988 'Date: '.$date."\r\n".989 'Subject: just a test subject'."\r\n".990 'From: Chris Corbyn <chris.corbyn@swiftmailer.org>'."\r\n".991 'MIME-Version: 1.0'."\r\n".992 'Content-Type: multipart/mixed;'."\r\n".993 ' boundary="'.$boundary.'"'."\r\n".994 "\r\n\r\n".995 '--'.$boundary."\r\n".996 'Content-Type: text/html; charset=iso-8859-1'."\r\n".997 'Content-Transfer-Encoding: quoted-printable'."\r\n".998 "\r\n".999 'foo'.1000 "\r\n\r\n".1001 '--'.$boundary."\r\n".1002 'Content-Type: application/pdf; name=foo.pdf'."\r\n".1003 'Content-Transfer-Encoding: base64'."\r\n".1004 'Content-Disposition: attachment; filename=foo.pdf'."\r\n".1005 "\r\n".1006 base64_encode('<pdf data>').1007 "\r\n\r\n".1008 '--'.$boundary.'--'."\r\n",1009 $message->toString()1010 );1011 }1012 public function testHtmlPartAlwaysAppearsLast()1013 {1014 $message = $this->createMessage();1015 $message->setReturnPath('chris@w3style.co.uk');1016 $message->setSubject('just a test subject');1017 $message->setFrom(array(1018 'chris.corbyn@swiftmailer.org' => 'Chris Corbyn', ));1019 $id = $message->getId();1020 $date = $message->getDate()->format('r');1021 $boundary = $message->getBoundary();1022 $part1 = $this->createMimePart();1023 $part1->setContentType('text/html');1024 $part1->setBody('foo');1025 $part2 = $this->createMimePart();1026 $part2->setContentType('text/plain');1027 $part2->setBody('bar');1028 $message->attach($part1);1029 $message->attach($part2);1030 $this->assertEquals(1031 'Return-Path: <chris@w3style.co.uk>'."\r\n".1032 'Message-ID: <'.$id.'>'."\r\n".1033 'Date: '.$date."\r\n".1034 'Subject: just a test subject'."\r\n".1035 'From: Chris Corbyn <chris.corbyn@swiftmailer.org>'."\r\n".1036 'MIME-Version: 1.0'."\r\n".1037 'Content-Type: multipart/alternative;'."\r\n".1038 ' boundary="'.$boundary.'"'."\r\n".1039 "\r\n\r\n".1040 '--'.$boundary."\r\n".1041 'Content-Type: text/plain'."\r\n".1042 'Content-Transfer-Encoding: quoted-printable'."\r\n".1043 "\r\n".1044 'bar'.1045 "\r\n\r\n".1046 '--'.$boundary."\r\n".1047 'Content-Type: text/html'."\r\n".1048 'Content-Transfer-Encoding: quoted-printable'."\r\n".1049 "\r\n".1050 'foo'.1051 "\r\n\r\n".1052 '--'.$boundary.'--'."\r\n",1053 $message->toString()1054 );1055 }1056 public function testBodyBecomesPartIfOtherPartsAttached()1057 {1058 $message = $this->createMessage();1059 $message->setReturnPath('chris@w3style.co.uk');1060 $message->setSubject('just a test subject');1061 $message->setFrom(array(1062 'chris.corbyn@swiftmailer.org' => 'Chris Corbyn', ));1063 $message->setContentType('text/html');1064 $message->setBody('foo');1065 $id = $message->getId();1066 $date = $message->getDate()->format('r');1067 $boundary = $message->getBoundary();1068 $part2 = $this->createMimePart();1069 $part2->setContentType('text/plain');1070 $part2->setBody('bar');1071 $message->attach($part2);1072 $this->assertEquals(1073 'Return-Path: <chris@w3style.co.uk>'."\r\n".1074 'Message-ID: <'.$id.'>'."\r\n".1075 'Date: '.$date."\r\n".1076 'Subject: just a test subject'."\r\n".1077 'From: Chris Corbyn <chris.corbyn@swiftmailer.org>'."\r\n".1078 'MIME-Version: 1.0'."\r\n".1079 'Content-Type: multipart/alternative;'."\r\n".1080 ' boundary="'.$boundary.'"'."\r\n".1081 "\r\n\r\n".1082 '--'.$boundary."\r\n".1083 'Content-Type: text/plain'."\r\n".1084 'Content-Transfer-Encoding: quoted-printable'."\r\n".1085 "\r\n".1086 'bar'.1087 "\r\n\r\n".1088 '--'.$boundary."\r\n".1089 'Content-Type: text/html'."\r\n".1090 'Content-Transfer-Encoding: quoted-printable'."\r\n".1091 "\r\n".1092 'foo'.1093 "\r\n\r\n".1094 '--'.$boundary.'--'."\r\n",1095 $message->toString()1096 );1097 }1098 public function testBodyIsCanonicalized()1099 {1100 $message = $this->createMessage();1101 $message->setReturnPath('chris@w3style.co.uk');1102 $message->setSubject('just a test subject');1103 $message->setFrom(array(1104 'chris.corbyn@swiftmailer.org' => 'Chris Corbyn', ));1105 $message->setBody(1106 'just a test body'."\n".1107 'with a new line'1108 );1109 $id = $message->getId();1110 $date = $message->getDate();1111 $this->assertEquals(1112 'Return-Path: <chris@w3style.co.uk>'."\r\n".1113 'Message-ID: <'.$id.'>'."\r\n".1114 'Date: '.$date->format('r')."\r\n".1115 'Subject: just a test subject'."\r\n".1116 'From: Chris Corbyn <chris.corbyn@swiftmailer.org>'."\r\n".1117 'MIME-Version: 1.0'."\r\n".1118 'Content-Type: text/plain'."\r\n".1119 'Content-Transfer-Encoding: quoted-printable'."\r\n".1120 "\r\n".1121 'just a test body'."\r\n".1122 'with a new line',1123 $message->toString()1124 );1125 }1126 protected function createMessage()1127 {1128 return new Swift_Message();1129 }1130 protected function createMimePart()1131 {1132 return new Swift_MimePart();1133 }1134 protected function createAttachment()1135 {1136 return new Swift_Attachment();1137 }1138 protected function createEmbeddedFile()1139 {1140 return new Swift_EmbeddedFile();1141 }1142}...

Full Screen

Full Screen

messagelib_test.php

Source:messagelib_test.php Github

copy

Full Screen

...166 $message->fullmessageformat = FORMAT_MARKDOWN;167 $message->fullmessagehtml = '<p>message body</p>';168 $message->smallmessage = 'small message';169 $message->notification = '0';170 $sink = $this->redirectMessages();171 $this->setCurrentTimeStart();172 $messageid = message_send($message);173 $savedmessages = $sink->get_messages();174 $this->assertCount(1, $savedmessages);175 $savedmessage = reset($savedmessages);176 $this->assertEquals($messageid, $savedmessage->id);177 $this->assertEquals($user1->id, $savedmessage->useridfrom);178 $this->assertEquals($user2->id, $savedmessage->useridto);179 $this->assertEquals($message->fullmessage, $savedmessage->fullmessage);180 $this->assertEquals($message->fullmessageformat, $savedmessage->fullmessageformat);181 $this->assertEquals($message->fullmessagehtml, $savedmessage->fullmessagehtml);182 $this->assertEquals($message->smallmessage, $savedmessage->smallmessage);183 $this->assertEquals($message->smallmessage, $savedmessage->smallmessage);184 $this->assertEquals($message->notification, $savedmessage->notification);185 $this->assertNull($savedmessage->contexturl);186 $this->assertNull($savedmessage->contexturlname);187 $this->assertTimeCurrent($savedmessage->timecreated);188 $record = $DB->get_record('message_read', array('id' => $savedmessage->id), '*', MUST_EXIST);189 $this->assertEquals($record, $savedmessage);190 $sink->clear();191 $this->assertFalse($DB->record_exists('message', array()));192 $DB->delete_records('message_read', array());193 $message = new \core\message\message();194 $message->courseid = 1;195 $message->component = 'moodle';196 $message->name = 'instantmessage';197 $message->userfrom = $user1->id;198 $message->userto = $user2->id;199 $message->subject = 'message subject 1';200 $message->fullmessage = 'message body';201 $message->fullmessageformat = FORMAT_MARKDOWN;202 $message->fullmessagehtml = '<p>message body</p>';203 $message->smallmessage = 'small message';204 $message->notification = '0';205 $message->contexturl = new moodle_url('/');206 $message->contexturlname = 'front';207 $sink = $this->redirectMessages();208 $messageid = message_send($message);209 $savedmessages = $sink->get_messages();210 $this->assertCount(1, $savedmessages);211 $savedmessage = reset($savedmessages);212 $this->assertEquals($messageid, $savedmessage->id);213 $this->assertEquals($user1->id, $savedmessage->useridfrom);214 $this->assertEquals($user2->id, $savedmessage->useridto);215 $this->assertEquals($message->fullmessage, $savedmessage->fullmessage);216 $this->assertEquals($message->fullmessageformat, $savedmessage->fullmessageformat);217 $this->assertEquals($message->fullmessagehtml, $savedmessage->fullmessagehtml);218 $this->assertEquals($message->smallmessage, $savedmessage->smallmessage);219 $this->assertEquals($message->smallmessage, $savedmessage->smallmessage);220 $this->assertEquals($message->notification, $savedmessage->notification);221 $this->assertEquals($message->contexturl->out(), $savedmessage->contexturl);222 $this->assertEquals($message->contexturlname, $savedmessage->contexturlname);223 $this->assertTimeCurrent($savedmessage->timecreated);224 $record = $DB->get_record('message_read', array('id' => $savedmessage->id), '*', MUST_EXIST);225 $this->assertEquals($record, $savedmessage);226 $sink->clear();227 $this->assertFalse($DB->record_exists('message', array()));228 $DB->delete_records('message_read', array());229 // Test phpunit problem detection.230 $message = new \core\message\message();231 $message->courseid = 1;232 $message->component = 'xxxxx';233 $message->name = 'instantmessage';234 $message->userfrom = $user1;235 $message->userto = $user2;236 $message->subject = 'message subject 1';237 $message->fullmessage = 'message body';238 $message->fullmessageformat = FORMAT_MARKDOWN;239 $message->fullmessagehtml = '<p>message body</p>';240 $message->smallmessage = 'small message';241 $message->notification = '0';242 $sink = $this->redirectMessages();243 try {244 message_send($message);245 } catch (moodle_exception $e) {246 $this->assertInstanceOf('coding_exception', $e);247 }248 $this->assertCount(0, $sink->get_messages());249 $message->component = 'moodle';250 $message->name = 'xxx';251 $sink = $this->redirectMessages();252 try {253 message_send($message);254 } catch (moodle_exception $e) {255 $this->assertInstanceOf('coding_exception', $e);256 }257 $this->assertCount(0, $sink->get_messages());258 $sink->close();259 $this->assertFalse($DB->record_exists('message', array()));260 $this->assertFalse($DB->record_exists('message_read', array()));261 // Invalid users.262 $message = new \core\message\message();263 $message->courseid = 1;264 $message->component = 'moodle';265 $message->name = 'instantmessage';266 $message->userfrom = $user1;267 $message->userto = -1;268 $message->subject = 'message subject 1';269 $message->fullmessage = 'message body';270 $message->fullmessageformat = FORMAT_MARKDOWN;271 $message->fullmessagehtml = '<p>message body</p>';272 $message->smallmessage = 'small message';273 $message->notification = '0';274 $messageid = message_send($message);275 $this->assertFalse($messageid);276 $this->assertDebuggingCalled('Attempt to send msg to unknown user');277 $message = new \core\message\message();278 $message->courseid = 1;279 $message->component = 'moodle';280 $message->name = 'instantmessage';281 $message->userfrom = -1;282 $message->userto = $user2;283 $message->subject = 'message subject 1';284 $message->fullmessage = 'message body';285 $message->fullmessageformat = FORMAT_MARKDOWN;286 $message->fullmessagehtml = '<p>message body</p>';287 $message->smallmessage = 'small message';288 $message->notification = '0';289 $messageid = message_send($message);290 $this->assertFalse($messageid);291 $this->assertDebuggingCalled('Attempt to send msg from unknown user');292 $message = new \core\message\message();293 $message->courseid = 1;294 $message->component = 'moodle';295 $message->name = 'instantmessage';296 $message->userfrom = $user1;297 $message->userto = core_user::NOREPLY_USER;298 $message->subject = 'message subject 1';299 $message->fullmessage = 'message body';300 $message->fullmessageformat = FORMAT_MARKDOWN;301 $message->fullmessagehtml = '<p>message body</p>';302 $message->smallmessage = 'small message';303 $message->notification = '0';304 $messageid = message_send($message);305 $this->assertFalse($messageid);306 $this->assertDebuggingCalled('Attempt to send msg to internal (noreply) user');307 // Some debugging hints for devs.308 unset($user2->emailstop);309 $message = new \core\message\message();310 $message->courseid = 1;311 $message->component = 'moodle';312 $message->name = 'instantmessage';313 $message->userfrom = $user1;314 $message->userto = $user2;315 $message->subject = 'message subject 1';316 $message->fullmessage = 'message body';317 $message->fullmessageformat = FORMAT_MARKDOWN;318 $message->fullmessagehtml = '<p>message body</p>';319 $message->smallmessage = 'small message';320 $message->notification = '0';321 $sink = $this->redirectMessages();322 $messageid = message_send($message);323 $savedmessages = $sink->get_messages();324 $this->assertCount(1, $savedmessages);325 $savedmessage = reset($savedmessages);326 $this->assertEquals($messageid, $savedmessage->id);327 $this->assertEquals($user1->id, $savedmessage->useridfrom);328 $this->assertEquals($user2->id, $savedmessage->useridto);329 $this->assertDebuggingCalled('Necessary properties missing in userto object, fetching full record');330 $sink->clear();331 $user2->emailstop = '0';332 }333 public function test_send_message() {334 global $DB, $CFG;335 $this->preventResetByRollback();336 $this->resetAfterTest();337 $user1 = $this->getDataGenerator()->create_user(array('maildisplay' => 1));338 $user2 = $this->getDataGenerator()->create_user();339 set_config('allowedemaildomains', 'example.com');340 // Test basic email redirection.341 $this->assertFileExists("$CFG->dirroot/message/output/email/version.php");342 $this->assertFileExists("$CFG->dirroot/message/output/popup/version.php");343 $DB->set_field_select('message_processors', 'enabled', 0, "name <> 'email' AND name <> 'popup'");344 get_message_processors(true, true);345 $eventsink = $this->redirectEvents();346 // Will always use the pop-up processor.347 set_user_preference('message_provider_moodle_instantmessage_loggedoff', 'none', $user2);348 $message = new \core\message\message();349 $message->courseid = 1;350 $message->component = 'moodle';351 $message->name = 'instantmessage';352 $message->userfrom = $user1;353 $message->userto = $user2;354 $message->subject = 'message subject 1';355 $message->fullmessage = 'message body';356 $message->fullmessageformat = FORMAT_MARKDOWN;357 $message->fullmessagehtml = '<p>message body</p>';358 $message->smallmessage = 'small message';359 $message->notification = '0';360 $sink = $this->redirectEmails();361 $messageid = message_send($message);362 $emails = $sink->get_messages();363 $this->assertCount(0, $emails);364 $savedmessage = $DB->get_record('message', array('id' => $messageid), '*', MUST_EXIST);365 $sink->clear();366 $this->assertFalse($DB->record_exists('message_read', array()));367 $DB->delete_records('message', array());368 $events = $eventsink->get_events();369 $this->assertCount(1, $events);370 $this->assertInstanceOf('\core\event\message_sent', $events[0]);371 $eventsink->clear();372 $CFG->messaging = 0;373 $message = new \core\message\message();374 $message->courseid = 1;375 $message->component = 'moodle';376 $message->name = 'instantmessage';377 $message->userfrom = $user1;378 $message->userto = $user2;379 $message->subject = 'message subject 1';380 $message->fullmessage = 'message body';381 $message->fullmessageformat = FORMAT_MARKDOWN;382 $message->fullmessagehtml = '<p>message body</p>';383 $message->smallmessage = 'small message';384 $message->notification = '0';385 $messageid = message_send($message);386 $emails = $sink->get_messages();387 $this->assertCount(0, $emails);388 $savedmessage = $DB->get_record('message_read', array('id' => $messageid), '*', MUST_EXIST);389 $sink->clear();390 $this->assertFalse($DB->record_exists('message', array()));391 $DB->delete_records('message_read', array());392 $events = $eventsink->get_events();393 $this->assertCount(2, $events);394 $this->assertInstanceOf('\core\event\message_sent', $events[0]);395 $this->assertInstanceOf('\core\event\message_viewed', $events[1]);396 $eventsink->clear();397 $CFG->messaging = 1;398 $message = new \core\message\message();399 $message->courseid = 1;400 $message->component = 'moodle';401 $message->name = 'instantmessage';402 $message->userfrom = $user1;403 $message->userto = $user2;404 $message->subject = 'message subject 1';405 $message->fullmessage = 'message body';406 $message->fullmessageformat = FORMAT_MARKDOWN;407 $message->fullmessagehtml = '<p>message body</p>';408 $message->smallmessage = 'small message';409 $message->notification = '1';410 $messageid = message_send($message);411 $emails = $sink->get_messages();412 $this->assertCount(0, $emails);413 $savedmessage = $DB->get_record('message_read', array('id' => $messageid), '*', MUST_EXIST);414 $sink->clear();415 $this->assertFalse($DB->record_exists('message', array()));416 $DB->delete_records('message_read', array());417 $events = $eventsink->get_events();418 $this->assertCount(2, $events);419 $this->assertInstanceOf('\core\event\message_sent', $events[0]);420 $this->assertInstanceOf('\core\event\message_viewed', $events[1]);421 $eventsink->clear();422 // Will always use the pop-up processor.423 set_user_preference('message_provider_moodle_instantmessage_loggedoff', 'email', $user2);424 $message = new \core\message\message();425 $message->courseid = 1;426 $message->component = 'moodle';427 $message->name = 'instantmessage';428 $message->userfrom = $user1;429 $message->userto = $user2;430 $message->subject = 'message subject 1';431 $message->fullmessage = 'message body';432 $message->fullmessageformat = FORMAT_MARKDOWN;433 $message->fullmessagehtml = '<p>message body</p>';434 $message->smallmessage = 'small message';435 $message->notification = '0';436 $user2->emailstop = '1';437 $sink = $this->redirectEmails();438 $messageid = message_send($message);439 $emails = $sink->get_messages();440 $this->assertCount(0, $emails);441 $savedmessage = $DB->get_record('message', array('id' => $messageid), '*', MUST_EXIST);442 $sink->clear();443 $this->assertFalse($DB->record_exists('message_read', array()));444 $DB->delete_records('message', array());445 $events = $eventsink->get_events();446 $this->assertCount(1, $events);447 $this->assertInstanceOf('\core\event\message_sent', $events[0]);448 $eventsink->clear();449 $user2->emailstop = '0';450 // Will always use the pop-up processor.451 set_user_preference('message_provider_moodle_instantmessage_loggedoff', 'email', $user2);452 $message = new \core\message\message();453 $message->courseid = 1;454 $message->component = 'moodle';455 $message->name = 'instantmessage';456 $message->userfrom = $user1;457 $message->userto = $user2;458 $message->subject = 'message subject 1';459 $message->fullmessage = 'message body';460 $message->fullmessageformat = FORMAT_MARKDOWN;461 $message->fullmessagehtml = '<p>message body</p>';462 $message->smallmessage = 'small message';463 $message->notification = '0';464 $messageid = message_send($message);465 $emails = $sink->get_messages();466 $this->assertCount(1, $emails);467 $email = reset($emails);468 $savedmessage = $DB->get_record('message', array('id' => $messageid), '*', MUST_EXIST);469 $this->assertSame($user1->email, $email->from);470 $this->assertSame($user2->email, $email->to);471 $this->assertSame($message->subject, $email->subject);472 $this->assertNotEmpty($email->header);473 $this->assertNotEmpty($email->body);474 $sink->clear();475 $this->assertFalse($DB->record_exists('message_read', array()));476 $DB->delete_records('message_read', array());477 $events = $eventsink->get_events();478 $this->assertCount(1, $events);479 $this->assertInstanceOf('\core\event\message_sent', $events[0]);480 $eventsink->clear();481 set_user_preference('message_provider_moodle_instantmessage_loggedoff', 'email,popup', $user2);482 $message = new \core\message\message();483 $message->courseid = 1;484 $message->component = 'moodle';485 $message->name = 'instantmessage';486 $message->userfrom = $user1;487 $message->userto = $user2;488 $message->subject = 'message subject 1';489 $message->fullmessage = 'message body';490 $message->fullmessageformat = FORMAT_MARKDOWN;491 $message->fullmessagehtml = '<p>message body</p>';492 $message->smallmessage = 'small message';493 $message->notification = '0';494 $messageid = message_send($message);495 $emails = $sink->get_messages();496 $this->assertCount(1, $emails);497 $email = reset($emails);498 $savedmessage = $DB->get_record('message', array('id' => $messageid), '*', MUST_EXIST);499 $working = $DB->get_record('message_working', array('unreadmessageid' => $messageid), '*', MUST_EXIST);500 $this->assertSame($user1->email, $email->from);501 $this->assertSame($user2->email, $email->to);502 $this->assertSame($message->subject, $email->subject);503 $this->assertNotEmpty($email->header);504 $this->assertNotEmpty($email->body);505 $sink->clear();506 $this->assertFalse($DB->record_exists('message_read', array()));507 $DB->delete_records('message', array());508 $events = $eventsink->get_events();509 $this->assertCount(1, $events);510 $this->assertInstanceOf('\core\event\message_sent', $events[0]);511 $eventsink->clear();512 set_user_preference('message_provider_moodle_instantmessage_loggedoff', 'popup', $user2);513 $message = new \core\message\message();514 $message->courseid = 1;515 $message->component = 'moodle';516 $message->name = 'instantmessage';517 $message->userfrom = $user1;518 $message->userto = $user2;519 $message->subject = 'message subject 1';520 $message->fullmessage = 'message body';521 $message->fullmessageformat = FORMAT_MARKDOWN;522 $message->fullmessagehtml = '<p>message body</p>';523 $message->smallmessage = 'small message';524 $message->notification = '0';525 $messageid = message_send($message);526 $emails = $sink->get_messages();527 $this->assertCount(0, $emails);528 $savedmessage = $DB->get_record('message', array('id' => $messageid), '*', MUST_EXIST);529 $working = $DB->get_record('message_working', array('unreadmessageid' => $messageid), '*', MUST_EXIST);530 $sink->clear();531 $this->assertFalse($DB->record_exists('message_read', array()));532 $DB->delete_records('message', array());533 $events = $eventsink->get_events();534 $this->assertCount(1, $events);535 $this->assertInstanceOf('\core\event\message_sent', $events[0]);536 $eventsink->clear();537 $this->assertFalse($DB->is_transaction_started());538 $transaction = $DB->start_delegated_transaction();539 if (!$DB->is_transaction_started()) {540 $this->markTestSkipped('Databases that do not support transactions should not be used at all!');541 }542 $transaction->allow_commit();543 // Will always use the pop-up processor.544 set_user_preference('message_provider_moodle_instantmessage_loggedoff', 'none', $user2);545 $message = new \core\message\message();546 $message->courseid = 1;547 $message->component = 'moodle';548 $message->name = 'instantmessage';549 $message->userfrom = $user1;550 $message->userto = $user2;551 $message->subject = 'message subject 1';552 $message->fullmessage = 'message body';553 $message->fullmessageformat = FORMAT_MARKDOWN;554 $message->fullmessagehtml = '<p>message body</p>';555 $message->smallmessage = 'small message';556 $message->notification = '0';557 $transaction = $DB->start_delegated_transaction();558 $sink = $this->redirectEmails();559 $messageid = message_send($message);560 $emails = $sink->get_messages();561 $this->assertCount(0, $emails);562 $savedmessage = $DB->get_record('message', array('id' => $messageid), '*', MUST_EXIST);563 $sink->clear();564 $this->assertFalse($DB->record_exists('message_read', array()));565 $DB->delete_records('message', array());566 $events = $eventsink->get_events();567 $this->assertCount(0, $events);568 $eventsink->clear();569 $transaction->allow_commit();570 $events = $eventsink->get_events();571 $this->assertCount(1, $events);572 $this->assertInstanceOf('\core\event\message_sent', $events[0]);573 // Will always use the pop-up processor.574 set_user_preference('message_provider_moodle_instantmessage_loggedoff', 'email', $user2);575 $message = new \core\message\message();576 $message->courseid = 1;577 $message->component = 'moodle';578 $message->name = 'instantmessage';579 $message->userfrom = $user1;580 $message->userto = $user2;581 $message->subject = 'message subject 1';582 $message->fullmessage = 'message body';583 $message->fullmessageformat = FORMAT_MARKDOWN;584 $message->fullmessagehtml = '<p>message body</p>';585 $message->smallmessage = 'small message';586 $message->notification = '0';587 $transaction = $DB->start_delegated_transaction();588 $sink = $this->redirectEmails();589 $messageid = message_send($message);590 $emails = $sink->get_messages();591 $this->assertCount(0, $emails);592 $savedmessage = $DB->get_record('message', array('id' => $messageid), '*', MUST_EXIST);593 $sink->clear();594 $this->assertFalse($DB->record_exists('message_read', array()));595 $events = $eventsink->get_events();596 $this->assertCount(1, $events);597 $this->assertInstanceOf('\core\event\message_sent', $events[0]);598 $transaction->allow_commit();599 $events = $eventsink->get_events();600 $this->assertCount(2, $events);601 $this->assertInstanceOf('\core\event\message_sent', $events[1]);602 $eventsink->clear();603 $transaction = $DB->start_delegated_transaction();604 message_send($message);605 message_send($message);606 $this->assertCount(3, $DB->get_records('message'));607 $this->assertFalse($DB->record_exists('message_read', array()));608 $events = $eventsink->get_events();609 $this->assertCount(0, $events);610 $transaction->allow_commit();611 $events = $eventsink->get_events();612 $this->assertCount(2, $events);613 $this->assertInstanceOf('\core\event\message_sent', $events[0]);614 $this->assertInstanceOf('\core\event\message_sent', $events[1]);615 $eventsink->clear();616 $DB->delete_records('message', array());617 $DB->delete_records('message_read', array());618 $transaction = $DB->start_delegated_transaction();619 message_send($message);620 message_send($message);621 $this->assertCount(2, $DB->get_records('message'));622 $this->assertCount(0, $DB->get_records('message_read'));623 $events = $eventsink->get_events();624 $this->assertCount(0, $events);625 try {626 $transaction->rollback(new Exception('ignore'));627 } catch (Exception $e) {628 $this->assertSame('ignore', $e->getMessage());629 }630 $events = $eventsink->get_events();631 $this->assertCount(0, $events);632 $this->assertCount(0, $DB->get_records('message'));633 $this->assertCount(0, $DB->get_records('message_read'));634 message_send($message);635 $this->assertCount(1, $DB->get_records('message'));636 $this->assertCount(0, $DB->get_records('message_read'));637 $events = $eventsink->get_events();638 $this->assertCount(1, $events);639 $this->assertInstanceOf('\core\event\message_sent', $events[0]);640 $sink->clear();641 $DB->delete_records('message_read', array());642 }...

Full Screen

Full Screen

SMimeSignerTest.php

Source:SMimeSignerTest.php Github

copy

Full Screen

...11 $this->replacementFactory = Swift_DependencyContainer::getInstance()12 ->lookup('transport.replacementfactory');13 $this->samplesDir = str_replace('\\', '/', realpath(__DIR__.'/../../../_samples/')).'/';14 }15 public function testUnSingedMessage()16 {17 $message = (new Swift_Message('Wonderful Subject'))18 ->setFrom(array('john@doe.com' => 'John Doe'))19 ->setTo(array('receiver@domain.org', 'other@domain.org' => 'A name'))20 ->setBody('Here is the message itself');21 $this->assertEquals('Here is the message itself', $message->getBody());22 }23 public function testSingedMessage()24 {25 $message = (new Swift_Message('Wonderful Subject'))26 ->setFrom(array('john@doe.com' => 'John Doe'))27 ->setTo(array('receiver@domain.org', 'other@domain.org' => 'A name'))28 ->setBody('Here is the message itself');29 $signer = new Swift_Signers_SMimeSigner();30 $signer->setSignCertificate($this->samplesDir.'smime/sign.crt', $this->samplesDir.'smime/sign.key');31 $message->attachSigner($signer);32 $messageStream = $this->newFilteredStream();33 $message->toByteStream($messageStream);34 $messageStream->commit();35 $entityString = $messageStream->getContent();36 $headers = self::getHeadersOfMessage($entityString);37 if (!($boundary = $this->getBoundary($headers['content-type']))) {38 return false;39 }40 $expectedBody = <<<OEL41This is an S/MIME signed message42--$boundary43Content-Type: text/plain; charset=utf-844Content-Transfer-Encoding: quoted-printable45Here is the message itself46--$boundary47Content-Type: application/(x\-)?pkcs7-signature; name="smime\.p7s"48Content-Transfer-Encoding: base6449Content-Disposition: attachment; filename="smime\.p7s"50(?:^[a-zA-Z0-9\/\\r\\n+]*={0,2})51--$boundary--52OEL;53 $this->assertValidVerify($expectedBody, $messageStream);54 unset($messageStream);55 }56 public function testSingedMessageExtraCerts()57 {58 $message = (new Swift_Message('Wonderful Subject'))59 ->setFrom(array('john@doe.com' => 'John Doe'))60 ->setTo(array('receiver@domain.org', 'other@domain.org' => 'A name'))61 ->setBody('Here is the message itself');62 $signer = new Swift_Signers_SMimeSigner();63 $signer->setSignCertificate($this->samplesDir.'smime/sign2.crt', $this->samplesDir.'smime/sign2.key', PKCS7_DETACHED, $this->samplesDir.'smime/intermediate.crt');64 $message->attachSigner($signer);65 $messageStream = $this->newFilteredStream();66 $message->toByteStream($messageStream);67 $messageStream->commit();68 $entityString = $messageStream->getContent();69 $headers = self::getHeadersOfMessage($entityString);70 if (!($boundary = $this->getBoundary($headers['content-type']))) {71 return false;72 }73 $expectedBody = <<<OEL74This is an S/MIME signed message75--$boundary76Content-Type: text/plain; charset=utf-877Content-Transfer-Encoding: quoted-printable78Here is the message itself79--$boundary80Content-Type: application/(x\-)?pkcs7-signature; name="smime\.p7s"81Content-Transfer-Encoding: base6482Content-Disposition: attachment; filename="smime\.p7s"83(?:^[a-zA-Z0-9\/\\r\\n+]*={0,2})84--$boundary--85OEL;86 $this->assertValidVerify($expectedBody, $messageStream);87 unset($messageStream);88 }89 public function testSingedMessageBinary()90 {91 $message = (new Swift_Message('Wonderful Subject'))92 ->setFrom(array('john@doe.com' => 'John Doe'))93 ->setTo(array('receiver@domain.org', 'other@domain.org' => 'A name'))94 ->setBody('Here is the message itself');95 $signer = new Swift_Signers_SMimeSigner();96 $signer->setSignCertificate($this->samplesDir.'smime/sign.crt', $this->samplesDir.'smime/sign.key', PKCS7_BINARY);97 $message->attachSigner($signer);98 $messageStream = $this->newFilteredStream();99 $message->toByteStream($messageStream);100 $messageStream->commit();101 $entityString = $messageStream->getContent();102 $headers = self::getHeadersOfMessage($entityString);103 if (!preg_match('#^application/(x\-)?pkcs7-mime; smime-type=signed\-data;#', $headers['content-type'])) {104 $this->fail('Content-type does not match.');105 return false;106 }107 $this->assertEquals($headers['content-transfer-encoding'], 'base64');108 $this->assertEquals($headers['content-disposition'], 'attachment; filename="smime.p7m"');109 $expectedBody = '(?:^[a-zA-Z0-9\/\\r\\n+]*={0,2})';110 $messageStreamClean = $this->newFilteredStream();111 $this->assertValidVerify($expectedBody, $messageStream);112 unset($messageStreamClean, $messageStream);113 }114 public function testSingedMessageWithAttachments()115 {116 $message = (new Swift_Message('Wonderful Subject'))117 ->setFrom(array('john@doe.com' => 'John Doe'))118 ->setTo(array('receiver@domain.org', 'other@domain.org' => 'A name'))119 ->setBody('Here is the message itself');120 $message->attach(Swift_Attachment::fromPath($this->samplesDir.'/files/textfile.zip'));121 $signer = new Swift_Signers_SMimeSigner();122 $signer->setSignCertificate($this->samplesDir.'smime/sign.crt', $this->samplesDir.'smime/sign.key');123 $message->attachSigner($signer);124 $messageStream = $this->newFilteredStream();125 $message->toByteStream($messageStream);126 $messageStream->commit();127 $entityString = $messageStream->getContent();128 $headers = self::getHeadersOfMessage($entityString);129 if (!($boundary = $this->getBoundary($headers['content-type']))) {130 return false;131 }132 $expectedBody = <<<OEL133This is an S/MIME signed message134--$boundary135Content-Type: multipart/mixed;136 boundary="([a-z0-9\\'\\(\\)\\+_\\-,\\.\\/:=\\?\\ ]{0,69}[a-z0-9\\'\\(\\)\\+_\\-,\\.\\/:=\\?])"137--\\1138Content-Type: text/plain; charset=utf-8139Content-Transfer-Encoding: quoted-printable140Here is the message itself141--\\1142Content-Type: application/zip; name=textfile\\.zip143Content-Transfer-Encoding: base64144Content-Disposition: attachment; filename=textfile\\.zip145UEsDBAoAAgAAAMi6VjiOTiKwLgAAAC4AAAAMABUAdGV4dGZpbGUudHh0VVQJAAN3vr5Hd76\\+R1V4146BAD1AfUBVGhpcyBpcyBwYXJ0IG9mIGEgU3dpZnQgTWFpbGVyIHY0IHNtb2tlIHRlc3QuClBLAQIX147AwoAAgAAAMi6VjiOTiKwLgAAAC4AAAAMAA0AAAAAAAEAAACkgQAAAAB0ZXh0ZmlsZS50eHRVVAUA148A3e\\+vkdVeAAAUEsFBgAAAAABAAEARwAAAG0AAAAAAA==149--\\1--150--$boundary151Content-Type: application/(x\-)?pkcs7-signature; name="smime\\.p7s"152Content-Transfer-Encoding: base64153Content-Disposition: attachment; filename="smime\\.p7s"154(?:^[a-zA-Z0-9\/\\r\\n+]*={0,2})155--$boundary--156OEL;157 $this->assertValidVerify($expectedBody, $messageStream);158 unset($messageStream);159 }160 public function testEncryptedMessage()161 {162 $message = (new Swift_Message('Wonderful Subject'))163 ->setFrom(array('john@doe.com' => 'John Doe'))164 ->setTo(array('receiver@domain.org', 'other@domain.org' => 'A name'))165 ->setBody('Here is the message itself');166 $originalMessage = $this->cleanMessage($message->toString());167 $signer = new Swift_Signers_SMimeSigner();168 $signer->setEncryptCertificate($this->samplesDir.'smime/encrypt.crt');169 $message->attachSigner($signer);170 $messageStream = new Swift_ByteStream_TemporaryFileByteStream();171 $message->toByteStream($messageStream);172 $messageStream->commit();173 $entityString = $messageStream->getContent();174 $headers = self::getHeadersOfMessage($entityString);175 if (!preg_match('#^application/(x\-)?pkcs7-mime; smime-type=enveloped\-data;#', $headers['content-type'])) {176 $this->fail('Content-type does not match.');177 return false;178 }179 $expectedBody = '(?:^[a-zA-Z0-9\/\\r\\n+]*={0,2})';180 $decryptedMessageStream = new Swift_ByteStream_TemporaryFileByteStream();181 if (!openssl_pkcs7_decrypt($messageStream->getPath(), $decryptedMessageStream->getPath(), 'file://'.$this->samplesDir.'smime/encrypt.crt', array('file://'.$this->samplesDir.'smime/encrypt.key', 'swift'))) {182 $this->fail(sprintf('Decrypt of the message failed. Internal error "%s".', openssl_error_string()));183 }184 $this->assertEquals($originalMessage, $decryptedMessageStream->getContent());185 unset($decryptedMessageStream, $messageStream);186 }187 public function testEncryptedMessageWithMultipleCerts()188 {189 $message = (new Swift_Message('Wonderful Subject'))190 ->setFrom(array('john@doe.com' => 'John Doe'))191 ->setTo(array('receiver@domain.org', 'other@domain.org' => 'A name'))192 ->setBody('Here is the message itself');193 $originalMessage = $this->cleanMessage($message->toString());194 $signer = new Swift_Signers_SMimeSigner();195 $signer->setEncryptCertificate(array($this->samplesDir.'smime/encrypt.crt', $this->samplesDir.'smime/encrypt2.crt'));196 $message->attachSigner($signer);197 $messageStream = new Swift_ByteStream_TemporaryFileByteStream();198 $message->toByteStream($messageStream);199 $messageStream->commit();200 $entityString = $messageStream->getContent();201 $headers = self::getHeadersOfMessage($entityString);202 if (!preg_match('#^application/(x\-)?pkcs7-mime; smime-type=enveloped\-data;#', $headers['content-type'])) {203 $this->fail('Content-type does not match.');204 return false;205 }206 $expectedBody = '(?:^[a-zA-Z0-9\/\\r\\n+]*={0,2})';207 $decryptedMessageStream = new Swift_ByteStream_TemporaryFileByteStream();208 if (!openssl_pkcs7_decrypt($messageStream->getPath(), $decryptedMessageStream->getPath(), 'file://'.$this->samplesDir.'smime/encrypt.crt', array('file://'.$this->samplesDir.'smime/encrypt.key', 'swift'))) {209 $this->fail(sprintf('Decrypt of the message failed. Internal error "%s".', openssl_error_string()));210 }211 $this->assertEquals($originalMessage, $decryptedMessageStream->getContent());212 unset($decryptedMessageStream);213 $decryptedMessageStream = new Swift_ByteStream_TemporaryFileByteStream();214 if (!openssl_pkcs7_decrypt($messageStream->getPath(), $decryptedMessageStream->getPath(), 'file://'.$this->samplesDir.'smime/encrypt2.crt', array('file://'.$this->samplesDir.'smime/encrypt2.key', 'swift'))) {215 $this->fail(sprintf('Decrypt of the message failed. Internal error "%s".', openssl_error_string()));216 }217 $this->assertEquals($originalMessage, $decryptedMessageStream->getContent());218 unset($decryptedMessageStream, $messageStream);219 }220 public function testSignThenEncryptedMessage()221 {222 $message = (new Swift_Message('Wonderful Subject'))223 ->setFrom(array('john@doe.com' => 'John Doe'))224 ->setTo(array('receiver@domain.org', 'other@domain.org' => 'A name'))225 ->setBody('Here is the message itself');226 $signer = new Swift_Signers_SMimeSigner();227 $signer->setSignCertificate($this->samplesDir.'smime/sign.crt', $this->samplesDir.'smime/sign.key');228 $signer->setEncryptCertificate($this->samplesDir.'smime/encrypt.crt');229 $message->attachSigner($signer);230 $messageStream = new Swift_ByteStream_TemporaryFileByteStream();231 $message->toByteStream($messageStream);232 $messageStream->commit();233 $entityString = $messageStream->getContent();234 $headers = self::getHeadersOfMessage($entityString);235 if (!preg_match('#^application/(x\-)?pkcs7-mime; smime-type=enveloped\-data;#', $headers['content-type'])) {236 $this->fail('Content-type does not match.');237 return false;238 }239 $expectedBody = '(?:^[a-zA-Z0-9\/\\r\\n+]*={0,2})';240 $decryptedMessageStream = new Swift_ByteStream_TemporaryFileByteStream();241 if (!openssl_pkcs7_decrypt($messageStream->getPath(), $decryptedMessageStream->getPath(), 'file://'.$this->samplesDir.'smime/encrypt.crt', array('file://'.$this->samplesDir.'smime/encrypt.key', 'swift'))) {242 $this->fail(sprintf('Decrypt of the message failed. Internal error "%s".', openssl_error_string()));243 }244 $entityString = $decryptedMessageStream->getContent();245 $headers = self::getHeadersOfMessage($entityString);246 if (!($boundary = $this->getBoundary($headers['content-type']))) {247 return false;248 }249 $expectedBody = <<<OEL250This is an S/MIME signed message251--$boundary252Content-Type: text/plain; charset=utf-8253Content-Transfer-Encoding: quoted-printable254Here is the message itself255--$boundary256Content-Type: application/(x\-)?pkcs7-signature; name="smime\.p7s"257Content-Transfer-Encoding: base64258Content-Disposition: attachment; filename="smime\.p7s"259(?:^[a-zA-Z0-9\/\\r\\n+]*={0,2})260--$boundary--261OEL;262 if (!$this->assertValidVerify($expectedBody, $decryptedMessageStream)) {263 return false;264 }265 unset($decryptedMessageStream, $messageStream);266 }267 public function testEncryptThenSignMessage()268 {269 $message = (new Swift_Message('Wonderful Subject'))270 ->setFrom(array('john@doe.com' => 'John Doe'))271 ->setTo(array('receiver@domain.org', 'other@domain.org' => 'A name'))272 ->setBody('Here is the message itself');273 $originalMessage = $this->cleanMessage($message->toString());274 $signer = new Swift_Signers_SMimeSigner();275 $signer->setSignCertificate($this->samplesDir.'smime/sign.crt', $this->samplesDir.'smime/sign.key');276 $signer->setEncryptCertificate($this->samplesDir.'smime/encrypt.crt');277 $signer->setSignThenEncrypt(false);278 $message->attachSigner($signer);279 $messageStream = $this->newFilteredStream();280 $message->toByteStream($messageStream);281 $messageStream->commit();282 $entityString = $messageStream->getContent();283 $headers = self::getHeadersOfMessage($entityString);284 if (!($boundary = $this->getBoundary($headers['content-type']))) {285 return false;286 }287 $expectedBody = <<<OEL288This is an S/MIME signed message289--$boundary290(?P<encrypted_message>MIME-Version: 1\.0291Content-Disposition: attachment; filename="smime\.p7m"292Content-Type: application/(x\-)?pkcs7-mime; smime-type=enveloped-data; name="smime\.p7m"293Content-Transfer-Encoding: base64294(?:^[a-zA-Z0-9\/\\r\\n+]*={0,2})295)--$boundary296Content-Type: application/(x\-)?pkcs7-signature; name="smime\.p7s"297Content-Transfer-Encoding: base64298Content-Disposition: attachment; filename="smime\.p7s"299(?:^[a-zA-Z0-9\/\\r\\n+]*={0,2})300--$boundary--301OEL;302 if (!$this->assertValidVerify($expectedBody, $messageStream)) {303 return false;304 }305 $expectedBody = str_replace("\n", "\r\n", $expectedBody);306 if (!preg_match('%'.$expectedBody.'*%m', $entityString, $entities)) {307 $this->fail('Failed regex match.');308 return false;309 }310 $messageStreamClean = new Swift_ByteStream_TemporaryFileByteStream();311 $messageStreamClean->write($entities['encrypted_message']);312 $decryptedMessageStream = new Swift_ByteStream_TemporaryFileByteStream();313 if (!openssl_pkcs7_decrypt($messageStreamClean->getPath(), $decryptedMessageStream->getPath(), 'file://'.$this->samplesDir.'smime/encrypt.crt', array('file://'.$this->samplesDir.'smime/encrypt.key', 'swift'))) {314 $this->fail(sprintf('Decrypt of the message failed. Internal error "%s".', openssl_error_string()));315 }316 $this->assertEquals($originalMessage, $decryptedMessageStream->getContent());317 unset($messageStreamClean, $messageStream, $decryptedMessageStream);318 }319 protected function assertValidVerify($expected, Swift_ByteStream_TemporaryFileByteStream $messageStream)320 {321 $actual = $messageStream->getContent();322 // File is UNIX encoded so convert them to correct line ending323 $expected = str_replace("\n", "\r\n", $expected);324 $actual = trim(self::getBodyOfMessage($actual));325 if (!$this->assertRegExp('%^'.$expected.'$\s*%m', $actual)) {326 return false;327 }328 $opensslOutput = new Swift_ByteStream_TemporaryFileByteStream();329 $verify = openssl_pkcs7_verify($messageStream->getPath(), null, $opensslOutput->getPath(), array($this->samplesDir.'smime/ca.crt'));330 if (false === $verify) {331 $this->fail('Verification of the message failed.');332 return false;333 } elseif (-1 === $verify) {334 $this->fail(sprintf('Verification of the message failed. Internal error "%s".', openssl_error_string()));335 return false;336 }337 return true;338 }339 protected function getBoundary($contentType)340 {341 if (!preg_match('/boundary=("[^"]+"|(?:[^\s]+|$))/is', $contentType, $contentTypeData)) {342 $this->fail('Failed to find Boundary parameter');343 return false;344 }345 return trim($contentTypeData[1], '"');346 }347 protected function newFilteredStream()348 {349 $messageStream = new Swift_ByteStream_TemporaryFileByteStream();350 $messageStream->addFilter($this->replacementFactory->createFilter("\r\n", "\n"), 'CRLF to LF');351 $messageStream->addFilter($this->replacementFactory->createFilter("\n", "\r\n"), 'LF to CRLF');352 return $messageStream;353 }354 protected static function getBodyOfMessage($message)355 {356 return substr($message, strpos($message, "\r\n\r\n"));357 }358 /**359 * Strips of the sender headers and Mime-Version.360 */361 protected function cleanMessage($content)362 {363 $newContent = '';364 $headers = self::getHeadersOfMessage($content);365 foreach ($headers as $headerName => $value) {366 if (!in_array($headerName, array('content-type', 'content-transfer-encoding', 'content-disposition'))) {367 continue;368 }369 $headerName = explode('-', $headerName);370 $headerName = array_map('ucfirst', $headerName);371 $headerName = implode('-', $headerName);372 if (strlen($value) > 62) {373 $value = wordwrap($value, 62, "\n ");374 }375 $newContent .= "$headerName: $value\r\n";376 }377 return $newContent."\r\n".ltrim(self::getBodyOfMessage($content));378 }379 /**380 * Returns the headers of the message.381 *382 * Header-names are lowercase.383 *384 * @param string $message385 *386 * @return array387 */388 protected static function getHeadersOfMessage($message)389 {390 $headersPosEnd = strpos($message, "\r\n\r\n");391 $headerData = substr($message, 0, $headersPosEnd);392 $headerLines = explode("\r\n", $headerData);393 if (empty($headerLines)) {394 return array();395 }396 $headers = array();397 foreach ($headerLines as $headerLine) {398 if (ctype_space($headerLines[0]) || false === strpos($headerLine, ':')) {399 $headers[$currentHeaderName] .= ' '.trim($headerLine);400 continue;401 }402 $header = explode(':', $headerLine, 2);...

Full Screen

Full Screen

events_test.php

Source:events_test.php Github

copy

Full Screen

...191 }192 public function test_mesage_sent_without_other_courseid() {193 // Creating a message_sent event without other[courseid] leads to exception.194 $this->expectException('coding_exception');195 $this->expectExceptionMessage('The \'courseid\' value must be set in other');196 $event = \core\event\message_sent::create(array(197 'userid' => 1,198 'context' => context_system::instance(),199 'relateduserid' => 2,200 'other' => array(201 'messageid' => 3,202 )203 ));204 }205 public function test_mesage_sent_via_create_from_ids() {206 // Containing courseid.207 $event = \core\event\message_sent::create_from_ids(1, 2, 3, 4);208 // Trigger and capturing the event.209 $sink = $this->redirectEvents();210 $event->trigger();211 $events = $sink->get_events();212 $event = reset($events);213 // Check that the event data is valid.214 $this->assertInstanceOf('\core\event\message_sent', $event);215 $this->assertEquals(context_system::instance(), $event->get_context());216 $expected = array(SITEID, 'message', 'write', 'index.php?user=1&id=2&history=1#m3', 1);217 $this->assertEventLegacyLogData($expected, $event);218 $url = new moodle_url('/message/index.php', array('user1' => $event->userid, 'user2' => $event->relateduserid));219 $this->assertEquals($url, $event->get_url());220 $this->assertEquals(3, $event->other['messageid']);221 $this->assertEquals(4, $event->other['courseid']);222 }223 public function test_mesage_sent_via_create_from_ids_without_other_courseid() {224 // Creating a message_sent event without courseid leads to debugging + SITEID.225 // TODO: MDL-55449 Ensure this leads to exception instead of debugging in Moodle 3.6.226 $event = \core\event\message_sent::create_from_ids(1, 2, 3);227 // Trigger and capturing the event.228 $sink = $this->redirectEvents();229 $event->trigger();230 $events = $sink->get_events();231 $event = reset($events);232 $this->assertDebuggingCalled();233 $this->assertEquals(SITEID, $event->other['courseid']);234 }235 /**236 * Test the message viewed event.237 */238 public function test_message_viewed() {239 global $DB;240 // Create a message to mark as read.241 $message = new stdClass();242 $message->useridfrom = '1';243 $message->useridto = '2';244 $message->subject = 'Subject';245 $message->message = 'Message';246 $message->id = $DB->insert_record('message', $message);247 // Trigger and capture the event.248 $sink = $this->redirectEvents();249 message_mark_message_read($message, time());250 $events = $sink->get_events();251 $event = reset($events);252 // Check that the event data is valid.253 $this->assertInstanceOf('\core\event\message_viewed', $event);254 $this->assertEquals(context_user::instance(2), $event->get_context());255 $url = new moodle_url('/message/index.php', array('user1' => $event->userid, 'user2' => $event->relateduserid));256 $this->assertEquals($url, $event->get_url());257 }258 /**259 * Test the message deleted event.260 */261 public function test_message_deleted() {262 global $DB;263 // Create a message.264 $message = new stdClass();265 $message->useridfrom = '1';266 $message->useridto = '2';267 $message->subject = 'Subject';268 $message->message = 'Message';269 $message->timeuserfromdeleted = 0;270 $message->timeusertodeleted = 0;271 $message->id = $DB->insert_record('message', $message);272 // Trigger and capture the event.273 $sink = $this->redirectEvents();274 message_delete_message($message, $message->useridfrom);275 $events = $sink->get_events();276 $event = reset($events);277 // Check that the event data is valid.278 $this->assertInstanceOf('\core\event\message_deleted', $event);279 $this->assertEquals($message->useridfrom, $event->userid); // The user who deleted it.280 $this->assertEquals($message->useridto, $event->relateduserid);281 $this->assertEquals('message', $event->other['messagetable']);282 $this->assertEquals($message->id, $event->other['messageid']);283 $this->assertEquals($message->useridfrom, $event->other['useridfrom']);284 $this->assertEquals($message->useridto, $event->other['useridto']);285 // Create a read message.286 $message = new stdClass();287 $message->useridfrom = '2';288 $message->useridto = '1';289 $message->subject = 'Subject';290 $message->message = 'Message';291 $message->timeuserfromdeleted = 0;292 $message->timeusertodeleted = 0;293 $message->timeread = time();294 $message->id = $DB->insert_record('message_read', $message);295 // Trigger and capture the event.296 $sink = $this->redirectEvents();297 message_delete_message($message, $message->useridto);298 $events = $sink->get_events();299 $event = reset($events);300 // Check that the event data is valid.301 $this->assertInstanceOf('\core\event\message_deleted', $event);302 $this->assertEquals($message->useridto, $event->userid);303 $this->assertEquals($message->useridfrom, $event->relateduserid);304 $this->assertEquals('message_read', $event->other['messagetable']);305 $this->assertEquals($message->id, $event->other['messageid']);306 $this->assertEquals($message->useridfrom, $event->other['useridfrom']);307 $this->assertEquals($message->useridto, $event->other['useridto']);308 }309 /**310 * Test the message deleted event is fired when deleting a conversation.311 */312 public function test_message_deleted_whole_conversation() {313 global $DB;314 // Create a message.315 $message = new stdClass();316 $message->useridfrom = '1';317 $message->useridto = '2';318 $message->subject = 'Subject';319 $message->message = 'Message';320 $message->timeuserfromdeleted = 0;321 $message->timeusertodeleted = 0;322 $message->timecreated = 1;323 $messages = [];324 // Send this a few times.325 $messages[] = $DB->insert_record('message', $message);326 $message->timecreated++;327 $messages[] = $DB->insert_record('message', $message);328 $message->timecreated++;329 $messages[] = $DB->insert_record('message', $message);330 $message->timecreated++;331 $messages[] = $DB->insert_record('message', $message);332 // Create a read message.333 $message->timeread = time();...

Full Screen

Full Screen

message_test.php

Source:message_test.php Github

copy

Full Screen

1<?php2// This file is part of Moodle - http://moodle.org/3//4// Moodle is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.8//9// Moodle is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the12// GNU General Public License for more details.13//14// You should have received a copy of the GNU General Public License15// along with Moodle. If not, see <http://www.gnu.org/licenses/>.16/**17 * Test classes for \core\message\message.18 *19 * @package core_message20 * @category test21 * @copyright 2015 onwards Ankit Agarwal22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later23 */24defined('MOODLE_INTERNAL') || die();25global $CFG;26/**27 * Test script for message class.28 *29 * @package core_message30 * @category test31 * @copyright 2015 onwards Ankit Agarwal32 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later33 */34class core_message_testcase extends advanced_testcase {35 /**36 * Test the method get_eventobject_for_processor().37 */38 public function test_get_eventobject_for_processor() {39 global $USER;40 $this->resetAfterTest();41 $this->setAdminUser();42 $user = $this->getDataGenerator()->create_user();43 $message = new \core\message\message();44 $message->courseid = SITEID;45 $message->component = 'moodle';46 $message->name = 'instantmessage';47 $message->userfrom = $USER;48 $message->userto = $user;49 $message->subject = 'message subject 1';50 $message->fullmessage = 'message body';51 $message->fullmessageformat = FORMAT_MARKDOWN;52 $message->fullmessagehtml = '<p>message body</p>';53 $message->smallmessage = 'small message';54 $message->notification = '0';55 $message->contexturl = 'http://GalaxyFarFarAway.com';56 $message->contexturlname = 'Context name';57 $message->replyto = "random@example.com";58 $message->attachname = 'attachment';59 $content = array('*' => array('header' => ' test ', 'footer' => ' test ')); // Extra content for all types of messages.60 $message->set_additional_content('test', $content);61 // Create a file instance.62 $usercontext = context_user::instance($user->id);63 $file = new stdClass;64 $file->contextid = $usercontext->id;65 $file->component = 'user';66 $file->filearea = 'private';67 $file->itemid = 0;68 $file->filepath = '/';69 $file->filename = '1.txt';70 $file->source = 'test';71 $fs = get_file_storage();72 $file = $fs->create_file_from_string($file, 'file1 content');73 $message->attachment = $file;74 $stdclass = $message->get_eventobject_for_processor('test');75 $this->assertSame($message->courseid, $stdclass->courseid);76 $this->assertSame($message->component, $stdclass->component);77 $this->assertSame($message->name, $stdclass->name);78 $this->assertSame($message->userfrom, $stdclass->userfrom);79 $this->assertSame($message->userto, $stdclass->userto);80 $this->assertSame($message->subject, $stdclass->subject);81 $this->assertSame(' test ' . $message->fullmessage . ' test ', $stdclass->fullmessage);82 $this->assertSame(' test ' . $message->fullmessagehtml . ' test ', $stdclass->fullmessagehtml);83 $this->assertSame(' test ' . $message->smallmessage . ' test ', $stdclass->smallmessage);84 $this->assertSame($message->notification, $stdclass->notification);85 $this->assertSame($message->contexturl, $stdclass->contexturl);86 $this->assertSame($message->contexturlname, $stdclass->contexturlname);87 $this->assertSame($message->replyto, $stdclass->replyto);88 $this->assertSame($message->attachname, $stdclass->attachname);89 // Extra content for fullmessage only.90 $content = array('fullmessage' => array('header' => ' test ', 'footer' => ' test '));91 $message->set_additional_content('test', $content);92 $stdclass = $message->get_eventobject_for_processor('test');93 $this->assertSame(' test ' . $message->fullmessage . ' test ', $stdclass->fullmessage);94 $this->assertSame($message->fullmessagehtml, $stdclass->fullmessagehtml);95 $this->assertSame($message->smallmessage, $stdclass->smallmessage);96 // Extra content for fullmessagehtml and smallmessage only.97 $content = array('fullmessagehtml' => array('header' => ' test ', 'footer' => ' test '),98 'smallmessage' => array('header' => ' testsmall ', 'footer' => ' testsmall '));99 $message->set_additional_content('test', $content);100 $stdclass = $message->get_eventobject_for_processor('test');101 $this->assertSame($message->fullmessage, $stdclass->fullmessage);102 $this->assertSame(' test ' . $message->fullmessagehtml . ' test ', $stdclass->fullmessagehtml);103 $this->assertSame(' testsmall ' . $message->smallmessage . ' testsmall ', $stdclass->smallmessage);104 // Extra content for * and smallmessage.105 $content = array('*' => array('header' => ' test ', 'footer' => ' test '),106 'smallmessage' => array('header' => ' testsmall ', 'footer' => ' testsmall '));107 $message->set_additional_content('test', $content);108 $stdclass = $message->get_eventobject_for_processor('test');109 $this->assertSame(' test ' . $message->fullmessage . ' test ', $stdclass->fullmessage);110 $this->assertSame(' test ' . $message->fullmessagehtml . ' test ', $stdclass->fullmessagehtml);111 $this->assertSame(' testsmall ' . ' test ' . $message->smallmessage . ' test ' . ' testsmall ', $stdclass->smallmessage);112 }113 /**114 * Test sending messages as email works with the new class.115 */116 public function test_send_message() {117 global $DB, $CFG;118 $this->preventResetByRollback();119 $this->resetAfterTest();120 $user1 = $this->getDataGenerator()->create_user(array('maildisplay' => 1));121 $user2 = $this->getDataGenerator()->create_user();122 set_config('allowedemaildomains', 'example.com');123 // Test basic email processor.124 $this->assertFileExists("$CFG->dirroot/message/output/email/version.php");125 $this->assertFileExists("$CFG->dirroot/message/output/popup/version.php");126 $DB->set_field_select('message_processors', 'enabled', 0, "name <> 'email'");127 set_user_preference('message_provider_moodle_instantmessage_loggedoff', 'email', $user2);128 // Extra content for all types of messages.129 $message = new \core\message\message();130 $message->courseid = 1;131 $message->component = 'moodle';132 $message->name = 'instantmessage';133 $message->userfrom = $user1;134 $message->userto = $user2;135 $message->subject = 'message subject 1';136 $message->fullmessage = 'message body';137 $message->fullmessageformat = FORMAT_MARKDOWN;138 $message->fullmessagehtml = '<p>message body</p>';139 $message->smallmessage = 'small message';140 $message->notification = '0';141 $content = array('*' => array('header' => ' test ', 'footer' => ' test '));142 $message->set_additional_content('email', $content);143 $sink = $this->redirectEmails();144 $messageid = message_send($message);145 $emails = $sink->get_messages();146 $this->assertCount(1, $emails);147 $email = reset($emails);148 $recordexists = $DB->record_exists('message', array('id' => $messageid));149 $this->assertSame(true, $recordexists);150 $this->assertSame($user1->email, $email->from);151 $this->assertSame($user2->email, $email->to);152 $this->assertSame($message->subject, $email->subject);153 $this->assertNotEmpty($email->header);154 $this->assertNotEmpty($email->body);155 $this->assertRegExp('/test message body test/', $email->body);156 $sink->clear();157 // Test that event fired includes the courseid.158 $eventsink = $this->redirectEvents();159 $messageid = message_send($message);160 $events = $eventsink->get_events();161 $event = reset($events);162 $this->assertEquals($message->courseid, $event->other['courseid']);163 $eventsink->clear();164 $sink->clear();165 // Extra content for small message only. Shouldn't show up in emails as we sent fullmessage and fullmessagehtml only in166 // the emails.167 $message = new \core\message\message();168 $message->courseid = 1;169 $message->component = 'moodle';170 $message->name = 'instantmessage';171 $message->userfrom = $user1;172 $message->userto = $user2;173 $message->subject = 'message subject 1';174 $message->fullmessage = 'message body';175 $message->fullmessageformat = FORMAT_MARKDOWN;176 $message->fullmessagehtml = '<p>message body</p>';177 $message->smallmessage = 'small message';178 $message->notification = '0';179 $content = array('smallmessage' => array('header' => ' test ', 'footer' => ' test '));180 $message->set_additional_content('email', $content);181 $messageid = message_send($message);182 $emails = $sink->get_messages();183 $this->assertCount(1, $emails);184 $email = reset($emails);185 $recordexists = $DB->record_exists('message', array('id' => $messageid));186 $this->assertSame(true, $recordexists);187 $this->assertSame($user1->email, $email->from);188 $this->assertSame($user2->email, $email->to);189 $this->assertSame($message->subject, $email->subject);190 $this->assertNotEmpty($email->header);191 $this->assertNotEmpty($email->body);192 $this->assertNotRegExp('/test message body test/', $email->body);193 // Test that event fired includes the courseid.194 $eventsink = $this->redirectEvents();195 $messageid = message_send($message);196 $events = $eventsink->get_events();197 $event = reset($events);198 $this->assertEquals($message->courseid, $event->other['courseid']);199 $eventsink->close();200 $sink->close();201 }202}...

Full Screen

Full Screen

EmailService.php

Source:EmailService.php Github

copy

Full Screen

...40 */41 public function getEmailConfig() {42 return $this->emailConfig;43 }44 public function setMessageSubject($messageSubject) {45 $this->messageSubject = $messageSubject;46 }47 public function setMessageFrom($messageFrom) {48 $this->messageFrom = $messageFrom;49 }50 public function setMessageTo($messageTo) {51 $this->messageTo = $messageTo;52 }53 public function setMessageBody($messageBody) {54 $this->messageBody = $messageBody;55 }56 public function setMessageCc($messageCc) {57 $this->messageCc = $messageCc;58 }59 public function setMessageBcc($messageBcc) {60 $this->messageBcc = $messageBcc;61 }62 public function __construct() {63 $emailConfigurationService = new EmailConfigurationService();64 $this->emailConfig = $emailConfigurationService->getEmailConfiguration();65 if ($this->emailConfig->getMailType() == 'smtp' ||66 $this->emailConfig->getMailType() == 'sendmail') {67 $this->configSet = true;68 }69 }70 private function _getMailer() {71 $mailer = null;72 if ($this->configSet) {73 switch ($this->emailConfig->getMailType()) {74 case 'smtp':75 $transport = Swift_SmtpTransport::newInstance(76 $this->emailConfig->getSmtpHost(),77 $this->emailConfig->getSmtpPort());78 if ($this->emailConfig->getSmtpAuthType() == self::SMTP_AUTH_LOGIN) {79 $transport->setUsername($this->emailConfig->getSmtpUsername());80 $transport->setPassword($this->emailConfig->getSmtpPassword());81 }82 if ($this->emailConfig->getSmtpSecurityType() == self::SMTP_SECURITY_SSL ||83 $this->emailConfig->getSmtpSecurityType() == self::SMTP_SECURITY_TLS) {84 $transport->setEncryption($this->emailConfig->getSmtpSecurityType());85 }86 $mailer = Swift_Mailer::newInstance($transport);87 break;88 case 'sendmail':89 $transport = Swift_SendmailTransport::newInstance($this->emailConfig->getSendmailPath());90 $mailer = Swift_Mailer::newInstance($transport);91 break;92 }93 }94 return $mailer;95 }96 private function _getMessage() {97 if (empty($this->messageSubject)) {98 throw new Exception("Email subjet is not set");99 }100 if (empty($this->messageFrom)) {101 $this->_validateEmailAddress($this->emailConfig->getSentAs());102 $this->messageFrom = array($this->emailConfig->getSentAs() => 'OrangeHRM');103 }104 if (empty($this->messageTo)) {105 throw new Exception("Email 'to' is not set");106 }107 if (empty($this->messageBody)) {108 throw new Exception("Email body is not set");109 }110 $message = Swift_Message::newInstance();111 $message->setSubject($this->messageSubject);112 $message->setFrom($this->messageFrom);113 $message->setTo($this->messageTo);114 $message->setBody($this->messageBody);115 if (!empty($this->messageCc)) {116 $message->setCc($this->messageCc);117 }118 if (!empty($this->messageBcc)) {119 $message->setBcc($this->messageBcc);120 }121 return $message;122 }123 public function sendEmail() {124 if ($this->configSet) {125 try {126 $mailer = $this->_getMailer();127 $message = $this->_getMessage();128 $result = $mailer->send($message);129 $logMessage = 'Emails was sent to ';130 $logMessage .= implode(', ', $this->messageTo);131 if (!empty($this->messageCc)) {132 $logMessage .= ' and CCed to ';133 $logMessage .= implode(', ', $this->messageCc);134 }135 if (!empty($this->messageBcc)) {136 $logMessage .= ' and BCCed to ';137 $logMessage .= implode(', ', $this->messageBcc);138 }139 $logMessage .= ' using '.$this->emailConfig->getMailType();140 $this->_logResult('Success', $logMessage);141 return true;142 } catch (Exception $e) {143 $logMessage = 'Sending email failed to ';144 $logMessage .= implode(', ', $this->messageTo);145 if (!empty($this->messageCc)) {146 $logMessage .= ' and CCing to ';147 $logMessage .= implode(', ', $this->messageCc);148 }149 if (!empty($this->messageBcc)) {150 $logMessage .= ' and BCCing to ';151 $logMessage .= implode(', ', $this->messageBcc);152 }153 $logMessage .= ' using '.$this->emailConfig->getMailType();154 $logMessage .= '. Reason: '.$e->getMessage();155 $this->_logResult('Failure', $logMessage);156 return false;157 }158 } else {159 $this->_logResult('Failure', 'Email configuration is not set.');160 return false;161 }162 }163 public function sendTestEmail($toEmail) {164 $mailType = $this->emailConfig->getMailType();165 if ($mailType == 'smtp') {166 $subject = "SMTP Configuration Test Email";167 $body = "This email confirms that SMTP details set in OrangeHRM are ";168 $body .= "correct. You received this email since your email address ";169 $body .= "was entered to test email in configuration screen.";170 171 } elseif ($mailType == 'sendmail') {172 $subject = "Sendmail Configuration Test Email";173 $body = "This email confirms that Sendmail details set in OrangeHRM ";174 $body .= "are correct. You received this email since your email ";175 $body .= "address was entered to test email in configuration screen.";176 }177 $this->_validateEmailAddress($toEmail);178 $this->messageSubject = $subject;179 $this->messageTo = array($toEmail);180 $this->messageBody = $body;181 return $this->sendEmail();182 }183 private function _validateEmailAddress($emailAddress) {184 if (!preg_match("/^[^@]*@[^@]*\.[^@]*$/", $emailAddress)) {185 throw new Exception("Invalid email address");186 }187 }188 private function _logResult($type = '', $logMessage = '') {189 $logPath = ROOT_PATH . '/lib/logs/notification_mails.log';190 if (file_exists($logPath) && !is_writable($logPath)) {191 throw new Exception("EmailService : Log file is not writable");192 }193 $message = '========== Message Begins ==========';194 $message .= "\r\n\n";195 $message .= 'Time : '.date("F j, Y, g:i a");196 $message .= "\r\n";197 $message .= 'Message Type : '.$type;198 $message .= "\r\n";199 $message .= 'Message : '.$logMessage;200 $message .= "\r\n\n";201 $message .= '========== Message Ends ==========';202 $message .= "\r\n\n";203 file_put_contents($logPath, $message, FILE_APPEND);204 }205}...

Full Screen

Full Screen

GelfMessageFormatterTest.php

Source:GelfMessageFormatterTest.php Github

copy

Full Screen

...12namespace Monolog\Formatter; 13 14use Monolog\Logger; 15 16class GelfMessageFormatterTest extends \PHPUnit_Framework_TestCase 17{ 18 public function setUp() 19 { 20 if (!class_exists('\Gelf\Message')) { 21 $this->markTestSkipped("graylog2/gelf-php or mlehner/gelf-php is not installed"); 22 } 23 } 24 25 /** 26 * @covers Monolog\Formatter\GelfMessageFormatter::format 27 */ 28 public function testDefaultFormatter() 29 { 30 $formatter = new GelfMessageFormatter(); 31 $record = array( 32 'level' => Logger::ERROR, 33 'level_name' => 'ERROR', 34 'channel' => 'meh', 35 'context' => array(), 36 'datetime' => new \DateTime("@0"), 37 'extra' => array(), 38 'message' => 'log', 39 ); 40 41 $message = $formatter->format($record); 42 43 $this->assertInstanceOf('Gelf\Message', $message); 44 $this->assertEquals(0, $message->getTimestamp()); 45 $this->assertEquals('log', $message->getShortMessage()); 46 $this->assertEquals('meh', $message->getFacility()); 47 $this->assertEquals(null, $message->getLine()); 48 $this->assertEquals(null, $message->getFile()); 49 $this->assertEquals($this->isLegacy() ? 3 : 'error', $message->getLevel()); 50 $this->assertNotEmpty($message->getHost()); 51 52 $formatter = new GelfMessageFormatter('mysystem'); 53 54 $message = $formatter->format($record); 55 56 $this->assertInstanceOf('Gelf\Message', $message); 57 $this->assertEquals('mysystem', $message->getHost()); 58 } 59 60 /** 61 * @covers Monolog\Formatter\GelfMessageFormatter::format 62 */ 63 public function testFormatWithFileAndLine() 64 { 65 $formatter = new GelfMessageFormatter(); 66 $record = array( 67 'level' => Logger::ERROR, 68 'level_name' => 'ERROR', 69 'channel' => 'meh', 70 'context' => array('from' => 'logger'), 71 'datetime' => new \DateTime("@0"), 72 'extra' => array('file' => 'test', 'line' => 14), 73 'message' => 'log', 74 ); 75 76 $message = $formatter->format($record); 77 78 $this->assertInstanceOf('Gelf\Message', $message); 79 $this->assertEquals('test', $message->getFile()); 80 $this->assertEquals(14, $message->getLine()); 81 } 82 83 /** 84 * @covers Monolog\Formatter\GelfMessageFormatter::format 85 * @expectedException InvalidArgumentException 86 */ 87 public function testFormatInvalidFails() 88 { 89 $formatter = new GelfMessageFormatter(); 90 $record = array( 91 'level' => Logger::ERROR, 92 'level_name' => 'ERROR', 93 ); 94 95 $formatter->format($record); 96 } 97 98 /** 99 * @covers Monolog\Formatter\GelfMessageFormatter::format 100 */ 101 public function testFormatWithContext() 102 { 103 $formatter = new GelfMessageFormatter(); 104 $record = array( 105 'level' => Logger::ERROR, 106 'level_name' => 'ERROR', 107 'channel' => 'meh', 108 'context' => array('from' => 'logger'), 109 'datetime' => new \DateTime("@0"), 110 'extra' => array('key' => 'pair'), 111 'message' => 'log', 112 ); 113 114 $message = $formatter->format($record); 115 116 $this->assertInstanceOf('Gelf\Message', $message); 117 118 $message_array = $message->toArray(); 119 120 $this->assertArrayHasKey('_ctxt_from', $message_array); 121 $this->assertEquals('logger', $message_array['_ctxt_from']); 122 123 // Test with extraPrefix 124 $formatter = new GelfMessageFormatter(null, null, 'CTX'); 125 $message = $formatter->format($record); 126 127 $this->assertInstanceOf('Gelf\Message', $message); 128 129 $message_array = $message->toArray(); 130 131 $this->assertArrayHasKey('_CTXfrom', $message_array); 132 $this->assertEquals('logger', $message_array['_CTXfrom']); 133 } 134 135 /** 136 * @covers Monolog\Formatter\GelfMessageFormatter::format 137 */ 138 public function testFormatWithContextContainingException() 139 { 140 $formatter = new GelfMessageFormatter(); 141 $record = array( 142 'level' => Logger::ERROR, 143 'level_name' => 'ERROR', 144 'channel' => 'meh', 145 'context' => array('from' => 'logger', 'exception' => array( 146 'class' => '\Exception', 147 'file' => '/some/file/in/dir.php:56', 148 'trace' => array('/some/file/1.php:23', '/some/file/2.php:3'), 149 )), 150 'datetime' => new \DateTime("@0"), 151 'extra' => array(), 152 'message' => 'log', 153 ); 154 155 $message = $formatter->format($record); 156 157 $this->assertInstanceOf('Gelf\Message', $message); 158 159 $this->assertEquals("/some/file/in/dir.php", $message->getFile()); 160 $this->assertEquals("56", $message->getLine()); 161 } 162 163 /** 164 * @covers Monolog\Formatter\GelfMessageFormatter::format 165 */ 166 public function testFormatWithExtra() 167 { 168 $formatter = new GelfMessageFormatter(); 169 $record = array( 170 'level' => Logger::ERROR, 171 'level_name' => 'ERROR', 172 'channel' => 'meh', 173 'context' => array('from' => 'logger'), 174 'datetime' => new \DateTime("@0"), 175 'extra' => array('key' => 'pair'), 176 'message' => 'log', 177 ); 178 179 $message = $formatter->format($record); 180 181 $this->assertInstanceOf('Gelf\Message', $message); 182 183 $message_array = $message->toArray(); 184 185 $this->assertArrayHasKey('_key', $message_array); 186 $this->assertEquals('pair', $message_array['_key']); 187 188 // Test with extraPrefix 189 $formatter = new GelfMessageFormatter(null, 'EXT'); 190 $message = $formatter->format($record); 191 192 $this->assertInstanceOf('Gelf\Message', $message); 193 194 $message_array = $message->toArray(); 195 196 $this->assertArrayHasKey('_EXTkey', $message_array); 197 $this->assertEquals('pair', $message_array['_EXTkey']); 198 } 199 200 public function testFormatWithLargeData() 201 { 202 $formatter = new GelfMessageFormatter(); 203 $record = array( 204 'level' => Logger::ERROR, 205 'level_name' => 'ERROR', 206 'channel' => 'meh', 207 'context' => array('exception' => str_repeat(' ', 32767)), 208 'datetime' => new \DateTime("@0"), 209 'extra' => array('key' => str_repeat(' ', 32767)), 210 'message' => 'log' 211 ); 212 $message = $formatter->format($record); 213 $messageArray = $message->toArray(); 214 215 // 200 for padding + metadata 216 $length = 200; 217 218 foreach ($messageArray as $key => $value) { 219 if (!in_array($key, array('level', 'timestamp'))) { 220 $length += strlen($value); 221 } 222 } 223 224 $this->assertLessThanOrEqual(65792, $length, 'The message length is no longer than the maximum allowed length'); 225 } 226 227 public function testFormatWithUnlimitedLength() 228 { 229 $formatter = new GelfMessageFormatter('LONG_SYSTEM_NAME', null, 'ctxt_', PHP_INT_MAX); 230 $record = array( 231 'level' => Logger::ERROR, 232 'level_name' => 'ERROR', 233 'channel' => 'meh', 234 'context' => array('exception' => str_repeat(' ', 32767 * 2)), 235 'datetime' => new \DateTime("@0"), 236 'extra' => array('key' => str_repeat(' ', 32767 * 2)), 237 'message' => 'log' 238 ); 239 $message = $formatter->format($record); 240 $messageArray = $message->toArray(); 241 242 // 200 for padding + metadata 243 $length = 200; 244 245 foreach ($messageArray as $key => $value) { 246 if (!in_array($key, array('level', 'timestamp'))) { 247 $length += strlen($value); 248 } 249 } 250 251 $this->assertGreaterThanOrEqual(131289, $length, 'The message should not be truncated'); 252 } 253 254 private function isLegacy() 255 { 256 return interface_exists('\Gelf\IMessagePublisher'); 257 } 258} ...

Full Screen

Full Screen

MailChannel.php

Source:MailChannel.php Github

copy

Full Screen

...59 * Get the mailer Closure for the message.60 *61 * @param mixed $notifiable62 * @param \Illuminate\Notifications\Notification $notification63 * @param \Illuminate\Notifications\Messages\MailMessage $message64 * @return \Closure65 */66 protected function messageBuilder($notifiable, $notification, $message)67 {68 return function ($mailMessage) use ($notifiable, $notification, $message) {69 $this->buildMessage($mailMessage, $notifiable, $notification, $message);70 };71 }72 /**73 * Build the notification's view.74 *75 * @param \Illuminate\Notifications\Messages\MailMessage $message76 * @return string|array77 */78 protected function buildView($message)79 {80 if ($message->view) {81 return $message->view;82 }83 return [84 'html' => $this->markdown->render($message->markdown, $message->data()),85 'text' => $this->markdown->renderText($message->markdown, $message->data()),86 ];87 }88 /**89 * Build the mail message.90 *91 * @param \Illuminate\Mail\Message $mailMessage92 * @param mixed $notifiable93 * @param \Illuminate\Notifications\Notification $notification94 * @param \Illuminate\Notifications\Messages\MailMessage $message95 * @return void96 */97 protected function buildMessage($mailMessage, $notifiable, $notification, $message)98 {99 $this->addressMessage($mailMessage, $notifiable, $notification, $message);100 $mailMessage->subject($message->subject ?: Str::title(101 Str::snake(class_basename($notification), ' ')102 ));103 $this->addAttachments($mailMessage, $message);104 if (! is_null($message->priority)) {105 $mailMessage->setPriority($message->priority);106 }107 }108 /**109 * Address the mail message.110 *111 * @param \Illuminate\Mail\Message $mailMessage112 * @param mixed $notifiable113 * @param \Illuminate\Notifications\Notification $notification114 * @param \Illuminate\Notifications\Messages\MailMessage $message115 * @return void116 */117 protected function addressMessage($mailMessage, $notifiable, $notification, $message)118 {119 $this->addSender($mailMessage, $message);120 $mailMessage->to($this->getRecipients($notifiable, $notification, $message));121 if ($message->cc) {122 $mailMessage->cc($message->cc[0], Arr::get($message->cc, 1));123 }124 if ($message->bcc) {125 $mailMessage->bcc($message->bcc[0], Arr::get($message->bcc, 1));126 }127 }128 /**129 * Add the "from" and "reply to" addresses to the message.130 *131 * @param \Illuminate\Mail\Message $mailMessage132 * @param \Illuminate\Notifications\Messages\MailMessage $message133 * @return void134 */135 protected function addSender($mailMessage, $message)136 {137 if (! empty($message->from)) {138 $mailMessage->from($message->from[0], Arr::get($message->from, 1));139 }140 if (! empty($message->replyTo)) {141 $mailMessage->replyTo($message->replyTo[0], Arr::get($message->replyTo, 1));142 }143 }144 /**145 * Get the recipients of the given message.146 *147 * @param mixed $notifiable148 * @param \Illuminate\Notifications\Notification $notification149 * @param \Illuminate\Notifications\Messages\MailMessage $message150 * @return mixed151 */152 protected function getRecipients($notifiable, $notification, $message)153 {154 if (is_string($recipients = $notifiable->routeNotificationFor('mail', $notification))) {155 $recipients = [$recipients];156 }157 return collect($recipients)->map(function ($recipient) {158 return is_string($recipient) ? $recipient : $recipient->email;159 })->all();160 }161 /**162 * Add the attachments to the message.163 *164 * @param \Illuminate\Mail\Message $mailMessage165 * @param \Illuminate\Notifications\Messages\MailMessage $message166 * @return void167 */168 protected function addAttachments($mailMessage, $message)169 {170 foreach ($message->attachments as $attachment) {171 $mailMessage->attach($attachment['file'], $attachment['options']);172 }173 foreach ($message->rawAttachments as $attachment) {174 $mailMessage->attachData($attachment['data'], $attachment['name'], $attachment['options']);175 }176 }177}...

Full Screen

Full Screen

Message

Using AI Code Generation

copy

Full Screen

1require_once 'vendor/autoload.php';2use Behat\Gherkin\Node\PyStringNode;3use Behat\Gherkin\Node\TableNode;4use Behat\Gherkin\Node\FeatureNode;5use Behat\Gherkin\Node\ScenarioNode;6use Behat\Gherkin\Node\StepNode;7use Behat\Gherkin\Node\BackgroundNode;8use Behat\Gherkin\Node\OutlineNode;9use Behat\Gherkin\Node\ExampleNode;10use Behat\Gherkin\Node\ExamplesNode;11use Behat\Gherkin\Node\StepContainerInterface;12use Behat\Gherkin\Node\StepContainer;13use Behat\Gherkin\Node\TaggedNodeInterface;14use Behat\Gherkin\Node\TaggedNode;15use Behat\Gherkin\Node\NodeInterface;16use Behat\Gherkin\Node\Node;17use Behat\Gherkin\Node\FeatureElementNode;18use Behat\Gherkin\Node\FeatureElement;19use Behat\Gherkin\Node\ArgumentInterface;20use Behat\Gherkin\Node\Argument;21use Behat\Gherkin\Node\Argument\PyStringArgument;22use Behat\Gherkin\Node\Argument\TableArgument;23use Behat\Gherkin\Node\Argument\ArgumentInterface;24use Behat\Gherkin\Node\Argument\Argument;25use Behat\Gherkin\Node\Argument\PyStringArgument;26use Behat\Gherkin\Node\Argument\TableArgument;27use Behat\Gherkin\Node\Argument\ArgumentInterface;28use Behat\Gherkin\Node\Argument\Argument;29use Behat\Gherkin\Node\Argument\PyStringArgument;30use Behat\Gherkin\Node\Argument\TableArgument;31use Behat\Gherkin\Node\Argument\ArgumentInterface;32use Behat\Gherkin\Node\Argument\Argument;33use Behat\Gherkin\Node\Argument\PyStringArgument;34use Behat\Gherkin\Node\Argument\TableArgument;35use Behat\Gherkin\Node\Argument\ArgumentInterface;36use Behat\Gherkin\Node\Argument\Argument;

Full Screen

Full Screen

Message

Using AI Code Generation

copy

Full Screen

1require_once "vendor/autoload.php";2use Behat\Gherkin\Node\PyStringNode;3use Behat\Gherkin\Node\TableNode;4use Behat\Gherkin\Node\StepNode;5use Behat\Gherkin\Node\ScenarioNode;6use Behat\Gherkin\Node\FeatureNode;7use Behat\Gherkin\Node\BackgroundNode;8use Behat\Gherkin\Node\OutlineNode;9use Behat\Gherkin\Node\StepContainer;10use Behat\Gherkin\Node\FeatureNode;11use Behat\Gherkin\Node\StepNode;12use Behat\Gherkin\Node\ScenarioNode;13use Behat\Gherkin\Node\TableNode;14use Behat\Gherkin\Node\PyStringNode;15use Behat\Gherkin\Node\BackgroundNode;16use Behat\Gherkin\Node\OutlineNode;17use Behat\Gherkin\Node\StepContainer;18use Behat\Gherkin\Node\FeatureNode;19use Behat\Gherkin\Node\StepNode;20use Behat\Gherkin\Node\ScenarioNode;21use Behat\Gherkin\Node\TableNode;22use Behat\Gherkin\Node\PyStringNode;23use Behat\Gherkin\Node\BackgroundNode;24use Behat\Gherkin\Node\OutlineNode;25use Behat\Gherkin\Node\StepContainer;26use Behat\Gherkin\Node\FeatureNode;27use Behat\Gherkin\Node\StepNode;28use Behat\Gherkin\Node\ScenarioNode;29use Behat\Gherkin\Node\TableNode;30use Behat\Gherkin\Node\PyStringNode;31use Behat\Gherkin\Node\BackgroundNode;32use Behat\Gherkin\Node\OutlineNode;33use Behat\Gherkin\Node\StepContainer;34use Behat\Gherkin\Node\FeatureNode;35use Behat\Gherkin\Node\StepNode;36use Behat\Gherkin\Node\ScenarioNode;37use Behat\Gherkin\Node\TableNode;38use Behat\Gherkin\Node\PyStringNode;

Full Screen

Full Screen

Message

Using AI Code Generation

copy

Full Screen

1require_once "vendor/autoload.php";2use Behat\Gherkin\Node\PyStringNode;3use Behat\Gherkin\Node\TableNode;4use Behat\Gherkin\Node\StepNode;5use Behat\Gherkin\Node\ScenarioNode;6use Behat\Gherkin\Node\FeatureNode;7use Behat\Gherkin\Node\BackgroundNode;8use Behat\Gherkin\Node\OutlineNode;9use Behat\Gherkin\Node\ExampleTableNode;10use Behat\Gherkin\Node\ExampleNode;11use Behat\Gherkin\Node\StepContainerInterface;12use Behat\Gherkin\Node\NodeInterface;13use Behat\Gherkin\Node\FeatureNode;14use Behat\Gherkin\Node\ScenarioNode;15use Behat\Gherkin\Filter\NameFilter;16use Behat\Gherkin\Filter\LineFilter;17use Behat\Gherkin\Filter\TagFilter;18use Behat\Gherkin\Filter\FeatureFilter;19use Behat\Gherkin\Filter\CompositeFilter;20use Behat\Gherkin\Loader\GherkinFileLoader;21use Behat\Gherkin\Loader\GherkinStringLoader;22use Behat\Gherkin\Loader\CachedFileLoader;23use Behat\Gherkin\Loader\LoaderInterface;24use Behat\Gherkin\Loader\Nodejs\Loader as NodejsLoader;25use Behat\Gherkin\Filter\FilterInterface;26use Behat\Gherkin\Keywords\KeywordsInterface;27use Behat\Gherkin\Keywords\ArrayKeywords;28use Behat\Gherkin\Keywords\Keywords;29use Behat\Gherkin\Keywords\KeywordsArray;30use Behat\Gherkin\Keywords\KeywordsHash;31use Behat\Gherkin\Keywords\KeywordsInterface;32use Behat\Gherkin\Keywords\KeywordsTable;33use Behat\Gherkin\Keywords\KeywordsHash;34use Behat\Gherkin\Keywords\KeywordsArray;35use Behat\Gherkin\Keywords\KeywordsTable;36use Behat\Gherkin\Keywords\KeywordsHash;37use Behat\Gherkin\Keywords\KeywordsArray;

Full Screen

Full Screen

Message

Using AI Code Generation

copy

Full Screen

1use Behat\Gherkin\Node\PyStringNode;2use Behat\Gherkin\Node\TableNode;3use Behat\MinkExtension\Context\MinkContext;4use Behat\Behat\Context\Step;5use Behat\Behat\Exception\PendingException;6use Behat\Behat\Context\Step\Given;7use Behat\Behat\Context\Step\When;8use Behat\Behat\Context\Step\Then;9use Behat\Behat\Context\Step\And;10use Behat\Behat\Context\Step\But;11use Behat\Behat\Context\Step\Example;12use Behat\Behat\Context\Step\Example\Given;13use Behat\Behat\Context\Step\Example\When;14use Behat\Behat\Context\Step\Example\Then;15use Behat\Behat\Context\Step\Example\And;16use Behat\Behat\Context\Step\Example\But;17use Behat\Behat\Context\Step\Example\Example;18use Behat\Behat\Context\Step\Example\Example\Given;

Full Screen

Full Screen

Message

Using AI Code Generation

copy

Full Screen

1use Behat\Gherkin\Node\MessageNode;2use Behat\Gherkin\Node\TableNode;3use Behat\Gherkin\Node\PyStringNode;4use Behat\Gherkin\Node\MessageNode;5use Behat\Gherkin\Node\TableNode;6use Behat\Gherkin\Node\PyStringNode;7use Behat\Gherkin\Node\MessageNode;8use Behat\Gherkin\Node\TableNode;9use Behat\Gherkin\Node\PyStringNode;10use Behat\Gherkin\Node\MessageNode;11use Behat\Gherkin\Node\TableNode;12use Behat\Gherkin\Node\PyStringNode;13use Behat\Gherkin\Node\MessageNode;14use Behat\Gherkin\Node\TableNode;15use Behat\Gherkin\Node\PyStringNode;16use Behat\Gherkin\Node\MessageNode;17use Behat\Gherkin\Node\TableNode;18use Behat\Gherkin\Node\PyStringNode;19use Behat\Gherkin\Node\MessageNode;20use Behat\Gherkin\Node\TableNode;21use Behat\Gherkin\Node\PyStringNode;22use Behat\Gherkin\Node\MessageNode;23use Behat\Gherkin\Node\TableNode;24use Behat\Gherkin\Node\PyStringNode;25use Behat\Gherkin\Node\MessageNode;26use Behat\Gherkin\Node\TableNode;27use Behat\Gherkin\Node\PyStringNode;28use Behat\Gherkin\Node\MessageNode;

Full Screen

Full Screen

Message

Using AI Code Generation

copy

Full Screen

1require 'vendor/autoload.php';2use Behat\Gherkin\Keywords\ArrayKeywords;3use Behat\Gherkin\Keywords\KeywordsInterface;4use Behat\Gherkin\Keywords\KeywordsCollection;5use Behat\Gherkin\Keywords\KeywordsDumper;6use Behat\Gherkin\Keywords\KeywordsDumperInterface;7use Behat\Gherkin\Keywords\KeywordsLoader;8use Behat\Gherkin\Keywords\KeywordsLoaderInterface;9use Behat\Gherkin\Keywords\KeywordsTable;10use Behat\Gherkin\Keywords\KeywordsTableInterface;11use Behat\Gherkin\Keywords\KeywordsTableNode;12use Behat\Gherkin\Keywords\KeywordsTableNodeInterface;13use Behat\Gherkin\Keywords\KeywordsTableNodeDumper;14use Behat\Gherkin\Keywords\KeywordsTableNodeDumperInterface;15use Behat\Gherkin\Keywords\KeywordsTableNodeLoader;16use Behat\Gherkin\Keywords\KeywordsTableNodeLoaderInterface;17use Behat\Gherkin\Keywords\KeywordsTableNodeParser;18use Behat\Gherkin\Keywords\KeywordsTableNodeParserInterface;19use Behat\Gherkin\Keywords\KeywordsTableParser;20use Behat\Gherkin\Keywords\KeywordsTableParserInterface;21use Behat\Gherkin\Keywords\KeywordsTableDumper;22use Behat\Gherkin\Keywords\KeywordsTableDumperInterface;23use Behat\Gherkin\Keywords\KeywordsTableLoader;24use Behat\Gherkin\Keywords\KeywordsTableLoaderInterface;25use Behat\Gherkin\Keywords\KeywordsTableNodeDumper;26use Behat\Gherkin\Keywords\KeywordsTableNodeDumperInterface;27use Behat\Gherkin\Keywords\KeywordsTableNodeLoader;28use Behat\Gherkin\Keywords\KeywordsTableNodeLoaderInterface;29use Behat\Gherkin\Keywords\KeywordsTableNodeParser;30use Behat\Gherkin\Keywords\KeywordsTableNodeParserInterface;31use Behat\Gherkin\Keywords\KeywordsTableParser;32use Behat\Gherkin\Keywords\KeywordsTableParserInterface;33use Behat\Gherkin\Keywords\KeywordsTableDumper;34use Behat\Gherkin\Keywords\KeywordsTableDumperInterface;

Full Screen

Full Screen

Message

Using AI Code Generation

copy

Full Screen

1use Behat\Gherkin\Node\MessageNode;2use Behat\Gherkin\Node\MessageNode;3use Behat\Gherkin\Node\MessageNode;4use Behat\Gherkin\Node\MessageNode;5use Behat\Gherkin\Node\MessageNode;6use Behat\Gherkin\Node\MessageNode;7use Behat\Gherkin\Node\MessageNode;8use Behat\Gherkin\Node\MessageNode;9use Behat\Gherkin\Node\MessageNode;10use Behat\Gherkin\Node\MessageNode;11use Behat\Gherkin\Node\MessageNode;12use Behat\Gherkin\Node\MessageNode;13use Behat\Gherkin\Node\MessageNode;14use Behat\Gherkin\Node\MessageNode;15use Behat\Gherkin\Node\MessageNode;16use Behat\Gherkin\Node\MessageNode;17use Behat\Gherkin\Node\MessageNode;18use Behat\Gherkin\Node\MessageNode;

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Gherkin-php automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Most used methods in Message

Run Selenium Automation Tests on LambdaTest Cloud Grid

Trigger Selenium automation tests on a cloud-based Grid of 3000+ real browsers and operating systems.

Test now for Free

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful