PageRenderTime 52ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/tests/Zend/Service/LiveDocx/MailMergeTest.php

https://bitbucket.org/ksekar/campus
PHP | 709 lines | 532 code | 98 blank | 79 comment | 19 complexity | 47f9601292e79860b64294a1a58bbf18 MD5 | raw file
Possible License(s): BSD-3-Clause, LGPL-2.0, MIT
  1. <?php
  2. /**
  3. * Zend Framework
  4. *
  5. * LICENSE
  6. *
  7. * This source file is subject to the new BSD license that is bundled
  8. * with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://framework.zend.com/license/new-bsd
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@zend.com so we can send you a copy immediately.
  14. *
  15. * @category Zend
  16. * @package Zend_Service_LiveDocx
  17. * @subpackage UnitTests
  18. * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. * @version $Id: $
  21. */
  22. if (!defined('PHPUnit_MAIN_METHOD')) {
  23. define('PHPUnit_MAIN_METHOD', 'Zend_Service_LiveDocx_MailMergeTest::main');
  24. }
  25. require_once 'Zend/Service/LiveDocx/MailMerge.php';
  26. /**
  27. * Zend_Service_LiveDocx test case
  28. *
  29. * @category Zend
  30. * @package Zend_Service_LiveDocx
  31. * @subpackage UnitTests
  32. * @group Zend_Service
  33. * @group Zend_Service_LiveDocx
  34. * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
  35. * @license http://framework.zend.com/license/new-bsd New BSD License
  36. * @version $Id: $
  37. */
  38. class Zend_Service_LiveDocx_MailMergeTest extends PHPUnit_Framework_TestCase
  39. {
  40. const TEST_TEMPLATE_1 = 'phpunit-template.docx';
  41. const TEST_TEMPLATE_2 = 'phpunit-template-block-fields.doc';
  42. const TEST_IMAGE_1 = 'image-01.png';
  43. const TEST_IMAGE_2 = 'image-02.png';
  44. const ENDPOINT = 'https://api.livedocx.com/2.0/mailmerge.asmx?wsdl';
  45. public $path;
  46. public $phpLiveDocx;
  47. // -------------------------------------------------------------------------
  48. public static function main()
  49. {
  50. $suite = new PHPUnit_Framework_TestSuite(__CLASS__);
  51. $result = PHPUnit_TextUI_TestRunner::run($suite);
  52. }
  53. public function setUp()
  54. {
  55. if (!constant('TESTS_ZEND_SERVICE_LIVEDOCX_USERNAME')
  56. || !constant('TESTS_ZEND_SERVICE_LIVEDOCX_PASSWORD')
  57. ) {
  58. $this->markTestSkipped('LiveDocx tests disabled');
  59. return;
  60. }
  61. $this->phpLiveDocx = new Zend_Service_LiveDocx_MailMerge();
  62. $this->phpLiveDocx->setUsername(TESTS_ZEND_SERVICE_LIVEDOCX_USERNAME)
  63. ->setPassword(TESTS_ZEND_SERVICE_LIVEDOCX_PASSWORD);
  64. foreach($this->phpLiveDocx->listTemplates() as $template) {
  65. $this->phpLiveDocx->deleteTemplate($template['filename']);
  66. }
  67. $this->path = realpath(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'MailMerge');
  68. }
  69. public function tearDown()
  70. {
  71. if (isset($this->phpLiveDocx)) {
  72. foreach($this->phpLiveDocx->listTemplates() as $template) {
  73. $this->phpLiveDocx->deleteTemplate($template['filename']);
  74. }
  75. unset($this->phpLiveDocx);
  76. }
  77. }
  78. // -------------------------------------------------------------------------
  79. public function testLoginUsernamePassword()
  80. {
  81. $phpLiveDocx = new Zend_Service_LiveDocx_MailMerge();
  82. $phpLiveDocx->setUsername(TESTS_ZEND_SERVICE_LIVEDOCX_USERNAME);
  83. $phpLiveDocx->setPassword(TESTS_ZEND_SERVICE_LIVEDOCX_PASSWORD);
  84. $this->assertTrue($phpLiveDocx->logIn());
  85. }
  86. public function testLoginUsernamePasswordSoapClient()
  87. {
  88. $phpLiveDocx = new Zend_Service_LiveDocx_MailMerge();
  89. $phpLiveDocx->setUsername(TESTS_ZEND_SERVICE_LIVEDOCX_USERNAME);
  90. $phpLiveDocx->setPassword(TESTS_ZEND_SERVICE_LIVEDOCX_PASSWORD);
  91. $phpLiveDocx->setSoapClient(new Zend_Soap_Client(self::ENDPOINT));
  92. $this->assertTrue($phpLiveDocx->logIn());
  93. }
  94. /**
  95. * @expectedException Zend_Service_LiveDocx_Exception
  96. */
  97. public function testLoginUsernamePasswordException()
  98. {
  99. $phpLiveDocx = new Zend_Service_LiveDocx_MailMerge();
  100. $phpLiveDocx->setUsername('phpunitInvalidUsername');
  101. $phpLiveDocx->setPassword('phpunitInvalidPassword');
  102. $phpLiveDocx->logIn();
  103. }
  104. /**
  105. * @expectedException Zend_Service_LiveDocx_Exception
  106. */
  107. public function testLoginUsernamePasswordSoapClientException()
  108. {
  109. $phpLiveDocx = new Zend_Service_LiveDocx_MailMerge();
  110. $phpLiveDocx->setUsername('phpunitInvalidUsername');
  111. $phpLiveDocx->setPassword('phpunitInvalidPassword');
  112. $phpLiveDocx->setSoapClient(new Zend_Soap_Client(self::ENDPOINT));
  113. $phpLiveDocx->logIn();
  114. }
  115. public function testConstructorOptionsUsernamePassword()
  116. {
  117. $phpLiveDocx = new Zend_Service_LiveDocx_MailMerge(
  118. array (
  119. 'username' => TESTS_ZEND_SERVICE_LIVEDOCX_USERNAME,
  120. 'password' => TESTS_ZEND_SERVICE_LIVEDOCX_PASSWORD
  121. )
  122. );
  123. $this->assertTrue($phpLiveDocx->logIn());
  124. }
  125. public function testConstructorOptionsUsernamePasswordSoapClient()
  126. {
  127. $phpLiveDocx = new Zend_Service_LiveDocx_MailMerge(
  128. array (
  129. 'username' => TESTS_ZEND_SERVICE_LIVEDOCX_USERNAME,
  130. 'password' => TESTS_ZEND_SERVICE_LIVEDOCX_PASSWORD,
  131. 'soapClient' => new Zend_Soap_Client(self::ENDPOINT)
  132. )
  133. );
  134. $this->assertTrue($phpLiveDocx->logIn());
  135. }
  136. // -------------------------------------------------------------------------
  137. public function testSetLocalTemplate()
  138. {
  139. $this->assertTrue(is_a($this->phpLiveDocx->setLocalTemplate($this->path . DIRECTORY_SEPARATOR . self::TEST_TEMPLATE_1), 'Zend_Service_LiveDocx_MailMerge'));
  140. $this->setExpectedException('Zend_Service_LiveDocx_Exception');
  141. @$this->phpLiveDocx->setLocalTemplate('phpunit-nonexistent.doc');
  142. }
  143. public function testSetRemoteTemplate()
  144. {
  145. $this->phpLiveDocx->uploadTemplate($this->path . DIRECTORY_SEPARATOR . self::TEST_TEMPLATE_1);
  146. $this->assertTrue(is_a($this->phpLiveDocx->setRemoteTemplate(self::TEST_TEMPLATE_1), 'Zend_Service_LiveDocx_MailMerge'));
  147. $this->phpLiveDocx->deleteTemplate(self::TEST_TEMPLATE_1);
  148. }
  149. public function testSetFieldValues()
  150. {
  151. $testValues = array('software' => 'phpunit');
  152. // Remote Template
  153. $this->phpLiveDocx->uploadTemplate($this->path . DIRECTORY_SEPARATOR . self::TEST_TEMPLATE_1);
  154. $this->phpLiveDocx->setRemoteTemplate(self::TEST_TEMPLATE_1);
  155. $this->assertTrue(is_a($this->phpLiveDocx->setFieldValues($testValues), 'Zend_Service_LiveDocx_MailMerge'));
  156. $this->phpLiveDocx->deleteTemplate(self::TEST_TEMPLATE_1);
  157. // Local Template
  158. $this->phpLiveDocx->setLocalTemplate($this->path . DIRECTORY_SEPARATOR . self::TEST_TEMPLATE_1);
  159. $this->assertTrue(is_a($this->phpLiveDocx->setFieldValues($testValues), 'Zend_Service_LiveDocx_MailMerge'));
  160. }
  161. public function testSetFieldValue()
  162. {
  163. $testKey = 'software';
  164. $testValue = 'phpunit';
  165. // Remote Template
  166. $this->phpLiveDocx->uploadTemplate($this->path . DIRECTORY_SEPARATOR . self::TEST_TEMPLATE_1);
  167. $this->assertTrue(is_a($this->phpLiveDocx->setFieldValue($testKey, $testValue), 'Zend_Service_LiveDocx_MailMerge'));
  168. $this->phpLiveDocx->deleteTemplate(self::TEST_TEMPLATE_1);
  169. // Local Template
  170. $this->phpLiveDocx->setLocalTemplate($this->path . DIRECTORY_SEPARATOR . self::TEST_TEMPLATE_1);
  171. $this->assertTrue(is_a($this->phpLiveDocx->setFieldValue($testKey, $testValue), 'Zend_Service_LiveDocx_MailMerge'));
  172. }
  173. public function testAssign()
  174. {
  175. $testKey = 'software';
  176. $testValue = 'phpunit';
  177. // Remote Template
  178. $this->phpLiveDocx->uploadTemplate($this->path . DIRECTORY_SEPARATOR . self::TEST_TEMPLATE_1);
  179. $this->assertTrue(is_a($this->phpLiveDocx->assign($testKey, $testValue), 'Zend_Service_LiveDocx_MailMerge'));
  180. $this->phpLiveDocx->deleteTemplate(self::TEST_TEMPLATE_1);
  181. // Local Template
  182. $this->phpLiveDocx->setLocalTemplate($this->path . DIRECTORY_SEPARATOR . self::TEST_TEMPLATE_1);
  183. $this->assertTrue(is_a($this->phpLiveDocx->assign($testKey, $testValue), 'Zend_Service_LiveDocx_MailMerge'));
  184. }
  185. public function testSetBlockFieldValues()
  186. {
  187. $testKey = 'connection';
  188. $testValues = array(array('connection_number' => 'unittest', 'connection_duration' => 'unittest', 'fee' => 'unittest'),
  189. array('connection_number' => 'unittest', 'connection_duration' => 'unittest', 'fee' => 'unittest'),
  190. array('connection_number' => 'unittest', 'connection_duration' => 'unittest', 'fee' => 'unittest'),
  191. array('connection_number' => 'unittest', 'connection_duration' => 'unittest', 'fee' => 'unittest') );
  192. // Remote Template
  193. $this->phpLiveDocx->uploadTemplate($this->path . DIRECTORY_SEPARATOR . self::TEST_TEMPLATE_2);
  194. $this->assertTrue(is_a($this->phpLiveDocx->setBlockFieldValues($testKey, $testValues), 'Zend_Service_LiveDocx_MailMerge'));
  195. $this->phpLiveDocx->deleteTemplate(self::TEST_TEMPLATE_2);
  196. // Local Template
  197. $this->phpLiveDocx->setLocalTemplate($this->path . DIRECTORY_SEPARATOR . self::TEST_TEMPLATE_2);
  198. $this->assertTrue(is_a($this->phpLiveDocx->setBlockFieldValues($testKey, $testValues), 'Zend_Service_LiveDocx_MailMerge'));
  199. }
  200. // -------------------------------------------------------------------------
  201. public function testCreateDocument()
  202. {
  203. $testValues = array(
  204. 'software' => 'phpunit',
  205. 'licensee' => 'phpunit',
  206. 'company' => 'phpunit',
  207. 'date' => 'phpunit',
  208. 'time' => 'phpunit',
  209. 'city' => 'phpunit',
  210. 'country' => 'phpunit',
  211. );
  212. // Remote Template
  213. $this->phpLiveDocx->uploadTemplate($this->path . DIRECTORY_SEPARATOR . self::TEST_TEMPLATE_1);
  214. $this->phpLiveDocx->setRemoteTemplate(self::TEST_TEMPLATE_1);
  215. $this->phpLiveDocx->assign($testValues);
  216. $this->assertNull($this->phpLiveDocx->createDocument());
  217. $this->phpLiveDocx->deleteTemplate(self::TEST_TEMPLATE_1);
  218. // Local Template
  219. $this->phpLiveDocx->setLocalTemplate($this->path . DIRECTORY_SEPARATOR . self::TEST_TEMPLATE_1);
  220. $this->phpLiveDocx->assign($testValues);
  221. $this->assertNull($this->phpLiveDocx->createDocument());
  222. }
  223. public function testRetrieveDocument()
  224. {
  225. $testValues = array(
  226. 'software' => 'phpunit',
  227. 'licensee' => 'phpunit',
  228. 'company' => 'phpunit',
  229. 'date' => 'phpunit',
  230. 'time' => 'phpunit',
  231. 'city' => 'phpunit',
  232. 'country' => 'phpunit',
  233. );
  234. // PDF and DOCs are always slightly different:
  235. // - PDF because of the timestamp in meta data
  236. // - DOC because of ???
  237. $expectedResults = array(
  238. 'docx' => 'f21728491855c27a9e64a47266c2a720',
  239. 'rtf' => 'fb75deabf481b0264927cb4a5c9db765',
  240. 'txd' => 'd1f645405ded0718edff6ae6f50a496e',
  241. 'txt' => 'ec2f680646540edd79cd22773fa7e183',
  242. 'html' => 'e3a28523794b0071501c09f791f8c795',
  243. );
  244. // Remote Template
  245. $this->phpLiveDocx->uploadTemplate($this->path . DIRECTORY_SEPARATOR . self::TEST_TEMPLATE_1);
  246. $this->phpLiveDocx->setRemoteTemplate(self::TEST_TEMPLATE_1);
  247. $this->phpLiveDocx->assign($testValues);
  248. $this->phpLiveDocx->createDocument();
  249. foreach($expectedResults as $format => $hash) {
  250. $document = $this->phpLiveDocx->retrieveDocument($format);
  251. $this->assertEquals($hash, md5($document));
  252. }
  253. $this->phpLiveDocx->deleteTemplate(self::TEST_TEMPLATE_1);
  254. // Local Template
  255. $this->phpLiveDocx->setLocalTemplate($this->path . DIRECTORY_SEPARATOR . self::TEST_TEMPLATE_1);
  256. $this->phpLiveDocx->assign($testValues);
  257. $this->phpLiveDocx->createDocument();
  258. foreach($expectedResults as $format => $hash) {
  259. $document = $this->phpLiveDocx->retrieveDocument($format);
  260. $this->assertEquals($hash, md5($document));
  261. }
  262. }
  263. public function testRetrieveDocumentAppended()
  264. {
  265. $testValues = array(
  266. array(
  267. 'software' => 'phpunit - document 1',
  268. 'licensee' => 'phpunit - document 1',
  269. 'company' => 'phpunit - document 1',
  270. 'date' => 'phpunit - document 1',
  271. 'time' => 'phpunit - document 1',
  272. 'city' => 'phpunit - document 1',
  273. 'country' => 'phpunit - document 1',
  274. ),
  275. array(
  276. 'software' => 'phpunit - document 2',
  277. 'licensee' => 'phpunit - document 2',
  278. 'company' => 'phpunit - document 2',
  279. 'date' => 'phpunit - document 2',
  280. 'time' => 'phpunit - document 2',
  281. 'city' => 'phpunit - document 2',
  282. 'country' => 'phpunit - document 2',
  283. ),
  284. );
  285. // PDF and DOCs are always slightly different:
  286. // - PDF because of the timestamp in meta data
  287. // - DOC because of ???
  288. $expectedResults = array(
  289. 'docx' => '2757b4d10c8c031d8f501231be39fcfe',
  290. 'rtf' => '2997e531011d826f315291fca1351988',
  291. 'txd' => '8377a5a62f2e034974fc299c322d137f',
  292. 'txt' => 'a7d23668f81b314e15d653ab657316f9',
  293. 'html' => '57365a2ff02347a7863626317505e037',
  294. );
  295. // Remote Template
  296. $this->phpLiveDocx->uploadTemplate($this->path . DIRECTORY_SEPARATOR . self::TEST_TEMPLATE_1);
  297. $this->phpLiveDocx->setRemoteTemplate(self::TEST_TEMPLATE_1);
  298. $this->phpLiveDocx->assign($testValues);
  299. $this->phpLiveDocx->createDocument();
  300. foreach($expectedResults as $format => $hash) {
  301. $document = $this->phpLiveDocx->retrieveDocument($format);
  302. $this->assertEquals($hash, md5($document));
  303. }
  304. $this->phpLiveDocx->deleteTemplate(self::TEST_TEMPLATE_1);
  305. // Local Template
  306. $this->phpLiveDocx->setLocalTemplate($this->path . DIRECTORY_SEPARATOR . self::TEST_TEMPLATE_1);
  307. $this->phpLiveDocx->assign($testValues);
  308. $this->phpLiveDocx->createDocument();
  309. foreach($expectedResults as $format => $hash) {
  310. $document = $this->phpLiveDocx->retrieveDocument($format);
  311. $this->assertEquals($hash, md5($document));
  312. }
  313. }
  314. // -------------------------------------------------------------------------
  315. public function testGetTemplateFormats()
  316. {
  317. $expectedResults = array('doc' , 'docx' , 'rtf' , 'txd');
  318. $this->assertEquals($expectedResults, $this->phpLiveDocx->getTemplateFormats());
  319. }
  320. public function testGetDocumentFormats()
  321. {
  322. $expectedResults = array('doc' , 'docx' , 'html' , 'pdf' , 'rtf' , 'txd' , 'txt');
  323. $this->assertEquals($expectedResults, $this->phpLiveDocx->getDocumentFormats());
  324. }
  325. public function testGetImageImportFormats()
  326. {
  327. $expectedResults = array('bmp' , 'gif' , 'jpg' , 'png' , 'tiff', 'wmf');
  328. $this->assertEquals($expectedResults, $this->phpLiveDocx->getImageImportFormats());
  329. }
  330. public function testGetImageExportFormats()
  331. {
  332. $expectedResults = array('bmp' , 'gif' , 'jpg' , 'png' , 'tiff');
  333. $this->assertEquals($expectedResults, $this->phpLiveDocx->getImageExportFormats());
  334. }
  335. // -------------------------------------------------------------------------
  336. public function testGetBitmaps()
  337. {
  338. $testValues = array(
  339. 'software' => 'phpunit',
  340. 'licensee' => 'phpunit',
  341. 'company' => 'phpunit',
  342. 'date' => 'phpunit',
  343. 'time' => 'phpunit',
  344. 'city' => 'phpunit',
  345. 'country' => 'phpunit',
  346. );
  347. $expectedResults = array(
  348. 'bmp' => 'a1934f2153172f021847af7ece9049ce',
  349. 'gif' => 'd7281d7b6352ff897917e25d6b92746f',
  350. 'jpg' => 'e0b20ea2c9a6252886f689f227109085',
  351. 'png' => 'c449f0c2726f869e9a42156e366f1bf9',
  352. 'tiff' => '20a96a94762a531e9879db0aa6bd673f',
  353. );
  354. $this->phpLiveDocx->setLocalTemplate($this->path . DIRECTORY_SEPARATOR . self::TEST_TEMPLATE_1);
  355. $this->phpLiveDocx->assign($testValues);
  356. $this->phpLiveDocx->createDocument();
  357. foreach($this->phpLiveDocx->getImageExportFormats() as $format) {
  358. $bitmaps = $this->phpLiveDocx->getBitmaps(1, 1, 20, $format);
  359. $this->assertEquals($expectedResults[$format], md5(serialize($bitmaps)));
  360. }
  361. }
  362. public function testGetAllBitmaps()
  363. {
  364. $testValues = array(
  365. 'software' => 'phpunit',
  366. 'licensee' => 'phpunit',
  367. 'company' => 'phpunit',
  368. 'date' => 'phpunit',
  369. 'time' => 'phpunit',
  370. 'city' => 'phpunit',
  371. 'country' => 'phpunit',
  372. );
  373. $expectedResults = array(
  374. 'bmp' => 'e8a884ee61c394deec8520fb397d1cf1',
  375. 'gif' => '2255fee47b4af8438b109efc3cb0d304',
  376. 'jpg' => 'e1acfc3001fc62567de2a489eccdb552',
  377. 'png' => '15eac34d08e602cde042862b467fa865',
  378. 'tiff' => '98bad79380a80c9cc43dfffc5158d0f9',
  379. );
  380. $this->phpLiveDocx->setLocalTemplate($this->path . DIRECTORY_SEPARATOR . self::TEST_TEMPLATE_1);
  381. $this->phpLiveDocx->assign($testValues);
  382. $this->phpLiveDocx->createDocument();
  383. foreach($this->phpLiveDocx->getImageExportFormats() as $format) {
  384. $bitmaps = $this->phpLiveDocx->getAllBitmaps(20, $format);
  385. $this->assertEquals($expectedResults[$format], md5(serialize($bitmaps)));
  386. }
  387. }
  388. public function testGetFontNames()
  389. {
  390. $fonts = $this->phpLiveDocx->getFontNames();
  391. if (is_array($fonts) && count($fonts) > 5) {
  392. foreach (array('Courier New' , 'Verdana' , 'Arial' , 'Times New Roman') as $font) {
  393. if (in_array($font, $fonts)) {
  394. $this->assertTrue(true);
  395. } else {
  396. $this->assertTrue(false);
  397. }
  398. }
  399. } else {
  400. $this->assertTrue(false);
  401. }
  402. }
  403. public function testGetFieldNames()
  404. {
  405. $expectedResults = array('phone', 'date', 'name', 'customer_number', 'invoice_number', 'account_number', 'service_phone', 'service_fax', 'month', 'monthly_fee', 'total_net', 'tax', 'tax_value', 'total');
  406. // Remote Template
  407. $this->phpLiveDocx->uploadTemplate($this->path . DIRECTORY_SEPARATOR . self::TEST_TEMPLATE_2);
  408. $this->phpLiveDocx->setRemoteTemplate(self::TEST_TEMPLATE_2);
  409. $this->assertEquals($expectedResults, $this->phpLiveDocx->getFieldNames());
  410. $this->phpLiveDocx->deleteTemplate(self::TEST_TEMPLATE_2);
  411. // Local Template
  412. $this->phpLiveDocx->setLocalTemplate($this->path . DIRECTORY_SEPARATOR . self::TEST_TEMPLATE_2);
  413. $this->assertEquals($expectedResults, $this->phpLiveDocx->getFieldNames());
  414. }
  415. public function testGetBlockFieldNames()
  416. {
  417. $expectedResults = array('connection_number', 'connection_duration', 'fee');
  418. // Remote Template
  419. $this->phpLiveDocx->uploadTemplate($this->path . DIRECTORY_SEPARATOR . self::TEST_TEMPLATE_2);
  420. $this->phpLiveDocx->setRemoteTemplate(self::TEST_TEMPLATE_2);
  421. $this->assertEquals($expectedResults, $this->phpLiveDocx->getBlockFieldNames('connection'));
  422. $this->phpLiveDocx->deleteTemplate(self::TEST_TEMPLATE_2);
  423. // Local Template
  424. $this->phpLiveDocx->setLocalTemplate($this->path . DIRECTORY_SEPARATOR . self::TEST_TEMPLATE_2);
  425. $this->assertEquals($expectedResults, $this->phpLiveDocx->getBlockFieldNames('connection'));
  426. }
  427. public function testGetBlockNames()
  428. {
  429. $expectedResults = array('connection');
  430. // Remote Template
  431. $this->phpLiveDocx->uploadTemplate($this->path . DIRECTORY_SEPARATOR . self::TEST_TEMPLATE_2);
  432. $this->phpLiveDocx->setRemoteTemplate(self::TEST_TEMPLATE_2);
  433. $this->assertEquals($expectedResults, $this->phpLiveDocx->getBlockNames());
  434. $this->phpLiveDocx->deleteTemplate(self::TEST_TEMPLATE_2);
  435. // Local Template
  436. $this->phpLiveDocx->setLocalTemplate($this->path . DIRECTORY_SEPARATOR . self::TEST_TEMPLATE_2);
  437. $this->assertEquals($expectedResults, $this->phpLiveDocx->getBlockNames());
  438. }
  439. // -------------------------------------------------------------------------
  440. public function testUploadTemplate()
  441. {
  442. $this->phpLiveDocx->deleteTemplate(self::TEST_TEMPLATE_2);
  443. $this->assertNull($this->phpLiveDocx->uploadTemplate($this->path . DIRECTORY_SEPARATOR . self::TEST_TEMPLATE_2));
  444. $this->phpLiveDocx->deleteTemplate(self::TEST_TEMPLATE_2);
  445. }
  446. public function testDownloadTemplate()
  447. {
  448. $expectedResults = '2f076af778ca5f8afc9661cfb9deb7c6';
  449. $this->phpLiveDocx->uploadTemplate($this->path . DIRECTORY_SEPARATOR . self::TEST_TEMPLATE_2);
  450. $template = $this->phpLiveDocx->downloadTemplate(self::TEST_TEMPLATE_2);
  451. $this->assertEquals($expectedResults, md5($template));
  452. }
  453. public function testDeleteTemplate()
  454. {
  455. $this->phpLiveDocx->uploadTemplate($this->path . DIRECTORY_SEPARATOR . self::TEST_TEMPLATE_2);
  456. $this->phpLiveDocx->deleteTemplate(self::TEST_TEMPLATE_2);
  457. $templateDeleted = true;
  458. foreach($this->phpLiveDocx->listTemplates() as $template) {
  459. if($template['filename'] == self::TEST_TEMPLATE_2) {
  460. $templateDeleted = false;
  461. }
  462. }
  463. $this->assertTrue($templateDeleted);
  464. }
  465. public function testListTemplates()
  466. {
  467. $this->phpLiveDocx->uploadTemplate($this->path . DIRECTORY_SEPARATOR . self::TEST_TEMPLATE_1);
  468. $this->phpLiveDocx->uploadTemplate($this->path . DIRECTORY_SEPARATOR . self::TEST_TEMPLATE_2);
  469. // Where templates uploaded and are being listed?
  470. $testTemplate1Exists = false;
  471. $testTemplate2Exists = false;
  472. $templates = $this->phpLiveDocx->listTemplates();
  473. foreach($templates as $template) {
  474. if(self::TEST_TEMPLATE_1 === $template['filename']) {
  475. $testTemplate1Exists = true;
  476. } elseif(self::TEST_TEMPLATE_2 === $template['filename']) {
  477. $testTemplate2Exists = true;
  478. }
  479. }
  480. $this->assertTrue($testTemplate1Exists && $testTemplate2Exists);
  481. // Is all info about templates available?
  482. $expectedResults = array('filename', 'fileSize', 'createTime', 'modifyTime');
  483. foreach($templates as $template) {
  484. $this->assertEquals($expectedResults, array_keys($template));
  485. }
  486. // Is all info about templates correct?
  487. foreach($templates as $template) {
  488. $this->assertTrue(strlen($template['filename']) > 0);
  489. $this->assertTrue($template['fileSize'] > 1);
  490. $this->assertTrue($template['createTime'] > mktime(0, 0, 0, 1, 1, 1980));
  491. $this->assertTrue($template['modifyTime'] > mktime(0, 0, 0, 1, 1, 1980));
  492. }
  493. $this->phpLiveDocx->deleteTemplate(self::TEST_TEMPLATE_1);
  494. $this->phpLiveDocx->deleteTemplate(self::TEST_TEMPLATE_2);
  495. }
  496. public function testTemplateExists()
  497. {
  498. $this->phpLiveDocx->uploadTemplate($this->path . DIRECTORY_SEPARATOR . self::TEST_TEMPLATE_2);
  499. $this->assertTrue($this->phpLiveDocx->templateExists(self::TEST_TEMPLATE_2));
  500. $this->phpLiveDocx->deleteTemplate(self::TEST_TEMPLATE_2);
  501. }
  502. // -------------------------------------------------------------------------
  503. public function testUploadImage()
  504. {
  505. $this->phpLiveDocx->deleteImage(self::TEST_IMAGE_2);
  506. $this->assertNull($this->phpLiveDocx->uploadImage($this->path . DIRECTORY_SEPARATOR . self::TEST_IMAGE_2));
  507. $this->phpLiveDocx->deleteImage(self::TEST_IMAGE_2);
  508. }
  509. public function testDownloadImage()
  510. {
  511. $expectedResults = 'f8b663e465acd570414395d5c33541ab';
  512. $this->phpLiveDocx->uploadImage($this->path . DIRECTORY_SEPARATOR . self::TEST_IMAGE_2);
  513. $image = $this->phpLiveDocx->downloadImage(self::TEST_IMAGE_2);
  514. $this->assertEquals($expectedResults, md5($image));
  515. }
  516. public function testDeleteImage()
  517. {
  518. $this->phpLiveDocx->uploadImage($this->path . DIRECTORY_SEPARATOR . self::TEST_IMAGE_2);
  519. $this->phpLiveDocx->deleteImage(self::TEST_IMAGE_2);
  520. $imageDeleted = true;
  521. foreach($this->phpLiveDocx->listImages() as $image) {
  522. if($image['filename'] == self::TEST_IMAGE_2) {
  523. $imageDeleted = false;
  524. }
  525. }
  526. $this->assertTrue($imageDeleted);
  527. }
  528. public function testListImages()
  529. {
  530. $this->phpLiveDocx->uploadImage($this->path . DIRECTORY_SEPARATOR . self::TEST_IMAGE_1);
  531. $this->phpLiveDocx->uploadImage($this->path . DIRECTORY_SEPARATOR . self::TEST_IMAGE_2);
  532. // Where images uploaded and are being listed?
  533. $testImage1Exists = false;
  534. $testImage2Exists = false;
  535. $images = $this->phpLiveDocx->listImages();
  536. foreach($images as $image) {
  537. if(self::TEST_IMAGE_1 === $image['filename']) {
  538. $testImage1Exists = true;
  539. } elseif(self::TEST_IMAGE_2 === $image['filename']) {
  540. $testImage2Exists = true;
  541. }
  542. }
  543. $this->assertTrue($testImage1Exists && $testImage2Exists);
  544. // Is all info about images available?
  545. $expectedResults = array('filename', 'fileSize', 'createTime', 'modifyTime');
  546. foreach($images as $image) {
  547. $this->assertEquals($expectedResults, array_keys($image));
  548. }
  549. // Is all info about images correct?
  550. foreach($images as $image) {
  551. $this->assertTrue(strlen($image['filename']) > 0);
  552. $this->assertTrue($image['fileSize'] > 1);
  553. $this->assertTrue($image['createTime'] > mktime(0, 0, 0, 1, 1, 1980));
  554. $this->assertTrue($image['modifyTime'] > mktime(0, 0, 0, 1, 1, 1980));
  555. }
  556. $this->phpLiveDocx->deleteImage(self::TEST_IMAGE_1);
  557. $this->phpLiveDocx->deleteImage(self::TEST_IMAGE_2);
  558. }
  559. public function testImageExists()
  560. {
  561. $this->phpLiveDocx->uploadImage($this->path . DIRECTORY_SEPARATOR . self::TEST_IMAGE_2);
  562. $this->assertTrue($this->phpLiveDocx->imageExists(self::TEST_IMAGE_2));
  563. $this->phpLiveDocx->deleteImage(self::TEST_IMAGE_2);
  564. }
  565. // -------------------------------------------------------------------------
  566. public function testAssocArrayToArrayOfArrayOfString()
  567. {
  568. $testValues = array(
  569. 'a' => '1',
  570. 'b' => '2',
  571. 'c' => '3',
  572. );
  573. $expectedResults = array(
  574. array('a', 'b', 'c'),
  575. array('1', '2', '3'),
  576. );
  577. $actualResults = Zend_Service_LiveDocx_MailMerge::assocArrayToArrayOfArrayOfString($testValues);
  578. $this->assertEquals($expectedResults, $actualResults);
  579. }
  580. public function testMultiAssocArrayToArrayOfArrayOfString()
  581. {
  582. $testValues = array(
  583. array(
  584. 'a' => '1',
  585. 'b' => '2',
  586. 'c' => '3',
  587. ),
  588. array(
  589. 'a' => '4',
  590. 'b' => '5',
  591. 'c' => '6',
  592. ),
  593. array(
  594. 'a' => '7',
  595. 'b' => '8',
  596. 'c' => '9',
  597. ),
  598. );
  599. $expectedResults = array(
  600. array('a', 'b', 'c'),
  601. array('1', '2', '3'),
  602. array('4', '5', '6'),
  603. array('7', '8', '9'),
  604. );
  605. $actualResults = Zend_Service_LiveDocx_MailMerge::multiAssocArrayToArrayOfArrayOfString($testValues);
  606. $this->assertEquals($expectedResults, $actualResults);
  607. }
  608. }
  609. if (PHPUnit_MAIN_METHOD == 'Zend_Service_LiveDocx_MailMergeTest::main') {
  610. Zend_Service_LiveDocx_MailMergeTest::main();
  611. }