Code formatting for PSR1 & PSR2 - Part 3
This commit is contained in:
parent
46a0768d29
commit
92cfa12d71
|
|
@ -16,8 +16,14 @@ class AutoloaderTest extends PHPUnit_Framework_TestCase
|
|||
|
||||
public function testAutoloadLegacy()
|
||||
{
|
||||
$this->assertNull(PHPWord_Autoloader::load('Foo'), 'PHPWord_Autoloader::load() is trying to load classes outside of the PHPWord namespace');
|
||||
$this->assertTrue(PHPWord_Autoloader::load('PHPWord'), 'PHPWord_Autoloader::load() failed to autoload the PHPWord class');
|
||||
$this->assertNull(
|
||||
PHPWord_Autoloader::load('Foo'),
|
||||
'PHPWord_Autoloader::load() is trying to load classes outside of the PHPWord namespace'
|
||||
);
|
||||
$this->assertTrue(
|
||||
PHPWord_Autoloader::load('PHPWord'),
|
||||
'PHPWord_Autoloader::load() failed to autoload the PHPWord class'
|
||||
);
|
||||
}
|
||||
|
||||
public function testAutoload()
|
||||
|
|
@ -25,8 +31,20 @@ class AutoloaderTest extends PHPUnit_Framework_TestCase
|
|||
$declared = get_declared_classes();
|
||||
$declaredCount = count($declared);
|
||||
Autoloader::autoload('Foo');
|
||||
$this->assertEquals($declaredCount, count(get_declared_classes()), 'PhpOffice\\PhpWord\\Autoloader::autoload() is trying to load classes outside of the PhpOffice\\PhpWord namespace');
|
||||
Autoloader::autoload('PhpOffice\\PhpWord\\Exceptions\\InvalidStyleException'); // TODO change this class to the main PHPWord class when it is namespaced
|
||||
$this->assertTrue(in_array('PhpOffice\\PhpWord\\Exceptions\\InvalidStyleException', get_declared_classes()), 'PhpOffice\\PhpWord\\Autoloader::autoload() failed to autoload the PhpOffice\\PhpWord\\Exceptions\\InvalidStyleException class');
|
||||
$this->assertEquals(
|
||||
$declaredCount,
|
||||
count(get_declared_classes()),
|
||||
'PhpOffice\\PhpWord\\Autoloader::autoload() is trying to load classes ' .
|
||||
'outside of the PhpOffice\\PhpWord namespace'
|
||||
);
|
||||
// TODO change this class to the main PHPWord class when it is namespaced
|
||||
Autoloader::autoload(
|
||||
'PhpOffice\\PhpWord\\Exceptions\\InvalidStyleException'
|
||||
);
|
||||
$this->assertTrue(
|
||||
in_array('PhpOffice\\PhpWord\\Exceptions\\InvalidStyleException', get_declared_classes()),
|
||||
'PhpOffice\\PhpWord\\Autoloader::autoload() failed to autoload the ' .
|
||||
'PhpOffice\\PhpWord\\Exceptions\\InvalidStyleException class'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,7 +16,11 @@ class IOFactoryTest extends \PHPUnit_Framework_TestCase
|
|||
{
|
||||
public function testGetSearchLocations()
|
||||
{
|
||||
$this->assertAttributeEquals(PHPWord_IOFactory::getSearchLocations(), '_searchLocations', 'PHPWord_IOFactory');
|
||||
$this->assertAttributeEquals(
|
||||
PHPWord_IOFactory::getSearchLocations(),
|
||||
'_searchLocations',
|
||||
'PHPWord_IOFactory'
|
||||
);
|
||||
}
|
||||
|
||||
public function testSetSearchLocationsWithArray()
|
||||
|
|
@ -38,7 +42,11 @@ class IOFactoryTest extends \PHPUnit_Framework_TestCase
|
|||
{
|
||||
PHPWord_IOFactory::setSearchLocations(array());
|
||||
PHPWord_IOFactory::addSearchLocation('type', 'location', 'classname');
|
||||
$this->assertAttributeEquals(array(array('type' => 'type', 'path' => 'location', 'class' => 'classname')), '_searchLocations', 'PHPWord_IOFactory');
|
||||
$this->assertAttributeEquals(
|
||||
array(array('type' => 'type', 'path' => 'location', 'class' => 'classname')),
|
||||
'_searchLocations',
|
||||
'PHPWord_IOFactory'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -57,6 +65,9 @@ class IOFactoryTest extends \PHPUnit_Framework_TestCase
|
|||
{
|
||||
$oPHPWord = new PHPWord();
|
||||
|
||||
$this->assertEquals(PHPWord_IOFactory::createWriter($oPHPWord, 'Word2007'), new PHPWord_Writer_Word2007($oPHPWord));
|
||||
$this->assertEquals(
|
||||
PHPWord_IOFactory::createWriter($oPHPWord, 'Word2007'),
|
||||
new PHPWord_Writer_Word2007($oPHPWord)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,7 +26,11 @@ class PreserveTextTest extends \PHPUnit_Framework_TestCase
|
|||
|
||||
public function testConstructWithArray()
|
||||
{
|
||||
$oPreserveText = new PHPWord_Section_Footer_PreserveText('text', array('align' => 'center'), array('marginLeft' => 600, 'marginRight' => 600, 'marginTop' => 600, 'marginBottom' => 600));
|
||||
$oPreserveText = new PHPWord_Section_Footer_PreserveText(
|
||||
'text',
|
||||
array('align' => 'center'),
|
||||
array('marginLeft' => 600, 'marginRight' => 600, 'marginTop' => 600, 'marginBottom' => 600)
|
||||
);
|
||||
$this->assertInstanceOf('PHPWord_Style_Font', $oPreserveText->getFontStyle());
|
||||
$this->assertInstanceOf('PHPWord_Style_Paragraph', $oPreserveText->getParagraphStyle());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -87,7 +87,9 @@ class FooterTest extends \PHPUnit_Framework_TestCase
|
|||
public function testAddMemoryImage()
|
||||
{
|
||||
$oFooter = new PHPWord_Section_Footer(1);
|
||||
$element = $oFooter->addMemoryImage('https://assets.mozillalabs.com/Brands-Logos/Thunderbird/logo-only/thunderbird_logo-only_RGB.png');
|
||||
$element = $oFooter->addMemoryImage(
|
||||
'https://assets.mozillalabs.com/Brands-Logos/Thunderbird/logo-only/thunderbird_logo-only_RGB.png'
|
||||
);
|
||||
|
||||
$this->assertCount(1, $oFooter->getElements());
|
||||
$this->assertInstanceOf('PHPWord_Section_MemoryImage', $element);
|
||||
|
|
|
|||
|
|
@ -83,7 +83,9 @@ class HeaderTest extends \PHPUnit_Framework_TestCase
|
|||
public function testAddMemoryImage()
|
||||
{
|
||||
$oHeader = new PHPWord_Section_Header(1);
|
||||
$element = $oHeader->addMemoryImage('https://assets.mozillalabs.com/Brands-Logos/Thunderbird/logo-only/thunderbird_logo-only_RGB.png');
|
||||
$element = $oHeader->addMemoryImage(
|
||||
'https://assets.mozillalabs.com/Brands-Logos/Thunderbird/logo-only/thunderbird_logo-only_RGB.png'
|
||||
);
|
||||
|
||||
$this->assertCount(1, $oHeader->getElements());
|
||||
$this->assertInstanceOf('PHPWord_Section_MemoryImage', $element);
|
||||
|
|
|
|||
|
|
@ -28,7 +28,11 @@ class ImageTest extends \PHPUnit_Framework_TestCase
|
|||
\DIRECTORY_SEPARATOR,
|
||||
array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'images', 'firefox.png')
|
||||
);
|
||||
$oImage = new PHPWord_Section_Image($src, array('width' => 210, 'height' => 210, 'align' => 'center', 'wrappingStyle' => \PHPWord_Style_Image::WRAPPING_STYLE_BEHIND));
|
||||
$oImage = new PHPWord_Section_Image(
|
||||
$src,
|
||||
array('width' => 210, 'height' => 210, 'align' => 'center',
|
||||
'wrappingStyle' => \PHPWord_Style_Image::WRAPPING_STYLE_BEHIND)
|
||||
);
|
||||
|
||||
$this->assertInstanceOf('PHPWord_Style_Image', $oImage->getStyle());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,7 +20,12 @@ class LinkTest extends \PHPUnit_Framework_TestCase
|
|||
|
||||
public function testConstructWithParamsArray()
|
||||
{
|
||||
$oLink = new PHPWord_Section_Link('http://www.google.com', 'Search Engine', array('color' => '0000FF', 'underline' => PHPWord_Style_Font::UNDERLINE_SINGLE), array('marginLeft' => 600, 'marginRight' => 600, 'marginTop' => 600, 'marginBottom' => 600));
|
||||
$oLink = new PHPWord_Section_Link(
|
||||
'http://www.google.com',
|
||||
'Search Engine',
|
||||
array('color' => '0000FF', 'underline' => PHPWord_Style_Font::UNDERLINE_SINGLE),
|
||||
array('marginLeft' => 600, 'marginRight' => 600, 'marginTop' => 600, 'marginBottom' => 600)
|
||||
);
|
||||
|
||||
$this->assertInstanceOf('PHPWord_Section_Link', $oLink);
|
||||
$this->assertEquals($oLink->getLinkSrc(), 'http://www.google.com');
|
||||
|
|
|
|||
|
|
@ -16,7 +16,12 @@ class ListItemTest extends \PHPUnit_Framework_TestCase
|
|||
|
||||
public function testStyle()
|
||||
{
|
||||
$oListItem = new PHPWord_Section_ListItem('text', 1, null, array('listType' => PHPWord_Style_ListItem::TYPE_NUMBER));
|
||||
$oListItem = new PHPWord_Section_ListItem(
|
||||
'text',
|
||||
1,
|
||||
null,
|
||||
array('listType' => PHPWord_Style_ListItem::TYPE_NUMBER)
|
||||
);
|
||||
|
||||
$this->assertInstanceOf('PHPWord_Style_ListItem', $oListItem->getStyle());
|
||||
$this->assertEquals($oListItem->getStyle()->getListType(), PHPWord_Style_ListItem::TYPE_NUMBER);
|
||||
|
|
|
|||
|
|
@ -130,7 +130,9 @@ class CellTest extends \PHPUnit_Framework_TestCase
|
|||
public function testAddMemoryImageSection()
|
||||
{
|
||||
$oCell = new PHPWord_Section_Table_Cell('section', 1);
|
||||
$element = $oCell->addMemoryImage('https://assets.mozillalabs.com/Brands-Logos/Thunderbird/logo-only/thunderbird_logo-only_RGB.png');
|
||||
$element = $oCell->addMemoryImage(
|
||||
'https://assets.mozillalabs.com/Brands-Logos/Thunderbird/logo-only/thunderbird_logo-only_RGB.png'
|
||||
);
|
||||
|
||||
$this->assertCount(1, $oCell->getElements());
|
||||
$this->assertInstanceOf('PHPWord_Section_MemoryImage', $element);
|
||||
|
|
@ -139,7 +141,9 @@ class CellTest extends \PHPUnit_Framework_TestCase
|
|||
public function testAddMemoryImageHeader()
|
||||
{
|
||||
$oCell = new PHPWord_Section_Table_Cell('header', 1);
|
||||
$element = $oCell->addMemoryImage('https://assets.mozillalabs.com/Brands-Logos/Thunderbird/logo-only/thunderbird_logo-only_RGB.png');
|
||||
$element = $oCell->addMemoryImage(
|
||||
'https://assets.mozillalabs.com/Brands-Logos/Thunderbird/logo-only/thunderbird_logo-only_RGB.png'
|
||||
);
|
||||
|
||||
$this->assertCount(1, $oCell->getElements());
|
||||
$this->assertInstanceOf('PHPWord_Section_MemoryImage', $element);
|
||||
|
|
@ -148,7 +152,9 @@ class CellTest extends \PHPUnit_Framework_TestCase
|
|||
public function testAddMemoryImageFooter()
|
||||
{
|
||||
$oCell = new PHPWord_Section_Table_Cell('footer', 1);
|
||||
$element = $oCell->addMemoryImage('https://assets.mozillalabs.com/Brands-Logos/Thunderbird/logo-only/thunderbird_logo-only_RGB.png');
|
||||
$element = $oCell->addMemoryImage(
|
||||
'https://assets.mozillalabs.com/Brands-Logos/Thunderbird/logo-only/thunderbird_logo-only_RGB.png'
|
||||
);
|
||||
|
||||
$this->assertCount(1, $oCell->getElements());
|
||||
$this->assertInstanceOf('PHPWord_Section_MemoryImage', $element);
|
||||
|
|
|
|||
|
|
@ -22,7 +22,12 @@ class RowTest extends \PHPUnit_Framework_TestCase
|
|||
{
|
||||
$iVal = rand(1, 1000);
|
||||
$iVal2 = rand(1, 1000);
|
||||
$oRow = new PHPWord_Section_Table_Row('section', $iVal, $iVal2, array('borderBottomSize' => 18, 'borderBottomColor' => '0000FF', 'bgColor' => '66BBFF'));
|
||||
$oRow = new PHPWord_Section_Table_Row(
|
||||
'section',
|
||||
$iVal,
|
||||
$iVal2,
|
||||
array('borderBottomSize' => 18, 'borderBottomColor' => '0000FF', 'bgColor' => '66BBFF')
|
||||
);
|
||||
|
||||
$this->assertEquals($oRow->getHeight(), $iVal2);
|
||||
$this->assertInstanceOf('PHPWord_Style_Row', $oRow->getStyle());
|
||||
|
|
|
|||
|
|
@ -26,7 +26,11 @@ class TableTest extends \PHPUnit_Framework_TestCase
|
|||
|
||||
public function testStyleArray()
|
||||
{
|
||||
$oTable = new PHPWord_Section_Table('section', 1, array('borderSize' => 6, 'borderColor' => '006699', 'cellMargin' => 80));
|
||||
$oTable = new PHPWord_Section_Table(
|
||||
'section',
|
||||
1,
|
||||
array('borderSize' => 6, 'borderColor' => '006699', 'cellMargin' => 80)
|
||||
);
|
||||
|
||||
$this->assertInstanceOf('PHPWord_Style_Table', $oTable->getStyle());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,29 +20,7 @@ class BaseTest extends \PHPUnit_Framework_TestCase
|
|||
TestHelperDOCX::clear();
|
||||
}
|
||||
|
||||
public function testWriteImage_Position()
|
||||
{
|
||||
$PHPWord = new PHPWord();
|
||||
$section = $PHPWord->createSection();
|
||||
$section->addImage(
|
||||
PHPWORD_TESTS_DIR_ROOT . '/_files/images/earth.jpg',
|
||||
array(
|
||||
'marginTop' => -1,
|
||||
'marginLeft' => -1,
|
||||
'wrappingStyle' => 'behind'
|
||||
)
|
||||
);
|
||||
|
||||
$doc = TestHelperDOCX::getDocument($PHPWord);
|
||||
$element = $doc->getElement('/w:document/w:body/w:p/w:r/w:pict/v:shape');
|
||||
|
||||
$style = $element->getAttribute('style');
|
||||
|
||||
$this->assertRegExp('/z\-index:\-[0-9]*/', $style);
|
||||
$this->assertRegExp('/position:absolute;/', $style);
|
||||
}
|
||||
|
||||
public function testWriteParagraphStyle_Align()
|
||||
public function testWriteParagraphStyleAlign()
|
||||
{
|
||||
$PHPWord = new PHPWord();
|
||||
$section = $PHPWord->createSection();
|
||||
|
|
@ -55,34 +33,10 @@ class BaseTest extends \PHPUnit_Framework_TestCase
|
|||
$this->assertEquals('right', $element->getAttribute('w:val'));
|
||||
}
|
||||
|
||||
public function testWriteCellStyle_CellGridSpan()
|
||||
{
|
||||
$PHPWord = new PHPWord();
|
||||
$section = $PHPWord->createSection();
|
||||
|
||||
$table = $section->addTable();
|
||||
|
||||
$table->addRow();
|
||||
$cell = $table->addCell(200);
|
||||
$cell->getStyle()->setGridSpan(5);
|
||||
|
||||
$table->addRow();
|
||||
$table->addCell(40);
|
||||
$table->addCell(40);
|
||||
$table->addCell(40);
|
||||
$table->addCell(40);
|
||||
$table->addCell(40);
|
||||
|
||||
$doc = TestHelperDOCX::getDocument($PHPWord);
|
||||
$element = $doc->getElement('/w:document/w:body/w:tbl/w:tr/w:tc/w:tcPr/w:gridSpan');
|
||||
|
||||
$this->assertEquals(5, $element->getAttribute('w:val'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test write paragraph pagination
|
||||
*/
|
||||
public function testWriteParagraphStyle_Pagination()
|
||||
public function testWriteParagraphStylePagination()
|
||||
{
|
||||
// Create the doc
|
||||
$PHPWord = new PHPWord();
|
||||
|
|
@ -109,6 +63,52 @@ class BaseTest extends \PHPUnit_Framework_TestCase
|
|||
}
|
||||
}
|
||||
|
||||
public function testWriteCellStyleCellGridSpan()
|
||||
{
|
||||
$PHPWord = new PHPWord();
|
||||
$section = $PHPWord->createSection();
|
||||
|
||||
$table = $section->addTable();
|
||||
|
||||
$table->addRow();
|
||||
$cell = $table->addCell(200);
|
||||
$cell->getStyle()->setGridSpan(5);
|
||||
|
||||
$table->addRow();
|
||||
$table->addCell(40);
|
||||
$table->addCell(40);
|
||||
$table->addCell(40);
|
||||
$table->addCell(40);
|
||||
$table->addCell(40);
|
||||
|
||||
$doc = TestHelperDOCX::getDocument($PHPWord);
|
||||
$element = $doc->getElement('/w:document/w:body/w:tbl/w:tr/w:tc/w:tcPr/w:gridSpan');
|
||||
|
||||
$this->assertEquals(5, $element->getAttribute('w:val'));
|
||||
}
|
||||
|
||||
public function testWriteImagePosition()
|
||||
{
|
||||
$PHPWord = new PHPWord();
|
||||
$section = $PHPWord->createSection();
|
||||
$section->addImage(
|
||||
PHPWORD_TESTS_DIR_ROOT . '/_files/images/earth.jpg',
|
||||
array(
|
||||
'marginTop' => -1,
|
||||
'marginLeft' => -1,
|
||||
'wrappingStyle' => 'behind'
|
||||
)
|
||||
);
|
||||
|
||||
$doc = TestHelperDOCX::getDocument($PHPWord);
|
||||
$element = $doc->getElement('/w:document/w:body/w:p/w:r/w:pict/v:shape');
|
||||
|
||||
$style = $element->getAttribute('style');
|
||||
|
||||
$this->assertRegExp('/z\-index:\-[0-9]*/', $style);
|
||||
$this->assertRegExp('/position:absolute;/', $style);
|
||||
}
|
||||
|
||||
public function testWritePreserveText()
|
||||
{
|
||||
$PHPWord = new PHPWord();
|
||||
|
|
|
|||
|
|
@ -2,15 +2,15 @@
|
|||
namespace PHPWord\Tests;
|
||||
|
||||
use PHPWord;
|
||||
use DOMDocument;
|
||||
|
||||
class TestHelperDOCX
|
||||
{
|
||||
/** @var string $file */
|
||||
static protected $file;
|
||||
|
||||
/**
|
||||
* @param \PHPWord $PHPWord
|
||||
* @return \PHPWord\Tests\Xml_Document
|
||||
* @return \PHPWord\Tests\XmlDocument
|
||||
*/
|
||||
public static function getDocument(PHPWord $PHPWord)
|
||||
{
|
||||
|
|
@ -29,7 +29,7 @@ class TestHelperDOCX
|
|||
$zip->close();
|
||||
}
|
||||
|
||||
return new Xml_Document(sys_get_temp_dir() . '/PHPWord_Unit_Test/');
|
||||
return new XmlDocument(sys_get_temp_dir() . '/PHPWord_Unit_Test/');
|
||||
}
|
||||
|
||||
public static function clear()
|
||||
|
|
@ -50,9 +50,9 @@ class TestHelperDOCX
|
|||
foreach (scandir($dir) as $file) {
|
||||
if ($file === '.' || $file === '..') {
|
||||
continue;
|
||||
} else if (is_file($dir . "/" . $file)) {
|
||||
} elseif (is_file($dir . "/" . $file)) {
|
||||
unlink($dir . "/" . $file);
|
||||
} else if (is_dir($dir . "/" . $file)) {
|
||||
} elseif (is_dir($dir . "/" . $file)) {
|
||||
self::deleteDir($dir . "/" . $file);
|
||||
}
|
||||
}
|
||||
|
|
@ -60,65 +60,3 @@ class TestHelperDOCX
|
|||
rmdir($dir);
|
||||
}
|
||||
}
|
||||
|
||||
class Xml_Document
|
||||
{
|
||||
/** @var string $path */
|
||||
private $path;
|
||||
|
||||
/** @var \DOMDocument $dom */
|
||||
private $dom;
|
||||
|
||||
/** @var \DOMXpath $xpath */
|
||||
private $xpath;
|
||||
|
||||
/** @var string $file */
|
||||
private $file;
|
||||
|
||||
/**
|
||||
* @param string $path
|
||||
*/
|
||||
public function __construct($path)
|
||||
{
|
||||
$this->path = realpath($path);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $file
|
||||
* @return \DOMDocument
|
||||
*/
|
||||
public function getFileDom($file = 'word/document.xml')
|
||||
{
|
||||
if (null !== $this->dom && $file === $this->file) {
|
||||
return $this->dom;
|
||||
}
|
||||
|
||||
$this->xpath = null;
|
||||
$this->file = $file;
|
||||
|
||||
$file = $this->path . '/' . $file;
|
||||
$this->dom = new DOMDocument();
|
||||
$this->dom->load($file);
|
||||
return $this->dom;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $path
|
||||
* @param string $file
|
||||
* @return \DOMElement
|
||||
*/
|
||||
public function getElement($path, $file = 'word/document.xml')
|
||||
{
|
||||
if ($this->dom === null || $file !== $this->file) {
|
||||
$this->getFileDom($file);
|
||||
}
|
||||
|
||||
if (null === $this->xpath) {
|
||||
$this->xpath = new \DOMXpath($this->dom);
|
||||
|
||||
}
|
||||
|
||||
$elements = $this->xpath->query($path);
|
||||
return $elements->item(0);
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue