Permalink
Browse files

First commit. Importing 1.5 branch from Google Code

  • Loading branch information...
0 parents commit 9ff529aff72c8722d6ec113f78d7894c718e44c9 @tylerhall committed Feb 25, 2009
@@ -0,0 +1,15 @@
+# This turns on mod_rewrite and redirects any paths that don't physically exist
+# to /index.php. You can then access that path info (to determine what to do) in
+# PHP using $_SERVER['REQUEST_URI'] and $_SERVER['REDIRECT_URL']. This is an easy
+# way to avoid having hundreds of rewrite rules slowing down Apache and making things
+# more complicated than they should be.
+
+# Note: If you're having trouble making Apache pickup your .htaccess file,
+# make sure AllowOverride is set to "All" instead of "None".
+
+# RewriteEngine On
+# RewriteBase /
+
+# RewriteCond %{REQUEST_FILENAME} !-f # If not a file...
+# RewriteCond %{REQUEST_FILENAME} !-d # and not a directory...
+# RewriteRule . /index.php [L] # serve index.php
29 LICENSE
@@ -0,0 +1,29 @@
+* Copyright (c) 2006 - 2008, Simple PHP Framework <tylerhall@gmail.com>
+* http://code.google.com/p/simple-php-framework/
+* All rights reserved.
+*
+* This software is released under the terms of the New BSD License.
+* http://www.opensource.org/licenses/bsd-license.php
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions are met:
+* * Redistributions of source code must retain the above copyright
+* notice, this list of conditions and the following disclaimer.
+* * Redistributions in binary form must reproduce the above copyright
+* notice, this list of conditions and the following disclaimer in the
+* documentation and/or other materials provided with the distribution.
+* * Neither the name of the Simple PHP Framework nor the
+* names of its contributors may be used to endorse or promote products
+* derived from this software without specific prior written permission.
+*
+* THIS SOFTWARE IS PROVIDED BY Simple PHP Framework "AS IS" AND ANY
+* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+* DISCLAIMED. IN NO EVENT SHALL Simple PHP Framework OR ITS CONTRIBUTORS
+* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+* THE POSSIBILITY OF SUCH DAMAGE.
@@ -0,0 +1,26 @@
+--
+-- Table structure for table `sessions`
+--
+
+CREATE TABLE `sessions` (
+ `id` varchar(255) collate utf8_unicode_ci NOT NULL,
+ `data` text collate utf8_unicode_ci NOT NULL,
+ `updated_on` int(10) NOT NULL,
+ PRIMARY KEY (`id`)
+) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+
+-- --------------------------------------------------------
+
+--
+-- Table structure for table `users`
+--
+
+CREATE TABLE `users` (
+ `id` int(11) NOT NULL auto_increment,
+ `username` varchar(65) collate utf8_unicode_ci NOT NULL,
+ `password` varchar(65) collate utf8_unicode_ci NOT NULL,
+ `level` enum('user','admin') collate utf8_unicode_ci NOT NULL,
+ `email` varchar(65) collate utf8_unicode_ci default NULL,
+ PRIMARY KEY (`id`),
+ UNIQUE KEY `username` (`username`)
+) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
@@ -0,0 +1 @@
+<?PHP phpinfo();
@@ -0,0 +1,124 @@
+<?PHP
+ class Test
+ {
+ public $log;
+ public $numPass;
+ public $numFail;
+ public $info;
+
+ public function __construct()
+ {
+ $this->log = array();
+ $this->numPass = 0;
+ $this->numFail = 0;
+
+ $this->runTests();
+ $this->outputText();
+ }
+
+ public function runTests()
+ {
+ foreach(get_class_methods(get_class($this)) as $m)
+ {
+ if(preg_match('/^test[A-Z].*/', $m) > 0)
+ {
+ $this->info = null;
+ $this->$m();
+ }
+ }
+ }
+
+ public function outputText()
+ {
+ foreach($this->log as $log)
+ {
+ if($log['result'] == 'fail')
+ {
+ echo "*** {$log['function']}\n";
+ echo "Test: {$log['test']}\n";
+ echo "val: {$log['args'][0]}\n";
+ for($i = 1; $i < count($log['args']); $i++)
+ echo "arg$i: {$log['args'][$i]}\n";
+ if(isset($this->info))
+ echo "Info: {$this->info}\n";
+ echo "\n";
+ }
+ elseif($log['result'] == 'pass')
+ {
+ // echo "PASSED {$log['function']}\n";
+ }
+ }
+
+ echo get_class($this) . ' - ';
+ if($this->numFail == 0)
+ echo "Passed {$this->numPass} tests successfully.\n";
+ else
+ echo "Failed {$this->numFail} tests.\n";
+ }
+
+ public function doFail()
+ {
+ $this->fail();
+ }
+
+ public function doPass()
+ {
+ $this->pass();
+ }
+
+ private function fail()
+ {
+ $bt = debug_backtrace();
+ $arr = array();
+ $arr['function'] = $bt[2]['function'];
+ $arr['result'] = 'fail';
+ $arr['test'] = $bt[1]['function'];
+ $arr['args'] = $bt[1]['args'];
+ $this->log[] = $arr;
+ $this->numFail++;
+ }
+
+ private function pass()
+ {
+ $bt = debug_backtrace();
+ $arr = array();
+ $arr['function'] = $bt[2]['function'];
+ $arr['result'] = 'pass';
+ $arr['test'] = $bt[1]['function'];
+ $arr['args'] = $bt[1]['args'];
+ $this->log[] = $arr;
+ $this->numPass++;
+ }
+
+ public function true($val)
+ {
+ if($val !== true)
+ $this->fail();
+ else
+ $this->pass();
+ }
+
+ public function false($val)
+ {
+ if($val !== false)
+ $this->fail();
+ else
+ $this->pass();
+ }
+
+ public function equals($val, $exp1)
+ {
+ if($val != $exp1)
+ $this->fail();
+ else
+ $this->pass();
+ }
+
+ public function range($val, $min, $max)
+ {
+ if($val < $min || $val > $max)
+ $this->fail();
+ else
+ $this->pass();
+ }
+ }
@@ -0,0 +1,3 @@
+<?PHP
+ include 'test.class.loop.php';
+ include 'test.functions.inc.php';
@@ -0,0 +1,36 @@
+<?PHP
+ require_once 'class.test.php';
+ require_once '../../includes/class.loop.php';
+
+ class TestLoop extends Test
+ {
+ function testGet()
+ {
+ $l = new Loop('foo', 'bar', 'charlie');
+ $this->equals($l->get(), 'foo');
+ $this->equals($l->get(), 'bar');
+ $this->equals($l->get(), 'charlie');
+ $this->equals($l->get(), 'foo');
+ }
+
+ function testToString()
+ {
+ $l = new Loop('foo', 'bar', 'charlie');
+ $this->equals($l->__tostring(), 'foo');
+ $this->equals($l->__tostring(), 'bar');
+ $this->equals($l->__tostring(), 'charlie');
+ $this->equals($l->__tostring(), 'foo');
+ }
+
+ function testRandom()
+ {
+ $l = new Loop('foo', 'bar', 'charlie');
+ $arr = array('foo', 'bar', 'charlie');
+ $this->true(in_array($l->rand(), $arr));
+ $this->true(in_array($l->rand(), $arr));
+ $this->true(in_array($l->rand(), $arr));
+ $this->true(in_array($l->rand(), $arr));
+ }
+ }
+
+ $t = new TestLoop();
@@ -0,0 +1,150 @@
+<?PHP
+ require_once 'class.test.php';
+ require_once '../../includes/functions.inc.php';
+
+ class TestFunctions extends Test
+ {
+ function testSlugify()
+ {
+ $this->equals(slugify('Hello! This is a test 1...2...3...'), 'hello-this-is-a-test-123');
+ }
+
+ function testCalendar()
+ {
+ for($year = 1998; $year <= 2010; $year++)
+ {
+ for($month = 1; $month <= 12; $month++)
+ {
+ $this->info = "$month/$year";
+ $this->range(count(calendar($month, $year)), 4, 6);
+ }
+ }
+ }
+
+ function testPickOff()
+ {
+ $_SERVER['REQUEST_URI'] = '/people/tylerhall/tags/apple';
+ $ret = pick_off();
+ if($ret['people'] != 'tylerhall' || $ret['tags'] != 'apple' || count($ret) != 2)
+ $this->doFail($_SERVER['REQUEST_URI']);
+ else
+ $this->doPass();
+
+ $_SERVER['REQUEST_URI'] = '/people/tylerhall/tags/apple';
+ $ret = pick_off(false);
+ if($ret['people'] != 'tylerhall' || $ret['tags'] != 'apple' || count($ret) != 2)
+ $this->doFail($_SERVER['REQUEST_URI']);
+ else
+ $this->doPass();
+
+ $_SERVER['REQUEST_URI'] = '/newest/people/tylerhall/tags/apple';
+ $ret = pick_off(true);
+ if($ret[0] != 'newest' || $ret['people'] != 'tylerhall' || $ret['tags'] != 'apple' || count($ret) != 3)
+ $this->doFail($_SERVER['REQUEST_URI']);
+ else
+ $this->doPass();
+ }
+
+ function testDater()
+ {
+ $ts = time();
+ $date = date('Y-m-d H:i:s', $ts);
+
+ $this->equals(dater($ts, 'Y-m-d H:i:s'), $date);
+ $this->equals(dater($date, 'Y-m-d H:i:s'), $date);
+ $this->equals(dater(strtotime($date), 'Y-m-d H:i:s'), $date);
+ }
+
+ function testFormatPhone()
+ {
+ $this->equals(format_phone('6154295938'), "(615) 429-5938");
+ $this->equals(format_phone('615-429-5938'), "(615) 429-5938");
+ $this->equals(format_phone("(615)-429-5938"), "(615) 429-5938");
+ $this->equals(format_phone('615.429.5938'), "(615) 429-5938");
+ $this->equals(format_phone('4295938'), '429-5938');
+ $this->equals(format_phone('429-5938'), '429-5938');
+ $this->equals(format_phone('429-5938'), '429-5938');
+ $this->equals(format_phone('429.5938'), '429-5938');
+ $this->equals(format_phone("429.ASF*^&%AS*^5938"), '429-5938');
+ }
+
+ function testRemoteFilesize()
+ {
+ $this->equals(remote_filesize("http://s3.amazonaws.com/amz.clickontyler.com/blog/105home.png"), '132729');
+ }
+
+ function testBytes2Str()
+ {
+ $arr = array('0.9B', '1B', '1.1B', '921.6B', '1KB', '1.1KB', '921.6KB', '1MB', '1.1MB', '921.6MB', '1GB', '1.1GB', '921.6GB', '1TB', '1.1TB', '921.6TB', '1PB', '1.1PB', '921.6PB', '1EB', '1.1EB', '921.6EB', '1ZB', '1.1ZB', '921.6ZB', '1YB', '1.1YB');
+ for($i = 0; $i < 9; $i++)
+ {
+ $this->equals(bytes2str(pow(1024, $i) *.9, 2), array_shift($arr));
+ $this->equals(bytes2str(pow(1024, $i), 2), array_shift($arr));
+ $this->equals(bytes2str(pow(1024, $i) * 1.1, 2), array_shift($arr));
+ }
+ }
+
+ function testSlash()
+ {
+ $this->equals(slash('foobar/'), 'foobar/');
+ $this->equals(slash('/foobar/'), '/foobar/');
+ $this->equals(slash('/foobar'), '/foobar/');
+ $this->equals(slash('/foobar///'), '/foobar/');
+ }
+
+ function testUnslash()
+ {
+ $this->equals(unslash('foobar/'), 'foobar');
+ $this->equals(unslash('/foobar/'), '/foobar');
+ $this->equals(unslash('/foobar'), '/foobar');
+ $this->equals(unslash('/foobar///'), '/foobar');
+ }
+
+ function testGimme()
+ {
+ $arr = array(array(1, 3, 5, 7, 9),
+ array(2, 4, 5, 6, 1),
+ array(3, 1, 4, 4, 5));
+ $this->true(array(1, 2, 3) === gimme($arr));
+ $this->true(array(3, 4, 1) === gimme($arr, 1));
+ $this->true(array(9, 1, 5) === gimme($arr, 4));
+ }
+
+ function testValidEmail()
+ {
+ $this->true(valid_email("email@foo123.com"));
+ $this->true(valid_email("my1email@123foo.com"));
+ $this->true(valid_email("123mail@fo220o.com"));
+ $this->true(valid_email("mail-123.hello@foo.com"));
+ $this->true(valid_email("email+bucket@foo.com"));
+ $this->true(valid_email("tylerhall@gmail.com", true));
+ $this->false(valid_email("em ail@foo.com"));
+ $this->false(valid_email("em\ail@foo.com"));
+ $this->false(valid_email("em ail@ foo.com"));
+ $this->false(valid_email("em ail@foo."));
+ $this->false(valid_email("@"));
+ $this->false(valid_email(''));
+ $this->false(valid_email(' '));
+ }
+
+ function testMatch()
+ {
+ $str = 'aaabbbcdefg';
+ $this->equals(match('/[a-b]+/', $str), 'aaabbb');
+ $this->equals(match('/a+(b*c)c*/', $str, 1), 'bbbc');
+ $this->false(match('/c[a-b]+/', $str));
+ }
+
+ function testPick()
+ {
+ $this->equals(pick(1, 2, 3), 1);
+ $this->equals(pick('', 2, 3), 2);
+ $this->equals(pick(null, 2, 3), 2);
+ $this->equals(pick(0, 2, 3), 2);
+ $this->equals(pick('', '', 3), 3);
+ $this->equals(pick(), '');
+ $this->equals(pick(1), 1);
+ }
+ }
+
+ $t = new TestFunctions();
Oops, something went wrong.

0 comments on commit 9ff529a

Please sign in to comment.