Files
kupshop/bundles/KupShop/KupShopBundle/Tests/DateUtilTest.php
2025-08-02 16:30:27 +02:00

71 lines
2.9 KiB
PHP

<?php
namespace KupShop\KupShopBundle\Tests;
use KupShop\KupShopBundle\Util\DateUtil;
class DateUtilTest extends \PHPUnit\Framework\TestCase
{
protected $opening_hours;
protected function setUp(): void
{
$this->opening_hours = [
// [od, do, přestávka_od, přestávka_do]
[null, null, null, null], // Pondělí (není otevřeno)
['09:00', '17:00', null, null], // Úterý (otevřeno od 09:00 do 17:00)
['09:00', '17:00', '12:00', '13:00'], // Středa (otevřeno od 09:00 do 17:00 s přestávkou od 12:00 do 13:00)
];
}
public function testIsOpen()
{
$opening_hours = $this->opening_hours;
// Test pro pondělí (není otevřeno)
$result = DateUtil::isOpen($opening_hours, 0);
$this->assertFalse($result['is_open']);
// Test pro úterý (otevřeno od 09:00 do 17:00)
$result = DateUtil::isOpen($opening_hours, 1, '10:00');
$this->assertTrue($result['is_open']);
$result = DateUtil::isOpen($opening_hours, 1, '20:00');
$this->assertFalse($result['is_open']);
// Test pro středu (otevřeno od 09:00 do 12:00, přestávka od 12:00 do 13:00, a poté opět otevřeno od 13:00 do 17:00)
$result = DateUtil::isOpen($opening_hours, 2, '12:30');
$this->assertFalse($result['is_open']);
$result = DateUtil::isOpen($opening_hours, 2, '12:30');
$this->assertFalse($result['is_open']);
}
public function testIsOpenToday()
{
$opening_hours = $this->opening_hours;
// Test pro pondělí (není otevřeno)
$result = DateUtil::isOpen($opening_hours, 0);
$this->assertFalse($result['is_open_today']);
// Test pro úterý (otevřeno od 09:00 do 17:00)
$result = DateUtil::isOpen($opening_hours, 1, '10:00');
$this->assertEquals('09:00', $result['is_open_today']['from']);
$this->assertEquals('17:00', $result['is_open_today']['to']);
$this->assertFalse($result['is_open_today']['break_from']);
$this->assertFalse($result['is_open_today']['break_to']);
// Test pro středu (otevřeno od 09:00 do 12:00, přestávka od 12:00 do 13:00, a poté opět otevřeno od 13:00 do 17:00)
$result = DateUtil::isOpen($opening_hours, 2, '10:00');
$this->assertEquals('09:00', $result['is_open_today']['from']);
$this->assertEquals('17:00', $result['is_open_today']['to']);
$this->assertEquals('12:00', $result['is_open_today']['break_from']);
$this->assertEquals('13:00', $result['is_open_today']['break_to']);
$result = DateUtil::isOpen($opening_hours, 2, '12:30');
$this->assertEquals('09:00', $result['is_open_today']['from']);
$this->assertEquals('17:00', $result['is_open_today']['to']);
$this->assertEquals('12:00', $result['is_open_today']['break_from']);
$this->assertEquals('13:00', $result['is_open_today']['break_to']);
}
}