Skip to content

Commit

Permalink
Merge pull request #89 from extcode/88-add-acceptance-tests
Browse files Browse the repository at this point in the history
[TASK] Add first acceptance test
  • Loading branch information
extcode authored Aug 22, 2024
2 parents 4eacc34 + d1d66ca commit 9e0007e
Show file tree
Hide file tree
Showing 17 changed files with 655 additions and 0 deletions.
9 changes: 9 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -99,3 +99,12 @@ jobs:

- name: Run Unit Tests PHP8.3
run: nix-shell --arg phpVersion \"php83\" --pure --run project-test-unit

- name: Run Acceptance Tests PHP8.1
run: nix-shell --arg phpVersion \"php81\" --pure --run project-test-acceptance

- name: Run Acceptance Tests PHP8.2
run: nix-shell --arg phpVersion \"php82\" --pure --run project-test-acceptance

- name: Run Acceptance Tests PHP8.3
run: nix-shell --arg phpVersion \"php83\" --pure --run project-test-acceptance
52 changes: 52 additions & 0 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,58 @@ test:php83:typo3_12:
TYPO3_VERSION: ^12.4
COVERAGE: 1

.test_codeception: &test_codeception
stage: test
image: $CONTAINER_IMAGE
only:
- branches
before_script:
- sed -i -e "s#ssh://git@code.extco.de:22722#https://gitlab-ci-token:$CI_JOB_TOKEN@code.extco.de#g" composer.json
- composer config --no-plugins allow-plugins.typo3/cms-composer-installers true
- composer config --no-plugins allow-plugins.typo3/class-alias-loader true
- composer require typo3/cms-core="${TYPO3_VERSION}"
script:
- mkdir -p .build/public/typo3temp/var/tests/acceptance-sqlite-dbs
- export typo3DatabaseDriver=pdo_sqlite
- export PROJECT_ROOT="$(pwd)"
- export INSTANCE_PATH="$(pwd)/.build/web/typo3temp/var/tests/acceptance"
- mkdir -p "$INSTANCE_PATH"
- mkdir -p "$PROJECT_ROOT/.build/web/typo3temp/var/tests/acceptance-logs/"
- vendor/bin/codecept run
artifacts:
paths:
- .build
expire_in: 1 day
when: always

# Build in PHP 8.1 and TYPO3 12.4
test:codception:php81:typo3_12:
<<: *test_codeception
variables:
CONTAINER_IMAGE: $CI_REGISTRY/containers/codeception-with-php-8.1:main
TYPO3_VERSION: ^12.4
GECKODRIVER_VERSION: v0.34.0

# Build in PHP 8.2 and TYPO3 12.4
test:codception:php82:typo3_12:
<<: *test_codeception
needs:
- test:codception:php81:typo3_12
variables:
CONTAINER_IMAGE: $CI_REGISTRY/containers/codeception-with-php-8.2:main
TYPO3_VERSION: ^12.4
GECKODRIVER_VERSION: v0.34.0

# Build in PHP 8.3 and TYPO3 12.4
test:codception:php83:typo3_12:
<<: *test_codeception
needs:
- test:codception:php82:typo3_12
variables:
CONTAINER_IMAGE: $CI_REGISTRY/containers/codeception-with-php-8.3:main
TYPO3_VERSION: ^12.4
GECKODRIVER_VERSION: v0.34.0

documentation:
stage: documentation
image:
Expand Down
Empty file added Tests/Acceptance/Data/.gitkeep
Empty file.
50 changes: 50 additions & 0 deletions Tests/Acceptance/EventListCest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php

declare(strict_types=1);

namespace Extcode\CartEvents\Tests\Acceptance;

