1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the EasyBanglaDate package. |
5
|
|
|
* |
6
|
|
|
* Copyright (c) 2015 Roni Saha |
7
|
|
|
* |
8
|
|
|
* This source file is subject to the MIT license that is bundled |
9
|
|
|
* with this source code in the file LICENSE. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
|
13
|
|
|
namespace EasyBanglaDateTests\Tools; |
14
|
|
|
|
15
|
|
|
|
16
|
|
|
use EasyBanglaDateTests\Utils\CsvFileIterator; |
17
|
|
|
use EasyBanglaDate\Tools\Converter; |
18
|
|
|
use PHPUnit\Framework\TestCase; |
19
|
|
|
|
20
|
|
|
class ConverterTest extends TestCase |
21
|
|
|
{ |
22
|
|
|
public function flagDataProvider() |
23
|
|
|
{ |
24
|
|
|
return new CsvFileIterator(__DIR__ . '/../Resources/bn_conversion_data.csv'); |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @dataProvider flagDataProvider |
29
|
|
|
* @param $time |
30
|
|
|
* @param $year |
31
|
|
|
* @param $month |
32
|
|
|
* @param $day |
33
|
|
|
*/ |
34
|
|
|
public function testBengaliDateMonthYear($time, $year, $month, $day) |
35
|
|
|
{ |
36
|
|
|
$object = new \DateTime($time, new \DateTimeZone('Asia/Dhaka')); |
37
|
|
|
|
38
|
|
|
$arr = Converter::getBengaliDateMonthYear($object, 6); |
39
|
|
|
|
40
|
|
|
$expected = array('day' => $day, 'month' => $month, 'year' => $year); |
41
|
|
|
|
42
|
|
|
$this->assertEquals($expected, $arr); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
public function testCustomMorningTest() |
46
|
|
|
{ |
47
|
|
|
$object = new \DateTime("2015-01-01 05:00:00", new \DateTimeZone('Asia/Dhaka')); |
48
|
|
|
$this->assertDateConversion($object, 6, "17"); |
49
|
|
|
$this->assertDateConversion($object, 4, "18"); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @dataProvider flagDataProvider |
54
|
|
|
* @param $time |
55
|
|
|
* @param $year |
56
|
|
|
* @param $month |
57
|
|
|
* @param $day |
58
|
|
|
*/ |
59
|
|
|
public function testEnglishTimeFromBanglaDate($time, $year, $month, $day) |
60
|
|
|
{ |
61
|
|
|
$object = new \DateTime($time, new \DateTimeZone('Asia/Dhaka')); |
62
|
|
|
$object->modify('+1 day +2 month +1 year'); |
63
|
|
|
$newObj = Converter::getEnglishTimeFromBanglaDate($object, array('day' => $day, 'month' => $month, 'year' => $year), 6); |
64
|
|
|
|
65
|
|
|
$this->assertEquals($time, $newObj->format('Y-m-d H:i:s'), "$time, $year, $month, $day"); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* @param $object |
70
|
|
|
* @param $morning |
71
|
|
|
* @param $expected |
72
|
|
|
*/ |
73
|
|
|
private function assertDateConversion($object, $morning, $expected) |
74
|
|
|
{ |
75
|
|
|
$arr = Converter::getBengaliDateMonthYear($object, $morning); |
76
|
|
|
$this->assertEquals($expected, $arr['day']); |
77
|
|
|
} |
78
|
|
|
} |
79
|
|
|
|