PHP code example of gamajo / codeception-redirects
1. Go to this page and download the library: Download gamajo/codeception-redirects library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
gamajo / codeception-redirects example snippets
use Codeception\Example;
class RedirectsCest {
/**
* @var AcceptanceTester
*/
protected $I;
public function _before( AcceptanceTester $I ) {
$this->I = $I;
}
/**
* @example(old="content/abou", new="about-us")
* @example(old="content/abou/over.php", new="about-us/company-overview")
* @example(old="content/abou/miss.php", new="about-us/top-third-mission")
* @example(old="content/abou/exec.php", new="about-us/executive-team")
* @example(old="content/abou/team.php", new="about-us/risk-management-specialists")
*
* @group redirects
* @group redirectsabout
*/
public function redirectOldAboutUrlsToAboutUsPages( AcceptanceTester $I, Example $example ) {
$this->testIfOldRedirectsToNew($example['old'], $example['new']);
}
/**
* @example(old="content/myac/index.php", new="my-account")
* @example(old="content/myac/stat.php", new="my-account/account-statements-explained")
* @example(old="content/myac/depo.php", new="my-account/deposits-withdrawals")
* @example(old="content/myac/wire.php", new="wire-instructions-r-j-obrien")
*
* @group redirects
* @group redirectsmyaccount
*/
public function redirectOldMyAccountUrlsToNewMyAccountPages( AcceptanceTester $I, Example $example ) {
$this->testIfOldRedirectsToNew( $example['old'], $example['new'] );
}
private function testIfOldRedirectsToNew($old, $new, $checkDestination = true) {
$this->I->seePermanentRedirectBetween($old, $new);
if ($checkDestinationExists) {
$this->I->urlDoesNotRedirect($new);
}
// Check old URL with trailing slash also redirects.
if (
'/' !== substr($old, -1) &&
false === strpos( strrev($old), strrev('.php')) &&
false === strpos( strrev($old), strrev('.pdf')) &&
false === strpos( $old, '?')
) {
$old .= '/';
$this->testIfOldRedirectsToNew($old, $new, $checkDestinationExists);
}
}
}
use Page\ProfileCalendar;
use Page\ProfileContactInformation;
use Page\ProfileMyProducts;
use Step\Acceptance\Login;
class ProtocolRedirectsCest
{
/**
* @group protocolRedirects
*/
public function forceHttp(Login $I)
{
$I->wantTo('check forced redirects to HTTP are working.');
$I->seeHttpProtocolAlwaysUsedFor(ProfileCalendar::$URL);
}
/**
* @group protocolRedirects
*/
public function forceHttps(Login $I)
{
$I->wantTo('check forced redirects to HTTPS are working.');
$I->seeHttpsProtocolAlwaysUsedFor(ProfileContactInformation::$URL);
$I->seeHttpsProtocolAlwaysUsedFor(ProfileMyProducts::$URL);
}
}