upskill-event-manager/wordpress-dev/vendor/yoast/phpunit-polyfills/src/TestCases/TestCasePHPUnitGte8.php
bengizmo 37f7b426b6 feat: Implement auto page creation & fix login E2E tests
Implements automatic creation of required plugin pages (Community Login,
Trainer Registration, Trainer Dashboard) upon plugin activation. This
addresses E2E test failures caused by missing pages in the test
environment.

- Adds activation hook in `hvac-community-events.php` to call
  `hvac_ce_create_required_pages`.
- The callback function checks for existing pages by slug and creates
  them using `wp_insert_post` if missing. Includes debug logging.

Also fixes issues identified during E2E test debugging:
- Corrects fatal error in `includes/community/class-login-handler.php`
  by replacing undefined constant `HVAC_COMMUNITY_EVENTS_PATH` with
  `HVAC_CE_PLUGIN_DIR`.
- Updates `tests/e2e/tests/login.spec.ts` to use the correct selector
  `#wp-submit` for the login form submit button instead of
  `button[type="submit"]`.

Documentation updates:
- Adds `docs/automatic-page-creation-plan.md`.
- Updates `README.md` regarding automatic page creation.
- Updates Memory Bank files (`decisionLog.md`, `progress.md`,
  `activeContext.md`).

Note: Activation hook logging did not appear during WP-CLI activation,
requiring further investigation if page creation issues persist. E2E
test confirmation pending.
2025-03-28 17:18:21 -03:00

164 lines
4.1 KiB
PHP

<?php
namespace Yoast\PHPUnitPolyfills\TestCases;
use PHPUnit\Framework\TestCase as PHPUnit_TestCase;
use Yoast\PHPUnitPolyfills\Helpers\AssertAttributeHelper;
use Yoast\PHPUnitPolyfills\Polyfills\AssertClosedResource;
use Yoast\PHPUnitPolyfills\Polyfills\AssertFileEqualsSpecializations;
use Yoast\PHPUnitPolyfills\Polyfills\AssertionRenames;
use Yoast\PHPUnitPolyfills\Polyfills\AssertObjectEquals;
use Yoast\PHPUnitPolyfills\Polyfills\AssertObjectProperty;
use Yoast\PHPUnitPolyfills\Polyfills\EqualToSpecializations;
use Yoast\PHPUnitPolyfills\Polyfills\ExpectExceptionMessageMatches;
use Yoast\PHPUnitPolyfills\Polyfills\ExpectPHPException;
/**
* Basic test case for use with PHPUnit >= 8.
*
* This test case uses renamed (snakecase) methods for the `setUpBeforeClass()`, `setUp()`,
* `assertPreConditions()`, `assertPostConditions()`, `tearDown()` and `tearDownAfterClass()`
* methods to get round the signature change in PHPUnit 8.
*
* When using this TestCase, the snakecase method names need to be used to overload a fixture method.
*
* @since 0.1.0
*/
abstract class TestCase extends PHPUnit_TestCase {
use AssertAttributeHelper;
use AssertClosedResource;
use AssertFileEqualsSpecializations;
use AssertionRenames;
use AssertObjectEquals;
use AssertObjectProperty;
use EqualToSpecializations;
use ExpectExceptionMessageMatches;
use ExpectPHPException;
/**
* This method is called before the first test of this test class is run.
*
* @codeCoverageIgnore
*
* @return void
*/
public static function setUpBeforeClass(): void {
parent::setUpBeforeClass();
static::set_up_before_class();
}
/**
* Sets up the fixture, for example, open a network connection.
*
* This method is called before each test.
*
* @return void
*/
protected function setUp(): void {
parent::setUp();
$this->set_up();
}
/**
* Performs assertions shared by all tests of a test case.
*
* This method is called before the execution of a test starts and after setUp() is called.
*
* @since 0.2.0
*
* @return void
*/
protected function assertPreConditions(): void {
parent::assertPreConditions();
$this->assert_pre_conditions();
}
/**
* Performs assertions shared by all tests of a test case.
*
* This method is called before the execution of a test ends and before tearDown() is called.
*
* @since 0.2.0
*
* @return void
*/
protected function assertPostConditions(): void {
parent::assertPostConditions();
$this->assert_post_conditions();
}
/**
* Tears down the fixture, for example, close a network connection.
*
* This method is called after each test.
*
* @return void
*/
protected function tearDown(): void {
$this->tear_down();
parent::tearDown();
}
/**
* This method is called after the last test of this test class is run.
*
* @codeCoverageIgnore
*
* @return void
*/
public static function tearDownAfterClass(): void {
static::tear_down_after_class();
parent::tearDownAfterClass();
}
/**
* This method is called before the first test of this test class is run.
*
* @return void
*/
public static function set_up_before_class() {}
/**
* Sets up the fixture, for example, open a network connection.
*
* This method is called before each test.
*
* @return void
*/
protected function set_up() {}
/**
* Performs assertions shared by all tests of a test case.
*
* This method is called before the execution of a test starts and after set_up() is called.
*
* @return void
*/
protected function assert_pre_conditions() {}
/**
* Performs assertions shared by all tests of a test case.
*
* This method is called before the execution of a test ends and before tear_down() is called.
*
* @return void
*/
protected function assert_post_conditions() {}
/**
* Tears down the fixture, for example, close a network connection.
*
* This method is called after each test.
*
* @return void
*/
protected function tear_down() {}
/**
* This method is called after the last test of this test class is run.
*
* @return void
*/
public static function tear_down_after_class() {}
}