summaryrefslogtreecommitdiff
path: root/vendor/swiftmailer/swiftmailer/tests/unit/Swift/StreamFilters
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/swiftmailer/swiftmailer/tests/unit/Swift/StreamFilters')
-rw-r--r--vendor/swiftmailer/swiftmailer/tests/unit/Swift/StreamFilters/ByteArrayReplacementFilterTest.php129
-rw-r--r--vendor/swiftmailer/swiftmailer/tests/unit/Swift/StreamFilters/StringReplacementFilterFactoryTest.php36
-rw-r--r--vendor/swiftmailer/swiftmailer/tests/unit/Swift/StreamFilters/StringReplacementFilterTest.php59
3 files changed, 224 insertions, 0 deletions
diff --git a/vendor/swiftmailer/swiftmailer/tests/unit/Swift/StreamFilters/ByteArrayReplacementFilterTest.php b/vendor/swiftmailer/swiftmailer/tests/unit/Swift/StreamFilters/ByteArrayReplacementFilterTest.php
new file mode 100644
index 0000000..c85bdc1
--- /dev/null
+++ b/vendor/swiftmailer/swiftmailer/tests/unit/Swift/StreamFilters/ByteArrayReplacementFilterTest.php
@@ -0,0 +1,129 @@
+<?php
+
+class Swift_StreamFilters_ByteArrayReplacementFilterTest extends \PHPUnit_Framework_TestCase
+{
+ public function testBasicReplacementsAreMade()
+ {
+ $filter = $this->_createFilter(array(0x61, 0x62), array(0x63, 0x64));
+ $this->assertEquals(
+ array(0x59, 0x60, 0x63, 0x64, 0x65),
+ $filter->filter(array(0x59, 0x60, 0x61, 0x62, 0x65))
+ );
+ }
+
+ public function testShouldBufferReturnsTrueIfPartialMatchAtEndOfBuffer()
+ {
+ $filter = $this->_createFilter(array(0x61, 0x62), array(0x63, 0x64));
+ $this->assertTrue($filter->shouldBuffer(array(0x59, 0x60, 0x61)),
+ '%s: Filter should buffer since 0x61 0x62 is the needle and the ending '.
+ '0x61 could be from 0x61 0x62'
+ );
+ }
+
+ public function testFilterCanMakeMultipleReplacements()
+ {
+ $filter = $this->_createFilter(array(array(0x61), array(0x62)), array(0x63));
+ $this->assertEquals(
+ array(0x60, 0x63, 0x60, 0x63, 0x60),
+ $filter->filter(array(0x60, 0x61, 0x60, 0x62, 0x60))
+ );
+ }
+
+ public function testMultipleReplacementsCanBeDifferent()
+ {
+ $filter = $this->_createFilter(array(array(0x61), array(0x62)), array(array(0x63), array(0x64)));
+ $this->assertEquals(
+ array(0x60, 0x63, 0x60, 0x64, 0x60),
+ $filter->filter(array(0x60, 0x61, 0x60, 0x62, 0x60))
+ );
+ }
+
+ public function testShouldBufferReturnsFalseIfPartialMatchNotAtEndOfString()
+ {
+ $filter = $this->_createFilter(array(0x0D, 0x0A), array(0x0A));
+ $this->assertFalse($filter->shouldBuffer(array(0x61, 0x62, 0x0D, 0x0A, 0x63)),
+ '%s: Filter should not buffer since x0Dx0A is the needle and is not at EOF'
+ );
+ }
+
+ public function testShouldBufferReturnsTrueIfAnyOfMultipleMatchesAtEndOfString()
+ {
+ $filter = $this->_createFilter(array(array(0x61, 0x62), array(0x63)), array(0x64));
+ $this->assertTrue($filter->shouldBuffer(array(0x59, 0x60, 0x61)),
+ '%s: Filter should buffer since 0x61 0x62 is a needle and the ending '.
+ '0x61 could be from 0x61 0x62'
+ );
+ }
+
+ public function testConvertingAllLineEndingsToCRLFWhenInputIsLF()
+ {
+ $filter = $this->_createFilter(
+ array(array(0x0D, 0x0A), array(0x0D), array(0x0A)),
+ array(array(0x0A), array(0x0A), array(0x0D, 0x0A))
+ );
+
+ $this->assertEquals(
+ array(0x60, 0x0D, 0x0A, 0x61, 0x0D, 0x0A, 0x62, 0x0D, 0x0A, 0x63),
+ $filter->filter(array(0x60, 0x0A, 0x61, 0x0A, 0x62, 0x0A, 0x63))
+ );
+ }
+
+ public function testConvertingAllLineEndingsToCRLFWhenInputIsCR()
+ {
+ $filter = $this->_createFilter(
+ array(array(0x0D, 0x0A), array(0x0D), array(0x0A)),
+ array(array(0x0A), array(0x0A), array(0x0D, 0x0A))
+ );
+
+ $this->assertEquals(
+ array(0x60, 0x0D, 0x0A, 0x61, 0x0D, 0x0A, 0x62, 0x0D, 0x0A, 0x63),
+ $filter->filter(array(0x60, 0x0D, 0x61, 0x0D, 0x62, 0x0D, 0x63))
+ );
+ }
+
+ public function testConvertingAllLineEndingsToCRLFWhenInputIsCRLF()
+ {
+ $filter = $this->_createFilter(
+ array(array(0x0D, 0x0A), array(0x0D), array(0x0A)),
+ array(array(0x0A), array(0x0A), array(0x0D, 0x0A))
+ );
+
+ $this->assertEquals(
+ array(0x60, 0x0D, 0x0A, 0x61, 0x0D, 0x0A, 0x62, 0x0D, 0x0A, 0x63),
+ $filter->filter(array(0x60, 0x0D, 0x0A, 0x61, 0x0D, 0x0A, 0x62, 0x0D, 0x0A, 0x63))
+ );
+ }
+
+ public function testConvertingAllLineEndingsToCRLFWhenInputIsLFCR()
+ {
+ $filter = $this->_createFilter(
+ array(array(0x0D, 0x0A), array(0x0D), array(0x0A)),
+ array(array(0x0A), array(0x0A), array(0x0D, 0x0A))
+ );
+
+ $this->assertEquals(
+ array(0x60, 0x0D, 0x0A, 0x0D, 0x0A, 0x61, 0x0D, 0x0A, 0x0D, 0x0A, 0x62, 0x0D, 0x0A, 0x0D, 0x0A, 0x63),
+ $filter->filter(array(0x60, 0x0A, 0x0D, 0x61, 0x0A, 0x0D, 0x62, 0x0A, 0x0D, 0x63))
+ );
+ }
+
+ public function testConvertingAllLineEndingsToCRLFWhenInputContainsLFLF()
+ {
+ //Lighthouse Bug #23
+
+ $filter = $this->_createFilter(
+ array(array(0x0D, 0x0A), array(0x0D), array(0x0A)),
+ array(array(0x0A), array(0x0A), array(0x0D, 0x0A))
+ );
+
+ $this->assertEquals(
+ array(0x60, 0x0D, 0x0A, 0x0D, 0x0A, 0x61, 0x0D, 0x0A, 0x0D, 0x0A, 0x62, 0x0D, 0x0A, 0x0D, 0x0A, 0x63),
+ $filter->filter(array(0x60, 0x0A, 0x0A, 0x61, 0x0A, 0x0A, 0x62, 0x0A, 0x0A, 0x63))
+ );
+ }
+
+ private function _createFilter($search, $replace)
+ {
+ return new Swift_StreamFilters_ByteArrayReplacementFilter($search, $replace);
+ }
+}
diff --git a/vendor/swiftmailer/swiftmailer/tests/unit/Swift/StreamFilters/StringReplacementFilterFactoryTest.php b/vendor/swiftmailer/swiftmailer/tests/unit/Swift/StreamFilters/StringReplacementFilterFactoryTest.php
new file mode 100644
index 0000000..c14d5dc
--- /dev/null
+++ b/vendor/swiftmailer/swiftmailer/tests/unit/Swift/StreamFilters/StringReplacementFilterFactoryTest.php
@@ -0,0 +1,36 @@
+<?php
+
+class Swift_StreamFilters_StringReplacementFilterFactoryTest extends \PHPUnit_Framework_TestCase
+{
+ public function testInstancesOfStringReplacementFilterAreCreated()
+ {
+ $factory = $this->_createFactory();
+ $this->assertInstanceOf(
+ 'Swift_StreamFilters_StringReplacementFilter',
+ $factory->createFilter('a', 'b')
+ );
+ }
+
+ public function testSameInstancesAreCached()
+ {
+ $factory = $this->_createFactory();
+ $filter1 = $factory->createFilter('a', 'b');
+ $filter2 = $factory->createFilter('a', 'b');
+ $this->assertSame($filter1, $filter2, '%s: Instances should be cached');
+ }
+
+ public function testDifferingInstancesAreNotCached()
+ {
+ $factory = $this->_createFactory();
+ $filter1 = $factory->createFilter('a', 'b');
+ $filter2 = $factory->createFilter('a', 'c');
+ $this->assertNotEquals($filter1, $filter2,
+ '%s: Differing instances should not be cached'
+ );
+ }
+
+ private function _createFactory()
+ {
+ return new Swift_StreamFilters_StringReplacementFilterFactory();
+ }
+}
diff --git a/vendor/swiftmailer/swiftmailer/tests/unit/Swift/StreamFilters/StringReplacementFilterTest.php b/vendor/swiftmailer/swiftmailer/tests/unit/Swift/StreamFilters/StringReplacementFilterTest.php
new file mode 100644
index 0000000..681e235
--- /dev/null
+++ b/vendor/swiftmailer/swiftmailer/tests/unit/Swift/StreamFilters/StringReplacementFilterTest.php
@@ -0,0 +1,59 @@
+<?php
+
+class Swift_StreamFilters_StringReplacementFilterTest extends \PHPUnit_Framework_TestCase
+{
+ public function testBasicReplacementsAreMade()
+ {
+ $filter = $this->_createFilter('foo', 'bar');
+ $this->assertEquals('XbarYbarZ', $filter->filter('XfooYfooZ'));
+ }
+
+ public function testShouldBufferReturnsTrueIfPartialMatchAtEndOfBuffer()
+ {
+ $filter = $this->_createFilter('foo', 'bar');
+ $this->assertTrue($filter->shouldBuffer('XfooYf'),
+ '%s: Filter should buffer since "foo" is the needle and the ending '.
+ '"f" could be from "foo"'
+ );
+ }
+
+ public function testFilterCanMakeMultipleReplacements()
+ {
+ $filter = $this->_createFilter(array('a', 'b'), 'foo');
+ $this->assertEquals('XfooYfooZ', $filter->filter('XaYbZ'));
+ }
+
+ public function testMultipleReplacementsCanBeDifferent()
+ {
+ $filter = $this->_createFilter(array('a', 'b'), array('foo', 'zip'));
+ $this->assertEquals('XfooYzipZ', $filter->filter('XaYbZ'));
+ }
+
+ public function testShouldBufferReturnsFalseIfPartialMatchNotAtEndOfString()
+ {
+ $filter = $this->_createFilter("\r\n", "\n");
+ $this->assertFalse($filter->shouldBuffer("foo\r\nbar"),
+ '%s: Filter should not buffer since x0Dx0A is the needle and is not at EOF'
+ );
+ }
+
+ public function testShouldBufferReturnsTrueIfAnyOfMultipleMatchesAtEndOfString()
+ {
+ $filter = $this->_createFilter(array('foo', 'zip'), 'bar');
+ $this->assertTrue($filter->shouldBuffer('XfooYzi'),
+ '%s: Filter should buffer since "zip" is a needle and the ending '.
+ '"zi" could be from "zip"'
+ );
+ }
+
+ public function testShouldBufferReturnsFalseOnEmptyBuffer()
+ {
+ $filter = $this->_createFilter("\r\n", "\n");
+ $this->assertFalse($filter->shouldBuffer(''));
+ }
+
+ private function _createFilter($search, $replace)
+ {
+ return new Swift_StreamFilters_StringReplacementFilter($search, $replace);
+ }
+}