Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TASK] Add acceptance and functional tests #93

Merged
merged 1 commit into from
Sep 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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

Expand Down
2 changes: 2 additions & 0 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
14 changes: 14 additions & 0 deletions Build/FunctionalTests.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" backupGlobals="true" bootstrap="../vendor/typo3/testing-framework/Resources/Core/Build/FunctionalTestsBootstrap.php" colors="true" stopOnError="false" stopOnFailure="false" stopOnIncomplete="false" stopOnSkipped="false" beStrictAboutTestsThatDoNotTestAnything="false" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.1/phpunit.xsd" cacheDirectory=".phpunit.cache" requireCoverageMetadata="false">
<coverage/>
<testsuites>
<testsuite name="Cart Events Extension">
<directory>../Tests/Functional/</directory>
</testsuite>
</testsuites>
<source>
<include>
<directory suffix=".php">../Classes/</directory>
</include>
</source>
</phpunit>
2 changes: 1 addition & 1 deletion Classes/Controller/EventController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
8 changes: 4 additions & 4 deletions Classes/Domain/Model/Category.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion Classes/Domain/Model/EventDate.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = '';
Expand Down
2 changes: 1 addition & 1 deletion Classes/Domain/Model/PriceCategory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = '';
Expand Down
2 changes: 1 addition & 1 deletion Classes/Domain/Model/SpecialPrice.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
4 changes: 2 additions & 2 deletions Classes/Domain/Repository/EventRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand All @@ -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);

Expand Down
18 changes: 9 additions & 9 deletions Configuration/TCA/Overrides/pages.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
81 changes: 75 additions & 6 deletions Tests/Acceptance/EventListCest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)');
}
}
38 changes: 34 additions & 4 deletions Tests/Fixtures/EventsDatabase.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
'sku' => 'eventdate-2',
'title' => 'Eventdate 2',
'begin' => '1722420000',
'end' => '1722427200',
'location' => '',
'lecturer' => '',
'note' => '',
Expand All @@ -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',
Expand Down
46 changes: 46 additions & 0 deletions Tests/Functional/Domain/Repository/EventDateRepositoryTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

declare(strict_types=1);

namespace Extcode\CartEvents\Tests\Functional\Domain\Repository;

/*
* This file is part of the package extcode/cart-events.
*
* For the full copyright and license information, please read the
* LICENSE file that was distributed with this source code.
*/

use Codappix\Typo3PhpDatasets\TestingFramework;
use Extcode\CartEvents\Domain\Repository\EventRepository;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\Test;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;

#[CoversClass(EventRepository::class)]
class EventDateRepositoryTest extends FunctionalTestCase
{
use TestingFramework;

private EventRepository $eventRepository;

public function setUp(): void
{
$this->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();
}
}
Loading
Loading