/*
* 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 Extcode\CartEvents\Tests\Acceptance\Support\Tester;

class EventListCest
{
public function testListAndDetailViewForNonBookableEvent(Tester $I): void
{
$I->amOnUrl('http://127.0.0.1:8080/events/');

$I->see('Event 1');
$I->see('Teaser 1');

$I->dontSee('Event 4');

$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
{
$I->amOnUrl('http://127.0.0.1:8080/events/');

$I->see('Event 2');
$I->see('Teaser 2');

$I->dontSee('Event 4');

$I->click('Event 2');
$I->see('Event 2', 'h1');
$I->see('31.07.2024 10:00');

$I->dontSee('This event date can not be booked.');
$I->seeElement("input[name='tx_cart_cart[quantity]']");
$I->seeElement('input[type="submit"]');
}
}
60 changes: 60 additions & 0 deletions Tests/Acceptance/Support/Environment.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?php

declare(strict_types=1);

namespace Extcode\CartEvents\Tests\Acceptance\Support;

/*
* 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\PhpDataSet;
use Codeception\Event\SuiteEvent;
use TYPO3\TestingFramework\Core\Acceptance\Extension\BackendEnvironment;

final class Environment extends BackendEnvironment
{
protected $localConfig = [
'coreExtensionsToLoad' => [
'typo3/cms-core',
'typo3/cms-backend',
'typo3/cms-extbase',
'typo3/cms-frontend',
'typo3/cms-fluid',
'typo3/cms-fluid-styled-content',
'typo3/cms-install',
],
'testExtensionsToLoad' => [
'extcode/cart',
'extcode/cart-events',
__DIR__ . '/../../Fixtures/cart_events_test',
],
'phpDatabaseFixtures' => [
'typo3conf/ext/cart_events/Tests/Fixtures/BackendUserDatabase.php',
'typo3conf/ext/cart_events/Tests/Fixtures/PagesDatabase.php',
'typo3conf/ext/cart_events/Tests/Fixtures/ContentDatabase.php',
'typo3conf/ext/cart_events/Tests/Fixtures/EventsDatabase.php',
],
'pathsToLinkInTestInstance' => [
'typo3conf/ext/cart_events/Tests/Fixtures/config/sites' => 'typo3conf/sites',
],
'configurationToUseInTestInstance' => [
'SYS' => [
'trustedHostsPattern' => '.*',
],
],
];

public function bootstrapTypo3Environment(SuiteEvent $suiteEvent): void
{
parent::bootstrapTypo3Environment($suiteEvent);

assert(is_array($this->config['phpDatabaseFixtures']));
foreach ($this->config['phpDatabaseFixtures'] as $dataSetFile) {
(new PhpDataSet())->import(include $dataSetFile);
}
}
}
37 changes: 37 additions & 0 deletions Tests/Acceptance/Support/Tester.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

declare(strict_types=1);

namespace Extcode\CartEvents\Tests\Acceptance\Support;

/*
* 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 Codeception\Actor;
use Extcode\CartEvents\Tests\Acceptance\Support\_generated\TesterActions;
use TYPO3\TestingFramework\Core\Acceptance\Step\FrameSteps;

/**
* @method void wantToTest($text)
* @method void wantTo($text)
* @method void execute($callable)
* @method void expectTo($prediction)
* @method void expect($prediction)
* @method void amGoingTo($argumentation)
* @method void am($role)
* @method void lookForwardTo($achieveValue)
* @method void comment($description)
* @method void pause()
*/
class Tester extends Actor
{
use TesterActions;

use FrameSteps;

protected int $retryNum = 2;
}
2 changes: 2 additions & 0 deletions Tests/Acceptance/Support/_generated/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*
!.gitignore
16 changes: 16 additions & 0 deletions Tests/Fixtures/BackendUserDatabase.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

declare(strict_types=1);

return [
'be_users' => [
[
'uid' => '1',
'pid' => '0',
'username' => 'test-admin',
'password' => '$2y$12$ksKbFwhPyf9EWWM52R2e4ubG09tPTK9W6139nxpsgwyUHW17W1nye',
'lang' => 'default',
'admin' => '1',
],
],
];
24 changes: 24 additions & 0 deletions Tests/Fixtures/ContentDatabase.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

declare(strict_types=1);

