<commit_before><?php
declare(strict_types = 1);

namespace Externals\Test\Email;

use Externals\Application\Application;
use Externals\Email\EmailContentParser;

require_once __DIR__ . '/../../.puli/GeneratedPuliFactory.php';

class EmailContentParserTest extends \PHPUnit_Framework_TestCase
{
    /**
     * @var EmailContentParser
     */
    private $parser;

    public function setUp()
    {
        $container = (new Application)->getContainer();
        $this->parser = $container->get(EmailContentParser::class);
    }

    /**
     * @test
     */
    public function should_parse_markdown()
    {
        $content = <<<MARKDOWN
This is a paragraph.

    echo 'code';

> Take that!
MARKDOWN;
        $expected = <<<HTML
<p>This is a paragraph.</p>
<pre><code>echo 'code';
</code></pre>
<blockquote>
<p>Take that!</p>
</blockquote>
HTML;
        $this->assertEquals($expected, trim($this->parser->parse($content)));
    }

    /**
     * @test
     */
    public function should_keep_line_breaks()
    {
        $content = <<<MARKDOWN
This is a paragraph
that spans on 2 lines:

echo 'code';
echo 'another code;
MARKDOWN;
        $expected = <<<HTML
<p>This is a paragraph <br>
that spans on 2 lines:</p>
<p>echo 'code'; <br>
echo 'another code;</p>
HTML;
        $this->assertEquals($expected, trim($this->parser->parse($content)));
    }

    /**
     * @test
     */
    public function should_strip_mailing_list_signature()
    {
        $content = <<<MARKDOWN
Hello<commit_msg>Add test for bug in Markdown parsing<commit_after><?php
declare(strict_types = 1);

namespace Externals\Test\Email;

use Externals\Application\Application;
use Externals\Email\EmailContentParser;

require_once __DIR__ . '/../../.puli/GeneratedPuliFactory.php';

class EmailContentParserTest extends \PHPUnit_Framework_TestCase
{
    /**
     * @var EmailContentParser
     */
    private $parser;

    public function setUp()
    {
        $container = (new Application)->getContainer();
        $this->parser = $container->get(EmailContentParser::class);
    }

    /**
     * @test
     */
    public function should_parse_markdown()
    {
        $content = <<<MARKDOWN
This is a paragraph.

    echo 'code';

> Take that!
MARKDOWN;
        $expected = <<<HTML
<p>This is a paragraph.</p>
<pre><code>echo 'code';
</code></pre>
<blockquote>
<p>Take that!</p>
</blockquote>
HTML;
        $this->assertEquals($expected, trim($this->parser->parse($content)));
    }

    /**
     * @test
     */
    public function should_keep_line_breaks()
    {
        $content = <<<MARKDOWN
This is a paragraph
that spans on 2 lines:

echo 'code';
echo 'another code;
MARKDOWN;
        $expected = <<<HTML
<p>This is a paragraph <br>
that spans on 2 lines:</p>
<p>echo 'code'; <br>
echo 'another code;</p>
HTML;
        $this->assertEquals($expected, trim($this->parser->parse($content)));
    }

    /**
     * @test
     */
    public function should_encode_html_entities()
    {
        $this->markTestSkipped('Waiting for https://github.com/thephpleague/commonmark/issues/252 to be answered');
        $content = <<<'EMAIL'
> and the test:
>
> <?php
> ini_set("pcntl.async_signals", "1");

We use 2/3 vote for "a feature affecting the language itself".
EMAIL;
        $expected = <<<HTML
<p>and the test:</p>
<blockquote>
&gt;?php
ini_set(&quot;pcntl.async_signals&quot;, &quot;1&quot;);
</blockquote>
<p>We use 2/3 vote for &quot;a feature affecting the language itself&quot;.</p>
HTML;
        $this->assertEquals($expected, trim($this->parser->parse($content)));
    }

    /**
     * @test
     */
    public function should_strip_mailing_list_signature()
    {
        $content = <<<MARKDOWN
Hello
{'fraction_non_alphanumeric': 0.15503665490089602, 'fraction_numerical': 0.0040727667662231876, 'mean_word_length': 3.1024498886414253, 'pattern_counts': {'":': 0, '<': 80, '<?xml version=': 0, '>': 69, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5511473', 'n_tokens_mistral': 1206, 'n_tokens_neox': 1174, 'n_words': 275}