| 1 | <?php |
|---|
| 2 | |
|---|
| 3 | $HOME = realpath(dirname(__FILE__)) . "/../../../.."; |
|---|
| 4 | require_once($HOME . "/tests/class/Common_TestCase.php"); |
|---|
| 5 | /* |
|---|
| 6 | * This file is part of EC-CUBE |
|---|
| 7 | * |
|---|
| 8 | * Copyright(c) 2000-2014 LOCKON CO.,LTD. All Rights Reserved. |
|---|
| 9 | * |
|---|
| 10 | * http://www.lockon.co.jp/ |
|---|
| 11 | * |
|---|
| 12 | * This program is free software; you can redistribute it and/or |
|---|
| 13 | * modify it under the terms of the GNU General Public License |
|---|
| 14 | * as published by the Free Software Foundation; either version 2 |
|---|
| 15 | * of the License, or (at your option) any later version. |
|---|
| 16 | * |
|---|
| 17 | * This program is distributed in the hope that it will be useful, |
|---|
| 18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 20 | * GNU General Public License for more details. |
|---|
| 21 | * |
|---|
| 22 | * You should have received a copy of the GNU General Public License |
|---|
| 23 | * along with this program; if not, write to the Free Software |
|---|
| 24 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|---|
| 25 | */ |
|---|
| 26 | |
|---|
| 27 | /** |
|---|
| 28 | * SC_Utils::sfCutString()のテストクラス. |
|---|
| 29 | * |
|---|
| 30 | * |
|---|
| 31 | * @author Hiroko Tamagawa |
|---|
| 32 | * @version $Id$ |
|---|
| 33 | */ |
|---|
| 34 | class SC_Utils_sfCutStringTest extends Common_TestCase |
|---|
| 35 | { |
|---|
| 36 | |
|---|
| 37 | |
|---|
| 38 | protected function setUp() |
|---|
| 39 | { |
|---|
| 40 | // parent::setUp(); |
|---|
| 41 | } |
|---|
| 42 | |
|---|
| 43 | protected function tearDown() |
|---|
| 44 | { |
|---|
| 45 | // parent::tearDown(); |
|---|
| 46 | } |
|---|
| 47 | |
|---|
| 48 | ///////////////////////////////////////// |
|---|
| 49 | public function testSfCutString_マルチバイト指定で指定長より2文字以上長い場合_指定長でカットされる() |
|---|
| 50 | { |
|---|
| 51 | $input = 'あいうえおABC、こんにちは。'; |
|---|
| 52 | $this->expected = 'あいうえおABC、こんにち...'; |
|---|
| 53 | $this->actual = SC_Utils::sfCutString($input, 13, false); |
|---|
| 54 | |
|---|
| 55 | $this->verify(); |
|---|
| 56 | } |
|---|
| 57 | |
|---|
| 58 | public function testSfCutString_マルチバイト指定で指定長より1文字長い場合_カットされない() |
|---|
| 59 | { |
|---|
| 60 | $input = 'あいうえおABC、こんにちは'; |
|---|
| 61 | $this->expected = 'あいうえおABC、こんにちは'; |
|---|
| 62 | $this->actual = SC_Utils::sfCutString($input, 13, false); |
|---|
| 63 | |
|---|
| 64 | $this->verify(); |
|---|
| 65 | } |
|---|
| 66 | |
|---|
| 67 | public function testSfCutString_マルチバイト指定で指定長以内の場合_カットされない() |
|---|
| 68 | { |
|---|
| 69 | $input = 'あいうえおABC、こんにち'; |
|---|
| 70 | $this->expected = 'あいうえおABC、こんにち'; |
|---|
| 71 | $this->actual = SC_Utils::sfCutString($input, 13, false); |
|---|
| 72 | |
|---|
| 73 | $this->verify(); |
|---|
| 74 | } |
|---|
| 75 | |
|---|
| 76 | public function testSfCutString_1バイト指定で指定長より3文字以上長い場合_指定長でカットされる() |
|---|
| 77 | { |
|---|
| 78 | $input = 'hello, world!!'; |
|---|
| 79 | $this->expected = 'hello, worl...'; |
|---|
| 80 | $this->actual = SC_Utils::sfCutString($input, 11); |
|---|
| 81 | |
|---|
| 82 | $this->verify(); |
|---|
| 83 | } |
|---|
| 84 | |
|---|
| 85 | public function testSfCutString_1バイト指定で指定長より2文字長い場合_カットされない() |
|---|
| 86 | { |
|---|
| 87 | $input = 'hello, world!'; |
|---|
| 88 | $this->expected = 'hello, world!'; |
|---|
| 89 | $this->actual = SC_Utils::sfCutString($input, 11); |
|---|
| 90 | |
|---|
| 91 | $this->verify(); |
|---|
| 92 | } |
|---|
| 93 | |
|---|
| 94 | public function testSfCutString_1バイト指定で指定長より1文字長い場合_カットされない() |
|---|
| 95 | { |
|---|
| 96 | $input = 'hello, world'; |
|---|
| 97 | $this->expected = 'hello, world'; |
|---|
| 98 | $this->actual = SC_Utils::sfCutString($input, 11); |
|---|
| 99 | |
|---|
| 100 | $this->verify(); |
|---|
| 101 | } |
|---|
| 102 | |
|---|
| 103 | public function testSfCutString_1バイト指定で指定長以内の場合_カットされない() |
|---|
| 104 | { |
|---|
| 105 | $input = 'hello, worl'; |
|---|
| 106 | $this->expected = 'hello, worl'; |
|---|
| 107 | $this->actual = SC_Utils::sfCutString($input, 11); |
|---|
| 108 | |
|---|
| 109 | $this->verify(); |
|---|
| 110 | } |
|---|
| 111 | |
|---|
| 112 | // [までの場合 |
|---|
| 113 | public function testSfCutString_絵文字を含んでカットされる場合_中途半端な絵文字がカットされる1() |
|---|
| 114 | { |
|---|
| 115 | $input = "hello[emoji:135], world."; |
|---|
| 116 | $this->expected = 'hello...'; |
|---|
| 117 | $this->actual = SC_Utils::sfCutString($input, 6); |
|---|
| 118 | |
|---|
| 119 | $this->verify(); |
|---|
| 120 | } |
|---|
| 121 | |
|---|
| 122 | // ]の直前までの場合 |
|---|
| 123 | public function testSfCutString_絵文字を含んでカットされる場合_中途半端な絵文字がカットされる2() |
|---|
| 124 | { |
|---|
| 125 | $input = "hello[emoji:135], world."; |
|---|
| 126 | $this->expected = 'hello...'; |
|---|
| 127 | $this->actual = SC_Utils::sfCutString($input, 15); |
|---|
| 128 | |
|---|
| 129 | $this->verify(); |
|---|
| 130 | } |
|---|
| 131 | |
|---|
| 132 | // 最初の絵文字の途中 |
|---|
| 133 | public function testSfCutString_複数の絵文字を含んでいてカットされる場合_中途半端な絵文字がカットされる1() |
|---|
| 134 | { |
|---|
| 135 | $input = "hello[emoji:100][emoji:20], world![emoji:10]"; |
|---|
| 136 | $this->expected = 'hello...'; |
|---|
| 137 | $this->actual = SC_Utils::sfCutString($input, 10); |
|---|
| 138 | |
|---|
| 139 | $this->verify(); |
|---|
| 140 | } |
|---|
| 141 | |
|---|
| 142 | // 2つめの絵文字の途中 |
|---|
| 143 | public function testSfCutString_複数の絵文字を含んでいてカットされる場合_中途半端な絵文字がカットされる2() |
|---|
| 144 | { |
|---|
| 145 | $input = "hello[emoji:100][emoji:20], world![emoji:10]"; |
|---|
| 146 | $this->expected = 'hello[emoji:100]...'; |
|---|
| 147 | $this->actual = SC_Utils::sfCutString($input, 20); |
|---|
| 148 | |
|---|
| 149 | $this->verify(); |
|---|
| 150 | } |
|---|
| 151 | |
|---|
| 152 | // 3つめの絵文字の途中 |
|---|
| 153 | public function testSfCutString_複数の絵文字を含んでいてカットされる場合_中途半端な絵文字がカットされる3() |
|---|
| 154 | { |
|---|
| 155 | $input = "hello[emoji:100][emoji:20], world![emoji:10]"; |
|---|
| 156 | $this->expected = 'hello[emoji:100][emoji:20], wo...'; |
|---|
| 157 | $this->actual = SC_Utils::sfCutString($input, 30); |
|---|
| 158 | |
|---|
| 159 | $this->verify(); |
|---|
| 160 | } |
|---|
| 161 | |
|---|
| 162 | // TODO 要確認 三点リーダ付けない場合は、lenと比較した方が良いのでは? |
|---|
| 163 | public function testSfCutString_三点リーダ付加指定がない場合_付加されない() |
|---|
| 164 | { |
|---|
| 165 | $input = 'hello, world'; |
|---|
| 166 | $this->expected = 'hello'; |
|---|
| 167 | $this->actual = SC_Utils::sfCutString($input, 5, true, false); |
|---|
| 168 | |
|---|
| 169 | $this->verify(); |
|---|
| 170 | } |
|---|
| 171 | |
|---|
| 172 | ////////////////////////////////////////// |
|---|
| 173 | } |
|---|
| 174 | |
|---|