return [
'tt_content' => [
0 => [
'uid' => '1',
'pid' => '3',
'CType' => 'list',
'list_type' => 'cartevents_events',
'pages' => '7',
'pi_flexform' => '<?xml version="1.0" encoding="utf-8" standalone="yes" ?> <T3FlexForms> <data> <sheet index="sDEF"> <language index="lDEF"> <field index="switchableControllerActions"> <value index="vDEF">Event-&gt;show;Event-&gt;list</value> </field> <field index="settings.templateLayout"> <value index="vDEF">table</value> </field> <field index="settings.orderBy"> <value index="vDEF"></value> </field> <field index="settings.orderDirection"> <value index="vDEF"></value> </field> <field index="settings.showPageUids"> <value index="vDEF"></value> </field> <field index="settings.categoriesList"> <value index="vDEF"></value> </field> <field index="settings.listSubcategories"> <value index="vDEF">0</value> </field> </language> </sheet> </data> </T3FlexForms>',
],
1 => [
'uid' => '2',
'pid' => '11',
'CType' => 'list',
'list_type' => 'cart_cart',
'pages' => '',
'pi_flexform' => '<?xml version="1.0" encoding="utf-8" standalone="yes" ?><T3FlexForms><data><sheet index="sDEF"><language index="lDEF"><field index="settings.seller.emailFromName"></value index="vDEF"></value></field><field index="settings.seller.emailFromAddress"></value index="vDEF"></value></field><field index="settings.seller.emailToAddress"></value index="vDEF"></value></field><field index="settings.seller.emailCcAddress"></value index="vDEF"></value></field><field index="settings.seller.emailBccAddress"></value index="vDEF"></value></field><field index="settings.buyer.emailFromName"></value index="vDEF"></value></field><field index="settings.buyer.emailFromAddress"></value index="vDEF"></value></field><field index="settings.buyer.emailCcAddress"></value index="vDEF"></value></field><field index="settings.buyer.emailBccAddress"></value index="vDEF"></value></field><field index="settings.buyer.emailReplyToAddress"></value index="vDEF"></value></field></language></sheet></data></T3FlexForms>',
],
],
];
106 changes: 106 additions & 0 deletions Tests/Fixtures/EventsDatabase.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
<?php

declare(strict_types=1);

return [
'tx_cartevents_domain_model_event' => [
0 => [
'uid' => '1',
'pid' => '7',
'sku' => 'event-1',
'title' => 'Event 1',
'teaser' => 'Teaser 1',
'description' => '',
'meta_description' => '',
'audience' => '',
'path_segment' => 'event-1',
],
1 => [
'uid' => '2',
'pid' => '7',
'sku' => 'event-2',
'title' => 'Event 2',
'teaser' => 'Teaser 2',
'description' => '',
'meta_description' => '',
'audience' => '',
'path_segment' => 'event-2',
],
2 => [
'uid' => '3',
'pid' => '7',
'sku' => 'event-3',
'title' => 'Event 3',
'teaser' => 'Teaser 3',
'description' => '',
'meta_description' => '',
'audience' => '',
'path_segment' => 'event-3',
],
3 => [
'uid' => '4',
'pid' => '9',
'sku' => 'event-4',
'title' => 'Event 4',
'teaser' => '',
'description' => '',
'meta_description' => '',
'audience' => '',
'path_segment' => 'event-4',
],
],
'tx_cartevents_domain_model_eventdate' => [
0 => [
'uid' => '1',
'pid' => '7',
'event' => '1',
'sku' => 'eventdate-1',
'title' => 'Eventdate 1',
'begin' => '1722420000',
'location' => '',
'lecturer' => '',
'note' => '',
'price' => 9.99,
'bookable' => false,
],
1 => [
'uid' => '2',
'pid' => '7',
'event' => '2',
'sku' => 'eventdate-2',
'title' => 'Eventdate 2',
'begin' => '1722420000',
'location' => '',
'lecturer' => '',
'note' => '',
'price' => 19.99,
'bookable' => true,
],
2 => [
'uid' => '3',
'pid' => '7',
'event' => '3',
'sku' => 'eventdate-3',
'title' => 'Eventdate 3',
'begin' => '1722420000',
'location' => '',
'lecturer' => '',
'note' => '',
'price' => 29.99,
'bookable' => true,
],
3 => [
'uid' => '4',
'pid' => '9',
'event' => '4',
'sku' => 'eventdate-4',
'title' => 'Eventdate 4',
'begin' => '1722420000',
'location' => '',
'lecturer' => '',
'note' => '',
'price' => 9.99,
'bookable' => true,
],
],
];
Loading

0 comments on commit 9e0007e

Please sign in to comment.