diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 7fc4df2..370ad2a 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -76,6 +76,9 @@ jobs: run: |- composer require --no-interaction --prefer-dist --no-progress "typo3/cms-core:${{ matrix.typo3-version }}" "typo3/cms-extbase:${{ matrix.typo3-version }}" "typo3/cms-frontend:${{ matrix.typo3-version }}" + - name: Build codeception tester + run: vendor/bin/codecept build + - name: Code Quality (by PHPStan) run: vendor/bin/phpstan analyse -c Build/phpstan.neon @@ -100,6 +103,15 @@ jobs: - name: Run Unit Tests PHP8.3 run: nix-shell --arg phpVersion \"php83\" --pure --run project-test-unit + - name: Run Functional Tests PHP8.1 + run: nix-shell --arg phpVersion \"php81\" --pure --run project-test-functional + + - name: Run Functional Tests PHP8.2 + run: nix-shell --arg phpVersion \"php82\" --pure --run project-test-functional + + - name: Run Functional Tests PHP8.3 + run: nix-shell --arg phpVersion \"php83\" --pure --run project-test-functional + - name: Run Acceptance Tests PHP8.1 run: nix-shell --arg phpVersion \"php81\" --pure --run project-test-acceptance diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index ca69da6..9b7ca8e 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -86,6 +86,7 @@ phpstan:analyse: - composer config platform.php 8.1 - composer install --no-progress --no-ansi --no-interaction script: + - vendor/bin/codecept build - vendor/bin/phpstan analyse -c Build/phpstan.neon --memory-limit 256M .test_php: &test_php @@ -108,6 +109,7 @@ phpstan:analyse: if [[ "$COVERAGE" == "1" ]]; then XDEBUG_MODE=coverage TYPO3_PATH_WEB=${TYPO3_PATH_WEB} vendor/bin/phpunit --coverage-clover=phpunit.coverage.xml --log-junit=phpunit.report.xml -c Build/UnitTests.xml Tests/Unit fi + - typo3DatabaseDriver=pdo_sqlite vendor/bin/phpunit -c Build/FunctionalTests.xml artifacts: paths: - phpunit.coverage.xml diff --git a/Build/FunctionalTests.xml b/Build/FunctionalTests.xml new file mode 100644 index 0000000..48bfce6 --- /dev/null +++ b/Build/FunctionalTests.xml @@ -0,0 +1,14 @@ + + + + + + ../Tests/Functional/ + + + + + ../Classes/ + + + diff --git a/Classes/Controller/EventController.php b/Classes/Controller/EventController.php index 733c5db..920b2fa 100644 --- a/Classes/Controller/EventController.php +++ b/Classes/Controller/EventController.php @@ -84,7 +84,7 @@ public function teaserAction(): ResponseInterface 'CartEvents' )['view']['list']['limit']; - $events = $this->eventRepository->findByUids($limit, $this->settings['eventUids']); + $events = $this->eventRepository->findByUids($this->settings['eventUids'], $limit); $this->view->assign('events', $events); $this->view->assign('cartSettings', $this->cartConfiguration); diff --git a/Classes/Domain/Model/Category.php b/Classes/Domain/Model/Category.php index d7b2360..e0b2e08 100644 --- a/Classes/Domain/Model/Category.php +++ b/Classes/Domain/Model/Category.php @@ -13,16 +13,16 @@ class Category extends \TYPO3\CMS\Extbase\Domain\Model\Category { - protected int $cartEventListPid; + protected ?int $cartEventListPid = null; - protected int $cartEventShowPid; + protected ?int $cartEventShowPid = null; - public function getCartEventListPid(): int + public function getCartEventListPid(): ?int { return $this->cartEventListPid; } - public function getcartEventShowPid(): int + public function getCartEventShowPid(): ?int { return $this->cartEventShowPid; } diff --git a/Classes/Domain/Model/EventDate.php b/Classes/Domain/Model/EventDate.php index 31fe359..5bcacc1 100644 --- a/Classes/Domain/Model/EventDate.php +++ b/Classes/Domain/Model/EventDate.php @@ -20,7 +20,7 @@ class EventDate extends AbstractEventDate protected Event $event; #[Validate(['validator' => 'NotEmpty'])] - protected string $sku; + protected string $sku = ''; #[Validate(['validator' => 'NotEmpty'])] protected string $title = ''; diff --git a/Classes/Domain/Model/PriceCategory.php b/Classes/Domain/Model/PriceCategory.php index 3417a9e..11bdcdb 100644 --- a/Classes/Domain/Model/PriceCategory.php +++ b/Classes/Domain/Model/PriceCategory.php @@ -20,7 +20,7 @@ class PriceCategory extends AbstractEntity protected EventDate $eventDate; #[Validate(['validator' => 'NotEmpty'])] - protected string $sku; + protected string $sku = ''; #[Validate(['validator' => 'NotEmpty'])] protected string $title = ''; diff --git a/Classes/Domain/Model/SpecialPrice.php b/Classes/Domain/Model/SpecialPrice.php index f0f16fd..2a68fa8 100644 --- a/Classes/Domain/Model/SpecialPrice.php +++ b/Classes/Domain/Model/SpecialPrice.php @@ -23,7 +23,7 @@ class SpecialPrice extends AbstractEntity #[Validate(['validator' => 'NotEmpty'])] protected float $price = 0.0; - protected FrontendUserGroup $frontendUserGroup; + protected ?FrontendUserGroup $frontendUserGroup = null; public function getTitle(): string { diff --git a/Classes/Domain/Repository/EventRepository.php b/Classes/Domain/Repository/EventRepository.php index 9a092cc..c47ad61 100644 --- a/Classes/Domain/Repository/EventRepository.php +++ b/Classes/Domain/Repository/EventRepository.php @@ -38,7 +38,7 @@ public function findDemanded(EventDemand $demand): QueryResultInterface $categoryConstraints[] = $query->equals('category', $category); $categoryConstraints[] = $query->contains('categories', $category); } - $constraints = $query->logicalOr(...array_values($categoryConstraints)); + $constraints[] = $query->logicalOr(...array_values($categoryConstraints)); } if (!empty($constraints)) { @@ -61,7 +61,7 @@ public function findDemanded(EventDemand $demand): QueryResultInterface /** * Find all events based on selected uids */ - public function findByUids(int $limit, string $uids): array + public function findByUids(string $uids, ?int $limit = null): array { $uids = explode(',', $uids); diff --git a/Configuration/TCA/Overrides/pages.php b/Configuration/TCA/Overrides/pages.php index a147b73..17c5a69 100644 --- a/Configuration/TCA/Overrides/pages.php +++ b/Configuration/TCA/Overrides/pages.php @@ -8,19 +8,19 @@ $_LLL_be = 'LLL:EXT:cart_events/Resources/Private/Language/locallang_be.xlf'; $GLOBALS['TCA']['pages']['columns']['doktype']['config']['items'][] = [ - $_LLL_be . ':pages.doktype.185', - 185, - 'apps-pagetree-page-cartevents-events', + 'label' => $_LLL_be . ':pages.doktype.185', + 'value' => 185, + 'icon' => 'apps-pagetree-page-cartevents-events', ]; $GLOBALS['TCA']['pages']['columns']['doktype']['config']['items'][] = [ - $_LLL_be . ':pages.doktype.186', - 186, - 'apps-pagetree-page-cartevents-events', + 'label' => $_LLL_be . ':pages.doktype.186', + 'value' => 186, + 'icon' => 'apps-pagetree-page-cartevents-events', ]; $GLOBALS['TCA']['pages']['columns']['module']['config']['items'][] = [ - $_LLL_be . ':tcarecords-pages-contains.cart_events', - 'cartevents', - 'apps-pagetree-folder-cartevents-events', + 'label' => $_LLL_be . ':tcarecords-pages-contains.cart_events', + 'value' => 'cartevents', + 'icon' => 'apps-pagetree-folder-cartevents-events', ]; $GLOBALS['TCA']['pages']['ctrl']['typeicon_classes'][185] = 'apps-pagetree-page-cartevents-events'; diff --git a/Tests/Acceptance/EventListCest.php b/Tests/Acceptance/EventListCest.php index 5c53fcf..9fd7ea4 100644 --- a/Tests/Acceptance/EventListCest.php +++ b/Tests/Acceptance/EventListCest.php @@ -12,39 +12,108 @@ */ use Extcode\CartEvents\Tests\Acceptance\Support\Tester; +use PHPUnit\Framework\Attributes\Test; class EventListCest { - public function testListAndDetailViewForNonBookableEvent(Tester $I): void + #[Test] + public function listForEvents(Tester $I): void { $I->amOnUrl('http://127.0.0.1:8080/events/'); $I->see('Event 1'); $I->see('Teaser 1'); + $I->see('Event 2'); + $I->see('Teaser 2'); + $I->see('Event 3'); + $I->see('Teaser 3'); $I->dontSee('Event 4'); + } + + #[Test] + public function detailViewForNonBookableEvent(Tester $I): void + { + $I->amOnUrl('http://127.0.0.1:8080/events/'); + $I->see('Event 1'); $I->click('Event 1'); + $I->see('Event 1', 'h1'); $I->see('31.07.2024 10:00'); $I->see('This event date can not be booked.'); } - public function testListAndDetailViewForBookableEventWithoutPriceCategories(Tester $I): void + #[Test] + public function detailViewForBookableEventWithOneEventdateWithoutPriceCategories(Tester $I): void { $I->amOnUrl('http://127.0.0.1:8080/events/'); $I->see('Event 2'); - $I->see('Teaser 2'); + $I->click('Event 2'); - $I->dontSee('Event 4'); + $I->see('Event 2', 'h1'); + $I->see('Eventdate 2', 'h2'); + $I->see('31.07.2024 10:00 - 31.07.2024 12:00'); + $I->see('19,99 €'); + $I->dontSee('This event date can not be booked.'); + $I->seeElement("input[name='tx_cart_cart[quantity]']"); + $I->seeElement('input[type="submit"]'); + } + + #[Test] + public function detailViewForBookableEventWithTwoOrMoreEventdatesWithoutPriceCategories(Tester $I): void + { + $I->amOnUrl('http://127.0.0.1:8080/events/'); + + $I->see('Event 3'); + $I->click('Event 3'); + + $I->see('Event 3', 'h1'); + $I->see('Eventdate 3.1', 'h2'); + $I->see('31.07.2024 10:00 - 31.07.2024 12:00'); + $I->see('29,99 €'); + + $I->see('Eventdate 3.2', 'h2'); + $I->see('15.08.2024 10:00 - 15.08.2024 11:00'); + $I->see('32,99 €'); + + $I->see('Eventdate 3.3', 'h2'); + $I->see('16.08.2024 12:00 - 16.08.2024 13:30'); + $I->see('34,99 €'); + + $I->dontSee('This event date can not be booked.'); + } + + #[Test] + public function addBookableEventToCart(Tester $I): void + { + $I->amOnUrl('http://127.0.0.1:8080/cart/'); + $I->dontSee('Event 2'); + + $I->amOnUrl('http://127.0.0.1:8080/events/'); + + $I->see('Event 2'); $I->click('Event 2'); - $I->see('Event 2', 'h1'); - $I->see('31.07.2024 10:00'); + $I->see('19,99 €'); $I->dontSee('This event date can not be booked.'); $I->seeElement("input[name='tx_cart_cart[quantity]']"); + $I->seeInField("input[name='tx_cart_cart[quantity]']", '1'); $I->seeElement('input[type="submit"]'); + $I->click('input[type="submit"]'); + $I->see('Item was added to cart.'); + + $I->fillField("input[name='tx_cart_cart[quantity]']", '2'); + $I->click('input[type="submit"]'); + $I->see('2 Items were added to cart.'); + + $I->amOnUrl('http://127.0.0.1:8080/cart/'); + $I->see('Event 2'); + $I->see('19,99 €', '.checkout-product-table tr:nth-child(1) td:nth-child(2)'); + $I->seeElement("input[name='tx_cart_cart[quantities][CartEvents_2]']"); + $I->seeInField("input[name='tx_cart_cart[quantities][CartEvents_2]']", '3'); + $I->see('71,36 €', '.checkout-product-table tr:nth-child(1) td:nth-child(4)'); } } diff --git a/Tests/Fixtures/EventsDatabase.php b/Tests/Fixtures/EventsDatabase.php index cc91766..4c8ec5e 100644 --- a/Tests/Fixtures/EventsDatabase.php +++ b/Tests/Fixtures/EventsDatabase.php @@ -70,6 +70,7 @@ 'sku' => 'eventdate-2', 'title' => 'Eventdate 2', 'begin' => '1722420000', + 'end' => '1722427200', 'location' => '', 'lecturer' => '', 'note' => '', @@ -80,17 +81,46 @@ 'uid' => '3', 'pid' => '7', 'event' => '3', - 'sku' => 'eventdate-3', - 'title' => 'Eventdate 3', + 'sku' => 'eventdate-3-1', + 'title' => 'Eventdate 3.1', 'begin' => '1722420000', - 'location' => '', - 'lecturer' => '', + 'end' => '1722427200', + 'location' => 'Berlin', + 'lecturer' => 'Max Mustermann', 'note' => '', 'price' => 29.99, 'bookable' => true, ], 3 => [ 'uid' => '4', + 'pid' => '7', + 'event' => '3', + 'sku' => 'eventdate-3-2', + 'title' => 'Eventdate 3.2', + 'begin' => '1723716000', + 'end' => '1723719600', + 'location' => 'Hamburg', + 'lecturer' => 'Erika Musterfrau', + 'note' => '', + 'price' => 32.99, + 'bookable' => true, + ], + 4 => [ + 'uid' => '5', + 'pid' => '7', + 'event' => '3', + 'sku' => 'eventdate-3-3', + 'title' => 'Eventdate 3.3', + 'begin' => '1723809600', + 'end' => '1723815000', + 'location' => 'München', + 'lecturer' => 'Erika Musterfrau', + 'note' => '', + 'price' => 34.99, + 'bookable' => true, + ], + 5 => [ + 'uid' => '6', 'pid' => '9', 'event' => '4', 'sku' => 'eventdate-4', diff --git a/Tests/Functional/Domain/Repository/EventDateRepositoryTest.php b/Tests/Functional/Domain/Repository/EventDateRepositoryTest.php new file mode 100644 index 0000000..ff4e205 --- /dev/null +++ b/Tests/Functional/Domain/Repository/EventDateRepositoryTest.php @@ -0,0 +1,46 @@ +testExtensionsToLoad[] = 'extcode/cart'; + $this->testExtensionsToLoad[] = 'extcode/cart-events'; + + parent::setUp(); + + $this->eventRepository = GeneralUtility::makeInstance(EventRepository::class); + + $this->importPHPDataSet(__DIR__ . '/../../../Fixtures/PagesDatabase.php'); + $this->importPHPDataSet(__DIR__ . '/../../../Fixtures/EventsDatabase.php'); + } + + #[Test] + public function findNextReturnsNext() + { + self::markTestSkipped(); + } +} diff --git a/Tests/Functional/Domain/Repository/EventRepositoryTest.php b/Tests/Functional/Domain/Repository/EventRepositoryTest.php new file mode 100644 index 0000000..fbfc055 --- /dev/null +++ b/Tests/Functional/Domain/Repository/EventRepositoryTest.php @@ -0,0 +1,143 @@ +testExtensionsToLoad[] = 'extcode/cart'; + $this->testExtensionsToLoad[] = 'extcode/cart-events'; + + parent::setUp(); + + $this->eventRepository = GeneralUtility::makeInstance(EventRepository::class); + + $this->importPHPDataSet(__DIR__ . '/../../../Fixtures/PagesDatabase.php'); + $this->importPHPDataSet(__DIR__ . '/../../../Fixtures/EventsDatabase.php'); + } + + #[Test] + public function findByUidsWithoutLimit() + { + $uids = '1,2,3,4'; + $events = $this->eventRepository->findByUids($uids); + + self::assertCount( + 4, + $events + ); + } + + #[Test] + public function findByUidsWithLimit() + { + $uids = '1,2,3,4'; + $events = $this->eventRepository->findByUids($uids, 2); + + self::assertCount( + 2, + $events + ); + } + + #[Test] + public function findDemandedByNewEventDemand() + { + $eventDemand = new EventDemand(); + + $querySettings = GeneralUtility::makeInstance(QuerySettingsInterface::class); + $querySettings->setStoragePageIds([7]); + $this->eventRepository->setDefaultQuerySettings($querySettings); + $events = $this->eventRepository->findDemanded($eventDemand); + + self::assertCount( + 3, + $events + ); + } + + #[Test] + public function findDemandedByNewEventDemandWithLimit() + { + $eventDemand = new EventDemand(); + $eventDemand->setLimit(2); + + $querySettings = GeneralUtility::makeInstance(QuerySettingsInterface::class); + $querySettings->setStoragePageIds([7]); + $this->eventRepository->setDefaultQuerySettings($querySettings); + $events = $this->eventRepository->findDemanded($eventDemand); + + self::assertCount( + 2, + $events + ); + } + + #[Test] + public function findDemandedWithGivenSkuReturnsEvents(): void + { + $eventDemand = new EventDemand(); + $eventDemand->setSku('event-1'); + + $querySettings = GeneralUtility::makeInstance(QuerySettingsInterface::class); + $querySettings->setStoragePageIds([7]); + $this->eventRepository->setDefaultQuerySettings($querySettings); + $events = $this->eventRepository->findDemanded($eventDemand); + + self::assertCount( + 1, + $events + ); + + self::assertSame( + 1, + $events->getFirst()->getUid() + ); + } + + #[Test] + public function findDemandedWithGivenTitleReturnsEvents(): void + { + $eventDemand = new EventDemand(); + $eventDemand->setTitle('Event 3'); + + $querySettings = GeneralUtility::makeInstance(QuerySettingsInterface::class); + $querySettings->setStoragePageIds([7]); + $this->eventRepository->setDefaultQuerySettings($querySettings); + $events = $this->eventRepository->findDemanded($eventDemand); + + self::assertCount( + 1, + $events + ); + + self::assertSame( + 3, + $events->getFirst()->getUid() + ); + } +} diff --git a/Tests/Unit/Domain/Model/AbstractEventDateTest.php b/Tests/Unit/Domain/Model/AbstractEventDateTest.php new file mode 100644 index 0000000..caa3162 --- /dev/null +++ b/Tests/Unit/Domain/Model/AbstractEventDateTest.php @@ -0,0 +1,99 @@ +eventDate = new class extends AbstractEventDate {}; + } + + protected function tearDown(): void + { + unset($this->eventDate); + } + + #[Test] + public function getBeginReturnsInitialValueNull(): void + { + self::assertNull( + $this->eventDate->getBegin() + ); + } + + #[Test] + public function setBeginSetsBegin(): void + { + $dateString = '2024-09-01 15:43:38'; + $format = 'Y-m-d H:i:s'; + $dateTime = DateTime::createFromFormat($format, $dateString); + + $this->eventDate->setBegin($dateTime); + + self::assertSame( + $dateTime, + $this->eventDate->getBegin() + ); + } + + #[Test] + public function getEndReturnsInitialValueNull(): void + { + self::assertNull( + $this->eventDate->getEnd() + ); + } + + #[Test] + public function setEndSetsEnd(): void + { + $dateString = '2024-09-01 20:01:01'; + $format = 'Y-m-d H:i:s'; + $dateTime = DateTime::createFromFormat($format, $dateString); + $this->eventDate->setEnd($dateTime); + + self::assertSame( + $dateTime, + $this->eventDate->getEnd() + ); + } + + #[Test] + public function getNoteReturnsInitialValueForNote(): void + { + self::assertSame( + '', + $this->eventDate->getNote() + ); + } + + #[Test] + public function setNoteSetsNote(): void + { + $this->eventDate->setNote('Note'); + + self::assertSame( + 'Note', + $this->eventDate->getNote() + ); + } +} diff --git a/Tests/Unit/Domain/Model/CalenderEntryTest.php b/Tests/Unit/Domain/Model/CalenderEntryTest.php new file mode 100644 index 0000000..b52b560 --- /dev/null +++ b/Tests/Unit/Domain/Model/CalenderEntryTest.php @@ -0,0 +1,40 @@ +calendarEntry = new CalendarEntry(); + } + + protected function tearDown(): void + { + unset($this->calendarEntry); + } + + #[Test] + public function calendarEntryExtendsAbstractEventDate() + { + self::assertInstanceOf(AbstractEventDate::class, $this->calendarEntry); + } +} diff --git a/Tests/Unit/Domain/Model/CategoryTest.php b/Tests/Unit/Domain/Model/CategoryTest.php new file mode 100644 index 0000000..a778330 --- /dev/null +++ b/Tests/Unit/Domain/Model/CategoryTest.php @@ -0,0 +1,55 @@ +category = new Category(); + } + + protected function tearDown(): void + { + unset($this->category); + } + + #[Test] + public function categoryExtendsExtbaseCategoryModel() + { + self::assertInstanceOf(\TYPO3\CMS\Extbase\Domain\Model\Category::class, $this->category); + } + + #[Test] + public function getCartEventListPidReturnsInitialValueNull(): void + { + self::assertNull( + $this->category->getCartEventListPid() + ); + } + + #[Test] + public function getCartEventShowPidReturnsInitialValueNull(): void + { + self::assertNull( + $this->category->getCartEventShowPid() + ); + } +} diff --git a/Tests/Unit/Domain/Model/Dto/EventDemandTest.php b/Tests/Unit/Domain/Model/Dto/EventDemandTest.php new file mode 100644 index 0000000..5ce6b33 --- /dev/null +++ b/Tests/Unit/Domain/Model/Dto/EventDemandTest.php @@ -0,0 +1,170 @@ +eventDemand = new EventDemand(); + } + + protected function tearDown(): void + { + unset($this->eventDemand); + } + + #[Test] + public function getSkuReturnsInitialValueForSku(): void + { + self::assertSame( + '', + $this->eventDemand->getSku() + ); + } + + #[Test] + public function setSkuSetsSku(): void + { + $this->eventDemand->setSku('sku'); + + self::assertSame( + 'sku', + $this->eventDemand->getSku() + ); + } + + #[Test] + public function getTitleReturnsInitialValueForTitle(): void + { + self::assertSame( + '', + $this->eventDemand->getTitle() + ); + } + + #[Test] + public function setTitleSetsTitle(): void + { + $this->eventDemand->setTitle('Title'); + + self::assertSame( + 'Title', + $this->eventDemand->getTitle() + ); + } + + // todo: categories + + #[Test] + public function getOrderReturnsInitialValueForOrder(): void + { + self::assertSame( + '', + $this->eventDemand->getOrder() + ); + } + + #[Test] + public function setOrderSetsOrder(): void + { + $this->eventDemand->setOrder('Order'); + + self::assertSame( + 'Order', + $this->eventDemand->getOrder() + ); + } + + #[Test] + public function getLimitReturnsInitialValueForLimit(): void + { + self::assertSame( + 0, + $this->eventDemand->getLimit() + ); + } + + #[Test] + public function setLimitSetsLimit(): void + { + $this->eventDemand->setLimit(10); + + self::assertSame( + 10, + $this->eventDemand->getLimit() + ); + } + + #[Test] + public function getActionReturnsInitialValueForAction(): void + { + self::assertSame( + '', + $this->eventDemand->getAction() + ); + } + + #[Test] + public function setActionSetsAction(): void + { + $this->eventDemand->setAction('Action'); + + self::assertSame( + 'Action', + $this->eventDemand->getAction() + ); + } + + #[Test] + public function getClassReturnsInitialValueForClass(): void + { + self::assertSame( + '', + $this->eventDemand->getClass() + ); + } + + #[Test] + public function setClassSetsClass(): void + { + $this->eventDemand->setClass('Class'); + + self::assertSame( + 'Class', + $this->eventDemand->getClass() + ); + } + + #[Test] + public function setActionAndClassSetsActionAndClass(): void + { + $this->eventDemand->setActionAndClass('Action', 'Class'); + + self::assertSame( + 'Action', + $this->eventDemand->getAction() + ); + self::assertSame( + 'Class', + $this->eventDemand->getClass() + ); + } +} diff --git a/Tests/Unit/Domain/Model/EventDateTest.php b/Tests/Unit/Domain/Model/EventDateTest.php new file mode 100644 index 0000000..0a11472 --- /dev/null +++ b/Tests/Unit/Domain/Model/EventDateTest.php @@ -0,0 +1,120 @@ +eventDate = new EventDate(); + } + + protected function tearDown(): void + { + unset($this->eventDate); + } + + #[Test] + public function eventDateExtendsAbstractEventDate() + { + self::assertInstanceOf(AbstractEventDate::class, $this->eventDate); + } + + #[Test] + public function getSkuReturnsInitialValueForSku(): void + { + self::assertSame( + '', + $this->eventDate->getSku() + ); + } + + #[Test] + public function setSkuSetsSku(): void + { + $this->eventDate->setSku('sku'); + + self::assertSame( + 'sku', + $this->eventDate->getSku() + ); + } + + #[Test] + public function getTitleReturnsInitialValueForTitle(): void + { + self::assertSame( + '', + $this->eventDate->getTitle() + ); + } + + #[Test] + public function setTitleSetsTitle(): void + { + $this->eventDate->setTitle('Title'); + + self::assertSame( + 'Title', + $this->eventDate->getTitle() + ); + } + + #[Test] + public function getLocationReturnsInitialValueForLocation(): void + { + self::assertSame( + '', + $this->eventDate->getLocation() + ); + } + + #[Test] + public function setLocationSetsLocation(): void + { + $this->eventDate->setLocation('Location'); + + self::assertSame( + 'Location', + $this->eventDate->getLocation() + ); + } + + #[Test] + public function getLecturerReturnsInitialValueForLecturer(): void + { + self::assertSame( + '', + $this->eventDate->getLecturer() + ); + } + + #[Test] + public function setLecturerSetsLecturer(): void + { + $this->eventDate->setLecturer('Lecturer'); + + self::assertSame( + 'Lecturer', + $this->eventDate->getLecturer() + ); + } +} diff --git a/Tests/Unit/Domain/Model/EventTest.php b/Tests/Unit/Domain/Model/EventTest.php index 5384c1f..12792a5 100644 --- a/Tests/Unit/Domain/Model/EventTest.php +++ b/Tests/Unit/Domain/Model/EventTest.php @@ -12,16 +12,14 @@ */ use Extcode\CartEvents\Domain\Model\Event; +use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\Test; use TYPO3\TestingFramework\Core\Unit\UnitTestCase; +#[CoversClass(Event::class)] class EventTest extends UnitTestCase { - /** - * Event - * - * @var Event - */ - protected $event; + protected Event $event; protected function setUp(): void { @@ -33,9 +31,84 @@ protected function tearDown(): void unset($this->event); } - /** - * @test - */ + #[Test] + public function isVirtualProductReturnsInitialValueForVirtualProduct(): void + { + self::assertTrue( + $this->event->isVirtualProduct() + ); + } + + #[Test] + public function setVirtualProductSetsVirtualProduct() + { + $this->event->setVirtualProduct(false); + + self::assertFalse( + $this->event->isVirtualProduct() + ); + } + + #[Test] + public function getFormDefinitionReturnsInitialValueNull(): void + { + self::assertNull( + $this->event->getFormDefinition() + ); + } + + #[Test] + public function setFormDefinitionSetsFormDefinition() + { + $this->event->setFormDefinition('EXT:cart_events/Resources/Private/Forms/test-form.form.yaml'); + + self::assertSame( + 'EXT:cart_events/Resources/Private/Forms/test-form.form.yaml', + $this->event->getFormDefinition() + ); + } + + #[Test] + public function getSkuReturnsInitialValueForSku(): void + { + self::assertSame( + '', + $this->event->getSku() + ); + } + + #[Test] + public function setSkuSetsSku(): void + { + $this->event->setSku('sku'); + + self::assertSame( + 'sku', + $this->event->getSku() + ); + } + + #[Test] + public function getTitleReturnsInitialValueForTitle(): void + { + self::assertSame( + '', + $this->event->getTitle() + ); + } + + #[Test] + public function setTitleSetsTitle(): void + { + $this->event->setTitle('Title'); + + self::assertSame( + 'Title', + $this->event->getTitle() + ); + } + + #[Test] public function getTeaserReturnsInitialValueForTeaser(): void { self::assertSame( @@ -44,16 +117,76 @@ public function getTeaserReturnsInitialValueForTeaser(): void ); } - /** - * @test - */ - public function setTeaserForStringSetsTeaser(): void + #[Test] + public function setTeaserSetsTeaser(): void { - $this->event->setTeaser('Conceived at T3CON10'); + $this->event->setTeaser('Teaser'); self::assertSame( - 'Conceived at T3CON10', + 'Teaser', $this->event->getTeaser() ); } + + #[Test] + public function getDescriptionReturnsInitialValueForDescription(): void + { + self::assertSame( + '', + $this->event->getDescription() + ); + } + + #[Test] + public function setDescriptionSetsDescription(): void + { + $this->event->setDescription('Description'); + + self::assertSame( + 'Description', + $this->event->getDescription() + ); + } + + #[Test] + public function getAudienceReturnsInitialValueForAudience(): void + { + self::assertSame( + '', + $this->event->getAudience() + ); + } + + #[Test] + public function setAudienceSetsAudience(): void + { + $this->event->setAudience('Audience'); + + self::assertSame( + 'Audience', + $this->event->getAudience() + ); + } + + // todo: images, files, eventDates, relatedEvents, taxClassId, + + #[Test] + public function getMetaDescriptionReturnsInitialValueForMetaDescription(): void + { + self::assertSame( + '', + $this->event->getMetaDescription() + ); + } + + #[Test] + public function setMetaDescriptionSetsMetaDescription(): void + { + $this->event->setMetaDescription('MetaDescription'); + + self::assertSame( + 'MetaDescription', + $this->event->getMetaDescription() + ); + } } diff --git a/Tests/Unit/Domain/Model/PriceCategoryTest.php b/Tests/Unit/Domain/Model/PriceCategoryTest.php new file mode 100644 index 0000000..0e131b4 --- /dev/null +++ b/Tests/Unit/Domain/Model/PriceCategoryTest.php @@ -0,0 +1,137 @@ +priceCategory = new PriceCategory(); + } + + protected function tearDown(): void + { + unset($this->priceCategory); + } + + #[Test] + public function getSkuReturnsInitialValueForSku(): void + { + self::assertSame( + '', + $this->priceCategory->getSku() + ); + } + + #[Test] + public function setSkuSetsSku(): void + { + $this->priceCategory->setSku('sku'); + + self::assertSame( + 'sku', + $this->priceCategory->getSku() + ); + } + + #[Test] + public function getTitleReturnsInitialValueForTitle(): void + { + self::assertSame( + '', + $this->priceCategory->getTitle() + ); + } + + #[Test] + public function setTitleSetsTitle(): void + { + $this->priceCategory->setTitle('Title'); + + self::assertSame( + 'Title', + $this->priceCategory->getTitle() + ); + } + + #[Test] + public function getPriceReturnsInitialValueForPrice(): void + { + self::assertSame( + 0.0, + $this->priceCategory->getPrice() + ); + } + + #[Test] + public function setPriceSetsPrice(): void + { + $this->priceCategory->setPrice(19.99); + + self::assertSame( + 19.99, + $this->priceCategory->getPrice() + ); + } + + // todo: specialPrice + + #[Test] + public function getSeatsNumberReturnsInitialValueForSeatsNumber(): void + { + self::assertSame( + 0, + $this->priceCategory->getSeatsNumber() + ); + } + + #[Test] + public function setSeatsNumberSetsSeatsNumber(): void + { + $this->priceCategory->setSeatsNumber(42); + + self::assertSame( + 42, + $this->priceCategory->getSeatsNumber() + ); + } + + #[Test] + public function getSeatsTakenReturnsInitialValueForSeatsTaken(): void + { + self::assertSame( + 0, + $this->priceCategory->getSeatsTaken() + ); + } + + #[Test] + public function setSeatsTakenSetsSeatsTaken(): void + { + $this->priceCategory->setSeatsTaken(42); + + self::assertSame( + 42, + $this->priceCategory->getSeatsTaken() + ); + } + + // todo getSeatsAvailable, specialPrice, isAvailable, isBookable +} diff --git a/Tests/Unit/Domain/Model/SpecialPriceTest.php b/Tests/Unit/Domain/Model/SpecialPriceTest.php new file mode 100644 index 0000000..04e4285 --- /dev/null +++ b/Tests/Unit/Domain/Model/SpecialPriceTest.php @@ -0,0 +1,96 @@ +specialPrice = new SpecialPrice(); + } + + protected function tearDown(): void + { + unset($this->specialPrice); + } + + #[Test] + public function getTitleReturnsInitialValueForTitle(): void + { + self::assertSame( + '', + $this->specialPrice->getTitle() + ); + } + + #[Test] + public function setTitleSetsTitle(): void + { + $this->specialPrice->setTitle('Title'); + + self::assertSame( + 'Title', + $this->specialPrice->getTitle() + ); + } + + #[Test] + public function getPriceReturnsInitialValueForPrice(): void + { + self::assertSame( + 0.0, + $this->specialPrice->getPrice() + ); + } + + #[Test] + public function setPriceSetsPrice(): void + { + $this->specialPrice->setPrice(19.99); + + self::assertSame( + 19.99, + $this->specialPrice->getPrice() + ); + } + + #[Test] + public function getFrontendUserGroupReturnsInitialValueNull(): void + { + self::assertNull( + $this->specialPrice->getFrontendUserGroup() + ); + } + + #[Test] + public function setFrontendUserGroupSetsFrontendUserGroup(): void + { + $frontendUserGroup = $this->createStub( + FrontendUserGroup::class + ); + $this->specialPrice->setFrontendUserGroup($frontendUserGroup); + + self::assertSame( + $frontendUserGroup, + $this->specialPrice->getFrontendUserGroup() + ); + } +} diff --git a/composer.json b/composer.json index 0f33a89..fbb562c 100644 --- a/composer.json +++ b/composer.json @@ -81,6 +81,9 @@ "test:php:unit": [ "vendor/bin/phpunit -c Build/UnitTests.xml" ], + "test:php:functional": [ + "typo3DatabaseDriver=\"pdo_sqlite\" vendor/bin/phpunit -c Build/FunctionalTests.xml" + ], "test:phpstan:analyse": [ "vendor/bin/phpstan analyse -c Build/phpstan.neon" ], @@ -95,7 +98,8 @@ ], "test:php": [ "@test:php:lint", - "@test:php:unit" + "@test:php:unit", + "@test:php:functional" ], "test:all": [ "@test:phpstan:analyse", diff --git a/shell.nix b/shell.nix index 3b54c6c..767318a 100644 --- a/shell.nix +++ b/shell.nix @@ -76,6 +76,18 @@ let ''; }; + projectTestFunctional = pkgs.writeShellApplication { + name = "project-test-functional"; + runtimeInputs = [ + php + projectInstall + ]; + text = '' + project-install + ./vendor/bin/phpunit -c Build/FunctionalTests.xml + ''; + }; + projectTestAcceptance = pkgs.writeShellApplication { name = "project-test-acceptance"; runtimeInputs = [ @@ -112,6 +124,7 @@ in pkgs.mkShellNoCC { projectCgl projectCglFix projectTestUnit + projectTestFunctional projectTestAcceptance ];