| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654 |
- <?php
- /**
- * Zend Framework
- *
- * LICENSE
- *
- * This source file is subject to the new BSD license that is bundled
- * with this package in the file LICENSE.txt.
- * It is also available through the world-wide-web at this URL:
- * http://framework.zend.com/license/new-bsd
- * If you did not receive a copy of the license and are unable to
- * obtain it through the world-wide-web, please send an email
- * to license@zend.com so we can send you a copy immediately.
- *
- * @category Zend
- * @package Zend_Service_LiveDocx
- * @subpackage UnitTests
- * @copyright Copyright(c) 2005-2009 Zend Technologies USA Inc.(http://www.zend.com)
- * @license http://framework.zend.com/license/new-bsd New BSD License
- * @version $Id: $
- */
- if (!defined('PHPUnit_MAIN_METHOD')) {
- define('PHPUnit_MAIN_METHOD', 'Zend_Service_LiveDocx_MailMergeTest::main');
- }
- /**
- * Test helper
- */
- require_once dirname(__FILE__) . '/../../../TestHelper.php';
- /** Zend_Service_LiveDocx_MailMerge */
- require_once 'Zend/Service/LiveDocx/MailMerge.php';
- /**
- * Zend_Service_LiveDocx test case
- *
- * @category Zend
- * @package Zend_Service_LiveDocx
- * @subpackage UnitTests
- * @copyright Copyright(c) 2005-2009 Zend Technologies USA Inc.(http://www.zend.com)
- * @license http://framework.zend.com/license/new-bsd New BSD License
- * @version $Id: $
- */
- class Zend_Service_LiveDocx_MailMergeTest extends PHPUnit_Framework_TestCase
- {
- const TEST_TEMPLATE_1 = 'phpunit-template.docx';
- const TEST_TEMPLATE_2 = 'phpunit-template-block-fields.doc';
- const ENDPOINT = 'https://api.livedocx.com/1.2/mailmerge.asmx?wsdl';
- public $path;
- public $phpLiveDocx;
- // -------------------------------------------------------------------------
- public static function main()
- {
- $suite = new PHPUnit_Framework_TestSuite(__CLASS__);
- $result = PHPUnit_TextUI_TestRunner::run($suite);
- }
- public function setUp()
- {
- if (!constant('TESTS_ZEND_SERVICE_LIVEDOCX_USERNAME')
- || !constant('TESTS_ZEND_SERVICE_LIVEDOCX_PASSWORD')
- ) {
- $this->markTestSkipped('LiveDocx tests disabled');
- return;
- }
-
- $this->phpLiveDocx = new Zend_Service_LiveDocx_MailMerge();
- $this->phpLiveDocx->setUsername(TESTS_ZEND_SERVICE_LIVEDOCX_USERNAME)
- ->setPassword(TESTS_ZEND_SERVICE_LIVEDOCX_PASSWORD);
- foreach($this->phpLiveDocx->listTemplates() as $template) {
- $this->phpLiveDocx->deleteTemplate($template['filename']);
- }
- $this->path = realpath(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'MailMerge');
- }
- public function tearDown()
- {
- foreach($this->phpLiveDocx->listTemplates() as $template) {
- $this->phpLiveDocx->deleteTemplate($template['filename']);
- }
- unset($this->phpLiveDocx);
- }
- // -------------------------------------------------------------------------
- public function testLoginUsernamePassword()
- {
- $phpLiveDocx = new Zend_Service_LiveDocx_MailMerge();
- $phpLiveDocx->setUsername(TESTS_ZEND_SERVICE_LIVEDOCX_USERNAME);
- $phpLiveDocx->setPassword(TESTS_ZEND_SERVICE_LIVEDOCX_PASSWORD);
- $this->assertTrue($phpLiveDocx->logIn());
- }
-
- public function testLoginUsernamePasswordSoapClient()
- {
- $phpLiveDocx = new Zend_Service_LiveDocx_MailMerge();
- $phpLiveDocx->setUsername(TESTS_ZEND_SERVICE_LIVEDOCX_USERNAME);
- $phpLiveDocx->setPassword(TESTS_ZEND_SERVICE_LIVEDOCX_PASSWORD);
- $phpLiveDocx->setSoapClient(new Zend_Soap_Client(self::ENDPOINT));
- $this->assertTrue($phpLiveDocx->logIn());
- }
-
- /**
- * @expectedException Zend_Service_LiveDocx_Exception
- */
- public function testLoginUsernamePasswordException()
- {
- $phpLiveDocx = new Zend_Service_LiveDocx_MailMerge();
- $phpLiveDocx->setUsername('phpunitInvalidUsername');
- $phpLiveDocx->setPassword('phpunitInvalidPassword');
- $phpLiveDocx->logIn();
- }
-
- /**
- * @expectedException Zend_Service_LiveDocx_Exception
- */
- public function testLoginUsernamePasswordSoapClientException()
- {
- $phpLiveDocx = new Zend_Service_LiveDocx_MailMerge();
- $phpLiveDocx->setUsername('phpunitInvalidUsername');
- $phpLiveDocx->setPassword('phpunitInvalidPassword');
- $phpLiveDocx->setSoapClient(new Zend_Soap_Client(self::ENDPOINT));
- $phpLiveDocx->logIn();
- }
-
- public function testConstructorOptionsUsernamePassword()
- {
- $phpLiveDocx = new Zend_Service_LiveDocx_MailMerge(
- array (
- 'username' => TESTS_ZEND_SERVICE_LIVEDOCX_USERNAME,
- 'password' => TESTS_ZEND_SERVICE_LIVEDOCX_PASSWORD
- )
- );
- $this->assertTrue($phpLiveDocx->logIn());
- }
-
- public function testConstructorOptionsUsernamePasswordSoapClient()
- {
- $phpLiveDocx = new Zend_Service_LiveDocx_MailMerge(
- array (
- 'username' => TESTS_ZEND_SERVICE_LIVEDOCX_USERNAME,
- 'password' => TESTS_ZEND_SERVICE_LIVEDOCX_PASSWORD,
- 'soapClient' => new Zend_Soap_Client(self::ENDPOINT)
- )
- );
- $this->assertTrue($phpLiveDocx->logIn());
- }
- // -------------------------------------------------------------------------
- public function testSetLocalTemplate()
- {
- $this->assertNull($this->phpLiveDocx->setLocalTemplate($this->path . DIRECTORY_SEPARATOR . self::TEST_TEMPLATE_1));
- $this->setExpectedException('Zend_Service_LiveDocx_Exception');
- @$this->phpLiveDocx->setLocalTemplate('phpunit-nonexistent.doc');
- }
- public function testSetRemoteTemplate()
- {
- $this->phpLiveDocx->uploadTemplate($this->path . DIRECTORY_SEPARATOR . self::TEST_TEMPLATE_1);
- $this->assertNull($this->phpLiveDocx->setRemoteTemplate(self::TEST_TEMPLATE_1));
- $this->phpLiveDocx->deleteTemplate(self::TEST_TEMPLATE_1);
- }
- public function testSetFieldValues()
- {
- $testValues = array('software' => 'phpunit');
- // Remote Template
- $this->phpLiveDocx->uploadTemplate($this->path . DIRECTORY_SEPARATOR . self::TEST_TEMPLATE_1);
- $this->phpLiveDocx->setRemoteTemplate(self::TEST_TEMPLATE_1);
- $this->assertNull($this->phpLiveDocx->setFieldValues($testValues));
- $this->phpLiveDocx->deleteTemplate(self::TEST_TEMPLATE_1);
- // Local Template
- $this->phpLiveDocx->setLocalTemplate($this->path . DIRECTORY_SEPARATOR . self::TEST_TEMPLATE_1);
- $this->assertNull($this->phpLiveDocx->setFieldValues($testValues));
- }
- public function testSetFieldValue()
- {
- $testKey = 'software';
- $testValue = 'phpunit';
- // Remote Template
- $this->phpLiveDocx->uploadTemplate($this->path . DIRECTORY_SEPARATOR . self::TEST_TEMPLATE_1);
- $this->assertNull($this->phpLiveDocx->setFieldValue($testKey, $testValue));
- $this->phpLiveDocx->deleteTemplate(self::TEST_TEMPLATE_1);
- // Local Template
- $this->phpLiveDocx->setLocalTemplate($this->path . DIRECTORY_SEPARATOR . self::TEST_TEMPLATE_1);
- $this->assertNull($this->phpLiveDocx->setFieldValue($testKey, $testValue));
- }
- public function testAssign()
- {
- $testKey = 'software';
- $testValue = 'phpunit';
- // Remote Template
- $this->phpLiveDocx->uploadTemplate($this->path . DIRECTORY_SEPARATOR . self::TEST_TEMPLATE_1);
- $this->assertNull($this->phpLiveDocx->assign($testKey, $testValue));
- $this->phpLiveDocx->deleteTemplate(self::TEST_TEMPLATE_1);
- // Local Template
- $this->phpLiveDocx->setLocalTemplate($this->path . DIRECTORY_SEPARATOR . self::TEST_TEMPLATE_1);
- $this->assertNull($this->phpLiveDocx->assign($testKey, $testValue));
- }
- public function testSetBlockFieldValues()
- {
- $testKey = 'connection';
- $testValues = array(array('connection_number' => 'unittest', 'connection_duration' => 'unittest', 'fee' => 'unittest'),
- array('connection_number' => 'unittest', 'connection_duration' => 'unittest', 'fee' => 'unittest'),
- array('connection_number' => 'unittest', 'connection_duration' => 'unittest', 'fee' => 'unittest'),
- array('connection_number' => 'unittest', 'connection_duration' => 'unittest', 'fee' => 'unittest') );
- // Remote Template
- $this->phpLiveDocx->uploadTemplate($this->path . DIRECTORY_SEPARATOR . self::TEST_TEMPLATE_2);
- $this->assertNull($this->phpLiveDocx->setBlockFieldValues($testKey, $testValues));
- $this->phpLiveDocx->deleteTemplate(self::TEST_TEMPLATE_2);
- // Local Template
- $this->phpLiveDocx->setLocalTemplate($this->path . DIRECTORY_SEPARATOR . self::TEST_TEMPLATE_2);
- $this->assertNull($this->phpLiveDocx->setBlockFieldValues($testKey, $testValues));
- }
- // -------------------------------------------------------------------------
- public function testCreateDocument()
- {
- $testValues = array(
- 'software' => 'phpunit',
- 'licensee' => 'phpunit',
- 'company' => 'phpunit',
- 'date' => 'phpunit',
- 'time' => 'phpunit',
- 'city' => 'phpunit',
- 'country' => 'phpunit',
- );
- // Remote Template
- $this->phpLiveDocx->uploadTemplate($this->path . DIRECTORY_SEPARATOR . self::TEST_TEMPLATE_1);
- $this->phpLiveDocx->setRemoteTemplate(self::TEST_TEMPLATE_1);
- $this->phpLiveDocx->assign($testValues);
- $this->assertNull($this->phpLiveDocx->createDocument());
- $this->phpLiveDocx->deleteTemplate(self::TEST_TEMPLATE_1);
- // Local Template
- $this->phpLiveDocx->setLocalTemplate($this->path . DIRECTORY_SEPARATOR . self::TEST_TEMPLATE_1);
- $this->phpLiveDocx->assign($testValues);
- $this->assertNull($this->phpLiveDocx->createDocument());
- }
- public function testRetrieveDocument()
- {
- $testValues = array(
- 'software' => 'phpunit',
- 'licensee' => 'phpunit',
- 'company' => 'phpunit',
- 'date' => 'phpunit',
- 'time' => 'phpunit',
- 'city' => 'phpunit',
- 'country' => 'phpunit',
- );
- // PDF and DOCs are always slightly different:
- // - PDF because of the timestamp in meta data
- // - DOC because of ???
- $expectedResults = array(
- 'docx' => '50fe2abd9b42e67c3126d355768b6e75',
- 'rtf' => '24f950ff620ba194fe5900c3a5360570',
- 'txd' => '22d7a7558b19ba8be9fe03b35068cf20',
- 'txt' => '3dc103f033ef6efba770c8196059d96d',
- 'html' => '8b91dc8617651b6e3142d0716c0f616a',
- );
- // Remote Template
- $this->phpLiveDocx->uploadTemplate($this->path . DIRECTORY_SEPARATOR . self::TEST_TEMPLATE_1);
- $this->phpLiveDocx->setRemoteTemplate(self::TEST_TEMPLATE_1);
- $this->phpLiveDocx->assign($testValues);
- $this->phpLiveDocx->createDocument();
- foreach($expectedResults as $format => $hash) {
- $document = $this->phpLiveDocx->retrieveDocument($format);
- $this->assertEquals($hash, md5($document));
- }
- $this->phpLiveDocx->deleteTemplate(self::TEST_TEMPLATE_1);
- // Local Template
- $this->phpLiveDocx->setLocalTemplate($this->path . DIRECTORY_SEPARATOR . self::TEST_TEMPLATE_1);
- $this->phpLiveDocx->assign($testValues);
- $this->phpLiveDocx->createDocument();
- foreach($expectedResults as $format => $hash) {
- $document = $this->phpLiveDocx->retrieveDocument($format);
- $this->assertEquals($hash, md5($document));
- }
- }
- public function testRetrieveDocumentAppended()
- {
- $testValues = array(
- array(
- 'software' => 'phpunit - document 1',
- 'licensee' => 'phpunit - document 1',
- 'company' => 'phpunit - document 1',
- 'date' => 'phpunit - document 1',
- 'time' => 'phpunit - document 1',
- 'city' => 'phpunit - document 1',
- 'country' => 'phpunit - document 1',
- ),
- array(
- 'software' => 'phpunit - document 2',
- 'licensee' => 'phpunit - document 2',
- 'company' => 'phpunit - document 2',
- 'date' => 'phpunit - document 2',
- 'time' => 'phpunit - document 2',
- 'city' => 'phpunit - document 2',
- 'country' => 'phpunit - document 2',
- ),
- );
- // PDF and DOCs are always slightly different:
- // - PDF because of the timestamp in meta data
- // - DOC because of ???
- $expectedResults = array(
- 'docx' => '0697e57da0c886dee9fa2d5c98335121',
- 'rtf' => '9a3f448519e2be0da08a13702fd9d48b',
- 'txd' => 'f76a6575e74db5b15b4c4be76157bc03',
- 'txt' => 'e997415fd0d5e766b2490fed9386da21',
- 'html' => '2dfafbb8f81281dbbae99e131963cd50',
- );
- // Remote Template
- $this->phpLiveDocx->uploadTemplate($this->path . DIRECTORY_SEPARATOR . self::TEST_TEMPLATE_1);
- $this->phpLiveDocx->setRemoteTemplate(self::TEST_TEMPLATE_1);
- $this->phpLiveDocx->assign($testValues);
- $this->phpLiveDocx->createDocument();
- foreach($expectedResults as $format => $hash) {
- $document = $this->phpLiveDocx->retrieveDocument($format);
- $this->assertEquals($hash, md5($document));
- }
- $this->phpLiveDocx->deleteTemplate(self::TEST_TEMPLATE_1);
- // Local Template
- $this->phpLiveDocx->setLocalTemplate($this->path . DIRECTORY_SEPARATOR . self::TEST_TEMPLATE_1);
- $this->phpLiveDocx->assign($testValues);
- $this->phpLiveDocx->createDocument();
- foreach($expectedResults as $format => $hash) {
- $document = $this->phpLiveDocx->retrieveDocument($format);
- $this->assertEquals($hash, md5($document));
- }
- }
- // -------------------------------------------------------------------------
- public function testGetTemplateFormats()
- {
- $expectedResults = array('doc', 'docx', 'rtf', 'txd');
- $this->assertEquals($expectedResults, $this->phpLiveDocx->getTemplateFormats());
- }
- public function testGetDocumentFormats()
- {
- $expectedResults = array('doc', 'docx', 'html', 'pdf', 'rtf', 'txd', 'txt');
- $this->assertEquals($expectedResults, $this->phpLiveDocx->getDocumentFormats());
- }
- public function testGetImageFormats()
- {
- $expectedResults = array('bmp', 'gif', 'jpg', 'png', 'tiff');
- $this->assertEquals($expectedResults, $this->phpLiveDocx->getImageFormats());
- }
- // -------------------------------------------------------------------------
- public function testGetMetafiles()
- {
- $this->markTestIncomplete();
- }
- public function testGetAllMetafiles()
- {
- $this->markTestIncomplete();
- }
- public function testGetBitmaps()
- {
- $testValues = array(
- 'software' => 'phpunit',
- 'licensee' => 'phpunit',
- 'company' => 'phpunit',
- 'date' => 'phpunit',
- 'time' => 'phpunit',
- 'city' => 'phpunit',
- 'country' => 'phpunit',
- );
- $expectedResults = array(
- 'bmp' => 'c588ee10d63e0598fe3541a032f509d6',
- 'gif' => '2edd4066dda5f4c2049717137d76cf58',
- 'jpg' => '8766618c572f19ceccc39af7ad0c8478',
- 'png' => '1e12e4937b9ccb0fa6d78dcd342b7f28',
- 'tiff' => '014ae48643e3a50f691b7d9442605426',
- );
- $this->phpLiveDocx->setLocalTemplate($this->path . DIRECTORY_SEPARATOR . self::TEST_TEMPLATE_1);
- $this->phpLiveDocx->assign($testValues);
- $this->phpLiveDocx->createDocument();
- foreach($this->phpLiveDocx->getImageFormats() as $format) {
- $bitmaps = $this->phpLiveDocx->getBitmaps(1, 1, 20, $format);
- $this->assertEquals($expectedResults[$format], md5(serialize($bitmaps)));
- }
- }
- public function testGetAllBitmaps()
- {
- $testValues = array(
- 'software' => 'phpunit',
- 'licensee' => 'phpunit',
- 'company' => 'phpunit',
- 'date' => 'phpunit',
- 'time' => 'phpunit',
- 'city' => 'phpunit',
- 'country' => 'phpunit',
- );
- $expectedResults = array(
- 'bmp' => '0ae732498dd3798fc51c1ccccd09e3e3',
- 'gif' => '9a5f7bfa2aafd8b99f6955b8bdbb8bf7',
- 'jpg' => '38550446bfc84af3ddd1a0f3339a84dd',
- 'png' => 'a3b5517bb118db67b8a8259652a389c2',
- 'tiff' => 'b49aa783c14bc7f07776d816085894a3',
- );
- $this->phpLiveDocx->setLocalTemplate($this->path . DIRECTORY_SEPARATOR . self::TEST_TEMPLATE_1);
- $this->phpLiveDocx->assign($testValues);
- $this->phpLiveDocx->createDocument();
- foreach($this->phpLiveDocx->getImageFormats() as $format) {
- $bitmaps = $this->phpLiveDocx->getAllBitmaps(20, $format);
- $this->assertEquals($expectedResults[$format], md5(serialize($bitmaps)));
- }
- }
- public function testGetFontNames()
- {
- $fonts = $this->phpLiveDocx->getFontNames();
- if (is_array($fonts) && count($fonts) > 5) {
- foreach (array('Courier New' , 'Verdana' , 'Arial' , 'Times New Roman') as $font) {
- if (in_array($font, $fonts)) {
- $this->assertTrue(true);
- } else {
- $this->assertTrue(false);
- }
- }
- } else {
- $this->assertTrue(false);
- }
- }
- public function testGetFieldNames()
- {
- $expectedResults = array('phone', 'date', 'name', 'customer_number', 'invoice_number', 'account_number', 'service_phone', 'service_fax', 'month', 'monthly_fee', 'total_net', 'tax', 'tax_value', 'total');
- // Remote Template
- $this->phpLiveDocx->uploadTemplate($this->path . DIRECTORY_SEPARATOR . self::TEST_TEMPLATE_2);
- $this->phpLiveDocx->setRemoteTemplate(self::TEST_TEMPLATE_2);
- $this->assertEquals($expectedResults, $this->phpLiveDocx->getFieldNames());
- $this->phpLiveDocx->deleteTemplate(self::TEST_TEMPLATE_2);
- // Local Template
- $this->phpLiveDocx->setLocalTemplate($this->path . DIRECTORY_SEPARATOR . self::TEST_TEMPLATE_2);
- $this->assertEquals($expectedResults, $this->phpLiveDocx->getFieldNames());
- }
- public function testGetBlockFieldNames()
- {
- $expectedResults = array('connection_number', 'connection_duration', 'fee');
- // Remote Template
- $this->phpLiveDocx->uploadTemplate($this->path . DIRECTORY_SEPARATOR . self::TEST_TEMPLATE_2);
- $this->phpLiveDocx->setRemoteTemplate(self::TEST_TEMPLATE_2);
- $this->assertEquals($expectedResults, $this->phpLiveDocx->getBlockFieldNames('connection'));
- $this->phpLiveDocx->deleteTemplate(self::TEST_TEMPLATE_2);
- // Local Template
- $this->phpLiveDocx->setLocalTemplate($this->path . DIRECTORY_SEPARATOR . self::TEST_TEMPLATE_2);
- $this->assertEquals($expectedResults, $this->phpLiveDocx->getBlockFieldNames('connection'));
- }
- public function testGetBlockNames()
- {
- $expectedResults = array('connection');
- // Remote Template
- $this->phpLiveDocx->uploadTemplate($this->path . DIRECTORY_SEPARATOR . self::TEST_TEMPLATE_2);
- $this->phpLiveDocx->setRemoteTemplate(self::TEST_TEMPLATE_2);
- $this->assertEquals($expectedResults, $this->phpLiveDocx->getBlockNames());
- $this->phpLiveDocx->deleteTemplate(self::TEST_TEMPLATE_2);
- // Local Template
- $this->phpLiveDocx->setLocalTemplate($this->path . DIRECTORY_SEPARATOR . self::TEST_TEMPLATE_2);
- $this->assertEquals($expectedResults, $this->phpLiveDocx->getBlockNames());
- }
- // -------------------------------------------------------------------------
- public function testSetDocumentProperties()
- {
- $testValues = array(
- 'title' => 'phpunit',
- 'author' => 'phpunit',
- 'subject' => 'phpunit',
- 'keywords' => 'phpunit',
- );
- $this->assertNull($this->phpLiveDocx->setDocumentProperties($testValues));
- }
- // -------------------------------------------------------------------------
- public function testUploadTemplate()
- {
- $this->phpLiveDocx->deleteTemplate(self::TEST_TEMPLATE_2);
- $this->assertNull($this->phpLiveDocx->uploadTemplate($this->path . DIRECTORY_SEPARATOR . self::TEST_TEMPLATE_2));
- $this->phpLiveDocx->deleteTemplate(self::TEST_TEMPLATE_2);
- }
- public function testDownloadTemplate()
- {
- $expectedResults = '2f076af778ca5f8afc9661cfb9deb7c6';
- $this->phpLiveDocx->uploadTemplate($this->path . DIRECTORY_SEPARATOR . self::TEST_TEMPLATE_2);
- $template = $this->phpLiveDocx->downloadTemplate(self::TEST_TEMPLATE_2);
- $this->assertEquals($expectedResults, md5($template));
- }
- public function testDeleteTemplate()
- {
- $this->phpLiveDocx->uploadTemplate($this->path . DIRECTORY_SEPARATOR . self::TEST_TEMPLATE_2);
- $this->phpLiveDocx->deleteTemplate(self::TEST_TEMPLATE_2);
- $templateDeleted = true;
- foreach($this->phpLiveDocx->listTemplates() as $template) {
- if($template['filename'] == self::TEST_TEMPLATE_2) {
- $templateDeleted = false;
- }
- }
- $this->assertTrue($templateDeleted);
- }
- public function testListTemplates()
- {
- $this->phpLiveDocx->uploadTemplate($this->path . DIRECTORY_SEPARATOR . self::TEST_TEMPLATE_1);
- $this->phpLiveDocx->uploadTemplate($this->path . DIRECTORY_SEPARATOR . self::TEST_TEMPLATE_2);
- // Where templates uploaded and are being listed?
- $testTemplate1Exists = false;
- $testTemplate2Exists = false;
- $templates = $this->phpLiveDocx->listTemplates();
- foreach($templates as $template) {
- if(self::TEST_TEMPLATE_1 === $template['filename']) {
- $testTemplate1Exists = true;
- } elseif(self::TEST_TEMPLATE_2 === $template['filename']) {
- $testTemplate2Exists = true;
- }
- }
- $this->assertTrue($testTemplate1Exists && $testTemplate2Exists);
- // Is all info about templates available?
- $expectedResults = array('filename', 'fileSize', 'createTime', 'modifyTime');
- foreach($templates as $template) {
- $this->assertEquals($expectedResults, array_keys($template));
- }
- // Is all info about templates correct?
- foreach($templates as $template) {
- $this->assertTrue(strlen($template['filename']) > 0);
- $this->assertTrue($template['fileSize'] > 1);
- $this->assertTrue($template['createTime'] > mktime(0, 0, 0, 1, 1, 1980));
- $this->assertTrue($template['modifyTime'] > mktime(0, 0, 0, 1, 1, 1980));
- }
- $this->phpLiveDocx->deleteTemplate(self::TEST_TEMPLATE_1);
- $this->phpLiveDocx->deleteTemplate(self::TEST_TEMPLATE_2);
- }
- public function testTemplateExists()
- {
- $this->phpLiveDocx->uploadTemplate($this->path . DIRECTORY_SEPARATOR . self::TEST_TEMPLATE_2);
- $this->assertTrue($this->phpLiveDocx->templateExists(self::TEST_TEMPLATE_2));
- $this->phpLiveDocx->deleteTemplate(self::TEST_TEMPLATE_2);
- }
- // -------------------------------------------------------------------------
- public function testAssocArrayToArrayOfArrayOfString()
- {
- $testValues = array(
- 'a' => '1',
- 'b' => '2',
- 'c' => '3',
- );
- $expectedResults = array(
- array('a', 'b', 'c'),
- array('1', '2', '3'),
- );
- $actualResults = Zend_Service_LiveDocx_MailMerge::assocArrayToArrayOfArrayOfString($testValues);
- $this->assertEquals($expectedResults, $actualResults);
- }
- public function testMultiAssocArrayToArrayOfArrayOfString()
- {
- $testValues = array(
- array(
- 'a' => '1',
- 'b' => '2',
- 'c' => '3',
- ),
- array(
- 'a' => '4',
- 'b' => '5',
- 'c' => '6',
- ),
- array(
- 'a' => '7',
- 'b' => '8',
- 'c' => '9',
- ),
- );
- $expectedResults = array(
- array('a', 'b', 'c'),
- array('1', '2', '3'),
- array('4', '5', '6'),
- array('7', '8', '9'),
- );
- $actualResults = Zend_Service_LiveDocx_MailMerge::multiAssocArrayToArrayOfArrayOfString($testValues);
- $this->assertEquals($expectedResults, $actualResults);
- }
- }
- if (PHPUnit_MAIN_METHOD == 'Zend_Service_LiveDocx_MailMergeTest::main') {
- Zend_Service_LiveDocx_MailMergeTest::main();
- }
|