Commit Graph

2430 Commits

Author SHA1 Message Date
Adrien Crivelli 5a92a5f6b4
Scrutinizer wait shorter for coverage
Since switching to pcov Travis build are much faster and we don't
need to wait that long
2020-05-25 11:20:08 +09:00
oleibman 5dd7e883c6
Fix Issue 1441 (isDateTime and Formulas) (#1480)
* Fix Issue 1441 (isDateTime and Formulas)

When you have a date-field which is a formula, isDateTime returns false.
https://github.com/PHPOffice/PhpSpreadsheet/issues/1441

Report makes sense; fixed as suggested. Also fixed a few minor
related issues, and added tests so that Shared/Date and Shared/TimeZone
are now completely covered.

Date/setDefaultTimeZone and TimeZone/setTimeZone were not consistent
about what to do in event of failure - return false or throw.
They will now both return false, which is what Date's function
said it would do in its doc block anyhow. Date/validateTimeZone will
continue to throw; it was protected, but was never called outside
Date, so I changed it to private.

TimeZone/getTimeZoneAdjustment checked for 'UST' when it probably
meant 'UTC', and, as it turns out, the check is not even needed.

The most serious problem was that TimeZone/validateTimeZone does not
check the backwards-compatible time zones. The timezone project
aggressively, and very controversially, "demotes" timezones;
such timezones eventually wind up in the PHP backwards-compatible list.
We want to make sure to check that list so that our applications do not
break when this happens.
2020-05-24 20:02:39 +02:00
oleibman 585409a949
Testing - Delete Temp Files When No Longer Needed (#1488)
No code changes. The tests in all of these scripts write to at least
one temporary file, which is then read and not used again. The file
should be deleted to avoid filling up the disk system.
2020-05-24 20:03:07 +09:00
oleibman 41b95c1542
CSV Sample File Was Miscoded (#1489)
File author erroneously assumed that backslash was used to escape
quotes in CSV; in fact, doubling the quote is used for escape.
The test still worked, but mainly because the content of the cell
with the escape wasn't tested. The file is now fixed, and
a new test added.
2020-05-24 19:57:39 +09:00
oleibman 9947de3b89
Restore working directory if test fails (#1490)
This test changes directory then performs an assertion.
No problem if the assertion succeeds. I was a little concerned about
what would happen if the assertion fails, leaving us in the
new directory. So I have changed test to use setUp/tearDown
to ensure that we end up where we started.
2020-05-24 19:54:59 +09:00
oleibman 84e03da5c7
Code Coverage for Shared\CodePage (#1491)
While investigating something else in Shared, I noticed that CodePage
had poor test coverage and a high complexity rating. This change
addresses both; Scrutinizer would love it, although its interface on
GitHub seems broken at the moment (all PRs show "Waiting for External
Code Coverage").
2020-05-24 19:51:28 +09:00
Mark Baker 8ca7bfe53c
Range operator tests (#1487)
* Range Operator Tests
* Correct handling for range intersections that result in an empty array
2020-05-24 00:25:54 +02:00
Mark Baker 86e9d669c6
Range Operator Tests (#1486)
* Range Operator Tests
2020-05-23 22:07:45 +02:00
Vagir 3446bb0ef7
Fix saving XLSX with drawings (#1462)
* Fix incorrect behaviour when saving XLSX file with drawings
2020-05-23 13:09:10 +02:00
Collie-IT 6c23de78d8
Fix Warning if $relsVML->Relationship is NULL (#1420)
Fix Warning if $relsVML->Relationship is NULL (#1420)
2020-05-23 12:56:26 +02:00
F0Rt04ka 0945e87b6d
Fix "Undefined offset" if border style is "none" (#1423) 2020-05-23 12:51:48 +02:00
Gianni Genovesi 7b1957f996
fix: issue #1476 crash with numeric string value terminating with new line (#1481)
* fix: issue #1476 crash with numeric string value terminating with new line
* test: provided tests for issue #1476
2020-05-23 12:49:54 +02:00
oleibman 7d58ba8c86
Merge pull request #2 from PHPOffice/master
Sync with Base
2020-05-18 21:14:57 -07:00
Adrien Crivelli be415fab56
Update functions list 2020-05-18 15:50:46 +09:00
Adrien Crivelli 137268d61a
Remove undesired annotations 2020-05-18 15:49:29 +09:00
Adrien Crivelli fcd9f10663
Update PHP-CS-Fixer rules 2020-05-18 13:49:57 +09:00
Adrien Crivelli 38b360f912
Update CHANGELOG 2020-05-18 12:49:46 +09:00
oleibman 97a80f383c
Improve HTML Writer (#1464)
There are a number of situations where HTML write was producing
HTML which could not be validated. These include:

  - inconsistent use of backslash terminating META, IMG, and COL tags
  - @page style tags in body rather than header. Aside from being
    non-standard, HTML Reader treats those as spreadsheet data.
  - <div style="page-break-before:always" />, a construct which is
    usually better handled through css anyhow.
  - no alt tag for images (drawings and charts)

Other problems:

  - Windows file names not handled correctly for images
  - Memory drawings not handled in extendRowsForChartsAndImages
  - No handling of different values for showing gridlines
    for screen and print
  - Mpdf and Dompdf do not require the use of inline css.
    Tcpdf remains a holdout in the use of this inferior approach.
  - no need to chunk base64 encoding of embedded images
  - support for colors in number format was buggy (html tags
    run through htmlspecialchars)

Code has been refactored when practical to reduce the number of
very large functions.

Coverage is now 100% for the entire HTML Writer module,
from 75% lines and 39% methods beforehand.

All functions dealing only with charts
are bypassed for coverage because the version of Jpgraph available in
Composer is not suitable for PHP7. The code will, nevertheless,
run successfully, but with warning messages. I have confirmed that
the code is entirely covered, without warnings, when the current
version of Jpgraph is used in lieu of the one available in Composer.
I will be glad to revisit this when the Jpgraph problem is resolved.

Directory PhpSpreadsheetTests/Writer/Html was created to house
the new tests. It seemed logical to move HtmlCommentsTest to
the new directory from PhpSpreadsheetTests/Functional.

A function to generate all the HTML is useful, especially for testing,
but also in lieu of the multiple other generate* functions. I have
added and documented generateHTMLAll.

The documentation for the generate* functions (a) produces invalid html,
(b) produces html which cannot be handled correctly by HTML reader,
and (c) even if those were correct, does not actually affect
the display of the spreadsheet. The documentation has been replaced
by a valid, and more instructive, example.

The (undocumented) useEmbeddedCss property, and the functions
to test and set it are no longer needed. Rather than breaking
existing code by deleting them, I marked the functions deprecated.

This change borrows a change to LocaleFloatsTest from
pull request 1456, submitted a little over a week before this one.


## Improve NumberFormat Support

First phase of this change included correcting NumberFormat handling
in HTML Writer. Certain complex formats could not be handled without
changes to Style/NumberFormat, and I did not wish to combine those changes.

Once the original change had been pushed, I took this part of it back up.
HTML Writer can now handle conditions in formats like:
[Blue][>=3000.5]$#,##0.00;[Red][<0]$#,##0.00;$#,##0.00
In testing, I discovered several errors and omissions
in handling of some other formats.
These are now corrected, and tests added.
2020-05-18 12:43:18 +09:00
Owen Leibman 4f6d4af396
Save Excel 2010+ Functions Properly
For functions introduced in Excel 2010 and beyond, Excel saves them
in formulas with the xlfn_ prefix. PhpSpreadsheet does not do this;
as a result, when a spreadsheet so created is opened, the cells
which use the new functions display a #NAME? error.
This the cause of bug report 1246:
https://github.com/PHPOffice/PhpSpreadsheet/issues/1246
This change corrects that problem when the Xlsx writer encounters
a 2010+ formula for a cell or a conditional style. A new class
Writer/Xlsx/Xlfn, with 2 static methods,
is introduced to facilitate this change.

As part of the testing for this, I found some additional problems.
When an unknown function name is used, Excel generates a #NAME? error.
However, when an unknown function is used in PhpSpreadsheet:
  - if there are no parameters, it returns #VALUE!, which is wrong
  - if there are parameters, it throws an exception, which is horrible
Both of these situations will now return #NAME?
Tests have been added for these situations.

The MODE (and MODE.SNGL) function is not quite in alignment with Excel.
MODE(3, 3, 4, 4) returns 3 in both Excel and PhpSpreadsheet.
However, MODE(4, 3, 3, 4) returns 4 in Excel, but 3 in PhpSpreadsheet.
Both situations will now match Excel's result.
Also, Excel allows its parameters for MODE to be an array,
but PhpSpreadsheet did not; it now will.
There had not been any tests for MODE. Now there are.

The SHEET and SHEETS functions were introduced in Excel 2013,
but were not introduced in PhpSpreadsheet. They are now introduced
as DUMMY functions so that they can be parsed appropriately.

Finally, in common with the "rate" changes for which I am
creating a pull request at the same time as this one:
samples/Basic/13_CalculationCyclicFormulae
PhpUnit started reporting an error like "too much regression".
The test deals with an infinite cyclic formula, and allowed
the calculation engine to run for 100 cycles. The actual number of cycles
seems irrelevant for the purpose of this test. I changed it to 15,
and PhpUnit no longer complains.
2020-05-18 12:37:35 +09:00
Adrien Crivelli 414e5695ef
Update CHANGELOG 2020-05-17 19:52:34 +09:00
oleibman 9ae521cdd4
Fix RATE, PRICE, XIRR, and XNPV Functions (#1456)
There were about 20 skipped tests for RATE and PRICE marked
"This test should be fixed". This change does that by fixing
the code for those functions, validating the existing tests,
and adding new ones. XIRR and XNPV are also substantially changed.
As part of this change, the following functions also have minor changes:

  - isValidFrequency
  - COUPDAYBS
  - COUPNUM (additional tests)
  - DB
  - DDB

PhpUnit reports 100% coverage for all the changed functions.

Since I was dealing with skipped tests, I also fixed
tests/PhpSpreadsheetTests/Writer/Xlsx/LocaleFloatsTest,
which was being skipped in Windows. I also delete the temporary
file which it creates.
There is now only one remaining test which is skipped -
ODS Reader is not complete enough to run some tests against it.
Unfortunately, that test is too complicated for me to deal with now.

In researching this change, I found several places in the code where special code was added for Gnumeric claiming:

   - Gnumeric does not handle free-format string dates
   - Gnumeric adds extra options, not available in Excel,
     for the frequency parameter for functions such as YIELD
   - Gnumeric rounds the results for DB and DDB to 2 decimal places

None of these claims is true, at least not on a recent version
of Gnumeric, and the code which supports these differences is removed.
There did not appear to be any tests targeted for
these supposed properties of Gnumeric.

The PRICE function needed relatively minor changes - mostly
additional tests for invalid input. The main problem with the PRICE
tests is that Excel appears to have a bug. The algorithm is published:
https://support.office.com/en-us/article/price-function-3ea9deac-8dfa-436f-a7c8-17ea02c21b0a
The results that Excel returns for basis codes 2 and 3 appear to be
incorrect in many cases. I have segregated these tests into a
new test PRICE3. The results of these tests agree with the published
algorithm, and to the results for LibreOffice and Gnumeric.
The results returned by Excel do not agree with them.
The tests which remain in the test PRICE all use basis codes other
than 2 or 3, and all agree with Excel, LibreOffice, and Gnumeric.

For the RATE function, there appears to be a problem with how the
secant method was implemented. I studied the implementation of RATE
in Python numpy, and adapted its implementation of secant method.
The results now agree with numpy, and, more important, with Excel.

XIRR, which calls XNPV, permits its dates to be earlier than the
start date, whereas XNPV does not. I dealt with this by renaming
the existing XNPV function to xnpvOrdered, adding a parameter to
indicate whether start date has to be earliest. XNPV calls the new
function with that parameter set to TRUE, and XIRR calls it with
the parameter set to FALSE. Some additional error checking was
added to xnpvOrdered, and also to XIRR. XIRR tests benefited
from increasing the value of FINANCIAL_MAX_ITERATIONS.

Finally, since this change is very test-related:
samples/Basic/13_CalculationCyclicFormulae
PhpUnit started reporting an error like "too much regression".
The test deals with an infinite cyclic formula, and allowed
the calculation engine to run for 100 cycles. The actual number of cycles
seems irrelevant for the purpose of this test. I changed it to 15,
and PhpUnit no longer complains.
2020-05-17 19:50:01 +09:00
Adrien Crivelli 8eaceb0f92
Fix return type docblock for the Cells::get()
PHPStorm inspections and PHPStan display an incorrect hint or
error if the special type `null` is not specified.

Closes #1398
2020-05-17 19:42:28 +09:00
Adrien Crivelli 15bd764a08
A few more invalid displayBlanksAs 2020-05-17 19:35:18 +09:00
Chris Wolcott d49567aad0
File containing a chart can be opened by Excel 2003/2013/2019
All chart examples passed the displayBlanksAs parameter as 0 instead of 'gap'.
I added a constants EMPTY_AS_GAP, EMPTY_AS_ZERO and EMPTY_AS_SPAN to the
DataSeries and then change all chart samples to use this new constant.

Fixes #1337
Closes #1448
2020-05-17 19:28:27 +09:00
Adrien Crivelli c725128a68
CSV writer also use common code to open file 2020-05-17 18:58:32 +09:00
Adrien Crivelli 5f413b8a58
Keep sample bootstrap purely in samples 2020-05-17 18:51:13 +09:00
Adrien Crivelli cfb8b2f9e3
Use current PHPUnit configuration xsd 2020-05-17 18:38:49 +09:00
Adrien Crivelli e868e58d20
Allow to run an entire folder of tests
We now can do something like:

```sh
./vendor/bin/phpunit tests/PhpSpreadsheetTests/Reader/
```
2020-05-17 18:35:55 +09:00
oleibman 7517cdd008
Improve Coverage for CSV (#1475)
I believe that both CSV Reader and Writer are 100% covered now.

There were some errors uncovered during development.

The reader specifically permits encodings other than UTF-8 to be used.
However, fgetcsv will not properly handle other encodings.
I tried replacing it with fgets/iconv/strgetcsv, but that could not
handle line breaks within a cell, even for UTF-8.
This is, I'm sure, a very rare use case.
I eventually handled it by using php://memory to hold the translated
file contents for non-UTF8. There were no tests for this situation,
and now there are (probably too many).

"Contiguous" read was not handle correctly. There is a file
in samples which uses it. It was designed to read a large sheet,
and split it into three. The first sheet was corrrect, but the
second and third were almost entirely empty. This has been corrected,
and the sample code was adapted into a formal test with assertions
to confirm that it works as designed.

I made a minor documentation change. Unlike HTML, where you never
need a BOM because you can declare the encoding in the file,
a CSV with non-ASCII characters must explicitly include a BOM
for Excel to handle it correctly. This was explained in the Reading CSV
section, but was glossed over in the Writing CSV section, which I
have updated.
2020-05-17 18:15:18 +09:00
drewblin 3090c1e73f
Support CSV files with data wrapping a lot of lines
If there is "line" splited on lot of lines we can reach limit of recursion
nesting. It's better to use while instead of recursion.

Closes #1468
2020-05-17 17:58:08 +09:00
Benedikt Franke c4931de1f9
Limit composer package to `src/`
While there is value in providing those, they also clutter IDE auto-complete feature.
Now they users can opt-in to download them via `--prefer-source` flag.

Closes #908
Closes #1424
2020-05-17 12:47:55 +09:00
Tomas Votruba bc101dafbc
README - add link to migration path to show people easier way (#1460) 2020-05-16 20:40:36 +09:00
Adrien Crivelli 7e79782dae
Remove @throws comment
Those are extremely hard to maintain properly and bring almost
no value, especially if they are outdated
2020-05-16 20:33:25 +09:00
Adrien Crivelli 6579551954
Update CHANGELOG 2020-05-16 20:27:47 +09:00
Adrien Crivelli 8967696095
Merge pull request #1292 from basbl/write-to-stream-support
Support writing to resource handles in all IWriter implementations
2020-05-16 20:25:53 +09:00
Adrien Crivelli e34535329d
Remove obsolete arguments 2020-05-16 20:25:01 +09:00
Adrien Crivelli fcf7820467
All writers can write to stream 2020-05-16 20:12:28 +09:00
Adrien Crivelli 9cdbddf3bf
Early bail out if resource cannot be opened 2020-05-16 18:08:10 +09:00
Adrien Crivelli 4b5c922731
Follow redirect to download phpDocumentor 2020-05-02 21:45:11 +09:00
Adrien Crivelli 925fafdecf
Placeholder for new changelog 2020-05-02 12:35:42 +09:00
Adrien Crivelli 588ca6beb3
Replace migration tool with RectorPHP
Fixes #1445
2020-05-02 12:34:50 +09:00
oleibman 1861412d60
Merge pull request #1 from PHPOffice/master
Resync with base project
2020-04-27 22:04:30 -07:00
basbl b60b1d25c0
Test scrutinizer 2020-04-27 21:48:56 +02:00
basbl 11499aad9a
Add resource parameter handling to html, csv and xls writers 2020-04-27 21:26:55 +02:00
basbl ccb49de301
Add support for streaming zip files in the xlsx and ods writers 2020-04-27 21:26:55 +02:00
basbl 1bcdf15533
Add maennchen/zipstream-php dependency
The built-in ZipArchive class does not have the ability
to accept streams. This means that we would always have to
write the zip to disk. The ZipStream library does offer
support for writing to streams.
2020-04-27 21:26:54 +02:00
Adrien Crivelli 385b83362f
Keep PHPUnit result out of project 2020-04-27 21:16:53 +09:00
Adrien Crivelli b07cd2028d
Don't patch PHPUnit for phpcov 2020-04-27 20:21:07 +09:00
Adrien Crivelli f1a019e492
Upgrad PHP deps 2020-04-27 19:29:45 +09:00
Gennadiy Litvinyuk a7986520f9
Removed unnecessary object creation. (#1430) 2020-04-27 12:02:49 +02:00