<commit_before><?php
/**
 * Zend Framework (http://framework.zend.com/)
 *
 * @link      http://github.com/zendframework/zf2 for the canonical source repository
 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
 * @license   http://framework.zend.com/license/new-bsd New BSD License
 */

namespace ZendTest\Mail\Storage;

use Zend\Mime;
use Zend\Mime\Exception as MimeException;
use Zend\Mail\Exception as MailException;
use Zend\Mail\Storage;
use Zend\Mail\Storage\Exception;
use Zend\Mail\Storage\Message;

/**
 * @group      Zend_Mail
 */
class MessageTest extends \PHPUnit_Framework_TestCase
{
    protected $_file;

    public function setUp()
    {
        $this->_file = __DIR__ . '/../_files/mail.txt';
    }

    public function testInvalidFile()
    {
        try {
            $message = new Message(['file' => '/this/file/does/not/exists']);
        } catch (\Exception $e) {
            return; // ok
        }

        $this->fail('no exception raised while loading unknown file');
    }

    /**
     * @dataProvider filesProvider
     */
    public function testIsMultipart($params)
    {
        $message = new Message($params);
        $this->assertTrue($message->isMultipart());
    }

    /**
     * @dataProvider filesProvider
     */
    public function testGetHeader($params)
    {
        $message = new Message($params);
        $this->assertEquals($message->subject, 'multipart');
    }

    /**
     * @dataProvider filesProvider
     */
    public function testGetDecodedHeader($params)
    {
        $message = new Message($params);
        $this->assertEquals('<NAME> <<EMAIL>>', $message->from);
    }

    /**
     * @dataProvider filesProvider
     */
    public function testGetHeaderAsArray($params)
    {
        $message = new Message($params);
        $this->assertEquals(['multipart'], $message->getHeader('subject', 'array'), 'getHeader() value not match');
    }

    public function testGetFirstPart()
    {
        $message = new Message(['file' => $this->_file]);

        $this->assertEquals(substr($message->getPart(1)->getContent(), 0, 14), 'The first part');
    }

    public function testGetFirstPartTwice()
    {
        $message = new Message(['file' => $this->_file]);

        $message->getPart(1);
        $this->assertEquals(substr($message->getPart(1)->getContent(), 0, 14), 'The first part');
    }


    public function testGetWrongPart()
    {
        $message = new Message(['file' => $this->_file]);

        try {
            $message->getPart(-1);
        } catch (\Exception $e) {
            return; // ok
        }

        $this->fail('no exception raised while fetching unknown part');
    }

    public function testNoHeaderMessage()
    {
        $message = new Message(['file' => __FILE__]);

        $this->assertEquals(substr($message->getContent(), 0, 5), '<?php');

        $raw = file_get_contents(__FILE__);
        $raw = "\t" . $raw;
        $message = new Message(['raw' => $raw]);

        $this->assertEquals(substr($message->getContent(), 0, 6), "\t<?php");
    }

    public function testMultipleHeader()
    {
        $raw = file_get_contents($this->_file);
        $raw = "sUBject: test\nSubJect: test2\n" . $raw;
        $message = new Message(['raw' => $raw]);

        $this->assertEquals('test' . Mime\Mime::LINEEND . 'test2' . Mime\Mime::LINEEND . 'multipart',
                            $message->getHeader('subject', 'string'));

        $this->assertEquals(['test', 'test2', 'multipart'],
                            $message->getHeader('subject', 'array'));
    }

    public function testContentTypeDecode()
    {
        $message = new Message(['file' => $this->_file]);

        $this->assertEquals(Mime\Decode::splitContentType($message->ContentType),<commit_msg>Use EOL consistent, file uses (\r\n)<commit_after><?php
/**
 * Zend Framework (http://framework.zend.com/)
 *
 * @link      http://github.com/zendframework/zf2 for the canonical source repository
 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
 * @license   http://framework.zend.com/license/new-bsd New BSD License
 */

namespace ZendTest\Mail\Storage;

use Zend\Mime;
use Zend\Mime\Exception as MimeException;
use Zend\Mail\Exception as MailException;
use Zend\Mail\Storage;
use Zend\Mail\Storage\Exception;
use Zend\Mail\Storage\Message;

/**
 * @group      Zend_Mail
 */
class MessageTest extends \PHPUnit_Framework_TestCase
{
    protected $_file;

    public function setUp()
    {
        $this->_file = __DIR__ . '/../_files/mail.txt';
    }

    public function testInvalidFile()
    {
        try {
            $message = new Message(['file' => '/this/file/does/not/exists']);
        } catch (\Exception $e) {
            return; // ok
        }

        $this->fail('no exception raised while loading unknown file');
    }

    /**
     * @dataProvider filesProvider
     */
    public function testIsMultipart($params)
    {
        $message = new Message($params);
        $this->assertTrue($message->isMultipart());
    }

    /**
     * @dataProvider filesProvider
     */
    public function testGetHeader($params)
    {
        $message = new Message($params);
        $this->assertEquals($message->subject, 'multipart');
    }

    /**
     * @dataProvider filesProvider
     */
    public function testGetDecodedHeader($params)
    {
        $message = new Message($params);
        $this->assertEquals('<NAME> <<EMAIL>>', $message->from);
    }

    /**
     * @dataProvider filesProvider
     */
    public function testGetHeaderAsArray($params)
    {
        $message = new Message($params);
        $this->assertEquals(['multipart'], $message->getHeader('subject', 'array'), 'getHeader() value not match');
    }

    public function testGetFirstPart()
    {
        $message = new Message(['file' => $this->_file]);

        $this->assertEquals(substr($message->getPart(1)->getContent(), 0, 14), 'The first part');
    }

    public function testGetFirstPartTwice()
    {
        $message = new Message(['file' => $this->_file]);

        $message->getPart(1);
        $this->assertEquals(substr($message->getPart(1)->getContent(), 0, 14), 'The first part');
    }


    public function testGetWrongPart()
    {
        $message = new Message(['file' => $this->_file]);

        try {
            $message->getPart(-1);
        } catch (\Exception $e) {
            return; // ok
        }

        $this->fail('no exception raised while fetching unknown part');
    }

    public function testNoHeaderMessage()
    {
        $message = new Message(['file' => __FILE__]);

        $this->assertEquals(substr($message->getContent(), 0, 5), '<?php');

        $raw = file_get_contents(__FILE__);
        $raw = "\t" . $raw;
        $message = new Message(['raw' => $raw]);

        $this->assertEquals(substr($message->getContent(), 0, 6), "\t<?php");
    }

    public function testMultipleHeader()
    {
        $raw = file_get_contents($this->_file);
        $raw = "sUBject: test\r\nSubJect: test2\r\n" . $raw;
        $message = new Message(['raw' => $raw]);

        $this->assertEquals('test' . Mime\Mime::LINEEND . 'test2' . Mime\Mime::LINEEND . 'multipart',
                            $message->getHeader('subject', 'string'));

        $this->assertEquals(['test', 'test2', 'multipart'],
                            $message->getHeader('subject', 'array'));
    }

    public function testContentTypeDecode()
    {
        $message = new Message(['file' => $this->_file]);

        $this->assertEquals(Mime\Decode::splitContentType($message->ContentType),
{'fraction_non_alphanumeric': 0.16293092148381177, 'fraction_numerical': 0.006816096473980862, 'mean_word_length': 2.545539033457249, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 93, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '7561860', 'n_tokens_mistral': 2276, 'n_tokens_neox': 2174, 'n_words': 460}