bug66431_1.phpt 1.3 KB

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