110 lines
3.3 KiB
PHP
110 lines
3.3 KiB
PHP
<?php
|
|
|
|
namespace KupShop\ReclamationsElninoBundle\Tests;
|
|
|
|
use KupShop\DevelopmentBundle\MailArchive;
|
|
use KupShop\ReclamationsElninoBundle\Util\ReclamationsUtil;
|
|
|
|
class ReclamationsElninoTest extends \DatabaseTestCase
|
|
{
|
|
/** @var ReclamationsUtil */
|
|
private $reclamations;
|
|
/** @var MailArchive */
|
|
private $mailArchive;
|
|
|
|
public static function setUpBeforeClass(): void
|
|
{
|
|
if (!findModule('reclamations_elnino')) {
|
|
self::markTestSkipped('Modul reclamations_elnino není zapnutý.');
|
|
}
|
|
}
|
|
|
|
protected function setUp(): void
|
|
{
|
|
parent::setUp();
|
|
|
|
$this->reclamations = $this->get(ReclamationsUtil::class);
|
|
$this->mailArchive = $this->get(MailArchive::class);
|
|
}
|
|
|
|
public function testCreateAndGetReclamation()
|
|
{
|
|
$reclamationId = $this->reclamations->createReclamation([34 => 1], 1, [], '123-4561315454/0800', null, 'User note');
|
|
$reclamation = $this->reclamations->getReclamation($reclamationId);
|
|
|
|
$this->assertRegExp('/R\d{3}/', $reclamation->getCode());
|
|
|
|
$history = $reclamation->getHistory();
|
|
$history = reset($history);
|
|
|
|
$this->assertEquals('User note', $history['comment']);
|
|
}
|
|
|
|
public function testEmailSentOnReturnCreated()
|
|
{
|
|
$dbcfg = \Settings::getDefault();
|
|
$dbcfg->reclamations['descr'] = '{KOD_REKLAMACE}';
|
|
|
|
$this->reclamations->createReclamation([34 => 1], 1, [], '123-4561315454/0800', 'User note');
|
|
|
|
$email = $this->mailArchive->getLast();
|
|
|
|
$this->assertNotEmpty($email);
|
|
$this->assertRegExp('/Demo - Přijali jsme formulář s reklamací R\d{3}/', $email['subject']);
|
|
}
|
|
|
|
public function testGetEmails()
|
|
{
|
|
$contents = $this->reclamations->getEmails();
|
|
|
|
$this->assertNotEmpty($contents);
|
|
}
|
|
|
|
public function testLogAndGetHistory()
|
|
{
|
|
$this->reclamations->logHistory(100, 'Log history test');
|
|
|
|
$history = $this->reclamations->getHistory(100);
|
|
$last = end($history);
|
|
unset($last['date']);
|
|
|
|
$this->assertEquals($last, [
|
|
'comment' => 'Log history test',
|
|
'status' => 0,
|
|
'notified' => 0,
|
|
'custom_data' => [],
|
|
'admin' => null,
|
|
'status_name' => 'Nová',
|
|
'admin_name' => null,
|
|
]);
|
|
}
|
|
|
|
public function testChangeStatus()
|
|
{
|
|
$reclamation = $this->reclamations->getReclamation(100);
|
|
$this->assertEquals(0, $reclamation->getStatus());
|
|
$this->assertEmpty($reclamation->getDateAccepted());
|
|
$this->assertEmpty($reclamation->getDateHandle());
|
|
|
|
$this->reclamations->changeStatus(100, 1);
|
|
|
|
$reclamation = $this->reclamations->getReclamation(100);
|
|
$this->assertEquals(1, $reclamation->getStatus());
|
|
$this->assertNotEmpty($reclamation->getDateAccepted());
|
|
$this->assertEmpty($reclamation->getDateHandle());
|
|
|
|
$this->reclamations->changeStatus(100, 2);
|
|
|
|
$reclamation = $this->reclamations->getReclamation(100);
|
|
$this->assertEquals(2, $reclamation->getStatus());
|
|
$this->assertNotEmpty($reclamation->getDateAccepted());
|
|
$this->assertNotEmpty($reclamation->getDateHandle());
|
|
$this->assertTrue($reclamation->isClosed());
|
|
}
|
|
|
|
protected function getDataSet()
|
|
{
|
|
return $this->getJsonDataSetFromFile();
|
|
}
|
|
}
|