merge = new TestMerge();
}
/**
* Test plain text into a simple text document
*
* @dataProvider textToTextProvider
*/
public function testTextToText($testText, $expectedText)
{
$errors = [];
$this->merge->setReplacements(['$$replacement$$' => $testText]);
$result = $this->merge->merge_string(self::SIMPLE_TARGET, [1], $errors, "text/plain");
$this->assertEmpty($errors, "Errors when merging");
$this->assertEquals($expectedText, $result);
}
public function textToTextProvider() : array
{
return [
["Plain text", "Plain text"],
["New\nline text", "New\nline text"],
['Special -> characters <- & stuff', 'Special -> characters <- & stuff'],
['Contains HTML', 'Contains HTML'], // HTML is text too
['HTML
newline', "HTML
newline"], // HTML is text too
["Multi-line:\n1. First line\n -> Second\n", "Multi-line:\n1. First line\n -> Second\n"],
];
}
/**
* With no parsing into an HTML file, we expect the same
* @dataProvider textToHTMLProvider
*/
public function testTextToHtml($testText, $expectedText)
{
$errors = [];
$this->merge->setReplacements(['$$replacement$$' => $testText]);
$result = $this->merge->merge_string(self::SIMPLE_TARGET, [1], $errors, "text/html");
$this->assertEmpty($errors, "Errors when merging");
$this->assertEquals($expectedText, $result);
}
public function textToHtmlProvider() : array
{
return [
["Plain text", "Plain text"],
["New\nline text", "New
line text"], // Newlines get parsed anyway
['Special -> characters <- & stuff', 'Special -> characters '],
// strip_tags() is not smart. This could be improved
['Contains
HTML', 'Contains
HTML'], // Some tags are allowed
['Contains HTML that will be stripped
', 'Contains HTML that will be stripped'],
["Multi-line:\n1. First line\n -> Second\n", "Multi-line:
1. First line
-> Second
"],
];
}
}