-
Notifications
You must be signed in to change notification settings - Fork 2.7k
FBnil patch blocks #1147
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
FBnil patch blocks #1147
Conversation
See TemplateProcessor.php for what has changed
I removed the regexp (although I had a working regexp, it seems PHP7 does not like multiple non-greedy patterns. The need to anchor the query to <?xml> is very dirty). So I implemented the findBlockStart() and findBlockEnd() that search upto a paragraph change <w:p>, This has been tested with LibreOffice generated docx (that features <w:p>) and real MSOffice documents (that features extra parameters, nb: <w:p w:rsidR="00AC46F7" w:rsidRDefault="00AC46F7" w:rsidP="00AC46F7">). As well as a few new testcases to cover the new functionality. What is new? * Blocks with variables inside now expand like Rows, with #n at the end (and you can get the old behavior back with an extra parameter) * Block functions now return sensible information instead of void * you can throw exceptions if you can not find a block (enabled by an extra parameter) * getBlock() implemented See also TemplateProcessorTest.php for the additional test cases
…and phpunit give a green flag
Updating all phpcs warnings given. Basically merge develop->FBnil-patch-blocks
Fixed all the warnings phpcs gave
renamed variables to fix scrutinizer errors
…into FBnil-patch-blocks Conflicts: src/PhpWord/TemplateProcessor.php
updating through Webbrowser as git pull and git status state that I already committed the latest... silly...
…into FBnil-patch-blocks
Not sure what to do with the low scores of Scrutinizer. I can roll back the duplication of code, and use less functions-in-functions? (at a cost of more duplicate code, get it to B and C instead of D) |
…s in the document
Updates on 2017-10-02
You know the problem with adding lists? You need to put a block before and after one numbered list like so:
This then can be used with cloneBlock('myblock',2) and setValue('myelement#1', 'first substitution') etc. Now we allow this:
And we use: cloneBlock('myelement/',2) and setValue('myelement#1/', 'first substitution') etc.
We also added zipAddFromString(), which works like this if you want to replace an image in the docx, while keeping the position and size of that image in the document:
So
|
Received confirmation it closes #1121 |
Well, I can not get rid of the conflict, but I guess TemplateProcessor has been rewritten and is now conflicting with the parameters the old TemplateProcessor had (and I've added quite a few new parameters). Ok, latest additions: Segments now allow to search left or right. So take a needle, find that position, in the past, we only could search around it, that is, start tag was to the left and end tag was to the right, now we can search for both start/end tags to the right or left. The rest of the functional additions will be through traits or subclasses. |
@FBnil do you think you could come up with some proper unit testing for the TemplateProcessor. |
Will try. It seems only space related problems that Travis is giving. Give me a few days. |
@troosan Just to be clear I understand you: Testcases for the current TemplateProcessor in dev-master ? And with "proper", that includes reflections and maybe mocking? |
There currently are some tests defined already (in TemplateProcessorTest) but I have a feeling a lot of cases are not covered by those tests. That's the reason why we have so many issues with it. I would like to have a reasonable assurance that when we touch this class we do not break anything else. Today I really am not. |
I just tested there changes in my document where i'm having problems with cloning docs, using php 7.1. Looks like this definitely solved my problems. Keep up the good work! I hope this will be merged and released soon! |
I installed the fixer with My testing script is now: PROJECT=/var/www/html/cvprima
cd $PROJECT/vendor
cp phpoffice/PHPWord/src/PhpWord/TemplateProcessor.php phpoffice/phpword/src/PhpWord/TemplateProcessor.php;
phpunit -c $PROJECT/vendor/phpoffice/PHPWord/phpunit.xml.dist --bootstrap autoload.php phpoffice/PHPWord/tests/PhpWord/TemplateProcessorTest.php --coverage-html $PROJECT/public/coverage
cd -
cd /home/prima/github/PHPWord
phpcs ./src/PhpWord/TemplateProcessor.php ./tests/PhpWord/TemplateProcessorTest.php --standard=PSR2 --colors -v
phpmd src/,tests/ text ./phpmd.xml.dist --exclude pclzip.lib.php
phpdoc -q -d ./src -t ./build/docs --ignore "*/src/PhpWord/Shared/*/*" --template="responsive-twig"
php-cs-fixer fix --diff --verbose --dry-run ./src/PhpWord/TemplateProcessor.php
php-cs-fixer fix --diff --verbose --dry-run ./tests/PhpWord/TemplateProcessorTest.php
cd - Now looking into making more testcases... |
@MyDigitalLife I'd like to have a release (0.16?) dedicated to merge the different fixes/improvements on the TemplateProcessor, I guess this will need a bit of work :-P |
@troosan Could you create a milestone for 0.16 and add this then? If there are any other issues that need to be looked at I can give it a go. |
2d9f999
to
e458249
Compare
I removed the regexp (although I had a working regexp, it seems PHP7 does not like multiple non-greedy patterns. The need to anchor the query to <?xml> is very dirty -- to get one match only, instead of multipe --). (I have a Perl background and am very good with regular expressions)
So I implemented the findBlockStart() and findBlockEnd() that search upto a paragraph change <w:p>, This has been tested with LibreOffice generated docx (that features <w:p>) and real MSOffice documents (that features extra parameters, nb: <w:p w:rsidR="00AC46F7" w:rsidRDefault="00AC46F7" w:rsidP="00AC46F7">). As well as a few new testcases to cover the new functionality.
What is new?
Files modified:
./src/PhpWord/TemplateProcessor.php
./tests/PhpWord/OpenTemplateProcessor.php [EDIT: IS NOT REQUIRED ANYMORE]
./tests/PhpWord/TemplateProcessorTest.php
OpenTemplateProcessor is a subclass that allows access to the private fields in TemplateProcessor. This is required for good testing of the output results.
Tested with:
Todo: Tested under PHP 7.0.22 maybe try older versions too (although no PHP7-only have been used).