summaryrefslogtreecommitdiff
path: root/vendor/symfony/mime/Tests/Part/TextPartTest.php
diff options
context:
space:
mode:
authorGreg Roach <fisharebest@webtrees.net>2019-06-03 14:19:10 +0100
committerGreg Roach <fisharebest@webtrees.net>2019-06-03 14:19:10 +0100
commit69c8d4f5c90cef75da102f92e4e992d03a8f1cd8 (patch)
tree4f956848961891482b64ee2cd5c8d7290936e354 /vendor/symfony/mime/Tests/Part/TextPartTest.php
parent425f99bc29ab9e477e5407b5c86da5c85ba47461 (diff)
downloadwebtrees-69c8d4f5c90cef75da102f92e4e992d03a8f1cd8.tar.gz
webtrees-69c8d4f5c90cef75da102f92e4e992d03a8f1cd8.tar.bz2
webtrees-69c8d4f5c90cef75da102f92e4e992d03a8f1cd8.zip
:Update vendor dependencies
Diffstat (limited to 'vendor/symfony/mime/Tests/Part/TextPartTest.php')
-rw-r--r--vendor/symfony/mime/Tests/Part/TextPartTest.php92
1 files changed, 92 insertions, 0 deletions
diff --git a/vendor/symfony/mime/Tests/Part/TextPartTest.php b/vendor/symfony/mime/Tests/Part/TextPartTest.php
new file mode 100644
index 0000000000..c3818b883d
--- /dev/null
+++ b/vendor/symfony/mime/Tests/Part/TextPartTest.php
@@ -0,0 +1,92 @@
+<?php
+
+/*
+ * This file is part of the Symfony package.
+ *
+ * (c) Fabien Potencier <fabien@symfony.com>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Symfony\Component\Mime\Tests\Part;
+
+use PHPUnit\Framework\TestCase;
+use Symfony\Component\Mime\Header\Headers;
+use Symfony\Component\Mime\Header\ParameterizedHeader;
+use Symfony\Component\Mime\Header\UnstructuredHeader;
+use Symfony\Component\Mime\Part\TextPart;
+
+class TextPartTest extends TestCase
+{
+ public function testConstructor()
+ {
+ $p = new TextPart('content');
+ $this->assertEquals('content', $p->getBody());
+ $this->assertEquals('content', $p->bodyToString());
+ $this->assertEquals('content', implode('', iterator_to_array($p->bodyToIterable())));
+ // bodyToIterable() can be called several times
+ $this->assertEquals('content', implode('', iterator_to_array($p->bodyToIterable())));
+ $this->assertEquals('text', $p->getMediaType());
+ $this->assertEquals('plain', $p->getMediaSubType());
+
+ $p = new TextPart('content', null, 'html');
+ $this->assertEquals('html', $p->getMediaSubType());
+ }
+
+ public function testConstructorWithResource()
+ {
+ $f = fopen('php://memory', 'r+', false);
+ fwrite($f, 'content');
+ rewind($f);
+ $p = new TextPart($f);
+ $this->assertEquals('content', $p->getBody());
+ $this->assertEquals('content', $p->bodyToString());
+ $this->assertEquals('content', implode('', iterator_to_array($p->bodyToIterable())));
+ fclose($f);
+ }
+
+ public function testConstructorWithNonStringOrResource()
+ {
+ $this->expectException(\TypeError::class);
+ new TextPart(new \stdClass());
+ }
+
+ public function testHeaders()
+ {
+ $p = new TextPart('content');
+ $this->assertEquals(new Headers(
+ new ParameterizedHeader('Content-Type', 'text/plain', ['charset' => 'utf-8']),
+ new UnstructuredHeader('Content-Transfer-Encoding', 'quoted-printable')
+ ), $p->getPreparedHeaders());
+
+ $p = new TextPart('content', 'iso-8859-1');
+ $this->assertEquals(new Headers(
+ new ParameterizedHeader('Content-Type', 'text/plain', ['charset' => 'iso-8859-1']),
+ new UnstructuredHeader('Content-Transfer-Encoding', 'quoted-printable')
+ ), $p->getPreparedHeaders());
+ }
+
+ public function testEncoding()
+ {
+ $p = new TextPart('content', 'utf-8', 'plain', 'base64');
+ $this->assertEquals(base64_encode('content'), $p->bodyToString());
+ $this->assertEquals(base64_encode('content'), implode('', iterator_to_array($p->bodyToIterable())));
+ $this->assertEquals(new Headers(
+ new ParameterizedHeader('Content-Type', 'text/plain', ['charset' => 'utf-8']),
+ new UnstructuredHeader('Content-Transfer-Encoding', 'base64')
+ ), $p->getPreparedHeaders());
+ }
+
+ public function testSerialize()
+ {
+ $r = fopen('php://memory', 'r+', false);
+ fwrite($r, 'Text content');
+ rewind($r);
+
+ $p = new TextPart($r);
+ $p->getHeaders()->addTextHeader('foo', 'bar');
+ $expected = clone $p;
+ $this->assertEquals($expected->toString(), unserialize(serialize($p))->toString());
+ }
+}