1--TEST--
2Bug #66431 Special Character via COM Interface (CP_UTF8), Application.Word
3--EXTENSIONS--
4com_dotnet
5--SKIPIF--
6<?php
7try {
8    new COM("word.application", NULL, CP_UTF8);
9} catch (Exception $e) {
10    die('skip ' . $e->getMessage());
11}
12
13?>
14--FILE--
15<?php
16
17$text= "Xin chào cộng đồng PHP";
18$fpath = str_replace("/", "\\", __DIR__ . "/bug66431.docx");
19
20com_load_typelib('Word.Application');
21
22$Wrd = new COM("word.application", NULL, CP_UTF8);
23$Wrd->Documents->Add();
24$Wrd->Selection->TypeText($text);
25$Wrd->ActiveDocument->SaveAs($fpath);
26$Wrd->ActiveDocument->Close(false);
27$Wrd->Application->Quit();
28unset($Wrd);
29
30$Wrd = new COM("word.application", NULL, CP_UTF8);
31$Wrd->Documents->Open($fpath, NULL, false);
32$check_text = $Wrd->ActiveDocument->Range($Wrd->ActiveDocument->Sentences(1)->Start, $Wrd->ActiveDocument->Sentences(1)->End)->Text;
33$Wrd->ActiveDocument->Close(false);
34$Wrd->Application->Quit();
35unset($Wrd);
36
37/* trim the returned text as we'll get windows eol from a word doc. */
38$result = (trim($check_text) == $text);
39
40var_dump($result);
41
42if (!$result) {
43    echo "Expected: '$check_text'\n";
44    echo "Have: '$text'\n";
45}
46
47?>
48--CLEAN--
49<?php
50
51$fpath = str_replace("/", "\\", __DIR__ . "/bug66431.docx");
52
53if (file_exists($fpath)) {
54    unlink($fpath);
55}
56?>
57--EXPECT--
58bool(true)
59