<?php

namespace KupShop\DevelopmentBundle\Tests;

use KupShop\DevelopmentBundle\MailArchive;
use KupShop\DevelopmentBundle\Util\Tests\ContainerAwareTestTrait;

class MailArchiveTest extends \DatabaseTestCase
{
    use ContainerAwareTestTrait;

    /** @var MailArchive */
    protected $mailArchive;

    protected function setUp(): void
    {
        parent::setUp();

        $this->mailArchive = $this->get(MailArchive::class);
        $this->mailArchive->clearArchive();
    }

    public function testMailArchive()
    {
        $var = 'testtt';
        setCache('test', $var);
        $this->assertEquals('testtt', getCache('test'), 'Nefunguje cache!!!!');

        \SendMail('foo', 'test', 'test1234', 'testenzi');

        $this->assertEquals([['attachment' => [], 'from' => 'foo@localhost', 'body' => 'testenzi', 'subject' => 'test1234', 'to' => 'test@localhost', 'time' => date('Y-m-d H:i:s'), 'bcc' => null, 'cc' => null, 'replyTo' => 'foo@localhost', 'id' => 'not yet']], $this->mailArchive->getArchive());
    }

    public function testMailArchivePage()
    {
        $client = $this->createClient();
        \SendMail('test', 'test@test.com', '13371337', 'foo');

        $client->request('GET', '/emails/');

        $this->assertContains('13371337', $client->getResponse()->getContent());
    }

    public function testMailArchiveDetail()
    {
        $client = $this->createClient();
        \SendMail('test', 'test@test.com', 'foo', '13371337');
        $client->request('GET', '/emails/0/');
        $this->assertContains('13371337', $client->getResponse()->getContent());
    }
}
