Merge branch 'develop' into sdt

This commit is contained in:
Ivan Lanin 2014-06-24 00:15:39 +07:00
commit b2daeed6cb
17 changed files with 598 additions and 108 deletions

View File

@ -23,17 +23,6 @@ before_script:
## Composer
- composer self-update
- composer install --prefer-source --dev
## PHP Copy/Paste Detector
- curl -o phpcpd.phar https://phar.phpunit.de/phpcpd.phar
## PHP Mess Detector
- pear config-set preferred_state beta
- printf "\n" | pecl install imagick
- pear channel-discover pear.phpmd.org
- pear channel-discover pear.pdepend.org
- pear install --alldeps phpmd/PHP_PMD
- phpenv rehash
## PHPLOC
#- curl -o phploc.phar https://phar.phpunit.de/phploc.phar
## PHPDocumentor
- mkdir -p build/docs
- mkdir -p build/coverage
@ -42,15 +31,15 @@ script:
## PHP_CodeSniffer
- ./vendor/bin/phpcs src/ tests/ --standard=PSR2 -n --ignore=src/PhpWord/Shared/PCLZip
## PHP Copy/Paste Detector
- php phpcpd.phar src/ tests/ --verbose
- ./vendor/bin/phpcpd src/ tests/ --verbose
## PHP Mess Detector
- phpmd src/,tests/ text ./phpmd.xml.dist --exclude pclzip.lib.php
## PHPLOC
#- php phploc.phar src/
- ./vendor/bin/phpmd src/,tests/ text ./phpmd.xml.dist --exclude pclzip.lib.php
## PHPUnit
- phpunit -c ./ --coverage-text --coverage-html ./build/coverage
- ./vendor/bin/phpunit -c ./ --coverage-text --coverage-html ./build/coverage
## PHPLOC
- ./vendor/bin/phploc src/
## PHPDocumentor
- vendor/bin/phpdoc -q -d ./src -t ./build/docs --ignore "*/src/PhpWord/Shared/*/*" --template="responsive-twig"
- ./vendor/bin/phpdoc -q -d ./src -t ./build/docs --ignore "*/src/PhpWord/Shared/*/*" --template="responsive-twig"
after_script:
## PHPDocumentor

View File

@ -18,7 +18,8 @@ This release added form fields (textinput, checkbox, and dropdown), drawing shap
- Chart: Basic 2D chart (pie, doughnut, bar, line, area, scatter, radar) - @ivanlanin GH-278
- Chart: 3D charts and ability to set width and height - @ivanlanin
- FormField: Ability to add textinput, checkbox, and dropdown form elements - @ivanlanin GH-266
- Security: Ability to define document protection (readOnly, comments, trackedChanges, forms) - @ivanlanin
- Setting: Ability to define document protection (readOnly, comments, trackedChanges, forms) - @ivanlanin
- Setting: Ability to remove [Compatibility Mode] text in the MS Word title bar - @ivanlanin
### Bugfixes

View File

@ -39,6 +39,9 @@
"phpunit/phpunit": "3.7.*",
"phpdocumentor/phpdocumentor":"2.*",
"squizlabs/php_codesniffer": "1.*",
"phpmd/phpmd": "2.*",
"sebastian/phpcpd": "2.*",
"phploc/phploc": "2.*",
"dompdf/dompdf":"0.6.*",
"tecnick.com/tcpdf": "6.*",
"mpdf/mpdf": "5.*"

412
composer.lock generated
View File

