-
Notifications
You must be signed in to change notification settings - Fork 386
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This is a regression test for #812.
- Loading branch information
Showing
3 changed files
with
98 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
<?php | ||
|
||
// SPDX-FileCopyrightText: 2004-2023 Ryan Parman, Sam Sneddon, Ryan McCue | ||
// SPDX-License-Identifier: BSD-3-Clause | ||
|
||
declare(strict_types=1); | ||
|
||
namespace SimplePie\Tests\Integration; | ||
|
||
use Exception; | ||
use PHPUnit\Framework\TestCase; | ||
use Psr\SimpleCache\CacheInterface; | ||
use SimplePie\Cache; | ||
use SimplePie\Cache\Base; | ||
use SimplePie\File; | ||
use SimplePie\Misc; | ||
use SimplePie\SimplePie; | ||
use SimplePie\Tests\Fixtures\Cache\BaseCacheWithCallbacksMock; | ||
use SimplePie\Tests\Fixtures\FileMock; | ||
use SimplePie\Tests\Integration\Fixtures\HttpServer; | ||
|
||
final class FileTest extends TestCase | ||
{ | ||
/** | ||
* @return iterable<array{bool}> | ||
*/ | ||
public function redirectsConfigProvider(): iterable | ||
{ | ||
yield 'curl' => [ | ||
'force_fsockopen' => false, | ||
]; | ||
|
||
yield 'fsockopen' => [ | ||
'force_fsockopen' => true, | ||
]; | ||
} | ||
|
||
/** | ||
* @dataProvider redirectsConfigProvider | ||
*/ | ||
public function testRedirects(bool $force_fsockopen): void | ||
{ | ||
$server = new HttpServer(__DIR__ . '/Fixtures/redirects.php'); | ||
$server->start(); | ||
|
||
$base = $server->getBaseUri(); | ||
$file = new File( | ||
"{$base}/perm2", | ||
10, // timeout | ||
10, // redirects | ||
null, // headers | ||
null, // useragent | ||
$force_fsockopen | ||
); | ||
$server->terminate(); | ||
|
||
$this->assertSame("{$base}/temp2", $file->permanent_url); | ||
$this->assertSame("{$base}/final", $file->url); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
$redirect = function (int $status, string $location): void { | ||
http_response_code($status); | ||
header("Location: $location"); | ||
}; | ||
|
||
$output = function (int $status, string $text): void { | ||
http_response_code($status); | ||
echo $text; | ||
}; | ||
|
||
if ($_SERVER['REQUEST_URI'] === '/perm2') { | ||
$redirect(308, '/perm1'); | ||
} elseif ($_SERVER['REQUEST_URI'] === '/perm1') { | ||
$redirect(301, '/perm0'); | ||
} elseif ($_SERVER['REQUEST_URI'] === '/perm0') { | ||
$redirect(308, '/temp2'); | ||
} elseif ($_SERVER['REQUEST_URI'] === '/temp2') { | ||
$redirect(307, '/temp1'); | ||
} elseif ($_SERVER['REQUEST_URI'] === '/temp1') { | ||
$redirect(302, '/temp0'); | ||
} elseif ($_SERVER['REQUEST_URI'] === '/temp0') { | ||
$redirect(307, '/permA'); | ||
} elseif ($_SERVER['REQUEST_URI'] === '/permA') { | ||
$redirect(301, '/permB'); | ||
} elseif ($_SERVER['REQUEST_URI'] === '/permB') { | ||
$redirect(308, '/permC'); | ||
} elseif ($_SERVER['REQUEST_URI'] === '/permC') { | ||
$redirect(308, '/final'); | ||
} elseif ($_SERVER['REQUEST_URI'] === '/final') { | ||
$output(200, '/ok'); | ||
} else { | ||
$output(404, 'Not found'); | ||
} |