mirror of
https://github.com/PHPOffice/PhpSpreadsheet.git
synced 2026-08-30 20:18:00 +00:00
Merge commit from fork
This commit is contained in:
@@ -42,6 +42,7 @@ class Service
|
||||
// Get results from the webservice
|
||||
$ctxArray = [
|
||||
'http' => [
|
||||
'follow_location' => 0,
|
||||
'user_agent' => 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36',
|
||||
],
|
||||
];
|
||||
@@ -54,7 +55,7 @@ class Service
|
||||
return ExcelError::VALUE(); // Output not a string or too long
|
||||
}
|
||||
|
||||
return $output;
|
||||
return ($output === '') ? Functions::NOT_YET_IMPLEMENTED : $output;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -0,0 +1,69 @@
|
||||
<?php
|
||||
|
||||
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Web;
|
||||
|
||||
use PhpOffice\PhpSpreadsheet\Reader\Xlsx as XlsxReader;
|
||||
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\Process\Process;
|
||||
|
||||
class ServerTest extends TestCase
|
||||
{
|
||||
private static Process $httpServer;
|
||||
|
||||
private const SERVER = 'localhost:8080';
|
||||
private const DIRECT = 'http://' . self::SERVER . '/direct.php';
|
||||
private const REDIRECT = 'http://' . self::SERVER . '/redirect.php';
|
||||
private const OLDVALUE = 'LOCAL_REDIRECT_SECRET2';
|
||||
private const NEWVALUE = 'LOCAL_REDIRECT_SECRET3';
|
||||
|
||||
public static function setUpBeforeClass(): void
|
||||
{
|
||||
$commandLine = 'php -S ' . self::SERVER . ' -t ' . __DIR__;
|
||||
|
||||
self::$httpServer = Process::fromShellCommandline($commandLine);
|
||||
self::$httpServer->start();
|
||||
while (!self::$httpServer->isRunning()) {
|
||||
usleep(1000);
|
||||
}
|
||||
}
|
||||
|
||||
public static function tearDownAfterClass(): void
|
||||
{
|
||||
self::$httpServer->stop();
|
||||
}
|
||||
|
||||
public function testServer(): void
|
||||
{
|
||||
self::assertSame(self::NEWVALUE, file_get_contents(self::DIRECT));
|
||||
self::assertSame(self::NEWVALUE, file_get_contents(self::REDIRECT));
|
||||
}
|
||||
|
||||
public function testReadFile(): void
|
||||
{
|
||||
$reader = new XlsxReader();
|
||||
$spreadsheet = $reader->load(__DIR__ . '/redirect.xlsx');
|
||||
$spreadsheet->setDomainWhiteList(['localhost']);
|
||||
$sheet = $spreadsheet->getActiveSheet();
|
||||
self::assertSame(self::OLDVALUE, $sheet->getCell('A1')->getOldCalculatedValue());
|
||||
self::assertSame(self::OLDVALUE, $sheet->getCell('A2')->getOldCalculatedValue());
|
||||
self::assertSame(self::NEWVALUE, $sheet->getCell('A1')->getCalculatedValue(), 'no redirect so recomputed');
|
||||
self::assertSame(self::OLDVALUE, $sheet->getCell('A2')->getCalculatedValue(), 'redirect so use old computed');
|
||||
}
|
||||
|
||||
public static function testNew(): void
|
||||
{
|
||||
$spreadsheet = new Spreadsheet();
|
||||
$spreadsheet->setDomainWhiteList(['localhost']);
|
||||
$sheet = $spreadsheet->getActiveSheet();
|
||||
$sheet->getCell('G1')->setValue(self::DIRECT);
|
||||
$sheet->getCell('A1')->setValue('=WEBSERVICE(G1)');
|
||||
self::assertSame(self::NEWVALUE, $sheet->getCell('A1')->getCalculatedValue(), 'no redirect so computed');
|
||||
$sheet->getCell('G2')->setValue(self::REDIRECT);
|
||||
$sheet->getCell('A2')->setValue('=WEBSERVICE(G2)');
|
||||
self::assertNull(
|
||||
$sheet->getCell('A2')->getCalculatedValue(),
|
||||
'redirect so not computed'
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
<?php
|
||||
|
||||
header('Content-Type: text/plain');
|
||||
|
||||
echo 'LOCAL_REDIRECT_SECRET3';
|
||||
@@ -0,0 +1,3 @@
|
||||
<?php
|
||||
|
||||
header('Location: http://localhost:8080/direct.php', true, 302);
|
||||
Binary file not shown.
Reference in New Issue
Block a user