@ -1,9 +1,10 @@
{
"_readme": [
"This file locks the dependencies of your project to a known state",
"Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file"
"Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
"This file is @generated automatically"
],
"hash": "7d0a883164ca8e64ca34f4910aa64b96",
"hash": "50bae1209285a67796556b7ec42f64fc",
"packages": [
],
@ -706,6 +707,45 @@
],
"time": "2013-08-25 17:11:40"
},
{
"name": "pdepend/pdepend",
"version": "2.0.0",
"source": {
"type": "git",
"url": "https://github.com/pdepend/pdepend.git",
"reference": "b74f2bb68e86104cd97dfb8d74209692c9b465ce"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/pdepend/pdepend/zipball/b74f2bb68e86104cd97dfb8d74209692c9b465ce",
"reference": "b74f2bb68e86104cd97dfb8d74209692c9b465ce",
"shasum": ""
},
"require": {
"symfony/config": "@stable",
"symfony/dependency-injection": "@stable",
"symfony/filesystem": "@stable"
},
"require-dev": {
"phpunit/phpunit": "3.*@stable",
"squizlabs/php_codesniffer": "@stable"
},
"bin": [
"src/bin/pdepend"
],
"type": "library",
"autoload": {
"psr-0": {
"PDepend\\": "src/main/php/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"BSD-3-Clause"
],
"description": "Official version of pdepend to be handled with Composer",
"time": "2014-05-21 09:48:10"
},
{
"name": "phenx/php-font-lib",
"version": "0.2.2",
@ -1406,6 +1446,98 @@
],
"time": "2013-09-09 06:13:02"
},
{
"name": "phploc/phploc",
"version": "2.0.5",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/phploc.git",
"reference": "d177c22e2a08e448f7bdfa762045f7bd086834d7"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/sebastianbergmann/phploc/zipball/d177c22e2a08e448f7bdfa762045f7bd086834d7",
"reference": "d177c22e2a08e448f7bdfa762045f7bd086834d7",
"shasum": ""
},
"require": {
"php": ">=5.3.3",
"sebastian/finder-facade": ">=1.1.0",
"sebastian/git": ">=1.0.0",
"sebastian/version": ">=1.0.3",
"symfony/console": ">=2.2.0"
},
"bin": [
"phploc"
],
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "2.0-dev"
}
},
"autoload": {
"classmap": [
"src/"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"BSD-3-Clause"
],
"authors": [
{
"name": "Sebastian Bergmann",
"email": "sebastian@phpunit.de",
"role": "lead"
}
],
"description": "A tool for quickly measuring the size of a PHP project.",
"homepage": "https://github.com/sebastianbergmann/phploc",
"time": "2014-04-27 06:47:27"
},
{
"name": "phpmd/phpmd",
"version": "2.0.0",
"source": {
"type": "git",
"url": "https://github.com/phpmd/phpmd.git",
"reference": "68ced5452910d3555a38720bd87f5f2356c5a003"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/phpmd/phpmd/zipball/68ced5452910d3555a38720bd87f5f2356c5a003",
"reference": "68ced5452910d3555a38720bd87f5f2356c5a003",
"shasum": ""
},
"require": {
"pdepend/pdepend": "2.0.*",
"php": ">=5.3.0",
"symfony/config": "@stable",
"symfony/dependency-injection": "@stable",
"symfony/filesystem": "@stable"
},
"bin": [
"src/bin/phpmd"
],
"type": "library",
"autoload": {
"psr-0": {
"PHPMD\\": "src/main/php",
"PDepend\\": "vendor/pdepend/pdepend/src/main/php/"
}
},
"notification-url": "https://packagist.org/downloads/",
"include-path": [
"../../pdepend/pdepend/src/main/php",
"src/main/php"
],
"license": [
"BSD-3-Clause"
],
"description": "Official version of PHPMD handled with Composer.",
"time": "2014-05-21 12:45:23"
},
{
"name": "phpoption/phpoption",
"version": "1.4.0",
@ -1907,6 +2039,177 @@
],
"time": "2012-12-21 11:40:51"
},
{
"name": "sebastian/finder-facade",
"version": "1.1.0",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/finder-facade.git",
"reference": "1e396fda3449fce9df032749fa4fa2619e0347e0"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/sebastianbergmann/finder-facade/zipball/1e396fda3449fce9df032749fa4fa2619e0347e0",
"reference": "1e396fda3449fce9df032749fa4fa2619e0347e0",
"shasum": ""
},
"require": {
"symfony/finder": ">=2.2.0",
"theseer/fdomdocument": ">=1.3.1"
},
"type": "library",
"autoload": {
"classmap": [
"src/"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"BSD-3-Clause"
],
"authors": [
{
"name": "Sebastian Bergmann",
"email": "sebastian@phpunit.de",
"role": "lead"
}
],
"description": "FinderFacade is a convenience wrapper for Symfony's Finder component.",
"homepage": "https://github.com/sebastianbergmann/finder-facade",
"time": "2013-05-28 06:10:03"
},
{
"name": "sebastian/git",
"version": "2.0.0",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/git.git",
"reference": "572c35353fefcc8607d6fef0e362a9f3a5e84d96"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/sebastianbergmann/git/zipball/572c35353fefcc8607d6fef0e362a9f3a5e84d96",
"reference": "572c35353fefcc8607d6fef0e362a9f3a5e84d96",
"shasum": ""
},
"require": {
"php": ">=5.3.3"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "2.0-dev"
}
},
"autoload": {
"classmap": [
"src/"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"BSD-3-Clause"
],
"authors": [
{
"name": "Sebastian Bergmann",
"email": "sebastian@phpunit.de",
"role": "lead"
}
],
"description": "Simple wrapper for Git",
"homepage": "http://www.github.com/sebastianbergmann/git",
"keywords": [
"git"
],
"time": "2014-06-14 07:12:53"
},
{
"name": "sebastian/phpcpd",
"version": "2.0.1",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/phpcpd.git",
"reference": "a9462153f2dd90466a010179901d31fbff598365"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/sebastianbergmann/phpcpd/zipball/a9462153f2dd90466a010179901d31fbff598365",
"reference": "a9462153f2dd90466a010179901d31fbff598365",
"shasum": ""
},
"require": {
"php": ">=5.3.3",
"phpunit/php-timer": ">=1.0.4",
"sebastian/finder-facade": ">=1.1.0",
"sebastian/version": ">=1.0.3",
"symfony/console": ">=2.2.0",
"theseer/fdomdocument": "~1.4"
},
"bin": [
"phpcpd"
],
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "2.0-dev"
}
},
"autoload": {
"classmap": [
"src/"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"BSD-3-Clause"
],
"authors": [
{
"name": "Sebastian Bergmann",
"email": "sebastian@phpunit.de",
"role": "lead"
}
],
"description": "Copy/Paste Detector (CPD) for PHP code.",
"homepage": "https://github.com/sebastianbergmann/phpcpd",
"time": "2014-03-31 09:25:30"
},
{
"name": "sebastian/version",
"version": "1.0.3",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/version.git",
"reference": "b6e1f0cf6b9e1ec409a0d3e2f2a5fb0998e36b43"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/sebastianbergmann/version/zipball/b6e1f0cf6b9e1ec409a0d3e2f2a5fb0998e36b43",
"reference": "b6e1f0cf6b9e1ec409a0d3e2f2a5fb0998e36b43",
"shasum": ""
},
"type": "library",
"autoload": {
"classmap": [
"src/"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"BSD-3-Clause"
],
"authors": [
{
"name": "Sebastian Bergmann",
"email": "sebastian@phpunit.de",
"role": "lead"
}
],
"description": "Library that helps with managing the version number of Git-hosted PHP projects",
"homepage": "https://github.com/sebastianbergmann/version",
"time": "2014-03-07 15:35:33"
},
{
"name": "squizlabs/php_codesniffer",
"version": "1.5.3",
@ -2089,6 +2392,65 @@
"homepage": "http://symfony.com",
"time": "2014-05-22 08:54:24"
},
{
"name": "symfony/dependency-injection",
"version": "v2.5.0",
"target-dir": "Symfony/Component/DependencyInjection",
"source": {
"type": "git",
"url": "https://github.com/symfony/DependencyInjection.git",
"reference": "5dfb4c2b74c4976efe1efa783370da656a2dd742"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/DependencyInjection/zipball/5dfb4c2b74c4976efe1efa783370da656a2dd742",
"reference": "5dfb4c2b74c4976efe1efa783370da656a2dd742",
"shasum": ""
},
"require": {
"php": ">=5.3.3"
},
"require-dev": {
"symfony/config": "~2.2",
"symfony/expression-language": "~2.4",
"symfony/yaml": "~2.0"
},
"suggest": {
"symfony/config": "",
"symfony/proxy-manager-bridge": "Generate service proxies to lazy load them",
"symfony/yaml": ""
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "2.5-dev"
}
},
"autoload": {
"psr-0": {
"Symfony\\Component\\DependencyInjection\\": ""
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Fabien Potencier",
"email": "fabien@symfony.com",
"homepage": "http://fabien.potencier.org",
"role": "Lead Developer"
},
{
"name": "Symfony Community",
"homepage": "http://symfony.com/contributors"
}
],
"description": "Symfony DependencyInjection Component",
"homepage": "http://symfony.com",
"time": "2014-05-12 09:28:39"
},
{
"name": "symfony/event-dispatcher",
"version": "v2.5.0",
@ -2524,11 +2886,11 @@
},
{
"name": "tecnick.com/tcpdf",
"version": "6.0.083",
"version": "6.0.086",
"source": {
"type": "git",
"url": "git://git.code.sf.net/p/tcpdf/code",
"reference": "d6a2206ab366f493680a22151429f17fd045fe04"
"reference": "b1c0cc74a84948029d8c9824736d9021871a63a7"
},
"require": {
"php": ">=5.3.0"
@ -2577,7 +2939,47 @@
"pdf417",
"qrcode"
],
"time": "2014-05-29 18:28:56"
"time": "2014-06-20 15:28:34"
},
{
"name": "theseer/fdomdocument",
"version": "1.5.0",
"source": {
"type": "git",
"url": "https://github.com/theseer/fDOMDocument.git",
"reference": "137aa3b13bef05b4e301899cbabdaf7d501847d2"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/theseer/fDOMDocument/zipball/137aa3b13bef05b4e301899cbabdaf7d501847d2",
"reference": "137aa3b13bef05b4e301899cbabdaf7d501847d2",
"shasum": ""
},
"require": {
"ext-dom": "*",
"lib-libxml": "*",
"php": ">=5.3.3"
},
"type": "library",
"autoload": {
"classmap": [
"src/"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"BSD-3-Clause"
],
"authors": [
{
"name": "Arne Blankerts",
"email": "arne@blankerts.de",
"role": "lead"
}
],
"description": "The classes contained within this repository extend the standard DOM to use exceptions at all occasions of errors instead of PHP warnings or notices. They also add various custom methods and shortcuts for convenience and to simplify the usage of DOM.",
"homepage": "https://github.com/theseer/fDOMDocument",
"time": "2014-02-19 00:20:43"
},
{
"name": "twig/twig",

View File

@ -87,3 +87,12 @@ Apply 'HeadingN' paragraph style to TextRun or Link. Sample code:
// Link
$section->addLink('https://github.com/', 'GitHub', 'Link', 'Heading2');
Remove [Compatibility Mode] text in the MS Word title bar
---------------------------------------------------------
Use the ``Metadata\Compatibility\setOoxmlVersion(n)`` method with ``n`` is the version of Office (14 = Office 2010, 15 = Office 2013).
.. code-block:: php
$phpWord->getCompatibility()->setOoxmlVersion(15);

View File

@ -1053,6 +1053,14 @@ $textrun->addLink('https://github.com/PHPOffice/PHPWord', 'PHPWord', 'Link');
$section->addLink('https://github.com/', 'GitHub', 'Link', 'Heading2');
```
## Remove [Compatibility Mode] text in the MS Word title bar
Use the `Metadata\Compatibility\setOoxmlVersion(n)` method with `n` is the version of Office (14 = Office 2010, 15 = Office 2013).
```php
$phpWord->getCompatibility()->setOoxmlVersion(15);
```
# Frequently asked questions
## Is this the same with PHPWord that I found in CodePlex?

View File

@ -0,0 +1,62 @@
<?php
/**
* This file is part of PHPWord - A pure PHP library for reading and writing
* word processing documents.
*
* PHPWord is free software distributed under the terms of the GNU Lesser
* General Public License version 3 as published by the Free Software Foundation.
*
* For the full copyright and license information, please read the LICENSE
* file that was distributed with this source code. For the full list of
* contributors, visit https://github.com/PHPOffice/PHPWord/contributors.
*
* @link https://github.com/PHPOffice/PHPWord
* @copyright 2010-2014 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/
namespace PhpOffice\PhpWord\Metadata;
/**
* Compatibility setting class
*
* @since 0.12.0
* @link http://www.datypic.com/sc/ooxml/t-w_CT_Compat.html
*/
class Compatibility
{
/**
* OOXML version
*
* 12 = 2007
* 14 = 2010
* 15 = 2013
*
* @var int
* @link http://msdn.microsoft.com/en-us/library/dd909048%28v=office.12%29.aspx
*/
private $ooxmlVersion = 12;
/**
* Get OOXML version
*
* @return int
*/
public function getOoxmlVersion()
{
return $this->ooxmlVersion;
}
/**
* Set OOXML version
*
* @param int $value
* @return self
*/
public function setOoxmlVersion($value)
{
$this->ooxmlVersion = $value;
return $this;
}
}

View File

@ -81,17 +81,19 @@ class PhpWord
*/
public function __construct()
{
// Collection
$collections = array('Titles', 'Footnotes', 'Endnotes', 'Charts');
foreach ($collections as $collection) {
$class = 'PhpOffice\\PhpWord\\Collection\\' . $collection;
$this->collections[$collection] = new $class();
}
$metadata = 'PhpOffice\\PhpWord\\Metadata\\Protection';
$this->metadata['Protection'] = new $metadata();
$metadata = 'PhpOffice\\PhpWord\\Metadata\\DocInfo';
$this->metadata['DocInfo'] = new $metadata();
// Metadata
$metadata = array('DocInfo', 'Protection', 'Compatibility');
foreach ($metadata as $meta) {
$class = 'PhpOffice\\PhpWord\\Metadata\\' . $meta;
$this->metadata[$meta] = new $class();
}
}
/**
@ -147,9 +149,6 @@ class PhpWord
if (in_array($function, $addStyle)) {
return forward_static_call_array(array('PhpOffice\\PhpWord\\Style', $function), $args);
}
// All other methods
return null;
}
/**
@ -173,6 +172,17 @@ class PhpWord
return $this->metadata['Protection'];
}
/**
* Get compatibility
*
* @return \PhpOffice\PhpWord\Metadata\Compatibility
* @since 0.12.0
*/
public function getCompatibility()
{
return $this->metadata['Compatibility'];
}
/**
* Get all sections
*
@ -331,7 +341,7 @@ class PhpWord
/**
* Set document properties object
*
* @param \PhpOffice\PhpWord\Metadata\DocInfo
* @param \PhpOffice\PhpWord\Metadata\DocInfo $documentProperties
* @return self
* @deprecated 0.12.0
* @codeCoverageIgnore

View File

@ -24,6 +24,13 @@ namespace PhpOffice\PhpWord\Writer\Word2007\Part;
*/
class Settings extends AbstractPart
{
/**
* Settings value
*
* @var array
*/
private $settings = array();
/**
* Write part
*
@ -31,7 +38,7 @@ class Settings extends AbstractPart
*/
public function write()
{
$settings = $this->getSettings();
$this->getSettings();
$xmlWriter = $this->getXmlWriter();
@ -45,7 +52,7 @@ class Settings extends AbstractPart
$xmlWriter->writeAttribute('xmlns:v', 'urn:schemas-microsoft-com:vml');
$xmlWriter->writeAttribute('xmlns:w10', 'urn:schemas-microsoft-com:office:word');
foreach ($settings as $settingKey => $settingValue) {
foreach ($this->settings as $settingKey => $settingValue) {
$this->writeSetting($xmlWriter, $settingKey, $settingValue);
}
@ -84,63 +91,19 @@ class Settings extends AbstractPart
/**
* Get settings
*
* @return array
*/
private function getSettings()
{
// Default settings
$settings = $this->getDefaultSettings();
// Protection
$protection = $this->getParentWriter()->getPhpWord()->getProtection();
if ($protection->getEditing() !== null) {
$settings['w:documentProtection'] = array(
'@attributes' => array(
'w:enforcement' => 1,
'w:edit' => $protection->getEditing(),
)
);
}
return $settings;
}
/**
* Get default settings
*
* @return array
*/
private function getDefaultSettings()
{
return array(
$this->settings = array(
'w:zoom' => array('@attributes' => array('w:percent' => '100')),
'w:view' => array('@attributes' => array('w:val' => 'print')),
'w:embedSystemFonts' => '',
'w:defaultTabStop' => array('@attributes' => array('w:val' => '708')),
'w:hyphenationZone' => array('@attributes' => array('w:val' => '425')),
'w:doNotHyphenateCaps' => '',
'w:characterSpacingControl' => array('@attributes' => array('w:val' => 'doNotCompress')),
'w:doNotValidateAgainstSchema' => '',
'w:doNotDemarcateInvalidXml' => '',
'w:compat' => array(
'w:useNormalStyleForList' => '',
'w:doNotUseIndentAsNumberingTabStop' => '',
'w:useAltKinsokuLineBreakRules' => '',
'w:allowSpaceOfSameStyleInTable' => '',
'w:doNotSuppressIndentation' => '',
'w:doNotAutofitConstrainedTables' => '',
'w:autofitToFirstFixedWidthCell' => '',
'w:underlineTabInNumList' => '',
'w:displayHangulFixedWidth' => '',
// Commented for GH-274
// 'w:splitPgBreakAndParaMark' => '',
'w:doNotVertAlignCellWithSp' => '',
'w:doNotBreakConstrainedForcedTable' => '',
'w:doNotVertAlignInTxbx' => '',
'w:useAnsiKerningPairs' => '',
'w:cachedColBalance' => '',
),
'w:themeFontLang' => array('@attributes' => array('w:val' => 'en-US')),
'w:decimalSymbol' => array('@attributes' => array('w:val' => '.')),
'w:listSeparator' => array('@attributes' => array('w:val' => ';')),
'w:compat' => '',
'm:mathPr' => array(
'm:mathFont' => array('@attributes' => array('m:val' => 'Cambria Math')),
'm:brkBin' => array('@attributes' => array('m:val' => 'before')),
@ -154,8 +117,6 @@ class Settings extends AbstractPart
'm:intLim' => array('@attributes' => array('m:val' => 'subSup')),
'm:naryLim' => array('@attributes' => array('m:val' => 'undOvr')),
),
'w:uiCompat97To2003' => '',
'w:themeFontLang' => array('@attributes' => array('w:val' => 'de-DE')),
'w:clrSchemeMapping' => array(
'@attributes' => array(
'w:bg1' => 'light1',
@ -172,10 +133,41 @@ class Settings extends AbstractPart
'w:followedHyperlink' => 'followedHyperlink',
),
),
'w:doNotIncludeSubdocsInStats' => '',
'w:doNotAutoCompressPictures' => '',
'w:decimalSymbol' => array('@attributes' => array('w:val' => ',')),
'w:listSeparator' => array('@attributes' => array('w:val' => ';')),
);
// Other settings
$this->getProtection();
$this->getCompatibility();
}
/**
* Get protection settings
*/
private function getProtection()
{
$protection = $this->getParentWriter()->getPhpWord()->getProtection();
if ($protection->getEditing() !== null) {
$this->settings['w:documentProtection'] = array(
'@attributes' => array(
'w:enforcement' => 1,
'w:edit' => $protection->getEditing(),
)
);
}
}
/**
* Get compatibility setting
*/
private function getCompatibility()
{
$compatibility = $this->getParentWriter()->getPhpWord()->getCompatibility();
if ($compatibility->getOoxmlVersion() !== null) {
$this->settings['w:compat']['w:compatSetting'] = array('@attributes' => array(
'w:name' => 'compatibilityMode',
'w:uri' => 'http://schemas.microsoft.com/office/word',
'w:val' => $compatibility->getOoxmlVersion(),
));
}
}
}

View File

@ -43,12 +43,11 @@ class AutoloaderTest extends \PHPUnit_Framework_TestCase
*/
public function testAutoload()
{
$declared = get_declared_classes();
$declaredCount = count($declared);
$declaredCount = count(get_declared_classes());
Autoloader::autoload('Foo');
$this->assertEquals(
$this->assertCount(
$declaredCount,
count(get_declared_classes()),
get_declared_classes(),
'PhpOffice\\PhpWord\\Autoloader::autoload() is trying to load ' .
'classes outside of the PhpOffice\\PhpWord namespace'
);

View File

@ -28,8 +28,7 @@ class CollectionTest extends \PHPUnit_Framework_TestCase
$object->addItem(new Footnote()); // addItem #1
$this->assertEquals(2, $object->addItem(new Footnote())); // addItem #2. Should returns new item index
$this->assertEquals(2, $object->countItems()); // There are two items now
$this->assertEquals(2, count($object->getItems())); // getItems returns array
$this->assertCount(2, $object->getItems()); // getItems returns array
$this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Footnote', $object->getItem(1)); // getItem returns object
$this->assertNull($object->getItem(3)); // getItem returns null when invalid index is referenced

View File

@ -40,7 +40,7 @@ class MediaTest extends \PHPUnit_Framework_TestCase
*/
public function testCountSectionMediaElementsWithNull()
{
$this->assertEquals(Media::countElements('section'), 0);
$this->assertEquals(0, Media::countElements('section'));
}
/**
@ -57,7 +57,7 @@ class MediaTest extends \PHPUnit_Framework_TestCase
Media::addElement('section', 'object', $object);
Media::addElement('section', 'object', $object);
$this->assertEquals(3, Media::countElements('section'));
$this->assertCount(3, Media::getElements('section'));
}
/**
@ -69,8 +69,7 @@ class MediaTest extends \PHPUnit_Framework_TestCase
$actual = Media::addElement('section', 'link', 'http://test.com');
$this->assertEquals($expected, $actual);
$this->assertEquals(1, Media::countElements('section', 'link'));
$this->assertEquals(1, count(Media::getElements('section', 'link')));
$this->assertCount(1, Media::getElements('section', 'link'));
}
/**
@ -84,8 +83,7 @@ class MediaTest extends \PHPUnit_Framework_TestCase
Media::addElement('header1', 'image', $local, new Image($local));
Media::addElement('header1', 'image', $remote, new Image($remote));
$this->assertEquals(2, Media::countElements('header1'));
$this->assertEquals(2, count(Media::getElements('header1')));
$this->assertCount(2, Media::getElements('header1'));
$this->assertEmpty(Media::getElements('header2'));
}
@ -100,10 +98,10 @@ class MediaTest extends \PHPUnit_Framework_TestCase
Media::addElement('footer1', 'image', $local, new Image($local));
Media::addElement('footer1', 'image', $remote, new Image($remote));
$this->assertEquals(2, Media::countElements('footer1'));
$this->assertCount(2, Media::getElements('footer1'));
Media::resetElements();
$this->assertEquals(0, Media::countElements('footer1'));
$this->assertCount(0, Media::getElements('footer1'));
}
/**

View File

@ -47,7 +47,7 @@ class PhpWordTest extends \PHPUnit_Framework_TestCase
{
$phpWord = new PhpWord();
$phpWord->addSection();
$this->assertEquals(1, count($phpWord->getSections()));
$this->assertCount(1, $phpWord->getSections());
}
/**

View File

@ -34,7 +34,7 @@ class HtmlTest extends \PHPUnit_Framework_TestCase
// Default
$section = new Section(1);
$this->assertEquals(0, $section->countElements());
$this->assertCount(0, $section->getElements());
// Heading
$styles = array('strong', 'em', 'sup', 'sub');
@ -52,7 +52,7 @@ class HtmlTest extends \PHPUnit_Framework_TestCase
// Add HTML
Html::addHtml($section, $content);
$this->assertEquals(7, $section->countElements());
$this->assertCount(7, $section->getElements());
// Other parts
$section = new Section(1);

View File

@ -119,7 +119,7 @@ class ParagraphTest extends \PHPUnit_Framework_TestCase
{
$object = new Paragraph();
$object->setTabs(array(new Tab('left', 1550), new Tab('right', 5300)));
$this->assertEquals(2, count($object->getTabs()));
$this->assertCount(2, $object->getTabs());
}
/**

View File

@ -64,7 +64,7 @@ class StyleTest extends \PHPUnit_Framework_TestCase
Style::addTableStyle('Table', $table);
Style::setDefaultParagraphStyle($paragraph);
$this->assertEquals(count($styles), Style::countStyles());
$this->assertCount(count($styles), Style::getStyles());
foreach ($styles as $name => $style) {
$this->assertInstanceOf("PhpOffice\\PhpWord\\Style\\{$style}", Style::getStyle($name));
}
@ -75,6 +75,8 @@ class StyleTest extends \PHPUnit_Framework_TestCase
}
/**
* Test default paragraph style
*
* @covers ::setDefaultParagraphStyle
* @test
*/

View File

@ -49,4 +49,20 @@ class SettingsTest extends \PHPUnit_Framework_TestCase
$path = '/w:settings/w:documentProtection';
$this->assertTrue($doc->elementExists($path, $file));
}
/**
* Test compatibility
*/
public function testCompatibility()
{
$phpWord = new PhpWord();
$phpWord->getCompatibility()->setOoxmlVersion(15);
$doc = TestHelperDOCX::getDocument($phpWord);
$file = 'word/settings.xml';
$path = '/w:settings/w:compat/w:compatSetting';
$this->assertTrue($doc->elementExists($path, $file));
}
}