mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
Merge pull request #9665 from creative-commoners/pulls/4/php8-fqcn-token
This commit is contained in:
commit
ae0ece2b02
13
.travis.yml
13
.travis.yml
@ -27,6 +27,7 @@ matrix:
|
|||||||
- DB=PGSQL
|
- DB=PGSQL
|
||||||
- PHPCS_TEST=1
|
- PHPCS_TEST=1
|
||||||
- PHPUNIT_TEST=framework
|
- PHPUNIT_TEST=framework
|
||||||
|
- COMPOSER_INSTALL_ARG="--prefer-lowest"
|
||||||
|
|
||||||
- php: 7.2
|
- php: 7.2
|
||||||
env:
|
env:
|
||||||
@ -49,6 +50,16 @@ matrix:
|
|||||||
packages:
|
packages:
|
||||||
- libonig-dev
|
- libonig-dev
|
||||||
|
|
||||||
|
- php: nightly
|
||||||
|
env:
|
||||||
|
- DB=MYSQL
|
||||||
|
- PHPUNIT_TEST=framework
|
||||||
|
- COMPOSER_INSTALL_ARG="--ignore-platform-reqs"
|
||||||
|
addons:
|
||||||
|
apt:
|
||||||
|
packages:
|
||||||
|
- libonig-dev
|
||||||
|
|
||||||
- php: 7.3
|
- php: 7.3
|
||||||
if: type IN (cron)
|
if: type IN (cron)
|
||||||
env:
|
env:
|
||||||
@ -78,7 +89,7 @@ before_script:
|
|||||||
- composer require silverstripe/recipe-testing:^1 silverstripe/recipe-core:4.x-dev silverstripe/admin:1.x-dev silverstripe/versioned:1.x-dev --no-update
|
- composer require silverstripe/recipe-testing:^1 silverstripe/recipe-core:4.x-dev silverstripe/admin:1.x-dev silverstripe/versioned:1.x-dev --no-update
|
||||||
- if [[ $PHPUNIT_TEST == cms ]]; then composer require silverstripe/recipe-cms:4.x-dev --no-update; fi
|
- if [[ $PHPUNIT_TEST == cms ]]; then composer require silverstripe/recipe-cms:4.x-dev --no-update; fi
|
||||||
- if [[ $PHPCS_TEST ]]; then composer global require squizlabs/php_codesniffer:^3 --prefer-dist --no-interaction --no-progress --no-suggest -o; fi
|
- if [[ $PHPCS_TEST ]]; then composer global require squizlabs/php_codesniffer:^3 --prefer-dist --no-interaction --no-progress --no-suggest -o; fi
|
||||||
- composer install --prefer-source --no-interaction --no-progress --no-suggest --optimize-autoloader --verbose --profile
|
- composer update --prefer-source --no-interaction --no-progress --no-suggest --optimize-autoloader --verbose --profile $COMPOSER_INSTALL_ARG
|
||||||
|
|
||||||
# Log constants to CI for debugging purposes
|
# Log constants to CI for debugging purposes
|
||||||
- php ./tests/dump_constants.php
|
- php ./tests/dump_constants.php
|
||||||
|
@ -25,11 +25,11 @@
|
|||||||
"bramus/monolog-colored-line-formatter": "~2.0",
|
"bramus/monolog-colored-line-formatter": "~2.0",
|
||||||
"composer/installers": "~1.0",
|
"composer/installers": "~1.0",
|
||||||
"embed/embed": "^3.0",
|
"embed/embed": "^3.0",
|
||||||
"league/csv": "^8",
|
"league/csv": "^8 || ^9",
|
||||||
"league/flysystem": "~1.0.12",
|
"league/flysystem": "~1.0.12",
|
||||||
"m1/env": "^2.1",
|
"m1/env": "^2.1",
|
||||||
"monolog/monolog": "~1.11",
|
"monolog/monolog": "~1.16",
|
||||||
"nikic/php-parser": "^2 || ^3 || ^4",
|
"nikic/php-parser": "^3 || ^4",
|
||||||
"psr/container": "1.0.0",
|
"psr/container": "1.0.0",
|
||||||
"psr/container-implementation": "1.0.0",
|
"psr/container-implementation": "1.0.0",
|
||||||
"silverstripe/config": "^1@dev",
|
"silverstripe/config": "^1@dev",
|
||||||
@ -54,8 +54,8 @@
|
|||||||
"ext-xml": "*"
|
"ext-xml": "*"
|
||||||
},
|
},
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
"phpunit/phpunit": "^5.7",
|
"sminnee/phpunit": "^5.7.29",
|
||||||
"sminnee/phpunit-mock-objects": "^3.4.5",
|
"sminnee/phpunit-mock-objects": "^3.4.9",
|
||||||
"silverstripe/versioned": "^1",
|
"silverstripe/versioned": "^1",
|
||||||
"squizlabs/php_codesniffer": "^3.5"
|
"squizlabs/php_codesniffer": "^3.5"
|
||||||
},
|
},
|
||||||
|
@ -48,7 +48,7 @@ class HttpMethodBypass implements Bypass
|
|||||||
// uppercase and exclude empties
|
// uppercase and exclude empties
|
||||||
$methods = array_reduce(
|
$methods = array_reduce(
|
||||||
$methods,
|
$methods,
|
||||||
static function &(&$result, $method) {
|
function ($result, $method) {
|
||||||
$method = strtoupper(trim($method));
|
$method = strtoupper(trim($method));
|
||||||
if (strlen($method)) {
|
if (strlen($method)) {
|
||||||
$result[] = $method;
|
$result[] = $method;
|
||||||
|
@ -439,7 +439,13 @@ class ClassInfo
|
|||||||
$tokenName = is_array($token) ? $token[0] : $token;
|
$tokenName = is_array($token) ? $token[0] : $token;
|
||||||
|
|
||||||
// Get the class name
|
// Get the class name
|
||||||
if ($class === null && is_array($token) && $token[0] === T_STRING) {
|
if (\defined('T_NAME_QUALIFIED') && is_array($token) &&
|
||||||
|
($token[0] === T_NAME_QUALIFIED || $token[0] === T_NAME_FULLY_QUALIFIED)
|
||||||
|
) {
|
||||||
|
// PHP 8 exposes the FQCN as a single T_NAME_QUALIFIED or T_NAME_FULLY_QUALIFIED token
|
||||||
|
$class .= $token[1];
|
||||||
|
$hadNamespace = true;
|
||||||
|
} elseif ($class === null && is_array($token) && $token[0] === T_STRING) {
|
||||||
$class = $token[1];
|
$class = $token[1];
|
||||||
} elseif (is_array($token) && $token[0] === T_NS_SEPARATOR) {
|
} elseif (is_array($token) && $token[0] === T_NS_SEPARATOR) {
|
||||||
$class .= $token[1];
|
$class .= $token[1];
|
||||||
|
@ -32,8 +32,8 @@ class InheritanceMiddleware implements Middleware
|
|||||||
return $config;
|
return $config;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Skip if no parent class
|
// Skip if not a class or not parent class
|
||||||
$parent = get_parent_class($class);
|
$parent = class_exists($class) ? get_parent_class($class) : null;
|
||||||
if (!$parent) {
|
if (!$parent) {
|
||||||
return $config;
|
return $config;
|
||||||
}
|
}
|
||||||
|
@ -296,12 +296,17 @@ class Convert
|
|||||||
* @param string $val
|
* @param string $val
|
||||||
* @param boolean $disableDoctypes Disables the use of DOCTYPE, and will trigger an error if encountered.
|
* @param boolean $disableDoctypes Disables the use of DOCTYPE, and will trigger an error if encountered.
|
||||||
* false by default.
|
* false by default.
|
||||||
* @param boolean $disableExternals Disables the loading of external entities. false by default.
|
* @param boolean $disableExternals Disables the loading of external entities. false by default. No-op in PHP 8.
|
||||||
* @return array
|
* @return array
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public static function xml2array($val, $disableDoctypes = false, $disableExternals = false)
|
public static function xml2array($val, $disableDoctypes = false, $disableExternals = false)
|
||||||
{
|
{
|
||||||
|
// PHP 8 deprecates libxml_disable_entity_loader() as it is no longer needed
|
||||||
|
if (\PHP_VERSION_ID >= 80000) {
|
||||||
|
$disableExternals = false;
|
||||||
|
}
|
||||||
|
|
||||||
// Check doctype
|
// Check doctype
|
||||||
if ($disableDoctypes && preg_match('/\<\!DOCTYPE.+]\>/', $val)) {
|
if ($disableDoctypes && preg_match('/\<\!DOCTYPE.+]\>/', $val)) {
|
||||||
throw new InvalidArgumentException('XML Doctype parsing disabled');
|
throw new InvalidArgumentException('XML Doctype parsing disabled');
|
||||||
|
@ -20,6 +20,8 @@ class InjectionCreator implements Factory
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (count($params)) {
|
if (count($params)) {
|
||||||
|
// Remove named keys to ensure that PHP7 and PHP8 interpret these the same way
|
||||||
|
$params = array_values($params);
|
||||||
return $reflector->newInstanceArgs($params);
|
return $reflector->newInstanceArgs($params);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace SilverStripe\Dev;
|
namespace SilverStripe\Dev;
|
||||||
|
|
||||||
|
use League\Csv\MapIterator;
|
||||||
use League\Csv\Reader;
|
use League\Csv\Reader;
|
||||||
use SilverStripe\Control\Director;
|
use SilverStripe\Control\Director;
|
||||||
use SilverStripe\ORM\DataObject;
|
use SilverStripe\ORM\DataObject;
|
||||||
@ -76,9 +77,16 @@ class CsvBulkLoader extends BulkLoader
|
|||||||
$filepath = Director::getAbsFile($filepath);
|
$filepath = Director::getAbsFile($filepath);
|
||||||
$csvReader = Reader::createFromPath($filepath, 'r');
|
$csvReader = Reader::createFromPath($filepath, 'r');
|
||||||
$csvReader->setDelimiter($this->delimiter);
|
$csvReader->setDelimiter($this->delimiter);
|
||||||
$csvReader->stripBom(true);
|
|
||||||
|
|
||||||
$tabExtractor = function ($row, $rowOffset, $iterator) {
|
// league/csv 9
|
||||||
|
if (method_exists($csvReader, 'skipInputBOM')) {
|
||||||
|
$csvReader->skipInputBOM();
|
||||||
|
// league/csv 8
|
||||||
|
} else {
|
||||||
|
$csvReader->stripBom(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
$tabExtractor = function ($row, $rowOffset) {
|
||||||
foreach ($row as &$item) {
|
foreach ($row as &$item) {
|
||||||
// [SS-2017-007] Ensure all cells with leading tab and then [@=+] have the tab removed on import
|
// [SS-2017-007] Ensure all cells with leading tab and then [@=+] have the tab removed on import
|
||||||
if (preg_match("/^\t[\-@=\+]+.*/", $item)) {
|
if (preg_match("/^\t[\-@=\+]+.*/", $item)) {
|
||||||
@ -90,8 +98,9 @@ class CsvBulkLoader extends BulkLoader
|
|||||||
|
|
||||||
if ($this->columnMap) {
|
if ($this->columnMap) {
|
||||||
$headerMap = $this->getNormalisedColumnMap();
|
$headerMap = $this->getNormalisedColumnMap();
|
||||||
$remapper = function ($row, $rowOffset, $iterator) use ($headerMap, $tabExtractor) {
|
|
||||||
$row = $tabExtractor($row, $rowOffset, $iterator);
|
$remapper = function ($row, $rowOffset) use ($headerMap, $tabExtractor) {
|
||||||
|
$row = $tabExtractor($row, $rowOffset);
|
||||||
foreach ($headerMap as $column => $renamedColumn) {
|
foreach ($headerMap as $column => $renamedColumn) {
|
||||||
if ($column == $renamedColumn) {
|
if ($column == $renamedColumn) {
|
||||||
continue;
|
continue;
|
||||||
@ -110,9 +119,18 @@ class CsvBulkLoader extends BulkLoader
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ($this->hasHeaderRow) {
|
if ($this->hasHeaderRow) {
|
||||||
$rows = $csvReader->fetchAssoc(0, $remapper);
|
if (method_exists($csvReader, 'fetchAssoc')) {
|
||||||
|
$rows = $csvReader->fetchAssoc(0, $remapper);
|
||||||
|
} else {
|
||||||
|
$csvReader->setHeaderOffset(0);
|
||||||
|
$rows = new MapIterator($csvReader->getRecords(), $remapper);
|
||||||
|
}
|
||||||
} elseif ($this->columnMap) {
|
} elseif ($this->columnMap) {
|
||||||
$rows = $csvReader->fetchAssoc($headerMap, $remapper);
|
if (method_exists($csvReader, 'fetchAssoc')) {
|
||||||
|
$rows = $csvReader->fetchAssoc($headerMap, $remapper);
|
||||||
|
} else {
|
||||||
|
$rows = new MapIterator($csvReader->getRecords($headerMap), $remapper);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($rows as $row) {
|
foreach ($rows as $row) {
|
||||||
|
@ -257,6 +257,10 @@ class GridFieldExportButton implements GridField_HTMLProvider, GridField_ActionP
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (method_exists($csvWriter, 'getContent')) {
|
||||||
|
return $csvWriter->getContent();
|
||||||
|
}
|
||||||
|
|
||||||
return (string)$csvWriter;
|
return (string)$csvWriter;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -16,7 +16,7 @@ interface DataQueryManipulator
|
|||||||
* @param array $queriedColumns
|
* @param array $queriedColumns
|
||||||
* @param SQLSelect $sqlSelect
|
* @param SQLSelect $sqlSelect
|
||||||
*/
|
*/
|
||||||
public function beforeGetFinalisedQuery(DataQuery $dataQuery, $queriedColumns = [], SQLSelect $sqlSelect);
|
public function beforeGetFinalisedQuery(DataQuery $dataQuery, $queriedColumns, SQLSelect $sqlSelect);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Invoked after getFinalisedQuery()
|
* Invoked after getFinalisedQuery()
|
||||||
@ -25,5 +25,5 @@ interface DataQueryManipulator
|
|||||||
* @param array $queriedColumns
|
* @param array $queriedColumns
|
||||||
* @param SQLSelect $sqlQuery
|
* @param SQLSelect $sqlQuery
|
||||||
*/
|
*/
|
||||||
public function afterGetFinalisedQuery(DataQuery $dataQuery, $queriedColumns = [], SQLSelect $sqlQuery);
|
public function afterGetFinalisedQuery(DataQuery $dataQuery, $queriedColumns, SQLSelect $sqlQuery);
|
||||||
}
|
}
|
||||||
|
@ -231,7 +231,7 @@ class ManyManyThroughQueryManipulator implements DataQueryManipulator
|
|||||||
* @param array $queriedColumns
|
* @param array $queriedColumns
|
||||||
* @param SQLSelect $sqlSelect
|
* @param SQLSelect $sqlSelect
|
||||||
*/
|
*/
|
||||||
public function beforeGetFinalisedQuery(DataQuery $dataQuery, $queriedColumns = [], SQLSelect $sqlSelect)
|
public function beforeGetFinalisedQuery(DataQuery $dataQuery, $queriedColumns, SQLSelect $sqlSelect)
|
||||||
{
|
{
|
||||||
// Get metadata and SQL from join table
|
// Get metadata and SQL from join table
|
||||||
$hasManyRelation = $this->getParentRelationship($dataQuery);
|
$hasManyRelation = $this->getParentRelationship($dataQuery);
|
||||||
@ -281,7 +281,7 @@ class ManyManyThroughQueryManipulator implements DataQueryManipulator
|
|||||||
* @param array $queriedColumns
|
* @param array $queriedColumns
|
||||||
* @param SQLSelect $sqlQuery
|
* @param SQLSelect $sqlQuery
|
||||||
*/
|
*/
|
||||||
public function afterGetFinalisedQuery(DataQuery $dataQuery, $queriedColumns = [], SQLSelect $sqlQuery)
|
public function afterGetFinalisedQuery(DataQuery $dataQuery, $queriedColumns, SQLSelect $sqlQuery)
|
||||||
{
|
{
|
||||||
// Inject final replacement after manipulation has been performed on the base dataquery
|
// Inject final replacement after manipulation has been performed on the base dataquery
|
||||||
$joinTableSQL = $dataQuery->getQueryParam('Foreign.JoinTableSQL');
|
$joinTableSQL = $dataQuery->getQueryParam('Foreign.JoinTableSQL');
|
||||||
|
@ -56,7 +56,8 @@ abstract class PasswordEncryptor
|
|||||||
return new $class;
|
return new $class;
|
||||||
}
|
}
|
||||||
|
|
||||||
$arguments = $encryptors[$algorithm];
|
// Don't treat array keys as argument names - keeps PHP 7 and PHP 8 operating similarly
|
||||||
|
$arguments = array_values($encryptors[$algorithm]);
|
||||||
return($refClass->newInstanceArgs($arguments));
|
return($refClass->newInstanceArgs($arguments));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -29,7 +29,7 @@ class EmbedResource implements Embeddable
|
|||||||
/**
|
/**
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
protected $options;
|
protected $options = [];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var DispatcherInterface
|
* @var DispatcherInterface
|
||||||
|
@ -570,6 +570,13 @@ class i18nTextCollector
|
|||||||
if (is_array($token)) {
|
if (is_array($token)) {
|
||||||
list($id, $text) = $token;
|
list($id, $text) = $token;
|
||||||
|
|
||||||
|
// PHP 8 namespace tokens
|
||||||
|
if (\defined('T_NAME_QUALIFIED') && in_array($id, [T_NAME_FULLY_QUALIFIED, T_NAME_QUALIFIED])) {
|
||||||
|
$inNamespace = true;
|
||||||
|
$currentClass[] = $text;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
// Check class
|
// Check class
|
||||||
if ($id === T_NAMESPACE) {
|
if ($id === T_NAMESPACE) {
|
||||||
$inNamespace = true;
|
$inNamespace = true;
|
||||||
|
@ -105,7 +105,7 @@ class ClassInfoTest extends SapphireTest
|
|||||||
public function testNonClassName()
|
public function testNonClassName()
|
||||||
{
|
{
|
||||||
$this->expectException(ReflectionException::class);
|
$this->expectException(ReflectionException::class);
|
||||||
$this->expectExceptionMessage('Class IAmAClassThatDoesNotExist does not exist');
|
$this->expectExceptionMessageRegExp('/Class "?IAmAClassThatDoesNotExist"? does not exist/');
|
||||||
$this->assertEquals('IAmAClassThatDoesNotExist', ClassInfo::class_name('IAmAClassThatDoesNotExist'));
|
$this->assertEquals('IAmAClassThatDoesNotExist', ClassInfo::class_name('IAmAClassThatDoesNotExist'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -42,34 +42,34 @@ class DataProvider implements TestOnly
|
|||||||
public static function provideEqualLists()
|
public static function provideEqualLists()
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
[
|
'oneParameterOneItem' => [
|
||||||
'oneParameterOneItem' => [
|
[
|
||||||
['FirstName' => 'Ingo'],
|
['FirstName' => 'Ingo'],
|
||||||
],
|
],
|
||||||
self::$oneItemList,
|
self::$oneItemList,
|
||||||
],
|
],
|
||||||
[
|
'twoParametersOneItem' => [
|
||||||
'twoParametersOneItem' => [
|
[
|
||||||
['FirstName' => 'Ingo', 'Surname' => 'Schommer'],
|
['FirstName' => 'Ingo', 'Surname' => 'Schommer'],
|
||||||
],
|
],
|
||||||
self::$oneItemList,
|
self::$oneItemList,
|
||||||
],
|
],
|
||||||
[
|
'oneParameterTwoItems' => [
|
||||||
'oneParameterTwoItems' => [
|
[
|
||||||
['FirstName' => 'Ingo'],
|
['FirstName' => 'Ingo'],
|
||||||
['FirstName' => 'Sam'],
|
['FirstName' => 'Sam'],
|
||||||
],
|
],
|
||||||
self::$twoItemList,
|
self::$twoItemList,
|
||||||
],
|
],
|
||||||
[
|
'twoParametersTwoItems' => [
|
||||||
'twoParametersTwoItems' => [
|
[
|
||||||
['FirstName' => 'Ingo', 'Surname' => 'Schommer'],
|
['FirstName' => 'Ingo', 'Surname' => 'Schommer'],
|
||||||
['FirstName' => 'Sam', 'Surname' => 'Minnee'],
|
['FirstName' => 'Sam', 'Surname' => 'Minnee'],
|
||||||
],
|
],
|
||||||
self::$twoItemList,
|
self::$twoItemList,
|
||||||
],
|
],
|
||||||
[
|
'mixedParametersTwoItems' => [
|
||||||
'mixedParametersTwoItems' => [
|
[
|
||||||
['FirstName' => 'Ingo', 'Surname' => 'Schommer'],
|
['FirstName' => 'Ingo', 'Surname' => 'Schommer'],
|
||||||
['FirstName' => 'Sam'],
|
['FirstName' => 'Sam'],
|
||||||
],
|
],
|
||||||
@ -85,34 +85,34 @@ class DataProvider implements TestOnly
|
|||||||
{
|
{
|
||||||
|
|
||||||
return [
|
return [
|
||||||
[
|
'checkAgainstEmptyList' => [
|
||||||
'checkAgainstEmptyList' => [
|
[
|
||||||
['FirstName' => 'Ingo'],
|
['FirstName' => 'Ingo'],
|
||||||
],
|
],
|
||||||
[],
|
[],
|
||||||
],
|
],
|
||||||
[
|
'oneItemExpectedListContainsMore' => [
|
||||||
'oneItemExpectedListContainsMore' => [
|
[
|
||||||
['FirstName' => 'Ingo'],
|
['FirstName' => 'Ingo'],
|
||||||
],
|
],
|
||||||
self::$twoItemList,
|
self::$twoItemList,
|
||||||
],
|
],
|
||||||
[
|
'oneExpectationHasWrontParamter' => [
|
||||||
'oneExpectationHasWrontParamter' => [
|
[
|
||||||
['FirstName' => 'IngoXX'],
|
['FirstName' => 'IngoXX'],
|
||||||
['FirstName' => 'Sam'],
|
['FirstName' => 'Sam'],
|
||||||
],
|
],
|
||||||
self::$twoItemList,
|
self::$twoItemList,
|
||||||
],
|
],
|
||||||
[
|
'differentParametersInDifferentItemsAreWrong' => [
|
||||||
'differentParametersInDifferentItemsAreWrong' => [
|
[
|
||||||
['FirstName' => 'IngoXXX', 'Surname' => 'Schommer'],
|
['FirstName' => 'IngoXXX', 'Surname' => 'Schommer'],
|
||||||
['FirstName' => 'Sam', 'Surname' => 'MinneeXXX'],
|
['FirstName' => 'Sam', 'Surname' => 'MinneeXXX'],
|
||||||
],
|
],
|
||||||
self::$twoItemList,
|
self::$twoItemList,
|
||||||
],
|
],
|
||||||
[
|
'differentParametersNotMatching' => [
|
||||||
'differentParametersNotMatching' => [
|
[
|
||||||
['FirstName' => 'Daniel', 'Surname' => 'Foo'],
|
['FirstName' => 'Daniel', 'Surname' => 'Foo'],
|
||||||
['FirstName' => 'Dan'],
|
['FirstName' => 'Dan'],
|
||||||
],
|
],
|
||||||
|
@ -55,7 +55,7 @@ class GridFieldExportButtonTest extends SapphireTest
|
|||||||
$config = GridFieldConfig::create()->addComponent(new GridFieldExportButton());
|
$config = GridFieldConfig::create()->addComponent(new GridFieldExportButton());
|
||||||
$gridField = new GridField('testfield', 'testfield', $list, $config);
|
$gridField = new GridField('testfield', 'testfield', $list, $config);
|
||||||
|
|
||||||
$csvReader = Reader::createFromString($button->generateExportFileData($gridField));
|
$csvReader = $this->createReader($button->generateExportFileData($gridField));
|
||||||
$bom = $csvReader->getInputBOM();
|
$bom = $csvReader->getInputBOM();
|
||||||
|
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
@ -69,7 +69,7 @@ class GridFieldExportButtonTest extends SapphireTest
|
|||||||
$button = new GridFieldExportButton();
|
$button = new GridFieldExportButton();
|
||||||
$button->setExportColumns(['Name' => 'My Name']);
|
$button->setExportColumns(['Name' => 'My Name']);
|
||||||
|
|
||||||
$csvReader = Reader::createFromString($button->generateExportFileData($this->gridField));
|
$csvReader = $this->createReader($button->generateExportFileData($this->gridField));
|
||||||
$bom = $csvReader->getInputBOM();
|
$bom = $csvReader->getInputBOM();
|
||||||
|
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
@ -89,7 +89,7 @@ class GridFieldExportButtonTest extends SapphireTest
|
|||||||
$button = new GridFieldExportButton();
|
$button = new GridFieldExportButton();
|
||||||
$button->setExportColumns(['Name' => 'My Name']);
|
$button->setExportColumns(['Name' => 'My Name']);
|
||||||
|
|
||||||
$csvReader = Reader::createFromString($button->generateExportFileData($this->gridField));
|
$csvReader = $this->createReader($button->generateExportFileData($this->gridField));
|
||||||
$bom = $csvReader->getInputBOM();
|
$bom = $csvReader->getInputBOM();
|
||||||
|
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
@ -108,7 +108,7 @@ class GridFieldExportButtonTest extends SapphireTest
|
|||||||
}
|
}
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$csvReader = Reader::createFromString($button->generateExportFileData($this->gridField));
|
$csvReader = $this->createReader($button->generateExportFileData($this->gridField));
|
||||||
$bom = $csvReader->getInputBOM();
|
$bom = $csvReader->getInputBOM();
|
||||||
|
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
@ -125,7 +125,7 @@ class GridFieldExportButtonTest extends SapphireTest
|
|||||||
'City' => 'strtolower',
|
'City' => 'strtolower',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$csvReader = Reader::createFromString($button->generateExportFileData($this->gridField));
|
$csvReader = $this->createReader($button->generateExportFileData($this->gridField));
|
||||||
$bom = $csvReader->getInputBOM();
|
$bom = $csvReader->getInputBOM();
|
||||||
|
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
@ -143,7 +143,7 @@ class GridFieldExportButtonTest extends SapphireTest
|
|||||||
]);
|
]);
|
||||||
$button->setCsvHasHeader(false);
|
$button->setCsvHasHeader(false);
|
||||||
|
|
||||||
$csvReader = Reader::createFromString($button->generateExportFileData($this->gridField));
|
$csvReader = $this->createReader($button->generateExportFileData($this->gridField));
|
||||||
$bom = $csvReader->getInputBOM();
|
$bom = $csvReader->getInputBOM();
|
||||||
|
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
@ -167,7 +167,7 @@ class GridFieldExportButtonTest extends SapphireTest
|
|||||||
|
|
||||||
$exportData = $button->generateExportFileData($this->gridField);
|
$exportData = $button->generateExportFileData($this->gridField);
|
||||||
|
|
||||||
$csvReader = Reader::createFromString($exportData);
|
$csvReader = $this->createReader($exportData);
|
||||||
$bom = $csvReader->getInputBOM();
|
$bom = $csvReader->getInputBOM();
|
||||||
|
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
@ -183,7 +183,7 @@ class GridFieldExportButtonTest extends SapphireTest
|
|||||||
'RugbyTeamNumber' => 'Rugby Team Number'
|
'RugbyTeamNumber' => 'Rugby Team Number'
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$csvReader = Reader::createFromString($button->generateExportFileData($this->gridField));
|
$csvReader = $this->createReader($button->generateExportFileData($this->gridField));
|
||||||
$bom = $csvReader->getInputBOM();
|
$bom = $csvReader->getInputBOM();
|
||||||
|
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
@ -191,4 +191,16 @@ class GridFieldExportButtonTest extends SapphireTest
|
|||||||
(string) $csvReader
|
(string) $csvReader
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function createReader($string)
|
||||||
|
{
|
||||||
|
$reader = Reader::createFromString($string);
|
||||||
|
|
||||||
|
// Explicitly set the output BOM in league/csv 9
|
||||||
|
if (method_exists($reader, 'getContent')) {
|
||||||
|
$reader->setOutputBOM(Reader::BOM_UTF8);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $reader;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,7 @@ namespace SilverStripe\ORM\Tests;
|
|||||||
|
|
||||||
use InvalidArgumentException;
|
use InvalidArgumentException;
|
||||||
use SilverStripe\Core\Convert;
|
use SilverStripe\Core\Convert;
|
||||||
|
use SilverStripe\Core\Injector\InjectorNotFoundException;
|
||||||
use SilverStripe\Dev\SapphireTest;
|
use SilverStripe\Dev\SapphireTest;
|
||||||
use SilverStripe\ORM\DataList;
|
use SilverStripe\ORM\DataList;
|
||||||
use SilverStripe\ORM\DataQuery;
|
use SilverStripe\ORM\DataQuery;
|
||||||
@ -751,24 +752,23 @@ class DataListTest extends SapphireTest
|
|||||||
$this->assertEquals('Bob', $list->first()->Name, 'First comment should be from Bob');
|
$this->assertEquals('Bob', $list->first()->Name, 'First comment should be from Bob');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @expectedException \SilverStripe\Core\Injector\InjectorNotFoundException
|
|
||||||
* @expectedExceptionMessage Class DataListFilter.Bogus does not exist
|
|
||||||
*/
|
|
||||||
public function testSimpleFilterWithNonExistingComparisator()
|
public function testSimpleFilterWithNonExistingComparisator()
|
||||||
{
|
{
|
||||||
|
$this->expectException(InjectorNotFoundException::class);
|
||||||
|
$this->expectExceptionMessageRegExp('/Class "?DataListFilter.Bogus"? does not exist/');
|
||||||
|
|
||||||
$list = TeamComment::get();
|
$list = TeamComment::get();
|
||||||
$list->filter('Comment:Bogus', 'team comment');
|
$list->filter('Comment:Bogus', 'team comment');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Invalid modifiers are treated as failed filter construction
|
* Invalid modifiers are treated as failed filter construction
|
||||||
*
|
|
||||||
* @expectedException \SilverStripe\Core\Injector\InjectorNotFoundException
|
|
||||||
* @expectedExceptionMessage Class DataListFilter.invalidmodifier does not exist
|
|
||||||
*/
|
*/
|
||||||
public function testInvalidModifier()
|
public function testInvalidModifier()
|
||||||
{
|
{
|
||||||
|
$this->expectException(InjectorNotFoundException::class);
|
||||||
|
$this->expectExceptionMessageRegExp('/Class "?DataListFilter.invalidmodifier"? does not exist/');
|
||||||
|
|
||||||
$list = TeamComment::get();
|
$list = TeamComment::get();
|
||||||
$list->filter('Comment:invalidmodifier', 'team comment');
|
$list->filter('Comment:invalidmodifier', 'team comment');
|
||||||
}
|
}
|
||||||
|
@ -45,7 +45,6 @@ class MySQLPDOConnectorTest extends SapphireTest implements TestOnly
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @depends testConnectionCharsetControl
|
|
||||||
* @dataProvider charsetProvider
|
* @dataProvider charsetProvider
|
||||||
*/
|
*/
|
||||||
public function testConnectionCollationControl($charset, $defaultCollation, $customCollation)
|
public function testConnectionCollationControl($charset, $defaultCollation, $customCollation)
|
||||||
|
@ -38,7 +38,6 @@ class MySQLiConnectorTest extends SapphireTest implements TestOnly
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @depends testConnectionCharsetControl
|
|
||||||
* @dataProvider charsetProvider
|
* @dataProvider charsetProvider
|
||||||
*/
|
*/
|
||||||
public function testConnectionCollationControl($charset, $defaultCollation, $customCollation)
|
public function testConnectionCollationControl($charset, $defaultCollation, $customCollation)
|
||||||
|
Loading…
Reference in New Issue
Block a user