Initial commit
This commit is contained in:
87
templates/example-tests/ExampleAcceptanceCest.php
Normal file
87
templates/example-tests/ExampleAcceptanceCest.php
Normal file
@@ -0,0 +1,87 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Vendor\Extension\Tests\Acceptance;
|
||||
|
||||
use Vendor\Extension\Tests\Acceptance\AcceptanceTester;
|
||||
|
||||
/**
|
||||
* Example acceptance test demonstrating TYPO3 testing patterns
|
||||
*
|
||||
* Acceptance tests use a real browser to test complete user workflows.
|
||||
* They verify frontend functionality and user interactions.
|
||||
*/
|
||||
final class LoginCest
|
||||
{
|
||||
public function _before(AcceptanceTester $I): void
|
||||
{
|
||||
// Runs before each test method
|
||||
// Setup: Import fixtures, reset state, etc.
|
||||
}
|
||||
|
||||
public function loginAsBackendUser(AcceptanceTester $I): void
|
||||
{
|
||||
// Navigate to login page
|
||||
$I->amOnPage('/typo3');
|
||||
|
||||
// Fill login form
|
||||
$I->fillField('username', 'admin');
|
||||
$I->fillField('password', 'password');
|
||||
|
||||
// Submit form
|
||||
$I->click('Login');
|
||||
|
||||
// Verify successful login
|
||||
$I->see('Dashboard');
|
||||
$I->seeInCurrentUrl('/typo3/module/dashboard');
|
||||
}
|
||||
|
||||
public function loginFailsWithInvalidCredentials(AcceptanceTester $I): void
|
||||
{
|
||||
$I->amOnPage('/typo3');
|
||||
|
||||
$I->fillField('username', 'admin');
|
||||
$I->fillField('password', 'wrong_password');
|
||||
$I->click('Login');
|
||||
|
||||
// Verify login failed
|
||||
$I->see('Login error');
|
||||
$I->seeInCurrentUrl('/typo3');
|
||||
}
|
||||
|
||||
public function searchesForProducts(AcceptanceTester $I): void
|
||||
{
|
||||
// Navigate to product listing
|
||||
$I->amOnPage('/products');
|
||||
|
||||
// Wait for page to load
|
||||
$I->waitForElement('.product-list', 5);
|
||||
|
||||
// Use search
|
||||
$I->fillField('#search', 'laptop');
|
||||
$I->click('Search');
|
||||
|
||||
// Wait for results
|
||||
$I->waitForElement('.search-results', 5);
|
||||
|
||||
// Verify search results
|
||||
$I->see('laptop', '.product-title');
|
||||
$I->seeNumberOfElements('.product-item', [1, 10]);
|
||||
}
|
||||
|
||||
public function addsProductToCart(AcceptanceTester $I): void
|
||||
{
|
||||
$I->amOnPage('/products/1');
|
||||
|
||||
// Click add to cart button
|
||||
$I->click('#add-to-cart');
|
||||
|
||||
// Wait for AJAX response
|
||||
$I->waitForElement('.cart-badge', 3);
|
||||
|
||||
// Verify cart updated
|
||||
$I->see('1', '.cart-badge');
|
||||
$I->see('Product added to cart');
|
||||
}
|
||||
}
|
||||
91
templates/example-tests/ExampleFunctionalTest.php
Normal file
91
templates/example-tests/ExampleFunctionalTest.php
Normal file
@@ -0,0 +1,91 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Vendor\Extension\Tests\Functional\Domain\Repository;
|
||||
|
||||
use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;
|
||||
use Vendor\Extension\Domain\Model\Product;
|
||||
use Vendor\Extension\Domain\Repository\ProductRepository;
|
||||
|
||||
/**
|
||||
* Example functional test demonstrating TYPO3 testing patterns
|
||||
*
|
||||
* Functional tests use a real database and full TYPO3 instance.
|
||||
* They test repositories, controllers, and integration scenarios.
|
||||
*/
|
||||
final class ProductRepositoryTest extends FunctionalTestCase
|
||||
{
|
||||
protected ProductRepository $subject;
|
||||
|
||||
/**
|
||||
* Extensions to load for this test
|
||||
*/
|
||||
protected array $testExtensionsToLoad = [
|
||||
'typo3conf/ext/my_extension',
|
||||
];
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
// Get repository from dependency injection container
|
||||
$this->subject = $this->get(ProductRepository::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function findsProductsByCategory(): void
|
||||
{
|
||||
// Import test data from CSV fixture
|
||||
$this->importCSVDataSet(__DIR__ . '/../Fixtures/Products.csv');
|
||||
|
||||
// Execute repository method
|
||||
$products = $this->subject->findByCategory(1);
|
||||
|
||||
// Assert results
|
||||
self::assertCount(3, $products);
|
||||
self::assertInstanceOf(Product::class, $products[0]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function findsVisibleProductsOnly(): void
|
||||
{
|
||||
$this->importCSVDataSet(__DIR__ . '/../Fixtures/ProductsWithHidden.csv');
|
||||
|
||||
$products = $this->subject->findAll();
|
||||
|
||||
// Only visible products should be returned
|
||||
self::assertCount(2, $products);
|
||||
|
||||
foreach ($products as $product) {
|
||||
self::assertFalse($product->isHidden());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function persistsNewProduct(): void
|
||||
{
|
||||
$this->importCSVDataSet(__DIR__ . '/../Fixtures/Pages.csv');
|
||||
|
||||
$product = new Product();
|
||||
$product->setTitle('New Product');
|
||||
$product->setPrice(19.99);
|
||||
$product->setPid(1);
|
||||
|
||||
$this->subject->add($product);
|
||||
|
||||
// Persist to database
|
||||
$this->persistenceManager->persistAll();
|
||||
|
||||
// Verify product was saved
|
||||
$savedProducts = $this->subject->findAll();
|
||||
self::assertCount(1, $savedProducts);
|
||||
self::assertSame('New Product', $savedProducts[0]->getTitle());
|
||||
}
|
||||
}
|
||||
66
templates/example-tests/ExampleUnitTest.php
Normal file
66
templates/example-tests/ExampleUnitTest.php
Normal file
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Vendor\Extension\Tests\Unit\Domain\Validator;
|
||||
|
||||
use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
|
||||
use Vendor\Extension\Domain\Validator\EmailValidator;
|
||||
|
||||
/**
|
||||
* Example unit test demonstrating TYPO3 testing patterns
|
||||
*
|
||||
* Unit tests are fast, isolated tests without external dependencies.
|
||||
* They test individual components (validators, utilities, domain logic).
|
||||
*/
|
||||
final class EmailValidatorTest extends UnitTestCase
|
||||
{
|
||||
protected EmailValidator $subject;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
$this->subject = new EmailValidator();
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function validEmailPassesValidation(): void
|
||||
{
|
||||
$result = $this->subject->validate('user@example.com');
|
||||
|
||||
self::assertFalse($result->hasErrors());
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function invalidEmailFailsValidation(): void
|
||||
{
|
||||
$result = $this->subject->validate('invalid-email');
|
||||
|
||||
self::assertTrue($result->hasErrors());
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @dataProvider invalidEmailProvider
|
||||
*/
|
||||
public function rejectsInvalidEmails(string $email): void
|
||||
{
|
||||
$result = $this->subject->validate($email);
|
||||
|
||||
self::assertTrue($result->hasErrors(), "Email '$email' should be invalid");
|
||||
}
|
||||
|
||||
public static function invalidEmailProvider(): array
|
||||
{
|
||||
return [
|
||||
'missing @' => ['userexample.com'],
|
||||
'missing domain' => ['user@'],
|
||||
'empty string' => [''],
|
||||
'spaces' => ['user @example.com'],
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user