Some unit tests for Style Drawing, File, and String
This commit is contained in:
parent
8fb7da46ee
commit
e36b2c5a50
|
|
@ -57,7 +57,7 @@ class PHPWord_Shared_XMLWriter
|
|||
private $_tempFileName = '';
|
||||
|
||||
/**
|
||||
* Create a new PHPPowerPoint_Shared_XMLWriter instance
|
||||
* Create a new PHPWord_Shared_XMLWriter instance
|
||||
*
|
||||
* @param int $pTemporaryStorage Temporary storage location
|
||||
* @param string $pTemporaryStorageFolder Temporary storage folder
|
||||
|
|
|
|||
|
|
@ -212,7 +212,7 @@ class PHPWord_Writer_ODText implements PHPWord_Writer_IWriter
|
|||
*
|
||||
* @param PHPWord $pPHPWord PHPWord object
|
||||
* @throws Exception
|
||||
* @return PHPWord_Writer_PowerPoint2007
|
||||
* @return PHPWord_Writer_ODText
|
||||
*/
|
||||
public function setPHPWord(PHPWord $pPHPWord = null)
|
||||
{
|
||||
|
|
@ -261,7 +261,7 @@ class PHPWord_Writer_ODText implements PHPWord_Writer_IWriter
|
|||
* @param boolean $pValue
|
||||
* @param string $pDirectory Disk caching directory
|
||||
* @throws Exception Exception when directory does not exist
|
||||
* @return PHPWord_Writer_PowerPoint2007
|
||||
* @return PHPWord_Writer_ODText
|
||||
*/
|
||||
public function setUseDiskCaching($pValue = false, $pDirectory = null)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -117,7 +117,7 @@ class PHPWord_Writer_RTF implements PHPWord_Writer_IWriter
|
|||
*
|
||||
* @param PHPWord $pPHPWord PHPWord object
|
||||
* @throws Exception
|
||||
* @return PHPWord_Writer_PowerPoint2007
|
||||
* @return PHPWord_Writer_RTF
|
||||
*/
|
||||
public function setPHPWord(PHPWord $pPHPWord = null)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -172,7 +172,7 @@ class PHPWord_Writer_Word2007_ContentTypes extends PHPWord_Writer_Word2007_Write
|
|||
/**
|
||||
* Write Override content type
|
||||
*
|
||||
* @param PHPPowerPoint_Shared_XMLWriter $objWriter XML Writer
|
||||
* @param PHPWord_Shared_XMLWriter $objWriter XML Writer
|
||||
* @param string $pPartname Part name
|
||||
* @param string $pContentType Content type
|
||||
* @throws Exception
|
||||
|
|
|
|||
|
|
@ -0,0 +1,69 @@
|
|||
<?php
|
||||
namespace PHPWord\Tests\Shared;
|
||||
|
||||
use PHPUnit_Framework_TestCase;
|
||||
use PHPWord_Shared_Drawing;
|
||||
|
||||
/**
|
||||
* Class DrawingTest
|
||||
*
|
||||
* @package PHPWord\Tests
|
||||
* @runTestsInSeparateProcesses
|
||||
*/
|
||||
class DrawingTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
|
||||
/**
|
||||
* Test unit conversion functions with various numbers
|
||||
*/
|
||||
public function testUnitConversions()
|
||||
{
|
||||
$values[] = 0; // zero value
|
||||
$values[] = rand(1, 100) / 100; // fraction number
|
||||
$values[] = rand(1, 100); // integer
|
||||
|
||||
foreach ($values as $value) {
|
||||
$result = PHPWord_Shared_Drawing::pixelsToEMU($value);
|
||||
$this->assertEquals(round($value * 9525), $result);
|
||||
|
||||
$result = PHPWord_Shared_Drawing::EMUToPixels($value);
|
||||
$this->assertEquals(round($value / 9525), $result);
|
||||
|
||||
$result = PHPWord_Shared_Drawing::pixelsToPoints($value);
|
||||
$this->assertEquals($value * 0.67777777, $result);
|
||||
|
||||
$result = PHPWord_Shared_Drawing::pointsToPixels($value);
|
||||
$this->assertEquals($value * 1.333333333, $result);
|
||||
|
||||
$result = PHPWord_Shared_Drawing::degreesToAngle($value);
|
||||
$this->assertEquals((int)round($value * 60000), $result);
|
||||
|
||||
$result = PHPWord_Shared_Drawing::angleToDegrees($value);
|
||||
$this->assertEquals(round($value / 60000), $result);
|
||||
|
||||
$result = PHPWord_Shared_Drawing::pixelsToCentimeters($value);
|
||||
$this->assertEquals($value * 0.028, $result);
|
||||
|
||||
$result = PHPWord_Shared_Drawing::centimetersToPixels($value);
|
||||
$this->assertEquals($value / 0.028, $result);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test htmlToRGB()
|
||||
*/
|
||||
public function testHtmlToRGB()
|
||||
{
|
||||
// Prepare test values [ original, expected ]
|
||||
$values[] = array('#FF99DD', array(255, 153, 221)); // With #
|
||||
$values[] = array('FF99DD', array(255, 153, 221)); // 6 characters
|
||||
$values[] = array('F9D', array(255, 153, 221)); // 3 characters
|
||||
$values[] = array('0F9D', false); // 4 characters
|
||||
// Conduct test
|
||||
foreach ($values as $value) {
|
||||
$result = PHPWord_Shared_Drawing::htmlToRGB($value[0]);
|
||||
$this->assertEquals($value[1], $result);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,41 @@
|
|||
<?php
|
||||
namespace PHPWord\Tests\Shared;
|
||||
|
||||
use PHPUnit_Framework_TestCase;
|
||||
use PHPWord_Shared_File;
|
||||
|
||||
/**
|
||||
* Class FileTest
|
||||
*
|
||||
* @package PHPWord\Tests
|
||||
* @runTestsInSeparateProcesses
|
||||
*/
|
||||
class FileTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
|
||||
/**
|
||||
* Test file_exists()
|
||||
*/
|
||||
public function testFile_exists()
|
||||
{
|
||||
$dir = join(DIRECTORY_SEPARATOR,
|
||||
array(PHPWORD_TESTS_DIR_ROOT, '_files', 'templates')
|
||||
);
|
||||
chdir($dir);
|
||||
$this->assertTrue(PHPWord_Shared_File::file_exists('blank.docx'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test realpath()
|
||||
*/
|
||||
public function testRealpath()
|
||||
{
|
||||
$dir = join(DIRECTORY_SEPARATOR,
|
||||
array(PHPWORD_TESTS_DIR_ROOT, '_files', 'templates'));
|
||||
chdir($dir);
|
||||
$file = 'blank.docx';
|
||||
$expected = $dir . DIRECTORY_SEPARATOR . $file;
|
||||
$this->assertEquals($expected, PHPWord_Shared_File::realpath($file));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,45 @@
|
|||
<?php
|
||||
namespace PHPWord\Tests\Shared;
|
||||
|
||||
use PHPUnit_Framework_TestCase;
|
||||
use PHPWord_Shared_String;
|
||||
|
||||
/**
|
||||
* Class StringTest
|
||||
*
|
||||
* @package PHPWord\Tests
|
||||
* @runTestsInSeparateProcesses
|
||||
*/
|
||||
class StringTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
|
||||
/**
|
||||
* Test getIsMbstringEnabled() and getIsIconvEnabled()
|
||||
*/
|
||||
public function testGetIsMbstringAndIconvEnabled()
|
||||
{
|
||||
$features = array(
|
||||
'mbstring' => 'mb_convert_encoding',
|
||||
'iconv' => 'iconv',
|
||||
);
|
||||
foreach ($features as $key => $val) {
|
||||
$expected = function_exists($val);
|
||||
$get = "getIs{$key}Enabled";
|
||||
$firstResult = PHPWord_Shared_String::$get();
|
||||
$this->assertEquals($expected, $firstResult);
|
||||
$secondResult = PHPWord_Shared_String::$get();
|
||||
$this->assertEquals($firstResult, $secondResult);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test FormatNumber()
|
||||
*/
|
||||
public function testFormatNumber()
|
||||
{
|
||||
$expected = '1022.12';
|
||||
$returned = PHPWord_Shared_String::FormatNumber('1022.1234');
|
||||
$this->assertEquals($expected, $returned);
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue