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

Revision 22796, 2.5 KB checked in by h_yoshimoto, 13 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::sfGetUniqRandomId()のテストクラス.
29 * ランダムな生成結果をすべてテストすることはできないため,
30 * 文字数とランダム性のみをチェックする.
31 *
32 * @author Hiroko Tamagawa
33 * @version $Id$
34 */
35class SC_Utils_sfGetUniqRandomIdTest extends Common_TestCase {
36
37
38  protected function setUp() {
39    // parent::setUp();
40  }
41
42  protected function tearDown() {
43    // parent::tearDown();
44  }
45
46  /////////////////////////////////////////
47  public function test_prefix指定が無い場合_21文字のランダムな文字列が生成される() {
48    $output1 = SC_Utils::sfGetUniqRandomId();
49    $output2 = SC_Utils::sfGetUniqRandomId();
50
51    $this->assertEquals(21, strlen($output1), '文字列1の長さ');
52    $this->assertEquals(21, strlen($output2), '文字列2の長さ');
53    $this->assertNotEquals($output1, $output2, '生成結果がランダムになる');
54  }
55
56  public function test_prefix指定がある場合_prefixのあとに21文字のランダムな文字列が生成される() {
57    $output1 = SC_Utils::sfGetUniqRandomId('hello');
58    $output2 = SC_Utils::sfGetUniqRandomId('hello');
59
60    $this->assertEquals(26, strlen($output1), '文字列1の長さ');
61    $this->assertEquals('hello', substr($output1, 0, 5), 'prefix1');
62    $this->assertEquals(26, strlen($output2), '文字列2の長さ');
63    $this->assertEquals('hello', substr($output2, 0, 5), 'prefix2');
64    $this->assertNotEquals($output1, $output2, '生成結果がランダムになる');
65  }
66
67  //////////////////////////////////////////
68
69}
70
Note: See TracBrowser for help on using the repository browser.