0011730: fix doc export for php7
[tine20] / tests / tine20 / Addressbook / Export / DocTest.php
1 <?php
2 /**
3  * Tine 2.0 - http://www.tine20.org
4  *
5  * @package     Addressbook
6  * @license     http://www.gnu.org/licenses/agpl.html
7  * @copyright   Copyright (c) 2008-2016 Metaways Infosystems GmbH (http://www.metaways.de)
8  * @author      Cornelius WeiƟ <c.weiss@metaways.de>
9  */
10
11 use \PhpOffice\PhpWord;
12
13 /**
14  * Addressbook Doc generation class tests
15  *
16  * @package     Addressbook
17  * @subpackage  Export
18  */
19 class Addressbook_Export_DocTest extends TestCase
20 {
21     public function testExportLetter()
22     {
23         // make sure definition is imported
24         $definitionFile = __DIR__ . '/../../../../tine20/Addressbook/Export/definitions/adb_default_doc.xml';
25         $app = Tinebase_Application::getInstance()->getApplicationByName('Addressbook');
26         Tinebase_ImportExportDefinition::getInstance()->updateOrCreateFromFilename($definitionFile, $app);
27
28         $filter = new Addressbook_Model_ContactFilter(array(
29             array('field' => 'n_given', 'operator' => 'equals', 'value' => 'James')
30         ));
31         $doc = new Addressbook_Export_Doc($filter);
32         $doc->generate();
33
34         $tempfile = tempnam(Tinebase_Core::getTempDir(), __METHOD__ . '_') . '.docx';
35         $doc->save($tempfile);
36
37         $this->assertGreaterThan(0, filesize($tempfile));
38     }
39
40     // read and write sucks
41     // TODO make this work or remove it
42     public function _testReadWriteCycleSucks()
43     {
44         PhpWord\Settings::setTempDir(Tinebase_Core::getTempDir());
45
46         $source = str_replace('tests/tine20', 'tine20', __DIR__) . '/templates/addressbook_contact_letter.docx';
47         $phpWord = PhpWord\IOFactory::load($source);
48
49         $tempfile = tempnam(Tinebase_Core::getTempDir(), __METHOD__ . '_') . '.docx';
50         $writer = $phpWord->save($tempfile);
51
52         `open $tempfile`;
53     }
54 }