/public_html/test/class/page/LC_Page_Test.php

https://github.com/hatone/EC-CUBE-Ver2.11.3 · PHP · 158 lines · 51 code · 22 blank · 85 comment · 0 complexity · 564f8df8b3a0c1bbe4a20756d0701cac MD5 · raw file

  1. <?php
  2. /*
  3. * This file is part of EC-CUBE
  4. *
  5. * Copyright(c) 2000-2011 LOCKON CO.,LTD. All Rights Reserved.
  6. *
  7. * http://www.lockon.co.jp/
  8. *
  9. * This program is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU General Public License
  11. * as published by the Free Software Foundation; either version 2
  12. * of the License, or (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, write to the Free Software
  21. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  22. */
  23. // {{{ requires
  24. require_once(realpath(dirname(__FILE__)) . '/../../require.php');
  25. require_once(realpath(dirname(__FILE__)) . '/../../../data/class/pages/LC_Page.php');
  26. /**
  27. * LC_Page のテストケース.
  28. *
  29. * @package Page
  30. * @author LOCKON CO.,LTD.
  31. * @version $Id:LC_Page_Test.php 15116 2007-07-23 11:32:53Z nanasess $
  32. */
  33. class LC_Page_Test extends PHPUnit_Framework_TestCase {
  34. // }}}
  35. // {{{ functions
  36. /*
  37. * FIXME LC_Page::sendRedirect() は, リダイレクトしてしまうため,
  38. * PHPUnit3 ではテストできない...
  39. */
  40. /**
  41. * LC_Page::sendRedirect() のテストケース(エラー).
  42. */
  43. /*
  44. function testSendRedirect() {
  45. $objPage = new LC_Page();
  46. $result = $objPage->sendRedirect(HTTP_URL);
  47. $this->assertEquals(true, empty($result));
  48. }
  49. */
  50. /**
  51. * LC_Page::sendRedirect() のテストケース(エラー).
  52. */
  53. /*
  54. function testSendRedirectIsFailed() {
  55. $objPage = new LC_Page();
  56. $result = $objPage->sendRedirect("http://www.example.org");
  57. $this->assertEquals(false, $result);
  58. }
  59. */
  60. /**
  61. * LC_Page::getToken() のテストケース.
  62. */
  63. function testGetToken() {
  64. $objPage = new LC_Page();
  65. $objPage->setTokenTo();
  66. $token = $objPage->transactionid;
  67. // 40文字の16進数
  68. $this->assertEquals(1, preg_match("/[a-f0-9]{40,}/", $token));
  69. // セッションに文字列が格納されているか
  70. $this->assertEquals($token, $_SESSION[TRANSACTION_ID_NAME]);
  71. }
  72. /**
  73. * LC_Page::getLocation() のテストケース.
  74. */
  75. function testGetLocation() {
  76. $objPage = new LC_Page();
  77. $_SERVER['DOCUMENT_ROOT'] = realpath(dirname(__FILE__) . "/../../../html");
  78. $url = $objPage->getLocation("/abouts/index.php");
  79. $this->assertEquals(HTTP_URL . "abouts/index.php", $url);
  80. unset($_SERVER['DOCUMENT_ROOT']);
  81. }
  82. /**
  83. * LC_Page::getLocation() のテストケース.
  84. *
  85. * 絶対パス
  86. */
  87. function testGetLocationWithFullPath() {
  88. $objPage = new LC_Page();
  89. $_SERVER['DOCUMENT_ROOT'] = realpath(dirname(__FILE__) . "/../../../html");
  90. $url = $objPage->getLocation(ROOT_URLPATH . 'abouts/index.php');
  91. $this->assertEquals(HTTP_URL . "abouts/index.php", $url);
  92. unset($_SERVER['DOCUMENT_ROOT']);
  93. }
  94. /**
  95. * LC_Page::getLocation() のテストケース.
  96. *
  97. * QueryString 付与
  98. */
  99. function testGetLocationWithQueryString() {
  100. $objPage = new LC_Page();
  101. $_SERVER['DOCUMENT_ROOT'] = realpath(dirname(__FILE__) . "/../../../html");
  102. $queryString = array("mode" => "update", "type" => "text");
  103. $url = $objPage->getLocation("/abouts/index.php", $queryString);
  104. $this->assertEquals(HTTP_URL . "abouts/index.php?mode=update&type=text", $url);
  105. unset($_SERVER['DOCUMENT_ROOT']);
  106. }
  107. /**
  108. * LC_Page::getLocation() のテストケース.
  109. *
  110. * HTTPS_URL 使用
  111. */
  112. function testGetLocationUseSSL() {
  113. $objPage = new LC_Page();
  114. $_SERVER['DOCUMENT_ROOT'] = realpath(dirname(__FILE__) . "/../../../html");
  115. $queryString = array("mode" => "update", "type" => "text");
  116. $url = $objPage->getLocation("/abouts/index.php", $queryString, true);
  117. $this->assertEquals(HTTPS_URL . "abouts/index.php?mode=update&type=text", $url);
  118. unset($_SERVER['DOCUMENT_ROOT']);
  119. }
  120. /**
  121. * LC_Page::getLocation() のテストケース.
  122. *
  123. * DocumentRoot 指定
  124. */
  125. function testGetLocationWithDocumentRoot() {
  126. $objPage = new LC_Page();
  127. $documentRoot = realpath(dirname(__FILE__) . "/../../../html");
  128. $queryString = array("mode" => "update", "type" => "text");
  129. $url = $objPage->getLocation("/abouts/index.php", array(),
  130. false, $documentRoot);
  131. $this->assertEquals(HTTP_URL . "abouts/index.php", $url);
  132. }
  133. }
  134. ?>