Skip to content

Commit

Permalink
Merge pull request EC-CUBE#5286 from chihiro-adachi/fix-calender
Browse files Browse the repository at this point in the history
カレンダーの翌月判定の誤りを修正
  • Loading branch information
matsuoshi authored Feb 3, 2022
2 parents 31fb2bb + f2512c3 commit 1256f5b
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 10 deletions.
8 changes: 4 additions & 4 deletions codeception/acceptance/EA07BasicinfoCest.php
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ public function basicinfo_定休日カレンダー_表示(AcceptanceTester $I)
// 定休日を設定
$holidays = [
'定休日1' => Carbon::now()->day(1), // 今月1日
'定休日2' => Carbon::now()->addMonth(1)->day(28), // 翌月28日
'定休日2' => Carbon::now()->startOfMonth()->addMonth(1)->day(28), // 翌月28日
];

foreach ($holidays as $title => $date) {
Expand All @@ -426,11 +426,11 @@ public function basicinfo_定休日カレンダー_表示(AcceptanceTester $I)
$I->see('カレンダー', ['class' => 'ec-layoutRole__mainBottom']);

// フロント画面で定休日にクラス .ec-calendar__holiday が設定されていることを確認
$I->seeElement(['xpath' => '//table[@id="this-month-table"]//td[@class="ec-calendar__holiday"][text()="'.$holidays['定休日1']->format('j').'"]']);
$I->seeElement(['xpath' => '//table[@id="next-month-table"]//td[@class="ec-calendar__holiday"][text()="'.$holidays['定休日2']->format('j').'"]']);
$I->seeElement(['xpath' => '//table[@id="this-month-table"]//td[contains(@class,"ec-calendar__holiday")][text()="'.$holidays['定休日1']->format('j').'"]']);
$I->seeElement(['xpath' => '//table[@id="next-month-table"]//td[contains(@class,"ec-calendar__holiday")][text()="'.$holidays['定休日2']->format('j').'"]']);

// 今日の日付にクラス .ec-calendar__today が設定されていることを確認
$I->seeElement(['xpath' => '//table[@id="this-month-table"]//td[@class="ec-calendar__today"][text()="'.Carbon::now()->format('j').'"]']);
$I->seeElement(['xpath' => '//table[@id="this-month-table"]//td[contains(@class,"ec-calendar__today")][text()="'.Carbon::now()->format('j').'"]']);
}

/**
Expand Down
6 changes: 3 additions & 3 deletions src/Eccube/Controller/Block/CalendarController.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ public function index(Request $request)
{
$today = Carbon::now();
$firstDateOfThisMonth = $today->copy()->startOfMonth();
$firstDateOfNextMonth = $today->copy()->addMonth(1)->startOfMonth();
$endDateOfNextMonth = $today->copy()->addMonth(1)->endOfMonth();
$firstDateOfNextMonth = $today->copy()->startOfMonth()->addMonth(1)->startOfMonth();
$endDateOfNextMonth = $today->copy()->startOfMonth()->addMonth(1)->endOfMonth();

// 2ヶ月間の定休日を取得
$HolidaysOfTwoMonths = $this->calendarRepository->getHolidayList($firstDateOfThisMonth, $endDateOfNextMonth);
Expand All @@ -65,7 +65,7 @@ public function index(Request $request)
$thisMonthCalendar = $this->setHolidayAndTodayFlag($thisMonthCalendar, $holidayListOfTwoMonths, $today->copy());

// 来月のカレンダー配列に定休日フラグを設定
$nextMonthCalendar = $this->setHolidayAndTodayFlag($nextMonthCalendar, $holidayListOfTwoMonths, $today->copy()->addMonth(1));
$nextMonthCalendar = $this->setHolidayAndTodayFlag($nextMonthCalendar, $holidayListOfTwoMonths, $today->copy()->startOfMonth()->addMonth(1));

// 各カレンダータイトルを作成
$monthFormat = $this->translator->trans('front.block.calendar.month_format');
Expand Down
5 changes: 2 additions & 3 deletions tests/Eccube/Tests/Web/Block/CalendarControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@ public function testRoutingCalendar()
public function testThisMonthTitle()
{
$crawler = $this->client->request('GET', $this->generateUrl('block_calendar'));
$this->expected = Carbon::now()->format('Y年n月');
$this->expected = Carbon::now()->startOfMonth()->format('Y年n月');
$this->actual = $crawler->filter('#this-month-title')->text();
$this->verify();
}

public function testNextMonthTitle()
{
$crawler = $this->client->request('GET', $this->generateUrl('block_calendar'));
$this->expected = Carbon::now()->addMonth(1)->format('Y年n月');
$this->expected = Carbon::now()->startOfMonth()->addMonth(1)->format('Y年n月');
$this->actual = $crawler->filter('#next-month-title')->text();
$this->verify();
}
Expand All @@ -48,7 +48,6 @@ public function testTodayAndHolidayStyle()
->setHoliday(new \DateTime(Carbon::now()->format('Y-m-d')));
$this->entityManager->persist($Calendar);
$this->entityManager->flush();
dump($Calendar);

$crawler = $this->client->request('GET', $this->generateUrl('block_calendar'));
$this->expected = Carbon::now()->format('j');
Expand Down

0 comments on commit 1256f5b

Please sign in to comment.