source: branches/version-2_12-dev/tests/class/util/SC_Utils/SC_Utils_sfCutStringTest.php @ 22796

Revision 22796, 5.4 KB checked in by h_yoshimoto, 11 years ago (diff)

#2236 2.12.3リリース以降の2.12-devへのコミット差し戻し

  • Property svn:keywords set to Id Rev Date
Line 
1<?php
2
3$HOME = realpath(dirname(__FILE__)) . "/../../../..";
4require_once($HOME . "/tests/class/Common_TestCase.php");
5/*
6 * This file is part of EC-CUBE
7 *
8 * Copyright(c) 2000-2013 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 */
34class SC_Utils_sfCutStringTest extends Common_TestCase {
35
36
37  protected function setUp() {
38    // parent::setUp();
39  }
40
41  protected function tearDown() {
42    // parent::tearDown();
43  }
44
45  /////////////////////////////////////////
46  public function testSfCutString_マルチバイト指定で指定長より2文字以上長い場合_指定長でカットされる() {
47    $input = 'あいうえおABC、こんにちは。';
48    $this->expected = 'あいうえおABC、こんにち...';
49    $this->actual = SC_Utils::sfCutString($input, 13, false);
50
51    $this->verify();
52  }
53
54  public function testSfCutString_マルチバイト指定で指定長より1文字長い場合_カットされない() {
55    $input = 'あいうえおABC、こんにちは';
56    $this->expected = 'あいうえおABC、こんにちは';
57    $this->actual = SC_Utils::sfCutString($input, 13, false);
58
59    $this->verify();
60  }
61
62  public function testSfCutString_マルチバイト指定で指定長以内の場合_カットされない() {
63    $input = 'あいうえおABC、こんにち';
64    $this->expected = 'あいうえおABC、こんにち';
65    $this->actual = SC_Utils::sfCutString($input, 13, false);
66
67    $this->verify();
68  }
69
70  public function testSfCutString_1バイト指定で指定長より3文字以上長い場合_指定長でカットされる() {
71    $input = 'hello, world!!';
72    $this->expected = 'hello, worl...';
73    $this->actual = SC_Utils::sfCutString($input, 11);
74
75    $this->verify();
76  }
77
78  public function testSfCutString_1バイト指定で指定長より2文字長い場合_カットされない() {
79    $input = 'hello, world!';
80    $this->expected = 'hello, world!';
81    $this->actual = SC_Utils::sfCutString($input, 11);
82
83    $this->verify();
84  }
85
86  public function testSfCutString_1バイト指定で指定長より1文字長い場合_カットされない() {
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バイト指定で指定長以内の場合_カットされない() {
95    $input = 'hello, worl';
96    $this->expected = 'hello, worl';
97    $this->actual = SC_Utils::sfCutString($input, 11);
98
99    $this->verify();
100  }
101
102  // [までの場合
103  public function testSfCutString_絵文字を含んでカットされる場合_中途半端な絵文字がカットされる1() {
104    $input = "hello[emoji:135], world.";
105    $this->expected = 'hello...';
106    $this->actual = SC_Utils::sfCutString($input, 6);
107
108    $this->verify();
109  }
110
111  // ]の直前までの場合
112  public function testSfCutString_絵文字を含んでカットされる場合_中途半端な絵文字がカットされる2() {
113    $input = "hello[emoji:135], world.";
114    $this->expected = 'hello...';
115    $this->actual = SC_Utils::sfCutString($input, 15);
116
117    $this->verify();
118  }
119
120  // 最初の絵文字の途中
121  public function testSfCutString_複数の絵文字を含んでいてカットされる場合_中途半端な絵文字がカットされる1() {
122    $input = "hello[emoji:100][emoji:20], world![emoji:10]";
123    $this->expected = 'hello...';
124    $this->actual = SC_Utils::sfCutString($input, 10);
125
126    $this->verify();
127  }
128
129  // 2つめの絵文字の途中
130  public function testSfCutString_複数の絵文字を含んでいてカットされる場合_中途半端な絵文字がカットされる2() {
131    $input = "hello[emoji:100][emoji:20], world![emoji:10]";
132    $this->expected = 'hello[emoji:100]...';
133    $this->actual = SC_Utils::sfCutString($input, 20);
134
135    $this->verify();
136  }
137
138  // 3つめの絵文字の途中
139  public function testSfCutString_複数の絵文字を含んでいてカットされる場合_中途半端な絵文字がカットされる3() {
140    $input = "hello[emoji:100][emoji:20], world![emoji:10]";
141    $this->expected = 'hello[emoji:100][emoji:20], wo...';
142    $this->actual = SC_Utils::sfCutString($input, 30);
143   
144    $this->verify();
145  }
146
147  // TODO 要確認 三点リーダ付けない場合は、lenと比較した方が良いのでは?
148  public function testSfCutString_三点リーダ付加指定がない場合_付加されない() {
149    $input = 'hello, world';
150    $this->expected = 'hello';
151    $this->actual = SC_Utils::sfCutString($input, 5, true, false);
152
153    $this->verify();
154  }
155
156  //////////////////////////////////////////
157
158}
159
Note: See TracBrowser for help on using the repository browser.