code stringlengths 1 2.01M | repo_name stringlengths 3 62 | path stringlengths 1 267 | language stringclasses 231
values | license stringclasses 13
values | size int64 1 2.01M |
|---|---|---|---|---|---|
<?php
/**
* Short description for file.
*
* PHP 5
*
* CakePHP(tm) Tests <http://book.cakephp.org/view/1196/Testing>
* Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice
*
* @copyright Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://book.cakephp.org/view/1196/Testing CakePHP(tm) Tests
* @package Cake.Test.Fixture
* @since CakePHP(tm) v 1.2.0.4667
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
/**
* Short description for class.
*
* @package Cake.Test.Fixture
*/
class CounterCacheUserFixture extends CakeTestFixture {
public $name = 'CounterCacheUser';
public $fields = array(
'id' => array('type' => 'integer', 'key' => 'primary'),
'name' => array('type' => 'string', 'length' => 255, 'null' => false),
'post_count' => array('type' => 'integer', 'null' => true),
'posts_published' => array('type' => 'integer', 'null' => true)
);
public $records = array(
array('id' => 66, 'name' => 'Alexander', 'post_count' => 2, 'posts_published' => 1),
array('id' => 301, 'name' => 'Steven', 'post_count' => 1, 'posts_published' => 1),
);
}
| 0001-bee | trunk/cakephp2/lib/Cake/Test/Fixture/CounterCacheUserFixture.php | PHP | gpl3 | 1,320 |
<?php
/**
* Short description for file.
*
* PHP 5
*
* CakePHP(tm) Tests <http://book.cakephp.org/view/1196/Testing>
* Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice
*
* @copyright Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://book.cakephp.org/view/1196/Testing CakePHP(tm) Tests
* @package Cake.Test.Fixture
* @since CakePHP(tm) v 1.2.0.4667
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
/**
* Short description for class.
*
* @package Cake.Test.Fixture
*/
class ThreadFixture extends CakeTestFixture {
/**
* name property
*
* @var string 'Thread'
*/
public $name = 'Thread';
/**
* fields property
*
* @var array
*/
public $fields = array(
'id' => array('type' => 'integer', 'key' => 'primary'),
'project_id' => array('type' => 'integer', 'null' => false),
'name' => array('type' => 'string', 'null' => false)
);
/**
* records property
*
* @var array
*/
public $records = array(
array('project_id' => 1, 'name' => 'Project 1, Thread 1'),
array('project_id' => 1, 'name' => 'Project 1, Thread 2'),
array('project_id' => 2, 'name' => 'Project 2, Thread 1')
);
}
| 0001-bee | trunk/cakephp2/lib/Cake/Test/Fixture/ThreadFixture.php | PHP | gpl3 | 1,368 |
<?php
/**
* Short description for file.
*
* PHP 5
*
* CakePHP(tm) Tests <http://book.cakephp.org/view/1196/Testing>
* Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice
*
* @copyright Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://book.cakephp.org/view/1196/Testing CakePHP(tm) Tests
* @package Cake.Test.Fixture
* @since CakePHP(tm) v 7660
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
/**
* Short description for class.
*
* @package Cake.Test.Fixture
*/
class TestPluginCommentFixture extends CakeTestFixture {
/**
* name property
*
* @var string 'Comment'
*/
public $name = 'TestPluginComment';
/**
* fields property
*
* @var array
*/
public $fields = array(
'id' => array('type' => 'integer', 'key' => 'primary'),
'article_id' => array('type' => 'integer', 'null'=>false),
'user_id' => array('type' => 'integer', 'null'=>false),
'comment' => 'text',
'published' => array('type' => 'string', 'length' => 1, 'default' => 'N'),
'created' => 'datetime',
'updated' => 'datetime'
);
/**
* records property
*
* @var array
*/
public $records = array(
array('id' => 1, 'article_id' => 1, 'user_id' => 2, 'comment' => 'First Comment for First Plugin Article', 'published' => 'Y', 'created' => '2008-09-24 10:45:23', 'updated' => '2008-09-24 10:47:31'),
array('id' => 2, 'article_id' => 1, 'user_id' => 4, 'comment' => 'Second Comment for First Plugin Article', 'published' => 'Y', 'created' => '2008-09-24 10:47:23', 'updated' => '2008-09-24 10:49:31'),
array('id' => 3, 'article_id' => 1, 'user_id' => 1, 'comment' => 'Third Comment for First Plugin Article', 'published' => 'Y', 'created' => '2008-09-24 10:49:23', 'updated' => '2008-09-24 10:51:31'),
array('id' => 4, 'article_id' => 1, 'user_id' => 1, 'comment' => 'Fourth Comment for First Plugin Article', 'published' => 'N', 'created' => '2008-09-24 10:51:23', 'updated' => '2008-09-24 10:53:31'),
array('id' => 5, 'article_id' => 2, 'user_id' => 1, 'comment' => 'First Comment for Second Plugin Article', 'published' => 'Y', 'created' => '2008-09-24 10:53:23', 'updated' => '2008-09-24 10:55:31'),
array('id' => 6, 'article_id' => 2, 'user_id' => 2, 'comment' => 'Second Comment for Second Plugin Article', 'published' => 'Y', 'created' => '2008-09-24 10:55:23', 'updated' => '2008-09-24 10:57:31')
);
}
| 0001-bee | trunk/cakephp2/lib/Cake/Test/Fixture/TestPluginCommentFixture.php | PHP | gpl3 | 2,573 |
<?php
/**
* Tree behavior class.
*
* Enables a model object to act as a node-based tree.
*
* PHP 5
*
* CakePHP(tm) Tests <http://book.cakephp.org/view/1196/Testing>
* Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice
*
* @copyright Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://book.cakephp.org/view/1196/Testing CakePHP(tm) Tests
* @package Cake.Test.Fixture
* @since CakePHP(tm) v 1.2.0.5331
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
/**
* Number Tree Test Fixture
*
* Generates a tree of data for use testing the tree behavior
*
* @package Cake.Test.Fixture
*/
class NumberTreeFixture extends CakeTestFixture {
/**
* name property
*
* @var string 'NumberTree'
*/
public $name = 'NumberTree';
/**
* fields property
*
* @var array
*/
public $fields = array(
'id' => array('type' => 'integer','key' => 'primary'),
'name' => array('type' => 'string','null' => false),
'parent_id' => 'integer',
'lft' => array('type' => 'integer','null' => false),
'rght' => array('type' => 'integer','null' => false)
);
}
| 0001-bee | trunk/cakephp2/lib/Cake/Test/Fixture/NumberTreeFixture.php | PHP | gpl3 | 1,308 |
<?php
/**
* Short description for file.
*
* PHP 5
*
* CakePHP(tm) Tests <http://book.cakephp.org/view/1196/Testing>
* Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice
*
* @copyright Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://book.cakephp.org/view/1196/Testing CakePHP(tm) Tests
* @package Cake.Test.Fixture
* @since CakePHP(tm) v 1.2.0.4667
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
/**
* Short description for class.
*
* @package Cake.Test.Fixture
*/
class AttachmentFixture extends CakeTestFixture {
/**
* name property
*
* @var string 'Attachment'
*/
public $name = 'Attachment';
/**
* fields property
*
* @var array
*/
public $fields = array(
'id' => array('type' => 'integer', 'key' => 'primary'),
'comment_id' => array('type' => 'integer', 'null' => false),
'attachment' => array('type' => 'string', 'null' => false),
'created' => 'datetime',
'updated' => 'datetime'
);
/**
* records property
*
* @var array
*/
public $records = array(
array('comment_id' => 5, 'attachment' => 'attachment.zip', 'created' => '2007-03-18 10:51:23', 'updated' => '2007-03-18 10:53:31')
);
}
| 0001-bee | trunk/cakephp2/lib/Cake/Test/Fixture/AttachmentFixture.php | PHP | gpl3 | 1,392 |
<?php
/**
* Short description for file.
*
* PHP 5
*
* CakePHP(tm) Tests <http://book.cakephp.org/view/1196/Testing>
* Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice
*
* @copyright Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://book.cakephp.org/view/1196/Testing CakePHP(tm) Tests
* @package Cake.Test.Fixture
* @since CakePHP(tm) v 1.2.1.8013
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
/**
* Short description for class.
*
* @package Cake.Test.Fixture
*/
class AuthUserCustomFieldFixture extends CakeTestFixture {
/**
* name property
*
* @var string 'AuthUser'
*/
public $name = 'AuthUserCustomField';
/**
* fields property
*
* @var array
*/
public $fields = array(
'id' => array('type' => 'integer', 'key' => 'primary'),
'email' => array('type' => 'string', 'null' => false),
'password' => array('type' => 'string', 'null' => false),
'created' => 'datetime',
'updated' => 'datetime'
);
/**
* records property
*
* @var array
*/
public $records = array(
array('email' => 'mariano@example.com', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31'),
array('email' => 'nate@example.com', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:18:23', 'updated' => '2007-03-17 01:20:31'),
array('email' => 'larry@example.com', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:20:23', 'updated' => '2007-03-17 01:22:31'),
array('email' => 'garrett@example.com', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:22:23', 'updated' => '2007-03-17 01:24:31'),
array('email' => 'chartjes@example.com', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:22:23', 'updated' => '2007-03-17 01:24:31'),
);
}
| 0001-bee | trunk/cakephp2/lib/Cake/Test/Fixture/AuthUserCustomFieldFixture.php | PHP | gpl3 | 2,088 |
<?php
/**
* Short description for file.
*
* PHP 5
*
* CakePHP(tm) Tests <http://book.cakephp.org/view/1196/Testing>
* Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice
*
* @copyright Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://book.cakephp.org/view/1196/Testing CakePHP(tm) Tests
* @package Cake.Test.Fixture
* @since CakePHP(tm) v 1.2.0.4667
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
/**
* Short description for class.
*
* @package Cake.Test.Fixture
*/
class CounterCachePostNonstandardPrimaryKeyFixture extends CakeTestFixture {
public $name = 'CounterCachePostNonstandardPrimaryKey';
public $fields = array(
'pid' => array('type' => 'integer', 'key' => 'primary'),
'title' => array('type' => 'string', 'length' => 255, 'null' => false),
'uid' => array('type' => 'integer', 'null' => true),
);
public $records = array(
array('pid' => 1, 'title' => 'Rock and Roll', 'uid' => 66),
array('pid' => 2, 'title' => 'Music', 'uid' => 66),
array('pid' => 3, 'title' => 'Food', 'uid' => 301),
);
}
| 0001-bee | trunk/cakephp2/lib/Cake/Test/Fixture/CounterCachePostNonstandardPrimaryKeyFixture.php | PHP | gpl3 | 1,300 |
<?php
/**
* Short description for file.
*
* PHP 5
*
* CakePHP(tm) Tests <http://book.cakephp.org/view/1196/Testing>
* Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice
*
* @copyright Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://book.cakephp.org/view/1196/Testing CakePHP(tm) Tests
* @package Cake.Test.Fixture
* @since CakePHP(tm) v 1.2.0.4667
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
/**
* Short description for class.
*
* @package Cake.Test.Fixture
*/
class PostFixture extends CakeTestFixture {
/**
* name property
*
* @var string 'Post'
*/
public $name = 'Post';
/**
* fields property
*
* @var array
*/
public $fields = array(
'id' => array('type' => 'integer', 'key' => 'primary'),
'author_id' => array('type' => 'integer', 'null' => false),
'title' => array('type' => 'string', 'null' => false),
'body' => 'text',
'published' => array('type' => 'string', 'length' => 1, 'default' => 'N'),
'created' => 'datetime',
'updated' => 'datetime'
);
/**
* records property
*
* @var array
*/
public $records = array(
array('author_id' => 1, 'title' => 'First Post', 'body' => 'First Post Body', 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31'),
array('author_id' => 3, 'title' => 'Second Post', 'body' => 'Second Post Body', 'published' => 'Y', 'created' => '2007-03-18 10:41:23', 'updated' => '2007-03-18 10:43:31'),
array('author_id' => 1, 'title' => 'Third Post', 'body' => 'Third Post Body', 'published' => 'Y', 'created' => '2007-03-18 10:43:23', 'updated' => '2007-03-18 10:45:31')
);
}
| 0001-bee | trunk/cakephp2/lib/Cake/Test/Fixture/PostFixture.php | PHP | gpl3 | 1,851 |
<?php
/**
* Short description for file.
*
* PHP 5
*
* CakePHP(tm) Tests <http://book.cakephp.org/view/1196/Testing>
* Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice
*
* @copyright Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://book.cakephp.org/view/1196/Testing CakePHP(tm) Tests
* @package Cake.Test.Fixture
* @since CakePHP(tm) v 1.2.0.4667
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
/**
* Short description for class.
*
* @package Cake.Test.Fixture
*/
class AcoActionFixture extends CakeTestFixture {
/**
* name property
*
* @var string 'AcoAction'
*/
public $name = 'AcoAction';
/**
* fields property
*
* @var array
*/
public $fields = array(
'id' => array('type' => 'integer', 'key' => 'primary'),
'parent_id' => array('type' => 'integer', 'length' => 10, 'null' => true),
'model' => array('type' => 'string', 'default' => ''),
'foreign_key' => array('type' => 'integer', 'length' => 10, 'null' => true),
'alias' => array('type' => 'string', 'default' => ''),
'lft' => array('type' => 'integer', 'length' => 10, 'null' => true),
'rght' => array('type' => 'integer', 'length' => 10, 'null' => true)
);
/**
* records property
*
* @var array
*/
public $records = array();
}
| 0001-bee | trunk/cakephp2/lib/Cake/Test/Fixture/AcoActionFixture.php | PHP | gpl3 | 1,487 |
<?php
/**
* UUID Tree behavior fixture.
*
* PHP 5
*
* CakePHP(tm) Tests <http://book.cakephp.org/view/1196/Testing>
* Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice
*
* @copyright Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://book.cakephp.org/view/1196/Testing CakePHP(tm) Tests
* @package Cake.Test.Fixture
* @since CakePHP(tm) v 1.2.0.7984
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
/**
* UuidTreeFixture class
*
* @uses CakeTestFixture
* @package Cake.Test.Fixture
*/
class UuidTreeFixture extends CakeTestFixture {
/**
* name property
*
* @var string 'UuidTree'
*/
public $name = 'UuidTree';
/**
* fields property
*
* @var array
*/
public $fields = array(
'id' => array('type' => 'string', 'length' => 36, 'key' => 'primary'),
'name' => array('type' => 'string','null' => false),
'parent_id' => array('type' => 'string', 'length' => 36, 'null' => true),
'lft' => array('type' => 'integer','null' => false),
'rght' => array('type' => 'integer','null' => false)
);
}
| 0001-bee | trunk/cakephp2/lib/Cake/Test/Fixture/UuidTreeFixture.php | PHP | gpl3 | 1,281 |
<?php
/**
* Short description for file.
*
* PHP 5
*
* CakePHP(tm) Tests <http://book.cakephp.org/view/1196/Testing>
* Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice
*
* @copyright Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://book.cakephp.org/view/1196/Testing CakePHP(tm) Tests
* @package Cake.Test.Fixture
* @since CakePHP(tm) v 1.2.0.4667
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
/**
* Short description for class.
*
* @package Cake.Test.Fixture
*/
class UuiditemFixture extends CakeTestFixture {
/**
* name property
*
* @var string 'Uuiditem'
*/
public $name = 'Uuiditem';
/**
* fields property
*
* @var array
*/
public $fields = array(
'id' => array('type' => 'string', 'length' => 36, 'key' => 'primary'),
'published' => array('type' => 'boolean', 'null' => false),
'name' => array('type' => 'string', 'null' => false)
);
/**
* records property
*
* @var array
*/
public $records = array(
array('id' => '481fc6d0-b920-43e0-a40d-6d1740cf8569', 'published' => 0, 'name' => 'Item 1'),
array('id' => '48298a29-81c0-4c26-a7fb-413140cf8569', 'published' => 0, 'name' => 'Item 2'),
array('id' => '482b7756-8da0-419a-b21f-27da40cf8569', 'published' => 0, 'name' => 'Item 3'),
array('id' => '482cfd4b-0e7c-4ea3-9582-4cec40cf8569', 'published' => 0, 'name' => 'Item 4'),
array('id' => '4831181b-4020-4983-a29b-131440cf8569', 'published' => 0, 'name' => 'Item 5'),
array('id' => '483798c8-c7cc-430e-8cf9-4fcc40cf8569', 'published' => 0, 'name' => 'Item 6')
);
}
| 0001-bee | trunk/cakephp2/lib/Cake/Test/Fixture/UuiditemFixture.php | PHP | gpl3 | 1,775 |
<?php
/**
* Short description for file.
*
* PHP 5
*
* CakePHP(tm) Tests <http://book.cakephp.org/view/1196/Testing>
* Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice
*
* @copyright Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://book.cakephp.org/view/1196/Testing CakePHP(tm) Tests
* @package Cake.Test.Fixture
* @since CakePHP(tm) v 1.2.0.6700
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
/**
* Short description for class.
*
* @package Cake.Test.Fixture
*/
class UuidFixture extends CakeTestFixture {
/**
* name property
*
* @var string 'Uuid'
*/
public $name = 'Uuid';
/**
* fields property
*
* @var array
*/
public $fields = array(
'id' => array('type' => 'string', 'length' => 36, 'key' => 'primary'),
'title' => 'string',
'count' => array('type' => 'integer', 'default' => 0),
'created' => 'datetime',
'updated' => 'datetime'
);
/**
* records property
*
* @var array
*/
public $records = array(
array('id' => '47c36f9c-bc00-4d17-9626-4e183ca6822b', 'title' => 'Unique record 1', 'count' => 2, 'created' => '2008-03-13 01:16:23', 'updated' => '2008-03-13 01:18:31'),
array('id' => '47c36f9c-f2b0-43f5-b3f7-4e183ca6822b', 'title' => 'Unique record 2', 'count' => 4, 'created' => '2008-03-13 01:18:24', 'updated' => '2008-03-13 01:20:32'),
array('id' => '47c36f9c-0ffc-4084-9b03-4e183ca6822b', 'title' => 'Unique record 3', 'count' => 5, 'created' => '2008-03-13 01:20:25', 'updated' => '2008-03-13 01:22:33'),
array('id' => '47c36f9c-2578-4c2e-aeab-4e183ca6822b', 'title' => 'Unique record 4', 'count' => 3, 'created' => '2008-03-13 01:22:26', 'updated' => '2008-03-13 01:24:34'),
);
}
| 0001-bee | trunk/cakephp2/lib/Cake/Test/Fixture/UuidFixture.php | PHP | gpl3 | 1,902 |
<?php
/**
* Unconventional Tree behavior class test fixture.
*
* PHP 5
*
* CakePHP(tm) Tests <http://book.cakephp.org/view/1196/Testing>
* Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice
*
* @copyright Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://book.cakephp.org/view/1196/Testing CakePHP(tm) Tests
* @package Cake.Test.Fixture
* @since CakePHP(tm) v 1.2.0.7879
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
/**
* UnconventionalTreeFixture class
*
* Like Number tree, but doesn't use the default values for lft and rght or parent_id
*
* @uses CakeTestFixture
* @package Cake.Test.Fixture
*/
class UnconventionalTreeFixture extends CakeTestFixture {
/**
* name property
*
* @var string 'FlagTree'
*/
public $name = 'UnconventionalTree';
/**
* fields property
*
* @var array
*/
public $fields = array(
'id' => array('type' => 'integer','key' => 'primary'),
'name' => array('type' => 'string','null' => false),
'join' => 'integer',
'left' => array('type' => 'integer','null' => false),
'right' => array('type' => 'integer','null' => false),
);
}
| 0001-bee | trunk/cakephp2/lib/Cake/Test/Fixture/UnconventionalTreeFixture.php | PHP | gpl3 | 1,355 |
<?php
/**
* Short description for file.
*
* PHP 5
*
* CakePHP(tm) Tests <http://book.cakephp.org/view/1196/Testing>
* Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice
*
* @copyright Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://book.cakephp.org/view/1196/Testing CakePHP(tm) Tests
* @package Cake.Test.Fixture
* @since CakePHP(tm) v 1.2.0.4667
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
/**
* Short description for class.
*
* @package Cake.Test.Fixture
*/
class AcoFixture extends CakeTestFixture {
/**
* name property
*
* @var string 'Aco'
*/
public $name = 'Aco';
/**
* fields property
*
* @var array
*/
public $fields = array(
'id' => array('type' => 'integer', 'key' => 'primary'),
'parent_id' => array('type' => 'integer', 'length' => 10, 'null' => true),
'model' => array('type' => 'string', 'null' => true),
'foreign_key' => array('type' => 'integer', 'length' => 10, 'null' => true),
'alias' => array('type' => 'string', 'default' => ''),
'lft' => array('type' => 'integer', 'length' => 10, 'null' => true),
'rght' => array('type' => 'integer', 'length' => 10, 'null' => true)
);
/**
* records property
*
* @var array
*/
public $records = array(
array('parent_id' => null, 'model' => null, 'foreign_key' => null, 'alias' => 'ROOT', 'lft' => 1, 'rght' => 24),
array('parent_id' => 1, 'model' => null, 'foreign_key' => null, 'alias' => 'Controller1', 'lft' => 2, 'rght' => 9),
array('parent_id' => 2, 'model' => null, 'foreign_key' => null, 'alias' => 'action1', 'lft' => 3, 'rght' => 6),
array('parent_id' => 3, 'model' => null, 'foreign_key' => null, 'alias' => 'record1', 'lft' => 4, 'rght' => 5),
array('parent_id' => 2, 'model' => null, 'foreign_key' => null, 'alias' => 'action2', 'lft' => 7, 'rght' => 8),
array('parent_id' => 1, 'model' => null, 'foreign_key' => null, 'alias' => 'Controller2','lft' => 10, 'rght' => 17),
array('parent_id' => 6, 'model' => null, 'foreign_key' => null, 'alias' => 'action1', 'lft' => 11, 'rght' => 14),
array('parent_id' => 7, 'model' => null, 'foreign_key' => null, 'alias' => 'record1', 'lft' => 12, 'rght' => 13),
array('parent_id' => 6, 'model' => null, 'foreign_key' => null, 'alias' => 'action2', 'lft' => 15, 'rght' => 16),
array('parent_id' => 1, 'model' => null, 'foreign_key' => null, 'alias' => 'Users', 'lft' => 18, 'rght' => 23),
array('parent_id' => 9, 'model' => null, 'foreign_key' => null, 'alias' => 'Users', 'lft' => 19, 'rght' => 22),
array('parent_id' => 10, 'model' => null, 'foreign_key' => null, 'alias' => 'view', 'lft' => 20, 'rght' => 21),
);
}
| 0001-bee | trunk/cakephp2/lib/Cake/Test/Fixture/AcoFixture.php | PHP | gpl3 | 2,861 |
<?php
/**
* Short description for file.
*
* PHP 5
*
* CakePHP(tm) Tests <http://book.cakephp.org/view/1196/Testing>
* Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice
*
* @copyright Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://book.cakephp.org/view/1196/Testing CakePHP(tm) Tests
* @package Cake.Test.Fixture
* @since CakePHP(tm) v 1.2.0.5669
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
/**
* Short description for class.
*
* @package Cake.Test.Fixture
*/
class TranslateFixture extends CakeTestFixture {
/**
* name property
*
* @var string 'Translate'
*/
public $name = 'Translate';
/**
* table property
*
* @var string 'i18n'
*/
public $table = 'i18n';
/**
* fields property
*
* @var array
*/
public $fields = array(
'id' => array('type' => 'integer', 'key' => 'primary'),
'locale' => array('type' => 'string', 'length' => 6, 'null' => false),
'model' => array('type' => 'string', 'null' => false),
'foreign_key' => array('type' => 'integer', 'null' => false),
'field' => array('type' => 'string', 'null' => false),
'content' => array('type' => 'text')
);
/**
* records property
*
* @var array
*/
public $records = array(
array('locale' => 'eng', 'model' => 'TranslatedItem', 'foreign_key' => 1, 'field' => 'title', 'content' => 'Title #1'),
array('locale' => 'eng', 'model' => 'TranslatedItem', 'foreign_key' => 1, 'field' => 'content', 'content' => 'Content #1'),
array('locale' => 'deu', 'model' => 'TranslatedItem', 'foreign_key' => 1, 'field' => 'title', 'content' => 'Titel #1'),
array('locale' => 'deu', 'model' => 'TranslatedItem', 'foreign_key' => 1, 'field' => 'content', 'content' => 'Inhalt #1'),
array('locale' => 'cze', 'model' => 'TranslatedItem', 'foreign_key' => 1, 'field' => 'title', 'content' => 'Titulek #1'),
array('locale' => 'cze', 'model' => 'TranslatedItem', 'foreign_key' => 1, 'field' => 'content', 'content' => 'Obsah #1'),
array('locale' => 'eng', 'model' => 'TranslatedItem', 'foreign_key' => 2, 'field' => 'title', 'content' => 'Title #2'),
array('locale' => 'eng', 'model' => 'TranslatedItem', 'foreign_key' => 2, 'field' => 'content', 'content' => 'Content #2'),
array('locale' => 'deu', 'model' => 'TranslatedItem', 'foreign_key' => 2, 'field' => 'title', 'content' => 'Titel #2'),
array('locale' => 'deu', 'model' => 'TranslatedItem', 'foreign_key' => 2, 'field' => 'content', 'content' => 'Inhalt #2'),
array('locale' => 'cze', 'model' => 'TranslatedItem', 'foreign_key' => 2, 'field' => 'title', 'content' => 'Titulek #2'),
array('locale' => 'cze', 'model' => 'TranslatedItem', 'foreign_key' => 2, 'field' => 'content', 'content' => 'Obsah #2'),
array('locale' => 'eng', 'model' => 'TranslatedItem', 'foreign_key' => 3, 'field' => 'title', 'content' => 'Title #3'),
array('locale' => 'eng', 'model' => 'TranslatedItem', 'foreign_key' => 3, 'field' => 'content', 'content' => 'Content #3'),
array('locale' => 'deu', 'model' => 'TranslatedItem', 'foreign_key' => 3, 'field' => 'title', 'content' => 'Titel #3'),
array('locale' => 'deu', 'model' => 'TranslatedItem', 'foreign_key' => 3, 'field' => 'content', 'content' => 'Inhalt #3'),
array('locale' => 'cze', 'model' => 'TranslatedItem', 'foreign_key' => 3, 'field' => 'title', 'content' => 'Titulek #3'),
array('locale' => 'cze', 'model' => 'TranslatedItem', 'foreign_key' => 3, 'field' => 'content', 'content' => 'Obsah #3')
);
}
| 0001-bee | trunk/cakephp2/lib/Cake/Test/Fixture/TranslateFixture.php | PHP | gpl3 | 3,672 |
<?php
/**
* Short description for file.
*
* PHP 5
*
* CakePHP(tm) Tests <http://book.cakephp.org/view/1196/Testing>
* Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice
*
* @copyright Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://book.cakephp.org/view/1196/Testing CakePHP(tm) Tests
* @package Cake.Test.Fixture
* @since CakePHP(tm) v 1.2.0.4667
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
/**
* Short description for class.
*
* @package Cake.Test.Fixture
*/
class CategoryThreadFixture extends CakeTestFixture {
/**
* name property
*
* @var string 'CategoryThread'
*/
public $name = 'CategoryThread';
/**
* fields property
*
* @var array
*/
public $fields = array(
'id' => array('type' => 'integer', 'key' => 'primary'),
'parent_id' => array('type' => 'integer', 'null' => false),
'name' => array('type' => 'string', 'null' => false),
'created' => 'datetime',
'updated' => 'datetime'
);
/**
* records property
*
* @var array
*/
public $records = array(
array('parent_id' => 0, 'name' => 'Category 1', 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31'),
array('parent_id' => 1, 'name' => 'Category 1.1', 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31'),
array('parent_id' => 2, 'name' => 'Category 1.1.1', 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31'),
array('parent_id' => 3, 'name' => 'Category 1.1.2', 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31'),
array('parent_id' => 4, 'name' => 'Category 1.1.1.1', 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31'),
array('parent_id' => 5, 'name' => 'Category 2', 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31'),
array('parent_id' => 6, 'name' => 'Category 2.1', 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31')
);
}
| 0001-bee | trunk/cakephp2/lib/Cake/Test/Fixture/CategoryThreadFixture.php | PHP | gpl3 | 2,141 |
<?php
PHP_CodeCoverage_Filter::getInstance()->addFileToBlacklist(__FILE__, 'DEFAULT');
/**
* This class helps in testing the life-cycle of fixtures inside a CakeTestCase
*
* @package Cake.Test.Fixture
*/
class FixturizedTestCase extends CakeTestCase {
/**
* Fixtures to use in this thes
* @var array
*/
public $fixtures = array('core.category');
/**
* test that the shared fixture is correctly set
*
* @return void
*/
public function testFixturePresent() {
$this->assertInstanceOf('CakeFixtureManager', $this->fixtureManager);
}
/**
* test that it is possible to load fixtures on demand
*
* @return void
*/
public function testFixtureLoadOnDemand() {
$this->loadFixtures('Category');
}
/**
* test that a test is marked as skipped using skipIf and its first parameter evaluates to true
*
* @return void
*/
public function testSkipIfTrue() {
$this->skipIf(true);
}
/**
* test that a test is not marked as skipped using skipIf and its first parameter evaluates to false
*
* @return void
*/
public function testSkipIfFalse() {
$this->skipIf(false);
}
/**
* test that a fixtures are unoaded even if the test throws exceptions
*
* @return void
*/
public function testThrowException() {
throw new Exception();
}
} | 0001-bee | trunk/cakephp2/lib/Cake/Test/Fixture/FixturizedTestCase.php | PHP | gpl3 | 1,269 |
<?php
/**
* Short description for file.
*
* PHP 5
*
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
* Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://cakephp.org CakePHP(tm) Project
* @package Cake.Test.Fixture
* @since CakePHP(tm) v 1.2.0.6879//Correct version number as needed**
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
/**
* Short description for file.
*
* @package Cake.Test.Fixture
* @since CakePHP(tm) v 1.2.0.6879//Correct version number as needed**
*/
class DependencyFixture extends CakeTestFixture {
/**
* name property
*
* @var string 'Dependency'
*/
public $name = 'Dependency';
/**
* fields property
*
* @var array
*/
public $fields = array(
'child_id' => 'integer',
'parent_id' => 'integer'
);
/**
* records property
*
* @var array
*/
public $records = array(
array('child_id' => 1, 'parent_id' => 2),
);
}
| 0001-bee | trunk/cakephp2/lib/Cake/Test/Fixture/DependencyFixture.php | PHP | gpl3 | 1,215 |
<?php
/**
* Short description for file.
*
* PHP 5
*
* CakePHP(tm) Tests <http://book.cakephp.org/view/1196/Testing>
* Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice
*
* @copyright Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://book.cakephp.org/view/1196/Testing CakePHP(tm) Tests
* @package Cake.Test.Fixture
* @since CakePHP(tm) v 1.2.0.4667
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
/**
* Short description for class.
*
* @package Cake.Test.Fixture
*/
class UserFixture extends CakeTestFixture {
/**
* name property
*
* @var string 'User'
*/
public $name = 'User';
/**
* fields property
*
* @var array
*/
public $fields = array(
'id' => array('type' => 'integer', 'key' => 'primary'),
'user' => array('type' => 'string', 'null' => false),
'password' => array('type' => 'string', 'null' => false),
'created' => 'datetime',
'updated' => 'datetime'
);
/**
* records property
*
* @var array
*/
public $records = array(
array('user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31'),
array('user' => 'nate', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:18:23', 'updated' => '2007-03-17 01:20:31'),
array('user' => 'larry', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:20:23', 'updated' => '2007-03-17 01:22:31'),
array('user' => 'garrett', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:22:23', 'updated' => '2007-03-17 01:24:31'),
);
}
| 0001-bee | trunk/cakephp2/lib/Cake/Test/Fixture/UserFixture.php | PHP | gpl3 | 1,834 |
<?php
/**
* Short description for file.
*
* PHP 5
*
* CakePHP(tm) Tests <http://book.cakephp.org/view/1196/Testing>
* Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice
*
* @copyright Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://book.cakephp.org/view/1196/Testing CakePHP(tm) Tests
* @package Cake.Test.Fixture
* @since CakePHP(tm) v 1.2.0.4667
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
/**
* Short description for class.
*
* @package Cake.Test.Fixture
*/
class PostsTagFixture extends CakeTestFixture {
/**
* name property
*
* @var string 'PostsTag'
*/
public $name = 'PostsTag';
/**
* fields property
*
* @var array
*/
public $fields = array(
'post_id' => array('type' => 'integer', 'null' => false),
'tag_id' => array('type' => 'string', 'null' => false),
'indexes' => array('posts_tag' => array('column' => array('tag_id', 'post_id'), 'unique' => 1))
);
/**
* records property
*
* @var array
*/
public $records = array(
array('post_id' => 1, 'tag_id' => 'tag1'),
array('post_id' => 1, 'tag_id' => 'tag2'),
array('post_id' => 2, 'tag_id' => 'tag1'),
array('post_id' => 2, 'tag_id' => 'tag3')
);
}
| 0001-bee | trunk/cakephp2/lib/Cake/Test/Fixture/PostsTagFixture.php | PHP | gpl3 | 1,411 |
<?php
/**
* Short description for file.
*
* PHP 5
*
* CakePHP(tm) Tests <http://book.cakephp.org/view/1196/Testing>
* Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice
*
* @copyright Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://book.cakephp.org/view/1196/Testing CakePHP(tm) Tests
* @package Cake.Test.Fixture
* @since CakePHP(tm) v 1.2.0.4667
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
/**
* Short description for class.
*
* @package Cake.Test.Fixture
*/
class SampleFixture extends CakeTestFixture {
/**
* name property
*
* @var string 'Sample'
*/
public $name = 'Sample';
/**
* fields property
*
* @var array
*/
public $fields = array(
'id' => array('type' => 'integer', 'key' => 'primary'),
'apple_id' => array('type' => 'integer', 'null' => false),
'name' => array('type' => 'string', 'length' => 40, 'null' => false)
);
/**
* records property
*
* @var array
*/
public $records = array(
array('apple_id' => 3, 'name' => 'sample1'),
array('apple_id' => 2, 'name' => 'sample2'),
array('apple_id' => 4, 'name' => 'sample3'),
array('apple_id' => 5, 'name' => 'sample4')
);
}
| 0001-bee | trunk/cakephp2/lib/Cake/Test/Fixture/SampleFixture.php | PHP | gpl3 | 1,387 |
<?php
/**
* Short description for file.
*
* PHP 5
*
* CakePHP(tm) Tests <http://book.cakephp.org/view/1196/Testing>
* Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice
*
* @copyright Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://book.cakephp.org/view/1196/Testing CakePHP(tm) Tests
* @package Cake.Test.Fixture
* @since CakePHP(tm) v 1.2.0.6700
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
/**
* Short description for class.
*
* @package Cake.Test.Fixture
*/
class BinaryTestFixture extends CakeTestFixture {
/**
* name property
*
* @var string 'BinaryTest'
*/
public $name = 'BinaryTest';
/**
* fields property
*
* @var array
*/
public $fields = array(
'id' => array('type' => 'integer', 'key' => 'primary'),
'data' => array('type' => 'binary', 'length' => 300)
);
/**
* records property
*
* @var array
*/
public $records = array();
}
| 0001-bee | trunk/cakephp2/lib/Cake/Test/Fixture/BinaryTestFixture.php | PHP | gpl3 | 1,133 |
<?php
/**
* Short description for file.
*
* PHP 5
*
* CakePHP(tm) Tests <http://book.cakephp.org/view/1196/Testing>
* Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice
*
* @copyright Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://book.cakephp.org/view/1196/Testing CakePHP(tm) Tests
* @package Cake.Test.Fixture
* @since CakePHP(tm) v 1.2.0.4667
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
/**
* Short description for class.
*
* @package Cake.Test.Fixture
*/
class MyCategoryFixture extends CakeTestFixture {
/**
* name property
*
* @var string 'MyCategory'
*/
public $name = 'MyCategory';
/**
* fields property
*
* @var array
*/
public $fields = array(
'id' => array('type' => 'integer', 'key' => 'primary'),
'name' => array('type' => 'string', 'null' => false),
);
/**
* records property
*
* @var array
*/
public $records = array(
array('id' => 1, 'name' => 'A'),
array('id' => 2, 'name' => 'B'),
array('id' => 3, 'name' => 'C'),
);
}
| 0001-bee | trunk/cakephp2/lib/Cake/Test/Fixture/MyCategoryFixture.php | PHP | gpl3 | 1,241 |
<?php
/**
* Short description for file.
*
* PHP 5
*
* CakePHP(tm) Tests <http://book.cakephp.org/view/1196/Testing>
* Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice
*
* @copyright Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://book.cakephp.org/view/1196/Testing CakePHP(tm) Tests
* @package Cake.Test.Fixture
* @since CakePHP(tm) v 1.2.0.4667
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
/**
* Short description for class.
*
* @package Cake.Test.Fixture
*/
class DocumentDirectoryFixture extends CakeTestFixture {
/**
* name property
*
* @var string 'DocumentDirectory'
*/
public $name = 'DocumentDirectory';
/**
* fields property
*
* @var array
*/
public $fields = array(
'id' => array('type' => 'integer', 'key' => 'primary'),
'name' => array('type' => 'string', 'null' => false)
);
/**
* records property
*
* @var array
*/
public $records = array(
array('name' => 'DocumentDirectory 1')
);
}
| 0001-bee | trunk/cakephp2/lib/Cake/Test/Fixture/DocumentDirectoryFixture.php | PHP | gpl3 | 1,197 |
<?php
/**
* Short description for file.
*
* PHP 5
*
* CakePHP(tm) Tests <http://book.cakephp.org/view/1196/Testing>
* Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice
*
* @copyright Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://book.cakephp.org/view/1196/Testing CakePHP(tm) Tests
* @package Cake.Test.Fixture
* @since CakePHP(tm) v 1.2.0.4667
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
/**
* Short description for class.
*
* @package Cake.Test.Fixture
*/
class GroupUpdateAllFixture extends CakeTestFixture {
public $name = 'GroupUpdateAll';
public $table = 'group_update_all';
public $fields = array(
'id' => array('type'=>'integer', 'null' => false, 'default' => NULL, 'key' => 'primary'),
'name' => array('type'=>'string', 'null' => false, 'length' => 29),
'code' => array('type'=>'integer', 'null' => false, 'length' => 4),
'indexes' => array('PRIMARY' => array('column' => 'id', 'unique' => 1))
);
public $records = array(
array(
'id' => 1,
'name' => 'group one',
'code' => 120),
array(
'id' => 2,
'name' => 'group two',
'code' => 125),
array(
'id' => 3,
'name' => 'group three',
'code' => 130),
array(
'id' => 4,
'name' => 'group four',
'code' => 135)
);
}
| 0001-bee | trunk/cakephp2/lib/Cake/Test/Fixture/GroupUpdateAllFixture.php | PHP | gpl3 | 1,714 |
<?php
/**
* BakeCommentFixture
*
* PHP 5
*
* CakePHP(tm) Tests <http://book.cakephp.org/view/1196/Testing>
* Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://book.cakephp.org/view/1196/Testing CakePHP(tm) Tests
* @package Cake.Test.Fixture
* @since CakePHP(tm) v 2.0
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
/**
* Short description for class.
*
* @package Cake.Test.Fixture
*/
class BakeArticlesBakeTagFixture extends CakeTestFixture {
/**
* name property
*
* @var string 'ArticlesTag'
*/
public $name = 'BakeArticlesBakeTag';
/**
* fields property
*
* @var array
*/
public $fields = array(
'bake_article_id' => array('type' => 'integer', 'null' => false),
'bake_tag_id' => array('type' => 'integer', 'null' => false),
'indexes' => array('UNIQUE_TAG' => array('column'=> array('bake_article_id', 'bake_tag_id'), 'unique'=>1))
);
/**
* records property
*
* @var array
*/
public $records = array();
}
| 0001-bee | trunk/cakephp2/lib/Cake/Test/Fixture/BakeArticlesBakeTagFixture.php | PHP | gpl3 | 1,265 |
<?php
/**
* Short description for file.
*
* PHP 5
*
* CakePHP(tm) Tests <http://book.cakephp.org/view/1196/Testing>
* Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice
*
* @copyright Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://book.cakephp.org/view/1196/Testing CakePHP(tm) Tests
* @package Cake.Test.Fixture
* @since CakePHP(tm) v 1.2.0.4667
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
/**
* Short description for class.
*
* @package Cake.Test.Fixture
*/
class CommentFixture extends CakeTestFixture {
/**
* name property
*
* @var string 'Comment'
*/
public $name = 'Comment';
/**
* fields property
*
* @var array
*/
public $fields = array(
'id' => array('type' => 'integer', 'key' => 'primary'),
'article_id' => array('type' => 'integer', 'null'=>false),
'user_id' => array('type' => 'integer', 'null'=>false),
'comment' => 'text',
'published' => array('type' => 'string', 'length' => 1, 'default' => 'N'),
'created' => 'datetime',
'updated' => 'datetime'
);
/**
* records property
*
* @var array
*/
public $records = array(
array('article_id' => 1, 'user_id' => 2, 'comment' => 'First Comment for First Article', 'published' => 'Y', 'created' => '2007-03-18 10:45:23', 'updated' => '2007-03-18 10:47:31'),
array('article_id' => 1, 'user_id' => 4, 'comment' => 'Second Comment for First Article', 'published' => 'Y', 'created' => '2007-03-18 10:47:23', 'updated' => '2007-03-18 10:49:31'),
array('article_id' => 1, 'user_id' => 1, 'comment' => 'Third Comment for First Article', 'published' => 'Y', 'created' => '2007-03-18 10:49:23', 'updated' => '2007-03-18 10:51:31'),
array('article_id' => 1, 'user_id' => 1, 'comment' => 'Fourth Comment for First Article', 'published' => 'N', 'created' => '2007-03-18 10:51:23', 'updated' => '2007-03-18 10:53:31'),
array('article_id' => 2, 'user_id' => 1, 'comment' => 'First Comment for Second Article', 'published' => 'Y', 'created' => '2007-03-18 10:53:23', 'updated' => '2007-03-18 10:55:31'),
array('article_id' => 2, 'user_id' => 2, 'comment' => 'Second Comment for Second Article', 'published' => 'Y', 'created' => '2007-03-18 10:55:23', 'updated' => '2007-03-18 10:57:31')
);
}
| 0001-bee | trunk/cakephp2/lib/Cake/Test/Fixture/CommentFixture.php | PHP | gpl3 | 2,451 |
<?php
/**
* Short description for file.
*
* PHP 5
*
* CakePHP(tm) Tests <http://book.cakephp.org/view/1196/Testing>
* Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice
*
* @copyright Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://book.cakephp.org/view/1196/Testing CakePHP(tm) Tests
* @package Cake.Test.Fixture
* @since CakePHP(tm) v 1.2.0.4667
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
/**
* Short description for class.
*
* @package Cake.Test.Fixture
*/
class HomeFixture extends CakeTestFixture {
/**
* name property
*
* @var string 'Home'
*/
public $name = 'Home';
/**
* fields property
*
* @var array
*/
public $fields = array(
'id' => array('type' => 'integer', 'key' => 'primary'),
'another_article_id' => array('type' => 'integer', 'null' => false),
'advertisement_id' => array('type' => 'integer', 'null' => false),
'title' => array('type' => 'string', 'null' => false),
'created' => 'datetime',
'updated' => 'datetime'
);
/**
* records property
*
* @var array
*/
public $records = array(
array('another_article_id' => 1, 'advertisement_id' => 1, 'title' => 'First Home', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31'),
array('another_article_id' => 3, 'advertisement_id' => 1, 'title' => 'Second Home', 'created' => '2007-03-18 10:41:23', 'updated' => '2007-03-18 10:43:31')
);
}
| 0001-bee | trunk/cakephp2/lib/Cake/Test/Fixture/HomeFixture.php | PHP | gpl3 | 1,628 |
<?php
/**
* Short description for file.
*
* PHP 5
*
* CakePHP(tm) Tests <http://book.cakephp.org/view/1196/Testing>
* Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice
*
* @copyright Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://book.cakephp.org/view/1196/Testing CakePHP(tm) Tests
* @package Cake.Test.Fixture
* @since CakePHP(tm) v 1.2.0.4667
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
/**
* Short description for class.
*
* @package Cake.Test.Fixture
*/
class SessionFixture extends CakeTestFixture {
/**
* name property
*
* @var string 'Session'
*/
public $name = 'Session';
/**
* table property.
*
* @var string
*/
// public $table = 'sessions';
/**
* fields property
*
* @var array
*/
public $fields = array(
'id' => array('type' => 'string', 'length' => 128, 'key' => 'primary'),
'data' => array('type' => 'text','null' => true),
'expires' => array('type' => 'integer', 'length' => 11, 'null' => true)
);
/**
* records property
*
* @var array
*/
public $records = array();
}
| 0001-bee | trunk/cakephp2/lib/Cake/Test/Fixture/SessionFixture.php | PHP | gpl3 | 1,289 |
<?php
/**
* AllCacheTest file
*
* PHP 5
*
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
* Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://cakephp.org CakePHP(tm) Project
* @package Cake.Test.Case
* @since CakePHP(tm) v 2.0
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
/**
* AllCacheTest class
*
* This test group will run cache engine tests.
*
* @package Cake.Test.Case
*/
class AllCacheTest extends PHPUnit_Framework_TestSuite {
/**
* suite method, defines tests for this suite.
*
* @return void
*/
public static function suite() {
$suite = new CakeTestSuite('All Cache related class tests');
$suite->addTestDirectory(CORE_TEST_CASES . DS . 'Cache');
$suite->addTestDirectory(CORE_TEST_CASES . DS . 'Cache' . DS . 'Engine');
return $suite;
}
}
| 0001-bee | trunk/cakephp2/lib/Cake/Test/Case/AllCacheTest.php | PHP | gpl3 | 1,119 |
<?php
/**
* AllConsoleTest file
*
* PHP 5
*
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
* Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://cakephp.org CakePHP(tm) Project
* @package Cake.Test.Case
* @since CakePHP(tm) v 2.0
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
/**
* AllConsoleTest class
*
* This test group will run all console classes.
*
* @package Cake.Test.Case
*/
class AllConsoleTest extends PHPUnit_Framework_TestSuite {
/**
* suite method, defines tests for this suite.
*
* @return void
*/
public static function suite() {
$suite = new CakeTestSuite('All console classes');
$path = CORE_TEST_CASES . DS . 'Console' . DS;
$suite->addTestFile($path . 'AllConsoleLibsTest.php');
$suite->addTestFile($path . 'AllTasksTest.php');
$suite->addTestFile($path . 'AllShellsTest.php');
return $suite;
}
} | 0001-bee | trunk/cakephp2/lib/Cake/Test/Case/AllConsoleTest.php | PHP | gpl3 | 1,190 |
<?php
/**
* ScaffoldViewTest file
*
* PHP 5
*
* CakePHP(tm) Tests <http://book.cakephp.org/view/1196/Testing>
* Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice
*
* @copyright Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://book.cakephp.org/view/1196/Testing CakePHP(tm) Tests
* @package Cake.Test.Case.Controller
* @since CakePHP(tm) v 2.0
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
App::uses('Controller', 'Controller');
App::uses('Scaffold', 'Controller');
App::uses('ScaffoldView', 'View');
App::uses('AppModel', 'Model');
require_once dirname(dirname(__FILE__)) . DS . 'Model' . DS . 'models.php';
/**
* TestScaffoldView class
*
* @package Cake.Test.Case.Controller
*/
class TestScaffoldView extends ScaffoldView {
/**
* testGetFilename method
*
* @param mixed $action
* @return void
*/
public function testGetFilename($action) {
return $this->_getViewFileName($action);
}
}
/**
* ScaffoldViewMockController class
*
* @package Cake.Test.Case.Controller
*/
class ScaffoldViewMockController extends Controller {
/**
* name property
*
* @var string 'ScaffoldMock'
*/
public $name = 'ScaffoldMock';
/**
* scaffold property
*
* @var mixed
*/
public $scaffold;
}
/**
* ScaffoldViewTest class
*
* @package Cake.Test.Case.Controller
*/
class ScaffoldViewTest extends CakeTestCase {
/**
* fixtures property
*
* @var array
*/
public $fixtures = array('core.article', 'core.user', 'core.comment', 'core.join_thing', 'core.tag');
/**
* setUp method
*
* @return void
*/
public function setUp() {
parent::setUp();
$this->request = new CakeRequest(null, false);
$this->Controller = new ScaffoldViewMockController($this->request);
$this->Controller->response = $this->getMock('CakeResponse', array('_sendHeader'));
App::build(array(
'View' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'View' . DS),
'Plugin' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS)
));
CakePlugin::load('TestPlugin');
}
/**
* teardown method
*
* @return void
*/
public function tearDown() {
unset($this->Controller, $this->request);
parent::tearDown();
}
/**
* testGetViewFilename method
*
* @return void
*/
public function testGetViewFilename() {
$_admin = Configure::read('Routing.prefixes');
Configure::write('Routing.prefixes', array('admin'));
$this->Controller->request->params['action'] = 'index';
$ScaffoldView = new TestScaffoldView($this->Controller);
$result = $ScaffoldView->testGetFilename('index');
$expected = CAKE . 'View' . DS . 'Scaffolds' . DS . 'index.ctp';
$this->assertEqual($expected, $result);
$result = $ScaffoldView->testGetFilename('edit');
$expected = CAKE . 'View' . DS . 'Scaffolds' . DS . 'form.ctp';
$this->assertEqual($expected, $result);
$result = $ScaffoldView->testGetFilename('add');
$expected = CAKE . 'View' . DS . 'Scaffolds' . DS . 'form.ctp';
$this->assertEqual($expected, $result);
$result = $ScaffoldView->testGetFilename('view');
$expected = CAKE . 'View' . DS . 'Scaffolds' . DS . 'view.ctp';
$this->assertEqual($expected, $result);
$result = $ScaffoldView->testGetFilename('admin_index');
$expected = CAKE . 'View' . DS . 'Scaffolds' . DS . 'index.ctp';
$this->assertEqual($expected, $result);
$result = $ScaffoldView->testGetFilename('admin_view');
$expected = CAKE . 'View' . DS . 'Scaffolds' . DS . 'view.ctp';
$this->assertEqual($expected, $result);
$result = $ScaffoldView->testGetFilename('admin_edit');
$expected =CAKE . 'View' . DS . 'Scaffolds' . DS . 'form.ctp';
$this->assertEqual($expected, $result);
$result = $ScaffoldView->testGetFilename('admin_add');
$expected = CAKE . 'View' . DS . 'Scaffolds' . DS . 'form.ctp';
$this->assertEqual($expected, $result);
$result = $ScaffoldView->testGetFilename('error');
$expected = CAKE . 'View' . DS . 'Errors' . DS . 'scaffold_error.ctp';
$this->assertEqual($expected, $result);
$Controller = new ScaffoldViewMockController($this->request);
$Controller->scaffold = 'admin';
$Controller->viewPath = 'Posts';
$Controller->request['action'] = 'admin_edit';
$ScaffoldView = new TestScaffoldView($Controller);
$result = $ScaffoldView->testGetFilename('admin_edit');
$expected = CAKE . 'Test' . DS . 'test_app' .DS . 'View' . DS . 'Posts' . DS . 'scaffold.form.ctp';
$this->assertEqual($expected, $result);
$result = $ScaffoldView->testGetFilename('edit');
$expected = CAKE . 'Test' . DS . 'test_app' .DS . 'View' . DS . 'Posts' . DS . 'scaffold.form.ctp';
$this->assertEqual($expected, $result);
$Controller = new ScaffoldViewMockController($this->request);
$Controller->scaffold = 'admin';
$Controller->viewPath = 'Tests';
$Controller->request->addParams(array(
'plugin' => 'test_plugin',
'action' => 'admin_add',
'admin' => true
));
$Controller->plugin = 'TestPlugin';
$ScaffoldView = new TestScaffoldView($Controller);
$result = $ScaffoldView->testGetFilename('admin_add');
$expected = CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin'
. DS .'TestPlugin' . DS . 'View' . DS . 'Tests' . DS . 'scaffold.form.ctp';
$this->assertEqual($expected, $result);
$result = $ScaffoldView->testGetFilename('add');
$expected = CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin'
. DS .'TestPlugin' . DS . 'View' . DS . 'Tests' . DS . 'scaffold.form.ctp';
$this->assertEqual($expected, $result);
Configure::write('Routing.prefixes', $_admin);
}
/**
* test getting the view file name for themed scaffolds.
*
* @return void
*/
public function testGetViewFileNameWithTheme() {
$this->Controller->request['action'] = 'index';
$this->Controller->viewPath = 'Posts';
$this->Controller->theme = 'TestTheme';
$ScaffoldView = new TestScaffoldView($this->Controller);
$result = $ScaffoldView->testGetFilename('index');
$expected = CAKE . 'Test' . DS . 'test_app' . DS . 'View' . DS
. 'Themed' . DS . 'TestTheme' . DS . 'Posts' . DS . 'scaffold.index.ctp';
$this->assertEqual($expected, $result);
}
/**
* test default index scaffold generation
*
* @return void
*/
public function testIndexScaffold() {
$params = array(
'plugin' => null,
'pass' => array(),
'form' => array(),
'named' => array(),
'url' => array('url' =>'scaffold_mock'),
'controller' => 'scaffold_mock',
'action' => 'index',
);
$this->Controller->request->addParams($params);
$this->Controller->request->webroot = '/';
$this->Controller->request->base = '';
$this->Controller->request->here = '/scaffold_mock/index';
//set router.
Router::reload();
Router::setRequestInfo($this->Controller->request);
$this->Controller->constructClasses();
ob_start();
new Scaffold($this->Controller, $this->Controller->request);
$this->Controller->response->send();
$result = ob_get_clean();
$this->assertPattern('#<h2>Scaffold Mock</h2>#', $result);
$this->assertPattern('#<table cellpadding="0" cellspacing="0">#', $result);
$this->assertPattern('#<a href="/scaffold_users/view/1">1</a>#', $result); //belongsTo links
$this->assertPattern('#<li><a href="/scaffold_mock/add">New Scaffold Mock</a></li>#', $result);
$this->assertPattern('#<li><a href="/scaffold_users">List Scaffold Users</a></li>#', $result);
$this->assertPattern('#<li><a href="/scaffold_comments/add">New Comment</a></li>#', $result);
}
/**
* test default view scaffold generation
*
* @return void
*/
public function testViewScaffold() {
$this->Controller->request->base = '';
$this->Controller->request->here = '/scaffold_mock';
$this->Controller->request->webroot = '/';
$params = array(
'plugin' => null,
'pass' => array(1),
'form' => array(),
'named' => array(),
'url' => array('url' => 'scaffold_mock/view/1'),
'controller' => 'scaffold_mock',
'action' => 'view',
);
$this->Controller->request->addParams($params);
//set router.
Router::reload();
Router::setRequestInfo($this->Controller->request);
$this->Controller->constructClasses();
ob_start();
new Scaffold($this->Controller, $this->Controller->request);
$this->Controller->response->send();
$result = ob_get_clean();
$this->assertPattern('/<h2>View Scaffold Mock<\/h2>/', $result);
$this->assertPattern('/<dl>/', $result);
//TODO: add specific tests for fields.
$this->assertPattern('/<a href="\/scaffold_users\/view\/1">1<\/a>/', $result); //belongsTo links
$this->assertPattern('/<li><a href="\/scaffold_mock\/edit\/1">Edit Scaffold Mock<\/a>\s<\/li>/', $result);
$this->assertPattern('/<li><a href="\/scaffold_mock\/delete\/1"[^>]*>Delete Scaffold Mock<\/a>\s*<\/li>/', $result);
//check related table
$this->assertPattern('/<div class="related">\s*<h3>Related Scaffold Comments<\/h3>\s*<table cellpadding="0" cellspacing="0">/', $result);
$this->assertPattern('/<li><a href="\/scaffold_comments\/add">New Comment<\/a><\/li>/', $result);
$this->assertNoPattern('/<th>JoinThing<\/th>/', $result);
}
/**
* test default view scaffold generation
*
* @return void
*/
public function testEditScaffold() {
$this->Controller->request->base = '';
$this->Controller->request->webroot = '/';
$this->Controller->request->here = '/scaffold_mock/edit/1';
$params = array(
'plugin' => null,
'pass' => array(1),
'form' => array(),
'named' => array(),
'url' => array('url' =>'scaffold_mock'),
'controller' => 'scaffold_mock',
'action' => 'edit',
);
$this->Controller->request->addParams($params);
//set router.
Router::reload();
Router::setRequestInfo($this->Controller->request);
$this->Controller->constructClasses();
ob_start();
new Scaffold($this->Controller, $this->Controller->request);
$this->Controller->response->send();
$result = ob_get_clean();
$this->assertContains('<form action="/scaffold_mock/edit/1" id="ScaffoldMockEditForm" method="post"', $result);
$this->assertContains('<legend>Edit Scaffold Mock</legend>', $result);
$this->assertContains('input type="hidden" name="data[ScaffoldMock][id]" value="1" id="ScaffoldMockId"', $result);
$this->assertContains('select name="data[ScaffoldMock][user_id]" id="ScaffoldMockUserId"', $result);
$this->assertContains('input name="data[ScaffoldMock][title]" maxlength="255" type="text" value="First Article" id="ScaffoldMockTitle"', $result);
$this->assertContains('input name="data[ScaffoldMock][published]" maxlength="1" type="text" value="Y" id="ScaffoldMockPublished"', $result);
$this->assertContains('textarea name="data[ScaffoldMock][body]" cols="30" rows="6" id="ScaffoldMockBody"', $result);
$this->assertPattern('/<a href="\#" onclick="if[^>]*>Delete<\/a><\/li>/', $result);
}
/**
* Test Admin Index Scaffolding.
*
* @return void
*/
public function testAdminIndexScaffold() {
$_backAdmin = Configure::read('Routing.prefixes');
Configure::write('Routing.prefixes', array('admin'));
$params = array(
'plugin' => null,
'pass' => array(),
'form' => array(),
'named' => array(),
'prefix' => 'admin',
'url' => array('url' =>'admin/scaffold_mock'),
'controller' => 'scaffold_mock',
'action' => 'admin_index',
'admin' => 1,
);
$this->Controller->request->base = '';
$this->Controller->request->webroot = '/';
$this->Controller->request->here = '/admin/scaffold_mock';
$this->Controller->request->addParams($params);
//reset, and set router.
Router::reload();
Router::setRequestInfo($this->Controller->request);
$this->Controller->scaffold = 'admin';
$this->Controller->constructClasses();
ob_start();
$Scaffold = new Scaffold($this->Controller, $this->Controller->request);
$this->Controller->response->send();
$result = ob_get_clean();
$this->assertPattern('/<h2>Scaffold Mock<\/h2>/', $result);
$this->assertPattern('/<table cellpadding="0" cellspacing="0">/', $result);
//TODO: add testing for table generation
$this->assertPattern('/<li><a href="\/admin\/scaffold_mock\/add">New Scaffold Mock<\/a><\/li>/', $result);
Configure::write('Routing.prefixes', $_backAdmin);
}
/**
* Test Admin Index Scaffolding.
*
* @return void
*/
public function testAdminEditScaffold() {
Configure::write('Routing.prefixes', array('admin'));
$params = array(
'plugin' => null,
'pass' => array(1),
'form' => array(),
'named' => array(),
'prefix' => 'admin',
'url' => array('url' =>'admin/scaffold_mock/edit/1'),
'controller' => 'scaffold_mock',
'action' => 'admin_edit',
'admin' => 1,
);
$this->Controller->request->base = '';
$this->Controller->request->webroot = '/';
$this->Controller->request->here = '/admin/scaffold_mock/edit/1';
$this->Controller->request->addParams($params);
//reset, and set router.
Router::reload();
Router::setRequestInfo($this->Controller->request);
$this->Controller->scaffold = 'admin';
$this->Controller->constructClasses();
ob_start();
$Scaffold = new Scaffold($this->Controller, $this->Controller->request);
$this->Controller->response->send();
$result = ob_get_clean();
$this->assertPattern('#admin/scaffold_mock/edit/1#', $result);
$this->assertPattern('#Scaffold Mock#', $result);
}
/**
* Test Admin Index Scaffolding.
*
* @return void
*/
public function testMultiplePrefixScaffold() {
$_backAdmin = Configure::read('Routing.prefixes');
Configure::write('Routing.prefixes', array('admin', 'member'));
$params = array(
'plugin' => null,
'pass' => array(),
'form' => array(),
'named' => array(),
'prefix' => 'member',
'url' => array('url' =>'member/scaffold_mock'),
'controller' => 'scaffold_mock',
'action' => 'member_index',
'member' => 1,
);
$this->Controller->request->base = '';
$this->Controller->request->webroot = '/';
$this->Controller->request->here = '/member/scaffold_mock';
$this->Controller->request->addParams($params);
//reset, and set router.
Router::reload();
Router::setRequestInfo($this->Controller->request);
$this->Controller->scaffold = 'member';
$this->Controller->constructClasses();
ob_start();
$Scaffold = new Scaffold($this->Controller, $this->Controller->request);
$this->Controller->response->send();
$result = ob_get_clean();
$this->assertPattern('/<h2>Scaffold Mock<\/h2>/', $result);
$this->assertPattern('/<table cellpadding="0" cellspacing="0">/', $result);
//TODO: add testing for table generation
$this->assertPattern('/<li><a href="\/member\/scaffold_mock\/add">New Scaffold Mock<\/a><\/li>/', $result);
Configure::write('Routing.prefixes', $_backAdmin);
}
}
| 0001-bee | trunk/cakephp2/lib/Cake/Test/Case/View/ScaffoldViewTest.php | PHP | gpl3 | 14,803 |
<?php
/**
* ViewTest file
*
* PHP 5
*
* CakePHP(tm) Tests <http://book.cakephp.org/view/1196/Testing>
* Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice
*
* @copyright Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://book.cakephp.org/view/1196/Testing CakePHP(tm) Tests
* @package Cake.Test.Case.View
* @since CakePHP(tm) v 1.2.0.4206
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
App::uses('View', 'View');
App::uses('Helper', 'View');
App::uses('Controller', 'Controller');
App::uses('CacheHelper', 'View/Helper');
App::uses('ErrorHandler', 'Error');
/**
* ViewPostsController class
*
* @package Cake.Test.Case.View
*/
class ViewPostsController extends Controller {
/**
* name property
*
* @var string 'Posts'
*/
public $name = 'Posts';
/**
* uses property
*
* @var mixed null
*/
public $uses = null;
/**
* index method
*
* @return void
*/
public function index() {
$this->set('testData', 'Some test data');
$test2 = 'more data';
$test3 = 'even more data';
$this->set(compact('test2', 'test3'));
}
/**
* nocache_tags_with_element method
*
* @return void
*/
public function nocache_multiple_element() {
$this->set('foo', 'this is foo var');
$this->set('bar', 'this is bar var');
}
}
/**
* TestView class
*
* @package Cake.Test.Case.View
*/
class TestView extends View {
/**
* getViewFileName method
*
* @param mixed $name
* @return void
*/
public function getViewFileName($name = null) {
return $this->_getViewFileName($name);
}
/**
* getLayoutFileName method
*
* @param mixed $name
* @return void
*/
public function getLayoutFileName($name = null) {
return $this->_getLayoutFileName($name);
}
/**
* paths method
*
* @param string $plugin
* @param boolean $cached
* @return void
*/
public function paths($plugin = null, $cached = true) {
return $this->_paths($plugin, $cached);
}
/**
* _render wrapper for testing (temporary).
*
* @param string $___viewFn
* @param string $___dataForView
* @param string $loadHelpers
* @param string $cached
* @return void
*/
public function render_($___viewFn, $___dataForView, $loadHelpers = true, $cached = false) {
return $this->_render($___viewFn, $___dataForView, $loadHelpers, $cached);
}
/**
* Test only function to return instance scripts.
*
* @return array Scripts
*/
public function scripts() {
return $this->_scripts;
}
}
/**
* TestAfterHelper class
*
* @package Cake.Test.Case.View
*/
class TestAfterHelper extends Helper {
/**
* property property
*
* @var string ''
*/
public $property = '';
/**
* beforeLayout method
*
* @return void
*/
public function beforeLayout($viewFile) {
$this->property = 'Valuation';
}
/**
* afterLayout method
*
* @return void
*/
public function afterLayout($layoutFile) {
$this->_View->output .= 'modified in the afterlife';
}
}
/**
* ViewTest class
*
* @package Cake.Test.Case.View
*/
class ViewTest extends CakeTestCase {
/**
* setUp method
*
* @return void
*/
public function setUp() {
parent::setUp();
$request = $this->getMock('CakeRequest');
$this->Controller = new Controller($request);
$this->PostsController = new ViewPostsController($request);
$this->PostsController->viewPath = 'Posts';
$this->PostsController->index();
$this->View = new View($this->PostsController);
App::build(array(
'plugins' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS),
'View' => array(
CAKE . 'Test' . DS . 'test_app' . DS . 'View'. DS
)
), true);
CakePlugin::loadAll();
Configure::write('debug', 2);
}
/**
* tearDown method
*
* @return void
*/
public function tearDown() {
parent::tearDown();
CakePlugin::unload();
unset($this->View);
unset($this->PostsController);
unset($this->Controller);
}
/**
* testPluginGetTemplate method
*
* @return void
*/
public function testPluginGetTemplate() {
$this->Controller->plugin = 'TestPlugin';
$this->Controller->name = 'TestPlugin';
$this->Controller->viewPath = 'Tests';
$this->Controller->action = 'index';
$View = new TestView($this->Controller);
$expected = CakePlugin::path('TestPlugin') . 'View' . DS .'Tests' . DS .'index.ctp';
$result = $View->getViewFileName('index');
$this->assertEqual($expected, $result);
$expected = CakePlugin::path('TestPlugin') . 'View' . DS . 'Layouts' . DS .'default.ctp';
$result = $View->getLayoutFileName();
$this->assertEqual($expected, $result);
}
/**
* test that plugin/$plugin_name is only appended to the paths it should be.
*
* @return void
*/
public function testPluginPathGeneration() {
$this->Controller->plugin = 'TestPlugin';
$this->Controller->name = 'TestPlugin';
$this->Controller->viewPath = 'Tests';
$this->Controller->action = 'index';
$View = new TestView($this->Controller);
$paths = $View->paths();
$expected = array_merge(App::path('View'), App::core('View'));
$this->assertEqual($paths, $expected);
$paths = $View->paths('TestPlugin');
$pluginPath = CakePlugin::path('TestPlugin');
$expected = array(
CAKE . 'Test' . DS . 'test_app' . DS . 'View' . DS . 'Plugin' . DS . 'TestPlugin' . DS,
$pluginPath . 'View' . DS,
$pluginPath . 'views' . DS,
$pluginPath . 'Lib' . DS . 'View' . DS,
CAKE . 'Test' . DS . 'test_app' . DS . 'View' . DS,
CAKE . 'View' . DS
);
$this->assertEqual($paths, $expected);
}
/**
* test that CamelCase plugins still find their view files.
*
* @return void
*/
public function testCamelCasePluginGetTemplate() {
$this->Controller->plugin = 'TestPlugin';
$this->Controller->name = 'TestPlugin';
$this->Controller->viewPath = 'Tests';
$this->Controller->action = 'index';
$View = new TestView($this->Controller);
App::build(array(
'plugins' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS),
'View' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'View'. DS)
));
$pluginPath = CakePlugin::path('TestPlugin');
$expected = CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS .'TestPlugin' . DS . 'View' . DS .'Tests' . DS .'index.ctp';
$result = $View->getViewFileName('index');
$this->assertEqual($expected, $result);
$expected = $pluginPath. 'View' . DS . 'Layouts' . DS .'default.ctp';
$result = $View->getLayoutFileName();
$this->assertEqual($expected, $result);
}
/**
* testGetTemplate method
*
* @return void
*/
public function testGetTemplate() {
$this->Controller->plugin = null;
$this->Controller->name = 'Pages';
$this->Controller->viewPath = 'Pages';
$this->Controller->action = 'display';
$this->Controller->params['pass'] = array('home');
$View = new TestView($this->Controller);
$expected = CAKE . 'Test' . DS . 'test_app' . DS . 'View' . DS .'Pages' . DS .'home.ctp';
$result = $View->getViewFileName('home');
$this->assertEqual($expected, $result);
$expected = CAKE . 'Test' . DS . 'test_app' . DS . 'View' . DS .'Posts' . DS .'index.ctp';
$result = $View->getViewFileName('/Posts/index');
$this->assertEqual($expected, $result);
$expected = CAKE . 'Test' . DS . 'test_app' . DS . 'View' . DS .'Posts' . DS .'index.ctp';
$result = $View->getViewFileName('../Posts/index');
$this->assertEqual($expected, $result);
$expected = CAKE . 'Test' . DS . 'test_app' . DS . 'View' . DS . 'Layouts' . DS .'default.ctp';
$result = $View->getLayoutFileName();
$this->assertEqual($expected, $result);
$View->layoutPath = 'rss';
$expected = CAKE . 'Test' . DS . 'test_app' . DS . 'View' . DS . 'Layouts' . DS . 'rss' . DS . 'default.ctp';
$result = $View->getLayoutFileName();
$this->assertEqual($expected, $result);
$View->layoutPath = 'Emails' . DS . 'html';
$expected = CAKE . 'Test' . DS . 'test_app' . DS . 'View' . DS . 'Layouts' . DS . 'Emails' . DS . 'html' . DS . 'default.ctp';
$result = $View->getLayoutFileName();
$this->assertEqual($expected, $result);
}
/**
* testMissingView method
*
* @expectedException MissingViewException
* @return void
*/
public function testMissingView() {
$this->Controller->plugin = null;
$this->Controller->name = 'Pages';
$this->Controller->viewPath = 'Pages';
$this->Controller->action = 'display';
$this->Controller->params['pass'] = array('home');
$View = new TestView($this->Controller);
ob_start();
$result = $View->getViewFileName('does_not_exist');
}
/**
* testMissingLayout method
*
* @expectedException MissingLayoutException
* @return void
*/
public function testMissingLayout() {
$this->Controller->plugin = null;
$this->Controller->name = 'Posts';
$this->Controller->viewPath = 'Posts';
$this->Controller->layout = 'whatever';
$View = new TestView($this->Controller);
ob_start();
$result = $View->getLayoutFileName();
$expected = str_replace(array("\t", "\r\n", "\n"), "", ob_get_clean());
}
/**
* testViewVars method
*
* @return void
*/
public function testViewVars() {
$this->assertEqual($this->View->viewVars, array('testData' => 'Some test data', 'test2' => 'more data', 'test3' => 'even more data'));
}
/**
* testUUIDGeneration method
*
* @return void
*/
public function testUUIDGeneration() {
$result = $this->View->uuid('form', array('controller' => 'posts', 'action' => 'index'));
$this->assertEqual($result, 'form5988016017');
$result = $this->View->uuid('form', array('controller' => 'posts', 'action' => 'index'));
$this->assertEqual($result, 'formc3dc6be854');
$result = $this->View->uuid('form', array('controller' => 'posts', 'action' => 'index'));
$this->assertEqual($result, 'form28f92cc87f');
}
/**
* testAddInlineScripts method
*
* @return void
*/
public function testAddInlineScripts() {
$View = new TestView($this->Controller);
$View->addScript('prototype.js');
$View->addScript('prototype.js');
$this->assertEqual($View->scripts(), array('prototype.js'));
$View->addScript('mainEvent', 'Event.observe(window, "load", function() { doSomething(); }, true);');
$this->assertEqual($View->scripts(), array('prototype.js', 'mainEvent' => 'Event.observe(window, "load", function() { doSomething(); }, true);'));
}
/**
* testElement method
*
* @return void
*/
public function testElement() {
$result = $this->View->element('test_element');
$this->assertEqual($result, 'this is the test element');
$result = $this->View->element('plugin_element', array(), array('plugin' => 'TestPlugin'));
$this->assertEqual($result, 'this is the plugin element using params[plugin]');
$result = $this->View->element('plugin_element', array(), array('plugin' => 'test_plugin'));
$this->assertEqual($result, 'this is the plugin element using params[plugin]');
$this->View->plugin = 'TestPlugin';
$result = $this->View->element('test_plugin_element');
$this->assertEqual($result, 'this is the test set using View::$plugin plugin element');
$result = $this->View->element('non_existant_element');
$this->assertPattern('/Not Found:/', $result);
$this->assertPattern('/non_existant_element/', $result);
}
/**
* test that elements can have callbacks
*
*/
public function testElementCallbacks() {
$this->getMock('HtmlHelper', array(), array($this->View), 'ElementCallbackMockHtmlHelper');
$this->View->helpers = array('ElementCallbackMockHtml');
$this->View->loadHelpers();
$this->View->ElementCallbackMockHtml->expects($this->at(0))->method('beforeRender');
$this->View->ElementCallbackMockHtml->expects($this->at(1))->method('afterRender');
$this->View->element('test_element', array(), array('callbacks' => true));
$this->mockObjects[] = $this->View->ElementCallbackMockHtml;
}
/**
* test that additional element viewVars don't get overwritten with helpers.
*
* @return void
*/
public function testElementParamsDontOverwriteHelpers() {
$Controller = new ViewPostsController();
$Controller->helpers = array('Form');
$View = new View($Controller);
$result = $View->element('type_check', array('form' => 'string'), array('callbacks' => true));
$this->assertEqual('string', $result);
$View->set('form', 'string');
$result = $View->element('type_check', array(), array('callbacks' => true));
$this->assertEqual('string', $result);
}
/**
* testElementCacheHelperNoCache method
*
* @return void
*/
public function testElementCacheHelperNoCache() {
$Controller = new ViewPostsController();
$View = new TestView($Controller);
$helpers = $View->loadHelpers();
$result = $View->element('test_element', array('ram' => 'val', 'test' => array('foo', 'bar')));
$this->assertEqual($result, 'this is the test element');
}
/**
* testElementCache method
*
* @return void
*/
public function testElementCache() {
Cache::drop('test_view');
Cache::config('test_view', array(
'engine' => 'File',
'duration' => '+1 day',
'path' => CACHE . 'views' . DS,
'prefix' => ''
));
Cache::clear('test_view');
$View = new TestView($this->PostsController);
$View->elementCache = 'test_view';
$result = $View->element('test_element', array(), array('cache' => true));
$expected = 'this is the test element';
$this->assertEquals($expected, $result);
$result = Cache::read('element__test_element_cache', 'test_view');
$this->assertEquals($expected, $result);
$result = $View->element('test_element', array('param' => 'one', 'foo' => 'two'), array('cache' => true));
$this->assertEquals($expected, $result);
$result = Cache::read('element__test_element_cache_param_foo', 'test_view');
$this->assertEquals($expected, $result);
$result = $View->element('test_element', array(
'param' => 'one',
'foo' => 'two'
), array(
'cache' => array('key' => 'custom_key')
));
$result = Cache::read('element_custom_key', 'test_view');
$this->assertEquals($expected, $result);
$View->elementCache = 'default';
$result = $View->element('test_element', array(
'param' => 'one',
'foo' => 'two'
), array(
'cache' => array('config' => 'test_view'),
));
$result = Cache::read('element__test_element_cache_param_foo', 'test_view');
$this->assertEquals($expected, $result);
Cache::drop('test_view');
}
/**
* test __get allowing access to helpers.
*
* @return void
*/
public function test__get() {
$View = new View($this->PostsController);
$View->loadHelper('Html');
$this->assertInstanceOf('HtmlHelper', $View->Html);
}
/**
* test that ctp is used as a fallback file extension for elements
*
* @return void
*/
public function testElementCtpFallback() {
$View = new TestView($this->PostsController);
$View->ext = '.missing';
$element = 'test_element';
$expected = 'this is the test element';
$result = $View->element($element);
$this->assertEqual($expected, $result);
}
/**
* testLoadHelpers method
*
* @return void
*/
public function testLoadHelpers() {
$View = new View($this->PostsController);
$View->helpers = array('Html', 'Form');
$View->loadHelpers();
$this->assertInstanceOf('HtmlHelper', $View->Html, 'Object type is wrong.');
$this->assertInstanceOf('FormHelper', $View->Form, 'Object type is wrong.');
}
/**
* test the correct triggering of helper callbacks
*
* @return void
*/
public function testHelperCallbackTriggering() {
$View = new View($this->PostsController);
$View->helpers = array('Html', 'Session');
$View->Helpers = $this->getMock('HelperCollection', array('trigger'), array($View));
$View->Helpers->expects($this->at(0))->method('trigger')
->with('beforeRender', new PHPUnit_Framework_Constraint_IsAnything());
$View->Helpers->expects($this->at(1))->method('trigger')
->with('afterRender', new PHPUnit_Framework_Constraint_IsAnything());
$View->Helpers->expects($this->at(2))->method('trigger')
->with('beforeLayout', new PHPUnit_Framework_Constraint_IsAnything());
$View->Helpers->expects($this->at(3))->method('trigger')
->with('afterLayout', new PHPUnit_Framework_Constraint_IsAnything());
$View->render('index');
}
/**
* testBeforeLayout method
*
* @return void
*/
public function testBeforeLayout() {
$this->PostsController->helpers = array('Session', 'TestAfter', 'Html');
$View = new View($this->PostsController);
$View->render('index');
$this->assertEqual($View->Helpers->TestAfter->property, 'Valuation');
}
/**
* testAfterLayout method
*
* @return void
*/
public function testAfterLayout() {
$this->PostsController->helpers = array('Session', 'TestAfter', 'Html');
$this->PostsController->set('variable', 'values');
$View = new View($this->PostsController);
ClassRegistry::addObject('afterView', $View);
$content = 'This is my view output';
$result = $View->renderLayout($content, 'default');
$this->assertPattern('/modified in the afterlife/', $result);
$this->assertPattern('/This is my view output/', $result);
}
/**
* testRenderLoadHelper method
*
* @return void
*/
public function testRenderLoadHelper() {
$this->PostsController->helpers = array('Session', 'Html', 'Form', 'Number');
$View = new TestView($this->PostsController);
$result = $View->render('index', false);
$this->assertEqual($result, 'posts index');
$attached = $View->Helpers->attached();
$this->assertEquals($attached, array('Session', 'Html', 'Form', 'Number'));
$this->PostsController->helpers = array('Html', 'Form', 'Number', 'TestPlugin.PluggedHelper');
$View = new TestView($this->PostsController);
$result = $View->render('index', false);
$this->assertEqual($result, 'posts index');
$attached = $View->Helpers->attached();
$expected = array('Html', 'Form', 'Number', 'PluggedHelper');
$this->assertEquals($expected, $attached, 'Attached helpers are wrong.');
}
/**
* testRender method
*
* @return void
*/
public function testRender() {
$View = new TestView($this->PostsController);
$result = str_replace(array("\t", "\r\n", "\n"), "", $View->render('index'));
$this->assertPattern("/<meta http-equiv=\"Content-Type\" content=\"text\/html; charset=utf-8\" \/><title>/", $result);
$this->assertPattern("/<div id=\"content\">posts index<\/div>/", $result);
$this->assertPattern("/<div id=\"content\">posts index<\/div>/", $result);
$this->assertTrue(isset($View->viewVars['content_for_layout']), 'content_for_layout should be a view var');
$this->assertTrue(isset($View->viewVars['scripts_for_layout']), 'scripts_for_layout should be a view var');
$this->PostsController->set('url', 'flash');
$this->PostsController->set('message', 'yo what up');
$this->PostsController->set('pause', 3);
$this->PostsController->set('page_title', 'yo what up');
$View = new TestView($this->PostsController);
$result = str_replace(array("\t", "\r\n", "\n"), "", $View->render(false, 'flash'));
$this->assertPattern("/<title>yo what up<\/title>/", $result);
$this->assertPattern("/<p><a href=\"flash\">yo what up<\/a><\/p>/", $result);
$this->assertTrue($View->render(false, 'flash'));
$this->PostsController->helpers = array('Session', 'Cache', 'Html');
$this->PostsController->constructClasses();
$this->PostsController->cacheAction = array('index' => 3600);
$this->PostsController->request->params['action'] = 'index';
Configure::write('Cache.check', true);
$View = new TestView($this->PostsController);
$result = str_replace(array("\t", "\r\n", "\n"), "", $View->render('index'));
$this->assertPattern("/<meta http-equiv=\"Content-Type\" content=\"text\/html; charset=utf-8\" \/><title>/", $result);
$this->assertPattern("/<div id=\"content\">posts index<\/div>/", $result);
$this->assertPattern("/<div id=\"content\">posts index<\/div>/", $result);
}
/**
* test that View::$view works
*
* @return void
*/
public function testRenderUsingViewProperty() {
$this->PostsController->view = 'cache_form';
$View = new TestView($this->PostsController);
$this->assertEquals('cache_form', $View->view);
$result = $View->render();
$this->assertRegExp('/Add User/', $result);
}
/**
* test that view vars can replace the local helper variables
* and not overwrite the $this->Helper references
*
* @return void
*/
public function testViewVarOverwritingLocalHelperVar() {
$Controller = new ViewPostsController();
$Controller->helpers = array('Session', 'Html');
$Controller->set('html', 'I am some test html');
$View = new View($Controller);
$result = $View->render('helper_overwrite', false);
$this->assertPattern('/I am some test html/', $result);
$this->assertPattern('/Test link/', $result);
}
/**
* testGetViewFileName method
*
* @return void
*/
public function testViewFileName() {
$View = new TestView($this->PostsController);
$result = $View->getViewFileName('index');
$this->assertPattern('/Posts(\/|\\\)index.ctp/', $result);
$result = $View->getViewFileName('/Pages/home');
$this->assertPattern('/Pages(\/|\\\)home.ctp/', $result);
$result = $View->getViewFileName('../Elements/test_element');
$this->assertPattern('/Elements(\/|\\\)test_element.ctp/', $result);
$result = $View->getViewFileName('../Themed/TestTheme/Posts/index');
$this->assertPattern('/Themed(\/|\\\)TestTheme(\/|\\\)Posts(\/|\\\)index.ctp/', $result);
$expected = CAKE . 'Test' . DS . 'test_app' . DS . 'View' . DS .'Posts' . DS .'index.ctp';
$result = $View->getViewFileName('../Posts/index');
$this->assertEqual($expected, $result);
}
/**
* testRenderCache method
*
* @return void
*/
public function testRenderCache() {
$this->skipIf(!is_writable(CACHE . 'views' . DS), 'CACHE/views dir is not writable, cannot test renderCache.');
$view = 'test_view';
$View = new View($this->PostsController);
$path = CACHE . 'views' . DS . 'view_cache_' . $view;
$cacheText = '<!--cachetime:' . time() . '-->some cacheText';
$f = fopen($path, 'w+');
fwrite($f, $cacheText);
fclose($f);
$result = $View->renderCache($path, '+1 second');
$this->assertFalse($result);
if (file_exists($path)) {
unlink($path);
}
$cacheText = '<!--cachetime:' . (time() + 10) . '-->some cacheText';
$f = fopen($path, 'w+');
fwrite($f, $cacheText);
fclose($f);
ob_start();
$View->renderCache($path, '+1 second');
$result = ob_get_clean();
$expected = 'some cacheText';
$this->assertPattern('/^some cacheText/', $result);
@unlink($path);
}
/**
* Test that render() will remove the cake:nocache tags when only the cachehelper is present.
*
* @return void
*/
public function testRenderStrippingNoCacheTagsOnlyCacheHelper() {
Configure::write('Cache.check', false);
$View = new View($this->PostsController);
$View->set(array('superman' => 'clark', 'variable' => 'var'));
$View->helpers = array('Html', 'Form', 'Cache');
$View->layout = 'cache_layout';
$result = $View->render('index');
$this->assertNoPattern('/cake:nocache/', $result);
}
/**
* Test that render() will remove the cake:nocache tags when only the Cache.check is true.
*
* @return void
*/
public function testRenderStrippingNoCacheTagsOnlyCacheCheck() {
Configure::write('Cache.check', true);
$View = new View($this->PostsController);
$View->set(array('superman' => 'clark', 'variable' => 'var'));
$View->helpers = array('Html', 'Form');
$View->layout = 'cache_layout';
$result = $View->render('index');
$this->assertNoPattern('/cake:nocache/', $result);
}
/**
* testRenderNocache method
*
* @return void
*/
/* This is a new test case for a pending enhancement
public function testRenderNocache() {
$this->PostsController->helpers = array('Cache', 'Html');
$this->PostsController->constructClasses();
$this->PostsController->cacheAction = 21600;
$this->PostsController->here = '/posts/nocache_multiple_element';
$this->PostsController->action = 'nocache_multiple_element';
$this->PostsController->nocache_multiple_element();
Configure::write('Cache.check', true);
Configure::write('Cache.disable', false);
$filename = CACHE . 'views' . DS . 'posts_nocache_multiple_element.php';
$View = new TestView($this->PostsController);
$View->render();
ob_start();
$View->renderCache($filename, getMicroTime());
$result = ob_get_clean();
@unlink($filename);
$this->assertPattern('/php echo \$foo;/', $result);
$this->assertPattern('/php echo \$bar;/', $result);
$this->assertPattern('/php \$barfoo = \'in sub2\';/', $result);
$this->assertPattern('/php echo \$barfoo;/', $result);
$this->assertPattern('/printing: "in sub2"/', $result);
$this->assertPattern('/php \$foobar = \'in sub1\';/', $result);
$this->assertPattern('/php echo \$foobar;/', $result);
$this->assertPattern('/printing: "in sub1"/', $result);
}
*/
/**
* testSet method
*
* @return void
*/
public function testSet() {
$View = new TestView($this->PostsController);
$View->viewVars = array();
$View->set('somekey', 'someValue');
$this->assertIdentical($View->viewVars, array('somekey' => 'someValue'));
$this->assertIdentical($View->getVars(), array('somekey'));
$View->viewVars = array();
$keys = array('key1', 'key2');
$values = array('value1', 'value2');
$View->set($keys, $values);
$this->assertIdentical($View->viewVars, array('key1' => 'value1', 'key2' => 'value2'));
$this->assertIdentical($View->getVars(), array('key1', 'key2'));
$this->assertIdentical($View->getVar('key1'), 'value1');
$this->assertNull($View->getVar('key3'));
$View->set(array('key3' => 'value3'));
$this->assertIdentical($View->getVar('key3'), 'value3');
$View->viewVars = array();
$View->set(array(3 => 'three', 4 => 'four'));
$View->set(array(1 => 'one', 2 => 'two'));
$expected = array(3 => 'three', 4 => 'four', 1 => 'one', 2 => 'two');
$this->assertEqual($View->viewVars, $expected);
}
/**
* testBadExt method
*
* @expectedException MissingViewException
* @return void
*/
public function testBadExt() {
$this->PostsController->action = 'something';
$this->PostsController->ext = '.whatever';
$View = new TestView($this->PostsController);
$View->render('this_is_missing');
$result = str_replace(array("\t", "\r\n", "\n"), "", ob_get_clean());
}
/**
* testAltExt method
*
* @return void
*/
public function testAltExt() {
$this->PostsController->ext = '.alt';
$View = new TestView($this->PostsController);
$result = $View->render('alt_ext', false);
$this->assertEqual($result, 'alt ext');
}
/**
* testAltBadExt method
*
* @expectedException MissingViewException
* @return void
*/
public function testAltBadExt() {
$View = new TestView($this->PostsController);
$View->render('alt_ext');
$result = str_replace(array("\t", "\r\n", "\n"), "", ob_get_clean());
}
}
| 0001-bee | trunk/cakephp2/lib/Cake/Test/Case/View/ViewTest.php | PHP | gpl3 | 26,819 |
<?php
/**
* HelperTest file
*
* PHP 5
*
* CakePHP(tm) Tests <http://book.cakephp.org/view/1196/Testing>
* Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice
*
* @copyright Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://book.cakephp.org/view/1196/Testing CakePHP(tm) Tests
* @package Cake.Test.Case.View
* @since CakePHP(tm) v 1.2.0.4206
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
App::uses('View', 'View');
App::uses('Helper', 'View');
App::uses('Model', 'Model');
App::uses('Router', 'Routing');
/**
* HelperTestPost class
*
* @package Cake.Test.Case.View
*/
class HelperTestPost extends Model {
/**
* useTable property
*
* @var bool false
*/
public $useTable = false;
/**
* schema method
*
* @return void
*/
public function schema($field = false) {
$this->_schema = array(
'id' => array('type' => 'integer', 'null' => false, 'default' => '', 'length' => '8'),
'title' => array('type' => 'string', 'null' => false, 'default' => '', 'length' => '255'),
'body' => array('type' => 'string', 'null' => true, 'default' => '', 'length' => ''),
'number' => array('type' => 'integer', 'null' => false, 'default' => '', 'length' => '8'),
'date' => array('type' => 'date', 'null' => true, 'default' => '', 'length' => ''),
'created' => array('type' => 'date', 'null' => true, 'default' => '', 'length' => ''),
'modified' => array('type' => 'datetime', 'null' => true, 'default' => '', 'length' => null)
);
return $this->_schema;
}
/**
* hasAndBelongsToMany property
*
* @var array
*/
public $hasAndBelongsToMany = array('HelperTestTag'=> array('with' => 'HelperTestPostsTag'));
}
/**
* HelperTestComment class
*
* @package Cake.Test.Case.View
*/
class HelperTestComment extends Model {
/**
* useTable property
*
* @var bool false
*/
public $useTable = false;
/**
* schema method
*
* @return void
*/
public function schema($field = false) {
$this->_schema = array(
'id' => array('type' => 'integer', 'null' => false, 'default' => '', 'length' => '8'),
'author_id' => array('type' => 'integer', 'null' => false, 'default' => '', 'length' => '8'),
'title' => array('type' => 'string', 'null' => false, 'default' => '', 'length' => '255'),
'body' => array('type' => 'string', 'null' => true, 'default' => '', 'length' => ''),
'BigField' => array('type' => 'string', 'null' => true, 'default' => '', 'length' => ''),
'created' => array('type' => 'date', 'null' => true, 'default' => '', 'length' => ''),
'modified' => array('type' => 'datetime', 'null' => true, 'default' => '', 'length' => null)
);
return $this->_schema;
}
}
/**
* HelperTestTag class
*
* @package Cake.Test.Case.View
*/
class HelperTestTag extends Model {
/**
* useTable property
*
* @var bool false
*/
public $useTable = false;
/**
* schema method
*
* @return void
*/
public function schema($field = false) {
$this->_schema = array(
'id' => array('type' => 'integer', 'null' => false, 'default' => '', 'length' => '8'),
'name' => array('type' => 'string', 'null' => false, 'default' => '', 'length' => '255'),
'created' => array('type' => 'date', 'null' => true, 'default' => '', 'length' => ''),
'modified' => array('type' => 'datetime', 'null' => true, 'default' => '', 'length' => null)
);
return $this->_schema;
}
}
/**
* HelperTestPostsTag class
*
* @package Cake.Test.Case.View
*/
class HelperTestPostsTag extends Model {
/**
* useTable property
*
* @var bool false
*/
public $useTable = false;
/**
* schema method
*
* @return void
*/
public function schema($field = false) {
$this->_schema = array(
'helper_test_post_id' => array('type' => 'integer', 'null' => false, 'default' => '', 'length' => '8'),
'helper_test_tag_id' => array('type' => 'integer', 'null' => false, 'default' => '', 'length' => '8'),
);
return $this->_schema;
}
}
class TestHelper extends Helper {
/**
* Helpers for this helper.
*
* @var string
*/
public $helpers = array('Html', 'TestPlugin.OtherHelper');
/**
* expose a method as public
*
* @param string $options
* @param string $exclude
* @param string $insertBefore
* @param string $insertAfter
* @return void
*/
public function parseAttributes($options, $exclude = null, $insertBefore = ' ', $insertAfter = null) {
return $this->_parseAttributes($options, $exclude, $insertBefore, $insertAfter);
}
}
/**
* HelperTest class
*
* @package Cake.Test.Case.View
*/
class HelperTest extends CakeTestCase {
/**
* setUp method
*
* @return void
*/
public function setUp() {
ClassRegistry::flush();
Router::reload();
$null = null;
$this->View = new View($null);
$this->Helper = new Helper($this->View);
$this->Helper->request = new CakeRequest(null, false);
ClassRegistry::addObject('HelperTestPost', new HelperTestPost());
ClassRegistry::addObject('HelperTestComment', new HelperTestComment());
ClassRegistry::addObject('HelperTestTag', new HelperTestTag());
}
/**
* tearDown method
*
* @return void
*/
public function tearDown() {
CakePlugin::unload();
unset($this->Helper, $this->View);
ClassRegistry::flush();
}
/**
* Provider for setEntity test.
*
* @return array
*/
public static function entityProvider() {
return array(
array(
'HelperTestPost.id',
array('HelperTestPost', 'id')
),
array(
'HelperTestComment.body',
array('HelperTestComment', 'body')
),
array(
'HelperTest.1.Comment.body',
array('HelperTest', '1', 'Comment', 'body')
),
array(
'HelperTestComment.BigField',
array('HelperTestComment', 'BigField')
)
);
}
/**
* testFormFieldNameParsing method
*
* @dataProvider entityProvider
* @return void
*/
public function testSetEntity($entity, $expected) {
$this->Helper->setEntity($entity);
$this->assertEquals($expected, $this->Helper->entity());
}
/**
* test setEntity with setting a scope.
*
* @return
*/
public function testSetEntityScoped() {
$this->Helper->setEntity('HelperTestPost', true);
$this->assertEquals(array('HelperTestPost'), $this->Helper->entity());
$this->Helper->setEntity('id');
$expected = array('HelperTestPost', 'id');
$this->assertEquals($expected, $this->Helper->entity());
$this->Helper->setEntity('HelperTestComment.body');
$expected = array('HelperTestComment', 'body');
$this->assertEquals($expected, $this->Helper->entity());
$this->Helper->setEntity('body');
$expected = array('HelperTestPost', 'body');
$this->assertEquals($expected, $this->Helper->entity());
$this->Helper->setEntity('2.body');
$expected = array('HelperTestPost', '2', 'body');
$this->assertEquals($expected, $this->Helper->entity());
$this->Helper->setEntity('Something.else');
$expected = array('Something', 'else');
$this->assertEquals($expected, $this->Helper->entity());
$this->Helper->setEntity('HelperTestComment.5.id');
$expected = array('HelperTestComment', 5, 'id');
$this->assertEquals($expected, $this->Helper->entity());
$this->Helper->setEntity('HelperTestComment.id.time');
$expected = array('HelperTestComment', 'id', 'time');
$this->assertEquals($expected, $this->Helper->entity());
$this->Helper->setEntity('HelperTestComment.created.year');
$expected = array('HelperTestComment', 'created', 'year');
$this->assertEquals($expected, $this->Helper->entity());
$this->Helper->setEntity(null);
$this->Helper->setEntity('ModelThatDoesntExist.field_that_doesnt_exist');
$expected = array('ModelThatDoesntExist', 'field_that_doesnt_exist');
$this->assertEquals($expected, $this->Helper->entity());
}
/**
* Test that setEntity() and model()/field() work with associated models.
*
* @return void
*/
public function testSetEntityAssociated() {
$this->Helper->setEntity('HelperTestPost', true);
$this->Helper->setEntity('HelperTestPost.1.HelperTestComment.1.title');
$expected = array('HelperTestPost', '1', 'HelperTestComment', '1', 'title');
$this->assertEquals($expected, $this->Helper->entity());
$this->assertEquals('HelperTestComment', $this->Helper->model());
}
/**
* Test that setEntity doesn't make CamelCase fields that are not associations an
* associated model.
*
* @return void
*/
public function testSetEntityAssociatedCamelCaseField() {
$this->Helper->fieldset = array(
'HelperTestComment' => array(
'fields' => array('BigField' => array('type' => 'integer'))
)
);
$this->Helper->setEntity('HelperTestComment', true);
$this->Helper->setEntity('HelperTestComment.BigField');
$this->assertEquals('HelperTestComment', $this->Helper->model());
$this->assertEquals('BigField', $this->Helper->field());
}
/**
* Test that multiple fields work when they are camelcase and in fieldset
*
* @return void
*/
public function testSetEntityAssociatedCamelCaseFieldHabtmMultiple() {
$this->Helper->fieldset = array(
'HelperTestComment' => array(
'fields' => array('Tag' => array('type' => 'multiple'))
)
);
$this->Helper->setEntity('HelperTestComment', true);
$this->Helper->setEntity('Tag');
$this->assertEquals('Tag', $this->Helper->model());
$this->assertEquals('Tag', $this->Helper->field());
$this->assertEquals(array('Tag', 'Tag'), $this->Helper->entity());
}
/**
* test that 'view' doesn't break things.
*
* @return void
*/
public function testSetEntityWithView() {
$this->assertNull($this->Helper->setEntity('Allow.view.group_id'));
$this->assertNull($this->Helper->setEntity('Allow.view'));
$this->assertNull($this->Helper->setEntity('View.view'));
}
/**
* test getting values from Helper
*
* @return void
*/
public function testValue() {
$this->Helper->request->data = array('fullname' => 'This is me');
$this->Helper->setEntity('fullname');
$result = $this->Helper->value('fullname');
$this->assertEqual($result, 'This is me');
$this->Helper->request->data = array(
'Post' => array('name' => 'First Post')
);
$this->Helper->setEntity('Post.name');
$result = $this->Helper->value('Post.name');
$this->assertEqual($result, 'First Post');
$this->Helper->request->data = array(
'Post' => array(2 => array('name' => 'First Post'))
);
$this->Helper->setEntity('Post.2.name');
$result = $this->Helper->value('Post.2.name');
$this->assertEqual($result, 'First Post');
$this->Helper->request->data = array(
'Post' => array(
2 => array('created' => array('year' => '2008'))
)
);
$this->Helper->setEntity('Post.2.created');
$result = $this->Helper->value('Post.2.created');
$this->assertEqual($result, array('year' => '2008'));
$this->Helper->request->data = array(
'Post' => array(
2 => array('created' => array('year' => '2008'))
)
);
$this->Helper->setEntity('Post.2.created.year');
$result = $this->Helper->value('Post.2.created.year');
$this->assertEqual($result, '2008');
}
/**
* Test default values with value()
*
* @return void
*/
function testValueWithDefault() {
$this->Helper->request->data = array('zero' => 0);
$this->Helper->setEntity('zero');
$result = $this->Helper->value(array('default' => 'something'), 'zero');
$this->assertEqual($result, array('value' => 0));
$this->Helper->request->data = array('zero' => '0');
$result = $this->Helper->value(array('default' => 'something'), 'zero');
$this->assertEqual($result, array('value' => '0'));
$this->Helper->setEntity('inexistent');
$result = $this->Helper->value(array('default' => 'something'), 'inexistent');
$this->assertEqual($result, array('value' => 'something'));
}
/**
* Test habtm data fetching and ensure no pollution happens.
*
* @return void
*/
function testValueHabtmKeys() {
$this->Helper->request->data = array(
'HelperTestTag' => array('HelperTestTag' => '')
);
$this->Helper->setEntity('HelperTestTag.HelperTestTag');
$result = $this->Helper->value('HelperTestTag.HelperTestTag');
$this->assertEqual($result, '');
$this->Helper->request->data = array(
'HelperTestTag' => array(
'HelperTestTag' => array(2, 3, 4)
)
);
$this->Helper->setEntity('HelperTestTag.HelperTestTag');
$result = $this->Helper->value('HelperTestTag.HelperTestTag');
$this->assertEqual($result, array(2, 3, 4));
$this->Helper->request->data = array(
'HelperTestTag' => array(
array('id' => 3),
array('id' => 5)
)
);
$this->Helper->setEntity('HelperTestTag.HelperTestTag');
$result = $this->Helper->value('HelperTestTag.HelperTestTag');
$this->assertEqual($result, array(3 => 3, 5 => 5));
$this->Helper->request->data = array(
'HelperTestTag' => array(
'body' => '',
'title' => 'winning'
),
);
$this->Helper->setEntity('HelperTestTag.body');
$result = $this->Helper->value('HelperTestTag.body');
$this->assertEqual($result, '');
}
/**
* Ensure HTML escaping of url params. So link addresses are valid and not exploited
*
* @return void
*/
public function testUrlConversion() {
$result = $this->Helper->url('/controller/action/1');
$this->assertEqual($result, '/controller/action/1');
$result = $this->Helper->url('/controller/action/1?one=1&two=2');
$this->assertEqual($result, '/controller/action/1?one=1&two=2');
$result = $this->Helper->url(array('controller' => 'posts', 'action' => 'index', 'page' => '1" onclick="alert(\'XSS\');"'));
$this->assertEqual($result, "/posts/index/page:1" onclick="alert('XSS');"");
$result = $this->Helper->url('/controller/action/1/param:this+one+more');
$this->assertEqual($result, '/controller/action/1/param:this+one+more');
$result = $this->Helper->url('/controller/action/1/param:this%20one%20more');
$this->assertEqual($result, '/controller/action/1/param:this%20one%20more');
$result = $this->Helper->url('/controller/action/1/param:%7Baround%20here%7D%5Bthings%5D%5Bare%5D%24%24');
$this->assertEqual($result, '/controller/action/1/param:%7Baround%20here%7D%5Bthings%5D%5Bare%5D%24%24');
$result = $this->Helper->url(array(
'controller' => 'posts', 'action' => 'index', 'param' => '%7Baround%20here%7D%5Bthings%5D%5Bare%5D%24%24'
));
$this->assertEqual($result, "/posts/index/param:%7Baround%20here%7D%5Bthings%5D%5Bare%5D%24%24");
$result = $this->Helper->url(array(
'controller' => 'posts', 'action' => 'index', 'page' => '1',
'?' => array('one' => 'value', 'two' => 'value', 'three' => 'purple')
));
$this->assertEqual($result, "/posts/index/page:1?one=value&two=value&three=purple");
}
/**
* test assetTimestamp application
*
* @return void
*/
public function testAssetTimestamp() {
$_timestamp = Configure::read('Asset.timestamp');
$_debug = Configure::read('debug');
Configure::write('Asset.timestamp', false);
$result = $this->Helper->assetTimestamp(CSS_URL . 'cake.generic.css');
$this->assertEqual($result, CSS_URL . 'cake.generic.css');
Configure::write('Asset.timestamp', true);
Configure::write('debug', 0);
$result = $this->Helper->assetTimestamp(CSS_URL . 'cake.generic.css');
$this->assertEqual($result, CSS_URL . 'cake.generic.css');
Configure::write('Asset.timestamp', true);
Configure::write('debug', 2);
$result = $this->Helper->assetTimestamp(CSS_URL . 'cake.generic.css');
$this->assertPattern('/' . preg_quote(CSS_URL . 'cake.generic.css?', '/') . '[0-9]+/', $result);
Configure::write('Asset.timestamp', 'force');
Configure::write('debug', 0);
$result = $this->Helper->assetTimestamp(CSS_URL . 'cake.generic.css');
$this->assertPattern('/' . preg_quote(CSS_URL . 'cake.generic.css?', '/') . '[0-9]+/', $result);
$result = $this->Helper->assetTimestamp(CSS_URL . 'cake.generic.css?someparam');
$this->assertEqual($result, CSS_URL . 'cake.generic.css?someparam');
$this->Helper->request->webroot = '/some/dir/';
$result = $this->Helper->assetTimestamp('/some/dir/' . CSS_URL . 'cake.generic.css');
$this->assertPattern('/' . preg_quote(CSS_URL . 'cake.generic.css?', '/') . '[0-9]+/', $result);
Configure::write('debug', $_debug);
Configure::write('Asset.timestamp', $_timestamp);
}
/**
* test assetTimestamp with plugins and themes
*
* @return void
*/
public function testAssetTimestampPluginsAndThemes() {
$_timestamp = Configure::read('Asset.timestamp');
Configure::write('Asset.timestamp', 'force');
App::build(array(
'plugins' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS),
'View' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'View' . DS),
));
CakePlugin::loadAll();
$result = $this->Helper->assetTimestamp('/test_plugin/css/test_plugin_asset.css');
$this->assertPattern('#/test_plugin/css/test_plugin_asset.css\?[0-9]+$#', $result, 'Missing timestamp plugin');
$result = $this->Helper->assetTimestamp('/test_plugin/css/i_dont_exist.css');
$this->assertPattern('#/test_plugin/css/i_dont_exist.css\?$#', $result, 'No error on missing file');
$result = $this->Helper->assetTimestamp('/theme/test_theme/js/theme.js');
$this->assertPattern('#/theme/test_theme/js/theme.js\?[0-9]+$#', $result, 'Missing timestamp theme');
$result = $this->Helper->assetTimestamp('/theme/test_theme/js/non_existant.js');
$this->assertPattern('#/theme/test_theme/js/non_existant.js\?$#', $result, 'No error on missing file');
App::build();
Configure::write('Asset.timestamp', $_timestamp);
}
/**
* testFieldsWithSameName method
*
* @return void
*/
public function testFieldsWithSameName() {
$this->Helper->setEntity('HelperTestTag', true);
$this->Helper->setEntity('HelperTestTag.id');
$expected = array('HelperTestTag', 'id');
$this->assertEquals($expected, $this->Helper->entity());
$this->Helper->setEntity('My.id');
$expected = array('My', 'id');
$this->assertEquals($expected, $this->Helper->entity());
$this->Helper->setEntity('MyOther.id');
$expected = array('MyOther', 'id');
$this->assertEquals($expected, $this->Helper->entity());
}
/**
* testFieldSameAsModel method
*
* @return void
*/
public function testFieldSameAsModel() {
$this->Helper->setEntity('HelperTestTag', true);
$this->Helper->setEntity('helper_test_post');
$expected = array('HelperTestTag', 'helper_test_post');
$this->assertEquals($expected, $this->Helper->entity());
$this->Helper->setEntity('HelperTestTag');
$expected = array('HelperTestTag', 'HelperTestTag');
$this->assertEquals($expected, $this->Helper->entity());
}
/**
* testFieldSuffixForDate method
*
* @return void
*/
public function testFieldSuffixForDate() {
$this->Helper->setEntity('HelperTestPost', true);
$expected = array('HelperTestPost');
$this->assertEquals($expected, $this->Helper->entity());
foreach (array('year', 'month', 'day', 'hour', 'min', 'meridian') as $d) {
$this->Helper->setEntity('date.' . $d);
$expected = array('HelperTestPost', 'date', $d);
$this->assertEquals($expected, $this->Helper->entity());
}
}
/**
* testMulitDimensionValue method
*
* @return void
*/
public function testMultiDimensionValue() {
$this->Helper->data = array();
for ($i = 0; $i < 2; $i++) {
$this->Helper->request->data['Model'][$i] = 'what';
$result[] = $this->Helper->value("Model.{$i}");
$this->Helper->request->data['Model'][$i] = array();
for ($j = 0; $j < 2; $j++) {
$this->Helper->request->data['Model'][$i][$j] = 'how';
$result[] = $this->Helper->value("Model.{$i}.{$j}");
}
}
$expected = array('what', 'how', 'how', 'what', 'how', 'how');
$this->assertEqual($expected, $result);
$this->Helper->request->data['HelperTestComment']['5']['id'] = 'ok';
$result = $this->Helper->value('HelperTestComment.5.id');
$this->assertEqual($result, 'ok');
$this->Helper->setEntity('HelperTestPost', true);
$this->Helper->request->data['HelperTestPost']['5']['created']['month'] = '10';
$result = $this->Helper->value('5.created.month');
$this->assertEqual($result, 10);
$this->Helper->request->data['HelperTestPost']['0']['id'] = 100;
$result = $this->Helper->value('HelperTestPost.0.id');
$this->assertEqual($result, 100);
}
/**
* testClean method
*
* @return void
*/
public function testClean() {
$result = $this->Helper->clean(array());
$this->assertEqual($result, null);
$result = $this->Helper->clean(array('<script>with something</script>', '<applet>something else</applet>'));
$this->assertEqual($result, array('with something', 'something else'));
$result = $this->Helper->clean('<script>with something</script>');
$this->assertEqual($result, 'with something');
$result = $this->Helper->clean('<script type="text/javascript">alert("ruined");</script>');
$this->assertNoPattern('#</*script#', $result);
$result = $this->Helper->clean("<script \ntype=\"text/javascript\">\n\talert('ruined');\n\n\t\t</script>");
$this->assertNoPattern('#</*script#', $result);
$result = $this->Helper->clean('<body/onload=do(/something/)>');
$this->assertEqual($result, '<body/>');
$result = $this->Helper->clean('<script>alert(document.cookie)</script>');
$this->assertEqual($result, '&lt;script&gt;alert(document.cookie)&lt;/script&gt;');
}
/**
* testMultiDimensionalField method
*
* @return void
*/
public function testMultiDimensionalField() {
$this->Helper->setEntity('HelperTestPost', true);
$entity = 'HelperTestPost.2.HelperTestComment.1.title';
$this->Helper->setEntity($entity);
$expected = array(
'HelperTestPost', '2', 'HelperTestComment', '1', 'title'
);
$this->assertEquals($expected, $this->Helper->entity());
$entity = 'HelperTestPost.1.HelperTestComment.1.HelperTestTag.1.created';
$this->Helper->setEntity($entity);
$expected = array(
'HelperTestPost', '1', 'HelperTestComment', '1',
'HelperTestTag', '1', 'created'
);
$this->assertEquals($expected, $this->Helper->entity());
$entity = 'HelperTestPost.0.HelperTestComment.1.HelperTestTag.1.fake';
$expected = array(
'HelperTestPost', '0', 'HelperTestComment', '1',
'HelperTestTag', '1', 'fake'
);
$this->Helper->setEntity($entity);
$entity = '1.HelperTestComment.1.HelperTestTag.created.year';
$this->Helper->setEntity($entity);
$this->Helper->request->data['HelperTestPost'][2]['HelperTestComment'][1]['title'] = 'My Title';
$result = $this->Helper->value('HelperTestPost.2.HelperTestComment.1.title');
$this->assertEquals('My Title', $result);
$this->Helper->request->data['HelperTestPost'][2]['HelperTestComment'][1]['created']['year'] = 2008;
$result = $this->Helper->value('HelperTestPost.2.HelperTestComment.1.created.year');
$this->assertEquals(2008, $result);
$this->Helper->request->data[2]['HelperTestComment'][1]['created']['year'] = 2008;
$result = $this->Helper->value('HelperTestPost.2.HelperTestComment.1.created.year');
$this->assertEquals(2008, $result);
$this->Helper->request->data['HelperTestPost']['title'] = 'My Title';
$result = $this->Helper->value('title');
$this->assertEquals('My Title', $result);
$this->Helper->request->data['My']['title'] = 'My Title';
$result = $this->Helper->value('My.title');
$this->assertEqual($result,'My Title');
}
public function testWebrootPaths() {
$this->Helper->request->webroot = '/';
$result = $this->Helper->webroot('/img/cake.power.gif');
$expected = '/img/cake.power.gif';
$this->assertEqual($expected, $result);
$this->Helper->theme = 'test_theme';
App::build(array(
'View' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'View'. DS)
));
$result = $this->Helper->webroot('/img/cake.power.gif');
$expected = '/theme/test_theme/img/cake.power.gif';
$this->assertEqual($expected, $result);
$result = $this->Helper->webroot('/img/test.jpg');
$expected = '/theme/test_theme/img/test.jpg';
$this->assertEqual($expected, $result);
$webRoot = Configure::read('App.www_root');
Configure::write('App.www_root', CAKE . 'Test' . DS . 'test_app' . DS . 'webroot' . DS);
$result = $this->Helper->webroot('/img/cake.power.gif');
$expected = '/theme/test_theme/img/cake.power.gif';
$this->assertEqual($expected, $result);
$result = $this->Helper->webroot('/img/test.jpg');
$expected = '/theme/test_theme/img/test.jpg';
$this->assertEqual($expected, $result);
$result = $this->Helper->webroot('/img/cake.icon.gif');
$expected = '/img/cake.icon.gif';
$this->assertEqual($expected, $result);
$result = $this->Helper->webroot('/img/cake.icon.gif?some=param');
$expected = '/img/cake.icon.gif?some=param';
$this->assertEqual($expected, $result);
Configure::write('App.www_root', $webRoot);
}
/**
* test lazy loading helpers is seamless
*
* @return void
*/
public function testLazyLoadingHelpers() {
App::build(array(
'plugins' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS),
));
CakePlugin::loadAll();
$Helper = new TestHelper($this->View);
$this->assertInstanceOf('OtherHelperHelper', $Helper->OtherHelper);
$this->assertInstanceOf('HtmlHelper', $Helper->Html);
App::build();
}
/**
* test that a helpers Helper is not 'attached' to the collection
*
* @return void
*/
public function testThatHelperHelpersAreNotAttached() {
$Helper = new TestHelper($this->View);
$Helper->OtherHelper;
$result = $this->View->Helpers->enabled();
$expected = array();
$this->assertEquals($expected, $result, 'Helper helpers were attached to the collection.');
}
/**
* test that the lazy loader doesn't duplicate objects on each access.
*
* @return void
*/
public function testLazyLoadingUsesReferences() {
$Helper = new TestHelper($this->View);
$result1 = $Helper->Html;
$result2 = $Helper->Html;
$result1->testprop = 1;
$this->assertEquals($result1->testprop, $result2->testprop);
}
}
| 0001-bee | trunk/cakephp2/lib/Cake/Test/Case/View/HelperTest.php | PHP | gpl3 | 25,955 |
<?php
/**
* MediaViewTest file
*
* PHP 5
*
* CakePHP(tm) Tests <http://book.cakephp.org/view/1196/Testing>
* Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice
*
* @copyright Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://book.cakephp.org/view/1196/Testing CakePHP(tm) Tests
* @package Cake.Test.Case.View
* @since CakePHP(tm) v 1.2.0.4206
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
App::uses('Controller', 'Controller');
App::uses('MediaView', 'View');
App::uses('CakeResponse', 'Network');
/**
* MediaViewTest class
*
* @package Cake.Test.Case.View
*/
class MediaViewTest extends CakeTestCase {
/**
* setUp method
*
* @return void
*/
public function setUp() {
parent::setUp();
$controller = new Controller();
$this->MediaView = $this->getMock('MediaView', array('_isActive', '_clearBuffer', '_flushBuffer'));
$this->MediaView->response = $this->getMock('CakeResponse');
}
/**
* endTest method
*
* @return void
*/
public function tearDown() {
parent::tearDown();
unset($this->MediaView);
}
/**
* tests that rendering a file that does not exists throws an exception
*
* @expectedException NotFoundException
* @return void
*/
public function testRenderNotFound() {
$this->MediaView->viewVars = array(
'path' => '/some/missing/folder',
'id' => 'file.jpg'
);
$this->MediaView->render();
}
/**
* testRender method
*
* @return void
*/
public function testRender() {
$this->MediaView->viewVars = array(
'path' => CAKE . 'Test' . DS . 'test_app' . DS . 'Vendor' . DS .'css' . DS,
'id' => 'test_asset.css',
'extension' => 'css',
);
$this->MediaView->expects($this->exactly(2))
->method('_isActive')
->will($this->returnValue(true));
$this->MediaView->response->expects($this->exactly(1))
->method('type')
->with('css')
->will($this->returnArgument(0));
$this->MediaView->response->expects($this->at(1))
->method('header')
->with(array(
'Date' => gmdate('D, d M Y H:i:s', time()) . ' GMT',
'Expires' => '0',
'Cache-Control' => 'private, must-revalidate, post-check=0, pre-check=0',
'Pragma' => 'no-cache'
));
$this->MediaView->response->expects($this->at(2))
->method('header')
->with(array(
'Content-Length' => 31
));
$this->MediaView->response->expects($this->once())->method('send');
$this->MediaView->expects($this->once())->method('_clearBuffer');
$this->MediaView->expects($this->once())->method('_flushBuffer');
ob_start();
$result = $this->MediaView->render();
$output = ob_get_clean();
$this->assertEqual('this is the test asset css file', $output);
$this->assertTrue($result !== false);
}
/**
* testRenderWithUnknownFileTypeGeneric method
*
* @return void
*/
public function testRenderWithUnknownFileTypeGeneric() {
$currentUserAgent = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : null;
$_SERVER['HTTP_USER_AGENT'] = 'Some generic browser';
$this->MediaView->viewVars = array(
'path' => CAKE . 'Test' . DS . 'test_app' . DS . 'Config' . DS,
'id' => 'no_section.ini',
'extension' => 'ini',
);
$this->MediaView->expects($this->exactly(2))
->method('_isActive')
->will($this->returnValue(true));
$this->MediaView->response->expects($this->exactly(1))
->method('type')
->with('ini')
->will($this->returnValue(false));
$this->MediaView->response->expects($this->at(1))
->method('header')
->with(array(
'Date' => gmdate('D, d M Y H:i:s', time()) . ' GMT',
'Expires' => '0',
'Cache-Control' => 'private, must-revalidate, post-check=0, pre-check=0',
'Pragma' => 'no-cache'
));
$this->MediaView->response->expects($this->once())
->method('download')
->with('no_section.ini');
$this->MediaView->response->expects($this->at(3))
->method('header')
->with(array(
'Accept-Ranges' => 'bytes'
));
$this->MediaView->response->expects($this->at(4))
->method('header')
->with('Content-Length', 35);
$this->MediaView->response->expects($this->once())->method('send');
$this->MediaView->expects($this->once())->method('_clearBuffer');
$this->MediaView->expects($this->once())->method('_flushBuffer');
ob_start();
$result = $this->MediaView->render();
$output = ob_get_clean();
$this->assertEqual("some_key = some_value\nbool_key = 1\n", $output);
$this->assertTrue($result !== false);
if ($currentUserAgent !== null) {
$_SERVER['HTTP_USER_AGENT'] = $currentUserAgent;
}
}
/**
* testRenderWithUnknownFileTypeOpera method
*
* @return void
*/
public function testRenderWithUnknownFileTypeOpera() {
$currentUserAgent = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : null;
$_SERVER['HTTP_USER_AGENT'] = 'Opera/9.80 (Windows NT 6.0; U; en) Presto/2.8.99 Version/11.10';
$this->MediaView->viewVars = array(
'path' => CAKE . 'Test' . DS . 'test_app' . DS . 'Config' . DS,
'id' => 'no_section.ini',
'extension' => 'ini',
);
$this->MediaView->expects($this->exactly(2))
->method('_isActive')
->will($this->returnValue(true));
$this->MediaView->response->expects($this->at(0))
->method('type')
->with('ini')
->will($this->returnValue(false));
$this->MediaView->response->expects($this->at(1))
->method('header')
->with(array(
'Date' => gmdate('D, d M Y H:i:s', time()) . ' GMT',
'Expires' => '0',
'Cache-Control' => 'private, must-revalidate, post-check=0, pre-check=0',
'Pragma' => 'no-cache'
));
$this->MediaView->response->expects($this->at(2))
->method('type')
->with('application/octetstream')
->will($this->returnValue(false));
$this->MediaView->response->expects($this->once())
->method('download')
->with('no_section.ini');
$this->MediaView->response->expects($this->at(4))
->method('header')
->with(array(
'Accept-Ranges' => 'bytes'
));
$this->MediaView->response->expects($this->at(5))
->method('header')
->with('Content-Length', 35);
$this->MediaView->response->expects($this->once())->method('send');
$this->MediaView->expects($this->once())->method('_clearBuffer');
$this->MediaView->expects($this->once())->method('_flushBuffer');
ob_start();
$result = $this->MediaView->render();
$output = ob_get_clean();
$this->assertEqual("some_key = some_value\nbool_key = 1\n", $output);
$this->assertTrue($result !== false);
if ($currentUserAgent !== null) {
$_SERVER['HTTP_USER_AGENT'] = $currentUserAgent;
}
}
/**
* testRenderWithUnknownFileTypeIE method
*
* @return void
*/
public function testRenderWithUnknownFileTypeIE() {
$currentUserAgent = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : null;
$_SERVER['HTTP_USER_AGENT'] = 'Mozilla/5.0 (compatible; MSIE 8.0; Windows NT 5.2; Trident/4.0; Media Center PC 4.0; SLCC1; .NET CLR 3.0.04320)';
$this->MediaView->viewVars = array(
'path' => CAKE . 'Test' . DS . 'test_app' . DS . 'Config' . DS,
'id' => 'no_section.ini',
'extension' => 'ini',
);
$this->MediaView->expects($this->exactly(2))
->method('_isActive')
->will($this->returnValue(true));
$this->MediaView->response->expects($this->at(0))
->method('type')
->with('ini')
->will($this->returnValue(false));
$this->MediaView->response->expects($this->at(1))
->method('header')
->with(array(
'Date' => gmdate('D, d M Y H:i:s', time()) . ' GMT',
'Expires' => '0',
'Cache-Control' => 'private, must-revalidate, post-check=0, pre-check=0',
'Pragma' => 'no-cache'
));
$this->MediaView->response->expects($this->at(2))
->method('type')
->with('application/force-download')
->will($this->returnValue(false));
$this->MediaView->response->expects($this->once())
->method('download')
->with('no_section.ini');
$this->MediaView->response->expects($this->at(4))
->method('header')
->with(array(
'Accept-Ranges' => 'bytes'
));
$this->MediaView->response->expects($this->at(5))
->method('header')
->with('Content-Length', 35);
$this->MediaView->response->expects($this->once())->method('send');
$this->MediaView->expects($this->once())->method('_clearBuffer');
$this->MediaView->expects($this->once())->method('_flushBuffer');
ob_start();
$result = $this->MediaView->render();
$output = ob_get_clean();
$this->assertEqual("some_key = some_value\nbool_key = 1\n", $output);
$this->assertTrue($result !== false);
if ($currentUserAgent !== null) {
$_SERVER['HTTP_USER_AGENT'] = $currentUserAgent;
}
}
/**
* testConnectionAborted method
*
* @return void
*/
public function testConnectionAborted() {
$this->MediaView->viewVars = array(
'path' => CAKE . 'Test' . DS . 'test_app' . DS . 'Vendor' . DS .'css' . DS,
'id' => 'test_asset.css',
'extension' => 'css',
);
$this->MediaView->expects($this->once())
->method('_isActive')
->will($this->returnValue(false));
$this->MediaView->response->expects($this->never())
->method('type');
$result = $this->MediaView->render();
$this->assertFalse($result);
}
/**
* testConnectionAbortedOnBuffering method
*
* @return void
*/
public function testConnectionAbortedOnBuffering() {
$this->MediaView->viewVars = array(
'path' => CAKE . 'Test' . DS . 'test_app' . DS . 'Vendor' . DS .'css' . DS,
'id' => 'test_asset.css',
'extension' => 'css',
);
$this->MediaView->expects($this->at(0))
->method('_isActive')
->will($this->returnValue(true));
$this->MediaView->response->expects($this->any())
->method('type')
->with('css')
->will($this->returnArgument(0));
$this->MediaView->expects($this->at(1))
->method('_isActive')
->will($this->returnValue(false));
$this->MediaView->response->expects($this->once())->method('send');
$this->MediaView->expects($this->once())->method('_clearBuffer');
$this->MediaView->expects($this->never())->method('_flushBuffer');
$result = $this->MediaView->render();
$this->assertFalse($result);
}
/**
* Test downloading files with UPPERCASE extensions.
*
* @return void
*/
function testRenderUpperExtesnion() {
$this->MediaView->viewVars = array(
'path' => CAKE . 'Test' . DS . 'test_app' . DS . 'Vendor' . DS .'img' . DS,
'id' => 'test_2.JPG',
'extension' => 'JPG',
);
$this->MediaView->response->expects($this->any())
->method('type')
->with('jpg')
->will($this->returnArgument(0));
$this->MediaView->expects($this->at(0))
->method('_isActive')
->will($this->returnValue(true));
$this->MediaView->render();
}
}
| 0001-bee | trunk/cakephp2/lib/Cake/Test/Case/View/MediaViewTest.php | PHP | gpl3 | 10,792 |
<?php
/**
* HelperCollectionTest file
*
* PHP 5
*
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
* Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://book.cakephp.org/view/1196/Testing CakePHP(tm) Tests
* @package Cake.Test.Case.View
* @since CakePHP(tm) v 2.0
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
App::uses('HelperCollection', 'View');
App::uses('HtmlHelper', 'View/Helper');
App::uses('View', 'View');
/**
* Extended HtmlHelper
*/
class HtmlAliasHelper extends HtmlHelper {
}
class HelperCollectionTest extends CakeTestCase {
/**
* setup
*
* @return void
*/
public function setup() {
$this->View = $this->getMock('View', array(), array(null));
$this->Helpers = new HelperCollection($this->View);
}
/**
* teardown
*
* @return void
*/
public function teardown() {
CakePlugin::unload();
unset($this->Helpers, $this->View);
}
/**
* test triggering callbacks on loaded helpers
*
* @return void
*/
public function testLoad() {
$result = $this->Helpers->load('Html');
$this->assertInstanceOf('HtmlHelper', $result);
$this->assertInstanceOf('HtmlHelper', $this->Helpers->Html);
$result = $this->Helpers->attached();
$this->assertEquals(array('Html'), $result, 'attached() results are wrong.');
$this->assertTrue($this->Helpers->enabled('Html'));
}
/**
* Tests loading as an alias
*
* @return void
*/
public function testLoadWithAlias() {
$result = $this->Helpers->load('Html', array('className' => 'HtmlAlias'));
$this->assertInstanceOf('HtmlAliasHelper', $result);
$this->assertInstanceOf('HtmlAliasHelper', $this->Helpers->Html);
$result = $this->Helpers->attached();
$this->assertEquals(array('Html'), $result, 'attached() results are wrong.');
$this->assertTrue($this->Helpers->enabled('Html'));
$result = $this->Helpers->load('Html');
$this->assertInstanceOf('HtmlAliasHelper', $result);
App::build(array('plugins' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS)));
CakePlugin::loadAll();
$result = $this->Helpers->load('SomeOther', array('className' => 'TestPlugin.OtherHelper'));
$this->assertInstanceOf('OtherHelperHelper', $result);
$this->assertInstanceOf('OtherHelperHelper', $this->Helpers->SomeOther);
$result = $this->Helpers->attached();
$this->assertEquals(array('Html', 'SomeOther'), $result, 'attached() results are wrong.');
App::build();
}
/**
* test that the enabled setting disables the helper.
*
* @return void
*/
public function testLoadWithEnabledFalse() {
$result = $this->Helpers->load('Html', array('enabled' => false));
$this->assertInstanceOf('HtmlHelper', $result);
$this->assertInstanceOf('HtmlHelper', $this->Helpers->Html);
$this->assertFalse($this->Helpers->enabled('Html'), 'Html should be disabled');
}
/**
* test missinghelper exception
*
* @expectedException MissingHelperException
* @return void
*/
public function testLoadMissingHelper() {
$result = $this->Helpers->load('ThisHelperShouldAlwaysBeMissing');
}
/**
* test loading a plugin helper.
*
* @return void
*/
public function testLoadPluginHelper() {
App::build(array(
'plugins' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS),
));
CakePlugin::loadAll();
$result = $this->Helpers->load('TestPlugin.OtherHelper');
$this->assertInstanceOf('OtherHelperHelper', $result, 'Helper class is wrong.');
$this->assertInstanceOf('OtherHelperHelper', $this->Helpers->OtherHelper, 'Class is wrong');
App::build();
}
/**
* test unload()
*
* @return void
*/
public function testUnload() {
$this->Helpers->load('Form');
$this->Helpers->load('Html');
$result = $this->Helpers->attached();
$this->assertEquals(array('Form', 'Html'), $result, 'loaded helpers is wrong');
$this->Helpers->unload('Html');
$this->assertFalse(isset($this->Helpers->Html));
$this->assertTrue(isset($this->Helpers->Form));
$result = $this->Helpers->attached();
$this->assertEquals(array('Form'), $result, 'loaded helpers is wrong');
}
}
| 0001-bee | trunk/cakephp2/lib/Cake/Test/Case/View/HelperCollectionTest.php | PHP | gpl3 | 4,336 |
<?php
/**
* HtmlHelperTest file
*
* PHP 5
*
* CakePHP(tm) Tests <http://book.cakephp.org/view/1196/Testing>
* Copyright 2005-2011, Cake Software Foundation, Inc.
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice
*
* @copyright Copyright 2005-2011, Cake Software Foundation, Inc.
* @link http://book.cakephp.org/view/1196/Testing CakePHP(tm) Tests
* @package Cake.Test.Case.View.Helper
* @since CakePHP(tm) v 1.2.0.4206
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
App::uses('Controller', 'Controller');
App::uses('Helper', 'View');
App::uses('AppHelper', 'View/Helper');
App::uses('HtmlHelper', 'View/Helper');
App::uses('FormHelper', 'View/Helper');
App::uses('ClassRegistry', 'Utility');
App::uses('Folder', 'Utility');
if (!defined('FULL_BASE_URL')) {
define('FULL_BASE_URL', 'http://cakephp.org');
}
/**
* TheHtmlTestController class
*
* @package Cake.Test.Case.View.Helper
*/
class TheHtmlTestController extends Controller {
/**
* name property
*
* @var string 'TheTest'
*/
public $name = 'TheTest';
/**
* uses property
*
* @var mixed null
*/
public $uses = null;
}
class TestHtmlHelper extends HtmlHelper {
/**
* expose a method as public
*
* @param string $options
* @param string $exclude
* @param string $insertBefore
* @param string $insertAfter
* @return void
*/
public function parseAttributes($options, $exclude = null, $insertBefore = ' ', $insertAfter = null) {
return $this->_parseAttributes($options, $exclude, $insertBefore, $insertAfter);
}
/**
* Get a protected attribute value
*
* @param string $attribute
* @return mixed
*/
public function getAttribute($attribute) {
if (!isset($this->{$attribute})) {
return null;
}
return $this->{$attribute};
}
}
/**
* Html5TestHelper class
*
* @package Cake.Test.Case.View.Helper
*/
class Html5TestHelper extends TestHtmlHelper {
/**
* Minimized
*
* @var array
*/
protected $_minimizedAttributes = array('require', 'checked');
/**
* Allow compact use in HTML
*
* @var string
*/
protected $_minimizedAttributeFormat = '%s';
/**
* Test to attribute format
*
* @var string
*/
protected $_attributeFormat = 'data-%s="%s"';
}
/**
* HtmlHelperTest class
*
* @package Cake.Test.Case.View.Helper
*/
class HtmlHelperTest extends CakeTestCase {
/**
* Regexp for CDATA start block
*
* @var string
*/
public $cDataStart = 'preg:/^\/\/<!\[CDATA\[[\n\r]*/';
/**
* Regexp for CDATA end block
*
* @var string
*/
public $cDataEnd = 'preg:/[^\]]*\]\]\>[\s\r\n]*/';
/**
* html property
*
* @var object
*/
public $Html = null;
/**
* setUp method
*
* @return void
*/
public function setUp() {
parent::setUp();
$this->View = $this->getMock('View', array('addScript'), array(new TheHtmlTestController()));
$this->Html = new TestHtmlHelper($this->View);
$this->Html->request = new CakeRequest(null, false);
$this->Html->request->webroot = '';
Configure::write('Asset.timestamp', false);
}
/**
* tearDown method
*
* @return void
*/
public function tearDown() {
parent::tearDown();
unset($this->Html, $this->View);
}
/**
* testDocType method
*
* @return void
*/
public function testDocType() {
$result = $this->Html->docType();
$expected = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">';
$this->assertEqual($expected, $result);
$result = $this->Html->docType('html4-strict');
$expected = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">';
$this->assertEqual($expected, $result);
$this->assertNull($this->Html->docType('non-existing-doctype'));
}
/**
* testLink method
*
* @return void
*/
public function testLink() {
$this->Html->request->webroot = '';
$result = $this->Html->link('/home');
$expected = array('a' => array('href' => '/home'), 'preg:/\/home/', '/a');
$this->assertTags($result, $expected);
$result = $this->Html->link('Posts', array('controller' => 'posts', 'action' => 'index', 'full_base' => true));
$expected = array('a' => array('href' => FULL_BASE_URL . '/posts'), 'Posts', '/a');
$this->assertTags($result, $expected);
$result = $this->Html->link('Home', '/home', array('confirm' => 'Are you sure you want to do this?'));
$expected = array(
'a' => array('href' => '/home', 'onclick' => 'return confirm('Are you sure you want to do this?');'),
'Home',
'/a'
);
$this->assertTags($result, $expected);
$result = $this->Html->link('Home', '/home', array('default' => false));
$expected = array(
'a' => array('href' => '/home', 'onclick' => 'event.returnValue = false; return false;'),
'Home',
'/a'
);
$this->assertTags($result, $expected);
$result = $this->Html->link('Home', '/home', array('default' => false, 'onclick' => 'someFunction();'));
$expected = array(
'a' => array('href' => '/home', 'onclick' => 'someFunction(); event.returnValue = false; return false;'),
'Home',
'/a'
);
$this->assertTags($result, $expected);
$result = $this->Html->link('Next >', '#');
$expected = array(
'a' => array('href' => '#'),
'Next >',
'/a'
);
$this->assertTags($result, $expected);
$result = $this->Html->link('Next >', '#', array('escape' => true));
$expected = array(
'a' => array('href' => '#'),
'Next >',
'/a'
);
$this->assertTags($result, $expected);
$result = $this->Html->link('Next >', '#', array('escape' => 'utf-8'));
$expected = array(
'a' => array('href' => '#'),
'Next >',
'/a'
);
$this->assertTags($result, $expected);
$result = $this->Html->link('Next >', '#', array('escape' => false));
$expected = array(
'a' => array('href' => '#'),
'Next >',
'/a'
);
$this->assertTags($result, $expected);
$result = $this->Html->link('Next >', '#', array(
'title' => 'to escape … or not escape?',
'escape' => false
));
$expected = array(
'a' => array('href' => '#', 'title' => 'to escape … or not escape?'),
'Next >',
'/a'
);
$this->assertTags($result, $expected);
$result = $this->Html->link('Next >', '#', array(
'title' => 'to escape … or not escape?',
'escape' => true
));
$expected = array(
'a' => array('href' => '#', 'title' => 'to escape &#8230; or not escape?'),
'Next >',
'/a'
);
$this->assertTags($result, $expected);
$result = $this->Html->link('Original size', array(
'controller' => 'images', 'action' => 'view', 3, '?' => array('height' => 100, 'width' => 200)
));
$expected = array(
'a' => array('href' => '/images/view/3?height=100&width=200'),
'Original size',
'/a'
);
$this->assertTags($result, $expected);
Configure::write('Asset.timestamp', false);
$result = $this->Html->link($this->Html->image('test.gif'), '#', array('escape' => false));
$expected = array(
'a' => array('href' => '#'),
'img' => array('src' => 'img/test.gif', 'alt' => ''),
'/a'
);
$this->assertTags($result, $expected);
$result = $this->Html->image('test.gif', array('url' => '#'));
$expected = array(
'a' => array('href' => '#'),
'img' => array('src' => 'img/test.gif', 'alt' => ''),
'/a'
);
$this->assertTags($result, $expected);
Configure::write('Asset.timestamp', 'force');
$result = $this->Html->link($this->Html->image('../favicon.ico'), '#', array('escape' => false));
$expected = array(
'a' => array('href' => '#'),
'img' => array('src' => 'preg:/img\/..\/favicon\.ico\?\d*/', 'alt' => ''),
'/a'
);
$this->assertTags($result, $expected);
$result = $this->Html->image('../favicon.ico', array('url' => '#'));
$expected = array(
'a' => array('href' => '#'),
'img' => array('src' => 'preg:/img\/..\/favicon\.ico\?\d*/', 'alt' => ''),
'/a'
);
$this->assertTags($result, $expected);
}
/**
* testImageTag method
*
* @return void
*/
public function testImageTag() {
$this->Html->request->webroot = '';
$result = $this->Html->image('test.gif');
$this->assertTags($result, array('img' => array('src' => 'img/test.gif', 'alt' => '')));
$result = $this->Html->image('http://google.com/logo.gif');
$this->assertTags($result, array('img' => array('src' => 'http://google.com/logo.gif', 'alt' => '')));
$result = $this->Html->image(array('controller' => 'test', 'action' => 'view', 1, 'ext' => 'gif'));
$this->assertTags($result, array('img' => array('src' => '/test/view/1.gif', 'alt' => '')));
$result = $this->Html->image('/test/view/1.gif');
$this->assertTags($result, array('img' => array('src' => '/test/view/1.gif', 'alt' => '')));
}
/**
* test image() with Asset.timestamp
*
* @return void
*/
public function testImageWithTimestampping() {
Configure::write('Asset.timestamp', 'force');
$this->Html->request->webroot = '/';
$result = $this->Html->image('cake.icon.png');
$this->assertTags($result, array('img' => array('src' => 'preg:/\/img\/cake\.icon\.png\?\d+/', 'alt' => '')));
Configure::write('debug', 0);
Configure::write('Asset.timestamp', 'force');
$result = $this->Html->image('cake.icon.png');
$this->assertTags($result, array('img' => array('src' => 'preg:/\/img\/cake\.icon\.png\?\d+/', 'alt' => '')));
$this->Html->request->webroot = '/testing/longer/';
$result = $this->Html->image('cake.icon.png');
$expected = array(
'img' => array('src' => 'preg:/\/testing\/longer\/img\/cake\.icon\.png\?[0-9]+/', 'alt' => '')
);
$this->assertTags($result, $expected);
}
/**
* Tests creation of an image tag using a theme and asset timestamping
*
* @return void
*/
public function testImageTagWithTheme() {
$this->skipIf(!is_writable(WWW_ROOT . 'theme'), 'Cannot write to webroot/theme.');
App::uses('File', 'Utility');
$testfile = WWW_ROOT . 'theme' . DS . 'test_theme' . DS . 'img' . DS . '__cake_test_image.gif';
$file = new File($testfile, true);
App::build(array(
'views' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'View'. DS)
));
Configure::write('Asset.timestamp', true);
Configure::write('debug', 1);
$this->Html->request->webroot = '/';
$this->Html->theme = 'test_theme';
$result = $this->Html->image('__cake_test_image.gif');
$this->assertTags($result, array(
'img' => array(
'src' => 'preg:/\/theme\/test_theme\/img\/__cake_test_image\.gif\?\d+/',
'alt' => ''
)));
$this->Html->request->webroot = '/testing/';
$result = $this->Html->image('__cake_test_image.gif');
$this->assertTags($result, array(
'img' => array(
'src' => 'preg:/\/testing\/theme\/test_theme\/img\/__cake_test_image\.gif\?\d+/',
'alt' => ''
)));
$dir = new Folder(WWW_ROOT . 'theme' . DS . 'test_theme');
$dir->delete();
}
/**
* test theme assets in main webroot path
*
* @return void
*/
public function testThemeAssetsInMainWebrootPath() {
App::build(array(
'views' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'View'. DS)
));
$webRoot = Configure::read('App.www_root');
Configure::write('App.www_root', CAKE . 'Test' . DS . 'test_app' . DS . 'webroot' . DS);
$this->Html->theme = 'test_theme';
$result = $this->Html->css('webroot_test');
$expected = array(
'link' => array('rel' => 'stylesheet', 'type' => 'text/css', 'href' => 'preg:/.*theme\/test_theme\/css\/webroot_test\.css/')
);
$this->assertTags($result, $expected);
$this->Html->theme = 'test_theme';
$result = $this->Html->css('theme_webroot');
$expected = array(
'link' => array('rel' => 'stylesheet', 'type' => 'text/css', 'href' => 'preg:/.*theme\/test_theme\/css\/theme_webroot\.css/')
);
$this->assertTags($result, $expected);
Configure::write('App.www_root', $webRoot);
}
/**
* testStyle method
*
* @return void
*/
public function testStyle() {
$result = $this->Html->style('display: none;');
$this->assertEqual($result, 'display: none;');
$result = $this->Html->style(array('display'=> 'none', 'margin'=>'10px'));
$expected = 'display:none; margin:10px;';
$this->assertPattern('/^display\s*:\s*none\s*;\s*margin\s*:\s*10px\s*;?$/', $expected);
$result = $this->Html->style(array('display'=> 'none', 'margin'=>'10px'), false);
$lines = explode("\n", $result);
$this->assertPattern('/^\s*display\s*:\s*none\s*;\s*$/', $lines[0]);
$this->assertPattern('/^\s*margin\s*:\s*10px\s*;?$/', $lines[1]);
}
/**
* testCssLink method
*
* @return void
*/
public function testCssLink() {
Configure::write('Asset.filter.css', false);
$result = $this->Html->css('screen');
$expected = array(
'link' => array('rel' => 'stylesheet', 'type' => 'text/css', 'href' => 'preg:/.*css\/screen\.css/')
);
$this->assertTags($result, $expected);
$result = $this->Html->css('screen.css');
$this->assertTags($result, $expected);
$result = $this->Html->css('my.css.library');
$expected['link']['href'] = 'preg:/.*css\/my\.css\.library\.css/';
$this->assertTags($result, $expected);
$result = $this->Html->css('screen.css?1234');
$expected['link']['href'] = 'preg:/.*css\/screen\.css\?1234/';
$this->assertTags($result, $expected);
$result = $this->Html->css('http://whatever.com/screen.css?1234');
$expected['link']['href'] = 'preg:/http:\/\/.*\/screen\.css\?1234/';
$this->assertTags($result, $expected);
Configure::write('Asset.filter.css', 'css.php');
$result = $this->Html->css('cake.generic');
$expected['link']['href'] = 'preg:/.*ccss\/cake\.generic\.css/';
$this->assertTags($result, $expected);
Configure::write('Asset.filter.css', false);
$result = explode("\n", trim($this->Html->css(array('cake.generic', 'vendor.generic'))));
$expected['link']['href'] = 'preg:/.*css\/cake\.generic\.css/';
$this->assertTags($result[0], $expected);
$expected['link']['href'] = 'preg:/.*css\/vendor\.generic\.css/';
$this->assertTags($result[1], $expected);
$this->assertEqual(count($result), 2);
$this->View->expects($this->at(0))->method('addScript')
->with($this->matchesRegularExpression('/css_in_head.css/'));
$this->View->expects($this->at(1))
->method('addScript')
->with($this->matchesRegularExpression('/more_css_in_head.css/'));
$result = $this->Html->css('css_in_head', null, array('inline' => false));
$this->assertNull($result);
$result = $this->Html->css('more_css_in_head', null, array('inline' => false));
$this->assertNull($result);
}
/**
* test use of css() and timestamping
*
* @return void
*/
public function testCssTimestamping() {
Configure::write('debug', 2);
Configure::write('Asset.timestamp', true);
$expected = array(
'link' => array('rel' => 'stylesheet', 'type' => 'text/css', 'href' => '')
);
$result = $this->Html->css('cake.generic');
$expected['link']['href'] = 'preg:/.*css\/cake\.generic\.css\?[0-9]+/';
$this->assertTags($result, $expected);
Configure::write('debug', 0);
$result = $this->Html->css('cake.generic');
$expected['link']['href'] = 'preg:/.*css\/cake\.generic\.css/';
$this->assertTags($result, $expected);
Configure::write('Asset.timestamp', 'force');
$result = $this->Html->css('cake.generic');
$expected['link']['href'] = 'preg:/.*css\/cake\.generic\.css\?[0-9]+/';
$this->assertTags($result, $expected);
$this->Html->request->webroot = '/testing/';
$result = $this->Html->css('cake.generic');
$expected['link']['href'] = 'preg:/\/testing\/css\/cake\.generic\.css\?[0-9]+/';
$this->assertTags($result, $expected);
$this->Html->request->webroot = '/testing/longer/';
$result = $this->Html->css('cake.generic');
$expected['link']['href'] = 'preg:/\/testing\/longer\/css\/cake\.generic\.css\?[0-9]+/';
$this->assertTags($result, $expected);
}
/**
* test timestamp enforcement for script tags.
*
* @return void
*/
public function testScriptTimestamping() {
$this->skipIf(!is_writable(JS), 'webroot/js is not Writable, timestamp testing has been skipped.');
Configure::write('debug', 2);
Configure::write('Asset.timestamp', true);
touch(WWW_ROOT . 'js' . DS. '__cake_js_test.js');
$timestamp = substr(strtotime('now'), 0, 8);
$result = $this->Html->script('__cake_js_test', array('inline' => true, 'once' => false));
$this->assertPattern('/__cake_js_test.js\?' . $timestamp . '[0-9]{2}"/', $result, 'Timestamp value not found %s');
Configure::write('debug', 0);
Configure::write('Asset.timestamp', 'force');
$result = $this->Html->script('__cake_js_test', array('inline' => true, 'once' => false));
$this->assertPattern('/__cake_js_test.js\?' . $timestamp . '[0-9]{2}"/', $result, 'Timestamp value not found %s');
unlink(WWW_ROOT . 'js' . DS. '__cake_js_test.js');
Configure::write('Asset.timestamp', false);
}
/**
* test that scripts added with uses() are only ever included once.
* test script tag generation
*
* @return void
*/
public function testScript() {
$result = $this->Html->script('foo');
$expected = array(
'script' => array('type' => 'text/javascript', 'src' => 'js/foo.js')
);
$this->assertTags($result, $expected);
$result = $this->Html->script(array('foobar', 'bar'));
$expected = array(
array('script' => array('type' => 'text/javascript', 'src' => 'js/foobar.js')),
'/script',
array('script' => array('type' => 'text/javascript', 'src' => 'js/bar.js')),
'/script',
);
$this->assertTags($result, $expected);
$result = $this->Html->script('jquery-1.3');
$expected = array(
'script' => array('type' => 'text/javascript', 'src' => 'js/jquery-1.3.js')
);
$this->assertTags($result, $expected);
$result = $this->Html->script('test.json');
$expected = array(
'script' => array('type' => 'text/javascript', 'src' => 'js/test.json.js')
);
$this->assertTags($result, $expected);
$result = $this->Html->script('http://example.com/test.json');
$expected = array(
'script' => array('type' => 'text/javascript', 'src' => 'http://example.com/test.json')
);
$this->assertTags($result, $expected);
$result = $this->Html->script('/plugin/js/jquery-1.3.2.js?someparam=foo');
$expected = array(
'script' => array('type' => 'text/javascript', 'src' => '/plugin/js/jquery-1.3.2.js?someparam=foo')
);
$this->assertTags($result, $expected);
$result = $this->Html->script('test.json.js?foo=bar');
$expected = array(
'script' => array('type' => 'text/javascript', 'src' => 'js/test.json.js?foo=bar')
);
$this->assertTags($result, $expected);
$result = $this->Html->script('foo');
$this->assertNull($result, 'Script returned upon duplicate inclusion %s');
$result = $this->Html->script(array('foo', 'bar', 'baz'));
$this->assertNoPattern('/foo.js/', $result);
$result = $this->Html->script('foo', array('inline' => true, 'once' => false));
$this->assertNotNull($result);
$result = $this->Html->script('jquery-1.3.2', array('defer' => true, 'encoding' => 'utf-8'));
$expected = array(
'script' => array('type' => 'text/javascript', 'src' => 'js/jquery-1.3.2.js', 'defer' => 'defer', 'encoding' => 'utf-8')
);
$this->assertTags($result, $expected);
$this->View->expects($this->any())->method('addScript')
->with($this->matchesRegularExpression('/script_in_head.js/'));
$result = $this->Html->script('script_in_head', array('inline' => false));
$this->assertNull($result);
}
/**
* test a script file in the webroot/theme dir.
*
* @return void
*/
public function testScriptInTheme() {
$this->skipIf(!is_writable(WWW_ROOT . 'theme'), 'Cannot write to webroot/theme.');
App::uses('File', 'Utility');
$testfile = WWW_ROOT . 'theme' . DS . 'test_theme' . DS . 'js' . DS . '__test_js.js';
$file = new File($testfile, true);
App::build(array(
'views' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'View'. DS)
));
$this->Html->webroot = '/';
$this->Html->theme = 'test_theme';
$result = $this->Html->script('__test_js.js');
$expected = array(
'script' => array('src' => '/theme/test_theme/js/__test_js.js', 'type' => 'text/javascript')
);
$this->assertTags($result, $expected);
$folder = new Folder(WWW_ROOT . 'theme' . DS . 'test_theme');
$folder->delete();
App::build();
}
/**
* test Script block generation
*
* @return void
*/
public function testScriptBlock() {
$result = $this->Html->scriptBlock('window.foo = 2;');
$expected = array(
'script' => array('type' => 'text/javascript'),
$this->cDataStart,
'window.foo = 2;',
$this->cDataEnd,
'/script',
);
$this->assertTags($result, $expected);
$result = $this->Html->scriptBlock('window.foo = 2;', array('safe' => false));
$expected = array(
'script' => array('type' => 'text/javascript'),
'window.foo = 2;',
'/script',
);
$this->assertTags($result, $expected);
$result = $this->Html->scriptBlock('window.foo = 2;', array('safe' => true));
$expected = array(
'script' => array('type' => 'text/javascript'),
$this->cDataStart,
'window.foo = 2;',
$this->cDataEnd,
'/script',
);
$this->assertTags($result, $expected);
$this->View->expects($this->any())->method('addScript')
->with($this->matchesRegularExpression('/window\.foo\s\=\s2;/'));
$result = $this->Html->scriptBlock('window.foo = 2;', array('inline' => false));
$this->assertNull($result);
$result = $this->Html->scriptBlock('window.foo = 2;', array('safe' => false, 'encoding' => 'utf-8'));
$expected = array(
'script' => array('type' => 'text/javascript', 'encoding' => 'utf-8'),
'window.foo = 2;',
'/script',
);
$this->assertTags($result, $expected);
}
/**
* test script tag output buffering when using scriptStart() and scriptEnd();
*
* @return void
*/
public function testScriptStartAndScriptEnd() {
$result = $this->Html->scriptStart(array('safe' => true));
$this->assertNull($result);
echo 'this is some javascript';
$result = $this->Html->scriptEnd();
$expected = array(
'script' => array('type' => 'text/javascript'),
$this->cDataStart,
'this is some javascript',
$this->cDataEnd,
'/script'
);
$this->assertTags($result, $expected);
$result = $this->Html->scriptStart(array('safe' => false));
$this->assertNull($result);
echo 'this is some javascript';
$result = $this->Html->scriptEnd();
$expected = array(
'script' => array('type' => 'text/javascript'),
'this is some javascript',
'/script'
);
$this->assertTags($result, $expected);
$this->View->expects($this->once())->method('addScript');
$result = $this->Html->scriptStart(array('safe' => false, 'inline' => false));
$this->assertNull($result);
echo 'this is some javascript';
$result = $this->Html->scriptEnd();
$this->assertNull($result);
}
/**
* testCharsetTag method
*
* @return void
*/
public function testCharsetTag() {
Configure::write('App.encoding', null);
$result = $this->Html->charset();
$this->assertTags($result, array('meta' => array('http-equiv' => 'Content-Type', 'content' => 'text/html; charset=utf-8')));
Configure::write('App.encoding', 'ISO-8859-1');
$result = $this->Html->charset();
$this->assertTags($result, array('meta' => array('http-equiv' => 'Content-Type', 'content' => 'text/html; charset=iso-8859-1')));
$result = $this->Html->charset('UTF-7');
$this->assertTags($result, array('meta' => array('http-equiv' => 'Content-Type', 'content' => 'text/html; charset=UTF-7')));
}
/**
* testBreadcrumb method
*
* @return void
*/
public function testBreadcrumb() {
$this->assertNull($this->Html->getCrumbs());
$this->Html->addCrumb('First', '#first');
$this->Html->addCrumb('Second', '#second');
$this->Html->addCrumb('Third', '#third');
$result = $this->Html->getCrumbs();
$expected = array(
array('a' => array('href' => '#first')),
'First',
'/a',
'»',
array('a' => array('href' => '#second')),
'Second',
'/a',
'»',
array('a' => array('href' => '#third')),
'Third',
'/a',
);
$this->assertTags($result, $expected);
$result = $this->Html->getCrumbs(' > ');
$expected = array(
array('a' => array('href' => '#first')),
'First',
'/a',
' > ',
array('a' => array('href' => '#second')),
'Second',
'/a',
' > ',
array('a' => array('href' => '#third')),
'Third',
'/a',
);
$this->assertTags($result, $expected);
$this->assertPattern('/^<a[^<>]+>First<\/a> > <a[^<>]+>Second<\/a> > <a[^<>]+>Third<\/a>$/', $result);
$this->assertPattern('/<a\s+href=["\']+\#first["\']+[^<>]*>First<\/a>/', $result);
$this->assertPattern('/<a\s+href=["\']+\#second["\']+[^<>]*>Second<\/a>/', $result);
$this->assertPattern('/<a\s+href=["\']+\#third["\']+[^<>]*>Third<\/a>/', $result);
$this->assertNoPattern('/<a[^<>]+[^href]=[^<>]*>/', $result);
$this->Html->addCrumb('Fourth', null);
$result = $this->Html->getCrumbs();
$expected = array(
array('a' => array('href' => '#first')),
'First',
'/a',
'»',
array('a' => array('href' => '#second')),
'Second',
'/a',
'»',
array('a' => array('href' => '#third')),
'Third',
'/a',
'»',
'Fourth'
);
$this->assertTags($result, $expected);
$result = $this->Html->getCrumbs('-', 'Start');
$expected = array(
array('a' => array('href' => '/')),
'Start',
'/a',
'-',
array('a' => array('href' => '#first')),
'First',
'/a',
'-',
array('a' => array('href' => '#second')),
'Second',
'/a',
'-',
array('a' => array('href' => '#third')),
'Third',
'/a',
'-',
'Fourth'
);
$this->assertTags($result, $expected);
}
/**
* testNestedList method
*
* @return void
*/
public function testNestedList() {
$list = array(
'Item 1',
'Item 2' => array(
'Item 2.1'
),
'Item 3',
'Item 4' => array(
'Item 4.1',
'Item 4.2',
'Item 4.3' => array(
'Item 4.3.1',
'Item 4.3.2'
)
),
'Item 5' => array(
'Item 5.1',
'Item 5.2'
)
);
$result = $this->Html->nestedList($list);
$expected = array(
'<ul',
'<li', 'Item 1', '/li',
'<li', 'Item 2',
'<ul', '<li', 'Item 2.1', '/li', '/ul',
'/li',
'<li', 'Item 3', '/li',
'<li', 'Item 4',
'<ul',
'<li', 'Item 4.1', '/li',
'<li', 'Item 4.2', '/li',
'<li', 'Item 4.3',
'<ul',
'<li', 'Item 4.3.1', '/li',
'<li', 'Item 4.3.2', '/li',
'/ul',
'/li',
'/ul',
'/li',
'<li', 'Item 5',
'<ul',
'<li', 'Item 5.1', '/li',
'<li', 'Item 5.2', '/li',
'/ul',
'/li',
'/ul'
);
$this->assertTags($result, $expected);
$result = $this->Html->nestedList($list, null);
$expected = array(
'<ul',
'<li', 'Item 1', '/li',
'<li', 'Item 2',
'<ul', '<li', 'Item 2.1', '/li', '/ul',
'/li',
'<li', 'Item 3', '/li',
'<li', 'Item 4',
'<ul',
'<li', 'Item 4.1', '/li',
'<li', 'Item 4.2', '/li',
'<li', 'Item 4.3',
'<ul',
'<li', 'Item 4.3.1', '/li',
'<li', 'Item 4.3.2', '/li',
'/ul',
'/li',
'/ul',
'/li',
'<li', 'Item 5',
'<ul',
'<li', 'Item 5.1', '/li',
'<li', 'Item 5.2', '/li',
'/ul',
'/li',
'/ul'
);
$this->assertTags($result, $expected);
$result = $this->Html->nestedList($list, array(), array(), 'ol');
$expected = array(
'<ol',
'<li', 'Item 1', '/li',
'<li', 'Item 2',
'<ol', '<li', 'Item 2.1', '/li', '/ol',
'/li',
'<li', 'Item 3', '/li',
'<li', 'Item 4',
'<ol',
'<li', 'Item 4.1', '/li',
'<li', 'Item 4.2', '/li',
'<li', 'Item 4.3',
'<ol',
'<li', 'Item 4.3.1', '/li',
'<li', 'Item 4.3.2', '/li',
'/ol',
'/li',
'/ol',
'/li',
'<li', 'Item 5',
'<ol',
'<li', 'Item 5.1', '/li',
'<li', 'Item 5.2', '/li',
'/ol',
'/li',
'/ol'
);
$this->assertTags($result, $expected);
$result = $this->Html->nestedList($list, 'ol');
$expected = array(
'<ol',
'<li', 'Item 1', '/li',
'<li', 'Item 2',
'<ol', '<li', 'Item 2.1', '/li', '/ol',
'/li',
'<li', 'Item 3', '/li',
'<li', 'Item 4',
'<ol',
'<li', 'Item 4.1', '/li',
'<li', 'Item 4.2', '/li',
'<li', 'Item 4.3',
'<ol',
'<li', 'Item 4.3.1', '/li',
'<li', 'Item 4.3.2', '/li',
'/ol',
'/li',
'/ol',
'/li',
'<li', 'Item 5',
'<ol',
'<li', 'Item 5.1', '/li',
'<li', 'Item 5.2', '/li',
'/ol',
'/li',
'/ol'
);
$this->assertTags($result, $expected);
$result = $this->Html->nestedList($list, array('class'=>'list'));
$expected = array(
array('ul' => array('class' => 'list')),
'<li', 'Item 1', '/li',
'<li', 'Item 2',
array('ul' => array('class' => 'list')), '<li', 'Item 2.1', '/li', '/ul',
'/li',
'<li', 'Item 3', '/li',
'<li', 'Item 4',
array('ul' => array('class' => 'list')),
'<li', 'Item 4.1', '/li',
'<li', 'Item 4.2', '/li',
'<li', 'Item 4.3',
array('ul' => array('class' => 'list')),
'<li', 'Item 4.3.1', '/li',
'<li', 'Item 4.3.2', '/li',
'/ul',
'/li',
'/ul',
'/li',
'<li', 'Item 5',
array('ul' => array('class' => 'list')),
'<li', 'Item 5.1', '/li',
'<li', 'Item 5.2', '/li',
'/ul',
'/li',
'/ul'
);
$this->assertTags($result, $expected);
$result = $this->Html->nestedList($list, array(), array('class' => 'item'));
$expected = array(
'<ul',
array('li' => array('class' => 'item')), 'Item 1', '/li',
array('li' => array('class' => 'item')), 'Item 2',
'<ul', array('li' => array('class' => 'item')), 'Item 2.1', '/li', '/ul',
'/li',
array('li' => array('class' => 'item')), 'Item 3', '/li',
array('li' => array('class' => 'item')), 'Item 4',
'<ul',
array('li' => array('class' => 'item')), 'Item 4.1', '/li',
array('li' => array('class' => 'item')), 'Item 4.2', '/li',
array('li' => array('class' => 'item')), 'Item 4.3',
'<ul',
array('li' => array('class' => 'item')), 'Item 4.3.1', '/li',
array('li' => array('class' => 'item')), 'Item 4.3.2', '/li',
'/ul',
'/li',
'/ul',
'/li',
array('li' => array('class' => 'item')), 'Item 5',
'<ul',
array('li' => array('class' => 'item')), 'Item 5.1', '/li',
array('li' => array('class' => 'item')), 'Item 5.2', '/li',
'/ul',
'/li',
'/ul'
);
$this->assertTags($result, $expected);
$result = $this->Html->nestedList($list, array(), array('even' => 'even', 'odd' => 'odd'));
$expected = array(
'<ul',
array('li' => array('class' => 'odd')), 'Item 1', '/li',
array('li' => array('class' => 'even')), 'Item 2',
'<ul', array('li' => array('class' => 'odd')), 'Item 2.1', '/li', '/ul',
'/li',
array('li' => array('class' => 'odd')), 'Item 3', '/li',
array('li' => array('class' => 'even')), 'Item 4',
'<ul',
array('li' => array('class' => 'odd')), 'Item 4.1', '/li',
array('li' => array('class' => 'even')), 'Item 4.2', '/li',
array('li' => array('class' => 'odd')), 'Item 4.3',
'<ul',
array('li' => array('class' => 'odd')), 'Item 4.3.1', '/li',
array('li' => array('class' => 'even')), 'Item 4.3.2', '/li',
'/ul',
'/li',
'/ul',
'/li',
array('li' => array('class' => 'odd')), 'Item 5',
'<ul',
array('li' => array('class' => 'odd')), 'Item 5.1', '/li',
array('li' => array('class' => 'even')), 'Item 5.2', '/li',
'/ul',
'/li',
'/ul'
);
$this->assertTags($result, $expected);
$result = $this->Html->nestedList($list, array('class'=>'list'), array('class' => 'item'));
$expected = array(
array('ul' => array('class' => 'list')),
array('li' => array('class' => 'item')), 'Item 1', '/li',
array('li' => array('class' => 'item')), 'Item 2',
array('ul' => array('class' => 'list')), array('li' => array('class' => 'item')), 'Item 2.1', '/li', '/ul',
'/li',
array('li' => array('class' => 'item')), 'Item 3', '/li',
array('li' => array('class' => 'item')), 'Item 4',
array('ul' => array('class' => 'list')),
array('li' => array('class' => 'item')), 'Item 4.1', '/li',
array('li' => array('class' => 'item')), 'Item 4.2', '/li',
array('li' => array('class' => 'item')), 'Item 4.3',
array('ul' => array('class' => 'list')),
array('li' => array('class' => 'item')), 'Item 4.3.1', '/li',
array('li' => array('class' => 'item')), 'Item 4.3.2', '/li',
'/ul',
'/li',
'/ul',
'/li',
array('li' => array('class' => 'item')), 'Item 5',
array('ul' => array('class' => 'list')),
array('li' => array('class' => 'item')), 'Item 5.1', '/li',
array('li' => array('class' => 'item')), 'Item 5.2', '/li',
'/ul',
'/li',
'/ul'
);
$this->assertTags($result, $expected);
}
/**
* testMeta method
*
* @return void
*/
public function testMeta() {
$result = $this->Html->meta('this is an rss feed', array('controller' => 'posts', 'ext' => 'rss'));
$this->assertTags($result, array('link' => array('href' => 'preg:/.*\/posts\.rss/', 'type' => 'application/rss+xml', 'rel' => 'alternate', 'title' => 'this is an rss feed')));
$result = $this->Html->meta('rss', array('controller' => 'posts', 'ext' => 'rss'), array('title' => 'this is an rss feed'));
$this->assertTags($result, array('link' => array('href' => 'preg:/.*\/posts\.rss/', 'type' => 'application/rss+xml', 'rel' => 'alternate', 'title' => 'this is an rss feed')));
$result = $this->Html->meta('atom', array('controller' => 'posts', 'ext' => 'xml'));
$this->assertTags($result, array('link' => array('href' => 'preg:/.*\/posts\.xml/', 'type' => 'application/atom+xml', 'title' => 'atom')));
$result = $this->Html->meta('non-existing');
$this->assertTags($result, array('<meta'));
$result = $this->Html->meta('non-existing', '/posts.xpp');
$this->assertTags($result, array('link' => array('href' => 'preg:/.*\/posts\.xpp/', 'type' => 'application/rss+xml', 'rel' => 'alternate', 'title' => 'non-existing')));
$result = $this->Html->meta('non-existing', '/posts.xpp', array('type' => 'atom'));
$this->assertTags($result, array('link' => array('href' => 'preg:/.*\/posts\.xpp/', 'type' => 'application/atom+xml', 'title' => 'non-existing')));
$result = $this->Html->meta('atom', array('controller' => 'posts', 'ext' => 'xml'), array('link' => '/articles.rss'));
$this->assertTags($result, array('link' => array('href' => 'preg:/.*\/articles\.rss/', 'type' => 'application/atom+xml', 'title' => 'atom')));
$result = $this->Html->meta(array('link' => 'favicon.ico', 'rel' => 'icon'));
$expected = array(
'link' => array('href' => 'preg:/.*favicon\.ico/', 'rel' => 'icon'),
array('link' => array('href' => 'preg:/.*favicon\.ico/', 'rel' => 'shortcut icon'))
);
$this->assertTags($result, $expected);
$result = $this->Html->meta('icon', 'favicon.ico');
$expected = array(
'link' => array('href' => 'preg:/.*favicon\.ico/', 'type' => 'image/x-icon', 'rel' => 'icon'),
array('link' => array('href' => 'preg:/.*favicon\.ico/', 'type' => 'image/x-icon', 'rel' => 'shortcut icon'))
);
$this->assertTags($result, $expected);
$result = $this->Html->meta('icon');
$expected = array(
'link' => array('href' => 'preg:/.*favicon\.ico/', 'type' => 'image/x-icon', 'rel' => 'icon'),
array('link' => array('href' => 'preg:/.*favicon\.ico/', 'type' => 'image/x-icon', 'rel' => 'shortcut icon'))
);
$this->assertTags($result, $expected);
$result = $this->Html->meta('keywords', 'these, are, some, meta, keywords');
$this->assertTags($result, array('meta' => array('name' => 'keywords', 'content' => 'these, are, some, meta, keywords')));
$this->assertPattern('/\s+\/>$/', $result);
$result = $this->Html->meta('description', 'this is the meta description');
$this->assertTags($result, array('meta' => array('name' => 'description', 'content' => 'this is the meta description')));
$result = $this->Html->meta(array('name' => 'ROBOTS', 'content' => 'ALL'));
$this->assertTags($result, array('meta' => array('name' => 'ROBOTS', 'content' => 'ALL')));
$this->View->expects($this->any())->method('addScript')
->with($this->matchesRegularExpression('/^<meta/'));
$result = $this->Html->meta(array('name' => 'ROBOTS', 'content' => 'ALL'), null, array('inline' => false));
$this->assertNull($result);
}
/**
* testTableHeaders method
*
* @return void
*/
public function testTableHeaders() {
$result = $this->Html->tableHeaders(array('ID', 'Name', 'Date'));
$expected = array('<tr', '<th', 'ID', '/th', '<th', 'Name', '/th', '<th', 'Date', '/th', '/tr');
$this->assertTags($result, $expected);
}
/**
* testTableCells method
*
* @return void
*/
public function testTableCells() {
$tr = array(
'td content 1',
array('td content 2', array("width" => "100px")),
array('td content 3', "width=100px")
);
$result = $this->Html->tableCells($tr);
$expected = array(
'<tr',
'<td', 'td content 1', '/td',
array('td' => array('width' => '100px')), 'td content 2', '/td',
array('td' => array('width' => 'preg:/100px/')), 'td content 3', '/td',
'/tr'
);
$this->assertTags($result, $expected);
$tr = array('td content 1', 'td content 2', 'td content 3');
$result = $this->Html->tableCells($tr, null, null, true);
$expected = array(
'<tr',
array('td' => array('class' => 'column-1')), 'td content 1', '/td',
array('td' => array('class' => 'column-2')), 'td content 2', '/td',
array('td' => array('class' => 'column-3')), 'td content 3', '/td',
'/tr'
);
$this->assertTags($result, $expected);
$tr = array('td content 1', 'td content 2', 'td content 3');
$result = $this->Html->tableCells($tr, true);
$expected = array(
'<tr',
array('td' => array('class' => 'column-1')), 'td content 1', '/td',
array('td' => array('class' => 'column-2')), 'td content 2', '/td',
array('td' => array('class' => 'column-3')), 'td content 3', '/td',
'/tr'
);
$this->assertTags($result, $expected);
$tr = array(
array('td content 1', 'td content 2', 'td content 3'),
array('td content 1', 'td content 2', 'td content 3'),
array('td content 1', 'td content 2', 'td content 3')
);
$result = $this->Html->tableCells($tr, array('class' => 'odd'), array('class' => 'even'));
$expected = "<tr class=\"even\"><td>td content 1</td> <td>td content 2</td> <td>td content 3</td></tr>\n<tr class=\"odd\"><td>td content 1</td> <td>td content 2</td> <td>td content 3</td></tr>\n<tr class=\"even\"><td>td content 1</td> <td>td content 2</td> <td>td content 3</td></tr>";
$this->assertEqual($expected, $result);
$tr = array(
array('td content 1', 'td content 2', 'td content 3'),
array('td content 1', 'td content 2', 'td content 3'),
array('td content 1', 'td content 2', 'td content 3'),
array('td content 1', 'td content 2', 'td content 3')
);
$result = $this->Html->tableCells($tr, array('class' => 'odd'), array('class' => 'even'));
$expected = "<tr class=\"odd\"><td>td content 1</td> <td>td content 2</td> <td>td content 3</td></tr>\n<tr class=\"even\"><td>td content 1</td> <td>td content 2</td> <td>td content 3</td></tr>\n<tr class=\"odd\"><td>td content 1</td> <td>td content 2</td> <td>td content 3</td></tr>\n<tr class=\"even\"><td>td content 1</td> <td>td content 2</td> <td>td content 3</td></tr>";
$this->assertEqual($expected, $result);
$tr = array(
array('td content 1', 'td content 2', 'td content 3'),
array('td content 1', 'td content 2', 'td content 3'),
array('td content 1', 'td content 2', 'td content 3')
);
$this->Html->tableCells($tr, array('class' => 'odd'), array('class' => 'even'));
$result = $this->Html->tableCells($tr, array('class' => 'odd'), array('class' => 'even'), false, false);
$expected = "<tr class=\"odd\"><td>td content 1</td> <td>td content 2</td> <td>td content 3</td></tr>\n<tr class=\"even\"><td>td content 1</td> <td>td content 2</td> <td>td content 3</td></tr>\n<tr class=\"odd\"><td>td content 1</td> <td>td content 2</td> <td>td content 3</td></tr>";
$this->assertEqual($expected, $result);
}
/**
* testTag method
*
* @return void
*/
public function testTag() {
$result = $this->Html->tag('div');
$this->assertTags($result, '<div');
$result = $this->Html->tag('div', 'text');
$this->assertTags($result, '<div', 'text', '/div');
$result = $this->Html->tag('div', '<text>', 'class-name');
$this->assertTags($result, array('div' => array('class' => 'class-name'), 'preg:/<text>/', '/div'));
$result = $this->Html->tag('div', '<text>', array('class' => 'class-name', 'escape' => true));
$this->assertTags($result, array('div' => array('class' => 'class-name'), '<text>', '/div'));
}
/**
* testUseTag method
*
* @return void
*/
public function testUseTag() {
$result = $this->Html->useTag('unknowntag');
$this->assertEqual($result, '');
$result = $this->Html->useTag('formend');
$this->assertTags($result, '/form');
$result = $this->Html->useTag('form', 'url', ' test');
$this->assertEqual($result, '<form action="url" test>');
$result = $this->Html->useTag('form', 'example.com', array('test' => 'ok'));
$this->assertTags($result, array('form' => array('test' => 'ok', 'action' => 'example.com')));
}
/**
* testDiv method
*
* @return void
*/
public function testDiv() {
$result = $this->Html->div('class-name');
$this->assertTags($result, array('div' => array('class' => 'class-name')));
$result = $this->Html->div('class-name', 'text');
$this->assertTags($result, array('div' => array('class' => 'class-name'), 'text', '/div'));
$result = $this->Html->div('class-name', '<text>', array('escape' => true));
$this->assertTags($result, array('div' => array('class' => 'class-name'), '<text>', '/div'));
}
/**
* testPara method
*
* @return void
*/
public function testPara() {
$result = $this->Html->para('class-name', '');
$this->assertTags($result, array('p' => array('class' => 'class-name')));
$result = $this->Html->para('class-name', 'text');
$this->assertTags($result, array('p' => array('class' => 'class-name'), 'text', '/p'));
$result = $this->Html->para('class-name', '<text>', array('escape' => true));
$this->assertTags($result, array('p' => array('class' => 'class-name'), '<text>', '/p'));
}
/**
* testCrumbList method
*
*
* @return void
*/
public function testCrumbList() {
$this->assertNull($this->Html->getCrumbList());
$this->Html->addCrumb('Home', '/', array('class' => 'home'));
$this->Html->addCrumb('Some page', '/some_page');
$this->Html->addCrumb('Another page');
$result = $this->Html->getCrumbList(
array('class' => 'breadcrumbs')
);
$this->assertTags(
$result,
array(
array('ul' => array('class' => 'breadcrumbs')),
array('li' => array('class' => 'first')),
array('a' => array('class' => 'home', 'href' => '/')), 'Home', '/a',
'/li',
'<li',
array('a' => array('href' => '/some_page')), 'Some page', '/a',
'/li',
array('li' => array('class' => 'last')),
'Another page',
'/li',
'/ul'
)
);
}
/**
* testLoadConfig method
*
* @return void
*/
public function testLoadConfig() {
$path = CAKE . 'Test' . DS . 'test_app' . DS . 'Config'. DS;
$result = $this->Html->loadConfig('htmlhelper_tags', $path);
$expected = array(
'tags' => array(
'form' => 'start form',
'formend' => 'finish form'
)
);
$this->assertEqual($expected, $result);
$tags = $this->Html->getAttribute('_tags');
$this->assertEqual($tags['form'], 'start form');
$this->assertEqual($tags['formend'], 'finish form');
$this->assertEqual($tags['selectend'], '</select>');
$result = $this->Html->loadConfig(array('htmlhelper_minimized.ini', 'ini'), $path);
$expected = array(
'minimizedAttributeFormat' => 'format'
);
$this->assertEqual($expected, $result);
$this->assertEqual($this->Html->getAttribute('_minimizedAttributeFormat'), 'format');
}
/**
* testLoadConfigWrongFile method
*
* @return void
* @expectedException ConfigureException
*/
public function testLoadConfigWrongFile() {
$result = $this->Html->loadConfig('wrong_file');
}
/**
* testLoadConfigWrongReader method
*
* @return void
* @expectedException ConfigureException
*/
public function testLoadConfigWrongReader() {
$path = CAKE . 'Test' . DS . 'test_app' . DS . 'Config'. DS;
$result = $this->Html->loadConfig(array('htmlhelper_tags', 'wrong_reader'), $path);
}
/**
* test parsing attributes.
*
* @return void
*/
public function testParseAttributeCompact() {
$helper = new TestHtmlHelper($this->View);
$compact = array('compact', 'checked', 'declare', 'readonly', 'disabled',
'selected', 'defer', 'ismap', 'nohref', 'noshade', 'nowrap', 'multiple', 'noresize');
foreach ($compact as $attribute) {
foreach (array('true', true, 1, '1', $attribute) as $value) {
$attrs = array($attribute => $value);
$expected = ' ' . $attribute . '="' . $attribute . '"';
$this->assertEqual($helper->parseAttributes($attrs), $expected, '%s Failed on ' . $value);
}
}
$this->assertEqual($helper->parseAttributes(array('compact')), ' compact="compact"');
$helper = new Html5TestHelper($this->View);
$expected = ' require';
$this->assertEqual($helper->parseAttributes(array('require')), $expected);
$this->assertEqual($helper->parseAttributes(array('require' => true)), $expected);
$this->assertEqual($helper->parseAttributes(array('require' => false)), '');
}
}
| 0001-bee | trunk/cakephp2/lib/Cake/Test/Case/View/Helper/HtmlHelperTest.php | PHP | gpl3 | 45,292 |
<?php
/**
* TextHelperTest file
*
* PHP 5
*
* CakePHP(tm) Tests <http://book.cakephp.org/view/1196/Testing>
* Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice
*
* @copyright Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://book.cakephp.org/view/1196/Testing CakePHP(tm) Tests
* @package Cake.Test.Case.View.Helper
* @since CakePHP(tm) v 1.2.0.4206
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
App::uses('View', 'View');
App::uses('TextHelper', 'View/Helper');
/**
* TextHelperTest class
*
* @package Cake.Test.Case.View.Helper
*/
class TextHelperTest extends CakeTestCase {
/**
* setUp method
*
* @return void
*/
public function setUp() {
$controller = null;
$this->View = new View($controller);
$this->Text = new TextHelper($this->View);
}
/**
* tearDown method
*
* @return void
*/
public function tearDown() {
unset($this->View, $this->Text);
}
/**
* testTruncate method
*
* @return void
*/
public function testTruncate() {
$text1 = 'The quick brown fox jumps over the lazy dog';
$text2 = 'Heizölrückstoßabdämpfung';
$text3 = '<b>© 2005-2007, Cake Software Foundation, Inc.</b><br />written by Alexander Wegener';
$text4 = '<img src="mypic.jpg"> This image tag is not XHTML conform!<br><hr/><b>But the following image tag should be conform <img src="mypic.jpg" alt="Me, myself and I" /></b><br />Great, or?';
$text5 = '0<b>1<i>2<span class="myclass">3</span>4<u>5</u>6</i>7</b>8<b>9</b>0';
$text6 = '<p><strong>Extra dates have been announced for this year\'s tour.</strong></p><p>Tickets for the new shows in</p>';
$text7 = 'El moño está en el lugar correcto. Eso fue lo que dijo la niña, ¿habrá dicho la verdad?';
$text8 = 'Vive la R'.chr(195).chr(169).'publique de France';
$text9 = 'НОПРСТУФХЦЧШЩЪЫЬЭЮЯабвгдежзийклмнопрстуфхцчшщъыь';
$this->assertIdentical($this->Text->truncate($text1, 15), 'The quick br...');
$this->assertIdentical($this->Text->truncate($text1, 15, array('exact' => false)), 'The quick...');
$this->assertIdentical($this->Text->truncate($text1, 100), 'The quick brown fox jumps over the lazy dog');
$this->assertIdentical($this->Text->truncate($text2, 10), 'Heiz&ou...');
$this->assertIdentical($this->Text->truncate($text2, 10, array('exact' => false)), '...');
$this->assertIdentical($this->Text->truncate($text3, 20), '<b>© 2005-20...');
$this->assertIdentical($this->Text->truncate($text4, 15), '<img src="my...');
$this->assertIdentical($this->Text->truncate($text5, 6, array('ending' => '')), '0<b>1<');
$this->assertIdentical($this->Text->truncate($text1, 15, array('html' => true)), 'The quick br...');
$this->assertIdentical($this->Text->truncate($text1, 15, array('exact' => false, 'html' => true)), 'The quick...');
$this->assertIdentical($this->Text->truncate($text2, 10, array('html' => true)), 'Heizölr...');
$this->assertIdentical($this->Text->truncate($text2, 10, array('exact' => false, 'html' => true)), '...');
$this->assertIdentical($this->Text->truncate($text3, 20, array('html' => true)), '<b>© 2005-2007, Cake...</b>');
$this->assertIdentical($this->Text->truncate($text4, 15, array('html' => true)), '<img src="mypic.jpg"> This image ...');
$this->assertIdentical($this->Text->truncate($text4, 45, array('html' => true)), '<img src="mypic.jpg"> This image tag is not XHTML conform!<br><hr/><b>But t...</b>');
$this->assertIdentical($this->Text->truncate($text4, 90, array('html' => true)), '<img src="mypic.jpg"> This image tag is not XHTML conform!<br><hr/><b>But the following image tag should be conform <img src="mypic.jpg" alt="Me, myself and I" /></b><br />Grea...');
$this->assertIdentical($this->Text->truncate($text5, 6, array('ending' => '', 'html' => true)), '0<b>1<i>2<span class="myclass">3</span>4<u>5</u></i></b>');
$this->assertIdentical($this->Text->truncate($text5, 20, array('ending' => '', 'html' => true)), $text5);
$this->assertIdentical($this->Text->truncate($text6, 57, array('exact' => false, 'html' => true)), "<p><strong>Extra dates have been announced for this year's...</strong></p>");
$this->assertIdentical($this->Text->truncate($text7, 255), $text7);
$this->assertIdentical($this->Text->truncate($text7, 15), 'El moño está...');
$this->assertIdentical($this->Text->truncate($text8, 15), 'Vive la R'.chr(195).chr(169).'pu...');
$this->assertIdentical($this->Text->truncate($text9, 10), 'НОПРСТУ...');
}
/**
* testHighlight method
*
* @return void
*/
public function testHighlight() {
$text = 'This is a test text';
$phrases = array('This', 'text');
$result = $this->Text->highlight($text, $phrases, array('format' => '<b>\1</b>'));
$expected = '<b>This</b> is a test <b>text</b>';
$this->assertEqual($expected, $result);
$text = 'This is a test text';
$phrases = null;
$result = $this->Text->highlight($text, $phrases, array('format' => '<b>\1</b>'));
$this->assertEqual($result, $text);
$text = 'Ich saß in einem Café am Übergang';
$expected = 'Ich <b>saß</b> in einem <b>Café</b> am <b>Übergang</b>';
$phrases = array('saß', 'café', 'übergang');
$result = $this->Text->highlight($text, $phrases, array('format' => '<b>\1</b>'));
$this->assertEqual($expected, $result);
}
/**
* testHighlightHtml method
*
* @return void
*/
public function testHighlightHtml() {
$text1 = '<p>strongbow isn’t real cider</p>';
$text2 = '<p>strongbow <strong>isn’t</strong> real cider</p>';
$text3 = '<img src="what-a-strong-mouse.png" alt="What a strong mouse!" />';
$text4 = 'What a strong mouse: <img src="what-a-strong-mouse.png" alt="What a strong mouse!" />';
$options = array('format' => '<b>\1</b>', 'html' => true);
$expected = '<p><b>strong</b>bow isn’t real cider</p>';
$this->assertEqual($this->Text->highlight($text1, 'strong', $options), $expected);
$expected = '<p><b>strong</b>bow <strong>isn’t</strong> real cider</p>';
$this->assertEqual($this->Text->highlight($text2, 'strong', $options), $expected);
$this->assertEqual($this->Text->highlight($text3, 'strong', $options), $text3);
$this->assertEqual($this->Text->highlight($text3, array('strong', 'what'), $options), $text3);
$expected = '<b>What</b> a <b>strong</b> mouse: <img src="what-a-strong-mouse.png" alt="What a strong mouse!" />';
$this->assertEqual($this->Text->highlight($text4, array('strong', 'what'), $options), $expected);
}
/**
* testHighlightMulti method
*
* @return void
*/
public function testHighlightMulti() {
$text = 'This is a test text';
$phrases = array('This', 'text');
$result = $this->Text->highlight($text, $phrases, array('format' => array('<b>\1</b>', '<em>\1</em>')));
$expected = '<b>This</b> is a test <em>text</em>';
$this->assertEqual($expected, $result);
}
/**
* testStripLinks method
*
* @return void
*/
public function testStripLinks() {
$text = 'This is a test text';
$expected = 'This is a test text';
$result = $this->Text->stripLinks($text);
$this->assertEqual($expected, $result);
$text = 'This is a <a href="#">test</a> text';
$expected = 'This is a test text';
$result = $this->Text->stripLinks($text);
$this->assertEqual($expected, $result);
$text = 'This <strong>is</strong> a <a href="#">test</a> <a href="#">text</a>';
$expected = 'This <strong>is</strong> a test text';
$result = $this->Text->stripLinks($text);
$this->assertEqual($expected, $result);
$text = 'This <strong>is</strong> a <a href="#">test</a> and <abbr>some</abbr> other <a href="#">text</a>';
$expected = 'This <strong>is</strong> a test and <abbr>some</abbr> other text';
$result = $this->Text->stripLinks($text);
$this->assertEqual($expected, $result);
}
/**
* testAutoLink method
*
* @return void
*/
public function testAutoLink() {
$text = 'This is a test text';
$expected = 'This is a test text';
$result = $this->Text->autoLink($text);
$this->assertEqual($expected, $result);
$text = 'Text with a partial www.cakephp.org URL and test@cakephp.org email address';
$result = $this->Text->autoLink($text);
$expected = 'Text with a partial <a href="http://www.cakephp.org">www.cakephp.org</a> URL and <a href="mailto:test@cakephp\.org">test@cakephp\.org</a> email address';
$this->assertPattern('#^' . $expected . '$#', $result);
$text = 'This is a test text with URL http://www.cakephp.org';
$expected = 'This is a test text with URL <a href="http://www.cakephp.org">http://www.cakephp.org</a>';
$result = $this->Text->autoLink($text);
$this->assertEqual($expected, $result);
$text = 'This is a test text with URL http://www.cakephp.org and some more text';
$expected = 'This is a test text with URL <a href="http://www.cakephp.org">http://www.cakephp.org</a> and some more text';
$result = $this->Text->autoLink($text);
$this->assertEqual($expected, $result);
$text = "This is a test text with URL http://www.cakephp.org\tand some more text";
$expected = "This is a test text with URL <a href=\"http://www.cakephp.org\">http://www.cakephp.org</a>\tand some more text";
$result = $this->Text->autoLink($text);
$this->assertEqual($expected, $result);
$text = 'This is a test text with URL http://www.cakephp.org(and some more text)';
$expected = 'This is a test text with URL <a href="http://www.cakephp.org">http://www.cakephp.org</a>(and some more text)';
$result = $this->Text->autoLink($text);
$this->assertEqual($expected, $result);
$text = 'This is a test text with URL http://www.cakephp.org';
$expected = 'This is a test text with URL <a href="http://www.cakephp.org" class="link">http://www.cakephp.org</a>';
$result = $this->Text->autoLink($text, array('class'=>'link'));
$this->assertEqual($expected, $result);
$text = 'This is a test text with URL http://www.cakephp.org';
$expected = 'This is a test text with URL <a href="http://www.cakephp.org" class="link" id="MyLink">http://www.cakephp.org</a>';
$result = $this->Text->autoLink($text, array('class'=>'link', 'id'=>'MyLink'));
$this->assertEqual($expected, $result);
}
/**
* testAutoLinkUrls method
*
* @return void
*/
public function testAutoLinkUrls() {
$text = 'This is a test text';
$expected = 'This is a test text';
$result = $this->Text->autoLinkUrls($text);
$this->assertEqual($expected, $result);
$text = 'This is a test that includes (www.cakephp.org)';
$expected = 'This is a test that includes (<a href="http://www.cakephp.org">www.cakephp.org</a>)';
$result = $this->Text->autoLinkUrls($text);
$this->assertEqual($expected, $result);
$text = 'Text with a partial www.cakephp.org URL';
$expected = 'Text with a partial <a href="http://www.cakephp.org"\s*>www.cakephp.org</a> URL';
$result = $this->Text->autoLinkUrls($text);
$this->assertPattern('#^' . $expected . '$#', $result);
$text = 'Text with a partial www.cakephp.org URL';
$expected = 'Text with a partial <a href="http://www.cakephp.org" \s*class="link">www.cakephp.org</a> URL';
$result = $this->Text->autoLinkUrls($text, array('class' => 'link'));
$this->assertPattern('#^' . $expected . '$#', $result);
$text = 'Text with a partial WWW.cakephp.org URL';
$expected = 'Text with a partial <a href="http://WWW.cakephp.org"\s*>WWW.cakephp.org</a> URL';
$result = $this->Text->autoLinkUrls($text);
$this->assertPattern('#^' . $expected . '$#', $result);
$text = 'Text with a partial WWW.cakephp.org © URL';
$expected = 'Text with a partial <a href="http://WWW.cakephp.org"\s*>WWW.cakephp.org</a> © URL';
$result = $this->Text->autoLinkUrls($text, array('escape' => false));
$this->assertPattern('#^' . $expected . '$#', $result);
$text = 'Text with a url www.cot.ag/cuIb2Q and more';
$expected = 'Text with a url <a href="http://www.cot.ag/cuIb2Q">www.cot.ag/cuIb2Q</a> and more';
$result = $this->Text->autoLinkUrls($text);
$this->assertEqual($expected, $result);
$text = 'Text with a url http://www.does--not--work.com and more';
$expected = 'Text with a url <a href="http://www.does--not--work.com">http://www.does--not--work.com</a> and more';
$result = $this->Text->autoLinkUrls($text);
$this->assertEqual($expected, $result);
$text = 'Text with a url http://www.not--work.com and more';
$expected = 'Text with a url <a href="http://www.not--work.com">http://www.not--work.com</a> and more';
$result = $this->Text->autoLinkUrls($text);
$this->assertEqual($expected, $result);
$text = 'Text with a partial <a href="http://www.cakephp.org">link</a> link';
$expected = 'Text with a partial <a href="http://www.cakephp.org">link</a> link';
$result = $this->Text->autoLinkUrls($text, array('escape' => false));
$this->assertEqual($expected, $result);
$text = 'Text with a partial <iframe src="http://www.cakephp.org" /> link';
$expected = 'Text with a partial <iframe src="http://www.cakephp.org" /> link';
$result = $this->Text->autoLinkUrls($text, array('escape' => false));
$this->assertEqual($expected, $result);
}
/**
* testAutoLinkEmails method
*
* @return void
*/
public function testAutoLinkEmails() {
$text = 'This is a test text';
$expected = 'This is a test text';
$result = $this->Text->autoLinkUrls($text);
$this->assertEqual($expected, $result);
$text = 'Text with email@example.com address';
$expected = 'Text with <a href="mailto:email@example.com"\s*>email@example.com</a> address';
$result = $this->Text->autoLinkEmails($text);
$this->assertPattern('#^' . $expected . '$#', $result);
$text = "Text with o'hare._-bob@example.com address";
$expected = 'Text with <a href="mailto:o'hare._-bob@example.com">o'hare._-bob@example.com</a> address';
$result = $this->Text->autoLinkEmails($text);
$this->assertEqual($expected, $result);
$text = 'Text with email@example.com address';
$expected = 'Text with <a href="mailto:email@example.com" \s*class="link">email@example.com</a> address';
$result = $this->Text->autoLinkEmails($text, array('class' => 'link'));
$this->assertPattern('#^' . $expected . '$#', $result);
}
/**
* test invalid email addresses.
*
* @return void
*/
public function testAutoLinkEmailInvalid() {
$result = $this->Text->autoLinkEmails('this is a myaddress@gmx-de test');
$expected = 'this is a myaddress@gmx-de test';
$this->assertEqual($expected, $result);
}
/**
* testHighlightCaseInsensitivity method
*
* @return void
*/
public function testHighlightCaseInsensitivity() {
$text = 'This is a Test text';
$expected = 'This is a <b>Test</b> text';
$result = $this->Text->highlight($text, 'test', array('format' => '<b>\1</b>'));
$this->assertEqual($expected, $result);
$result = $this->Text->highlight($text, array('test'), array('format' => '<b>\1</b>'));
$this->assertEqual($expected, $result);
}
/**
* testExcerpt method
*
* @return void
*/
public function testExcerpt() {
$text = 'This is a phrase with test text to play with';
$expected = '...with test text...';
$result = $this->Text->excerpt($text, 'test', 9, '...');
$this->assertEqual($expected, $result);
$expected = 'This is a...';
$result = $this->Text->excerpt($text, 'not_found', 9, '...');
$this->assertEqual($expected, $result);
$expected = 'This is a phras...';
$result = $this->Text->excerpt($text, null, 9, '...');
$this->assertEqual($expected, $result);
$expected = $text;
$result = $this->Text->excerpt($text, null, 200, '...');
$this->assertEqual($expected, $result);
$expected = '...phrase...';
$result = $this->Text->excerpt($text, 'phrase', 2, '...');
$this->assertEqual($expected, $result);
$phrase = 'This is a phrase with test';
$expected = $text;
$result = $this->Text->excerpt($text, $phrase, strlen($phrase) + 3, '...');
$this->assertEqual($expected, $result);
$phrase = 'This is a phrase with text';
$expected = $text;
$result = $this->Text->excerpt($text, $phrase, 10, '...');
$this->assertEqual($expected, $result);
}
/**
* testExcerptCaseInsensitivity method
*
* @return void
*/
public function testExcerptCaseInsensitivity() {
$text = 'This is a phrase with test text to play with';
$expected = '...with test text...';
$result = $this->Text->excerpt($text, 'TEST', 9, '...');
$this->assertEqual($expected, $result);
$expected = 'This is a...';
$result = $this->Text->excerpt($text, 'NOT_FOUND', 9, '...');
$this->assertEqual($expected, $result);
}
/**
* testListGeneration method
*
* @return void
*/
public function testListGeneration() {
$result = $this->Text->toList(array());
$this->assertEqual($result, '');
$result = $this->Text->toList(array('One'));
$this->assertEqual($result, 'One');
$result = $this->Text->toList(array('Larry', 'Curly', 'Moe'));
$this->assertEqual($result, 'Larry, Curly and Moe');
$result = $this->Text->toList(array('Dusty', 'Lucky', 'Ned'), 'y');
$this->assertEqual($result, 'Dusty, Lucky y Ned');
$result = $this->Text->toList(array( 1 => 'Dusty', 2 => 'Lucky', 3 => 'Ned'), 'y');
$this->assertEqual($result, 'Dusty, Lucky y Ned');
$result = $this->Text->toList(array( 1 => 'Dusty', 2 => 'Lucky', 3 => 'Ned'), 'and', ' + ');
$this->assertEqual($result, 'Dusty + Lucky and Ned');
$result = $this->Text->toList(array( 'name1' => 'Dusty', 'name2' => 'Lucky'));
$this->assertEqual($result, 'Dusty and Lucky');
$result = $this->Text->toList(array( 'test_0' => 'banana', 'test_1' => 'apple', 'test_2' => 'lemon'));
$this->assertEqual($result, 'banana, apple and lemon');
}
}
| 0001-bee | trunk/cakephp2/lib/Cake/Test/Case/View/Helper/TextHelperTest.php | PHP | gpl3 | 17,871 |
<?php
/**
* JsHelper Test Case
*
* TestCase for the JsHelper
*
* PHP 5
*
* CakePHP(tm) Tests <http://book.cakephp.org/view/1196/Testing>
* Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice
*
* @copyright Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://book.cakephp.org/view/1196/Testing CakePHP(tm) Tests
* @package Cake.Test.Case.View.Helper
* @since CakePHP(tm) v 1.3
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
App::uses('HtmlHelper', 'View/Helper');
App::uses('JsHelper', 'View/Helper');
App::uses('JsBaseEngineHelper', 'View/Helper');
App::uses('FormHelper', 'View/Helper');
App::uses('View', 'View');
App::uses('ClassRegistry', 'Utility');
class JsEncodingObject {
protected $_title = 'Old thing';
private $__noshow = 'Never ever';
}
class OptionEngineHelper extends JsBaseEngineHelper {
protected $_optionMap = array(
'request' => array(
'complete' => 'success',
'request' => 'beforeSend',
'type' => 'dataType'
)
);
/**
* test method for testing option mapping
*
* @return array
*/
public function testMap($options = array()) {
return $this->_mapOptions('request', $options);
}
/**
* test method for option parsing
*
* @return void
*/
public function testParseOptions($options, $safe = array()) {
return $this->_parseOptions($options, $safe);
}
public function get($selector) {}
public function event($type, $callback, $options = array()) {}
public function domReady($functionBody) {}
public function each($callback) {}
public function effect($name, $options = array()) {}
public function request($url, $options = array()) {}
public function drag($options = array()) {}
public function drop($options = array()) {}
public function sortable($options = array()) {}
public function slider($options = array()) {}
public function serializeForm($options = array()) {}
}
/**
* JsHelper TestCase.
*
* @package Cake.Test.Case.View.Helper
*/
class JsHelperTest extends CakeTestCase {
/**
* Regexp for CDATA start block
*
* @var string
*/
public $cDataStart = 'preg:/^\/\/<!\[CDATA\[[\n\r]*/';
/**
* Regexp for CDATA end block
*
* @var string
*/
public $cDataEnd = 'preg:/[^\]]*\]\]\>[\s\r\n]*/';
/**
* setUp method
*
* @return void
*/
public function setUp() {
$this->_asset = Configure::read('Asset.timestamp');
Configure::write('Asset.timestamp', false);
$controller = null;
$this->View = $this->getMock('View', array('addScript'), array(&$controller));
$this->Js = new JsHelper($this->View, 'Option');
$request = new CakeRequest(null, false);
$this->Js->request = $request;
$this->Js->Html = new HtmlHelper($this->View);
$this->Js->Html->request = $request;
$this->Js->Form = new FormHelper($this->View);
$this->Js->Form->request = $request;
$this->Js->Form->Html = $this->Js->Html;
$this->Js->OptionEngine = new OptionEngineHelper($this->View);
}
/**
* tearDown method
*
* @return void
*/
public function tearDown() {
Configure::write('Asset.timestamp', $this->_asset);
unset($this->Js);
}
/**
* Switches $this->Js to a mocked engine.
*
* @return void
*/
function _useMock() {
$request = new CakeRequest(null, false);
if (!class_exists('TestJsEngineHelper', false)) {
$this->getMock('JsBaseEngineHelper', array(), array($this->View), 'TestJsEngineHelper');
}
$this->Js = new JsHelper($this->View, array('TestJs'));
$this->Js->TestJsEngine = new TestJsEngineHelper($this->View);
$this->mockObjects[] = $this->Js->TestJsEngine;
$this->Js->request = $request;
$this->Js->Html = new HtmlHelper($this->View);
$this->Js->Html->request = $request;
$this->Js->Form = new FormHelper($this->View);
$this->Js->Form->request = $request;
$this->Js->Form->Html = new HtmlHelper($this->View);
}
/**
* test object construction
*
* @return void
*/
public function testConstruction() {
$js = new JsHelper($this->View);
$this->assertEqual($js->helpers, array('Html', 'Form', 'JqueryEngine'));
$js = new JsHelper($this->View, array('mootools'));
$this->assertEqual($js->helpers, array('Html', 'Form', 'mootoolsEngine'));
$js = new JsHelper($this->View, 'prototype');
$this->assertEqual($js->helpers, array('Html', 'Form', 'prototypeEngine'));
$js = new JsHelper($this->View, 'MyPlugin.Dojo');
$this->assertEqual($js->helpers, array('Html', 'Form', 'MyPlugin.DojoEngine'));
}
/**
* test that methods dispatch internally and to the engine class
*
* @return void
*/
public function testMethodDispatching() {
$this->_useMock();
$this->Js->TestJsEngine
->expects($this->once())
->method('event')
->with('click', 'callback');
$this->Js->event('click', 'callback');
$this->Js->TestJsEngine = new StdClass();
$this->expectError();
$this->Js->someMethodThatSurelyDoesntExist();
}
/**
* Test that method dispatching for events respects buffer parameters and bufferedMethods Lists.
*
* @return void
*/
public function testEventDispatchWithBuffering() {
$this->_useMock();
$this->Js->TestJsEngine->bufferedMethods = array('event', 'sortables');
$this->Js->TestJsEngine->expects($this->exactly(3))
->method('event')
->will($this->returnValue('This is an event call'));
$this->Js->event('click', 'foo');
$result = $this->Js->getBuffer();
$this->assertEqual(count($result), 1);
$this->assertEqual($result[0], 'This is an event call');
$result = $this->Js->event('click', 'foo', array('buffer' => false));
$buffer = $this->Js->getBuffer();
$this->assertTrue(empty($buffer));
$this->assertEqual($result, 'This is an event call');
$result = $this->Js->event('click', 'foo', false);
$buffer = $this->Js->getBuffer();
$this->assertTrue(empty($buffer));
$this->assertEqual($result, 'This is an event call');
}
/**
* Test that method dispatching for effects respects buffer parameters and bufferedMethods Lists.
*
* @return void
*/
public function testEffectDispatchWithBuffering() {
$this->_useMock();
$this->Js->TestJsEngine->expects($this->exactly(4))
->method('effect')
->will($this->returnValue('I am not buffered.'));
$result = $this->Js->effect('slideIn');
$buffer = $this->Js->getBuffer();
$this->assertTrue(empty($buffer));
$this->assertEqual($result, 'I am not buffered.');
$result = $this->Js->effect('slideIn', true);
$buffer = $this->Js->getBuffer();
$this->assertNull($result);
$this->assertEqual(count($buffer), 1);
$this->assertEqual($buffer[0], 'I am not buffered.');
$result = $this->Js->effect('slideIn', array('speed' => 'slow'), true);
$buffer = $this->Js->getBuffer();
$this->assertNull($result);
$this->assertEqual(count($buffer), 1);
$this->assertEqual($buffer[0], 'I am not buffered.');
$result = $this->Js->effect('slideIn', array('speed' => 'slow', 'buffer' => true));
$buffer = $this->Js->getBuffer();
$this->assertNull($result);
$this->assertEqual(count($buffer), 1);
$this->assertEqual($buffer[0], 'I am not buffered.');
}
/**
* test that writeScripts generates scripts inline.
*
* @return void
*/
public function testWriteScriptsNoFile() {
$this->_useMock();
$this->Js->buffer('one = 1;');
$this->Js->buffer('two = 2;');
$result = $this->Js->writeBuffer(array('onDomReady' => false, 'cache' => false, 'clear' => false));
$expected = array(
'script' => array('type' => 'text/javascript'),
$this->cDataStart,
"one = 1;\ntwo = 2;",
$this->cDataEnd,
'/script',
);
$this->assertTags($result, $expected);
$this->Js->TestJsEngine->expects($this->atLeastOnce())->method('domReady');
$result = $this->Js->writeBuffer(array('onDomReady' => true, 'cache' => false, 'clear' => false));
$this->View->expects($this->once())
->method('addScript')
->with($this->matchesRegularExpression('/one\s\=\s1;\ntwo\s\=\s2;/'));
$result = $this->Js->writeBuffer(array('onDomReady' => false, 'inline' => false, 'cache' => false));
}
/**
* test that writing the buffer with inline = false includes a script tag.
*
* @return void
*/
public function testWriteBufferNotInline() {
$this->Js->set('foo', 1);
$this->View->expects($this->once())
->method('addScript')
->with($this->matchesRegularExpression('#<script type="text\/javascript">window.app \= \{"foo"\:1\}\;<\/script>#'));
$result = $this->Js->writeBuffer(array('onDomReady' => false, 'inline' => false, 'safe' => false));
}
/**
* test that writeBuffer() sets domReady = false when the request is done by XHR.
* Including a domReady() when in XHR can cause issues as events aren't triggered by some libraries
*
* @return void
*/
public function testWriteBufferAndXhr() {
$this->_useMock();
$this->Js->params['isAjax'] = true;
$this->Js->buffer('alert("test");');
$this->Js->TestJsEngine->expects($this->never())->method('domReady');
$result = $this->Js->writeBuffer();
}
/**
* test that writeScripts makes files, and puts the events into them.
*
* @return void
*/
public function testWriteScriptsInFile() {
$this->skipIf(!is_writable(JS), 'webroot/js is not Writable, script caching test has been skipped.');
$this->Js->request->webroot = '/';
$this->Js->JsBaseEngine = new TestJsEngineHelper($this->View);
$this->Js->buffer('one = 1;');
$this->Js->buffer('two = 2;');
$result = $this->Js->writeBuffer(array('onDomReady' => false, 'cache' => true));
$expected = array(
'script' => array('type' => 'text/javascript', 'src' => 'preg:/(.)*\.js/'),
);
$this->assertTags($result, $expected);
preg_match('/src="(.*\.js)"/', $result, $filename);
$this->assertTrue(file_exists(WWW_ROOT . $filename[1]));
$contents = file_get_contents(WWW_ROOT . $filename[1]);
$this->assertPattern('/one\s=\s1;\ntwo\s=\s2;/', $contents);
@unlink(WWW_ROOT . $filename[1]);
}
/**
* test link()
*
* @return void
*/
public function testLinkWithMock() {
$this->_useMock();
$options = array('update' => '#content');
$this->Js->TestJsEngine->expects($this->at(0))
->method('get');
$this->Js->TestJsEngine->expects($this->at(1))
->method('request')
->with('/posts/view/1', $options)
->will($this->returnValue('--ajax code--'));
$this->Js->TestJsEngine->expects($this->at(2))
->method('event')
->with('click', '--ajax code--', $options + array('buffer' => null));
$result = $this->Js->link('test link', '/posts/view/1', $options);
$expected = array(
'a' => array('id' => 'preg:/link-\d+/', 'href' => '/posts/view/1'),
'test link',
'/a'
);
$this->assertTags($result, $expected);
}
/**
* test link with a mock and confirmation
*
* @return void
*/
public function testLinkWithMockAndConfirm() {
$this->_useMock();
$options = array(
'confirm' => 'Are you sure?',
'update' => '#content',
'class' => 'my-class',
'id' => 'custom-id',
'escape' => false
);
$this->Js->TestJsEngine->expects($this->once())
->method('confirmReturn')
->with($options['confirm'])
->will($this->returnValue('--confirm script--'));
$this->Js->TestJsEngine->expects($this->once())
->method('request')
->with('/posts/view/1');
$this->Js->TestJsEngine->expects($this->once())
->method('event')
->with('click', '--confirm script--');
$result = $this->Js->link('test link »', '/posts/view/1', $options);
$expected = array(
'a' => array('id' => $options['id'], 'class' => $options['class'], 'href' => '/posts/view/1'),
'test link »',
'/a'
);
$this->assertTags($result, $expected);
}
/**
* test link passing on htmlAttributes
*
* @return void
*/
public function testLinkWithAribtraryAttributes() {
$this->_useMock();
$options = array('id' => 'something', 'htmlAttributes' => array('arbitrary' => 'value', 'batman' => 'robin'));
$result = $this->Js->link('test link', '/posts/view/1', $options);
$expected = array(
'a' => array('id' => $options['id'], 'href' => '/posts/view/1', 'arbitrary' => 'value',
'batman' => 'robin'),
'test link',
'/a'
);
$this->assertTags($result, $expected);
}
/**
* test that link() and no buffering returns an <a> and <script> tags.
*
* @return void
*/
public function testLinkWithNoBuffering() {
$this->_useMock();
$this->Js->TestJsEngine->expects($this->at(1))
->method('request')
->with('/posts/view/1', array('update' => '#content'))
->will($this->returnValue('ajax code'));
$this->Js->TestJsEngine->expects($this->at(2))
->method('event')
->will($this->returnValue('-event handler-'));
$options = array('update' => '#content', 'buffer' => false);
$result = $this->Js->link('test link', '/posts/view/1', $options);
$expected = array(
'a' => array('id' => 'preg:/link-\d+/', 'href' => '/posts/view/1'),
'test link',
'/a',
'script' => array('type' => 'text/javascript'),
$this->cDataStart,
'-event handler-',
$this->cDataEnd,
'/script'
);
$this->assertTags($result, $expected);
}
/**
* test link with buffering off and safe on.
*
* @return void
*/
public function testLinkWithNoBufferingAndSafe() {
$this->_useMock();
$this->Js->TestJsEngine->expects($this->at(1))
->method('request')
->with('/posts/view/1', array('update' => '#content'))
->will($this->returnValue('ajax code'));
$this->Js->TestJsEngine->expects($this->at(2))
->method('event')
->will($this->returnValue('-event handler-'));
$options = array('update' => '#content', 'buffer' => false, 'safe' => false);
$result = $this->Js->link('test link', '/posts/view/1', $options);
$expected = array(
'a' => array('id' => 'preg:/link-\d+/', 'href' => '/posts/view/1'),
'test link',
'/a',
'script' => array('type' => 'text/javascript'),
'-event handler-',
'/script'
);
$this->assertTags($result, $expected);
}
/**
* test submit() with a Mock to check Engine method calls
*
* @return void
*/
public function testSubmitWithMock() {
$this->_useMock();
$options = array('update' => '#content', 'id' => 'test-submit', 'style' => 'margin: 0');
$this->Js->TestJsEngine->expects($this->at(0))
->method('get');
$this->Js->TestJsEngine->expects($this->at(1))
->method('serializeForm')
->will($this->returnValue('serialize-code'));
$this->Js->TestJsEngine->expects($this->at(2))
->method('request')
->will($this->returnValue('ajax-code'));
$params = array(
'update' => $options['update'], 'data' => 'serialize-code',
'method' => 'post', 'dataExpression' => true, 'buffer' => null
);
$this->Js->TestJsEngine->expects($this->at(3))
->method('event')
->with('click', "ajax-code", $params);
$result = $this->Js->submit('Save', $options);
$expected = array(
'div' => array('class' => 'submit'),
'input' => array('type' => 'submit', 'id' => $options['id'], 'value' => 'Save', 'style' => 'margin: 0'),
'/div'
);
$this->assertTags($result, $expected);
}
/**
* test submit() with a mock
*
* @return void
*/
public function testSubmitWithMockRequestParams() {
$this->_useMock();
$this->Js->TestJsEngine->expects($this->at(0))
->method('get');
$this->Js->TestJsEngine->expects($this->at(1))
->method('serializeForm')
->will($this->returnValue('serialize-code'));
$requestParams = array(
'update' => '#content',
'data' => 'serialize-code',
'method' => 'post',
'dataExpression' => true
);
$this->Js->TestJsEngine->expects($this->at(2))
->method('request')
->with('/custom/url', $requestParams)
->will($this->returnValue('ajax-code'));
$params = array(
'update' => '#content', 'data' => 'serialize-code',
'method' => 'post', 'dataExpression' => true, 'buffer' => null
);
$this->Js->TestJsEngine->expects($this->at(3))
->method('event')
->with('click', "ajax-code", $params);
$options = array('update' => '#content', 'id' => 'test-submit', 'url' => '/custom/url');
$result = $this->Js->submit('Save', $options);
$expected = array(
'div' => array('class' => 'submit'),
'input' => array('type' => 'submit', 'id' => $options['id'], 'value' => 'Save'),
'/div'
);
$this->assertTags($result, $expected);
}
/**
* test that no buffer works with submit() and that parameters are leaking into the script tag.
*
* @return void
*/
public function testSubmitWithNoBuffer() {
$this->_useMock();
$options = array('update' => '#content', 'id' => 'test-submit', 'buffer' => false, 'safe' => false);
$this->Js->TestJsEngine->expects($this->at(0))
->method('get');
$this->Js->TestJsEngine->expects($this->at(1))
->method('serializeForm')
->will($this->returnValue('serialize-code'));
$this->Js->TestJsEngine->expects($this->at(2))
->method('request')
->will($this->returnValue('ajax-code'));
$this->Js->TestJsEngine->expects($this->at(3))
->method('event')
->will($this->returnValue('event-handler'));
$params = array(
'update' => $options['update'], 'data' => 'serialize-code',
'method' => 'post', 'dataExpression' => true, 'buffer' => false
);
$this->Js->TestJsEngine->expects($this->at(3))
->method('event')
->with('click', "ajax-code", $params);
$result = $this->Js->submit('Save', $options);
$expected = array(
'div' => array('class' => 'submit'),
'input' => array('type' => 'submit', 'id' => $options['id'], 'value' => 'Save'),
'/div',
'script' => array('type' => 'text/javascript'),
'event-handler',
'/script'
);
$this->assertTags($result, $expected);
}
/**
* Test that Object::Object() is not breaking json output in JsHelper
*
* @return void
*/
public function testObjectPassThrough() {
$result = $this->Js->object(array('one' => 'first', 'two' => 'second'));
$expected = '{"one":"first","two":"second"}';
$this->assertEqual($expected, $result);
}
/**
* Test that inherited Helper::value() is overwritten in JsHelper::value()
* and calls JsBaseEngineHelper::value().
*
* @return void
*/
public function testValuePassThrough() {
$result = $this->Js->value('string "quote"', true);
$expected = '"string \"quote\""';
$this->assertEqual($expected, $result);
}
/**
* test set()'ing variables to the Javascript buffer and controlling the output var name.
*
* @return void
*/
public function testSet() {
$this->Js->set('loggedIn', true);
$this->Js->set(array('height' => 'tall', 'color' => 'purple'));
$result = $this->Js->getBuffer();
$expected = 'window.app = {"loggedIn":true,"height":"tall","color":"purple"};';
$this->assertEqual($result[0], $expected);
$this->Js->set('loggedIn', true);
$this->Js->set(array('height' => 'tall', 'color' => 'purple'));
$this->Js->setVariable = 'WICKED';
$result = $this->Js->getBuffer();
$expected = 'window.WICKED = {"loggedIn":true,"height":"tall","color":"purple"};';
$this->assertEqual($result[0], $expected);
$this->Js->set('loggedIn', true);
$this->Js->set(array('height' => 'tall', 'color' => 'purple'));
$this->Js->setVariable = 'Application.variables';
$result = $this->Js->getBuffer();
$expected = 'Application.variables = {"loggedIn":true,"height":"tall","color":"purple"};';
$this->assertEqual($result[0], $expected);
}
/**
* test that vars set with Js->set() go to the top of the buffered scripts list.
*
* @return void
*/
public function testSetVarsAtTopOfBufferedScripts() {
$this->Js->set(array('height' => 'tall', 'color' => 'purple'));
$this->Js->alert('hey you!', array('buffer' => true));
$this->Js->confirm('Are you sure?', array('buffer' => true));
$result = $this->Js->getBuffer(false);
$expected = 'window.app = {"height":"tall","color":"purple"};';
$this->assertEqual($result[0], $expected);
$this->assertEqual($result[1], 'alert("hey you!");');
$this->assertEqual($result[2], 'confirm("Are you sure?");');
}
}
/**
* JsBaseEngine Class Test case
*
* @package Cake.Test.Case.View.Helper
*/
class JsBaseEngineTest extends CakeTestCase {
/**
* setUp method
*
* @return void
*/
public function setUp() {
parent::setUp();
$controller = null;
$this->View = $this->getMock('View', array('addScript'), array(&$controller));
$this->JsEngine = new OptionEngineHelper($this->View);
}
/**
* tearDown method
*
* @return void
*/
public function tearDown() {
parent::tearDown();
unset($this->JsEngine);
}
/**
* test escape string skills
*
* @return void
*/
public function testEscaping() {
$result = $this->JsEngine->escape('');
$expected = '';
$this->assertEqual($expected, $result);
$result = $this->JsEngine->escape('CakePHP' . "\n" . 'Rapid Development Framework');
$expected = 'CakePHP\\nRapid Development Framework';
$this->assertEqual($expected, $result);
$result = $this->JsEngine->escape('CakePHP' . "\r\n" . 'Rapid Development Framework' . "\r" . 'For PHP');
$expected = 'CakePHP\\r\\nRapid Development Framework\\rFor PHP';
$this->assertEqual($expected, $result);
$result = $this->JsEngine->escape('CakePHP: "Rapid Development Framework"');
$expected = 'CakePHP: \\"Rapid Development Framework\\"';
$this->assertEqual($expected, $result);
$result = $this->JsEngine->escape("CakePHP: 'Rapid Development Framework'");
$expected = "CakePHP: 'Rapid Development Framework'";
$this->assertEqual($expected, $result);
$result = $this->JsEngine->escape('my \\"string\\"');
$expected = 'my \\\\\\"string\\\\\\"';
$this->assertEqual($expected, $result);
}
/**
* test prompt() creation
*
* @return void
*/
public function testPrompt() {
$result = $this->JsEngine->prompt('Hey, hey you', 'hi!');
$expected = 'prompt("Hey, hey you", "hi!");';
$this->assertEqual($expected, $result);
$result = $this->JsEngine->prompt('"Hey"', '"hi"');
$expected = 'prompt("\"Hey\"", "\"hi\"");';
$this->assertEqual($expected, $result);
}
/**
* test alert generation
*
* @return void
*/
public function testAlert() {
$result = $this->JsEngine->alert('Hey there');
$expected = 'alert("Hey there");';
$this->assertEqual($expected, $result);
$result = $this->JsEngine->alert('"Hey"');
$expected = 'alert("\"Hey\"");';
$this->assertEqual($expected, $result);
}
/**
* test confirm generation
*
* @return void
*/
public function testConfirm() {
$result = $this->JsEngine->confirm('Are you sure?');
$expected = 'confirm("Are you sure?");';
$this->assertEqual($expected, $result);
$result = $this->JsEngine->confirm('"Are you sure?"');
$expected = 'confirm("\"Are you sure?\"");';
$this->assertEqual($expected, $result);
}
/**
* test Redirect
*
* @return void
*/
public function testRedirect() {
$result = $this->JsEngine->redirect(array('controller' => 'posts', 'action' => 'view', 1));
$expected = 'window.location = "/posts/view/1";';
$this->assertEqual($expected, $result);
}
/**
* testObject encoding with non-native methods.
*
* @return void
*/
public function testObject() {
$object = array('title' => 'New thing', 'indexes' => array(5, 6, 7, 8));
$result = $this->JsEngine->object($object);
$expected = '{"title":"New thing","indexes":[5,6,7,8]}';
$this->assertEqual($expected, $result);
$object = new JsEncodingObject();
$object->title = 'New thing';
$object->indexes = array(5,6,7,8);
$result = $this->JsEngine->object($object);
$this->assertEqual($expected, $result);
$result = $this->JsEngine->object(array('default' => 0));
$expected = '{"default":0}';
$this->assertEqual($expected, $result);
$result = $this->JsEngine->object(array(
'2007' => array(
'Spring' => array(
'1' => array('id' => 1, 'name' => 'Josh'), '2' => array('id' => 2, 'name' => 'Becky')
),
'Fall' => array(
'1' => array('id' => 1, 'name' => 'Josh'), '2' => array('id' => 2, 'name' => 'Becky')
)
),
'2006' => array(
'Spring' => array(
'1' => array('id' => 1, 'name' => 'Josh'), '2' => array('id' => 2, 'name' => 'Becky')
),
'Fall' => array(
'1' => array('id' => 1, 'name' => 'Josh'), '2' => array('id' => 2, 'name' => 'Becky')
)
)
));
$expected = '{"2007":{"Spring":{"1":{"id":1,"name":"Josh"},"2":{"id":2,"name":"Becky"}},"Fall":{"1":{"id":1,"name":"Josh"},"2":{"id":2,"name":"Becky"}}},"2006":{"Spring":{"1":{"id":1,"name":"Josh"},"2":{"id":2,"name":"Becky"}},"Fall":{"1":{"id":1,"name":"Josh"},"2":{"id":2,"name":"Becky"}}}}';
$this->assertEqual($expected, $result);
foreach (array('true' => true, 'false' => false, 'null' => null) as $expected => $data) {
$result = $this->JsEngine->object($data);
$this->assertEqual($expected, $result);
}
$object = array('title' => 'New thing', 'indexes' => array(5, 6, 7, 8), 'object' => array('inner' => array('value' => 1)));
$result = $this->JsEngine->object($object, array('prefix' => 'PREFIX', 'postfix' => 'POSTFIX'));
$this->assertPattern('/^PREFIX/', $result);
$this->assertPattern('/POSTFIX$/', $result);
$this->assertNoPattern('/.PREFIX./', $result);
$this->assertNoPattern('/.POSTFIX./', $result);
}
/**
* test Mapping of options.
*
* @return void
*/
public function testOptionMapping() {
$JsEngine = new OptionEngineHelper($this->View);
$result = $JsEngine->testMap();
$this->assertEqual($result, array());
$result = $JsEngine->testMap(array('foo' => 'bar', 'baz' => 'sho'));
$this->assertEqual($result, array('foo' => 'bar', 'baz' => 'sho'));
$result = $JsEngine->testMap(array('complete' => 'myFunc', 'type' => 'json', 'update' => '#element'));
$this->assertEqual($result, array('success' => 'myFunc', 'dataType' => 'json', 'update' => '#element'));
$result = $JsEngine->testMap(array('success' => 'myFunc', 'dataType' => 'json', 'update' => '#element'));
$this->assertEqual($result, array('success' => 'myFunc', 'dataType' => 'json', 'update' => '#element'));
}
/**
* test that option parsing escapes strings and saves what is supposed to be saved.
*
* @return void
*/
public function testOptionParsing() {
$JsEngine = new OptionEngineHelper($this->View);
$result = $JsEngine->testParseOptions(array('url' => '/posts/view/1', 'key' => 1));
$expected = 'key:1, url:"\\/posts\\/view\\/1"';
$this->assertEqual($expected, $result);
$result = $JsEngine->testParseOptions(array('url' => '/posts/view/1', 'success' => 'doSuccess'), array('success'));
$expected = 'success:doSuccess, url:"\\/posts\\/view\\/1"';
$this->assertEqual($expected, $result);
}
}
| 0001-bee | trunk/cakephp2/lib/Cake/Test/Case/View/Helper/JsHelperTest.php | PHP | gpl3 | 26,489 |
<?php
/**
* FormHelperTest file
*
* PHP 5
*
* CakePHP(tm) Tests <http://book.cakephp.org/view/1196/Testing>
* Copyright 2005-2011, Cake Software Foundation, Inc.
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice
*
* @copyright Copyright 2005-2011, Cake Software Foundation, Inc.
* @link http://book.cakephp.org/view/1196/Testing CakePHP(tm) Tests
* @package Cake.Test.Case.View.Helper
* @since CakePHP(tm) v 1.2.0.4206
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
App::uses('ClassRegistry', 'Utility');
App::uses('Controller', 'Controller');
App::uses('View', 'View');
App::uses('Model', 'Model');
App::uses('Security', 'Utility');
App::uses('CakeRequest', 'Network');
App::uses('HtmlHelper', 'View/Helper');
App::uses('FormHelper', 'View/Helper');
App::uses('Router', 'Routing');
/**
* ContactTestController class
*
* @package cake
* @package Cake.Test.Case.View.Helper
*/
class ContactTestController extends Controller {
/**
* name property
*
* @var string 'ContactTest'
*/
public $name = 'ContactTest';
/**
* uses property
*
* @var mixed null
*/
public $uses = null;
}
/**
* Contact class
*
* @package cake
* @package Cake.Test.Case.View.Helper
*/
class Contact extends CakeTestModel {
/**
* primaryKey property
*
* @var string 'id'
*/
public $primaryKey = 'id';
/**
* useTable property
*
* @var bool false
*/
public $useTable = false;
/**
* name property
*
* @var string 'Contact'
*/
public $name = 'Contact';
/**
* Default schema
*
* @var array
*/
protected $_schema = array(
'id' => array('type' => 'integer', 'null' => '', 'default' => '', 'length' => '8'),
'name' => array('type' => 'string', 'null' => '', 'default' => '', 'length' => '255'),
'email' => array('type' => 'string', 'null' => '', 'default' => '', 'length' => '255'),
'phone' => array('type' => 'string', 'null' => '', 'default' => '', 'length' => '255'),
'password' => array('type' => 'string', 'null' => '', 'default' => '', 'length' => '255'),
'published' => array('type' => 'date', 'null' => true, 'default' => null, 'length' => null),
'created' => array('type' => 'date', 'null' => '1', 'default' => '', 'length' => ''),
'updated' => array('type' => 'datetime', 'null' => '1', 'default' => '', 'length' => null),
'age' => array('type' => 'integer', 'null' => '', 'default' => '', 'length' => null)
);
/**
* validate property
*
* @var array
*/
public $validate = array(
'non_existing' => array(),
'idontexist' => array(),
'imrequired' => array('rule' => array('between', 5, 30), 'allowEmpty' => false),
'imalsorequired' => array('rule' => 'alphaNumeric', 'allowEmpty' => false),
'imrequiredtoo' => array('rule' => 'notEmpty'),
'required_one' => array('required' => array('rule' => array('notEmpty'))),
'imnotrequired' => array('required' => false, 'rule' => 'alphaNumeric', 'allowEmpty' => true),
'imalsonotrequired' => array(
'alpha' => array('rule' => 'alphaNumeric','allowEmpty' => true),
'between' => array('rule' => array('between', 5, 30)),
),
'imnotrequiredeither' => array('required' => true, 'rule' => array('between', 5, 30), 'allowEmpty' => true),
);
/**
* schema method
*
* @return void
*/
public function setSchema($schema) {
$this->_schema = $schema;
}
/**
* hasAndBelongsToMany property
*
* @var array
*/
public $hasAndBelongsToMany = array('ContactTag' => array('with' => 'ContactTagsContact'));
/**
* hasAndBelongsToMany property
*
* @var array
*/
public $belongsTo = array('User' => array('className' => 'UserForm'));
}
/**
* ContactTagsContact class
*
* @package cake
* @package Cake.Test.Case.View.Helper
*/
class ContactTagsContact extends CakeTestModel {
/**
* useTable property
*
* @var bool false
*/
public $useTable = false;
/**
* name property
*
* @var string 'Contact'
*/
public $name = 'ContactTagsContact';
/**
* Default schema
*
* @var array
*/
protected $_schema = array(
'contact_id' => array('type' => 'integer', 'null' => '', 'default' => '', 'length' => '8'),
'contact_tag_id' => array(
'type' => 'integer', 'null' => '', 'default' => '', 'length' => '8'
)
);
/**
* schema method
*
* @return void
*/
public function setSchema($schema) {
$this->_schema = $schema;
}
}
/**
* ContactNonStandardPk class
*
* @package cake
* @package Cake.Test.Case.View.Helper
*/
class ContactNonStandardPk extends Contact {
/**
* primaryKey property
*
* @var string 'pk'
*/
public $primaryKey = 'pk';
/**
* name property
*
* @var string 'ContactNonStandardPk'
*/
public $name = 'ContactNonStandardPk';
/**
* schema method
*
* @return void
*/
public function schema($field = false) {
$this->_schema = parent::schema();
$this->_schema['pk'] = $this->_schema['id'];
unset($this->_schema['id']);
return $this->_schema;
}
}
/**
* ContactTag class
*
* @package cake
* @package Cake.Test.Case.View.Helper
*/
class ContactTag extends Model {
/**
* useTable property
*
* @var bool false
*/
public $useTable = false;
/**
* schema definition
*
* @var array
*/
protected $_schema = array(
'id' => array('type' => 'integer', 'null' => false, 'default' => '', 'length' => '8'),
'name' => array('type' => 'string', 'null' => false, 'default' => '', 'length' => '255'),
'created' => array('type' => 'date', 'null' => true, 'default' => '', 'length' => ''),
'modified' => array('type' => 'datetime', 'null' => true, 'default' => '', 'length' => null)
);
}
/**
* UserForm class
*
* @package cake
* @package Cake.Test.Case.View.Helper
*/
class UserForm extends CakeTestModel {
/**
* useTable property
*
* @var bool false
*/
public $useTable = false;
/**
* primaryKey property
*
* @var string 'id'
*/
public $primaryKey = 'id';
/**
* name property
*
* @var string 'UserForm'
*/
public $name = 'UserForm';
/**
* hasMany property
*
* @var array
*/
public $hasMany = array(
'OpenidUrl' => array('className' => 'OpenidUrl', 'foreignKey' => 'user_form_id'
));
/**
* schema definition
*
* @var array
*/
protected $_schema = array(
'id' => array('type' => 'integer', 'null' => '', 'default' => '', 'length' => '8'),
'published' => array('type' => 'date', 'null' => true, 'default' => null, 'length' => null),
'other' => array('type' => 'text', 'null' => true, 'default' => null, 'length' => null),
'stuff' => array('type' => 'string', 'null' => true, 'default' => null, 'length' => 10),
'something' => array('type' => 'string', 'null' => true, 'default' => null, 'length' => 255),
'active' => array('type' => 'boolean', 'null' => false, 'default' => false),
'created' => array('type' => 'date', 'null' => '1', 'default' => '', 'length' => ''),
'updated' => array('type' => 'datetime', 'null' => '1', 'default' => '', 'length' => null)
);
}
/**
* OpenidUrl class
*
* @package cake
* @package Cake.Test.Case.View.Helper
*/
class OpenidUrl extends CakeTestModel {
/**
* useTable property
*
* @var bool false
*/
public $useTable = false;
/**
* primaryKey property
*
* @var string 'id'
*/
public $primaryKey = 'id';
/**
* name property
*
* @var string 'OpenidUrl'
*/
public $name = 'OpenidUrl';
/**
* belongsTo property
*
* @var array
*/
public $belongsTo = array('UserForm' => array(
'className' => 'UserForm', 'foreignKey' => 'user_form_id'
));
/**
* validate property
*
* @var array
*/
public $validate = array('openid_not_registered' => array());
/**
* schema method
*
* @var array
*/
protected $_schema = array(
'id' => array('type' => 'integer', 'null' => '', 'default' => '', 'length' => '8'),
'user_form_id' => array(
'type' => 'user_form_id', 'null' => '', 'default' => '', 'length' => '8'
),
'url' => array('type' => 'string', 'null' => '', 'default' => '', 'length' => '255'),
);
/**
* beforeValidate method
*
* @return void
*/
public function beforeValidate($options = array()) {
$this->invalidate('openid_not_registered');
return true;
}
}
/**
* ValidateUser class
*
* @package cake
* @package Cake.Test.Case.View.Helper
*/
class ValidateUser extends CakeTestModel {
/**
* primaryKey property
*
* @var string 'id'
*/
public $primaryKey = 'id';
/**
* useTable property
*
* @var bool false
*/
public $useTable = false;
/**
* name property
*
* @var string 'ValidateUser'
*/
public $name = 'ValidateUser';
/**
* hasOne property
*
* @var array
*/
public $hasOne = array('ValidateProfile' => array(
'className' => 'ValidateProfile', 'foreignKey' => 'user_id'
));
/**
* schema method
*
* @var array
*/
protected $_schema = array(
'id' => array('type' => 'integer', 'null' => '', 'default' => '', 'length' => '8'),
'name' => array('type' => 'string', 'null' => '', 'default' => '', 'length' => '255'),
'email' => array('type' => 'string', 'null' => '', 'default' => '', 'length' => '255'),
'balance' => array('type' => 'float', 'null' => false, 'length' => '5,2'),
'created' => array('type' => 'date', 'null' => '1', 'default' => '', 'length' => ''),
'updated' => array('type' => 'datetime', 'null' => '1', 'default' => '', 'length' => null)
);
/**
* beforeValidate method
*
* @return void
*/
public function beforeValidate($options = array()) {
$this->invalidate('email');
return false;
}
}
/**
* ValidateProfile class
*
* @package cake
* @package Cake.Test.Case.View.Helper
*/
class ValidateProfile extends CakeTestModel {
/**
* primaryKey property
*
* @var string 'id'
*/
public $primaryKey = 'id';
/**
* useTable property
*
* @var bool false
*/
public $useTable = false;
/**
* schema property
*
* @var array
*/
protected $_schema = array(
'id' => array('type' => 'integer', 'null' => '', 'default' => '', 'length' => '8'),
'user_id' => array('type' => 'integer', 'null' => '', 'default' => '', 'length' => '8'),
'full_name' => array('type' => 'string', 'null' => '', 'default' => '', 'length' => '255'),
'city' => array('type' => 'string', 'null' => '', 'default' => '', 'length' => '255'),
'created' => array('type' => 'date', 'null' => '1', 'default' => '', 'length' => ''),
'updated' => array('type' => 'datetime', 'null' => '1', 'default' => '', 'length' => null)
);
/**
* name property
*
* @var string 'ValidateProfile'
*/
public $name = 'ValidateProfile';
/**
* hasOne property
*
* @var array
*/
public $hasOne = array('ValidateItem' => array(
'className' => 'ValidateItem', 'foreignKey' => 'profile_id'
));
/**
* belongsTo property
*
* @var array
*/
public $belongsTo = array('ValidateUser' => array(
'className' => 'ValidateUser', 'foreignKey' => 'user_id'
));
/**
* beforeValidate method
*
* @return void
*/
public function beforeValidate($options = array()) {
$this->invalidate('full_name');
$this->invalidate('city');
return false;
}
}
/**
* ValidateItem class
*
* @package cake
* @package Cake.Test.Case.View.Helper
*/
class ValidateItem extends CakeTestModel {
/**
* primaryKey property
*
* @var string 'id'
*/
public $primaryKey = 'id';
/**
* useTable property
*
* @var bool false
*/
public $useTable = false;
/**
* name property
*
* @var string 'ValidateItem'
*/
public $name = 'ValidateItem';
/**
* schema property
*
* @var array
*/
protected $_schema = array(
'id' => array('type' => 'integer', 'null' => '', 'default' => '', 'length' => '8'),
'profile_id' => array('type' => 'integer', 'null' => '', 'default' => '', 'length' => '8'),
'name' => array('type' => 'text', 'null' => '', 'default' => '', 'length' => '255'),
'description' => array(
'type' => 'string', 'null' => '', 'default' => '', 'length' => '255'
),
'created' => array('type' => 'date', 'null' => '1', 'default' => '', 'length' => ''),
'updated' => array('type' => 'datetime', 'null' => '1', 'default' => '', 'length' => null)
);
/**
* belongsTo property
*
* @var array
*/
public $belongsTo = array('ValidateProfile' => array('foreignKey' => 'profile_id'));
/**
* beforeValidate method
*
* @return void
*/
public function beforeValidate($options = array()) {
$this->invalidate('description');
return false;
}
}
/**
* TestMail class
*
* @package cake
* @package Cake.Test.Case.View.Helper
*/
class TestMail extends CakeTestModel {
/**
* primaryKey property
*
* @var string 'id'
*/
public $primaryKey = 'id';
/**
* useTable property
*
* @var bool false
*/
public $useTable = false;
/**
* name property
*
* @var string 'TestMail'
*/
public $name = 'TestMail';
}
/**
* FormHelperTest class
*
* @package cake
* @package Cake.Test.Case.View.Helper
*/
class FormHelperTest extends CakeTestCase {
/**
* Fixtures to be used
*
* @var array
*/
public $fixtures = array('core.post');
/**
* Do not load the fixtures by default
*
* @var boolean
*/
public $autoFixtures = false;
/**
* setUp method
*
* @return void
*/
public function setUp() {
parent::setUp();
Configure::write('App.base', '');
$this->Controller = new ContactTestController();
$this->View = new View($this->Controller);
$this->Form = new FormHelper($this->View);
$this->Form->Html = new HtmlHelper($this->View);
$this->Form->request = new CakeRequest('contacts/add', false);
$this->Form->request->here = '/contacts/add';
$this->Form->request['action'] = 'add';
$this->Form->request->webroot = '';
$this->Form->request->base = '';
ClassRegistry::addObject('Contact', new Contact());
ClassRegistry::addObject('ContactNonStandardPk', new ContactNonStandardPk());
ClassRegistry::addObject('OpenidUrl', new OpenidUrl());
ClassRegistry::addObject('User', new UserForm());
ClassRegistry::addObject('ValidateItem', new ValidateItem());
ClassRegistry::addObject('ValidateUser', new ValidateUser());
ClassRegistry::addObject('ValidateProfile', new ValidateProfile());
$this->oldSalt = Configure::read('Security.salt');
$this->dateRegex = array(
'daysRegex' => 'preg:/(?:<option value="0?([\d]+)">\\1<\/option>[\r\n]*)*/',
'monthsRegex' => 'preg:/(?:<option value="[\d]+">[\w]+<\/option>[\r\n]*)*/',
'yearsRegex' => 'preg:/(?:<option value="([\d]+)">\\1<\/option>[\r\n]*)*/',
'hoursRegex' => 'preg:/(?:<option value="0?([\d]+)">\\1<\/option>[\r\n]*)*/',
'minutesRegex' => 'preg:/(?:<option value="([\d]+)">0?\\1<\/option>[\r\n]*)*/',
'meridianRegex' => 'preg:/(?:<option value="(am|pm)">\\1<\/option>[\r\n]*)*/',
);
Configure::write('Security.salt', 'foo!');
}
/**
* tearDown method
*
* @return void
*/
public function tearDown() {
parent::tearDown();
unset($this->Form->Html, $this->Form, $this->Controller, $this->View);
Configure::write('Security.salt', $this->oldSalt);
}
/**
* testFormCreateWithSecurity method
*
* Test form->create() with security key.
*
* @return void
*/
public function testCreateWithSecurity() {
$this->Form->request['_Token'] = array('key' => 'testKey');
$encoding = strtolower(Configure::read('App.encoding'));
$result = $this->Form->create('Contact', array('url' => '/contacts/add'));
$expected = array(
'form' => array('method' => 'post', 'action' => '/contacts/add', 'accept-charset' => $encoding, 'id' => 'ContactAddForm'),
'div' => array('style' => 'display:none;'),
array('input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST')),
array('input' => array(
'type' => 'hidden', 'name' => 'data[_Token][key]', 'value' => 'testKey', 'id'
)),
'/div'
);
$this->assertTags($result, $expected);
$result = $this->Form->create('Contact', array('url' => '/contacts/add', 'id' => 'MyForm'));
$expected['form']['id'] = 'MyForm';
$this->assertTags($result, $expected);
}
/**
* test that create() clears the fields property so it starts fresh
*
* @return void
*/
public function testCreateClearingFields() {
$this->Form->fields = array('model_id');
$this->Form->create('Contact');
$this->assertEqual($this->Form->fields, array());
}
/**
* Tests form hash generation with model-less data
*
* @return void
*/
public function testValidateHashNoModel() {
$this->Form->request['_Token'] = array('key' => 'foo');
$result = $this->Form->secure(array('anything'));
$this->assertPattern('/540ac9c60d323c22bafe997b72c0790f39a8bdef/', $result);
}
/**
* Tests that models with identical field names get resolved properly
*
* @return void
*/
public function testDuplicateFieldNameResolution() {
$result = $this->Form->create('ValidateUser');
$this->assertEqual($this->Form->entity(), array('ValidateUser'));
$result = $this->Form->input('ValidateItem.name');
$this->assertEqual($this->Form->entity(), array('ValidateItem', 'name'));
$result = $this->Form->input('ValidateUser.name');
$this->assertEqual($this->Form->entity(), array('ValidateUser', 'name'));
$this->assertPattern('/name="data\[ValidateUser\]\[name\]"/', $result);
$this->assertPattern('/type="text"/', $result);
$result = $this->Form->input('ValidateItem.name');
$this->assertEqual($this->Form->entity(), array('ValidateItem', 'name'));
$this->assertPattern('/name="data\[ValidateItem\]\[name\]"/', $result);
$this->assertPattern('/<textarea/', $result);
$result = $this->Form->input('name');
$this->assertEqual($this->Form->entity(), array('ValidateUser', 'name'));
$this->assertPattern('/name="data\[ValidateUser\]\[name\]"/', $result);
$this->assertPattern('/type="text"/', $result);
}
/**
* Tests that hidden fields generated for checkboxes don't get locked
*
* @return void
*/
public function testNoCheckboxLocking() {
$this->Form->request['_Token'] = array('key' => 'foo');
$this->assertIdentical($this->Form->fields, array());
$this->Form->checkbox('check', array('value' => '1'));
$this->assertIdentical($this->Form->fields, array('check'));
}
/**
* testFormSecurityFields method
*
* Test generation of secure form hash generation.
*
* @return void
*/
public function testFormSecurityFields() {
$key = 'testKey';
$fields = array('Model.password', 'Model.username', 'Model.valid' => '0');
$this->Form->request['_Token'] = array('key' => $key);
$result = $this->Form->secure($fields);
$expected = Security::hash(serialize($fields) . Configure::read('Security.salt'));
$expected .= ':' . 'Model.valid';
$expected = array(
'div' => array('style' => 'display:none;'),
array('input' => array(
'type' => 'hidden', 'name' => 'data[_Token][fields]',
'value' => urlencode($expected), 'id' => 'preg:/TokenFields\d+/'
)),
array('input' => array(
'type' => 'hidden', 'name' => 'data[_Token][unlocked]',
'value' => '', 'id' => 'preg:/TokenUnlocked\d+/'
)),
'/div'
);
$this->assertTags($result, $expected);
}
/**
* Tests correct generation of number fields for double and float fields
*
* @return void
*/
public function testTextFieldGenerationForFloats() {
$model = ClassRegistry::getObject('Contact');
$model->setSchema(array('foo' => array(
'type' => 'float',
'null' => false,
'default' => null,
'length' => null
)));
$this->Form->create('Contact');
$result = $this->Form->input('foo');
$expected = array(
'div' => array('class' => 'input number'),
'label' => array('for' => 'ContactFoo'),
'Foo',
'/label',
array('input' => array(
'type' => 'number',
'name' => 'data[Contact][foo]',
'id' => 'ContactFoo',
'step' => 'any'
)),
'/div'
);
$this->assertTags($result, $expected);
$result = $this->Form->input('foo', array('step' => 0.5));
$expected = array(
'div' => array('class' => 'input number'),
'label' => array('for' => 'ContactFoo'),
'Foo',
'/label',
array('input' => array(
'type' => 'number',
'name' => 'data[Contact][foo]',
'id' => 'ContactFoo',
'step' => '0.5'
)),
'/div'
);
$this->assertTags($result, $expected);
}
/**
* Tests correct generation of number fields for integer fields
*
* @access public
* @return void
*/
public function testTextFieldTypeNumberGenerationForIntegers() {
$model = ClassRegistry::getObject('Contact');
$model->setSchema(array('foo' => array(
'type' => 'integer',
'null' => false,
'default' => null,
'length' => null
)));
$this->Form->create('Contact');
$result = $this->Form->input('foo');
$expected = array(
'div' => array('class' => 'input number'),
'label' => array('for' => 'ContactFoo'),
'Foo',
'/label',
array('input' => array(
'type' => 'number', 'name' => 'data[Contact][foo]',
'id' => 'ContactFoo'
)),
'/div'
);
$this->assertTags($result, $expected);
}
/**
* testFormSecurityMultipleFields method
*
* Test secure() with multiple row form. Ensure hash is correct.
*
* @return void
*/
public function testFormSecurityMultipleFields() {
$key = 'testKey';
$fields = array(
'Model.0.password', 'Model.0.username', 'Model.0.hidden' => 'value',
'Model.0.valid' => '0', 'Model.1.password', 'Model.1.username',
'Model.1.hidden' => 'value', 'Model.1.valid' => '0'
);
$this->Form->request['_Token'] = array('key' => $key);
$result = $this->Form->secure($fields);
$hash = '51e3b55a6edd82020b3f29c9ae200e14bbeb7ee5%3AModel.0.hidden%7CModel.0.valid';
$hash .= '%7CModel.1.hidden%7CModel.1.valid';
$expected = array(
'div' => array('style' => 'display:none;'),
array('input' => array(
'type' => 'hidden', 'name' => 'data[_Token][fields]',
'value' => $hash, 'id' => 'preg:/TokenFields\d+/'
)),
array('input' => array(
'type' => 'hidden', 'name' => 'data[_Token][unlocked]',
'value' => '', 'id' => 'preg:/TokenUnlocked\d+/'
)),
'/div'
);
$this->assertTags($result, $expected);
}
/**
* testFormSecurityMultipleSubmitButtons
*
* test form submit generation and ensure that _Token is only created on end()
*
* @return void
*/
public function testFormSecurityMultipleSubmitButtons() {
$key = 'testKey';
$this->Form->request['_Token'] = array('key' => $key);
$this->Form->create('Addresses');
$this->Form->input('Address.title');
$this->Form->input('Address.first_name');
$result = $this->Form->submit('Save', array('name' => 'save'));
$expected = array(
'div' => array('class' => 'submit'),
'input' => array('type' => 'submit', 'name' => 'save', 'value' => 'Save'),
'/div',
);
$this->assertTags($result, $expected);
$result = $this->Form->submit('Cancel', array('name' => 'cancel'));
$expected = array(
'div' => array('class' => 'submit'),
'input' => array('type' => 'submit', 'name' => 'cancel', 'value' => 'Cancel'),
'/div',
);
$this->assertTags($result, $expected);
$result = $this->Form->end(null);
$expected = array(
'div' => array('style' => 'display:none;'),
array('input' => array(
'type' => 'hidden', 'name' => 'data[_Token][fields]',
'value' => 'preg:/.+/', 'id' => 'preg:/TokenFields\d+/'
)),
array('input' => array(
'type' => 'hidden', 'name' => 'data[_Token][unlocked]',
'value' => 'cancel%7Csave', 'id' => 'preg:/TokenUnlocked\d+/'
)),
'/div'
);
$this->assertTags($result, $expected);
}
/**
* Test that the correct fields are unlocked for image submits with no names.
*
* @return void
*/
public function testSecuritySubmitImageNoName() {
$key = 'testKey';
$this->Form->request['_Token'] = array('key' => $key);
$this->Form->create('User');
$result = $this->Form->submit('save.png');
$expected = array(
'div' => array('class' => 'submit'),
'input' => array('type' => 'image', 'src' => 'img/save.png'),
'/div'
);
$this->assertTags($result, $expected);
$this->assertEquals(array('x', 'y'), $this->Form->unlockField());
}
/**
* Test that the correct fields are unlocked for image submits with names.
*
* @return void
*/
public function testSecuritySubmitImageName() {
$key = 'testKey';
$this->Form->request['_Token'] = array('key' => $key);
$this->Form->create('User');
$result = $this->Form->submit('save.png', array('name' => 'test'));
$expected = array(
'div' => array('class' => 'submit'),
'input' => array('type' => 'image', 'name' => 'test', 'src' => 'img/save.png'),
'/div'
);
$this->assertTags($result, $expected);
$this->assertEquals(array('test', 'test_x', 'test_y'), $this->Form->unlockField());
}
/**
* testFormSecurityMultipleInputFields method
*
* Test secure form creation with multiple row creation. Checks hidden, text, checkbox field types
*
* @return void
*/
public function testFormSecurityMultipleInputFields() {
$key = 'testKey';
$this->Form->request['_Token'] = array('key' => $key);
$this->Form->create('Addresses');
$this->Form->hidden('Addresses.0.id', array('value' => '123456'));
$this->Form->input('Addresses.0.title');
$this->Form->input('Addresses.0.first_name');
$this->Form->input('Addresses.0.last_name');
$this->Form->input('Addresses.0.address');
$this->Form->input('Addresses.0.city');
$this->Form->input('Addresses.0.phone');
$this->Form->input('Addresses.0.primary', array('type' => 'checkbox'));
$this->Form->hidden('Addresses.1.id', array('value' => '654321'));
$this->Form->input('Addresses.1.title');
$this->Form->input('Addresses.1.first_name');
$this->Form->input('Addresses.1.last_name');
$this->Form->input('Addresses.1.address');
$this->Form->input('Addresses.1.city');
$this->Form->input('Addresses.1.phone');
$this->Form->input('Addresses.1.primary', array('type' => 'checkbox'));
$result = $this->Form->secure($this->Form->fields);
$hash = 'c9118120e680a7201b543f562e5301006ccfcbe2%3AAddresses.0.id%7CAddresses.1.id';
$expected = array(
'div' => array('style' => 'display:none;'),
array('input' => array(
'type' => 'hidden', 'name' => 'data[_Token][fields]',
'value' => $hash, 'id' => 'preg:/TokenFields\d+/'
)),
array('input' => array(
'type' => 'hidden', 'name' => 'data[_Token][unlocked]',
'value' => '', 'id' => 'preg:/TokenUnlocked\d+/'
)),
'/div'
);
$this->assertTags($result, $expected);
}
/**
* Test form security with Model.field.0 style inputs
*
* @return void
*/
function testFormSecurityArrayFields() {
$key = 'testKey';
$this->Form->request->params['_Token']['key'] = $key;
$this->Form->create('Address');
$this->Form->input('Address.primary.1');
$this->assertEqual('Address.primary', $this->Form->fields[0]);
}
/**
* testFormSecurityMultipleInputDisabledFields method
*
* test secure form generation with multiple records and disabled fields.
*
* @return void
*/
public function testFormSecurityMultipleInputDisabledFields() {
$key = 'testKey';
$this->Form->request->params['_Token'] = array(
'key' => $key,
'unlockedFields' => array('first_name', 'address')
);
$this->Form->create();
$this->Form->hidden('Addresses.0.id', array('value' => '123456'));
$this->Form->input('Addresses.0.title');
$this->Form->input('Addresses.0.first_name');
$this->Form->input('Addresses.0.last_name');
$this->Form->input('Addresses.0.address');
$this->Form->input('Addresses.0.city');
$this->Form->input('Addresses.0.phone');
$this->Form->hidden('Addresses.1.id', array('value' => '654321'));
$this->Form->input('Addresses.1.title');
$this->Form->input('Addresses.1.first_name');
$this->Form->input('Addresses.1.last_name');
$this->Form->input('Addresses.1.address');
$this->Form->input('Addresses.1.city');
$this->Form->input('Addresses.1.phone');
$result = $this->Form->secure($this->Form->fields);
$hash = '629b6536dcece48aa41a117045628ce602ccbbb2%3AAddresses.0.id%7CAddresses.1.id';
$expected = array(
'div' => array('style' => 'display:none;'),
array('input' => array(
'type' => 'hidden', 'name' => 'data[_Token][fields]',
'value' => $hash, 'id' => 'preg:/TokenFields\d+/'
)),
array('input' => array(
'type' => 'hidden', 'name' => 'data[_Token][unlocked]',
'value' => 'address%7Cfirst_name', 'id' => 'preg:/TokenUnlocked\d+/'
)),
'/div'
);
$this->assertTags($result, $expected);
}
/**
* testFormSecurityInputDisabledFields method
*
* Test single record form with disabled fields.
*
* @return void
*/
public function testFormSecurityInputUnlockedFields() {
$key = 'testKey';
$this->Form->request['_Token'] = array(
'key' => $key,
'unlockedFields' => array('first_name', 'address')
);
$this->Form->create();
$this->assertEquals($this->Form->request['_Token']['unlockedFields'], $this->Form->unlockField());
$this->Form->hidden('Addresses.id', array('value' => '123456'));
$this->Form->input('Addresses.title');
$this->Form->input('Addresses.first_name');
$this->Form->input('Addresses.last_name');
$this->Form->input('Addresses.address');
$this->Form->input('Addresses.city');
$this->Form->input('Addresses.phone');
$result = $this->Form->fields;
$expected = array(
'Addresses.id' => '123456', 'Addresses.title', 'Addresses.last_name',
'Addresses.city', 'Addresses.phone'
);
$this->assertEqual($expected, $result);
$result = $this->Form->secure($expected);
$hash = '2981c38990f3f6ba935e6561dc77277966fabd6d%3AAddresses.id';
$expected = array(
'div' => array('style' => 'display:none;'),
array('input' => array(
'type' => 'hidden', 'name' => 'data[_Token][fields]',
'value' => $hash, 'id' => 'preg:/TokenFields\d+/'
)),
array('input' => array(
'type' => 'hidden', 'name' => 'data[_Token][unlocked]',
'value' => 'address%7Cfirst_name', 'id' => 'preg:/TokenUnlocked\d+/'
)),
'/div'
);
$this->assertTags($result, $expected);
}
/**
* test securing inputs with custom name attributes.
*
* @return void
*/
public function testFormSecureWithCustomNameAttribute() {
$this->Form->request->params['_Token']['key'] = 'testKey';
$this->Form->text('UserForm.published', array('name' => 'data[User][custom]'));
$this->assertEqual('User.custom', $this->Form->fields[0]);
$this->Form->text('UserForm.published', array('name' => 'data[User][custom][another][value]'));
$this->assertEqual('User.custom.another.value', $this->Form->fields[1]);
}
/**
* testFormSecuredInput method
*
* Test generation of entire secure form, assertions made on input() output.
*
* @return void
*/
public function testFormSecuredInput() {
$this->Form->request['_Token'] = array('key' => 'testKey');
$result = $this->Form->create('Contact', array('url' => '/contacts/add'));
$encoding = strtolower(Configure::read('App.encoding'));
$expected = array(
'form' => array('method' => 'post', 'action' => '/contacts/add', 'accept-charset' => $encoding, 'id' => 'ContactAddForm'),
'div' => array('style' => 'display:none;'),
array('input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST')),
array('input' => array(
'type' => 'hidden', 'name' => 'data[_Token][key]',
'value' => 'testKey', 'id' => 'preg:/Token\d+/'
)),
'/div'
);
$this->assertTags($result, $expected);
$result = $this->Form->input('UserForm.published', array('type' => 'text'));
$expected = array(
'div' => array('class' => 'input text'),
'label' => array('for' => 'UserFormPublished'),
'Published',
'/label',
array('input' => array(
'type' => 'text', 'name' => 'data[UserForm][published]',
'id' => 'UserFormPublished'
)),
'/div'
);
$this->assertTags($result, $expected);
$result = $this->Form->input('UserForm.other', array('type' => 'text'));
$expected = array(
'div' => array('class' => 'input text'),
'label' => array('for' => 'UserFormOther'),
'Other',
'/label',
array('input' => array(
'type' => 'text', 'name' => 'data[UserForm][other]',
'id' => 'UserFormOther'
)),
'/div'
);
$this->assertTags($result, $expected);
$result = $this->Form->hidden('UserForm.stuff');
$expected = array('input' => array(
'type' => 'hidden', 'name' => 'data[UserForm][stuff]',
'id' => 'UserFormStuff'
));
$this->assertTags($result, $expected);
$result = $this->Form->hidden('UserForm.hidden', array('value' => '0'));
$expected = array('input' => array(
'type' => 'hidden', 'name' => 'data[UserForm][hidden]',
'value' => '0', 'id' => 'UserFormHidden'
));
$this->assertTags($result, $expected);
$result = $this->Form->input('UserForm.something', array('type' => 'checkbox'));
$expected = array(
'div' => array('class' => 'input checkbox'),
array('input' => array(
'type' => 'hidden', 'name' => 'data[UserForm][something]',
'value' => '0', 'id' => 'UserFormSomething_'
)),
array('input' => array(
'type' => 'checkbox', 'name' => 'data[UserForm][something]',
'value' => '1', 'id' => 'UserFormSomething'
)),
'label' => array('for' => 'UserFormSomething'),
'Something',
'/label',
'/div'
);
$this->assertTags($result, $expected);
$result = $this->Form->fields;
$expected = array(
'UserForm.published', 'UserForm.other', 'UserForm.stuff' => '',
'UserForm.hidden' => '0', 'UserForm.something'
);
$this->assertEqual($expected, $result);
$hash = 'bd7c4a654e5361f9a433a43f488ff9a1065d0aaf%3AUserForm.hidden%7CUserForm.stuff';
$result = $this->Form->secure($this->Form->fields);
$expected = array(
'div' => array('style' => 'display:none;'),
array('input' => array(
'type' => 'hidden', 'name' => 'data[_Token][fields]',
'value' => $hash, 'id' => 'preg:/TokenFields\d+/'
)),
array('input' => array(
'type' => 'hidden', 'name' => 'data[_Token][unlocked]',
'value' => '', 'id' => 'preg:/TokenUnlocked\d+/'
)),
'/div'
);
$this->assertTags($result, $expected);
}
/**
* Tests that the correct keys are added to the field hash index
*
* @return void
*/
public function testFormSecuredFileInput() {
$this->Form->request['_Token'] = array('key' => 'testKey');
$this->assertEqual($this->Form->fields, array());
$result = $this->Form->file('Attachment.file');
$expected = array (
'Attachment.file.name', 'Attachment.file.type', 'Attachment.file.tmp_name',
'Attachment.file.error', 'Attachment.file.size'
);
$this->assertEqual($this->Form->fields, $expected);
}
/**
* test that multiple selects keys are added to field hash
*
* @return void
*/
public function testFormSecuredMultipleSelect() {
$this->Form->request['_Token'] = array('key' => 'testKey');
$this->assertEqual($this->Form->fields, array());
$options = array('1' => 'one', '2' => 'two');
$this->Form->select('Model.select', $options);
$expected = array('Model.select');
$this->assertEqual($this->Form->fields, $expected);
$this->Form->fields = array();
$this->Form->select('Model.select', $options, array('multiple' => true));
$this->assertEqual($this->Form->fields, $expected);
}
/**
* testFormSecuredRadio method
*
* @return void
*/
public function testFormSecuredRadio() {
$this->Form->request['_Token'] = array('key' => 'testKey');
$this->assertEqual($this->Form->fields, array());
$options = array('1' => 'option1', '2' => 'option2');
$this->Form->radio('Test.test', $options);
$expected = array('Test.test');
$this->assertEqual($this->Form->fields, $expected);
}
/**
* testDisableSecurityUsingForm method
*
* @return void
*/
public function testDisableSecurityUsingForm() {
$this->Form->request['_Token'] = array(
'key' => 'testKey',
'disabledFields' => array()
);
$this->Form->create();
$this->Form->hidden('Addresses.id', array('value' => '123456'));
$this->Form->input('Addresses.title');
$this->Form->input('Addresses.first_name', array('secure' => false));
$this->Form->input('Addresses.city', array('type' => 'textarea', 'secure' => false));
$this->Form->input('Addresses.zip', array(
'type' => 'select', 'options' => array(1,2), 'secure' => false
));
$result = $this->Form->fields;
$expected = array(
'Addresses.id' => '123456', 'Addresses.title',
);
$this->assertEqual($expected, $result);
}
/**
* test disableField
*
* @return void
*/
public function testUnlockFieldAddsToList() {
$this->Form->request['_Token'] = array(
'key' => 'testKey',
'unlockedFields' => array()
);
$this->Form->create('Contact');
$this->Form->unlockField('Contact.name');
$this->Form->text('Contact.name');
$this->assertEquals(array('Contact.name'), $this->Form->unlockField());
$this->assertEquals(array(), $this->Form->fields);
}
/**
* test unlockField removing from fields array.
*
* @return void
*/
public function testUnlockFieldRemovingFromFields() {
$this->Form->request['_Token'] = array(
'key' => 'testKey',
'unlockedFields' => array()
);
$this->Form->create('Contact');
$this->Form->hidden('Contact.id', array('value' => 1));
$this->Form->text('Contact.name');
$this->assertEquals(1, $this->Form->fields['Contact.id'], 'Hidden input should be secured.');
$this->assertTrue(in_array('Contact.name', $this->Form->fields), 'Field should be secured.');
$this->Form->unlockField('Contact.name');
$this->Form->unlockField('Contact.id');
$this->assertEquals(array(), $this->Form->fields);
}
/**
* testPasswordValidation method
*
* test validation errors on password input.
*
* @return void
*/
public function testPasswordValidation() {
$Contact = ClassRegistry::getObject('Contact');
$Contact->validationErrors['password'] = array('Please provide a password');
$result = $this->Form->input('Contact.password');
$expected = array(
'div' => array('class' => 'input password error'),
'label' => array('for' => 'ContactPassword'),
'Password',
'/label',
'input' => array(
'type' => 'password', 'name' => 'data[Contact][password]',
'id' => 'ContactPassword', 'class' => 'form-error'
),
array('div' => array('class' => 'error-message')),
'Please provide a password',
'/div',
'/div'
);
$this->assertTags($result, $expected);
}
/**
* testEmptyErrorValidation method
*
* test validation error div when validation message is an empty string
*
* @access public
* @return void
*/
function testEmptyErrorValidation() {
$this->Form->validationErrors['Contact']['password'] = '';
$result = $this->Form->input('Contact.password');
$expected = array(
'div' => array('class' => 'input password error'),
'label' => array('for' => 'ContactPassword'),
'Password',
'/label',
'input' => array(
'type' => 'password', 'name' => 'data[Contact][password]',
'id' => 'ContactPassword', 'class' => 'form-error'
),
array('div' => array('class' => 'error-message')),
array(),
'/div',
'/div'
);
$this->assertTags($result, $expected);
}
/**
* testEmptyInputErrorValidation method
*
* test validation error div when validation message is overriden by an empty string when calling input()
*
* @access public
* @return void
*/
function testEmptyInputErrorValidation() {
$this->Form->validationErrors['Contact']['password'] = 'Please provide a password';
$result = $this->Form->input('Contact.password', array('error' => ''));
$expected = array(
'div' => array('class' => 'input password error'),
'label' => array('for' => 'ContactPassword'),
'Password',
'/label',
'input' => array(
'type' => 'password', 'name' => 'data[Contact][password]',
'id' => 'ContactPassword', 'class' => 'form-error'
),
array('div' => array('class' => 'error-message')),
array(),
'/div',
'/div'
);
$this->assertTags($result, $expected);
}
/**
* testFormValidationAssociated method
*
* test display of form errors in conjunction with model::validates.
*
* @return void
*/
public function testFormValidationAssociated() {
$this->UserForm = ClassRegistry::getObject('UserForm');
$this->UserForm->OpenidUrl = ClassRegistry::getObject('OpenidUrl');
$data = array(
'UserForm' => array('name' => 'user'),
'OpenidUrl' => array('url' => 'http://www.cakephp.org')
);
$result = $this->UserForm->OpenidUrl->create($data);
$this->assertFalse(empty($result));
$this->assertFalse($this->UserForm->OpenidUrl->validates());
$result = $this->Form->create('UserForm', array('type' => 'post', 'action' => 'login'));
$encoding = strtolower(Configure::read('App.encoding'));
$expected = array(
'form' => array(
'method' => 'post', 'action' => '/user_forms/login', 'id' => 'UserFormLoginForm',
'accept-charset' => $encoding
),
'div' => array('style' => 'display:none;'),
'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'),
'/div'
);
$this->assertTags($result, $expected);
$result = $this->Form->error(
'OpenidUrl.openid_not_registered', 'Error, not registered', array('wrap' => false)
);
$this->assertEqual($result, 'Error, not registered');
unset($this->UserForm->OpenidUrl, $this->UserForm);
}
/**
* testFormValidationAssociatedFirstLevel method
*
* test form error display with associated model.
*
* @return void
*/
public function testFormValidationAssociatedFirstLevel() {
$this->ValidateUser = ClassRegistry::getObject('ValidateUser');
$this->ValidateUser->ValidateProfile = ClassRegistry::getObject('ValidateProfile');
$data = array(
'ValidateUser' => array('name' => 'mariano'),
'ValidateProfile' => array('full_name' => 'Mariano Iglesias')
);
$result = $this->ValidateUser->create($data);
$this->assertFalse(empty($result));
$this->assertFalse($this->ValidateUser->validates());
$this->assertFalse($this->ValidateUser->ValidateProfile->validates());
$result = $this->Form->create('ValidateUser', array('type' => 'post', 'action' => 'add'));
$encoding = strtolower(Configure::read('App.encoding'));
$expected = array(
'form' => array('method' => 'post', 'action' => '/validate_users/add', 'id','accept-charset' => $encoding),
'div' => array('style' => 'display:none;'),
'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'),
'/div'
);
$this->assertTags($result, $expected);
$result = $this->Form->error(
'ValidateUser.email', 'Invalid email', array('wrap' => false)
);
$this->assertEqual($result, 'Invalid email');
$result = $this->Form->error(
'ValidateProfile.full_name', 'Invalid name', array('wrap' => false)
);
$this->assertEqual($result, 'Invalid name');
$result = $this->Form->error(
'ValidateProfile.city', 'Invalid city', array('wrap' => false)
);
$this->assertEqual($result, 'Invalid city');
unset($this->ValidateUser->ValidateProfile);
unset($this->ValidateUser);
}
/**
* testFormValidationAssociatedSecondLevel method
*
* test form error display with associated model.
*
* @return void
*/
public function testFormValidationAssociatedSecondLevel() {
$this->ValidateUser = ClassRegistry::getObject('ValidateUser');
$this->ValidateUser->ValidateProfile = ClassRegistry::getObject('ValidateProfile');
$this->ValidateUser->ValidateProfile->ValidateItem = ClassRegistry::getObject('ValidateItem');
$data = array(
'ValidateUser' => array('name' => 'mariano'),
'ValidateProfile' => array('full_name' => 'Mariano Iglesias'),
'ValidateItem' => array('name' => 'Item')
);
$result = $this->ValidateUser->create($data);
$this->assertFalse(empty($result));
$this->assertFalse($this->ValidateUser->validates());
$this->assertFalse($this->ValidateUser->ValidateProfile->validates());
$this->assertFalse($this->ValidateUser->ValidateProfile->ValidateItem->validates());
$result = $this->Form->create('ValidateUser', array('type' => 'post', 'action' => 'add'));
$encoding = strtolower(Configure::read('App.encoding'));
$expected = array(
'form' => array('method' => 'post', 'action' => '/validate_users/add', 'id','accept-charset' => $encoding),
'div' => array('style' => 'display:none;'),
'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'),
'/div'
);
$this->assertTags($result, $expected);
$result = $this->Form->error(
'ValidateUser.email', 'Invalid email', array('wrap' => false)
);
$this->assertEqual($result, 'Invalid email');
$result = $this->Form->error(
'ValidateProfile.full_name', 'Invalid name', array('wrap' => false)
);
$this->assertEqual($result, 'Invalid name');
$result = $this->Form->error(
'ValidateProfile.city', 'Invalid city', array('wrap' => false)
);
$result = $this->Form->error(
'ValidateItem.description', 'Invalid description', array('wrap' => false)
);
$this->assertEqual($result, 'Invalid description');
unset($this->ValidateUser->ValidateProfile->ValidateItem);
unset($this->ValidateUser->ValidateProfile);
unset($this->ValidateUser);
}
/**
* testFormValidationMultiRecord method
*
* test form error display with multiple records.
*
* @return void
*/
public function testFormValidationMultiRecord() {
$Contact = ClassRegistry::getObject('Contact');
$Contact->validationErrors[2] = array(
'name' => array('This field cannot be left blank')
);
$result = $this->Form->input('Contact.2.name');
$expected = array(
'div' => array('class' => 'input text error'),
'label' => array('for' => 'Contact2Name'),
'Name',
'/label',
'input' => array(
'type' => 'text', 'name' => 'data[Contact][2][name]', 'id' => 'Contact2Name',
'class' => 'form-error', 'maxlength' => 255
),
array('div' => array('class' => 'error-message')),
'This field cannot be left blank',
'/div',
'/div'
);
$this->assertTags($result, $expected);
}
/**
* testMultipleInputValidation method
*
* test multiple record form validation error display.
*
* @return void
*/
public function testMultipleInputValidation() {
$Address = ClassRegistry::init(array('class' => 'Address', 'table' => false, 'ds' => 'test'));
$Address->validationErrors[0] = array(
'title' => array('This field cannot be empty'),
'first_name' => array('This field cannot be empty')
);
$Address->validationErrors[1] = array(
'last_name' => array('You must have a last name')
);
$this->Form->create();
$result = $this->Form->input('Address.0.title');
$expected = array(
'div' => array('class'),
'label' => array('for'),
'preg:/[^<]+/',
'/label',
'input' => array(
'type' => 'text', 'name', 'id', 'class' => 'form-error'
),
array('div' => array('class' => 'error-message')),
'This field cannot be empty',
'/div',
'/div'
);
$this->assertTags($result, $expected);
$result = $this->Form->input('Address.0.first_name');
$expected = array(
'div' => array('class'),
'label' => array('for'),
'preg:/[^<]+/',
'/label',
'input' => array('type' => 'text', 'name', 'id', 'class' => 'form-error'),
array('div' => array('class' => 'error-message')),
'This field cannot be empty',
'/div',
'/div'
);
$this->assertTags($result, $expected);
$result = $this->Form->input('Address.0.last_name');
$expected = array(
'div' => array('class'),
'label' => array('for'),
'preg:/[^<]+/',
'/label',
'input' => array('type' => 'text', 'name', 'id'),
'/div'
);
$this->assertTags($result, $expected);
$result = $this->Form->input('Address.1.last_name');
$expected = array(
'div' => array('class'),
'label' => array('for'),
'preg:/[^<]+/',
'/label',
'input' => array(
'type' => 'text', 'name' => 'preg:/[^<]+/',
'id' => 'preg:/[^<]+/', 'class' => 'form-error'
),
array('div' => array('class' => 'error-message')),
'You must have a last name',
'/div',
'/div'
);
$this->assertTags($result, $expected);
}
/**
* testInput method
*
* Test various incarnations of input().
*
* @return void
*/
public function testInput() {
$result = $this->Form->input('ValidateUser.balance');
$expected = array(
'div' => array('class'),
'label' => array('for'),
'Balance',
'/label',
'input' => array('name', 'type' => 'number', 'maxlength' => 8, 'id'),
'/div',
);
$this->assertTags($result, $expected);
$result = $this->Form->input('Contact.email', array('id' => 'custom'));
$expected = array(
'div' => array('class' => 'input text'),
'label' => array('for' => 'custom'),
'Email',
'/label',
array('input' => array(
'type' => 'text', 'name' => 'data[Contact][email]',
'id' => 'custom', 'maxlength' => 255
)),
'/div'
);
$this->assertTags($result, $expected);
$result = $this->Form->input('Contact.email', array('div' => array('class' => false)));
$expected = array(
'<div',
'label' => array('for' => 'ContactEmail'),
'Email',
'/label',
array('input' => array(
'type' => 'text', 'name' => 'data[Contact][email]',
'id' => 'ContactEmail', 'maxlength' => 255
)),
'/div'
);
$this->assertTags($result, $expected);
$result = $this->Form->hidden('Contact.idontexist');
$expected = array('input' => array(
'type' => 'hidden', 'name' => 'data[Contact][idontexist]',
'id' => 'ContactIdontexist'
));
$this->assertTags($result, $expected);
$result = $this->Form->input('Contact.email', array('type' => 'text'));
$expected = array(
'div' => array('class' => 'input text'),
'label' => array('for' => 'ContactEmail'),
'Email',
'/label',
array('input' => array(
'type' => 'text', 'name' => 'data[Contact][email]',
'id' => 'ContactEmail'
)),
'/div'
);
$this->assertTags($result, $expected);
$result = $this->Form->input('Contact.5.email', array('type' => 'text'));
$expected = array(
'div' => array('class' => 'input text'),
'label' => array('for' => 'Contact5Email'),
'Email',
'/label',
array('input' => array(
'type' => 'text', 'name' => 'data[Contact][5][email]',
'id' => 'Contact5Email'
)),
'/div'
);
$this->assertTags($result, $expected);
$result = $this->Form->input('Contact.password');
$expected = array(
'div' => array('class' => 'input password'),
'label' => array('for' => 'ContactPassword'),
'Password',
'/label',
array('input' => array(
'type' => 'password', 'name' => 'data[Contact][password]',
'id' => 'ContactPassword'
)),
'/div'
);
$this->assertTags($result, $expected);
$result = $this->Form->input('Contact.email', array(
'type' => 'file', 'class' => 'textbox'
));
$expected = array(
'div' => array('class' => 'input file'),
'label' => array('for' => 'ContactEmail'),
'Email',
'/label',
array('input' => array(
'type' => 'file', 'name' => 'data[Contact][email]', 'class' => 'textbox',
'id' => 'ContactEmail'
)),
'/div'
);
$this->assertTags($result, $expected);
$this->Form->request->data = array('Contact' => array('phone' => 'Hello & World > weird chars'));
$result = $this->Form->input('Contact.phone');
$expected = array(
'div' => array('class' => 'input text'),
'label' => array('for' => 'ContactPhone'),
'Phone',
'/label',
array('input' => array(
'type' => 'text', 'name' => 'data[Contact][phone]',
'value' => 'Hello & World > weird chars',
'id' => 'ContactPhone', 'maxlength' => 255
)),
'/div'
);
$this->assertTags($result, $expected);
$this->Form->request->data['Model']['0']['OtherModel']['field'] = 'My value';
$result = $this->Form->input('Model.0.OtherModel.field', array('id' => 'myId'));
$expected = array(
'div' => array('class' => 'input text'),
'label' => array('for' => 'myId'),
'Field',
'/label',
'input' => array(
'type' => 'text', 'name' => 'data[Model][0][OtherModel][field]',
'value' => 'My value', 'id' => 'myId'
),
'/div'
);
$this->assertTags($result, $expected);
unset($this->Form->request->data);
$Contact = ClassRegistry::getObject('Contact');
$Contact->validationErrors['field'] = array('Badness!');
$result = $this->Form->input('Contact.field');
$expected = array(
'div' => array('class' => 'input text error'),
'label' => array('for' => 'ContactField'),
'Field',
'/label',
'input' => array(
'type' => 'text', 'name' => 'data[Contact][field]',
'id' => 'ContactField', 'class' => 'form-error'
),
array('div' => array('class' => 'error-message')),
'Badness!',
'/div',
'/div'
);
$this->assertTags($result, $expected);
$result = $this->Form->input('Contact.field', array(
'div' => false, 'error' => array('attributes' => array('wrap' => 'span'))
));
$expected = array(
'label' => array('for' => 'ContactField'),
'Field',
'/label',
'input' => array(
'type' => 'text', 'name' => 'data[Contact][field]',
'id' => 'ContactField', 'class' => 'form-error'
),
array('span' => array('class' => 'error-message')),
'Badness!',
'/span'
);
$this->assertTags($result, $expected);
$result = $this->Form->input('Contact.field', array(
'div' => array('tag' => 'span'), 'error' => array('attributes' => array('wrap' => false))
));
$expected = array(
'span' => array('class' => 'input text error'),
'label' => array('for' => 'ContactField'),
'Field',
'/label',
'input' => array(
'type' => 'text', 'name' => 'data[Contact][field]',
'id' => 'ContactField', 'class' => 'form-error'
),
'Badness!',
'/span'
);
$this->assertTags($result, $expected);
$result = $this->Form->input('Contact.field', array('after' => 'A message to you, Rudy'));
$expected = array(
'div' => array('class' => 'input text error'),
'label' => array('for' => 'ContactField'),
'Field',
'/label',
'input' => array(
'type' => 'text', 'name' => 'data[Contact][field]',
'id' => 'ContactField', 'class' => 'form-error'
),
'A message to you, Rudy',
array('div' => array('class' => 'error-message')),
'Badness!',
'/div',
'/div'
);
$this->assertTags($result, $expected);
$this->Form->setEntity(null);
$this->Form->setEntity('Contact.field');
$result = $this->Form->input('Contact.field', array(
'after' => 'A message to you, Rudy', 'error' => false
));
$expected = array(
'div' => array('class' => 'input text'),
'label' => array('for' => 'ContactField'),
'Field',
'/label',
'input' => array('type' => 'text', 'name' => 'data[Contact][field]', 'id' => 'ContactField', 'class' => 'form-error'),
'A message to you, Rudy',
'/div'
);
$this->assertTags($result, $expected);
$result = $this->Form->input('Object.field', array('after' => 'A message to you, Rudy'));
$expected = array(
'div' => array('class' => 'input text'),
'label' => array('for' => 'ObjectField'),
'Field',
'/label',
'input' => array('type' => 'text', 'name' => 'data[Object][field]', 'id' => 'ObjectField'),
'A message to you, Rudy',
'/div'
);
$this->assertTags($result, $expected);
$Contact->validationErrors['field'] = array('minLength');
$result = $this->Form->input('Contact.field', array(
'error' => array(
'minLength' => 'Le login doit contenir au moins 2 caractères',
'maxLength' => 'login too large'
)
));
$expected = array(
'div' => array('class' => 'input text error'),
'label' => array('for' => 'ContactField'),
'Field',
'/label',
'input' => array('type' => 'text', 'name' => 'data[Contact][field]', 'id' => 'ContactField', 'class' => 'form-error'),
array('div' => array('class' => 'error-message')),
'Le login doit contenir au moins 2 caractères',
'/div',
'/div'
);
$this->assertTags($result, $expected);
$Contact->validationErrors['field'] = array('maxLength');
$result = $this->Form->input('Contact.field', array(
'error' => array(
'attributes' => array('wrap' => 'span', 'rel' => 'fake'),
'minLength' => 'Le login doit contenir au moins 2 caractères',
'maxLength' => 'login too large',
)
));
$expected = array(
'div' => array('class' => 'input text error'),
'label' => array('for' => 'ContactField'),
'Field',
'/label',
'input' => array('type' => 'text', 'name' => 'data[Contact][field]', 'id' => 'ContactField', 'class' => 'form-error'),
array('span' => array('class' => 'error-message', 'rel' => 'fake')),
'login too large',
'/span',
'/div'
);
$this->assertTags($result, $expected);
}
/**
* test input() with checkbox creation
*
* @return void
*/
public function testInputCheckbox() {
$result = $this->Form->input('User.active', array('label' => false, 'checked' => true));
$expected = array(
'div' => array('class' => 'input checkbox'),
'input' => array('type' => 'hidden', 'name' => 'data[User][active]', 'value' => '0', 'id' => 'UserActive_'),
array('input' => array('type' => 'checkbox', 'name' => 'data[User][active]', 'value' => '1', 'id' => 'UserActive', 'checked' => 'checked')),
'/div'
);
$this->assertTags($result, $expected);
$result = $this->Form->input('User.active', array('label' => false, 'checked' => 1));
$expected = array(
'div' => array('class' => 'input checkbox'),
'input' => array('type' => 'hidden', 'name' => 'data[User][active]', 'value' => '0', 'id' => 'UserActive_'),
array('input' => array('type' => 'checkbox', 'name' => 'data[User][active]', 'value' => '1', 'id' => 'UserActive', 'checked' => 'checked')),
'/div'
);
$this->assertTags($result, $expected);
$result = $this->Form->input('User.active', array('label' => false, 'checked' => '1'));
$expected = array(
'div' => array('class' => 'input checkbox'),
'input' => array('type' => 'hidden', 'name' => 'data[User][active]', 'value' => '0', 'id' => 'UserActive_'),
array('input' => array('type' => 'checkbox', 'name' => 'data[User][active]', 'value' => '1', 'id' => 'UserActive', 'checked' => 'checked')),
'/div'
);
$this->assertTags($result, $expected);
}
/**
* test form->input() with time types.
*
*/
public function testInputTime() {
extract($this->dateRegex);
$result = $this->Form->input('Contact.created', array('type' => 'time', 'timeFormat' => 24));
$result = explode(':', $result);
$this->assertPattern('/option value="23"/', $result[0]);
$this->assertNoPattern('/option value="24"/', $result[0]);
$result = $this->Form->input('Contact.created', array('type' => 'time', 'timeFormat' => 24));
$result = explode(':', $result);
$this->assertPattern('/option value="23"/', $result[0]);
$this->assertNoPattern('/option value="24"/', $result[0]);
$result = $this->Form->input('Model.field', array(
'type' => 'time', 'timeFormat' => 24, 'interval' => 15
));
$result = explode(':', $result);
$this->assertNoPattern('#<option value="12"[^>]*>12</option>#', $result[1]);
$this->assertNoPattern('#<option value="50"[^>]*>50</option>#', $result[1]);
$this->assertPattern('#<option value="15"[^>]*>15</option>#', $result[1]);
$result = $this->Form->input('Model.field', array(
'type' => 'time', 'timeFormat' => 12, 'interval' => 15
));
$result = explode(':', $result);
$this->assertNoPattern('#<option value="12"[^>]*>12</option>#', $result[1]);
$this->assertNoPattern('#<option value="50"[^>]*>50</option>#', $result[1]);
$this->assertPattern('#<option value="15"[^>]*>15</option>#', $result[1]);
$result = $this->Form->input('prueba', array(
'type' => 'time', 'timeFormat'=> 24 , 'dateFormat'=>'DMY' , 'minYear' => 2008,
'maxYear' => date('Y') + 1 ,'interval' => 15
));
$result = explode(':', $result);
$this->assertNoPattern('#<option value="12"[^>]*>12</option>#', $result[1]);
$this->assertNoPattern('#<option value="50"[^>]*>50</option>#', $result[1]);
$this->assertPattern('#<option value="15"[^>]*>15</option>#', $result[1]);
$this->assertPattern('#<option value="30"[^>]*>30</option>#', $result[1]);
$result = $this->Form->input('Random.start_time', array(
'type' => 'time',
'selected' => '18:15'
));
$this->assertPattern('#<option value="06"[^>]*>6</option>#', $result);
$this->assertPattern('#<option value="15"[^>]*>15</option>#', $result);
$this->assertPattern('#<option value="pm"[^>]*>pm</option>#', $result);
}
/**
* test form->input() with datetime, date and time types
*
* @return void
*/
function testInputDatetime() {
extract($this->dateRegex);
$result = $this->Form->input('prueba', array(
'type' => 'datetime', 'timeFormat'=> 24 , 'dateFormat'=>'DMY' , 'minYear' => 2008,
'maxYear' => date('Y') + 1 ,'interval' => 15
));
$result = explode(':', $result);
$this->assertNoPattern('#<option value="12"[^>]*>12</option>#', $result[1]);
$this->assertNoPattern('#<option value="50"[^>]*>50</option>#', $result[1]);
$this->assertPattern('#<option value="15"[^>]*>15</option>#', $result[1]);
$this->assertPattern('#<option value="30"[^>]*>30</option>#', $result[1]);
//related to ticket #5013
$result = $this->Form->input('Contact.date', array(
'type' => 'date', 'class' => 'customClass', 'onChange' => 'function(){}'
));
$this->assertPattern('/class="customClass"/', $result);
$this->assertPattern('/onChange="function\(\)\{\}"/', $result);
$result = $this->Form->input('Contact.date', array(
'type' => 'date', 'id' => 'customId', 'onChange' => 'function(){}'
));
$this->assertPattern('/id="customIdDay"/', $result);
$this->assertPattern('/id="customIdMonth"/', $result);
$this->assertPattern('/onChange="function\(\)\{\}"/', $result);
$result = $this->Form->input('Model.field', array(
'type' => 'datetime', 'timeFormat' => 24, 'id' => 'customID'
));
$this->assertPattern('/id="customIDDay"/', $result);
$this->assertPattern('/id="customIDHour"/', $result);
$result = explode('</select><select', $result);
$result = explode(':', $result[1]);
$this->assertPattern('/option value="23"/', $result[0]);
$this->assertNoPattern('/option value="24"/', $result[0]);
$result = $this->Form->input('Model.field', array(
'type' => 'datetime', 'timeFormat' => 12
));
$result = explode('</select><select', $result);
$result = explode(':', $result[1]);
$this->assertPattern('/option value="12"/', $result[0]);
$this->assertNoPattern('/option value="13"/', $result[0]);
$this->Form->request->data = array('Contact' => array('created' => null));
$result = $this->Form->input('Contact.created', array('empty' => 'Date Unknown'));
$expected = array(
'div' => array('class' => 'input date'),
'label' => array('for' => 'ContactCreatedMonth'),
'Created',
'/label',
array('select' => array('name' => 'data[Contact][created][month]', 'id' => 'ContactCreatedMonth')),
array('option' => array('value' => '')), 'Date Unknown', '/option',
$monthsRegex,
'/select', '-',
array('select' => array('name' => 'data[Contact][created][day]', 'id' => 'ContactCreatedDay')),
array('option' => array('value' => '')), 'Date Unknown', '/option',
$daysRegex,
'/select', '-',
array('select' => array('name' => 'data[Contact][created][year]', 'id' => 'ContactCreatedYear')),
array('option' => array('value' => '')), 'Date Unknown', '/option',
$yearsRegex,
'/select',
'/div'
);
$this->assertTags($result, $expected);
$this->Form->request->data = array('Contact' => array('created' => null));
$result = $this->Form->input('Contact.created', array('type' => 'datetime', 'dateFormat' => 'NONE'));
$this->assertPattern('/for\="ContactCreatedHour"/', $result);
$this->Form->request->data = array('Contact' => array('created' => null));
$result = $this->Form->input('Contact.created', array('type' => 'datetime', 'timeFormat' => 'NONE'));
$this->assertPattern('/for\="ContactCreatedMonth"/', $result);
$result = $this->Form->input('Contact.created', array(
'type' => 'date',
'id' => array('day' => 'created-day', 'month' => 'created-month', 'year' => 'created-year'),
'timeFormat' => 'NONE'
));
$this->assertPattern('/for\="created-month"/', $result);
}
/**
* Test generating checkboxes in a loop.
*
* @return void
*/
public function testInputCheckboxesInLoop() {
for ($i = 1; $i < 5; $i++) {
$result = $this->Form->input("Contact.{$i}.email", array('type' => 'checkbox', 'value' => $i));
$expected = array(
'div' => array('class' => 'input checkbox'),
'input' => array('type' => 'hidden', 'name' => "data[Contact][{$i}][email]", 'value' => '0', 'id' => "Contact{$i}Email_"),
array('input' => array('type' => 'checkbox', 'name' => "data[Contact][{$i}][email]", 'value' => $i, 'id' => "Contact{$i}Email")),
'label' => array('for' => "Contact{$i}Email"),
'Email',
'/label',
'/div'
);
$this->assertTags($result, $expected);
}
}
/**
* test input name with leading integer, ensure attributes are generated correctly.
*
* @return void
*/
public function testInputWithLeadingInteger() {
$result = $this->Form->text('0.Node.title');
$expected = array(
'input' => array('name' => 'data[0][Node][title]', 'id' => '0NodeTitle', 'type' => 'text')
);
$this->assertTags($result, $expected);
}
/**
* test form->input() with select type inputs.
*
* @return void
*/
public function testInputSelectType() {
$result = $this->Form->input('email', array(
'options' => array('è' => 'Firést', 'é' => 'Secoènd'), 'empty' => true)
);
$expected = array(
'div' => array('class' => 'input select'),
'label' => array('for' => 'email'),
'Email',
'/label',
array('select' => array('name' => 'data[email]', 'id' => 'email')),
array('option' => array('value' => '')),
'/option',
array('option' => array('value' => 'è')),
'Firést',
'/option',
array('option' => array('value' => 'é')),
'Secoènd',
'/option',
'/select',
'/div'
);
$this->assertTags($result, $expected);
$result = $this->Form->input('email', array(
'options' => array('First', 'Second'), 'empty' => true)
);
$expected = array(
'div' => array('class' => 'input select'),
'label' => array('for' => 'email'),
'Email',
'/label',
array('select' => array('name' => 'data[email]', 'id' => 'email')),
array('option' => array('value' => '')),
'/option',
array('option' => array('value' => '0')),
'First',
'/option',
array('option' => array('value' => '1')),
'Second',
'/option',
'/select',
'/div'
);
$this->assertTags($result, $expected);
$this->View->viewVars['users'] = array('value' => 'good', 'other' => 'bad');
$this->Form->request->data = array('Model' => array('user_id' => 'value'));
$result = $this->Form->input('Model.user_id', array('empty' => true));
$expected = array(
'div' => array('class' => 'input select'),
'label' => array('for' => 'ModelUserId'),
'User',
'/label',
'select' => array('name' => 'data[Model][user_id]', 'id' => 'ModelUserId'),
array('option' => array('value' => '')),
'/option',
array('option' => array('value' => 'value', 'selected' => 'selected')),
'good',
'/option',
array('option' => array('value' => 'other')),
'bad',
'/option',
'/select',
'/div'
);
$this->assertTags($result, $expected);
$this->View->viewVars['users'] = array('value' => 'good', 'other' => 'bad');
$this->Form->request->data = array('Thing' => array('user_id' => null));
$result = $this->Form->input('Thing.user_id', array('empty' => 'Some Empty'));
$expected = array(
'div' => array('class' => 'input select'),
'label' => array('for' => 'ThingUserId'),
'User',
'/label',
'select' => array('name' => 'data[Thing][user_id]', 'id' => 'ThingUserId'),
array('option' => array('value' => '')),
'Some Empty',
'/option',
array('option' => array('value' => 'value')),
'good',
'/option',
array('option' => array('value' => 'other')),
'bad',
'/option',
'/select',
'/div'
);
$this->assertTags($result, $expected);
$this->View->viewVars['users'] = array('value' => 'good', 'other' => 'bad');
$this->Form->request->data = array('Thing' => array('user_id' => 'value'));
$result = $this->Form->input('Thing.user_id', array('empty' => 'Some Empty'));
$expected = array(
'div' => array('class' => 'input select'),
'label' => array('for' => 'ThingUserId'),
'User',
'/label',
'select' => array('name' => 'data[Thing][user_id]', 'id' => 'ThingUserId'),
array('option' => array('value' => '')),
'Some Empty',
'/option',
array('option' => array('value' => 'value', 'selected' => 'selected')),
'good',
'/option',
array('option' => array('value' => 'other')),
'bad',
'/option',
'/select',
'/div'
);
$this->assertTags($result, $expected);
$this->View->viewVars['users'] = array('value' => 'good', 'other' => 'bad');
$this->Form->request->data = array('User' => array('User' => array('value')));
$result = $this->Form->input('User.User', array('empty' => true));
$expected = array(
'div' => array('class' => 'input select'),
'label' => array('for' => 'UserUser'),
'User',
'/label',
'input' => array('type' => 'hidden', 'name' => 'data[User][User]', 'value' => '', 'id' => 'UserUser_'),
'select' => array('name' => 'data[User][User][]', 'id' => 'UserUser', 'multiple' => 'multiple'),
array('option' => array('value' => '')),
'/option',
array('option' => array('value' => 'value', 'selected' => 'selected')),
'good',
'/option',
array('option' => array('value' => 'other')),
'bad',
'/option',
'/select',
'/div'
);
$this->assertTags($result, $expected);
$this->Form->data = array();
$result = $this->Form->input('Publisher.id', array(
'label' => 'Publisher',
'type' => 'select',
'multiple' => 'checkbox',
'options' => array('Value 1' => 'Label 1', 'Value 2' => 'Label 2')
));
$expected = array(
array('div' => array('class' => 'input select')),
array('label' => array('for' => 'PublisherId')),
'Publisher',
'/label',
'input' => array('type' => 'hidden', 'name' => 'data[Publisher][id]', 'value' => '', 'id' => 'PublisherId'),
array('div' => array('class' => 'checkbox')),
array('input' => array('type' => 'checkbox', 'name' => 'data[Publisher][id][]', 'value' => 'Value 1', 'id' => 'PublisherIdValue1')),
array('label' => array('for' => 'PublisherIdValue1')),
'Label 1',
'/label',
'/div',
array('div' => array('class' => 'checkbox')),
array('input' => array('type' => 'checkbox', 'name' => 'data[Publisher][id][]', 'value' => 'Value 2', 'id' => 'PublisherIdValue2')),
array('label' => array('for' => 'PublisherIdValue2')),
'Label 2',
'/label',
'/div',
'/div'
);
$this->assertTags($result, $expected);
}
/**
* test that input() and a non standard primary key makes a hidden input by default.
*
* @return void
*/
public function testInputWithNonStandardPrimaryKeyMakesHidden() {
$this->Form->create('User');
$this->Form->fieldset = array(
'User' => array(
'fields' => array(
'model_id' => array('type' => 'integer')
),
'validates' => array(),
'key' => 'model_id'
)
);
$result = $this->Form->input('model_id');
$expected = array(
'input' => array('type' => 'hidden', 'name' => 'data[User][model_id]', 'id' => 'UserModelId'),
);
$this->assertTags($result, $expected);
}
/**
* test that overriding the magic select type widget is possible
*
* @return void
*/
public function testInputOverridingMagicSelectType() {
$this->View->viewVars['users'] = array('value' => 'good', 'other' => 'bad');
$result = $this->Form->input('Model.user_id', array('type' => 'text'));
$expected = array(
'div' => array('class' => 'input text'),
'label' => array('for' => 'ModelUserId'), 'User', '/label',
'input' => array('name' => 'data[Model][user_id]', 'type' => 'text', 'id' => 'ModelUserId'),
'/div'
);
$this->assertTags($result, $expected);
//Check that magic types still work for plural/singular vars
$this->View->viewVars['types'] = array('value' => 'good', 'other' => 'bad');
$result = $this->Form->input('Model.type');
$expected = array(
'div' => array('class' => 'input select'),
'label' => array('for' => 'ModelType'), 'Type', '/label',
'select' => array('name' => 'data[Model][type]', 'id' => 'ModelType'),
array('option' => array('value' => 'value')), 'good', '/option',
array('option' => array('value' => 'other')), 'bad', '/option',
'/select',
'/div'
);
$this->assertTags($result, $expected);
}
/**
* Test that magic input() selects can easily be converted into radio types without error.
*
* @return void
*/
public function testInputMagicSelectChangeToRadio() {
$this->View->viewVars['users'] = array('value' => 'good', 'other' => 'bad');
$result = $this->Form->input('Model.user_id', array('type' => 'radio'));
$this->assertPattern('/input type="radio"/', $result);
}
/**
* fields with the same name as the model should work.
*
* @return void
*/
public function testInputWithMatchingFieldAndModelName() {
$this->Form->create('User');
$this->Form->fieldset = array(
'User' => array(
'fields' => array(
'User' => array('type' => 'text')
),
'validates' => array(),
'key' => 'id'
)
);
$this->Form->request->data['User']['User'] = 'ABC, Inc.';
$result = $this->Form->input('User', array('type' => 'text'));
$expected = array(
'div' => array('class' => 'input text'),
'label' => array('for' => 'UserUser'), 'User', '/label',
'input' => array('name' => 'data[User][User]', 'type' => 'text', 'id' => 'UserUser', 'value' => 'ABC, Inc.'),
'/div'
);
$this->assertTags($result, $expected);
}
/**
* testFormInputs method
*
* test correct results from form::inputs().
*
* @return void
*/
public function testFormInputs() {
$this->Form->create('Contact');
$result = $this->Form->inputs('The Legend');
$expected = array(
'<fieldset',
'<legend',
'The Legend',
'/legend',
'*/fieldset',
);
$this->assertTags($result, $expected);
$result = $this->Form->inputs(array('legend' => 'Field of Dreams', 'fieldset' => 'classy-stuff'));
$expected = array(
'fieldset' => array('class' => 'classy-stuff'),
'<legend',
'Field of Dreams',
'/legend',
'*/fieldset'
);
$this->assertTags($result, $expected);
$this->Form->create('Contact');
$this->Form->request['prefix'] = 'admin';
$this->Form->request['action'] = 'admin_edit';
$result = $this->Form->inputs();
$expected = array(
'<fieldset',
'<legend',
'Edit Contact',
'/legend',
'*/fieldset',
);
$this->assertTags($result, $expected);
$this->Form->create('Contact');
$result = $this->Form->inputs(false);
$expected = array(
'input' => array('type' => 'hidden', 'name' => 'data[Contact][id]', 'id' => 'ContactId'),
array('div' => array('class' => 'input text')),
'*/div',
array('div' => array('class' => 'input text')),
'*/div',
array('div' => array('class' => 'input text')),
'*/div',
array('div' => array('class' => 'input password')),
'*/div',
array('div' => array('class' => 'input date')),
'*/div',
array('div' => array('class' => 'input date')),
'*/div',
array('div' => array('class' => 'input datetime')),
'*/div',
array('div' => array('class' => 'input number')),
'*/div',
array('div' => array('class' => 'input select')),
'*/div',
);
$this->assertTags($result, $expected);
$this->Form->create('Contact');
$result = $this->Form->inputs(array('fieldset' => false, 'legend' => false));
$expected = array(
'input' => array('type' => 'hidden', 'name' => 'data[Contact][id]', 'id' => 'ContactId'),
array('div' => array('class' => 'input text')),
'*/div',
array('div' => array('class' => 'input text')),
'*/div',
array('div' => array('class' => 'input text')),
'*/div',
array('div' => array('class' => 'input password')),
'*/div',
array('div' => array('class' => 'input date')),
'*/div',
array('div' => array('class' => 'input date')),
'*/div',
array('div' => array('class' => 'input datetime')),
'*/div',
array('div' => array('class' => 'input number')),
'*/div',
array('div' => array('class' => 'input select')),
'*/div',
);
$this->assertTags($result, $expected);
$this->Form->create('Contact');
$result = $this->Form->inputs(array('fieldset' => true, 'legend' => false));
$expected = array(
'fieldset' => array(),
'input' => array('type' => 'hidden', 'name' => 'data[Contact][id]', 'id' => 'ContactId'),
array('div' => array('class' => 'input text')),
'*/div',
array('div' => array('class' => 'input text')),
'*/div',
array('div' => array('class' => 'input text')),
'*/div',
array('div' => array('class' => 'input password')),
'*/div',
array('div' => array('class' => 'input date')),
'*/div',
array('div' => array('class' => 'input date')),
'*/div',
array('div' => array('class' => 'input datetime')),
'*/div',
array('div' => array('class' => 'input number')),
'*/div',
array('div' => array('class' => 'input select')),
'*/div',
'/fieldset'
);
$this->assertTags($result, $expected);
$this->Form->create('Contact');
$result = $this->Form->inputs(array('fieldset' => false, 'legend' => 'Hello'));
$expected = array(
'input' => array('type' => 'hidden', 'name' => 'data[Contact][id]', 'id' => 'ContactId'),
array('div' => array('class' => 'input text')),
'*/div',
array('div' => array('class' => 'input text')),
'*/div',
array('div' => array('class' => 'input text')),
'*/div',
array('div' => array('class' => 'input password')),
'*/div',
array('div' => array('class' => 'input date')),
'*/div',
array('div' => array('class' => 'input date')),
'*/div',
array('div' => array('class' => 'input datetime')),
'*/div',
array('div' => array('class' => 'input number')),
'*/div',
array('div' => array('class' => 'input select')),
'*/div',
);
$this->assertTags($result, $expected);
$this->Form->create('Contact');
$result = $this->Form->inputs('Hello');
$expected = array(
'fieldset' => array(),
'legend' => array(),
'Hello',
'/legend',
'input' => array('type' => 'hidden', 'name' => 'data[Contact][id]', 'id' => 'ContactId'),
array('div' => array('class' => 'input text')),
'*/div',
array('div' => array('class' => 'input text')),
'*/div',
array('div' => array('class' => 'input text')),
'*/div',
array('div' => array('class' => 'input password')),
'*/div',
array('div' => array('class' => 'input date')),
'*/div',
array('div' => array('class' => 'input date')),
'*/div',
array('div' => array('class' => 'input datetime')),
'*/div',
array('div' => array('class' => 'input number')),
'*/div',
array('div' => array('class' => 'input select')),
'*/div',
'/fieldset'
);
$this->assertTags($result, $expected);
$this->Form->create('Contact');
$result = $this->Form->inputs(array('legend' => 'Hello'));
$expected = array(
'fieldset' => array(),
'legend' => array(),
'Hello',
'/legend',
'input' => array('type' => 'hidden', 'name' => 'data[Contact][id]', 'id' => 'ContactId'),
array('div' => array('class' => 'input text')),
'*/div',
array('div' => array('class' => 'input text')),
'*/div',
array('div' => array('class' => 'input text')),
'*/div',
array('div' => array('class' => 'input password')),
'*/div',
array('div' => array('class' => 'input date')),
'*/div',
array('div' => array('class' => 'input date')),
'*/div',
array('div' => array('class' => 'input datetime')),
'*/div',
array('div' => array('class' => 'input number')),
'*/div',
array('div' => array('class' => 'input select')),
'*/div',
'/fieldset'
);
$this->assertTags($result, $expected);
}
/**
* testSelectAsCheckbox method
*
* test multi-select widget with checkbox formatting.
*
* @return void
*/
public function testSelectAsCheckbox() {
$result = $this->Form->select('Model.multi_field', array('first', 'second', 'third'), array('multiple' => 'checkbox', 'value' => array(0, 1)));
$expected = array(
'input' => array('type' => 'hidden', 'name' => 'data[Model][multi_field]', 'value' => '', 'id' => 'ModelMultiField'),
array('div' => array('class' => 'checkbox')),
array('input' => array('type' => 'checkbox', 'name' => 'data[Model][multi_field][]', 'checked' => 'checked', 'value' => '0', 'id' => 'ModelMultiField0')),
array('label' => array('for' => 'ModelMultiField0', 'class' => 'selected')),
'first',
'/label',
'/div',
array('div' => array('class' => 'checkbox')),
array('input' => array('type' => 'checkbox', 'name' => 'data[Model][multi_field][]', 'checked' => 'checked', 'value' => '1', 'id' => 'ModelMultiField1')),
array('label' => array('for' => 'ModelMultiField1', 'class' => 'selected')),
'second',
'/label',
'/div',
array('div' => array('class' => 'checkbox')),
array('input' => array('type' => 'checkbox', 'name' => 'data[Model][multi_field][]', 'value' => '2', 'id' => 'ModelMultiField2')),
array('label' => array('for' => 'ModelMultiField2')),
'third',
'/label',
'/div',
);
$this->assertTags($result, $expected);
$result = $this->Form->select('Model.multi_field', array('1/2' => 'half'), array('multiple' => 'checkbox'));
$expected = array(
'input' => array('type' => 'hidden', 'name' => 'data[Model][multi_field]', 'value' => '', 'id' => 'ModelMultiField'),
array('div' => array('class' => 'checkbox')),
array('input' => array('type' => 'checkbox', 'name' => 'data[Model][multi_field][]', 'value' => '1/2', 'id' => 'ModelMultiField12')),
array('label' => array('for' => 'ModelMultiField12')),
'half',
'/label',
'/div',
);
$this->assertTags($result, $expected);
}
/**
* testLabel method
*
* test label generation.
*
* @return void
*/
public function testLabel() {
$this->Form->text('Person.name');
$result = $this->Form->label();
$this->assertTags($result, array('label' => array('for' => 'PersonName'), 'Name', '/label'));
$this->Form->text('Person.name');
$result = $this->Form->label();
$this->assertTags($result, array('label' => array('for' => 'PersonName'), 'Name', '/label'));
$result = $this->Form->label('Person.first_name');
$this->assertTags($result, array('label' => array('for' => 'PersonFirstName'), 'First Name', '/label'));
$result = $this->Form->label('Person.first_name', 'Your first name');
$this->assertTags($result, array('label' => array('for' => 'PersonFirstName'), 'Your first name', '/label'));
$result = $this->Form->label('Person.first_name', 'Your first name', array('class' => 'my-class'));
$this->assertTags($result, array('label' => array('for' => 'PersonFirstName', 'class' => 'my-class'), 'Your first name', '/label'));
$result = $this->Form->label('Person.first_name', 'Your first name', array('class' => 'my-class', 'id' => 'LabelID'));
$this->assertTags($result, array('label' => array('for' => 'PersonFirstName', 'class' => 'my-class', 'id' => 'LabelID'), 'Your first name', '/label'));
$result = $this->Form->label('Person.first_name', '');
$this->assertTags($result, array('label' => array('for' => 'PersonFirstName'), '/label'));
$result = $this->Form->label('Person.2.name', '');
$this->assertTags($result, array('label' => array('for' => 'Person2Name'), '/label'));
}
/**
* testTextbox method
*
* test textbox element generation
*
* @return void
*/
public function testTextbox() {
$result = $this->Form->text('Model.field');
$this->assertTags($result, array('input' => array('type' => 'text', 'name' => 'data[Model][field]', 'id' => 'ModelField')));
$result = $this->Form->text('Model.field', array('type' => 'password'));
$this->assertTags($result, array('input' => array('type' => 'password', 'name' => 'data[Model][field]', 'id' => 'ModelField')));
$result = $this->Form->text('Model.field', array('id' => 'theID'));
$this->assertTags($result, array('input' => array('type' => 'text', 'name' => 'data[Model][field]', 'id' => 'theID')));
$this->Form->request->data['Model']['text'] = 'test <strong>HTML</strong> values';
$result = $this->Form->text('Model.text');
$this->assertTags($result, array('input' => array('type' => 'text', 'name' => 'data[Model][text]', 'value' => 'test <strong>HTML</strong> values', 'id' => 'ModelText')));
$Contact = ClassRegistry::getObject('Contact');
$Contact->validationErrors['text'] = array(true);
$this->Form->request->data['Contact']['text'] = 'test';
$result = $this->Form->text('Contact.text', array('id' => 'theID'));
$this->assertTags($result, array('input' => array('type' => 'text', 'name' => 'data[Contact][text]', 'value' => 'test', 'id' => 'theID', 'class' => 'form-error')));
$this->Form->request->data['Model']['0']['OtherModel']['field'] = 'My value';
$result = $this->Form->text('Model.0.OtherModel.field', array('id' => 'myId'));
$expected = array(
'input' => array('type' => 'text', 'name' => 'data[Model][0][OtherModel][field]', 'value' => 'My value', 'id' => 'myId')
);
$this->assertTags($result, $expected);
}
/**
* testDefaultValue method
*
* Test default value setting
*
* @return void
*/
public function testDefaultValue() {
$this->Form->request->data['Model']['field'] = 'test';
$result = $this->Form->text('Model.field', array('default' => 'default value'));
$this->assertTags($result, array('input' => array('type' => 'text', 'name' => 'data[Model][field]', 'value' => 'test', 'id' => 'ModelField')));
unset($this->Form->request->data['Model']['field']);
$result = $this->Form->text('Model.field', array('default' => 'default value'));
$this->assertTags($result, array('input' => array('type' => 'text', 'name' => 'data[Model][field]', 'value' => 'default value', 'id' => 'ModelField')));
}
/**
* testCheckboxDefaultValue method
*
* Test default value setting on checkbox() method
*
* @return void
*/
public function testCheckboxDefaultValue() {
$this->Form->request->data['Model']['field'] = false;
$result = $this->Form->checkbox('Model.field', array('default' => true, 'hiddenField' => false));
$this->assertTags($result, array('input' => array('type' => 'checkbox', 'name' => 'data[Model][field]', 'value' => '1', 'id' => 'ModelField')));
unset($this->Form->request->data['Model']['field']);
$result = $this->Form->checkbox('Model.field', array('default' => true, 'hiddenField' => false));
$this->assertTags($result, array('input' => array('type' => 'checkbox', 'name' => 'data[Model][field]', 'value' => '1', 'id' => 'ModelField', 'checked' => 'checked')));
$this->Form->request->data['Model']['field'] = true;
$result = $this->Form->checkbox('Model.field', array('default' => false, 'hiddenField' => false));
$this->assertTags($result, array('input' => array('type' => 'checkbox', 'name' => 'data[Model][field]', 'value' => '1', 'id' => 'ModelField', 'checked' => 'checked')));
unset($this->Form->request->data['Model']['field']);
$result = $this->Form->checkbox('Model.field', array('default' => false, 'hiddenField' => false));
$this->assertTags($result, array('input' => array('type' => 'checkbox', 'name' => 'data[Model][field]', 'value' => '1', 'id' => 'ModelField')));
}
/**
* testError method
*
* Test field error generation
*
* @return void
*/
public function testError() {
$Contact = ClassRegistry::getObject('Contact');
$Contact->validationErrors['field'] = array(1);
$result = $this->Form->error('Contact.field');
$this->assertTags($result, array('div' => array('class' => 'error-message'), 'Error in field Field', '/div'));
$result = $this->Form->error('Contact.field', null, array('wrap' => false));
$this->assertEqual($result, 'Error in field Field');
$Contact->validationErrors['field'] = array("This field contains invalid input");
$result = $this->Form->error('Contact.field', null, array('wrap' => false));
$this->assertEqual($result, 'This field contains invalid input');
$Contact->validationErrors['field'] = array("This field contains invalid input");
$result = $this->Form->error('Contact.field', null, array('wrap' => 'span'));
$this->assertTags($result, array('span' => array('class' => 'error-message'), 'This field contains invalid input', '/span'));
$result = $this->Form->error('Contact.field', 'There is an error fool!', array('wrap' => 'span'));
$this->assertTags($result, array('span' => array('class' => 'error-message'), 'There is an error fool!', '/span'));
$result = $this->Form->error('Contact.field', "<strong>Badness!</strong>", array('wrap' => false));
$this->assertEqual($result, '<strong>Badness!</strong>');
$result = $this->Form->error('Contact.field', "<strong>Badness!</strong>", array('wrap' => false, 'escape' => true));
$this->assertEqual($result, '<strong>Badness!</strong>');
$result = $this->Form->error('Contact.field', "<strong>Badness!</strong>", array('wrap' => false, 'escape' => false));
$this->assertEqual($result, '<strong>Badness!</strong>');
$Contact->validationErrors['field'] = array("email");
$result = $this->Form->error('Contact.field', array('attributes' => array('class' => 'field-error'), 'email' => 'No good!'));
$expected = array(
'div' => array('class' => 'field-error'),
'No good!',
'/div'
);
$this->assertTags($result, $expected);
$Contact->validationErrors['field'] = array('notEmpty', 'email', 'Something else');
$result = $this->Form->error('Contact.field', array(
'notEmpty' => 'Cannot be empty',
'email' => 'No good!'
));
$expected = array(
'div' => array('class' => 'error-message'),
'ul' => array(),
'<li', 'Cannot be empty', '/li',
'<li', 'No good!', '/li',
'<li', 'Something else', '/li',
'/ul',
'/div'
);
$this->assertTags($result, $expected);
/** Testing error messages list options **/
$Contact->validationErrors['field'] = array('notEmpty', 'email');
$result = $this->Form->error('Contact.field', null, array('listOptions' => 'ol'));
$expected = array(
'div' => array('class' => 'error-message'),
'ol' => array(),
'<li', 'notEmpty', '/li',
'<li', 'email', '/li',
'/ol',
'/div'
);
$this->assertTags($result, $expected);
$result = $this->Form->error('Contact.field', null, array('listOptions' => array('tag' => 'ol')));
$expected = array(
'div' => array('class' => 'error-message'),
'ol' => array(),
'<li', 'notEmpty', '/li',
'<li', 'email', '/li',
'/ol',
'/div'
);
$this->assertTags($result, $expected);
$result = $this->Form->error('Contact.field', null, array(
'listOptions' => array(
'class' => 'ul-class',
'itemOptions' => array(
'class' => 'li-class'
)
)
));
$expected = array(
'div' => array('class' => 'error-message'),
'ul' => array('class' => 'ul-class'),
array('li' => array('class' => 'li-class')), 'notEmpty', '/li',
array('li' => array('class' => 'li-class')), 'email', '/li',
'/ul',
'/div'
);
$this->assertTags($result, $expected);
}
/**
* test error options when using form->input();
*
* @return void
*/
public function testInputErrorEscape() {
$this->Form->create('ValidateProfile');
$ValidateProfile = ClassRegistry::getObject('ValidateProfile');
$ValidateProfile->validationErrors['city'] = array('required<br>');
$result = $this->Form->input('city',array('error' => array('attributes' => array('escape' => true))));
$this->assertPattern('/required<br>/', $result);
$result = $this->Form->input('city',array('error' => array('attributes' => array('escape' => false))));
$this->assertPattern('/required<br>/', $result);
}
/**
* testPassword method
*
* Test password element generation
*
* @return void
*/
public function testPassword() {
$Contact = ClassRegistry::getObject('Contact');
$result = $this->Form->password('Contact.field');
$this->assertTags($result, array('input' => array('type' => 'password', 'name' => 'data[Contact][field]', 'id' => 'ContactField')));
$Contact->validationErrors['passwd'] = 1;
$this->Form->request->data['Contact']['passwd'] = 'test';
$result = $this->Form->password('Contact.passwd', array('id' => 'theID'));
$this->assertTags($result, array('input' => array('type' => 'password', 'name' => 'data[Contact][passwd]', 'value' => 'test', 'id' => 'theID', 'class' => 'form-error')));
}
/**
* testRadio method
*
* Test radio element set generation
*
* @return void
*/
public function testRadio() {
$result = $this->Form->radio('Model.field', array('option A'));
$expected = array(
'input' => array('type' => 'hidden', 'name' => 'data[Model][field]', 'value' => '', 'id' => 'ModelField_'),
array('input' => array('type' => 'radio', 'name' => 'data[Model][field]', 'value' => '0', 'id' => 'ModelField0')),
'label' => array('for' => 'ModelField0'),
'option A',
'/label'
);
$this->assertTags($result, $expected);
$result = $this->Form->radio('Model.field', array('1/2' => 'half'));
$expected = array(
'input' => array('type' => 'hidden', 'name' => 'data[Model][field]', 'value' => '', 'id' => 'ModelField_'),
array('input' => array('type' => 'radio', 'name' => 'data[Model][field]', 'value' => '1/2', 'id' => 'ModelField12')),
'label' => array('for' => 'ModelField12'),
'half',
'/label'
);
$this->assertTags($result, $expected);
$result = $this->Form->radio('Model.field', array('option A', 'option B'));
$expected = array(
'fieldset' => array(),
'legend' => array(),
'Field',
'/legend',
'input' => array('type' => 'hidden', 'name' => 'data[Model][field]', 'value' => '', 'id' => 'ModelField_'),
array('input' => array('type' => 'radio', 'name' => 'data[Model][field]', 'value' => '0', 'id' => 'ModelField0')),
array('label' => array('for' => 'ModelField0')),
'option A',
'/label',
array('input' => array('type' => 'radio', 'name' => 'data[Model][field]', 'value' => '1', 'id' => 'ModelField1')),
array('label' => array('for' => 'ModelField1')),
'option B',
'/label',
'/fieldset'
);
$this->assertTags($result, $expected);
$result = $this->Form->radio('Model.field', array('option A', 'option B'), array('separator' => '<br/>'));
$expected = array(
'fieldset' => array(),
'legend' => array(),
'Field',
'/legend',
'input' => array('type' => 'hidden', 'name' => 'data[Model][field]', 'value' => '', 'id' => 'ModelField_'),
array('input' => array('type' => 'radio', 'name' => 'data[Model][field]', 'value' => '0', 'id' => 'ModelField0')),
array('label' => array('for' => 'ModelField0')),
'option A',
'/label',
'br' => array(),
array('input' => array('type' => 'radio', 'name' => 'data[Model][field]', 'value' => '1', 'id' => 'ModelField1')),
array('label' => array('for' => 'ModelField1')),
'option B',
'/label',
'/fieldset'
);
$this->assertTags($result, $expected);
$result = $this->Form->radio('Model.field', array('1' => 'Yes', '0' => 'No'), array('value' => '1'));
$expected = array(
'fieldset' => array(),
'legend' => array(),
'Field',
'/legend',
array('input' => array('type' => 'radio', 'name' => 'data[Model][field]', 'value' => '1', 'id' => 'ModelField1', 'checked' => 'checked')),
array('label' => array('for' => 'ModelField1')),
'Yes',
'/label',
array('input' => array('type' => 'radio', 'name' => 'data[Model][field]', 'value' => '0', 'id' => 'ModelField0')),
array('label' => array('for' => 'ModelField0')),
'No',
'/label',
'/fieldset'
);
$this->assertTags($result, $expected);
$result = $this->Form->radio('Model.field', array('1' => 'Yes', '0' => 'No'), array('value' => '0'));
$expected = array(
'fieldset' => array(),
'legend' => array(),
'Field',
'/legend',
array('input' => array('type' => 'radio', 'name' => 'data[Model][field]', 'value' => '1', 'id' => 'ModelField1')),
array('label' => array('for' => 'ModelField1')),
'Yes',
'/label',
array('input' => array('type' => 'radio', 'name' => 'data[Model][field]', 'value' => '0', 'id' => 'ModelField0', 'checked' => 'checked')),
array('label' => array('for' => 'ModelField0')),
'No',
'/label',
'/fieldset'
);
$this->assertTags($result, $expected);
$result = $this->Form->radio('Model.field', array('1' => 'Yes', '0' => 'No'), array('value' => null));
$expected = array(
'fieldset' => array(),
'legend' => array(),
'Field',
'/legend',
'input' => array('type' => 'hidden', 'name' => 'data[Model][field]', 'value' => '', 'id' => 'ModelField_'),
array('input' => array('type' => 'radio', 'name' => 'data[Model][field]', 'value' => '1', 'id' => 'ModelField1')),
array('label' => array('for' => 'ModelField1')),
'Yes',
'/label',
array('input' => array('type' => 'radio', 'name' => 'data[Model][field]', 'value' => '0', 'id' => 'ModelField0')),
array('label' => array('for' => 'ModelField0')),
'No',
'/label',
'/fieldset'
);
$this->assertTags($result, $expected);
$result = $this->Form->radio('Model.field', array('1' => 'Yes', '0' => 'No'));
$expected = array(
'fieldset' => array(),
'legend' => array(),
'Field',
'/legend',
'input' => array('type' => 'hidden', 'name' => 'data[Model][field]', 'value' => '', 'id' => 'ModelField_'),
array('input' => array('type' => 'radio', 'name' => 'data[Model][field]', 'value' => '1', 'id' => 'ModelField1')),
array('label' => array('for' => 'ModelField1')),
'Yes',
'/label',
array('input' => array('type' => 'radio', 'name' => 'data[Model][field]', 'value' => '0', 'id' => 'ModelField0')),
array('label' => array('for' => 'ModelField0')),
'No',
'/label',
'/fieldset'
);
$this->assertTags($result, $expected);
$result = $this->Form->input('Newsletter.subscribe', array('legend' => 'Legend title', 'type' => 'radio', 'options' => array('0' => 'Unsubscribe', '1' => 'Subscribe')));
$expected = array(
'div' => array('class' => 'input radio'),
'fieldset' => array(),
'legend' => array(),
'Legend title',
'/legend',
'input' => array('type' => 'hidden', 'name' => 'data[Newsletter][subscribe]', 'value' => '', 'id' => 'NewsletterSubscribe_'),
array('input' => array('type' => 'radio', 'name' => 'data[Newsletter][subscribe]', 'value' => '0', 'id' => 'NewsletterSubscribe0')),
array('label' => array('for' => 'NewsletterSubscribe0')),
'Unsubscribe',
'/label',
array('input' => array('type' => 'radio', 'name' => 'data[Newsletter][subscribe]', 'value' => '1', 'id' => 'NewsletterSubscribe1')),
array('label' => array('for' => 'NewsletterSubscribe1')),
'Subscribe',
'/label',
'/fieldset',
'/div'
);
$this->assertTags($result, $expected);
$result = $this->Form->input('Newsletter.subscribe', array('legend' => false, 'type' => 'radio', 'options' => array('0' => 'Unsubscribe', '1' => 'Subscribe')));
$expected = array(
'div' => array('class' => 'input radio'),
'input' => array('type' => 'hidden', 'name' => 'data[Newsletter][subscribe]', 'value' => '', 'id' => 'NewsletterSubscribe_'),
array('input' => array('type' => 'radio', 'name' => 'data[Newsletter][subscribe]', 'value' => '0', 'id' => 'NewsletterSubscribe0')),
array('label' => array('for' => 'NewsletterSubscribe0')),
'Unsubscribe',
'/label',
array('input' => array('type' => 'radio', 'name' => 'data[Newsletter][subscribe]', 'value' => '1', 'id' => 'NewsletterSubscribe1')),
array('label' => array('for' => 'NewsletterSubscribe1')),
'Subscribe',
'/label',
'/div'
);
$this->assertTags($result, $expected);
$result = $this->Form->input('Newsletter.subscribe', array('legend' => 'Legend title', 'label' => false, 'type' => 'radio', 'options' => array('0' => 'Unsubscribe', '1' => 'Subscribe')));
$expected = array(
'div' => array('class' => 'input radio'),
'fieldset' => array(),
'legend' => array(),
'Legend title',
'/legend',
'input' => array('type' => 'hidden', 'name' => 'data[Newsletter][subscribe]', 'value' => '', 'id' => 'NewsletterSubscribe_'),
array('input' => array('type' => 'radio', 'name' => 'data[Newsletter][subscribe]', 'value' => '0', 'id' => 'NewsletterSubscribe0')),
'Unsubscribe',
array('input' => array('type' => 'radio', 'name' => 'data[Newsletter][subscribe]', 'value' => '1', 'id' => 'NewsletterSubscribe1')),
'Subscribe',
'/fieldset',
'/div'
);
$this->assertTags($result, $expected);
$result = $this->Form->input('Newsletter.subscribe', array('legend' => false, 'label' => false, 'type' => 'radio', 'options' => array('0' => 'Unsubscribe', '1' => 'Subscribe')));
$expected = array(
'div' => array('class' => 'input radio'),
'input' => array('type' => 'hidden', 'name' => 'data[Newsletter][subscribe]', 'value' => '', 'id' => 'NewsletterSubscribe_'),
array('input' => array('type' => 'radio', 'name' => 'data[Newsletter][subscribe]', 'value' => '0', 'id' => 'NewsletterSubscribe0')),
'Unsubscribe',
array('input' => array('type' => 'radio', 'name' => 'data[Newsletter][subscribe]', 'value' => '1', 'id' => 'NewsletterSubscribe1')),
'Subscribe',
'/div'
);
$this->assertTags($result, $expected);
$result = $this->Form->input('Newsletter.subscribe', array('legend' => false, 'label' => false, 'type' => 'radio', 'value' => '1', 'options' => array('0' => 'Unsubscribe', '1' => 'Subscribe')));
$expected = array(
'div' => array('class' => 'input radio'),
array('input' => array('type' => 'radio', 'name' => 'data[Newsletter][subscribe]', 'value' => '0', 'id' => 'NewsletterSubscribe0')),
'Unsubscribe',
array('input' => array('type' => 'radio', 'name' => 'data[Newsletter][subscribe]', 'value' => '1', 'id' => 'NewsletterSubscribe1', 'checked' => 'checked')),
'Subscribe',
'/div'
);
$this->assertTags($result, $expected);
$result = $this->Form->radio('Employee.gender', array('male' => 'Male', 'female' => 'Female'));
$expected = array(
'fieldset' => array(),
'legend' => array(),
'Gender',
'/legend',
'input' => array('type' => 'hidden', 'name' => 'data[Employee][gender]', 'value' => '', 'id' => 'EmployeeGender_'),
array('input' => array('type' => 'radio', 'name' => 'data[Employee][gender]', 'value' => 'male', 'id' => 'EmployeeGenderMale')),
array('label' => array('for' => 'EmployeeGenderMale')),
'Male',
'/label',
array('input' => array('type' => 'radio', 'name' => 'data[Employee][gender]', 'value' => 'female', 'id' => 'EmployeeGenderFemale')),
array('label' => array('for' => 'EmployeeGenderFemale')),
'Female',
'/label',
'/fieldset',
);
$this->assertTags($result, $expected);
$result = $this->Form->radio('Officer.gender', array('male' => 'Male', 'female' => 'Female'));
$expected = array(
'fieldset' => array(),
'legend' => array(),
'Gender',
'/legend',
'input' => array('type' => 'hidden', 'name' => 'data[Officer][gender]', 'value' => '', 'id' => 'OfficerGender_'),
array('input' => array('type' => 'radio', 'name' => 'data[Officer][gender]', 'value' => 'male', 'id' => 'OfficerGenderMale')),
array('label' => array('for' => 'OfficerGenderMale')),
'Male',
'/label',
array('input' => array('type' => 'radio', 'name' => 'data[Officer][gender]', 'value' => 'female', 'id' => 'OfficerGenderFemale')),
array('label' => array('for' => 'OfficerGenderFemale')),
'Female',
'/label',
'/fieldset',
);
$this->assertTags($result, $expected);
$result = $this->Form->radio('Contact.1.imrequired', array('option A'));
$expected = array(
'input' => array('type' => 'hidden', 'name' => 'data[Contact][1][imrequired]', 'value' => '', 'id' => 'Contact1Imrequired_'),
array('input' => array('type' => 'radio', 'name' => 'data[Contact][1][imrequired]', 'value' => '0', 'id' => 'Contact1Imrequired0')),
'label' => array('for' => 'Contact1Imrequired0'),
'option A',
'/label'
);
$this->assertTags($result, $expected);
$result = $this->Form->radio('Model.1.field', array('option A'));
$expected = array(
'input' => array('type' => 'hidden', 'name' => 'data[Model][1][field]', 'value' => '', 'id' => 'Model1Field_'),
array('input' => array('type' => 'radio', 'name' => 'data[Model][1][field]', 'value' => '0', 'id' => 'Model1Field0')),
'label' => array('for' => 'Model1Field0'),
'option A',
'/label'
);
$this->assertTags($result, $expected);
$result = $this->Form->radio('Model.field', array('option A', 'option B'), array('name' => 'data[Model][custom]'));
$expected = array(
'fieldset' => array(),
'legend' => array(),
'Field',
'/legend',
'input' => array('type' => 'hidden', 'name' => 'data[Model][custom]', 'value' => '', 'id' => 'ModelField_'),
array('input' => array('type' => 'radio', 'name' => 'data[Model][custom]', 'value' => '0', 'id' => 'ModelField0')),
array('label' => array('for' => 'ModelField0')),
'option A',
'/label',
array('input' => array('type' => 'radio', 'name' => 'data[Model][custom]', 'value' => '1', 'id' => 'ModelField1')),
array('label' => array('for' => 'ModelField1')),
'option B',
'/label',
'/fieldset'
);
$this->assertTags($result, $expected);
}
/**
* test disabled radio options
*
* @return void
*/
public function testRadioDisabled() {
$result = $this->Form->radio(
'Model.field',
array('option A', 'option B'),
array('disabled' => array('option A'), 'value' => 'option A')
);
$expected = array(
'fieldset' => array(),
'legend' => array(),
'Field',
'/legend',
array('input' => array('type' => 'radio', 'name' => 'data[Model][field]', 'value' => '0', 'id' => 'ModelField0', 'disabled' => 'disabled', 'checked' => 'checked')),
array('label' => array('for' => 'ModelField0')),
'option A',
'/label',
array('input' => array('type' => 'radio', 'name' => 'data[Model][field]', 'value' => '1', 'id' => 'ModelField1')),
array('label' => array('for' => 'ModelField1')),
'option B',
'/label',
'/fieldset'
);
$this->assertTags($result, $expected);
}
/**
* test disabling the hidden input for radio buttons
*
* @return void
*/
public function testRadioHiddenInputDisabling() {
$result = $this->Form->input('Model.1.field', array(
'type' => 'radio',
'options' => array('option A'),
'hiddenField' => false
)
);
$expected = array(
'div' => array('class' => 'input radio'),
'input' => array('type' => 'radio', 'name' => 'data[Model][1][field]', 'value' => '0', 'id' => 'Model1Field0'),
'label' => array('for' => 'Model1Field0'),
'option A',
'/label',
'/div'
);
$this->assertTags($result, $expected);
$result = $this->Form->radio('Model.1.field', array('option A'), array('hiddenField' => false));
$expected = array(
'input' => array('type' => 'radio', 'name' => 'data[Model][1][field]', 'value' => '0', 'id' => 'Model1Field0'),
'label' => array('for' => 'Model1Field0'),
'option A',
'/label'
);
$this->assertTags($result, $expected);
}
/**
* testSelect method
*
* Test select element generation.
*
* @return void
*/
public function testSelect() {
$result = $this->Form->select('Model.field', array());
$expected = array(
'select' => array('name' => 'data[Model][field]', 'id' => 'ModelField'),
array('option' => array('value' => '')),
'/option',
'/select'
);
$this->assertTags($result, $expected);
$this->Form->request->data = array('Model' => array('field' => 'value'));
$result = $this->Form->select('Model.field', array('value' => 'good', 'other' => 'bad'));
$expected = array(
'select' => array('name' => 'data[Model][field]', 'id' => 'ModelField'),
array('option' => array('value' => '')),
'/option',
array('option' => array('value' => 'value', 'selected' => 'selected')),
'good',
'/option',
array('option' => array('value' => 'other')),
'bad',
'/option',
'/select'
);
$this->assertTags($result, $expected);
$this->Form->request->data = array();
$result = $this->Form->select('Model.field', array('value' => 'good', 'other' => 'bad'));
$expected = array(
'select' => array('name' => 'data[Model][field]', 'id' => 'ModelField'),
array('option' => array('value' => '')),
'/option',
array('option' => array('value' => 'value')),
'good',
'/option',
array('option' => array('value' => 'other')),
'bad',
'/option',
'/select'
);
$this->assertTags($result, $expected);
$result = $this->Form->select(
'Model.field', array('first' => 'first "html" <chars>', 'second' => 'value'),
array('empty' => false)
);
$expected = array(
'select' => array('name' => 'data[Model][field]', 'id' => 'ModelField'),
array('option' => array('value' => 'first')),
'first "html" <chars>',
'/option',
array('option' => array('value' => 'second')),
'value',
'/option',
'/select'
);
$this->assertTags($result, $expected);
$result = $this->Form->select(
'Model.field',
array('first' => 'first "html" <chars>', 'second' => 'value'),
array('escape' => false, 'empty' => false)
);
$expected = array(
'select' => array('name' => 'data[Model][field]', 'id' => 'ModelField'),
array('option' => array('value' => 'first')),
'first "html" <chars>',
'/option',
array('option' => array('value' => 'second')),
'value',
'/option',
'/select'
);
$this->assertTags($result, $expected);
$this->Form->request->data = array('Model' => array('contact_id' => 228));
$result = $this->Form->select(
'Model.contact_id',
array('228' => '228 value', '228-1' => '228-1 value', '228-2' => '228-2 value'),
array('escape' => false, 'empty' => 'pick something')
);
$expected = array(
'select' => array('name' => 'data[Model][contact_id]', 'id' => 'ModelContactId'),
array('option' => array('value' => '')), 'pick something', '/option',
array('option' => array('value' => '228', 'selected' => 'selected')), '228 value', '/option',
array('option' => array('value' => '228-1')), '228-1 value', '/option',
array('option' => array('value' => '228-2')), '228-2 value', '/option',
'/select'
);
$this->assertTags($result, $expected);
}
/**
* test that select() with optiongroups listens to the escape param.
*
* @return void
*/
public function testSelectOptionGroupEscaping() {
$options = array(
'>< Key' => array(
1 => 'One',
2 => 'Two'
)
);
$result = $this->Form->select('Model.field', $options, array('empty' => false));
$expected = array(
'select' => array('name' => 'data[Model][field]', 'id' => 'ModelField'),
'optgroup' => array('label' => '>< Key'),
array('option' => array('value' => '1')), 'One', '/option',
array('option' => array('value' => '2')), 'Two', '/option',
'/optgroup',
'/select'
);
$this->assertTags($result, $expected);
$options = array(
'>< Key' => array(
1 => 'One',
2 => 'Two'
)
);
$result = $this->Form->select('Model.field', $options, array('empty' => false, 'escape' => false));
$expected = array(
'select' => array('name' => 'data[Model][field]', 'id' => 'ModelField'),
'optgroup' => array('label' => '>< Key'),
array('option' => array('value' => '1')), 'One', '/option',
array('option' => array('value' => '2')), 'Two', '/option',
'/optgroup',
'/select'
);
$this->assertTags($result, $expected);
}
/**
* Tests that FormHelper::select() allows null to be passed in the $attributes parameter
*
* @return void
*/
public function testSelectWithNullAttributes() {
$result = $this->Form->select('Model.field', array('first', 'second'), array('empty' => false));
$expected = array(
'select' => array('name' => 'data[Model][field]', 'id' => 'ModelField'),
array('option' => array('value' => '0')),
'first',
'/option',
array('option' => array('value' => '1')),
'second',
'/option',
'/select'
);
$this->assertTags($result, $expected);
}
/**
* testNestedSelect method
*
* test select element generation with optgroups
*
* @return void
*/
public function testNestedSelect() {
$result = $this->Form->select(
'Model.field',
array(1 => 'One', 2 => 'Two', 'Three' => array(
3 => 'Three', 4 => 'Four', 5 => 'Five'
)), array('empty' => false)
);
$expected = array(
'select' => array('name' => 'data[Model][field]',
'id' => 'ModelField'),
array('option' => array('value' => 1)),
'One',
'/option',
array('option' => array('value' => 2)),
'Two',
'/option',
array('optgroup' => array('label' => 'Three')),
array('option' => array('value' => 4)),
'Four',
'/option',
array('option' => array('value' => 5)),
'Five',
'/option',
'/optgroup',
'/select'
);
$this->assertTags($result, $expected);
$result = $this->Form->select(
'Model.field',
array(1 => 'One', 2 => 'Two', 'Three' => array(3 => 'Three', 4 => 'Four')),
array('showParents' => true, 'empty' => false)
);
$expected = array(
'select' => array('name' => 'data[Model][field]', 'id' => 'ModelField'),
array('option' => array('value' => 1)),
'One',
'/option',
array('option' => array('value' => 2)),
'Two',
'/option',
array('optgroup' => array('label' => 'Three')),
array('option' => array('value' => 3)),
'Three',
'/option',
array('option' => array('value' => 4)),
'Four',
'/option',
'/optgroup',
'/select'
);
$this->assertTags($result, $expected);
}
/**
* testSelectMultiple method
*
* test generation of multiple select elements
*
* @return void
*/
public function testSelectMultiple() {
$options = array('first', 'second', 'third');
$result = $this->Form->select(
'Model.multi_field', $options, array('multiple' => true)
);
$expected = array(
'input' => array(
'type' => 'hidden', 'name' => 'data[Model][multi_field]', 'value' => '', 'id' => 'ModelMultiField_'
),
'select' => array(
'name' => 'data[Model][multi_field][]',
'id' => 'ModelMultiField', 'multiple' => 'multiple'
),
array('option' => array('value' => '0')),
'first',
'/option',
array('option' => array('value' => '1')),
'second',
'/option',
array('option' => array('value' => '2')),
'third',
'/option',
'/select'
);
$this->assertTags($result, $expected);
$result = $this->Form->select(
'Model.multi_field', $options, array('multiple' => 'multiple')
);
$expected = array(
'input' => array(
'type' => 'hidden', 'name' => 'data[Model][multi_field]', 'value' => '', 'id' => 'ModelMultiField_'
),
'select' => array(
'name' => 'data[Model][multi_field][]',
'id' => 'ModelMultiField', 'multiple' => 'multiple'
),
array('option' => array('value' => '0')),
'first',
'/option',
array('option' => array('value' => '1')),
'second',
'/option',
array('option' => array('value' => '2')),
'third',
'/option',
'/select'
);
$this->assertTags($result, $expected);
$result = $this->Form->select(
'Model.multi_field', $options, array('multiple' => true, 'value' => array(0, 1))
);
$expected = array(
'input' => array(
'type' => 'hidden', 'name' => 'data[Model][multi_field]', 'value' => '', 'id' => 'ModelMultiField_'
),
'select' => array(
'name' => 'data[Model][multi_field][]', 'id' => 'ModelMultiField',
'multiple' => 'multiple'
),
array('option' => array('value' => '0', 'selected' => 'selected')),
'first',
'/option',
array('option' => array('value' => '1', 'selected' => 'selected')),
'second',
'/option',
array('option' => array('value' => '2')),
'third',
'/option',
'/select'
);
$this->assertTags($result, $expected);
$result = $this->Form->select(
'Model.multi_field', $options, array('multiple' => false, 'value' => array(0, 1))
);
$expected = array(
'select' => array(
'name' => 'data[Model][multi_field]', 'id' => 'ModelMultiField'
),
array('option' => array('value' => '0', 'selected' => 'selected')),
'first',
'/option',
array('option' => array('value' => '1', 'selected' => 'selected')),
'second',
'/option',
array('option' => array('value' => '2')),
'third',
'/option',
'/select'
);
$this->assertTags($result, $expected);
}
/**
* test generation of habtm select boxes.
*
* @return void
*/
public function testHabtmSelectBox() {
$this->View->viewVars['contactTags'] = array(
1 => 'blue',
2 => 'red',
3 => 'green'
);
$this->Form->request->data = array(
'Contact' => array(),
'ContactTag' => array(
array(
'id' => 1,
'name' => 'blue'
),
array(
'id' => 3,
'name' => 'green'
)
)
);
$this->Form->create('Contact');
$result = $this->Form->input('ContactTag', array('div' => false, 'label' => false));
$expected = array(
'input' => array(
'type' => 'hidden', 'name' => 'data[ContactTag][ContactTag]', 'value' => '', 'id' => 'ContactTagContactTag_'
),
'select' => array(
'name' => 'data[ContactTag][ContactTag][]', 'id' => 'ContactTagContactTag',
'multiple' => 'multiple'
),
array('option' => array('value' => '1', 'selected' => 'selected')),
'blue',
'/option',
array('option' => array('value' => '2')),
'red',
'/option',
array('option' => array('value' => '3', 'selected' => 'selected')),
'green',
'/option',
'/select'
);
$this->assertTags($result, $expected);
}
/**
* test generation of multi select elements in checkbox format
*
* @return void
*/
public function testSelectMultipleCheckboxes() {
$result = $this->Form->select(
'Model.multi_field',
array('first', 'second', 'third'),
array('multiple' => 'checkbox')
);
$expected = array(
'input' => array(
'type' => 'hidden', 'name' => 'data[Model][multi_field]', 'value' => '', 'id' => 'ModelMultiField'
),
array('div' => array('class' => 'checkbox')),
array('input' => array(
'type' => 'checkbox', 'name' => 'data[Model][multi_field][]',
'value' => '0', 'id' => 'ModelMultiField0'
)),
array('label' => array('for' => 'ModelMultiField0')),
'first',
'/label',
'/div',
array('div' => array('class' => 'checkbox')),
array('input' => array(
'type' => 'checkbox', 'name' => 'data[Model][multi_field][]',
'value' => '1', 'id' => 'ModelMultiField1'
)),
array('label' => array('for' => 'ModelMultiField1')),
'second',
'/label',
'/div',
array('div' => array('class' => 'checkbox')),
array('input' => array(
'type' => 'checkbox', 'name' => 'data[Model][multi_field][]',
'value' => '2', 'id' => 'ModelMultiField2'
)),
array('label' => array('for' => 'ModelMultiField2')),
'third',
'/label',
'/div'
);
$this->assertTags($result, $expected);
$result = $this->Form->select(
'Model.multi_field',
array('a' => 'first', 'b' => 'second', 'c' => 'third'),
array('multiple' => 'checkbox')
);
$expected = array(
'input' => array(
'type' => 'hidden', 'name' => 'data[Model][multi_field]', 'value' => '', 'id' => 'ModelMultiField'
),
array('div' => array('class' => 'checkbox')),
array('input' => array(
'type' => 'checkbox', 'name' => 'data[Model][multi_field][]',
'value' => 'a', 'id' => 'ModelMultiFieldA'
)),
array('label' => array('for' => 'ModelMultiFieldA')),
'first',
'/label',
'/div',
array('div' => array('class' => 'checkbox')),
array('input' => array(
'type' => 'checkbox', 'name' => 'data[Model][multi_field][]',
'value' => 'b', 'id' => 'ModelMultiFieldB'
)),
array('label' => array('for' => 'ModelMultiFieldB')),
'second',
'/label',
'/div',
array('div' => array('class' => 'checkbox')),
array('input' => array(
'type' => 'checkbox', 'name' => 'data[Model][multi_field][]',
'value' => 'c', 'id' => 'ModelMultiFieldC'
)),
array('label' => array('for' => 'ModelMultiFieldC')),
'third',
'/label',
'/div'
);
$this->assertTags($result, $expected);
$result = $this->Form->select(
'Model.multi_field', array('1' => 'first'), array('multiple' => 'checkbox')
);
$expected = array(
'input' => array(
'type' => 'hidden', 'name' => 'data[Model][multi_field]', 'value' => '', 'id' => 'ModelMultiField'
),
array('div' => array('class' => 'checkbox')),
array('input' => array(
'type' => 'checkbox', 'name' => 'data[Model][multi_field][]',
'value' => '1', 'id' => 'ModelMultiField1'
)),
array('label' => array('for' => 'ModelMultiField1')),
'first',
'/label',
'/div'
);
$this->assertTags($result, $expected);
$this->Form->request->data = array('Model' => array('tags' => array(1)));
$result = $this->Form->select(
'Model.tags', array('1' => 'first', 'Array' => 'Array'), array('multiple' => 'checkbox')
);
$expected = array(
'input' => array(
'type' => 'hidden', 'name' => 'data[Model][tags]', 'value' => '', 'id' => 'ModelTags'
),
array('div' => array('class' => 'checkbox')),
array('input' => array(
'type' => 'checkbox', 'name' => 'data[Model][tags][]',
'value' => '1', 'id' => 'ModelTags1', 'checked' => 'checked'
)),
array('label' => array('for' => 'ModelTags1', 'class' => 'selected')),
'first',
'/label',
'/div',
array('div' => array('class' => 'checkbox')),
array('input' => array(
'type' => 'checkbox', 'name' => 'data[Model][tags][]',
'value' => 'Array', 'id' => 'ModelTagsArray'
)),
array('label' => array('for' => 'ModelTagsArray')),
'Array',
'/label',
'/div'
);
$this->assertTags($result, $expected);
}
/**
* test multiple checkboxes with div styles.
*
* @return void
*/
public function testSelectMultipleCheckboxDiv() {
$result = $this->Form->select(
'Model.tags',
array('first', 'second'),
array('multiple' => 'checkbox', 'class' => 'my-class')
);
$expected = array(
'input' => array(
'type' => 'hidden', 'name' => 'data[Model][tags]', 'value' => '', 'id' => 'ModelTags'
),
array('div' => array('class' => 'my-class')),
array('input' => array(
'type' => 'checkbox', 'name' => 'data[Model][tags][]',
'value' => '0', 'id' => 'ModelTags0'
)),
array('label' => array('for' => 'ModelTags0')), 'first', '/label',
'/div',
array('div' => array('class' => 'my-class')),
array('input' => array(
'type' => 'checkbox', 'name' => 'data[Model][tags][]',
'value' => '1', 'id' => 'ModelTags1'
)),
array('label' => array('for' => 'ModelTags1')), 'second', '/label',
'/div'
);
$this->assertTags($result, $expected);
$result = $this->Form->input('Model.tags', array(
'options' => array('first', 'second'),
'multiple' => 'checkbox',
'class' => 'my-class',
'div' => false,
'label' => false
));
$this->assertTags($result, $expected);
$Contact = ClassRegistry::getObject('Contact');
$Contact->validationErrors['tags'] = 'Select atleast one option';
$result = $this->Form->input('Contact.tags', array(
'options' => array('one'),
'multiple' => 'checkbox',
'label' => false,
'div' => false
));
$expected = array(
'input' => array('type' => 'hidden', 'class' => 'form-error', 'name' => 'data[Contact][tags]', 'value' => '', 'id' => 'ContactTags'),
array('div' => array('class' => 'checkbox form-error')),
array('input' => array('type' => 'checkbox', 'name' => 'data[Contact][tags][]', 'value' => '0', 'id' => 'ContactTags0')),
array('label' => array('for' => 'ContactTags0')),
'one',
'/label',
'/div'
);
$this->assertTags($result, $expected);
$result = $this->Form->input('Contact.tags', array(
'options' => array('one'),
'multiple' => 'checkbox',
'class' => 'mycheckbox',
'label' => false,
'div' => false
));
$expected = array(
'input' => array('type' => 'hidden', 'class' => 'form-error', 'name' => 'data[Contact][tags]', 'value' => '', 'id' => 'ContactTags'),
array('div' => array('class' => 'mycheckbox form-error')),
array('input' => array('type' => 'checkbox', 'name' => 'data[Contact][tags][]', 'value' => '0', 'id' => 'ContactTags0')),
array('label' => array('for' => 'ContactTags0')),
'one',
'/label',
'/div'
);
$this->assertTags($result, $expected);
}
/**
* Checks the security hash array generated for multiple-input checkbox elements
*
* @return void
*/
public function testSelectMultipleCheckboxSecurity() {
$this->Form->request['_Token'] = array('key' => 'testKey');
$this->assertEqual($this->Form->fields, array());
$result = $this->Form->select(
'Model.multi_field', array('1' => 'first', '2' => 'second', '3' => 'third'),
array('multiple' => 'checkbox')
);
$this->assertEqual($this->Form->fields, array('Model.multi_field'));
$result = $this->Form->secure($this->Form->fields);
$key = 'f7d573650a295b94e0938d32b323fde775e5f32b%3A';
$this->assertPattern('/"' . $key . '"/', $result);
}
/**
* testInputMultipleCheckboxes method
*
* test input() resulting in multi select elements being generated.
*
* @return void
*/
public function testInputMultipleCheckboxes() {
$result = $this->Form->input('Model.multi_field', array(
'options' => array('first', 'second', 'third'),
'multiple' => 'checkbox'
));
$expected = array(
array('div' => array('class' => 'input select')),
array('label' => array('for' => 'ModelMultiField')),
'Multi Field',
'/label',
'input' => array('type' => 'hidden', 'name' => 'data[Model][multi_field]', 'value' => '', 'id' => 'ModelMultiField'),
array('div' => array('class' => 'checkbox')),
array('input' => array('type' => 'checkbox', 'name' => 'data[Model][multi_field][]', 'value' => '0', 'id' => 'ModelMultiField0')),
array('label' => array('for' => 'ModelMultiField0')),
'first',
'/label',
'/div',
array('div' => array('class' => 'checkbox')),
array('input' => array('type' => 'checkbox', 'name' => 'data[Model][multi_field][]', 'value' => '1', 'id' => 'ModelMultiField1')),
array('label' => array('for' => 'ModelMultiField1')),
'second',
'/label',
'/div',
array('div' => array('class' => 'checkbox')),
array('input' => array('type' => 'checkbox', 'name' => 'data[Model][multi_field][]', 'value' => '2', 'id' => 'ModelMultiField2')),
array('label' => array('for' => 'ModelMultiField2')),
'third',
'/label',
'/div',
'/div'
);
$this->assertTags($result, $expected);
$result = $this->Form->input('Model.multi_field', array(
'options' => array('a' => 'first', 'b' => 'second', 'c' => 'third'),
'multiple' => 'checkbox'
));
$expected = array(
array('div' => array('class' => 'input select')),
array('label' => array('for' => 'ModelMultiField')),
'Multi Field',
'/label',
'input' => array('type' => 'hidden', 'name' => 'data[Model][multi_field]', 'value' => '', 'id' => 'ModelMultiField'),
array('div' => array('class' => 'checkbox')),
array('input' => array('type' => 'checkbox', 'name' => 'data[Model][multi_field][]', 'value' => 'a', 'id' => 'ModelMultiFieldA')),
array('label' => array('for' => 'ModelMultiFieldA')),
'first',
'/label',
'/div',
array('div' => array('class' => 'checkbox')),
array('input' => array('type' => 'checkbox', 'name' => 'data[Model][multi_field][]', 'value' => 'b', 'id' => 'ModelMultiFieldB')),
array('label' => array('for' => 'ModelMultiFieldB')),
'second',
'/label',
'/div',
array('div' => array('class' => 'checkbox')),
array('input' => array('type' => 'checkbox', 'name' => 'data[Model][multi_field][]', 'value' => 'c', 'id' => 'ModelMultiFieldC')),
array('label' => array('for' => 'ModelMultiFieldC')),
'third',
'/label',
'/div',
'/div'
);
$this->assertTags($result, $expected);
$result = $this->Form->input('Model.multi_field', array(
'options' => array('1' => 'first'),
'multiple' => 'checkbox',
'label' => false,
'div' => false
));
$expected = array(
'input' => array('type' => 'hidden', 'name' => 'data[Model][multi_field]', 'value' => '', 'id' => 'ModelMultiField'),
array('div' => array('class' => 'checkbox')),
array('input' => array('type' => 'checkbox', 'name' => 'data[Model][multi_field][]', 'value' => '1', 'id' => 'ModelMultiField1')),
array('label' => array('for' => 'ModelMultiField1')),
'first',
'/label',
'/div'
);
$this->assertTags($result, $expected);
$result = $this->Form->input('Model.multi_field', array(
'options' => array('2' => 'second'),
'multiple' => 'checkbox',
'label' => false,
'div' => false
));
$expected = array(
'input' => array('type' => 'hidden', 'name' => 'data[Model][multi_field]', 'value' => '', 'id' => 'ModelMultiField'),
array('div' => array('class' => 'checkbox')),
array('input' => array('type' => 'checkbox', 'name' => 'data[Model][multi_field][]', 'value' => '2', 'id' => 'ModelMultiField2')),
array('label' => array('for' => 'ModelMultiField2')),
'second',
'/label',
'/div'
);
$this->assertTags($result, $expected);
}
/**
* testSelectHiddenFieldOmission method
*
* test that select() with 'hiddenField' => false omits the hidden field
*
* @return void
*/
public function testSelectHiddenFieldOmission() {
$result = $this->Form->select('Model.multi_field',
array('first', 'second'),
array('multiple' => 'checkbox', 'hiddenField' => false, 'value' => null)
);
$expected = array(
array('div' => array('class' => 'checkbox')),
array('input' => array('type' => 'checkbox', 'name' => 'data[Model][multi_field][]', 'value' => '0', 'id' => 'ModelMultiField0')),
array('label' => array('for' => 'ModelMultiField0')),
'first',
'/label',
'/div',
array('div' => array('class' => 'checkbox')),
array('input' => array('type' => 'checkbox', 'name' => 'data[Model][multi_field][]', 'value' => '1', 'id' => 'ModelMultiField1')),
array('label' => array('for' => 'ModelMultiField1')),
'second',
'/label',
'/div'
);
$this->assertTags($result, $expected);
$result = $this->Form->input('Model.multi_field', array(
'options' => array('first', 'second'),
'multiple' => 'checkbox',
'hiddenField' => false
));
$expected = array(
array('div' => array('class' => 'input select')),
array('label' => array('for' => 'ModelMultiField')),
'Multi Field',
'/label',
array('div' => array('class' => 'checkbox')),
array('input' => array('type' => 'checkbox', 'name' => 'data[Model][multi_field][]', 'value' => '0', 'id' => 'ModelMultiField0')),
array('label' => array('for' => 'ModelMultiField0')),
'first',
'/label',
'/div',
array('div' => array('class' => 'checkbox')),
array('input' => array('type' => 'checkbox', 'name' => 'data[Model][multi_field][]', 'value' => '1', 'id' => 'ModelMultiField1')),
array('label' => array('for' => 'ModelMultiField1')),
'second',
'/label',
'/div',
'/div'
);
$this->assertTags($result, $expected);
}
/**
* test that select() with multiple = checkbox works with overriding name attribute.
*
* @return void
*/
public function testSelectCheckboxMultipleOverrideName() {
$result = $this->Form->input('category', array(
'type' => 'select',
'multiple' => 'checkbox',
'name' => 'data[fish]',
'options' => array('1', '2'),
'div' => false,
'label' => false,
));
$expected = array(
'input' => array('type' => 'hidden', 'name' => 'data[fish]', 'value' => '', 'id' => 'category'),
array('div' => array('class' => 'checkbox')),
array('input' => array('type' => 'checkbox', 'name' => 'data[fish][]', 'value' => '0', 'id' => 'Category0')),
array('label' => array('for' => 'Category0')), '1', '/label',
'/div',
array('div' => array('class' => 'checkbox')),
array('input' => array('type' => 'checkbox', 'name' => 'data[fish][]', 'value' => '1', 'id' => 'Category1')),
array('label' => array('for' => 'Category1')), '2', '/label',
'/div'
);
$this->assertTags($result, $expected);
}
/**
* Test that 'id' overrides all the checkbox id's as well.
*
* @return void
*/
public function testSelectCheckboxMultipleId() {
$result = $this->Form->select(
'Model.multi_field',
array('first', 'second', 'third'),
array('multiple' => 'checkbox', 'id' => 'CustomId')
);
$expected = array(
'input' => array(
'type' => 'hidden', 'name' => 'data[Model][multi_field]', 'value' => '', 'id' => 'CustomId'
),
array('div' => array('class' => 'checkbox')),
array('input' => array(
'type' => 'checkbox', 'name' => 'data[Model][multi_field][]',
'value' => '0', 'id' => 'CustomId0'
)),
array('label' => array('for' => 'CustomId0')),
'first',
'/label',
'/div',
array('div' => array('class' => 'checkbox')),
array('input' => array(
'type' => 'checkbox', 'name' => 'data[Model][multi_field][]',
'value' => '1', 'id' => 'CustomId1'
)),
array('label' => array('for' => 'CustomId1')),
'second',
'/label',
'/div',
array('div' => array('class' => 'checkbox')),
array('input' => array(
'type' => 'checkbox', 'name' => 'data[Model][multi_field][]',
'value' => '2', 'id' => 'CustomId2'
)),
array('label' => array('for' => 'CustomId2')),
'third',
'/label',
'/div'
);
$this->assertTags($result, $expected);
}
/**
* testCheckbox method
*
* Test generation of checkboxes
*
* @return void
*/
public function testCheckbox() {
$result = $this->Form->checkbox('Model.field');
$expected = array(
'input' => array('type' => 'hidden', 'name' => 'data[Model][field]', 'value' => '0', 'id' => 'ModelField_'),
array('input' => array('type' => 'checkbox', 'name' => 'data[Model][field]', 'value' => '1', 'id' => 'ModelField'))
);
$this->assertTags($result, $expected);
$result = $this->Form->checkbox('Model.field', array('id' => 'theID', 'value' => 'myvalue'));
$expected = array(
'input' => array('type' => 'hidden', 'name' => 'data[Model][field]', 'value' => '0', 'id' => 'theID_'),
array('input' => array('type' => 'checkbox', 'name' => 'data[Model][field]', 'value' => 'myvalue', 'id' => 'theID'))
);
$this->assertTags($result, $expected);
$Contact = ClassRegistry::getObject('Contact');
$Contact->validationErrors['field'] = 1;
$this->Form->request->data['Contact']['field'] = 'myvalue';
$result = $this->Form->checkbox('Contact.field', array('id' => 'theID', 'value' => 'myvalue'));
$expected = array(
'input' => array('type' => 'hidden', 'class' => 'form-error', 'name' => 'data[Contact][field]', 'value' => '0', 'id' => 'theID_'),
array('input' => array('preg:/[^<]+/', 'value' => 'myvalue', 'id' => 'theID', 'checked' => 'checked', 'class' => 'form-error'))
);
$this->assertTags($result, $expected);
$result = $this->Form->checkbox('Contact.field', array('value' => 'myvalue'));
$expected = array(
'input' => array('type' => 'hidden', 'class' => 'form-error', 'name' => 'data[Contact][field]', 'value' => '0', 'id' => 'ContactField_'),
array('input' => array('preg:/[^<]+/', 'value' => 'myvalue', 'id' => 'ContactField', 'checked' => 'checked', 'class' => 'form-error'))
);
$this->assertTags($result, $expected);
$this->Form->request->data['Contact']['field'] = '';
$result = $this->Form->checkbox('Contact.field', array('id' => 'theID'));
$expected = array(
'input' => array('type' => 'hidden', 'class' => 'form-error', 'name' => 'data[Contact][field]', 'value' => '0', 'id' => 'theID_'),
array('input' => array('type' => 'checkbox', 'name' => 'data[Contact][field]', 'value' => '1', 'id' => 'theID', 'class' => 'form-error'))
);
$this->assertTags($result, $expected);
$Contact->validationErrors = array();
$result = $this->Form->checkbox('Contact.field', array('value' => 'myvalue'));
$expected = array(
'input' => array('type' => 'hidden', 'name' => 'data[Contact][field]', 'value' => '0', 'id' => 'ContactField_'),
array('input' => array('type' => 'checkbox', 'name' => 'data[Contact][field]', 'value' => 'myvalue', 'id' => 'ContactField'))
);
$this->assertTags($result, $expected);
$this->Form->request->data['Contact']['published'] = 1;
$result = $this->Form->checkbox('Contact.published', array('id' => 'theID'));
$expected = array(
'input' => array('type' => 'hidden', 'name' => 'data[Contact][published]', 'value' => '0', 'id' => 'theID_'),
array('input' => array('type' => 'checkbox', 'name' => 'data[Contact][published]', 'value' => '1', 'id' => 'theID', 'checked' => 'checked'))
);
$this->assertTags($result, $expected);
$this->Form->request->data['Contact']['published'] = 0;
$result = $this->Form->checkbox('Contact.published', array('id'=>'theID'));
$expected = array(
'input' => array('type' => 'hidden', 'name' => 'data[Contact][published]', 'value' => '0', 'id' => 'theID_'),
array('input' => array('type' => 'checkbox', 'name' => 'data[Contact][published]', 'value' => '1', 'id' => 'theID'))
);
$this->assertTags($result, $expected);
$result = $this->Form->checkbox('Model.CustomField.1.value');
$expected = array(
'input' => array('type' => 'hidden', 'name' => 'data[Model][CustomField][1][value]', 'value' => '0', 'id' => 'ModelCustomField1Value_'),
array('input' => array('type' => 'checkbox', 'name' => 'data[Model][CustomField][1][value]', 'value' => '1', 'id' => 'ModelCustomField1Value'))
);
$this->assertTags($result, $expected);
$result = $this->Form->checkbox('CustomField.1.value');
$expected = array(
'input' => array('type' => 'hidden', 'name' => 'data[CustomField][1][value]', 'value' => '0', 'id' => 'CustomField1Value_'),
array('input' => array('type' => 'checkbox', 'name' => 'data[CustomField][1][value]', 'value' => '1', 'id' => 'CustomField1Value'))
);
$this->assertTags($result, $expected);
}
/**
* test checkbox() with a custom name attribute
*
* @return void
*/
public function testCheckboxCustomNameAttribute() {
$result = $this->Form->checkbox('Test.test', array('name' => 'myField'));
$expected = array(
'input' => array('type' => 'hidden', 'name' => 'myField', 'value' => '0', 'id' => 'TestTest_'),
array('input' => array('type' => 'checkbox', 'name' => 'myField', 'value' => '1', 'id' => 'TestTest'))
);
$this->assertTags($result, $expected);
}
/**
* test the checked option for checkboxes.
*
* @return void
*/
public function testCheckboxCheckedOption() {
$result = $this->Form->checkbox('Model.field', array('checked' => 'checked'));
$expected = array(
'input' => array('type' => 'hidden', 'name' => 'data[Model][field]', 'value' => '0', 'id' => 'ModelField_'),
array('input' => array('type' => 'checkbox', 'name' => 'data[Model][field]', 'value' => '1', 'id' => 'ModelField', 'checked' => 'checked'))
);
$this->assertTags($result, $expected);
$result = $this->Form->checkbox('Model.field', array('checked' => 1));
$expected = array(
'input' => array('type' => 'hidden', 'name' => 'data[Model][field]', 'value' => '0', 'id' => 'ModelField_'),
array('input' => array('type' => 'checkbox', 'name' => 'data[Model][field]', 'value' => '1', 'id' => 'ModelField', 'checked' => 'checked'))
);
$this->assertTags($result, $expected);
$result = $this->Form->checkbox('Model.field', array('checked' => true));
$expected = array(
'input' => array('type' => 'hidden', 'name' => 'data[Model][field]', 'value' => '0', 'id' => 'ModelField_'),
array('input' => array('type' => 'checkbox', 'name' => 'data[Model][field]', 'value' => '1', 'id' => 'ModelField', 'checked' => 'checked'))
);
$this->assertTags($result, $expected);
$result = $this->Form->checkbox('Model.field', array('checked' => false));
$expected = array(
'input' => array('type' => 'hidden', 'name' => 'data[Model][field]', 'value' => '0', 'id' => 'ModelField_'),
array('input' => array('type' => 'checkbox', 'name' => 'data[Model][field]', 'value' => '1', 'id' => 'ModelField'))
);
$this->assertTags($result, $expected);
$this->Form->request->data['Model']['field'] = 1;
$result = $this->Form->checkbox('Model.field', array('checked' => false));
$expected = array(
'input' => array('type' => 'hidden', 'name' => 'data[Model][field]', 'value' => '0', 'id' => 'ModelField_'),
array('input' => array('type' => 'checkbox', 'name' => 'data[Model][field]', 'value' => '1', 'id' => 'ModelField'))
);
$this->assertTags($result, $expected);
}
/**
* Test that disabled attribute works on both the checkbox and hidden input.
*
* @return void
*/
public function testCheckboxDisabling() {
$result = $this->Form->checkbox('Account.show_name', array('disabled' => 'disabled'));
$expected = array(
array('input' => array('type' => 'hidden', 'name' => 'data[Account][show_name]', 'value' => '0', 'id' => 'AccountShowName_', 'disabled' => 'disabled')),
array('input' => array('type' => 'checkbox', 'name' => 'data[Account][show_name]', 'value' => '1', 'id' => 'AccountShowName', 'disabled' => 'disabled'))
);
$this->assertTags($result, $expected);
$result = $this->Form->checkbox('Account.show_name', array('disabled' => false));
$expected = array(
array('input' => array('type' => 'hidden', 'name' => 'data[Account][show_name]', 'value' => '0', 'id' => 'AccountShowName_')),
array('input' => array('type' => 'checkbox', 'name' => 'data[Account][show_name]', 'value' => '1', 'id' => 'AccountShowName'))
);
$this->assertTags($result, $expected);
}
/**
* Test that the hidden input for checkboxes can be removed/omitted from the output.
*
* @return void
*/
public function testCheckboxHiddenFieldOmission() {
$result = $this->Form->input('UserForm.something', array(
'type' => 'checkbox',
'hiddenField' => false
)
);
$expected = array(
'div' => array('class' => 'input checkbox'),
array('input' => array(
'type' => 'checkbox', 'name' => 'data[UserForm][something]',
'value' => '1', 'id' => 'UserFormSomething'
)),
'label' => array('for' => 'UserFormSomething'),
'Something',
'/label',
'/div'
);
$this->assertTags($result, $expected);
}
/**
* testDateTime method
*
* Test generation of date/time select elements
*
* @return void
*/
public function testDateTime() {
extract($this->dateRegex);
$result = $this->Form->dateTime('Contact.date', 'DMY', '12', array('empty' => false));
$now = strtotime('now');
$expected = array(
array('select' => array('name' => 'data[Contact][date][day]', 'id' => 'ContactDateDay')),
$daysRegex,
array('option' => array('value' => date('d', $now), 'selected' => 'selected')),
date('j', $now),
'/option',
'*/select',
'-',
array('select' => array('name' => 'data[Contact][date][month]', 'id' => 'ContactDateMonth')),
$monthsRegex,
array('option' => array('value' => date('m', $now), 'selected' => 'selected')),
date('F', $now),
'/option',
'*/select',
'-',
array('select' => array('name' => 'data[Contact][date][year]', 'id' => 'ContactDateYear')),
$yearsRegex,
array('option' => array('value' => date('Y', $now), 'selected' => 'selected')),
date('Y', $now),
'/option',
'*/select',
array('select' => array('name' => 'data[Contact][date][hour]', 'id' => 'ContactDateHour')),
$hoursRegex,
array('option' => array('value' => date('h', $now), 'selected' => 'selected')),
date('g', $now),
'/option',
'*/select',
':',
array('select' => array('name' => 'data[Contact][date][min]', 'id' => 'ContactDateMin')),
$minutesRegex,
array('option' => array('value' => date('i', $now), 'selected' => 'selected')),
date('i', $now),
'/option',
'*/select',
' ',
array('select' => array('name' => 'data[Contact][date][meridian]', 'id' => 'ContactDateMeridian')),
$meridianRegex,
array('option' => array('value' => date('a', $now), 'selected' => 'selected')),
date('a', $now),
'/option',
'*/select'
);
$this->assertTags($result, $expected);
$result = $this->Form->dateTime('Contact.date', 'DMY', '12');
$expected = array(
array('select' => array('name' => 'data[Contact][date][day]', 'id' => 'ContactDateDay')),
$daysRegex,
array('option' => array('value' => '')),
'/option',
'*/select',
'-',
array('select' => array('name' => 'data[Contact][date][month]', 'id' => 'ContactDateMonth')),
$monthsRegex,
array('option' => array('value' => '')),
'/option',
'*/select',
'-',
array('select' => array('name' => 'data[Contact][date][year]', 'id' => 'ContactDateYear')),
$yearsRegex,
array('option' => array('value' => '')),
'/option',
'*/select',
array('select' => array('name' => 'data[Contact][date][hour]', 'id' => 'ContactDateHour')),
$hoursRegex,
array('option' => array('value' => '')),
'/option',
'*/select',
':',
array('select' => array('name' => 'data[Contact][date][min]', 'id' => 'ContactDateMin')),
$minutesRegex,
array('option' => array('value' => '')),
'/option',
'*/select',
' ',
array('select' => array('name' => 'data[Contact][date][meridian]', 'id' => 'ContactDateMeridian')),
$meridianRegex,
array('option' => array('value' => '')),
'/option',
'*/select'
);
$this->assertTags($result, $expected);
$this->assertNoPattern('/<option[^<>]+value=""[^<>]+selected="selected"[^>]*>/', $result);
$result = $this->Form->dateTime('Contact.date', 'DMY', '12', array('value' => false));
$expected = array(
array('select' => array('name' => 'data[Contact][date][day]', 'id' => 'ContactDateDay')),
$daysRegex,
array('option' => array('value' => '')),
'/option',
'*/select',
'-',
array('select' => array('name' => 'data[Contact][date][month]', 'id' => 'ContactDateMonth')),
$monthsRegex,
array('option' => array('value' => '')),
'/option',
'*/select',
'-',
array('select' => array('name' => 'data[Contact][date][year]', 'id' => 'ContactDateYear')),
$yearsRegex,
array('option' => array('value' => '')),
'/option',
'*/select',
array('select' => array('name' => 'data[Contact][date][hour]', 'id' => 'ContactDateHour')),
$hoursRegex,
array('option' => array('value' => '')),
'/option',
'*/select',
':',
array('select' => array('name' => 'data[Contact][date][min]', 'id' => 'ContactDateMin')),
$minutesRegex,
array('option' => array('value' => '')),
'/option',
'*/select',
' ',
array('select' => array('name' => 'data[Contact][date][meridian]', 'id' => 'ContactDateMeridian')),
$meridianRegex,
array('option' => array('value' => '')),
'/option',
'*/select'
);
$this->assertTags($result, $expected);
$this->assertNoPattern('/<option[^<>]+value=""[^<>]+selected="selected"[^>]*>/', $result);
$result = $this->Form->dateTime('Contact.date', 'DMY', '12', array('value' => ''));
$expected = array(
array('select' => array('name' => 'data[Contact][date][day]', 'id' => 'ContactDateDay')),
$daysRegex,
array('option' => array('value' => '')),
'/option',
'*/select',
'-',
array('select' => array('name' => 'data[Contact][date][month]', 'id' => 'ContactDateMonth')),
$monthsRegex,
array('option' => array('value' => '')),
'/option',
'*/select',
'-',
array('select' => array('name' => 'data[Contact][date][year]', 'id' => 'ContactDateYear')),
$yearsRegex,
array('option' => array('value' => '')),
'/option',
'*/select',
array('select' => array('name' => 'data[Contact][date][hour]', 'id' => 'ContactDateHour')),
$hoursRegex,
array('option' => array('value' => '')),
'/option',
'*/select',
':',
array('select' => array('name' => 'data[Contact][date][min]', 'id' => 'ContactDateMin')),
$minutesRegex,
array('option' => array('value' => '')),
'/option',
'*/select',
' ',
array('select' => array('name' => 'data[Contact][date][meridian]', 'id' => 'ContactDateMeridian')),
$meridianRegex,
array('option' => array('value' => '')),
'/option',
'*/select'
);
$this->assertTags($result, $expected);
$this->assertNoPattern('/<option[^<>]+value=""[^<>]+selected="selected"[^>]*>/', $result);
$result = $this->Form->dateTime('Contact.date', 'DMY', '12', array('interval' => 5, 'value' => ''));
$expected = array(
array('select' => array('name' => 'data[Contact][date][day]', 'id' => 'ContactDateDay')),
$daysRegex,
array('option' => array('value' => '')),
'/option',
'*/select',
'-',
array('select' => array('name' => 'data[Contact][date][month]', 'id' => 'ContactDateMonth')),
$monthsRegex,
array('option' => array('value' => '')),
'/option',
'*/select',
'-',
array('select' => array('name' => 'data[Contact][date][year]', 'id' => 'ContactDateYear')),
$yearsRegex,
array('option' => array('value' => '')),
'/option',
'*/select',
array('select' => array('name' => 'data[Contact][date][hour]', 'id' => 'ContactDateHour')),
$hoursRegex,
array('option' => array('value' => '')),
'/option',
'*/select',
':',
array('select' => array('name' => 'data[Contact][date][min]', 'id' => 'ContactDateMin')),
$minutesRegex,
array('option' => array('value' => '')),
'/option',
array('option' => array('value' => '00')),
'00',
'/option',
array('option' => array('value' => '05')),
'05',
'/option',
array('option' => array('value' => '10')),
'10',
'/option',
'*/select',
' ',
array('select' => array('name' => 'data[Contact][date][meridian]', 'id' => 'ContactDateMeridian')),
$meridianRegex,
array('option' => array('value' => '')),
'/option',
'*/select'
);
$this->assertTags($result, $expected);
$this->assertNoPattern('/<option[^<>]+value=""[^<>]+selected="selected"[^>]*>/', $result);
$result = $this->Form->dateTime('Contact.date', 'DMY', '12', array('minuteInterval' => 5, 'value' => ''));
$expected = array(
array('select' => array('name' => 'data[Contact][date][day]', 'id' => 'ContactDateDay')),
$daysRegex,
array('option' => array('value' => '')),
'/option',
'*/select',
'-',
array('select' => array('name' => 'data[Contact][date][month]', 'id' => 'ContactDateMonth')),
$monthsRegex,
array('option' => array('value' => '')),
'/option',
'*/select',
'-',
array('select' => array('name' => 'data[Contact][date][year]', 'id' => 'ContactDateYear')),
$yearsRegex,
array('option' => array('value' => '')),
'/option',
'*/select',
array('select' => array('name' => 'data[Contact][date][hour]', 'id' => 'ContactDateHour')),
$hoursRegex,
array('option' => array('value' => '')),
'/option',
'*/select',
':',
array('select' => array('name' => 'data[Contact][date][min]', 'id' => 'ContactDateMin')),
$minutesRegex,
array('option' => array('value' => '')),
'/option',
array('option' => array('value' => '00')),
'00',
'/option',
array('option' => array('value' => '05')),
'05',
'/option',
array('option' => array('value' => '10')),
'10',
'/option',
'*/select',
' ',
array('select' => array('name' => 'data[Contact][date][meridian]', 'id' => 'ContactDateMeridian')),
$meridianRegex,
array('option' => array('value' => '')),
'/option',
'*/select'
);
$this->assertTags($result, $expected);
$this->assertNoPattern('/<option[^<>]+value=""[^<>]+selected="selected"[^>]*>/', $result);
$this->Form->request->data['Contact']['data'] = null;
$result = $this->Form->dateTime('Contact.date', 'DMY', '12');
$expected = array(
array('select' => array('name' => 'data[Contact][date][day]', 'id' => 'ContactDateDay')),
$daysRegex,
array('option' => array('value' => '')),
'/option',
'*/select',
'-',
array('select' => array('name' => 'data[Contact][date][month]', 'id' => 'ContactDateMonth')),
$monthsRegex,
array('option' => array('value' => '')),
'/option',
'*/select',
'-',
array('select' => array('name' => 'data[Contact][date][year]', 'id' => 'ContactDateYear')),
$yearsRegex,
array('option' => array('value' => '')),
'/option',
'*/select',
array('select' => array('name' => 'data[Contact][date][hour]', 'id' => 'ContactDateHour')),
$hoursRegex,
array('option' => array('value' => '')),
'/option',
'*/select',
':',
array('select' => array('name' => 'data[Contact][date][min]', 'id' => 'ContactDateMin')),
$minutesRegex,
array('option' => array('value' => '')),
'/option',
'*/select',
' ',
array('select' => array('name' => 'data[Contact][date][meridian]', 'id' => 'ContactDateMeridian')),
$meridianRegex,
array('option' => array('value' => '')),
'/option',
'*/select'
);
$this->assertTags($result, $expected);
$this->assertNoPattern('/<option[^<>]+value=""[^<>]+selected="selected"[^>]*>/', $result);
$this->Form->request->data['Model']['field'] = date('Y') . '-01-01 00:00:00';
$now = strtotime($this->Form->data['Model']['field']);
$result = $this->Form->dateTime('Model.field', 'DMY', '12', array('empty' => false));
$expected = array(
array('select' => array('name' => 'data[Model][field][day]', 'id' => 'ModelFieldDay')),
$daysRegex,
array('option' => array('value' => date('d', $now), 'selected' => 'selected')),
date('j', $now),
'/option',
'*/select',
'-',
array('select' => array('name' => 'data[Model][field][month]', 'id' => 'ModelFieldMonth')),
$monthsRegex,
array('option' => array('value' => date('m', $now), 'selected' => 'selected')),
date('F', $now),
'/option',
'*/select',
'-',
array('select' => array('name' => 'data[Model][field][year]', 'id' => 'ModelFieldYear')),
$yearsRegex,
array('option' => array('value' => date('Y', $now), 'selected' => 'selected')),
date('Y', $now),
'/option',
'*/select',
array('select' => array('name' => 'data[Model][field][hour]', 'id' => 'ModelFieldHour')),
$hoursRegex,
array('option' => array('value' => date('h', $now), 'selected' => 'selected')),
date('g', $now),
'/option',
'*/select',
':',
array('select' => array('name' => 'data[Model][field][min]', 'id' => 'ModelFieldMin')),
$minutesRegex,
array('option' => array('value' => date('i', $now), 'selected' => 'selected')),
date('i', $now),
'/option',
'*/select',
' ',
array('select' => array('name' => 'data[Model][field][meridian]', 'id' => 'ModelFieldMeridian')),
$meridianRegex,
array('option' => array('value' => date('a', $now), 'selected' => 'selected')),
date('a', $now),
'/option',
'*/select'
);
$this->assertTags($result, $expected);
$selected = strtotime('2008-10-26 12:33:00');
$result = $this->Form->dateTime('Model.field', 'DMY', '12', array('value' => $selected));
$this->assertPattern('/<option[^<>]+value="2008"[^<>]+selected="selected"[^>]*>2008<\/option>/', $result);
$this->assertPattern('/<option[^<>]+value="10"[^<>]+selected="selected"[^>]*>October<\/option>/', $result);
$this->assertPattern('/<option[^<>]+value="26"[^<>]+selected="selected"[^>]*>26<\/option>/', $result);
$this->assertPattern('/<option[^<>]+value="12"[^<>]+selected="selected"[^>]*>12<\/option>/', $result);
$this->assertPattern('/<option[^<>]+value="33"[^<>]+selected="selected"[^>]*>33<\/option>/', $result);
$this->assertPattern('/<option[^<>]+value="pm"[^<>]+selected="selected"[^>]*>pm<\/option>/', $result);
$this->Form->create('Contact');
$result = $this->Form->input('published');
$now = strtotime('now');
$expected = array(
'div' => array('class' => 'input date'),
'label' => array('for' => 'ContactPublishedMonth'),
'Published',
'/label',
array('select' => array('name' => 'data[Contact][published][month]', 'id' => 'ContactPublishedMonth')),
$monthsRegex,
array('option' => array('value' => date('m', $now), 'selected' => 'selected')),
date('F', $now),
'/option',
'*/select',
'-',
array('select' => array('name' => 'data[Contact][published][day]', 'id' => 'ContactPublishedDay')),
$daysRegex,
array('option' => array('value' => date('d', $now), 'selected' => 'selected')),
date('j', $now),
'/option',
'*/select',
'-',
array('select' => array('name' => 'data[Contact][published][year]', 'id' => 'ContactPublishedYear')),
$yearsRegex,
array('option' => array('value' => date('Y', $now), 'selected' => 'selected')),
date('Y', $now),
'/option',
'*/select',
'/div'
);
$this->assertTags($result, $expected);
$result = $this->Form->input('published2', array('type' => 'date'));
$now = strtotime('now');
$expected = array(
'div' => array('class' => 'input date'),
'label' => array('for' => 'ContactPublished2Month'),
'Published2',
'/label',
array('select' => array('name' => 'data[Contact][published2][month]', 'id' => 'ContactPublished2Month')),
$monthsRegex,
array('option' => array('value' => date('m', $now), 'selected' => 'selected')),
date('F', $now),
'/option',
'*/select',
'-',
array('select' => array('name' => 'data[Contact][published2][day]', 'id' => 'ContactPublished2Day')),
$daysRegex,
array('option' => array('value' => date('d', $now), 'selected' => 'selected')),
date('j', $now),
'/option',
'*/select',
'-',
array('select' => array('name' => 'data[Contact][published2][year]', 'id' => 'ContactPublished2Year')),
$yearsRegex,
array('option' => array('value' => date('Y', $now), 'selected' => 'selected')),
date('Y', $now),
'/option',
'*/select',
'/div'
);
$this->assertTags($result, $expected);
$this->Form->create('Contact');
$result = $this->Form->input('published', array('monthNames' => false));
$now = strtotime('now');
$expected = array(
'div' => array('class' => 'input date'),
'label' => array('for' => 'ContactPublishedMonth'),
'Published',
'/label',
array('select' => array('name' => 'data[Contact][published][month]', 'id' => 'ContactPublishedMonth')),
'preg:/(?:<option value="([\d])+">[\d]+<\/option>[\r\n]*)*/',
array('option' => array('value' => date('m', $now), 'selected' => 'selected')),
date('m', $now),
'/option',
'*/select',
'-',
array('select' => array('name' => 'data[Contact][published][day]', 'id' => 'ContactPublishedDay')),
$daysRegex,
array('option' => array('value' => date('d', $now), 'selected' => 'selected')),
date('j', $now),
'/option',
'*/select',
'-',
array('select' => array('name' => 'data[Contact][published][year]', 'id' => 'ContactPublishedYear')),
$yearsRegex,
array('option' => array('value' => date('Y', $now), 'selected' => 'selected')),
date('Y', $now),
'/option',
'*/select',
'/div'
);
$this->assertTags($result, $expected);
$result = $this->Form->input('published', array('type' => 'time'));
$now = strtotime('now');
$expected = array(
'div' => array('class' => 'input time'),
'label' => array('for' => 'ContactPublishedHour'),
'Published',
'/label',
array('select' => array('name' => 'data[Contact][published][hour]', 'id' => 'ContactPublishedHour')),
'preg:/(?:<option value="([\d])+">[\d]+<\/option>[\r\n]*)*/',
array('option' => array('value' => date('h', $now), 'selected' => 'selected')),
date('g', $now),
'/option',
'*/select',
':',
);
$this->assertTags($result, $expected);
$result = $this->Form->input('published', array(
'timeFormat' => 24,
'interval' => 5,
'selected' => strtotime('2009-09-03 13:37:00'),
'type' => 'datetime'
));
$this->assertPattern('/<option[^<>]+value="2009"[^<>]+selected="selected"[^>]*>2009<\/option>/', $result);
$this->assertPattern('/<option[^<>]+value="09"[^<>]+selected="selected"[^>]*>September<\/option>/', $result);
$this->assertPattern('/<option[^<>]+value="03"[^<>]+selected="selected"[^>]*>3<\/option>/', $result);
$this->assertPattern('/<option[^<>]+value="13"[^<>]+selected="selected"[^>]*>13<\/option>/', $result);
$this->assertPattern('/<option[^<>]+value="35"[^<>]+selected="selected"[^>]*>35<\/option>/', $result);
$this->assertNoErrors();
$this->Form->request->data['Contact'] = array(
'date' => array(
'day' => '',
'month' => '',
'year' => '',
'hour' => '',
'min' => '',
'meridian' => ''
)
);
$result = $this->Form->dateTime('Contact.date', 'DMY', '12', array('empty' => false));
}
/**
* test that datetime() and default values work.
*
* @return void
*/
public function testDatetimeWithDefault() {
$result = $this->Form->dateTime('Contact.updated', 'DMY', '12', array('value' => '2009-06-01 11:15:30'));
$this->assertPattern('/<option[^<>]+value="2009"[^<>]+selected="selected"[^>]*>2009<\/option>/', $result);
$this->assertPattern('/<option[^<>]+value="01"[^<>]+selected="selected"[^>]*>1<\/option>/', $result);
$this->assertPattern('/<option[^<>]+value="06"[^<>]+selected="selected"[^>]*>June<\/option>/', $result);
$result = $this->Form->dateTime('Contact.updated', 'DMY', '12', array(
'default' => '2009-06-01 11:15:30'
));
$this->assertPattern('/<option[^<>]+value="2009"[^<>]+selected="selected"[^>]*>2009<\/option>/', $result);
$this->assertPattern('/<option[^<>]+value="01"[^<>]+selected="selected"[^>]*>1<\/option>/', $result);
$this->assertPattern('/<option[^<>]+value="06"[^<>]+selected="selected"[^>]*>June<\/option>/', $result);
}
/**
* test that bogus non-date time data doesn't cause errors.
*
* @return void
*/
public function testDateTimeWithBogusData() {
$result = $this->Form->dateTime('Contact.updated', 'DMY', '12', array('value' => 'CURRENT_TIMESTAMP'));
$this->assertNoPattern('/selected="selected">\d/', $result);
}
/**
* testFormDateTimeMulti method
*
* test multiple datetime element generation
*
* @return void
*/
public function testFormDateTimeMulti() {
extract($this->dateRegex);
$result = $this->Form->dateTime('Contact.1.updated');
$expected = array(
array('select' => array('name' => 'data[Contact][1][updated][day]', 'id' => 'Contact1UpdatedDay')),
$daysRegex,
array('option' => array('value' => '')),
'/option',
'*/select',
'-',
array('select' => array('name' => 'data[Contact][1][updated][month]', 'id' => 'Contact1UpdatedMonth')),
$monthsRegex,
array('option' => array('value' => '')),
'/option',
'*/select',
'-',
array('select' => array('name' => 'data[Contact][1][updated][year]', 'id' => 'Contact1UpdatedYear')),
$yearsRegex,
array('option' => array('value' => '')),
'/option',
'*/select',
array('select' => array('name' => 'data[Contact][1][updated][hour]', 'id' => 'Contact1UpdatedHour')),
$hoursRegex,
array('option' => array('value' => '')),
'/option',
'*/select',
':',
array('select' => array('name' => 'data[Contact][1][updated][min]', 'id' => 'Contact1UpdatedMin')),
$minutesRegex,
array('option' => array('value' => '')),
'/option',
'*/select',
' ',
array('select' => array('name' => 'data[Contact][1][updated][meridian]', 'id' => 'Contact1UpdatedMeridian')),
$meridianRegex,
array('option' => array('value' => '')),
'/option',
'*/select'
);
$this->assertTags($result, $expected);
$result = $this->Form->dateTime('Contact.2.updated');
$expected = array(
array('select' => array('name' => 'data[Contact][2][updated][day]', 'id' => 'Contact2UpdatedDay')),
$daysRegex,
array('option' => array('value' => '')),
'/option',
'*/select',
'-',
array('select' => array('name' => 'data[Contact][2][updated][month]', 'id' => 'Contact2UpdatedMonth')),
$monthsRegex,
array('option' => array('value' => '')),
'/option',
'*/select',
'-',
array('select' => array('name' => 'data[Contact][2][updated][year]', 'id' => 'Contact2UpdatedYear')),
$yearsRegex,
array('option' => array('value' => '')),
'/option',
'*/select',
array('select' => array('name' => 'data[Contact][2][updated][hour]', 'id' => 'Contact2UpdatedHour')),
$hoursRegex,
array('option' => array('value' => '')),
'/option',
'*/select',
':',
array('select' => array('name' => 'data[Contact][2][updated][min]', 'id' => 'Contact2UpdatedMin')),
$minutesRegex,
array('option' => array('value' => '')),
'/option',
'*/select',
' ',
array('select' => array('name' => 'data[Contact][2][updated][meridian]', 'id' => 'Contact2UpdatedMeridian')),
$meridianRegex,
array('option' => array('value' => '')),
'/option',
'*/select'
);
$this->assertTags($result, $expected);
}
/**
* testMonth method
*
* @return void
*/
public function testMonth() {
$result = $this->Form->month('Model.field');
$expected = array(
array('select' => array('name' => 'data[Model][field][month]', 'id' => 'ModelFieldMonth')),
array('option' => array('value' => '')),
'/option',
array('option' => array('value' => '01')),
date('F', strtotime('2008-01-01 00:00:00')),
'/option',
array('option' => array('value' => '02')),
date('F', strtotime('2008-02-01 00:00:00')),
'/option',
'*/select',
);
$this->assertTags($result, $expected);
$result = $this->Form->month('Model.field', array('empty' => true));
$expected = array(
array('select' => array('name' => 'data[Model][field][month]', 'id' => 'ModelFieldMonth')),
array('option' => array('value' => '')),
'/option',
array('option' => array('value' => '01')),
date('F', strtotime('2008-01-01 00:00:00')),
'/option',
array('option' => array('value' => '02')),
date('F', strtotime('2008-02-01 00:00:00')),
'/option',
'*/select',
);
$this->assertTags($result, $expected);
$result = $this->Form->month('Model.field', array('monthNames' => false));
$expected = array(
array('select' => array('name' => 'data[Model][field][month]', 'id' => 'ModelFieldMonth')),
array('option' => array('value' => '')),
'/option',
array('option' => array('value' => '01')),
'01',
'/option',
array('option' => array('value' => '02')),
'02',
'/option',
'*/select',
);
$this->assertTags($result, $expected);
$monthNames = array(
'01' => 'Jan', '02' => 'Feb', '03' => 'Mar', '04' => 'Apr', '05' => 'May', '06' => 'Jun',
'07' => 'Jul', '08' => 'Aug', '09' => 'Sep', '10' => 'Oct', '11' => 'Nov', '12' => 'Dec');
$result = $this->Form->month('Model.field', array('monthNames' => $monthNames));
$expected = array(
array('select' => array('name' => 'data[Model][field][month]', 'id' => 'ModelFieldMonth')),
array('option' => array('value' => '')),
'/option',
array('option' => array('value' => '01')),
'Jan',
'/option',
array('option' => array('value' => '02')),
'Feb',
'/option',
'*/select',
);
$this->assertTags($result, $expected);
}
/**
* testDay method
*
* @return void
*/
public function testDay() {
extract($this->dateRegex);
$result = $this->Form->day('Model.field', array('value' => false));
$expected = array(
array('select' => array('name' => 'data[Model][field][day]', 'id' => 'ModelFieldDay')),
array('option' => array('value' => '')),
'/option',
array('option' => array('value' => '01')),
'1',
'/option',
array('option' => array('value' => '02')),
'2',
'/option',
$daysRegex,
'/select',
);
$this->assertTags($result, $expected);
$this->Form->request->data['Model']['field'] = '2006-10-10 23:12:32';
$result = $this->Form->day('Model.field');
$expected = array(
array('select' => array('name' => 'data[Model][field][day]', 'id' => 'ModelFieldDay')),
array('option' => array('value' => '')),
'/option',
array('option' => array('value' => '01')),
'1',
'/option',
array('option' => array('value' => '02')),
'2',
'/option',
$daysRegex,
array('option' => array('value' => '10', 'selected' => 'selected')),
'10',
'/option',
$daysRegex,
'/select',
);
$this->assertTags($result, $expected);
$this->Form->request->data['Model']['field'] = '';
$result = $this->Form->day('Model.field', array('value' => '10'));
$expected = array(
array('select' => array('name' => 'data[Model][field][day]', 'id' => 'ModelFieldDay')),
array('option' => array('value' => '')),
'/option',
array('option' => array('value' => '01')),
'1',
'/option',
array('option' => array('value' => '02')),
'2',
'/option',
$daysRegex,
array('option' => array('value' => '10', 'selected' => 'selected')),
'10',
'/option',
$daysRegex,
'/select',
);
$this->assertTags($result, $expected);
$this->Form->request->data['Model']['field'] = '2006-10-10 23:12:32';
$result = $this->Form->day('Model.field', array('value' => true));
$expected = array(
array('select' => array('name' => 'data[Model][field][day]', 'id' => 'ModelFieldDay')),
array('option' => array('value' => '')),
'/option',
array('option' => array('value' => '01')),
'1',
'/option',
array('option' => array('value' => '02')),
'2',
'/option',
$daysRegex,
array('option' => array('value' => '10', 'selected' => 'selected')),
'10',
'/option',
$daysRegex,
'/select',
);
$this->assertTags($result, $expected);
}
/**
* testMinute method
*
* @return void
*/
public function testMinute() {
extract($this->dateRegex);
$result = $this->Form->minute('Model.field');
$expected = array(
array('select' => array('name' => 'data[Model][field][min]', 'id' => 'ModelFieldMin')),
array('option' => array('value' => '')),
'/option',
array('option' => array('value' => '00')),
'00',
'/option',
array('option' => array('value' => '01')),
'01',
'/option',
array('option' => array('value' => '02')),
'02',
'/option',
$minutesRegex,
'/select',
);
$this->assertTags($result, $expected);
$this->Form->request->data['Model']['field'] = '2006-10-10 00:12:32';
$result = $this->Form->minute('Model.field');
$expected = array(
array('select' => array('name' => 'data[Model][field][min]', 'id' => 'ModelFieldMin')),
array('option' => array('value' => '')),
'/option',
array('option' => array('value' => '00')),
'00',
'/option',
array('option' => array('value' => '01')),
'01',
'/option',
array('option' => array('value' => '02')),
'02',
'/option',
$minutesRegex,
array('option' => array('value' => '12', 'selected' => 'selected')),
'12',
'/option',
$minutesRegex,
'/select',
);
$this->assertTags($result, $expected);
$this->Form->request->data['Model']['field'] = '';
$result = $this->Form->minute('Model.field', array('interval' => 5));
$expected = array(
array('select' => array('name' => 'data[Model][field][min]', 'id' => 'ModelFieldMin')),
array('option' => array('value' => '')),
'/option',
array('option' => array('value' => '00')),
'00',
'/option',
array('option' => array('value' => '05')),
'05',
'/option',
array('option' => array('value' => '10')),
'10',
'/option',
$minutesRegex,
'/select',
);
$this->assertTags($result, $expected);
$this->Form->request->data['Model']['field'] = '2006-10-10 00:10:32';
$result = $this->Form->minute('Model.field', array('interval' => 5));
$expected = array(
array('select' => array('name' => 'data[Model][field][min]', 'id' => 'ModelFieldMin')),
array('option' => array('value' => '')),
'/option',
array('option' => array('value' => '00')),
'00',
'/option',
array('option' => array('value' => '05')),
'05',
'/option',
array('option' => array('value' => '10', 'selected' => 'selected')),
'10',
'/option',
$minutesRegex,
'/select',
);
$this->assertTags($result, $expected);
}
/**
* testHour method
*
* @return void
*/
public function testHour() {
extract($this->dateRegex);
$result = $this->Form->hour('Model.field', false);
$expected = array(
array('select' => array('name' => 'data[Model][field][hour]', 'id' => 'ModelFieldHour')),
array('option' => array('value' => '')),
'/option',
array('option' => array('value' => '01')),
'1',
'/option',
array('option' => array('value' => '02')),
'2',
'/option',
$hoursRegex,
'/select',
);
$this->assertTags($result, $expected);
$this->Form->request->data['Model']['field'] = '2006-10-10 00:12:32';
$result = $this->Form->hour('Model.field', false);
$expected = array(
array('select' => array('name' => 'data[Model][field][hour]', 'id' => 'ModelFieldHour')),
array('option' => array('value' => '')),
'/option',
array('option' => array('value' => '01')),
'1',
'/option',
array('option' => array('value' => '02')),
'2',
'/option',
$hoursRegex,
array('option' => array('value' => '12', 'selected' => 'selected')),
'12',
'/option',
'/select',
);
$this->assertTags($result, $expected);
$this->Form->request->data['Model']['field'] = '';
$result = $this->Form->hour('Model.field', true, array('value' => '23'));
$expected = array(
array('select' => array('name' => 'data[Model][field][hour]', 'id' => 'ModelFieldHour')),
array('option' => array('value' => '')),
'/option',
array('option' => array('value' => '00')),
'0',
'/option',
array('option' => array('value' => '01')),
'1',
'/option',
array('option' => array('value' => '02')),
'2',
'/option',
$hoursRegex,
array('option' => array('value' => '23', 'selected' => 'selected')),
'23',
'/option',
'/select',
);
$this->assertTags($result, $expected);
$this->Form->request->data['Model']['field'] = '2006-10-10 00:12:32';
$result = $this->Form->hour('Model.field', true);
$expected = array(
array('select' => array('name' => 'data[Model][field][hour]', 'id' => 'ModelFieldHour')),
array('option' => array('value' => '')),
'/option',
array('option' => array('value' => '00', 'selected' => 'selected')),
'0',
'/option',
array('option' => array('value' => '01')),
'1',
'/option',
array('option' => array('value' => '02')),
'2',
'/option',
$hoursRegex,
'/select',
);
$this->assertTags($result, $expected);
unset($this->Form->request->data['Model']['field']);
$result = $this->Form->hour('Model.field', true, array('value' => 'now'));
$thisHour = date('H');
$optValue = date('G');
$this->assertPattern('/<option value="' . $thisHour . '" selected="selected">'. $optValue .'<\/option>/', $result);
}
/**
* testYear method
*
* @return void
*/
public function testYear() {
$result = $this->Form->year('Model.field', 2006, 2007);
$expected = array(
array('select' => array('name' => 'data[Model][field][year]', 'id' => 'ModelFieldYear')),
array('option' => array('value' => '')),
'/option',
array('option' => array('value' => '2007')),
'2007',
'/option',
array('option' => array('value' => '2006')),
'2006',
'/option',
'/select',
);
$this->assertTags($result, $expected);
$result = $this->Form->year('Model.field', 2006, 2007, array('orderYear' => 'asc'));
$expected = array(
array('select' => array('name' => 'data[Model][field][year]', 'id' => 'ModelFieldYear')),
array('option' => array('value' => '')),
'/option',
array('option' => array('value' => '2006')),
'2006',
'/option',
array('option' => array('value' => '2007')),
'2007',
'/option',
'/select',
);
$this->assertTags($result, $expected);
$this->request->data['Contact']['published'] = '';
$result = $this->Form->year('Contact.published', 2006, 2007, array('class' => 'year'));
$expected = array(
array('select' => array('name' => 'data[Contact][published][year]', 'id' => 'ContactPublishedYear', 'class' => 'year')),
array('option' => array('value' => '')),
'/option',
array('option' => array('value' => '2007')),
'2007',
'/option',
array('option' => array('value' => '2006')),
'2006',
'/option',
'/select',
);
$this->assertTags($result, $expected);
$this->Form->request->data['Contact']['published'] = '2006-10-10';
$result = $this->Form->year('Contact.published', 2006, 2007, array('empty' => false));
$expected = array(
array('select' => array('name' => 'data[Contact][published][year]', 'id' => 'ContactPublishedYear')),
array('option' => array('value' => '2007')),
'2007',
'/option',
array('option' => array('value' => '2006', 'selected' => 'selected')),
'2006',
'/option',
'/select',
);
$this->assertTags($result, $expected);
$this->Form->request->data['Contact']['published'] = '';
$result = $this->Form->year('Contact.published', 2006, 2007, array('value' => false));
$expected = array(
array('select' => array('name' => 'data[Contact][published][year]', 'id' => 'ContactPublishedYear')),
array('option' => array('value' => '')),
'/option',
array('option' => array('value' => '2007')),
'2007',
'/option',
array('option' => array('value' => '2006')),
'2006',
'/option',
'/select',
);
$this->assertTags($result, $expected);
$this->Form->request->data['Contact']['published'] = '2006-10-10';
$result = $this->Form->year('Contact.published', 2006, 2007, array('empty' => false, 'value' => false));
$expected = array(
array('select' => array('name' => 'data[Contact][published][year]', 'id' => 'ContactPublishedYear')),
array('option' => array('value' => '2007')),
'2007',
'/option',
array('option' => array('value' => '2006', 'selected' => 'selected')),
'2006',
'/option',
'/select',
);
$this->assertTags($result, $expected);
$this->Form->request->data['Contact']['published'] = '';
$result = $this->Form->year('Contact.published', 2006, 2007, array('value' => 2007));
$expected = array(
array('select' => array('name' => 'data[Contact][published][year]', 'id' => 'ContactPublishedYear')),
array('option' => array('value' => '')),
'/option',
array('option' => array('value' => '2007', 'selected' => 'selected')),
'2007',
'/option',
array('option' => array('value' => '2006')),
'2006',
'/option',
'/select',
);
$this->assertTags($result, $expected);
$this->Form->request->data['Contact']['published'] = '2006-10-10';
$result = $this->Form->year('Contact.published', 2006, 2007, array('empty' => false, 'value' => 2007));
$expected = array(
array('select' => array('name' => 'data[Contact][published][year]', 'id' => 'ContactPublishedYear')),
array('option' => array('value' => '2007', 'selected' => 'selected')),
'2007',
'/option',
array('option' => array('value' => '2006')),
'2006',
'/option',
'/select',
);
$this->assertTags($result, $expected);
$this->Form->request->data['Contact']['published'] = '';
$result = $this->Form->year('Contact.published', 2006, 2008, array('empty' => false, 'value' => 2007));
$expected = array(
array('select' => array('name' => 'data[Contact][published][year]', 'id' => 'ContactPublishedYear')),
array('option' => array('value' => '2008')),
'2008',
'/option',
array('option' => array('value' => '2007', 'selected' => 'selected')),
'2007',
'/option',
array('option' => array('value' => '2006')),
'2006',
'/option',
'/select',
);
$this->assertTags($result, $expected);
$this->Form->request->data['Contact']['published'] = '2006-10-10';
$result = $this->Form->year('Contact.published', 2006, 2008, array('empty' => false));
$expected = array(
array('select' => array('name' => 'data[Contact][published][year]', 'id' => 'ContactPublishedYear')),
array('option' => array('value' => '2008')),
'2008',
'/option',
array('option' => array('value' => '2007')),
'2007',
'/option',
array('option' => array('value' => '2006', 'selected' => 'selected')),
'2006',
'/option',
'/select',
);
$this->assertTags($result, $expected);
$this->Form->request->data = array();
$this->Form->create('Contact');
$result = $this->Form->year('published', 2006, 2008, array('empty' => false));
$expected = array(
array('select' => array('name' => 'data[Contact][published][year]', 'id' => 'ContactPublishedYear')),
array('option' => array('value' => '2008')),
'2008',
'/option',
array('option' => array('value' => '2007')),
'2007',
'/option',
array('option' => array('value' => '2006')),
'2006',
'/option',
'/select',
);
$this->assertTags($result, $expected);
}
/**
* testTextArea method
*
* @return void
*/
public function testTextArea() {
$this->Form->request->data = array('Model' => array('field' => 'some test data'));
$result = $this->Form->textarea('Model.field');
$expected = array(
'textarea' => array('name' => 'data[Model][field]', 'id' => 'ModelField'),
'some test data',
'/textarea',
);
$this->assertTags($result, $expected);
$result = $this->Form->textarea('Model.tmp');
$expected = array(
'textarea' => array('name' => 'data[Model][tmp]', 'id' => 'ModelTmp'),
'/textarea',
);
$this->assertTags($result, $expected);
$this->Form->request->data = array('Model' => array('field' => 'some <strong>test</strong> data with <a href="#">HTML</a> chars'));
$result = $this->Form->textarea('Model.field');
$expected = array(
'textarea' => array('name' => 'data[Model][field]', 'id' => 'ModelField'),
htmlentities('some <strong>test</strong> data with <a href="#">HTML</a> chars'),
'/textarea',
);
$this->assertTags($result, $expected);
$this->Form->request->data = array('Model' => array('field' => 'some <strong>test</strong> data with <a href="#">HTML</a> chars'));
$result = $this->Form->textarea('Model.field', array('escape' => false));
$expected = array(
'textarea' => array('name' => 'data[Model][field]', 'id' => 'ModelField'),
'some <strong>test</strong> data with <a href="#">HTML</a> chars',
'/textarea',
);
$this->assertTags($result, $expected);
$this->Form->request->data['Model']['0']['OtherModel']['field'] = null;
$result = $this->Form->textarea('Model.0.OtherModel.field');
$expected = array(
'textarea' => array('name' => 'data[Model][0][OtherModel][field]', 'id' => 'Model0OtherModelField'),
'/textarea'
);
$this->assertTags($result, $expected);
}
/**
* testTextAreaWithStupidCharacters method
*
* test text area with non-ascii characters
*
* @return void
*/
public function testTextAreaWithStupidCharacters() {
$this->loadFixtures('Post');
$result = $this->Form->input('Post.content', array(
'label' => 'Current Text', 'value' => "GREAT®", 'rows' => '15', 'cols' => '75'
));
$expected = array(
'div' => array('class' => 'input text'),
'label' => array('for' => 'PostContent'),
'Current Text',
'/label',
'textarea' => array('name' => 'data[Post][content]', 'id' => 'PostContent', 'rows' => '15', 'cols' => '75'),
'GREAT®',
'/textarea',
'/div'
);
$this->assertTags($result, $expected);
}
/**
* testHiddenField method
*
* @return void
*/
public function testHiddenField() {
$Contact = ClassRegistry::getObject('Contact');
$Contact->validationErrors['field'] = 1;
$this->Form->request->data['Contact']['field'] = 'test';
$result = $this->Form->hidden('Contact.field', array('id' => 'theID'));
$this->assertTags($result, array(
'input' => array('type' => 'hidden', 'class' => 'form-error', 'name' => 'data[Contact][field]', 'id' => 'theID', 'value' => 'test'))
);
}
/**
* testFileUploadField method
*
* @return void
*/
public function testFileUploadField() {
$result = $this->Form->file('Model.upload');
$this->assertTags($result, array('input' => array('type' => 'file', 'name' => 'data[Model][upload]', 'id' => 'ModelUpload')));
$this->Form->request->data['Model.upload'] = array("name" => "", "type" => "", "tmp_name" => "", "error" => 4, "size" => 0);
$result = $this->Form->input('Model.upload', array('type' => 'file'));
$expected = array(
'div' => array('class' => 'input file'),
'label' => array('for' => 'ModelUpload'),
'Upload',
'/label',
'input' => array('type' => 'file', 'name' => 'data[Model][upload]', 'id' => 'ModelUpload'),
'/div'
);
$this->assertTags($result, $expected);
}
/**
* test File upload input on a model not used in create();
*
* @return void
*/
public function testFileUploadOnOtherModel() {
$this->Form->create('ValidateUser', array('type' => 'file'));
$result = $this->Form->file('ValidateProfile.city');
$expected = array(
'input' => array('type' => 'file', 'name' => 'data[ValidateProfile][city]', 'id' => 'ValidateProfileCity')
);
$this->assertTags($result, $expected);
}
/**
* testButton method
*
* @return void
*/
public function testButton() {
$result = $this->Form->button('Hi');
$this->assertTags($result, array('button' => array('type' => 'submit'), 'Hi', '/button'));
$result = $this->Form->button('Clear Form >', array('type' => 'reset'));
$this->assertTags($result, array('button' => array('type' => 'reset'), 'Clear Form >', '/button'));
$result = $this->Form->button('Clear Form >', array('type' => 'reset', 'id' => 'clearForm'));
$this->assertTags($result, array('button' => array('type' => 'reset', 'id' => 'clearForm'), 'Clear Form >', '/button'));
$result = $this->Form->button('<Clear Form>', array('type' => 'reset', 'escape' => true));
$this->assertTags($result, array('button' => array('type' => 'reset'), '<Clear Form>', '/button'));
$result = $this->Form->button('Upload Text', array('onClick' => "$('#postAddForm').ajaxSubmit({target: '#postTextUpload', url: '/posts/text'});return false;'", 'escape' => false));
$this->assertNoPattern('/\&039/', $result);
}
/**
* Test that button() makes unlocked fields by default.
*
* @return void
*/
public function testButtonUnlockedByDefault() {
$this->Form->request->params['_Token']['key'] = 'secured';
$this->Form->button('Save', array('name' => 'save'));
$this->Form->button('Clear');
$result = $this->Form->unlockField();
$this->assertEquals(array('save'), $result);
}
/**
* testPostButton method
*
* @return void
*/
public function testPostButton() {
$result = $this->Form->postButton('Hi', '/controller/action');
$this->assertTags($result, array(
'form' => array('method' => 'post', 'action' => '/controller/action', 'accept-charset' => 'utf-8', 'style' => 'display:none;'),
'div' => array('style' => 'display:none;'),
'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'),
'/div',
'button' => array('type' => 'submit'),
'Hi',
'/button',
'/form'
));
$result = $this->Form->postButton('Send', '/', array('data' => array('extra' => 'value')));
$this->assertTrue(strpos($result, '<input type="hidden" name="data[extra]" value="value"/>') !== false);
}
/**
* Test that postButton adds _Token fields.
*
* @return void
*/
public function testSecurePostButton() {
$this->Form->request->params['_Token'] = array('key' => 'testkey');
$result = $this->Form->postButton('Delete', '/posts/delete/1');
$expected = array(
'form' => array(
'method' => 'post', 'action' => '/posts/delete/1', 'accept-charset' => 'utf-8',
'style' => 'display:none;'
),
array('div' => array('style' => 'display:none;')),
array('input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST')),
array('input' => array('type' => 'hidden', 'name' => 'data[_Token][key]', 'value' => 'testkey', 'id' => 'preg:/Token\d+/')),
'/div',
'button' => array('type' => 'submit'),
'Delete',
'/button',
array('div' => array('style' => 'display:none;')),
array('input' => array('type' => 'hidden', 'name' => 'data[_Token][fields]', 'value' => 'preg:/[\w\d%]+/', 'id' => 'preg:/TokenFields\d+/')),
array('input' => array('type' => 'hidden', 'name' => 'data[_Token][unlocked]', 'value' => '', 'id' => 'preg:/TokenUnlocked\d+/')),
'/div',
'/form',
);
$this->assertTags($result, $expected);
}
/**
* testPostLink method
*
* @return void
*/
public function testPostLink() {
$result = $this->Form->postLink('Delete', '/posts/delete/1');
$this->assertTags($result, array(
'form' => array(
'method' => 'post', 'action' => '/posts/delete/1',
'name' => 'preg:/post_\w+/', 'id' => 'preg:/post_\w+/', 'style' => 'display:none;'
),
'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'),
'/form',
'a' => array('href' => '#', 'onclick' => 'preg:/document\.post_\w+\.submit\(\); event\.returnValue = false; return false;/'),
'Delete',
'/a'
));
$result = $this->Form->postLink('Delete', '/posts/delete/1', array(), 'Confirm?');
$this->assertTags($result, array(
'form' => array(
'method' => 'post', 'action' => '/posts/delete/1',
'name' => 'preg:/post_\w+/', 'id' => 'preg:/post_\w+/', 'style' => 'display:none;'
),
'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'),
'/form',
'a' => array('href' => '#', 'onclick' => 'preg:/if \(confirm\('Confirm\?'\)\) \{ document\.post_\w+\.submit\(\); \} event\.returnValue = false; return false;/'),
'Delete',
'/a'
));
$result = $this->Form->postLink('Delete', '/posts/delete', array('data' => array('id' => 1)));
$this->assertContains('<input type="hidden" name="data[id]" value="1"/>', $result);
}
/**
* Test that postLink adds _Token fields.
*
* @return void
*/
public function testSecurePostLink() {
$this->Form->request->params['_Token'] = array('key' => 'testkey');
$result = $this->Form->postLink('Delete', '/posts/delete/1');
$expected = array(
'form' => array(
'method' => 'post', 'action' => '/posts/delete/1',
'name' => 'preg:/post_\w+/', 'id' => 'preg:/post_\w+/', 'style' => 'display:none;'
),
array('input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST')),
array('input' => array('type' => 'hidden', 'name' => 'data[_Token][key]', 'value' => 'testkey', 'id' => 'preg:/Token\d+/')),
'div' => array('style' => 'display:none;'),
array('input' => array('type' => 'hidden', 'name' => 'data[_Token][fields]', 'value' => 'preg:/[\w\d%]+/', 'id' => 'preg:/TokenFields\d+/')),
array('input' => array('type' => 'hidden', 'name' => 'data[_Token][unlocked]', 'value' => '', 'id' => 'preg:/TokenUnlocked\d+/')),
'/div',
'/form',
'a' => array('href' => '#', 'onclick' => 'preg:/document\.post_\w+\.submit\(\); event\.returnValue = false; return false;/'),
'Delete',
'/a'
);
$this->assertTags($result, $expected);
}
/**
* testSubmitButton method
*
* @return void
*/
public function testSubmitButton() {
$result = $this->Form->submit('');
$expected = array(
'div' => array('class' => 'submit'),
'input' => array('type' => 'submit', 'value' => ''),
'/div'
);
$this->assertTags($result, $expected);
$result = $this->Form->submit('Test Submit');
$expected = array(
'div' => array('class' => 'submit'),
'input' => array('type' => 'submit', 'value' => 'Test Submit'),
'/div'
);
$this->assertTags($result, $expected);
$result = $this->Form->submit('Test Submit', array('div' => array('tag' => 'span')));
$expected = array(
'span' => array('class' => 'submit'),
'input' => array('type' => 'submit', 'value' => 'Test Submit'),
'/span'
);
$this->assertTags($result, $expected);
$result = $this->Form->submit('Test Submit', array('class' => 'save', 'div' => false));
$expected = array('input' => array('type' => 'submit', 'value' => 'Test Submit', 'class' => 'save'));
$this->assertTags($result, $expected);
$result = $this->Form->submit('Test Submit', array('div' => array('id' => 'SaveButton')));
$expected = array(
'div' => array('class' => 'submit', 'id' => 'SaveButton'),
'input' => array('type' => 'submit', 'value' => 'Test Submit'),
'/div'
);
$this->assertTags($result, $expected);
$result = $this->Form->submit('Next >');
$expected = array(
'div' => array('class' => 'submit'),
'input' => array('type' => 'submit', 'value' => 'Next >'),
'/div'
);
$this->assertTags($result, $expected);
$result = $this->Form->submit('Next >', array('escape' => false));
$expected = array(
'div' => array('class' => 'submit'),
'input' => array('type' => 'submit', 'value' => 'Next >'),
'/div'
);
$this->assertTags($result, $expected);
$result = $this->Form->submit('Reset!', array('type' => 'reset'));
$expected = array(
'div' => array('class' => 'submit'),
'input' => array('type' => 'reset', 'value' => 'Reset!'),
'/div'
);
$this->assertTags($result, $expected);
$before = '--before--';
$after = '--after--';
$result = $this->Form->submit('Test', array('before' => $before));
$expected = array(
'div' => array('class' => 'submit'),
'--before--',
'input' => array('type' => 'submit', 'value' => 'Test'),
'/div'
);
$this->assertTags($result, $expected);
$result = $this->Form->submit('Test', array('after' => $after));
$expected = array(
'div' => array('class' => 'submit'),
'input' => array('type' => 'submit', 'value' => 'Test'),
'--after--',
'/div'
);
$this->assertTags($result, $expected);
$result = $this->Form->submit('Test', array('before' => $before, 'after' => $after));
$expected = array(
'div' => array('class' => 'submit'),
'--before--',
'input' => array('type' => 'submit', 'value' => 'Test'),
'--after--',
'/div'
);
$this->assertTags($result, $expected);
}
/**
* test image submit types.
*
* @return void
*/
public function testSubmitImage() {
$result = $this->Form->submit('http://example.com/cake.power.gif');
$expected = array(
'div' => array('class' => 'submit'),
'input' => array('type' => 'image', 'src' => 'http://example.com/cake.power.gif'),
'/div'
);
$this->assertTags($result, $expected);
$result = $this->Form->submit('/relative/cake.power.gif');
$expected = array(
'div' => array('class' => 'submit'),
'input' => array('type' => 'image', 'src' => 'relative/cake.power.gif'),
'/div'
);
$this->assertTags($result, $expected);
$result = $this->Form->submit('cake.power.gif');
$expected = array(
'div' => array('class' => 'submit'),
'input' => array('type' => 'image', 'src' => 'img/cake.power.gif'),
'/div'
);
$this->assertTags($result, $expected);
$result = $this->Form->submit('Not.an.image');
$expected = array(
'div' => array('class' => 'submit'),
'input' => array('type' => 'submit', 'value' => 'Not.an.image'),
'/div'
);
$this->assertTags($result, $expected);
$after = '--after--';
$before = '--before--';
$result = $this->Form->submit('cake.power.gif', array('after' => $after));
$expected = array(
'div' => array('class' => 'submit'),
'input' => array('type' => 'image', 'src' => 'img/cake.power.gif'),
'--after--',
'/div'
);
$this->assertTags($result, $expected);
$result = $this->Form->submit('cake.power.gif', array('before' => $before));
$expected = array(
'div' => array('class' => 'submit'),
'--before--',
'input' => array('type' => 'image', 'src' => 'img/cake.power.gif'),
'/div'
);
$this->assertTags($result, $expected);
$result = $this->Form->submit('cake.power.gif', array('before' => $before, 'after' => $after));
$expected = array(
'div' => array('class' => 'submit'),
'--before--',
'input' => array('type' => 'image', 'src' => 'img/cake.power.gif'),
'--after--',
'/div'
);
$this->assertTags($result, $expected);
$result = $this->Form->submit('Not.an.image', array('before' => $before, 'after' => $after));
$expected = array(
'div' => array('class' => 'submit'),
'--before--',
'input' => array('type' => 'submit', 'value' => 'Not.an.image'),
'--after--',
'/div'
);
$this->assertTags($result, $expected);
}
/**
* Submit buttons should be unlocked by default as there could be multiples, and only one will
* be submitted at a time.
*
* @return void
*/
public function testSubmitUnlockedByDefault() {
$this->Form->request->params['_Token']['key'] = 'secured';
$this->Form->submit('Go go');
$this->Form->submit('Save', array('name' => 'save'));
$result = $this->Form->unlockField();
$this->assertEquals(array('save'), $result, 'Only submits with name attributes should be unlocked.');
}
/**
* test the create() method
*
* @return void
*/
public function testCreate() {
$result = $this->Form->create('Contact');
$encoding = strtolower(Configure::read('App.encoding'));
$expected = array(
'form' => array(
'id' => 'ContactAddForm', 'method' => 'post', 'action' => '/contacts/add',
'accept-charset' => $encoding
),
'div' => array('style' => 'preg:/display\s*\:\s*none;\s*/'),
'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'),
'/div'
);
$this->assertTags($result, $expected);
$result = $this->Form->create('Contact', array('type' => 'GET'));
$expected = array('form' => array(
'id' => 'ContactAddForm', 'method' => 'get', 'action' => '/contacts/add',
'accept-charset' => $encoding
));
$this->assertTags($result, $expected);
$result = $this->Form->create('Contact', array('type' => 'get'));
$expected = array('form' => array(
'id' => 'ContactAddForm', 'method' => 'get', 'action' => '/contacts/add',
'accept-charset' => $encoding
));
$this->assertTags($result, $expected);
$result = $this->Form->create('Contact', array('type' => 'put'));
$expected = array(
'form' => array(
'id' => 'ContactAddForm', 'method' => 'post', 'action' => '/contacts/add',
'accept-charset' => $encoding
),
'div' => array('style' => 'display:none;'),
'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'PUT'),
'/div'
);
$this->assertTags($result, $expected);
$result = $this->Form->create('Contact', array('type' => 'file'));
$expected = array(
'form' => array(
'id' => 'ContactAddForm', 'method' => 'post', 'action' => '/contacts/add',
'accept-charset' => $encoding, 'enctype' => 'multipart/form-data'
),
'div' => array('style' => 'display:none;'),
'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'),
'/div'
);
$this->assertTags($result, $expected);
$this->Form->request->data['Contact']['id'] = 1;
$this->Form->request->here = '/contacts/edit/1';
$this->Form->request['action'] = 'edit';
$result = $this->Form->create('Contact');
$expected = array(
'form' => array(
'id' => 'ContactEditForm', 'method' => 'post', 'action' => '/contacts/edit/1',
'accept-charset' => $encoding
),
'div' => array('style' => 'display:none;'),
'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'PUT'),
'/div'
);
$this->assertTags($result, $expected);
$this->Form->request->data['Contact']['id'] = 1;
$this->Form->request->here = '/contacts/edit/1';
$this->Form->request['action'] = 'edit';
$result = $this->Form->create('Contact', array('type' => 'file'));
$expected = array(
'form' => array(
'id' => 'ContactEditForm', 'method' => 'post', 'action' => '/contacts/edit/1',
'accept-charset' => $encoding, 'enctype' => 'multipart/form-data'
),
'div' => array('style' => 'display:none;'),
'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'PUT'),
'/div'
);
$this->assertTags($result, $expected);
$this->Form->request->data['ContactNonStandardPk']['pk'] = 1;
$result = $this->Form->create('ContactNonStandardPk', array('url' => array('action' => 'edit')));
$expected = array(
'form' => array(
'id' => 'ContactNonStandardPkEditForm', 'method' => 'post',
'action' => '/contact_non_standard_pks/edit/1','accept-charset' => $encoding
),
'div' => array('style' => 'display:none;'),
'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'PUT'),
'/div'
);
$this->assertTags($result, $expected);
$result = $this->Form->create('Contact', array('id' => 'TestId'));
$expected = array(
'form' => array(
'id' => 'TestId', 'method' => 'post', 'action' => '/contacts/edit/1',
'accept-charset' => $encoding
),
'div' => array('style' => 'display:none;'),
'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'PUT'),
'/div'
);
$this->assertTags($result, $expected);
$this->Form->request['action'] = 'add';
$result = $this->Form->create('User', array('url' => array('action' => 'login')));
$expected = array(
'form' => array(
'id' => 'UserAddForm', 'method' => 'post', 'action' => '/users/login',
'accept-charset' => $encoding
),
'div' => array('style' => 'display:none;'),
'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'),
'/div'
);
$this->assertTags($result, $expected);
$result = $this->Form->create('User', array('action' => 'login'));
$expected = array(
'form' => array(
'id' => 'UserLoginForm', 'method' => 'post', 'action' => '/users/login',
'accept-charset' => $encoding
),
'div' => array('style' => 'display:none;'),
'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'),
'/div'
);
$this->assertTags($result, $expected);
$result = $this->Form->create('User', array('url' => '/users/login'));
$expected = array(
'form' => array('method' => 'post', 'action' => '/users/login', 'accept-charset' => $encoding, 'id' => 'UserAddForm'),
'div' => array('style' => 'display:none;'),
'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'),
'/div'
);
$this->assertTags($result, $expected);
$this->Form->request['controller'] = 'pages';
$result = $this->Form->create('User', array('action' => 'signup'));
$expected = array(
'form' => array(
'id' => 'UserSignupForm', 'method' => 'post', 'action' => '/users/signup',
'accept-charset' => $encoding
),
'div' => array('style' => 'display:none;'),
'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'),
'/div'
);
$this->assertTags($result, $expected);
$this->Form->request->data = array();
$this->Form->request['controller'] = 'contacts';
$this->Form->request['models'] = array('Contact' => array('plugin' => null, 'className' => 'Contact'));
$result = $this->Form->create(array('url' => array('action' => 'index', 'param')));
$expected = array(
'form' => array(
'id' => 'ContactAddForm', 'method' => 'post', 'action' => '/contacts/index/param',
'accept-charset' => 'utf-8'
),
'div' => array('style' => 'display:none;'),
'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'),
'/div'
);
$this->assertTags($result, $expected);
}
/**
* Test the onsubmit option for create()
*
* @return void
*/
public function testCreateOnSubmit() {
$this->Form->request->data = array();
$this->Form->request['controller'] = 'contacts';
$this->Form->request['models'] = array('Contact' => array('plugin' => null, 'className' => 'Contact'));
$result = $this->Form->create(array('url' => array('action' => 'index', 'param'), 'default' => false));
$expected = array(
'form' => array(
'id' => 'ContactAddForm', 'method' => 'post', 'onsubmit' => 'event.returnValue = false; return false;', 'action' => '/contacts/index/param',
'accept-charset' => 'utf-8'
),
'div' => array('style' => 'display:none;'),
'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'),
'/div'
);
$this->assertTags($result, $expected);
$this->Form->request->data = array();
$this->Form->request['controller'] = 'contacts';
$this->Form->request['models'] = array('Contact' => array('plugin' => null, 'className' => 'Contact'));
$result = $this->Form->create(array(
'url' => array('action' => 'index', 'param'),
'default' => false,
'onsubmit' => 'someFunction();'
));
$expected = array(
'form' => array(
'id' => 'ContactAddForm', 'method' => 'post',
'onsubmit' => 'someFunction();event.returnValue = false; return false;',
'action' => '/contacts/index/param',
'accept-charset' => 'utf-8'
),
'div' => array('style' => 'display:none;'),
'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'),
'/div'
);
$this->assertTags($result, $expected);
}
/**
* test create() with automatic url generation
*
* @return void
*/
public function testCreateAutoUrl() {
Router::setRequestInfo(array(array(), array('base' => '/base_url')));
$this->Form->request->here = '/base_url/contacts/add/Contact:1';
$this->Form->request->base = '/base_url';
$result = $this->Form->create('Contact');
$expected = array(
'form' => array(
'id' => 'ContactAddForm', 'method' => 'post', 'action' => '/base_url/contacts/add/Contact:1',
'accept-charset' => 'utf-8'
),
'div' => array('style' => 'display:none;'),
'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'),
'/div'
);
$this->assertTags($result, $expected);
$this->Form->request['action'] = 'delete';
$this->Form->request->here = '/base_url/contacts/delete/10/User:42';
$this->Form->request->base = '/base_url';
$result = $this->Form->create('Contact');
$expected = array(
'form' => array(
'id' => 'ContactDeleteForm', 'method' => 'post', 'action' => '/base_url/contacts/delete/10/User:42',
'accept-charset' => 'utf-8'
),
'div' => array('style' => 'display:none;'),
'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'),
'/div'
);
$this->assertTags($result, $expected);
}
/**
* test create() with a custom route
*
* @return void
*/
public function testCreateCustomRoute() {
Router::connect('/login', array('controller' => 'users', 'action' => 'login'));
$encoding = strtolower(Configure::read('App.encoding'));
$result = $this->Form->create('User', array('action' => 'login'));
$expected = array(
'form' => array(
'id' => 'UserLoginForm', 'method' => 'post', 'action' => '/login',
'accept-charset' => $encoding
),
'div' => array('style' => 'display:none;'),
'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'),
'/div'
);
$this->assertTags($result, $expected);
}
/**
* test that inputDefaults are stored and used.
*
* @return void
*/
public function testCreateWithInputDefaults() {
$this->Form->create('User', array(
'inputDefaults' => array('div' => false, 'label' => false)
));
$result = $this->Form->input('username');
$expected = array(
'input' => array('type' => 'text', 'name' => 'data[User][username]', 'id' => 'UserUsername')
);
$this->assertTags($result, $expected);
$result = $this->Form->input('username', array('div' => true, 'label' => 'username'));
$expected = array(
'div' => array('class' => 'input text'),
'label' => array('for' => 'UserUsername'), 'username', '/label',
'input' => array('type' => 'text', 'name' => 'data[User][username]', 'id' => 'UserUsername'),
'/div'
);
$this->assertTags($result, $expected);
}
/**
* test automatic accept-charset overriding
*
* @return void
*/
public function testCreateWithAcceptCharset() {
$result = $this->Form->create('UserForm', array(
'type' => 'post', 'action' => 'login','encoding' => 'iso-8859-1'
)
);
$expected = array(
'form' => array(
'method' => 'post', 'action' => '/user_forms/login', 'id' => 'UserFormLoginForm',
'accept-charset' => 'iso-8859-1'
),
'div' => array('style' => 'display:none;'),
'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'),
'/div'
);
$this->assertTags($result, $expected);
}
/**
* Test base form url when url param is passed with multiple parameters (&)
*
*/
public function testCreateQuerystringrequest() {
$encoding = strtolower(Configure::read('App.encoding'));
$result = $this->Form->create('Contact', array(
'type' => 'post',
'escape' => false,
'url' => array(
'controller' => 'controller',
'action' => 'action',
'?' => array('param1' => 'value1', 'param2' => 'value2')
)
));
$expected = array(
'form' => array(
'id' => 'ContactAddForm',
'method' => 'post',
'action' => '/controller/action?param1=value1&param2=value2',
'accept-charset' => $encoding
),
'div' => array('style' => 'display:none;'),
'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'),
'/div'
);
$this->assertTags($result, $expected);
$result = $this->Form->create('Contact', array(
'type' => 'post',
'url' => array(
'controller' => 'controller',
'action' => 'action',
'?' => array('param1' => 'value1', 'param2' => 'value2')
)
));
$expected = array(
'form' => array(
'id' => 'ContactAddForm',
'method' => 'post',
'action' => '/controller/action?param1=value1&param2=value2',
'accept-charset' => $encoding
),
'div' => array('style' => 'display:none;'),
'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'),
'/div'
);
$this->assertTags($result, $expected);
}
/**
* test that create() doesn't cause errors by multiple id's being in the primary key
* as could happen with multiple select or checkboxes.
*
* @return void
*/
public function testCreateWithMultipleIdInData() {
$encoding = strtolower(Configure::read('App.encoding'));
$this->Form->request->data['Contact']['id'] = array(1, 2);
$result = $this->Form->create('Contact');
$expected = array(
'form' => array(
'id' => 'ContactAddForm',
'method' => 'post',
'action' => '/contacts/add',
'accept-charset' => $encoding
),
'div' => array('style' => 'display:none;'),
'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'),
'/div'
);
$this->assertTags($result, $expected);
}
/**
* test that create() doesn't add in extra passed params.
*
* @return void
*/
public function testCreatePassedArgs() {
$encoding = strtolower(Configure::read('App.encoding'));
$this->Form->request->data['Contact']['id'] = 1;
$result = $this->Form->create('Contact', array(
'type' => 'post',
'escape' => false,
'url' => array(
'action' => 'edit',
'myparam'
)
));
$expected = array(
'form' => array(
'id' => 'ContactAddForm',
'method' => 'post',
'action' => '/contacts/edit/myparam',
'accept-charset' => $encoding
),
'div' => array('style' => 'display:none;'),
'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'),
'/div'
);
$this->assertTags($result, $expected);
}
/**
* test creating a get form, and get form inputs.
*
* @return void
*/
public function testGetFormCreate() {
$encoding = strtolower(Configure::read('App.encoding'));
$result = $this->Form->create('Contact', array('type' => 'get'));
$this->assertTags($result, array('form' => array(
'id' => 'ContactAddForm', 'method' => 'get', 'action' => '/contacts/add',
'accept-charset' => $encoding
)));
$result = $this->Form->text('Contact.name');
$this->assertTags($result, array('input' => array(
'name' => 'name', 'type' => 'text', 'id' => 'ContactName',
)));
$result = $this->Form->password('password');
$this->assertTags($result, array('input' => array(
'name' => 'password', 'type' => 'password', 'id' => 'ContactPassword'
)));
$this->assertNoPattern('/<input[^<>]+[^id|name|type|value]=[^<>]*>$/', $result);
$result = $this->Form->text('user_form');
$this->assertTags($result, array('input' => array(
'name' => 'user_form', 'type' => 'text', 'id' => 'ContactUserForm'
)));
}
/**
* test get form, and inputs when the model param is false
*
* @return void
*/
public function testGetFormWithFalseModel() {
$encoding = strtolower(Configure::read('App.encoding'));
$this->Form->request['controller'] = 'contact_test';
$result = $this->Form->create(false, array('type' => 'get', 'url' => array('controller' => 'contact_test')));
$expected = array('form' => array(
'id' => 'addForm', 'method' => 'get', 'action' => '/contact_test/add',
'accept-charset' => $encoding
));
$this->assertTags($result, $expected);
$result = $this->Form->text('reason');
$expected = array(
'input' => array('type' => 'text', 'name' => 'reason', 'id' => 'reason')
);
$this->assertTags($result, $expected);
}
/**
* test that datetime() works with GET style forms.
*
* @return void
*/
public function testDateTimeWithGetForms() {
extract($this->dateRegex);
$this->Form->create('Contact', array('type' => 'get'));
$result = $this->Form->datetime('created');
$this->assertPattern('/name="created\[year\]"/', $result, 'year name attribute is wrong.');
$this->assertPattern('/name="created\[month\]"/', $result, 'month name attribute is wrong.');
$this->assertPattern('/name="created\[day\]"/', $result, 'day name attribute is wrong.');
$this->assertPattern('/name="created\[hour\]"/', $result, 'hour name attribute is wrong.');
$this->assertPattern('/name="created\[min\]"/', $result, 'min name attribute is wrong.');
$this->assertPattern('/name="created\[meridian\]"/', $result, 'meridian name attribute is wrong.');
}
/**
* testEditFormWithData method
*
* test auto populating form elements from submitted data.
*
* @return void
*/
public function testEditFormWithData() {
$this->Form->request->data = array('Person' => array(
'id' => 1,
'first_name' => 'Nate',
'last_name' => 'Abele',
'email' => 'nate@example.com'
));
$this->Form->request->addParams(array(
'models' => array('Person'),
'controller' => 'people',
'action' => 'add'
));
$options = array(1 => 'Nate', 2 => 'Garrett', 3 => 'Larry');
$this->Form->create();
$result = $this->Form->select('People.People', $options, array('multiple' => true));
$expected = array(
'input' => array('type' => 'hidden', 'name' => 'data[People][People]', 'value' => '', 'id' => 'PeoplePeople_'),
'select' => array(
'name' => 'data[People][People][]', 'multiple' => 'multiple', 'id' => 'PeoplePeople'
),
array('option' => array('value' => 1)), 'Nate', '/option',
array('option' => array('value' => 2)), 'Garrett', '/option',
array('option' => array('value' => 3)), 'Larry', '/option',
'/select'
);
$this->assertTags($result, $expected);
}
/**
* testFormMagicInput method
*
* @return void
*/
public function testFormMagicInput() {
$encoding = strtolower(Configure::read('App.encoding'));
$result = $this->Form->create('Contact');
$expected = array(
'form' => array(
'id' => 'ContactAddForm', 'method' => 'post', 'action' => '/contacts/add',
'accept-charset' => $encoding
),
'div' => array('style' => 'display:none;'),
'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'),
'/div'
);
$this->assertTags($result, $expected);
$result = $this->Form->input('name');
$expected = array(
'div' => array('class' => 'input text'),
'label' => array('for' => 'ContactName'),
'Name',
'/label',
'input' => array(
'type' => 'text', 'name' => 'data[Contact][name]',
'id' => 'ContactName', 'maxlength' => '255'
),
'/div'
);
$this->assertTags($result, $expected);
$result = $this->Form->input('non_existing_field_in_contact_model');
$expected = array(
'div' => array('class' => 'input text'),
'label' => array('for' => 'ContactNonExistingFieldInContactModel'),
'Non Existing Field In Contact Model',
'/label',
'input' => array(
'type' => 'text', 'name' => 'data[Contact][non_existing_field_in_contact_model]',
'id' => 'ContactNonExistingFieldInContactModel'
),
'/div'
);
$this->assertTags($result, $expected);
$result = $this->Form->input('Address.street');
$expected = array(
'div' => array('class' => 'input text'),
'label' => array('for' => 'AddressStreet'),
'Street',
'/label',
'input' => array(
'type' => 'text', 'name' => 'data[Address][street]',
'id' => 'AddressStreet'
),
'/div'
);
$this->assertTags($result, $expected);
$result = $this->Form->input('Address.non_existing_field_in_model');
$expected = array(
'div' => array('class' => 'input text'),
'label' => array('for' => 'AddressNonExistingFieldInModel'),
'Non Existing Field In Model',
'/label',
'input' => array(
'type' => 'text', 'name' => 'data[Address][non_existing_field_in_model]',
'id' => 'AddressNonExistingFieldInModel'
),
'/div'
);
$this->assertTags($result, $expected);
$result = $this->Form->input('name', array('div' => false));
$expected = array(
'label' => array('for' => 'ContactName'),
'Name',
'/label',
'input' => array(
'type' => 'text', 'name' => 'data[Contact][name]',
'id' => 'ContactName', 'maxlength' => '255'
)
);
$this->assertTags($result, $expected);
$result = $this->Form->input('Contact.non_existing');
$expected = array(
'div' => array('class' => 'input text required'),
'label' => array('for' => 'ContactNonExisting'),
'Non Existing',
'/label',
'input' => array(
'type' => 'text', 'name' => 'data[Contact][non_existing]',
'id' => 'ContactNonExisting'
),
'/div'
);
$this->assertTags($result, $expected);
$result = $this->Form->input('Contact.imrequired');
$expected = array(
'div' => array('class' => 'input text required'),
'label' => array('for' => 'ContactImrequired'),
'Imrequired',
'/label',
'input' => array(
'type' => 'text', 'name' => 'data[Contact][imrequired]',
'id' => 'ContactImrequired'
),
'/div'
);
$this->assertTags($result, $expected);
$result = $this->Form->input('Contact.imalsorequired');
$expected = array(
'div' => array('class' => 'input text required'),
'label' => array('for' => 'ContactImalsorequired'),
'Imalsorequired',
'/label',
'input' => array(
'type' => 'text', 'name' => 'data[Contact][imalsorequired]',
'id' => 'ContactImalsorequired'
),
'/div'
);
$this->assertTags($result, $expected);
$result = $this->Form->input('Contact.imrequiredtoo');
$expected = array(
'div' => array('class' => 'input text required'),
'label' => array('for' => 'ContactImrequiredtoo'),
'Imrequiredtoo',
'/label',
'input' => array(
'type' => 'text', 'name' => 'data[Contact][imrequiredtoo]',
'id' => 'ContactImrequiredtoo'
),
'/div'
);
$this->assertTags($result, $expected);
$result = $this->Form->input('Contact.required_one');
$expected = array(
'div' => array('class' => 'input text required'),
'label' => array('for' => 'ContactRequiredOne'),
'Required One',
'/label',
'input' => array(
'type' => 'text', 'name' => 'data[Contact][required_one]',
'id' => 'ContactRequiredOne'
),
'/div'
);
$this->assertTags($result, $expected);
$result = $this->Form->input('Contact.imnotrequired');
$expected = array(
'div' => array('class' => 'input text'),
'label' => array('for' => 'ContactImnotrequired'),
'Imnotrequired',
'/label',
'input' => array(
'type' => 'text', 'name' => 'data[Contact][imnotrequired]',
'id' => 'ContactImnotrequired'
),
'/div'
);
$this->assertTags($result, $expected);
$result = $this->Form->input('Contact.imalsonotrequired');
$expected = array(
'div' => array('class' => 'input text'),
'label' => array('for' => 'ContactImalsonotrequired'),
'Imalsonotrequired',
'/label',
'input' => array(
'type' => 'text', 'name' => 'data[Contact][imalsonotrequired]',
'id' => 'ContactImalsonotrequired'
),
'/div'
);
$this->assertTags($result, $expected);
$result = $this->Form->input('Contact.imnotrequiredeither');
$expected = array(
'div' => array('class' => 'input text'),
'label' => array('for' => 'ContactImnotrequiredeither'),
'Imnotrequiredeither',
'/label',
'input' => array(
'type' => 'text', 'name' => 'data[Contact][imnotrequiredeither]',
'id' => 'ContactImnotrequiredeither'
),
'/div'
);
$this->assertTags($result, $expected);
extract($this->dateRegex);
$now = strtotime('now');
$result = $this->Form->input('Contact.published', array('div' => false));
$expected = array(
'label' => array('for' => 'ContactPublishedMonth'),
'Published',
'/label',
array('select' => array(
'name' => 'data[Contact][published][month]', 'id' => 'ContactPublishedMonth'
)),
$monthsRegex,
array('option' => array('value' => date('m', $now), 'selected' => 'selected')),
date('F', $now),
'/option',
'*/select',
'-',
array('select' => array(
'name' => 'data[Contact][published][day]', 'id' => 'ContactPublishedDay'
)),
$daysRegex,
array('option' => array('value' => date('d', $now), 'selected' => 'selected')),
date('j', $now),
'/option',
'*/select',
'-',
array('select' => array(
'name' => 'data[Contact][published][year]', 'id' => 'ContactPublishedYear'
)),
$yearsRegex,
array('option' => array('value' => date('Y', $now), 'selected' => 'selected')),
date('Y', $now),
'*/select'
);
$this->assertTags($result, $expected);
$result = $this->Form->input('Contact.updated', array('div' => false));
$expected = array(
'label' => array('for' => 'ContactUpdatedMonth'),
'Updated',
'/label',
array('select' => array(
'name' => 'data[Contact][updated][month]', 'id' => 'ContactUpdatedMonth'
)),
$monthsRegex,
array('option' => array('value' => date('m', $now), 'selected' => 'selected')),
date('F', $now),
'/option',
'*/select',
'-',
array('select' => array(
'name' => 'data[Contact][updated][day]', 'id' => 'ContactUpdatedDay'
)),
$daysRegex,
array('option' => array('value' => date('d', $now), 'selected' => 'selected')),
date('j', $now),
'/option',
'*/select',
'-',
array('select' => array(
'name' => 'data[Contact][updated][year]', 'id' => 'ContactUpdatedYear'
)),
$yearsRegex,
array('option' => array('value' => date('Y', $now), 'selected' => 'selected')),
date('Y', $now),
'*/select'
);
$this->assertTags($result, $expected);
$result = $this->Form->input('UserForm.stuff');
$expected = array(
'div' => array('class' => 'input text'),
'label' => array('for' => 'UserFormStuff'),
'Stuff',
'/label',
'input' => array(
'type' => 'text', 'name' => 'data[UserForm][stuff]',
'id' => 'UserFormStuff', 'maxlength' => 10
),
'/div'
);
$this->assertTags($result, $expected);
}
/**
* testForMagicInputNonExistingNorValidated method
*
* @return void
*/
public function testForMagicInputNonExistingNorValidated() {
$encoding = strtolower(Configure::read('App.encoding'));
$result = $this->Form->create('Contact');
$expected = array(
'form' => array(
'id' => 'ContactAddForm', 'method' => 'post', 'action' => '/contacts/add',
'accept-charset' => $encoding
),
'div' => array('style' => 'display:none;'),
'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'),
'/div'
);
$this->assertTags($result, $expected);
$result = $this->Form->input('Contact.non_existing_nor_validated', array('div' => false));
$expected = array(
'label' => array('for' => 'ContactNonExistingNorValidated'),
'Non Existing Nor Validated',
'/label',
'input' => array(
'type' => 'text', 'name' => 'data[Contact][non_existing_nor_validated]',
'id' => 'ContactNonExistingNorValidated'
)
);
$this->assertTags($result, $expected);
$result = $this->Form->input('Contact.non_existing_nor_validated', array(
'div' => false, 'value' => 'my value'
));
$expected = array(
'label' => array('for' => 'ContactNonExistingNorValidated'),
'Non Existing Nor Validated',
'/label',
'input' => array(
'type' => 'text', 'name' => 'data[Contact][non_existing_nor_validated]',
'value' => 'my value', 'id' => 'ContactNonExistingNorValidated'
)
);
$this->assertTags($result, $expected);
$this->Form->request->data = array(
'Contact' => array('non_existing_nor_validated' => 'CakePHP magic'
));
$result = $this->Form->input('Contact.non_existing_nor_validated', array('div' => false));
$expected = array(
'label' => array('for' => 'ContactNonExistingNorValidated'),
'Non Existing Nor Validated',
'/label',
'input' => array(
'type' => 'text', 'name' => 'data[Contact][non_existing_nor_validated]',
'value' => 'CakePHP magic', 'id' => 'ContactNonExistingNorValidated'
)
);
$this->assertTags($result, $expected);
}
/**
* testFormMagicInputLabel method
*
* @return void
*/
public function testFormMagicInputLabel() {
$encoding = strtolower(Configure::read('App.encoding'));
$result = $this->Form->create('Contact');
$expected = array(
'form' => array(
'id' => 'ContactAddForm', 'method' => 'post', 'action' => '/contacts/add',
'accept-charset' => $encoding
),
'div' => array('style' => 'display:none;'),
'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'),
'/div'
);
$this->assertTags($result, $expected);
$result = $this->Form->input('Contact.name', array('div' => false, 'label' => false));
$this->assertTags($result, array('input' => array(
'name' => 'data[Contact][name]', 'type' => 'text',
'id' => 'ContactName', 'maxlength' => '255')
));
$result = $this->Form->input('Contact.name', array('div' => false, 'label' => 'My label'));
$expected = array(
'label' => array('for' => 'ContactName'),
'My label',
'/label',
'input' => array(
'type' => 'text', 'name' => 'data[Contact][name]',
'id' => 'ContactName', 'maxlength' => '255'
)
);
$this->assertTags($result, $expected);
$result = $this->Form->input('Contact.name', array(
'div' => false, 'label' => array('class' => 'mandatory')
));
$expected = array(
'label' => array('for' => 'ContactName', 'class' => 'mandatory'),
'Name',
'/label',
'input' => array(
'type' => 'text', 'name' => 'data[Contact][name]',
'id' => 'ContactName', 'maxlength' => '255'
)
);
$this->assertTags($result, $expected);
$result = $this->Form->input('Contact.name', array(
'div' => false, 'label' => array('class' => 'mandatory', 'text' => 'My label')
));
$expected = array(
'label' => array('for' => 'ContactName', 'class' => 'mandatory'),
'My label',
'/label',
'input' => array(
'type' => 'text', 'name' => 'data[Contact][name]',
'id' => 'ContactName', 'maxlength' => '255'
)
);
$this->assertTags($result, $expected);
$result = $this->Form->input('Contact.name', array(
'div' => false, 'id' => 'my_id', 'label' => array('for' => 'my_id')
));
$expected = array(
'label' => array('for' => 'my_id'),
'Name',
'/label',
'input' => array(
'type' => 'text', 'name' => 'data[Contact][name]',
'id' => 'my_id', 'maxlength' => '255'
)
);
$this->assertTags($result, $expected);
$result = $this->Form->input('1.id');
$this->assertTags($result, array('input' => array(
'type' => 'hidden', 'name' => 'data[Contact][1][id]',
'id' => 'Contact1Id'
)));
$result = $this->Form->input("1.name");
$expected = array(
'div' => array('class' => 'input text'),
'label' => array('for' => 'Contact1Name'),
'Name',
'/label',
'input' => array(
'type' => 'text', 'name' => 'data[Contact][1][name]',
'id' => 'Contact1Name', 'maxlength' => '255'
),
'/div'
);
$this->assertTags($result, $expected);
$result = $this->Form->input('Contact.1.id');
$this->assertTags($result, array(
'input' => array(
'type' => 'hidden', 'name' => 'data[Contact][1][id]',
'id' => 'Contact1Id'
)
));
$result = $this->Form->input("Model.1.name");
$expected = array(
'div' => array('class' => 'input text'),
'label' => array('for' => 'Model1Name'),
'Name',
'/label',
'input' => array(
'type' => 'text', 'name' => 'data[Model][1][name]',
'id' => 'Model1Name'
),
'/div'
);
$this->assertTags($result, $expected);
}
/**
* testFormEnd method
*
* @return void
*/
public function testFormEnd() {
$this->assertEqual($this->Form->end(), '</form>');
$result = $this->Form->end('');
$expected = array(
'div' => array('class' => 'submit'),
'input' => array('type' => 'submit', 'value' => ''),
'/div',
'/form'
);
$this->assertTags($result, $expected);
$result = $this->Form->end(array('label' => ''));
$expected = array(
'div' => array('class' => 'submit'),
'input' => array('type' => 'submit', 'value' => ''),
'/div',
'/form'
);
$this->assertTags($result, $expected);
$result = $this->Form->end('save');
$expected = array(
'div' => array('class' => 'submit'),
'input' => array('type' => 'submit', 'value' => 'save'),
'/div',
'/form'
);
$this->assertTags($result, $expected);
$result = $this->Form->end(array('label' => 'save'));
$expected = array(
'div' => array('class' => 'submit'),
'input' => array('type' => 'submit', 'value' => 'save'),
'/div',
'/form'
);
$this->assertTags($result, $expected);
$result = $this->Form->end(array('label' => 'save', 'name' => 'Whatever'));
$expected = array(
'div' => array('class' => 'submit'),
'input' => array('type' => 'submit', 'value' => 'save', 'name' => 'Whatever'),
'/div',
'/form'
);
$this->assertTags($result, $expected);
$result = $this->Form->end(array('name' => 'Whatever'));
$expected = array(
'div' => array('class' => 'submit'),
'input' => array('type' => 'submit', 'value' => 'Submit', 'name' => 'Whatever'),
'/div',
'/form'
);
$this->assertTags($result, $expected);
$result = $this->Form->end(array('label' => 'save', 'name' => 'Whatever', 'div' => 'good'));
$expected = array(
'div' => array('class' => 'good'),
'input' => array('type' => 'submit', 'value' => 'save', 'name' => 'Whatever'),
'/div',
'/form'
);
$this->assertTags($result, $expected);
$result = $this->Form->end(array(
'label' => 'save', 'name' => 'Whatever', 'div' => array('class' => 'good')
));
$expected = array(
'div' => array('class' => 'good'),
'input' => array('type' => 'submit', 'value' => 'save', 'name' => 'Whatever'),
'/div',
'/form'
);
$this->assertTags($result, $expected);
}
/**
* testMultipleFormWithIdFields method
*
* @return void
*/
public function testMultipleFormWithIdFields() {
$this->Form->create('UserForm');
$result = $this->Form->input('id');
$this->assertTags($result, array('input' => array(
'type' => 'hidden', 'name' => 'data[UserForm][id]', 'id' => 'UserFormId'
)));
$result = $this->Form->input('ValidateItem.id');
$this->assertTags($result, array('input' => array(
'type' => 'hidden', 'name' => 'data[ValidateItem][id]',
'id' => 'ValidateItemId'
)));
$result = $this->Form->input('ValidateUser.id');
$this->assertTags($result, array('input' => array(
'type' => 'hidden', 'name' => 'data[ValidateUser][id]',
'id' => 'ValidateUserId'
)));
}
/**
* testDbLessModel method
*
* @return void
*/
public function testDbLessModel() {
$this->Form->create('TestMail');
$result = $this->Form->input('name');
$expected = array(
'div' => array('class' => 'input text'),
'label' => array('for' => 'TestMailName'),
'Name',
'/label',
'input' => array(
'name' => 'data[TestMail][name]', 'type' => 'text',
'id' => 'TestMailName'
),
'/div'
);
$this->assertTags($result, $expected);
ClassRegistry::init('TestMail');
$this->Form->create('TestMail');
$result = $this->Form->input('name');
$expected = array(
'div' => array('class' => 'input text'),
'label' => array('for' => 'TestMailName'),
'Name',
'/label',
'input' => array(
'name' => 'data[TestMail][name]', 'type' => 'text',
'id' => 'TestMailName'
),
'/div'
);
$this->assertTags($result, $expected);
}
/**
* testBrokenness method
*
* @return void
*/
public function testBrokenness() {
/*
* #4 This test has two parents and four children. By default (as of r7117) both
* parents are show but the first parent is missing a child. This is the inconsistency
* in the default behaviour - one parent has all children, the other does not - dependent
* on the data values.
*/
$result = $this->Form->select('Model.field', array(
'Fred' => array(
'freds_son_1' => 'Fred',
'freds_son_2' => 'Freddie'
),
'Bert' => array(
'berts_son_1' => 'Albert',
'berts_son_2' => 'Bertie')
),
array('showParents' => true, 'empty' => false)
);
$expected = array(
'select' => array('name' => 'data[Model][field]', 'id' => 'ModelField'),
array('optgroup' => array('label' => 'Fred')),
array('option' => array('value' => 'freds_son_1')),
'Fred',
'/option',
array('option' => array('value' => 'freds_son_2')),
'Freddie',
'/option',
'/optgroup',
array('optgroup' => array('label' => 'Bert')),
array('option' => array('value' => 'berts_son_1')),
'Albert',
'/option',
array('option' => array('value' => 'berts_son_2')),
'Bertie',
'/option',
'/optgroup',
'/select'
);
$this->assertTags($result, $expected);
/*
* #2 This is structurally identical to the test above (#1) - only the parent name has
* changed, so we should expect the same select list data, just with a different name
* for the parent. As of #7117, this test fails because option 3 => 'Three' disappears.
* This is where data corruption can occur, because when a select value is missing from
* a list a form will substitute the first value in the list - without the user knowing.
* If the optgroup name 'Parent' (above) is updated to 'Three' (below), this should not
* affect the availability of 3 => 'Three' as a valid option.
*/
$options = array(1 => 'One', 2 => 'Two', 'Three' => array(
3 => 'Three', 4 => 'Four', 5 => 'Five'
));
$result = $this->Form->select(
'Model.field', $options, array('showParents' => true, 'empty' => false)
);
$expected = array(
'select' => array('name' => 'data[Model][field]', 'id' => 'ModelField'),
array('option' => array('value' => 1)),
'One',
'/option',
array('option' => array('value' => 2)),
'Two',
'/option',
array('optgroup' => array('label' => 'Three')),
array('option' => array('value' => 3)),
'Three',
'/option',
array('option' => array('value' => 4)),
'Four',
'/option',
array('option' => array('value' => 5)),
'Five',
'/option',
'/optgroup',
'/select'
);
$this->assertTags($result, $expected);
}
/**
* Test the generation of fields for a multi record form.
*
* @return void
*/
public function testMultiRecordForm() {
$this->Form->create('ValidateProfile');
$this->Form->request->data['ValidateProfile'][1]['ValidateItem'][2]['name'] = 'Value';
$result = $this->Form->input('ValidateProfile.1.ValidateItem.2.name');
$expected = array(
'div' => array('class' => 'input textarea'),
'label' => array('for' => 'ValidateProfile1ValidateItem2Name'),
'Name',
'/label',
'textarea' => array(
'id' => 'ValidateProfile1ValidateItem2Name',
'name' => 'data[ValidateProfile][1][ValidateItem][2][name]',
'cols' => 30,
'rows' => 6
),
'Value',
'/textarea',
'/div'
);
$this->assertTags($result, $expected);
$result = $this->Form->input('ValidateProfile.1.ValidateItem.2.created',array('empty' => true));
$expected = array(
'div' => array('class' => 'input date'),
'label' => array('for' => 'ValidateProfile1ValidateItem2CreatedMonth'),
'Created',
'/label',
array('select' => array(
'name' => 'data[ValidateProfile][1][ValidateItem][2][created][month]',
'id' => 'ValidateProfile1ValidateItem2CreatedMonth'
)
),
array('option' => array('value' => '')), '/option',
$this->dateRegex['monthsRegex'],
'/select', '-',
array('select' => array(
'name' => 'data[ValidateProfile][1][ValidateItem][2][created][day]',
'id' => 'ValidateProfile1ValidateItem2CreatedDay'
)
),
array('option' => array('value' => '')), '/option',
$this->dateRegex['daysRegex'],
'/select', '-',
array('select' => array(
'name' => 'data[ValidateProfile][1][ValidateItem][2][created][year]',
'id' => 'ValidateProfile1ValidateItem2CreatedYear'
)
),
array('option' => array('value' => '')), '/option',
$this->dateRegex['yearsRegex'],
'/select',
'/div'
);
$this->assertTags($result, $expected);
$ValidateProfile = ClassRegistry::getObject('ValidateProfile');
$ValidateProfile->validationErrors[1]['ValidateItem'][2]['profile_id'] = 'Error';
$this->Form->request->data['ValidateProfile'][1]['ValidateItem'][2]['profile_id'] = '1';
$result = $this->Form->input('ValidateProfile.1.ValidateItem.2.profile_id');
$expected = array(
'div' => array('class' => 'input select error'),
'label' => array('for' => 'ValidateProfile1ValidateItem2ProfileId'),
'Profile',
'/label',
'select' => array(
'name' => 'data[ValidateProfile][1][ValidateItem][2][profile_id]',
'id' => 'ValidateProfile1ValidateItem2ProfileId',
'class' => 'form-error'
),
'/select',
array('div' => array('class' => 'error-message')),
'Error',
'/div',
'/div'
);
$this->assertTags($result, $expected);
}
/**
* test the correct display of multi-record form validation errors.
*
* @return void
*/
public function testMultiRecordFormValidationErrors() {
$this->Form->create('ValidateProfile');
$ValidateProfile = ClassRegistry::getObject('ValidateProfile');
$ValidateProfile->validationErrors[2]['ValidateItem'][1]['name'] = array('Error in field name');
$result = $this->Form->error('ValidateProfile.2.ValidateItem.1.name');
$this->assertTags($result, array('div' => array('class' => 'error-message'), 'Error in field name', '/div'));
$ValidateProfile->validationErrors[2]['city'] = array('Error in field city');
$result = $this->Form->error('ValidateProfile.2.city');
$this->assertTags($result, array('div' => array('class' => 'error-message'), 'Error in field city', '/div'));
$result = $this->Form->error('2.city');
$this->assertTags($result, array('div' => array('class' => 'error-message'), 'Error in field city', '/div'));
}
/**
* tests the ability to change the order of the form input placeholder "input", "label", "before", "between", "after", "error"
*
* @return void
*/
public function testInputTemplate() {
$result = $this->Form->input('Contact.email', array(
'type' => 'text', 'format' => array('input')
));
$expected = array(
'div' => array('class' => 'input text'),
'input' => array(
'type' => 'text', 'name' => 'data[Contact][email]',
'id' => 'ContactEmail'
),
'/div'
);
$this->assertTags($result, $expected);
$result = $this->Form->input('Contact.email', array(
'type' => 'text', 'format' => array('input', 'label'),
'label' => '<em>Email (required)</em>'
));
$expected = array(
'div' => array('class' => 'input text'),
array('input' => array(
'type' => 'text', 'name' => 'data[Contact][email]',
'id' => 'ContactEmail'
)),
'label' => array('for' => 'ContactEmail'),
'em' => array(),
'Email (required)',
'/em',
'/label',
'/div'
);
$this->assertTags($result, $expected);
$result = $this->Form->input('Contact.email', array(
'type' => 'text', 'format' => array('input', 'between', 'label', 'after'),
'between' => '<div>Something in the middle</div>',
'after' => '<span>Some text at the end</span>'
));
$expected = array(
'div' => array('class' => 'input text'),
array('input' => array(
'type' => 'text', 'name' => 'data[Contact][email]',
'id' => 'ContactEmail'
)),
array('div' => array()),
'Something in the middle',
'/div',
'label' => array('for' => 'ContactEmail'),
'Email',
'/label',
'span' => array(),
'Some text at the end',
'/span',
'/div'
);
$this->assertTags($result, $expected);
}
/**
* test that some html5 inputs + FormHelper::__call() work
*
* @return void
*/
public function testHtml5Inputs() {
$result = $this->Form->email('User.email');
$expected = array(
'input' => array('type' => 'email', 'name' => 'data[User][email]', 'id' => 'UserEmail')
);
$this->assertTags($result, $expected);
$result = $this->Form->search('User.query');
$expected = array(
'input' => array('type' => 'search', 'name' => 'data[User][query]', 'id' => 'UserQuery')
);
$this->assertTags($result, $expected);
$result = $this->Form->search('User.query', array('value' => 'test'));
$expected = array(
'input' => array('type' => 'search', 'name' => 'data[User][query]', 'id' => 'UserQuery', 'value' => 'test')
);
$this->assertTags($result, $expected);
$result = $this->Form->search('User.query', array('type' => 'text', 'value' => 'test'));
$expected = array(
'input' => array('type' => 'text', 'name' => 'data[User][query]', 'id' => 'UserQuery', 'value' => 'test')
);
$this->assertTags($result, $expected);
$result = $this->Form->input('User.website', array('type' => 'url', 'value' => 'http://domain.tld', 'div' => false, 'label' => false));
$expected = array(
'input' => array('type' => 'url', 'name' => 'data[User][website]', 'id' => 'UserWebsite', 'value' => 'http://domain.tld')
);
$this->assertTags($result, $expected);
}
/**
*
* @expectedException CakeException
* @return void
*/
public function testHtml5InputException() {
$this->Form->email();
}
/**
* Tests that a model can be loaded from the model names passed in the request object
*
* @return void
*/
public function testIntrospectModelFromRequest() {
$this->loadFixtures('Post');
App::build(array(
'plugins' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS)
));
CakePlugin::load('TestPlugin');
$this->Form->request['models'] = array('TestPluginPost' => array('plugin' => 'TestPlugin', 'className' => 'TestPluginPost'));
$this->assertFalse(ClassRegistry::isKeySet('TestPluginPost'));
$this->Form->create('TestPluginPost');
$this->assertTrue(ClassRegistry::isKeySet('TestPluginPost'));
$this->assertInstanceOf('TestPluginPost', ClassRegistry::getObject('TestPluginPost'));
CakePlugin::unload();
App::build();
}
/**
* Tests that it is possible to set the validation errors directly in the helper for a field
*
* @return void
*/
public function testCustomValidationErrors() {
$this->Form->validationErrors['Thing']['field'] = 'Badness!';
$result = $this->Form->error('Thing.field', null, array('wrap' => false));
$this->assertEquals('Badness!', $result);
}
}
| 0001-bee | trunk/cakephp2/lib/Cake/Test/Case/View/Helper/FormHelperTest.php | PHP | gpl3 | 242,587 |
<?php
/**
* SessionHelperTest file
*
* PHP 5
*
* CakePHP(tm) Tests <http://book.cakephp.org/view/1196/Testing>
* Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice
*
* @copyright Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://book.cakephp.org/view/1196/Testing CakePHP(tm) Tests
* @package Cake.Test.Case.View.Helper
* @since CakePHP(tm) v 1.2.0.4206
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
App::uses('Controller', 'Controller');
App::uses('View', 'View');
App::uses('SessionHelper', 'View/Helper');
/**
* SessionHelperTest class
*
* @package Cake.Test.Case.View.Helper
*/
class SessionHelperTest extends CakeTestCase {
/**
* setUp method
*
* @return void
*/
public function setUp() {
parent::setUp();
$controller = null;
$this->View = new View($controller);
$this->Session = new SessionHelper($this->View);
CakeSession::start();
if (!CakeSession::started()) {
CakeSession::start();
}
$_SESSION = array(
'test' => 'info',
'Message' => array(
'flash' => array(
'element' => 'default',
'params' => array(),
'message' => 'This is a calling'
),
'notification' => array(
'element' => 'session_helper',
'params' => array('title' => 'Notice!', 'name' => 'Alert!'),
'message' => 'This is a test of the emergency broadcasting system',
),
'classy' => array(
'element' => 'default',
'params' => array('class' => 'positive'),
'message' => 'Recorded'
),
'bare' => array(
'element' => null,
'message' => 'Bare message',
'params' => array(),
),
),
'Deeply' => array('nested' => array('key' => 'value')),
);
}
/**
* tearDown method
*
* @return void
*/
public function tearDown() {
$_SESSION = array();
unset($this->View, $this->Session);
parent::tearDown();
}
/**
* testRead method
*
* @return void
*/
public function testRead() {
$result = $this->Session->read('Deeply.nested.key');
$this->assertEqual($result, 'value');
$result = $this->Session->read('test');
$this->assertEqual($result, 'info');
}
/**
* testCheck method
*
* @return void
*/
public function testCheck() {
$this->assertTrue($this->Session->check('test'));
$this->assertTrue($this->Session->check('Message.flash.element'));
$this->assertFalse($this->Session->check('Does.not.exist'));
$this->assertFalse($this->Session->check('Nope'));
}
/**
* testFlash method
*
* @return void
*/
public function testFlash() {
$result = $this->Session->flash('flash');
$expected = '<div id="flashMessage" class="message">This is a calling</div>';
$this->assertEqual($expected, $result);
$this->assertFalse($this->Session->check('Message.flash'));
$expected = '<div id="classyMessage" class="positive">Recorded</div>';
$result = $this->Session->flash('classy');
$this->assertEqual($expected, $result);
App::build(array(
'View' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'View'. DS)
));
$result = $this->Session->flash('notification');
$result = str_replace("\r\n", "\n", $result);
$expected = "<div id=\"notificationLayout\">\n\t<h1>Alert!</h1>\n\t<h3>Notice!</h3>\n\t<p>This is a test of the emergency broadcasting system</p>\n</div>";
$this->assertEqual($expected, $result);
$this->assertFalse($this->Session->check('Message.notification'));
$result = $this->Session->flash('bare');
$expected = 'Bare message';
$this->assertEqual($expected, $result);
$this->assertFalse($this->Session->check('Message.bare'));
}
/**
* test flash() with the attributes.
*
* @return void
*/
public function testFlashAttributes() {
$result = $this->Session->flash('flash', array('params' => array('class' => 'test-message')));
$expected = '<div id="flashMessage" class="test-message">This is a calling</div>';
$this->assertEqual($expected, $result);
$this->assertFalse($this->Session->check('Message.flash'));
}
/**
* test setting the element from the attrs.
*
* @return void
*/
public function testFlashElementInAttrs() {
App::build(array(
'views' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'View'. DS)
));
$result = $this->Session->flash('flash', array(
'element' => 'session_helper',
'params' => array('title' => 'Notice!', 'name' => 'Alert!')
));
$expected = "<div id=\"notificationLayout\">\n\t<h1>Alert!</h1>\n\t<h3>Notice!</h3>\n\t<p>This is a calling</p>\n</div>";
}
}
| 0001-bee | trunk/cakephp2/lib/Cake/Test/Case/View/Helper/SessionHelperTest.php | PHP | gpl3 | 4,652 |
<?php
/**
* PrototypeEngine TestCase
*
* PHP 5
*
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
* Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright 2005-2011, Cake Software Foundation, Inc.
* @link http://cakephp.org CakePHP Project
* @package Cake.Test.Case.View.Helper
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
App::uses('View', 'View');
App::uses('HtmlHelper', 'View/Helper');
App::uses('JsHelper', 'View/Helper');
App::uses('PrototypeEngineHelper', 'View/Helper');
class PrototypeEngineHelperTest extends CakeTestCase {
/**
* setUp
*
* @return void
*/
public function setUp() {
parent::setUp();
$controller = null;
$this->View = $this->getMock('View', array('addScript'), array(&$controller));
$this->Proto = new PrototypeEngineHelper($this->View);
}
/**
* tearDown
*
* @return void
*/
public function tearDown() {
parent::tearDown();
unset($this->Proto);
}
/**
* test selector method
*
* @return void
*/
public function testSelector() {
$result = $this->Proto->get('#content');
$this->assertEqual($result, $this->Proto);
$this->assertEqual($this->Proto->selection, '$("content")');
$result = $this->Proto->get('a .remove');
$this->assertEqual($result, $this->Proto);
$this->assertEqual($this->Proto->selection, '$$("a .remove")');
$result = $this->Proto->get('document');
$this->assertEqual($result, $this->Proto);
$this->assertEqual($this->Proto->selection, "$(document)");
$result = $this->Proto->get('window');
$this->assertEqual($result, $this->Proto);
$this->assertEqual($this->Proto->selection, "$(window)");
$result = $this->Proto->get('ul');
$this->assertEqual($result, $this->Proto);
$this->assertEqual($this->Proto->selection, '$$("ul")');
$result = $this->Proto->get('#some_long-id.class');
$this->assertEqual($result, $this->Proto);
$this->assertEqual($this->Proto->selection, '$$("#some_long-id.class")');
}
/**
* test event binding
*
* @return void
*/
public function testEvent() {
$this->Proto->get('#myLink');
$result = $this->Proto->event('click', 'doClick', array('wrap' => false));
$expected = '$("myLink").observe("click", doClick);';
$this->assertEqual($expected, $result);
$result = $this->Proto->event('click', 'Element.hide(this);', array('stop' => false));
$expected = '$("myLink").observe("click", function (event) {Element.hide(this);});';
$this->assertEqual($expected, $result);
$result = $this->Proto->event('click', 'Element.hide(this);');
$expected = "\$(\"myLink\").observe(\"click\", function (event) {event.stop();\nElement.hide(this);});";
$this->assertEqual($expected, $result);
}
/**
* test dom ready event creation
*
* @return void
*/
public function testDomReady() {
$result = $this->Proto->domReady('foo.name = "bar";');
$expected = 'document.observe("dom:loaded", function (event) {foo.name = "bar";});';
$this->assertEqual($expected, $result);
}
/**
* test Each method
*
* @return void
*/
public function testEach() {
$this->Proto->get('#foo li');
$result = $this->Proto->each('item.hide();');
$expected = '$$("#foo li").each(function (item, index) {item.hide();});';
$this->assertEqual($expected, $result);
}
/**
* test Effect generation
*
* @return void
*/
public function testEffect() {
$this->Proto->get('#foo');
$result = $this->Proto->effect('show');
$expected = '$("foo").show();';
$this->assertEqual($expected, $result);
$result = $this->Proto->effect('hide');
$expected = '$("foo").hide();';
$this->assertEqual($expected, $result);
$result = $this->Proto->effect('fadeIn');
$expected = '$("foo").appear();';
$this->assertEqual($expected, $result);
$result = $this->Proto->effect('fadeIn', array('speed' => 'fast'));
$expected = '$("foo").appear({duration:0.50000000000});';
$this->assertEqual($expected, $result);
$result = $this->Proto->effect('fadeIn', array('speed' => 'slow'));
$expected = '$("foo").appear({duration:2});';
$this->assertEqual($expected, $result);
$result = $this->Proto->effect('fadeOut');
$expected = '$("foo").fade();';
$this->assertEqual($expected, $result);
$result = $this->Proto->effect('fadeOut', array('speed' => 'fast'));
$expected = '$("foo").fade({duration:0.50000000000});';
$this->assertEqual($expected, $result);
$result = $this->Proto->effect('fadeOut', array('speed' => 'slow'));
$expected = '$("foo").fade({duration:2});';
$this->assertEqual($expected, $result);
$result = $this->Proto->effect('slideIn');
$expected = 'Effect.slideDown($("foo"));';
$this->assertEqual($expected, $result);
$result = $this->Proto->effect('slideOut');
$expected = 'Effect.slideUp($("foo"));';
$this->assertEqual($expected, $result);
$result = $this->Proto->effect('slideOut', array('speed' => 'fast'));
$expected = 'Effect.slideUp($("foo"), {duration:0.50000000000});';
$this->assertEqual($expected, $result);
$result = $this->Proto->effect('slideOut', array('speed' => 'slow'));
$expected = 'Effect.slideUp($("foo"), {duration:2});';
$this->assertEqual($expected, $result);
}
/**
* Test Request Generation
*
* @return void
*/
public function testRequest() {
$result = $this->Proto->request(array('controller' => 'posts', 'action' => 'view', 1));
$expected = 'var jsRequest = new Ajax.Request("/posts/view/1");';
$this->assertEqual($expected, $result);
$result = $this->Proto->request('/posts/view/1', array(
'method' => 'post',
'complete' => 'doComplete',
'before' => 'doBefore',
'success' => 'doSuccess',
'error' => 'doError',
'data' => array('name' => 'jim', 'height' => '185cm'),
'wrapCallbacks' => false
));
$expected = 'var jsRequest = new Ajax.Request("/posts/view/1", {method:"post", onComplete:doComplete, onCreate:doBefore, onFailure:doError, onSuccess:doSuccess, parameters:{"name":"jim","height":"185cm"}});';
$this->assertEqual($expected, $result);
$result = $this->Proto->request('/posts/view/1', array('update' => 'content'));
$expected = 'var jsRequest = new Ajax.Updater("content", "/posts/view/1");';
$this->assertEqual($expected, $result);
$result = $this->Proto->request('/people/edit/1', array(
'method' => 'post',
'complete' => 'doSuccess',
'update' => '#update-zone',
'wrapCallbacks' => false
));
$expected = 'var jsRequest = new Ajax.Updater("update-zone", "/people/edit/1", {method:"post", onComplete:doSuccess});';
$this->assertEqual($expected, $result);
$result = $this->Proto->request('/people/edit/1', array(
'method' => 'post',
'complete' => 'doSuccess',
'error' => 'handleError',
'type' => 'json',
'data' => array('name' => 'jim', 'height' => '185cm'),
'wrapCallbacks' => false
));
$expected = 'var jsRequest = new Ajax.Request("/people/edit/1", {method:"post", onComplete:doSuccess, onFailure:handleError, parameters:{"name":"jim","height":"185cm"}});';
$this->assertEqual($expected, $result);
$result = $this->Proto->request('/people/edit/1', array(
'method' => 'post',
'complete' => 'doSuccess',
'error' => 'handleError',
'type' => 'json',
'data' => '$("element").serialize()',
'dataExpression' => true,
'wrapCallbacks' => false
));
$expected = 'var jsRequest = new Ajax.Request("/people/edit/1", {method:"post", onComplete:doSuccess, onFailure:handleError, parameters:$("element").serialize()});';
$this->assertEqual($expected, $result);
$result = $this->Proto->request('/people/edit/1', array(
'method' => 'post',
'before' => 'doBefore();',
'success' => 'doSuccess();',
'complete' => 'doComplete();',
'error' => 'handleError();',
));
$expected = 'var jsRequest = new Ajax.Request("/people/edit/1", {method:"post", onComplete:function (transport) {doComplete();}, onCreate:function (transport) {doBefore();}, onFailure:function (response, jsonHeader) {handleError();}, onSuccess:function (response, jsonHeader) {doSuccess();}});';
$this->assertEqual($expected, $result);
$result = $this->Proto->request('/people/edit/1', array(
'async' => false,
'method' => 'post',
'before' => 'doBefore();',
'success' => 'doSuccess();',
'complete' => 'doComplete();',
'error' => 'handleError();',
));
$expected = 'var jsRequest = new Ajax.Request("/people/edit/1", {asynchronous:false, method:"post", onComplete:function (transport) {doComplete();}, onCreate:function (transport) {doBefore();}, onFailure:function (response, jsonHeader) {handleError();}, onSuccess:function (response, jsonHeader) {doSuccess();}});';
$this->assertEqual($expected, $result);
$this->Proto->get('#submit');
$result = $this->Proto->request('/users/login', array(
'before' => 'login.create(event)',
'complete' => 'login.complete(event)',
'update' => 'auth',
'data' => $this->Proto->serializeForm(array('isForm' => false, 'inline' => true)),
'dataExpression' => true
));
$this->assertTrue(strpos($result, '$($("submit").form).serialize()') > 0);
$this->assertFalse(strpos($result, 'parameters:function () {$($("submit").form).serialize()}') > 0);
}
/**
* test sortable list generation
*
* @return void
*/
public function testSortable() {
$this->Proto->get('#myList');
$result = $this->Proto->sortable(array(
'complete' => 'onComplete',
'sort' => 'onSort',
'wrapCallbacks' => false
));
$expected = 'var jsSortable = Sortable.create($("myList"), {onChange:onSort, onUpdate:onComplete});';
$this->assertEqual($expected, $result);
}
/**
* test drag() method. Scriptaculous lacks the ability to take an Array of Elements
* in new Drag() when selection is a multiple type. Iterate over the array.
*
* @return void
*/
public function testDrag() {
$this->Proto->get('#element');
$result = $this->Proto->drag(array(
'start' => 'onStart',
'drag' => 'onDrag',
'stop' => 'onStop',
'snapGrid' => array(10, 10),
'wrapCallbacks' => false
));
$expected = 'var jsDrag = new Draggable($("element"), {onDrag:onDrag, onEnd:onStop, onStart:onStart, snap:[10,10]});';
$this->assertEqual($expected, $result);
$this->Proto->get('div.dragger');
$result = $this->Proto->drag(array(
'start' => 'onStart',
'drag' => 'onDrag',
'stop' => 'onStop',
'snapGrid' => array(10, 10),
'wrapCallbacks' => false
));
$expected = '$$("div.dragger").each(function (item, index) {new Draggable(item, {onDrag:onDrag, onEnd:onStop, onStart:onStart, snap:[10,10]});});';
$this->assertEqual($expected, $result);
}
/**
* test drop() method
*
* @return void
*/
public function testDrop() {
$this->Proto->get('#element');
$result = $this->Proto->drop(array(
'hover' => 'onHover',
'drop' => 'onDrop',
'accept' => '.drag-me',
'wrapCallbacks' => false
));
$expected = 'Droppables.add($("element"), {accept:".drag-me", onDrop:onDrop, onHover:onHover});';
$this->assertEqual($expected, $result);
}
/**
* ensure that slider() method behaves properly
*
* @return void
*/
public function testSlider() {
$this->Proto->get('#element');
$result = $this->Proto->slider(array(
'handle' => '#handle',
'direction' => 'horizontal',
'change' => 'onChange',
'complete' => 'onComplete',
'value' => 4,
'wrapCallbacks' => false
));
$expected = 'var jsSlider = new Control.Slider($("handle"), $("element"), {axis:"horizontal", onChange:onComplete, onSlide:onChange, sliderValue:4});';
$this->assertEqual($expected, $result);
$this->Proto->get('#element');
$result = $this->Proto->slider(array(
'handle' => '#handle',
'change' => 'change();',
'complete' => 'complete();',
'value' => 4,
'min' => 10,
'max' => 100
));
$expected = 'var jsSlider = new Control.Slider($("handle"), $("element"), {onChange:function (value) {complete();}, onSlide:function (value) {change();}, range:$R(10,100), sliderValue:4});';
$this->assertEqual($expected, $result);
}
/**
* test the serializeForm implementation.
*
* @return void
*/
public function testSerializeForm() {
$this->Proto->get('#element');
$result = $this->Proto->serializeForm(array('isForm' => true));
$expected = '$("element").serialize();';
$this->assertEqual($expected, $result);
$result = $this->Proto->serializeForm(array('isForm' => true, 'inline' => true));
$expected = '$("element").serialize()';
$this->assertEqual($expected, $result);
$result = $this->Proto->serializeForm(array('isForm' => false));
$expected = '$($("element").form).serialize();';
$this->assertEqual($expected, $result);
$result = $this->Proto->serializeForm(array('isForm' => false, 'inline' => true));
$expected = '$($("element").form).serialize()';
$this->assertEqual($expected, $result);
}
}
| 0001-bee | trunk/cakephp2/lib/Cake/Test/Case/View/Helper/PrototypeEngineHelperTest.php | PHP | gpl3 | 12,920 |
<?php
/**
* CacheHelperTest file
*
* PHP 5
*
* CakePHP(tm) Tests <http://book.cakephp.org/view/1196/Testing>
* Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice
*
* @copyright Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://book.cakephp.org/view/1196/Testing CakePHP(tm) Tests
* @package Cake.Test.Case.View.Helper
* @since CakePHP(tm) v 1.2.0.4206
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
App::uses('Controller', 'Controller');
App::uses('Model', 'Model');
App::uses('View', 'View');
App::uses('CacheHelper', 'View/Helper');
/**
* CacheTestController class
*
* @package Cake.Test.Case.View.Helper
*/
class CacheTestController extends Controller {
/**
* helpers property
*
* @var array
*/
public $helpers = array('Html', 'Cache');
/**
* cache_parsing method
*
* @return void
*/
public function cache_parsing() {
$this->viewPath = 'Posts';
$this->layout = 'cache_layout';
$this->set('variable', 'variableValue');
$this->set('superman', 'clark kent');
$this->set('batman', 'bruce wayne');
$this->set('spiderman', 'peter parker');
}
}
/**
* CacheHelperTest class
*
* @package Cake.Test.Case.View.Helper
*/
class CacheHelperTest extends CakeTestCase {
/**
* Checks if TMP/views is writable, and skips the case if it is not.
*
* @return void
*/
public function skip() {
$this->skipUnless(is_writable(TMP . 'cache' . DS . 'views' . DS), 'TMP/views is not writable %s');
}
/**
* setUp method
*
* @return void
*/
public function setUp() {
parent::setUp();
$_GET = array();
$request = new CakeRequest();
$this->Controller = new CacheTestController($request);
$View = new View($this->Controller);
$this->Cache = new CacheHelper($View);
Configure::write('Cache.check', true);
Configure::write('Cache.disable', false);
App::build(array(
'View' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'View'. DS)
), true);
}
/**
* tearDown method
*
* @return void
*/
public function tearDown() {
clearCache();
unset($this->Cache);
parent::tearDown();
}
/**
* test cache parsing with no cake:nocache tags in view file.
*
* @return void
*/
public function testLayoutCacheParsingNoTagsInView() {
$this->Controller->cache_parsing();
$this->Controller->request->addParams(array(
'controller' => 'cache_test',
'action' => 'cache_parsing',
'url' => array(),
'pass' => array(),
'named' => array()
));
$this->Controller->cacheAction = 21600;
$this->Controller->request->here = '/cacheTest/cache_parsing';
$this->Controller->request->action = 'cache_parsing';
$View = new View($this->Controller);
$result = $View->render('index');
$this->assertNoPattern('/cake:nocache/', $result);
$this->assertNoPattern('/php echo/', $result);
$filename = CACHE . 'views' . DS . 'cachetest_cache_parsing.php';
$this->assertTrue(file_exists($filename));
$contents = file_get_contents($filename);
$this->assertPattern('/php echo \$variable/', $contents);
$this->assertPattern('/php echo microtime()/', $contents);
$this->assertPattern('/clark kent/', $result);
@unlink($filename);
}
/**
* test cache parsing with non-latin characters in current route
*
* @return void
*/
public function testCacheNonLatinCharactersInRoute() {
$this->Controller->cache_parsing();
$this->Controller->request->addParams(array(
'controller' => 'cache_test',
'action' => 'cache_parsing',
'url' => array(),
'pass' => array('風街ろまん'),
'named' => array()
));
$this->Controller->cacheAction = 21600;
$this->Controller->request->here = '/posts/view/風街ろまん';
$this->Controller->action = 'view';
$View = new View($this->Controller);
$result = $View->render('index');
$filename = CACHE . 'views' . DS . 'posts_view_風街ろまん.php';
$this->assertTrue(file_exists($filename));
@unlink($filename);
}
/**
* Test cache parsing with cake:nocache tags in view file.
*
* @return void
*/
public function testLayoutCacheParsingWithTagsInView() {
$this->Controller->cache_parsing();
$this->Controller->request->addParams(array(
'controller' => 'cache_test',
'action' => 'cache_parsing',
'url' => array(),
'pass' => array(),
'named' => array()
));
$this->Controller->cacheAction = 21600;
$this->Controller->request->here = '/cacheTest/cache_parsing';
$this->Controller->action = 'cache_parsing';
$View = new View($this->Controller);
$result = $View->render('test_nocache_tags');
$this->assertNoPattern('/cake:nocache/', $result);
$this->assertNoPattern('/php echo/', $result);
$filename = CACHE . 'views' . DS . 'cachetest_cache_parsing.php';
$this->assertTrue(file_exists($filename));
$contents = file_get_contents($filename);
$this->assertPattern('/if \(is_writable\(TMP\)\)\:/', $contents);
$this->assertPattern('/php echo \$variable/', $contents);
$this->assertPattern('/php echo microtime()/', $contents);
$this->assertNoPattern('/cake:nocache/', $contents);
@unlink($filename);
}
/**
* test that multiple <!--nocache--> tags function with multiple nocache tags in the layout.
*
* @return void
*/
public function testMultipleNoCacheTagsInViewfile() {
$this->Controller->cache_parsing();
$this->Controller->request->addParams(array(
'controller' => 'cache_test',
'action' => 'cache_parsing',
'url' => array(),
'pass' => array(),
'named' => array()
));
$this->Controller->cacheAction = 21600;
$this->Controller->request->here = '/cacheTest/cache_parsing';
$this->Controller->action = 'cache_parsing';
$View = new View($this->Controller);
$result = $View->render('multiple_nocache');
$this->assertNoPattern('/cake:nocache/', $result);
$this->assertNoPattern('/php echo/', $result);
$filename = CACHE . 'views' . DS . 'cachetest_cache_parsing.php';
$this->assertTrue(file_exists($filename));
$contents = file_get_contents($filename);
$this->assertNoPattern('/cake:nocache/', $contents);
@unlink($filename);
}
/**
* testComplexNoCache method
*
* @return void
*/
public function testComplexNoCache () {
$this->Controller->cache_parsing();
$this->Controller->request->addParams(array(
'controller' => 'cache_test',
'action' => 'cache_complex',
'url' => array(),
'pass' => array(),
'named' => array()
));
$this->Controller->cacheAction = array('cache_complex' => 21600);
$this->Controller->request->here = '/cacheTest/cache_complex';
$this->Controller->action = 'cache_complex';
$this->Controller->layout = 'multi_cache';
$this->Controller->viewPath = 'Posts';
$View = new View($this->Controller);
$result = $View->render('sequencial_nocache');
$this->assertNoPattern('/cake:nocache/', $result);
$this->assertNoPattern('/php echo/', $result);
$this->assertPattern('/A\. Layout Before Content/', $result);
$this->assertPattern('/B\. In Plain Element/', $result);
$this->assertPattern('/C\. Layout After Test Element/', $result);
$this->assertPattern('/D\. In View File/', $result);
$this->assertPattern('/E\. Layout After Content/', $result);
//$this->assertPattern('/F\. In Element With No Cache Tags/', $result);
$this->assertPattern('/G\. Layout After Content And After Element With No Cache Tags/', $result);
$this->assertNoPattern('/1\. layout before content/', $result);
$this->assertNoPattern('/2\. in plain element/', $result);
$this->assertNoPattern('/3\. layout after test element/', $result);
$this->assertNoPattern('/4\. in view file/', $result);
$this->assertNoPattern('/5\. layout after content/', $result);
//$this->assertNoPattern('/6\. in element with no cache tags/', $result);
$this->assertNoPattern('/7\. layout after content and after element with no cache tags/', $result);
$filename = CACHE . 'views' . DS . 'cachetest_cache_complex.php';
$this->assertTrue(file_exists($filename));
$contents = file_get_contents($filename);
@unlink($filename);
$this->assertPattern('/A\. Layout Before Content/', $contents);
$this->assertNoPattern('/B\. In Plain Element/', $contents);
$this->assertPattern('/C\. Layout After Test Element/', $contents);
$this->assertPattern('/D\. In View File/', $contents);
$this->assertPattern('/E\. Layout After Content/', $contents);
//$this->assertPattern('/F\. In Element With No Cache Tags/', $contents);
$this->assertPattern('/G\. Layout After Content And After Element With No Cache Tags/', $contents);
$this->assertPattern('/1\. layout before content/', $contents);
$this->assertNoPattern('/2\. in plain element/', $contents);
$this->assertPattern('/3\. layout after test element/', $contents);
$this->assertPattern('/4\. in view file/', $contents);
$this->assertPattern('/5\. layout after content/', $contents);
//$this->assertPattern('/6\. in element with no cache tags/', $contents);
$this->assertPattern('/7\. layout after content and after element with no cache tags/', $contents);
}
/**
* test cache of view vars
*
* @return void
*/
public function testCacheViewVars() {
$this->Controller->cache_parsing();
$this->Controller->params = array(
'controller' => 'cache_test',
'action' => 'cache_parsing',
'url' => array(),
'pass' => array(),
'named' => array()
);
$this->Controller->cacheAction = 21600;
$this->Controller->here = '/cacheTest/cache_parsing';
$this->Controller->action = 'cache_parsing';
$View = new View($this->Controller);
$result = $View->render('index');
$this->assertNoPattern('/cake:nocache/', $result);
$this->assertNoPattern('/php echo/', $result);
$filename = CACHE . 'views' . DS . 'cachetest_cache_parsing.php';
$this->assertTrue(file_exists($filename));
$contents = file_get_contents($filename);
$this->assertPattern('/\$this\-\>viewVars/', $contents);
$this->assertPattern('/extract\(\$this\-\>viewVars, EXTR_SKIP\);/', $contents);
$this->assertPattern('/php echo \$variable/', $contents);
@unlink($filename);
}
/**
* Test that callback code is generated correctly.
*
* @return void
*/
public function testCacheCallbacks() {
$this->Controller->cache_parsing();
$this->Controller->params = array(
'controller' => 'cache_test',
'action' => 'cache_parsing',
'url' => array(),
'pass' => array(),
'named' => array()
);
$this->Controller->cacheAction = array(
'cache_parsing' => array(
'duration' => 21600,
'callbacks' => true
)
);
$this->Controller->here = '/cacheTest/cache_parsing';
$this->Controller->action = 'cache_parsing';
$View = new View($this->Controller);
$result = $View->render('index');
$filename = CACHE . 'views' . DS . 'cachetest_cache_parsing.php';
$this->assertTrue(file_exists($filename));
$contents = file_get_contents($filename);
$this->assertPattern('/\$controller->startupProcess\(\);/', $contents);
@unlink($filename);
}
/**
* test cacheAction set to a boolean
*
* @return void
*/
public function testCacheActionArray() {
$this->Controller->cache_parsing();
$this->Controller->request->addParams(array(
'controller' => 'cache_test',
'action' => 'cache_parsing',
'url' => array(),
'pass' => array(),
'named' => array()
));
$this->Controller->cacheAction = array(
'cache_parsing' => 21600
);
$this->Controller->request->here = '/cache_test/cache_parsing';
$this->Controller->action = 'cache_parsing';
$View = new View($this->Controller);
$result = $View->render('index');
$this->assertNoPattern('/cake:nocache/', $result);
$this->assertNoPattern('/php echo/', $result);
$filename = CACHE . 'views' . DS . 'cache_test_cache_parsing.php';
$this->assertTrue(file_exists($filename));
@unlink($filename);
$this->Controller->cache_parsing();
$this->Controller->cacheAction = array(
'cache_parsing' => 21600
);
$this->Controller->request->here = '/cacheTest/cache_parsing';
$this->Controller->action = 'cache_parsing';
$View = new View($this->Controller);
$result = $View->render('index');
$this->assertNoPattern('/cake:nocache/', $result);
$this->assertNoPattern('/php echo/', $result);
$filename = CACHE . 'views' . DS . 'cachetest_cache_parsing.php';
$this->assertTrue(file_exists($filename));
@unlink($filename);
$this->Controller->cache_parsing();
$this->Controller->request->addParams(array(
'controller' => 'cache_test',
'action' => 'cache_parsing',
'url' => array(),
'pass' => array(),
'named' => array()
));
$this->Controller->cacheAction = array(
'some_other_action' => 21600
);
$this->Controller->request->here = '/cacheTest/cache_parsing';
$this->Controller->action = 'cache_parsing';
$View = new View($this->Controller);
$result = $View->render('index');
$this->assertNoPattern('/cake:nocache/', $result);
$this->assertNoPattern('/php echo/', $result);
$filename = CACHE . 'views' . DS . 'cachetest_cache_parsing.php';
$this->assertFalse(file_exists($filename));
}
/**
* test with named and pass args.
*
* @return void
*/
public function testCacheWithNamedAndPassedArgs() {
Router::reload();
$this->Controller->cache_parsing();
$this->Controller->request->addParams(array(
'controller' => 'cache_test',
'action' => 'cache_parsing',
'url' => array(),
'pass' => array(1, 2),
'named' => array(
'name' => 'mark',
'ice' => 'cream'
)
));
$this->Controller->cacheAction = array(
'cache_parsing' => 21600
);
$this->Controller->request->here = '/cache_test/cache_parsing/1/2/name:mark/ice:cream';
$View = new View($this->Controller);
$result = $View->render('index');
$this->assertNoPattern('/cake:nocache/', $result);
$this->assertNoPattern('/php echo/', $result);
$filename = CACHE . 'views' . DS . 'cache_test_cache_parsing_1_2_name_mark_ice_cream.php';
$this->assertTrue(file_exists($filename));
@unlink($filename);
}
/**
* test that custom routes are respected when generating cache files.
*
* @return void
*/
public function testCacheWithCustomRoutes() {
Router::reload();
Router::connect('/:lang/:controller/:action/*', array(), array('lang' => '[a-z]{3}'));
$this->Controller->cache_parsing();
$this->Controller->request->addParams(array(
'lang' => 'en',
'controller' => 'cache_test',
'action' => 'cache_parsing',
'url' => array(),
'pass' => array(),
'named' => array()
));
$this->Controller->cacheAction = array(
'cache_parsing' => 21600
);
$this->Controller->request->here = '/en/cache_test/cache_parsing';
$this->Controller->action = 'cache_parsing';
$View = new View($this->Controller);
$result = $View->render('index');
$this->assertNoPattern('/cake:nocache/', $result);
$this->assertNoPattern('/php echo/', $result);
$filename = CACHE . 'views' . DS . 'en_cache_test_cache_parsing.php';
$this->assertTrue(file_exists($filename));
@unlink($filename);
}
/**
* test ControllerName contains AppName
*
* This test verifys view cache is created correctly when the app name is contained in part of the controller name.
* (webapp Name) base name is 'cache' controller is 'cacheTest' action is 'cache_name'
* apps url would look somehing like http://localhost/cache/cacheTest/cache_name
*
* @return void
**/
public function testCacheBaseNameControllerName() {
$this->Controller->cache_parsing();
$this->Controller->cacheAction = array(
'cache_name' => 21600
);
$this->Controller->params = array(
'controller' => 'cacheTest',
'action' => 'cache_name',
'url' => array(),
'pass' => array(),
'named' => array()
);
$this->Controller->here = '/cache/cacheTest/cache_name';
$this->Controller->action = 'cache_name';
$this->Controller->base = '/cache';
$View = new View($this->Controller);
$result = $View->render('index');
$this->assertNoPattern('/cake:nocache/', $result);
$this->assertNoPattern('/php echo/', $result);
$filename = CACHE . 'views' . DS . 'cache_cachetest_cache_name.php';
$this->assertTrue(file_exists($filename));
@unlink($filename);
}
/**
* test that afterRender checks the conditions correctly.
*
* @return void
*/
public function testAfterRenderConditions() {
Configure::write('Cache.check', true);
$View = new View($this->Controller);
$View->cacheAction = '+1 day';
$View->output = 'test';
$Cache = $this->getMock('CacheHelper', array('cache'), array($View));
$Cache->expects($this->once())->method('cache')
->with('posts/index', $View->output, false);
$Cache->afterRender('posts/index');
Configure::write('Cache.check', false);
$Cache->afterRender('posts/index');
Configure::write('Cache.check', true);
$View->cacheAction = false;
$Cache->afterRender('posts/index');
}
/**
* test that afterRender checks the conditions correctly.
*
* @return void
*/
public function testAfterLayoutConditions() {
Configure::write('Cache.check', true);
$View = new View($this->Controller);
$View->cacheAction = '+1 day';
$View->output = 'test';
$Cache = $this->getMock('CacheHelper', array('cache'), array($View));
$Cache->expects($this->once())->method('cache')
->with('posts/index', $View->output, true);
$Cache->afterLayout('posts/index');
Configure::write('Cache.check', false);
$Cache->afterLayout('posts/index');
Configure::write('Cache.check', true);
$View->cacheAction = false;
$Cache->afterLayout('posts/index');
}
/**
* testCacheEmptySections method
*
* This test must be uncommented/fixed in next release (1.2+)
*
* @return void
*/
public function testCacheEmptySections() {
$this->Controller->cache_parsing();
$this->Controller->params = array(
'controller' => 'cacheTest',
'action' => 'cache_empty_sections',
'url' => array(),
'pass' => array(),
'named' => array()
);
$this->Controller->cacheAction = array('cache_empty_sections' => 21600);
$this->Controller->here = '/cacheTest/cache_empty_sections';
$this->Controller->action = 'cache_empty_sections';
$this->Controller->layout = 'cache_empty_sections';
$this->Controller->viewPath = 'Posts';
$View = new View($this->Controller);
$result = $View->render('cache_empty_sections');
$this->assertNoPattern('/nocache/', $result);
$this->assertNoPattern('/php echo/', $result);
$this->assertPattern(
'@</title>\s*</head>\s*' .
'<body>\s*' .
'View Content\s*' .
'cached count is: 3\s*' .
'</body>@', $result);
$filename = CACHE . 'views' . DS . 'cachetest_cache_empty_sections.php';
$this->assertTrue(file_exists($filename));
$contents = file_get_contents($filename);
$this->assertNoPattern('/nocache/', $contents);
$this->assertPattern(
'@<head>\s*<title>Posts</title>\s*' .
'<\?php \$x \= 1; \?>\s*' .
'</head>\s*' .
'<body>\s*' .
'<\?php \$x\+\+; \?>\s*' .
'<\?php \$x\+\+; \?>\s*' .
'View Content\s*' .
'<\?php \$y = 1; \?>\s*' .
'<\?php echo \'cached count is: \' . \$x; \?>\s*' .
'@', $contents);
@unlink($filename);
}
}
| 0001-bee | trunk/cakephp2/lib/Cake/Test/Case/View/Helper/CacheHelperTest.php | PHP | gpl3 | 19,161 |
<?php
/**
* TimeHelperTest file
*
* PHP 5
*
* CakePHP(tm) Tests <http://book.cakephp.org/view/1196/Testing>
* Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice
*
* @copyright Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://book.cakephp.org/view/1196/Testing CakePHP(tm) Tests
* @package Cake.Test.Case.View.Helper
* @since CakePHP(tm) v 1.2.0.4206
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
App::uses('TimeHelper', 'View/Helper');
App::uses('View', 'View');
/**
* TimeHelperTest class
*
* @package Cake.Test.Case.View.Helper
*/
class TimeHelperTest extends CakeTestCase {
/**
* setUp method
*
* @return void
*/
public function setUp() {
$controller = null;
$View = new View($controller);
$this->Time = new TimeHelper($View);
}
/**
* tearDown method
*
* @return void
*/
public function tearDown() {
unset($this->Time);
}
/**
* testToQuarter method
*
* @return void
*/
public function testToQuarter() {
$result = $this->Time->toQuarter('2007-12-25');
$this->assertEqual($result, 4);
$result = $this->Time->toQuarter('2007-9-25');
$this->assertEqual($result, 3);
$result = $this->Time->toQuarter('2007-3-25');
$this->assertEqual($result, 1);
$result = $this->Time->toQuarter('2007-3-25', true);
$this->assertEqual($result, array('2007-01-01', '2007-03-31'));
$result = $this->Time->toQuarter('2007-5-25', true);
$this->assertEqual($result, array('2007-04-01', '2007-06-30'));
$result = $this->Time->toQuarter('2007-8-25', true);
$this->assertEqual($result, array('2007-07-01', '2007-09-30'));
$result = $this->Time->toQuarter('2007-12-25', true);
$this->assertEqual($result, array('2007-10-01', '2007-12-31'));
}
/**
* testTimeAgoInWords method
*
* @return void
*/
public function testTimeAgoInWords() {
$result = $this->Time->timeAgoInWords('-1 week');
$this->assertEqual($result, '1 week ago');
$result = $this->Time->timeAgoInWords('+1 week');
$this->assertEqual($result, '1 week');
$result = $this->Time->timeAgoInWords(strtotime('+4 months +2 weeks +3 days'), array('end' => '8 years'), true);
$this->assertEqual($result, '4 months, 2 weeks, 3 days');
$result = $this->Time->timeAgoInWords(strtotime('+4 months +2 weeks +2 days'), array('end' => '8 years'), true);
$this->assertEqual($result, '4 months, 2 weeks, 2 days');
$result = $this->Time->timeAgoInWords(strtotime('+4 months +2 weeks +1 day'), array('end' => '8 years'), true);
$this->assertEqual($result, '4 months, 2 weeks, 1 day');
$result = $this->Time->timeAgoInWords(strtotime('+3 months +2 weeks +1 day'), array('end' => '8 years'), true);
$this->assertEqual($result, '3 months, 2 weeks, 1 day');
$result = $this->Time->timeAgoInWords(strtotime('+3 months +2 weeks'), array('end' => '8 years'), true);
$this->assertEqual($result, '3 months, 2 weeks');
$result = $this->Time->timeAgoInWords(strtotime('+3 months +1 week +6 days'), array('end' => '8 years'), true);
$this->assertEqual($result, '3 months, 1 week, 6 days');
$result = $this->Time->timeAgoInWords(strtotime('+2 months +2 weeks +1 day'), array('end' => '8 years'), true);
$this->assertEqual($result, '2 months, 2 weeks, 1 day');
$result = $this->Time->timeAgoInWords(strtotime('+2 months +2 weeks'), array('end' => '8 years'), true);
$this->assertEqual($result, '2 months, 2 weeks');
$result = $this->Time->timeAgoInWords(strtotime('+2 months +1 week +6 days'), array('end' => '8 years'), true);
$this->assertEqual($result, '2 months, 1 week, 6 days');
$result = $this->Time->timeAgoInWords(strtotime('+1 month +1 week +6 days'), array('end' => '8 years'), true);
$this->assertEqual($result, '1 month, 1 week, 6 days');
for($i = 0; $i < 200; $i ++) {
$years = mt_rand(0, 3);
$months = mt_rand(0, 11);
$weeks = mt_rand(0, 3);
$days = mt_rand(0, 6);
$hours = 0;
$minutes = 0;
$seconds = 0;
$relative_date = '';
if ($years > 0) {
// years and months and days
$relative_date .= ($relative_date ? ', -' : '-') . $years . ' year' . ($years > 1 ? 's' : '');
$relative_date .= $months > 0 ? ($relative_date ? ', -' : '-') . $months . ' month' . ($months > 1 ? 's' : '') : '';
$relative_date .= $weeks > 0 ? ($relative_date ? ', -' : '-') . $weeks . ' week' . ($weeks > 1 ? 's' : '') : '';
$relative_date .= $days > 0 ? ($relative_date ? ', -' : '-') . $days . ' day' . ($days > 1 ? 's' : '') : '';
} elseif (abs($months) > 0) {
// months, weeks and days
$relative_date .= ($relative_date ? ', -' : '-') . $months . ' month' . ($months > 1 ? 's' : '');
$relative_date .= $weeks > 0 ? ($relative_date ? ', -' : '-') . $weeks . ' week' . ($weeks > 1 ? 's' : '') : '';
$relative_date .= $days > 0 ? ($relative_date ? ', -' : '-') . $days . ' day' . ($days > 1 ? 's' : '') : '';
} elseif (abs($weeks) > 0) {
// weeks and days
$relative_date .= ($relative_date ? ', -' : '-') . $weeks . ' week' . ($weeks > 1 ? 's' : '');
$relative_date .= $days > 0 ? ($relative_date ? ', -' : '-') . $days . ' day' . ($days > 1 ? 's' : '') : '';
} elseif (abs($days) > 0) {
// days and hours
$relative_date .= ($relative_date ? ', -' : '-') . $days . ' day' . ($days > 1 ? 's' : '');
$relative_date .= $hours > 0 ? ($relative_date ? ', -' : '-') . $hours . ' hour' . ($hours > 1 ? 's' : '') : '';
} elseif (abs($hours) > 0) {
// hours and minutes
$relative_date .= ($relative_date ? ', -' : '-') . $hours . ' hour' . ($hours > 1 ? 's' : '');
$relative_date .= $minutes > 0 ? ($relative_date ? ', -' : '-') . $minutes . ' minute' . ($minutes > 1 ? 's' : '') : '';
} elseif (abs($minutes) > 0) {
// minutes only
$relative_date .= ($relative_date ? ', -' : '-') . $minutes . ' minute' . ($minutes > 1 ? 's' : '');
} else {
// seconds only
$relative_date .= ($relative_date ? ', -' : '-') . $seconds . ' second' . ($seconds != 1 ? 's' : '');
}
if (date('j/n/y', strtotime(str_replace(',','',$relative_date))) != '1/1/70') {
$result = $this->Time->timeAgoInWords(strtotime(str_replace(',','',$relative_date)), array('end' => '8 years'), true);
if ($relative_date == '0 seconds') {
$relative_date = '0 seconds ago';
}
$relative_date = str_replace('-', '', $relative_date) . ' ago';
$this->assertEqual($result, $relative_date);
}
}
for ($i = 0; $i < 200; $i ++) {
$years = mt_rand(0, 3);
$months = mt_rand(0, 11);
$weeks = mt_rand(0, 3);
$days = mt_rand(0, 6);
$hours = 0;
$minutes = 0;
$seconds = 0;
$relative_date = '';
if ($years > 0) {
// years and months and days
$relative_date .= ($relative_date ? ', ' : '') . $years . ' year' . ($years > 1 ? 's' : '');
$relative_date .= $months > 0 ? ($relative_date ? ', ' : '') . $months . ' month' . ($months > 1 ? 's' : '') : '';
$relative_date .= $weeks > 0 ? ($relative_date ? ', ' : '') . $weeks . ' week' . ($weeks > 1 ? 's' : '') : '';
$relative_date .= $days > 0 ? ($relative_date ? ', ' : '') . $days . ' day' . ($days > 1 ? 's' : '') : '';
} elseif (abs($months) > 0) {
// months, weeks and days
$relative_date .= ($relative_date ? ', ' : '') . $months . ' month' . ($months > 1 ? 's' : '');
$relative_date .= $weeks > 0 ? ($relative_date ? ', ' : '') . $weeks . ' week' . ($weeks > 1 ? 's' : '') : '';
$relative_date .= $days > 0 ? ($relative_date ? ', ' : '') . $days . ' day' . ($days > 1 ? 's' : '') : '';
} elseif (abs($weeks) > 0) {
// weeks and days
$relative_date .= ($relative_date ? ', ' : '') . $weeks . ' week' . ($weeks > 1 ? 's' : '');
$relative_date .= $days > 0 ? ($relative_date ? ', ' : '') . $days . ' day' . ($days > 1 ? 's' : '') : '';
} elseif (abs($days) > 0) {
// days and hours
$relative_date .= ($relative_date ? ', ' : '') . $days . ' day' . ($days > 1 ? 's' : '');
$relative_date .= $hours > 0 ? ($relative_date ? ', ' : '') . $hours . ' hour' . ($hours > 1 ? 's' : '') : '';
} elseif (abs($hours) > 0) {
// hours and minutes
$relative_date .= ($relative_date ? ', ' : '') . $hours . ' hour' . ($hours > 1 ? 's' : '');
$relative_date .= $minutes > 0 ? ($relative_date ? ', ' : '') . $minutes . ' minute' . ($minutes > 1 ? 's' : '') : '';
} elseif (abs($minutes) > 0) {
// minutes only
$relative_date .= ($relative_date ? ', ' : '') . $minutes . ' minute' . ($minutes > 1 ? 's' : '');
} else {
// seconds only
$relative_date .= ($relative_date ? ', ' : '') . $seconds . ' second' . ($seconds != 1 ? 's' : '');
}
if (date('j/n/y', strtotime(str_replace(',','',$relative_date))) != '1/1/70') {
$result = $this->Time->timeAgoInWords(strtotime(str_replace(',','',$relative_date)), array('end' => '8 years'), true);
if ($relative_date == '0 seconds') {
$relative_date = '0 seconds ago';
}
$relative_date = str_replace('-', '', $relative_date) . '';
$this->assertEqual($result, $relative_date);
}
}
$result = $this->Time->timeAgoInWords(strtotime('-2 years -5 months -2 days'), array('end' => '3 years'), true);
$this->assertEqual($result, '2 years, 5 months, 2 days ago');
$result = $this->Time->timeAgoInWords('2007-9-25');
$this->assertEqual($result, 'on 25/9/07');
$result = $this->Time->timeAgoInWords('2007-9-25', 'Y-m-d');
$this->assertEqual($result, 'on 2007-09-25');
$result = $this->Time->timeAgoInWords('2007-9-25', 'Y-m-d', true);
$this->assertEqual($result, 'on 2007-09-25');
$result = $this->Time->timeAgoInWords(strtotime('-2 weeks -2 days'), 'Y-m-d', false);
$this->assertEqual($result, '2 weeks, 2 days ago');
$result = $this->Time->timeAgoInWords(strtotime('+2 weeks +2 days'), 'Y-m-d', true);
$this->assertPattern('/^2 weeks, [1|2] day(s)?$/', $result);
$result = $this->Time->timeAgoInWords(strtotime('+2 months +2 days'), array('end' => '1 month'));
$this->assertEqual($result, 'on ' . date('j/n/y', strtotime('+2 months +2 days')));
$result = $this->Time->timeAgoInWords(strtotime('+2 months +2 days'), array('end' => '3 month'));
$this->assertPattern('/2 months/', $result);
$result = $this->Time->timeAgoInWords(strtotime('+2 months +12 days'), array('end' => '3 month'));
$this->assertPattern('/2 months, 1 week/', $result);
$result = $this->Time->timeAgoInWords(strtotime('+3 months +5 days'), array('end' => '4 month'));
$this->assertEqual($result, '3 months, 5 days');
$result = $this->Time->timeAgoInWords(strtotime('-2 months -2 days'), array('end' => '3 month'));
$this->assertEqual($result, '2 months, 2 days ago');
$result = $this->Time->timeAgoInWords(strtotime('-2 months -2 days'), array('end' => '3 month'));
$this->assertEqual($result, '2 months, 2 days ago');
$result = $this->Time->timeAgoInWords(strtotime('+2 months +2 days'), array('end' => '3 month'));
$this->assertPattern('/2 months/', $result);
$result = $this->Time->timeAgoInWords(strtotime('+2 months +2 days'), array('end' => '1 month', 'format' => 'Y-m-d'));
$this->assertEqual($result, 'on ' . date('Y-m-d', strtotime('+2 months +2 days')));
$result = $this->Time->timeAgoInWords(strtotime('-2 months -2 days'), array('end' => '1 month', 'format' => 'Y-m-d'));
$this->assertEqual($result, 'on ' . date('Y-m-d', strtotime('-2 months -2 days')));
$result = $this->Time->timeAgoInWords(strtotime('-13 months -5 days'), array('end' => '2 years'));
$this->assertEqual($result, '1 year, 1 month, 5 days ago');
$fourHours = $this->Time->timeAgoInWords(strtotime('-5 days -2 hours'), array('userOffset' => -4));
$result = $this->Time->timeAgoInWords(strtotime('-5 days -2 hours'), array('userOffset' => 4));
$this->assertEqual($fourHours, $result);
$result = $this->Time->timeAgoInWords(strtotime('-2 hours'));
$expected = '2 hours ago';
$this->assertEqual($expected, $result);
$result = $this->Time->timeAgoInWords(strtotime('-12 minutes'));
$expected = '12 minutes ago';
$this->assertEqual($expected, $result);
$result = $this->Time->timeAgoInWords(strtotime('-12 seconds'));
$expected = '12 seconds ago';
$this->assertEqual($expected, $result);
$time = strtotime('-3 years -12 months');
$result = $this->Time->timeAgoInWords($time);
$expected = 'on ' . date('j/n/y', $time);
$this->assertEqual($expected, $result);
}
/**
* testNice method
*
* @return void
*/
public function testNice() {
$time = time() + 2 * DAY;
$this->assertEqual(date('D, M jS Y, H:i', $time), $this->Time->nice($time));
$time = time() - 2 * DAY;
$this->assertEqual(date('D, M jS Y, H:i', $time), $this->Time->nice($time));
$time = time();
$this->assertEqual(date('D, M jS Y, H:i', $time), $this->Time->nice($time));
$time = 0;
$this->assertEqual(date('D, M jS Y, H:i', time()), $this->Time->nice($time));
$time = null;
$this->assertEqual(date('D, M jS Y, H:i', time()), $this->Time->nice($time));
$time = time();
$this->assertEqual(date('D', $time), $this->Time->nice($time, null, '%a'));
$this->assertEqual(date('M d, Y', $time), $this->Time->nice($time, null, '%b %d, %Y'));
$this->Time->niceFormat = '%Y-%d-%m';
$this->assertEqual(date('Y-d-m', $time), $this->Time->nice($time));
}
/**
* testNiceShort method
*
* @return void
*/
public function testNiceShort() {
$time = time() + 2 * DAY;
if (date('Y', $time) == date('Y')) {
$this->assertEqual(date('M jS, H:i', $time), $this->Time->niceShort($time));
} else {
$this->assertEqual(date('M jS Y, H:i', $time), $this->Time->niceShort($time));
}
$time = time();
$this->assertEqual('Today, ' . date('H:i', $time), $this->Time->niceShort($time));
$time = time() - DAY;
$this->assertEqual('Yesterday, ' . date('H:i', $time), $this->Time->niceShort($time));
}
/**
* testDaysAsSql method
*
* @return void
*/
public function testDaysAsSql() {
$begin = time();
$end = time() + DAY;
$field = 'my_field';
$expected = '(my_field >= \''.date('Y-m-d', $begin).' 00:00:00\') AND (my_field <= \''.date('Y-m-d', $end).' 23:59:59\')';
$this->assertEqual($expected, $this->Time->daysAsSql($begin, $end, $field));
}
/**
* testDayAsSql method
*
* @return void
*/
public function testDayAsSql() {
$time = time();
$field = 'my_field';
$expected = '(my_field >= \''.date('Y-m-d', $time).' 00:00:00\') AND (my_field <= \''.date('Y-m-d', $time).' 23:59:59\')';
$this->assertEqual($expected, $this->Time->dayAsSql($time, $field));
}
/**
* testToUnix method
*
* @return void
*/
public function testToUnix() {
$this->assertEqual(time(), $this->Time->toUnix(time()));
$this->assertEqual(strtotime('+1 day'), $this->Time->toUnix('+1 day'));
$this->assertEqual(strtotime('+0 days'), $this->Time->toUnix('+0 days'));
$this->assertEqual(strtotime('-1 days'), $this->Time->toUnix('-1 days'));
$this->assertEqual(false, $this->Time->toUnix(''));
$this->assertEqual(false, $this->Time->toUnix(null));
}
/**
* testToAtom method
*
* @return void
*/
public function testToAtom() {
$this->assertEqual(date('Y-m-d\TH:i:s\Z'), $this->Time->toAtom(time()));
}
/**
* testToRss method
*
* @return void
*/
public function testToRss() {
$this->assertEqual(date('r'), $this->Time->toRss(time()));
if (!$this->skipIf(!class_exists('DateTimeZone'), '%s DateTimeZone class not available.')) {
$timezones = array('Europe/London', 'Europe/Brussels', 'UTC', 'America/Denver', 'America/Caracas', 'Asia/Kathmandu');
foreach($timezones as $timezone) {
$yourTimezone = new DateTimeZone($timezone);
$yourTime = new DateTime('now', $yourTimezone);
$userOffset = $yourTimezone->getOffset($yourTime) / HOUR;
$this->assertEqual($yourTime->format('r'), $this->Time->toRss(time(), $userOffset));
}
}
}
/**
* testFormat method
*
* @return void
*/
public function testFormat() {
$format = 'D-M-Y';
$arr = array(time(), strtotime('+1 days'), strtotime('+1 days'), strtotime('+0 days'));
foreach ($arr as $val) {
$this->assertEqual(date($format, $val), $this->Time->format($format, $val));
}
$result = $this->Time->format('Y-m-d', null, 'never');
$this->assertEqual($result, 'never');
}
/**
* testOfGmt method
*
* @return void
*/
public function testGmt() {
$hour = 3;
$min = 4;
$sec = 2;
$month = 5;
$day = 14;
$year = 2007;
$time = mktime($hour, $min, $sec, $month, $day, $year);
$expected = gmmktime($hour, $min, $sec, $month, $day, $year);
$this->assertEqual($expected, $this->Time->gmt(date('Y-n-j G:i:s', $time)));
$hour = date('H');
$min = date('i');
$sec = date('s');
$month = date('m');
$day = date('d');
$year = date('Y');
$expected = gmmktime($hour, $min, $sec, $month, $day, $year);
$this->assertEqual($expected, $this->Time->gmt(null));
}
/**
* testIsToday method
*
* @return void
*/
public function testIsToday() {
$result = $this->Time->isToday('+1 day');
$this->assertFalse($result);
$result = $this->Time->isToday('+1 days');
$this->assertFalse($result);
$result = $this->Time->isToday('+0 day');
$this->assertTrue($result);
$result = $this->Time->isToday('-1 day');
$this->assertFalse($result);
}
/**
* testIsThisWeek method
*
* @return void
*/
public function testIsThisWeek() {
// A map of days which goes from -1 day of week to +1 day of week
$map = array(
'Mon' => array(-1, 7), 'Tue' => array(-2, 6), 'Wed' => array(-3, 5),
'Thu' => array(-4, 4), 'Fri' => array(-5, 3), 'Sat' => array(-6, 2),
'Sun' => array(-7, 1)
);
$days = $map[date('D')];
for ($day = $days[0] + 1; $day < $days[1]; $day++) {
$this->assertTrue($this->Time->isThisWeek(($day > 0 ? '+' : '') . $day . ' days'));
}
$this->assertFalse($this->Time->isThisWeek($days[0] . ' days'));
$this->assertFalse($this->Time->isThisWeek('+' . $days[1] . ' days'));
}
/**
* testIsThisMonth method
*
* @return void
*/
public function testIsThisMonth() {
$result = $this->Time->isThisMonth('+0 day');
$this->assertTrue($result);
$result = $this->Time->isThisMonth($time = mktime(0, 0, 0, date('m'), mt_rand(1, 28), date('Y')));
$this->assertTrue($result);
$result = $this->Time->isThisMonth(mktime(0, 0, 0, date('m'), mt_rand(1, 28), date('Y') - mt_rand(1, 12)));
$this->assertFalse($result);
$result = $this->Time->isThisMonth(mktime(0, 0, 0, date('m'), mt_rand(1, 28), date('Y') + mt_rand(1, 12)));
$this->assertFalse($result);
}
/**
* testIsThisYear method
*
* @return void
*/
public function testIsThisYear() {
$result = $this->Time->isThisYear('+0 day');
$this->assertTrue($result);
$result = $this->Time->isThisYear(mktime(0, 0, 0, mt_rand(1, 12), mt_rand(1, 28), date('Y')));
$this->assertTrue($result);
}
/**
* testWasYesterday method
*
* @return void
*/
public function testWasYesterday() {
$result = $this->Time->wasYesterday('+1 day');
$this->assertFalse($result);
$result = $this->Time->wasYesterday('+1 days');
$this->assertFalse($result);
$result = $this->Time->wasYesterday('+0 day');
$this->assertFalse($result);
$result = $this->Time->wasYesterday('-1 day');
$this->assertTrue($result);
$result = $this->Time->wasYesterday('-1 days');
$this->assertTrue($result);
$result = $this->Time->wasYesterday('-2 days');
$this->assertFalse($result);
}
/**
* testIsTomorrow method
*
* @return void
*/
public function testIsTomorrow() {
$result = $this->Time->isTomorrow('+1 day');
$this->assertTrue($result);
$result = $this->Time->isTomorrow('+1 days');
$this->assertTrue($result);
$result = $this->Time->isTomorrow('+0 day');
$this->assertFalse($result);
$result = $this->Time->isTomorrow('-1 day');
$this->assertFalse($result);
}
/**
* testWasWithinLast method
*
* @return void
*/
public function testWasWithinLast() {
$this->assertTrue($this->Time->wasWithinLast('1 day', '-1 day'));
$this->assertTrue($this->Time->wasWithinLast('1 week', '-1 week'));
$this->assertTrue($this->Time->wasWithinLast('1 year', '-1 year'));
$this->assertTrue($this->Time->wasWithinLast('1 second', '-1 second'));
$this->assertTrue($this->Time->wasWithinLast('1 minute', '-1 minute'));
$this->assertTrue($this->Time->wasWithinLast('1 year', '-1 year'));
$this->assertTrue($this->Time->wasWithinLast('1 month', '-1 month'));
$this->assertTrue($this->Time->wasWithinLast('1 day', '-1 day'));
$this->assertTrue($this->Time->wasWithinLast('1 week', '-1 day'));
$this->assertTrue($this->Time->wasWithinLast('2 week', '-1 week'));
$this->assertFalse($this->Time->wasWithinLast('1 second', '-1 year'));
$this->assertTrue($this->Time->wasWithinLast('10 minutes', '-1 second'));
$this->assertTrue($this->Time->wasWithinLast('23 minutes', '-1 minute'));
$this->assertFalse($this->Time->wasWithinLast('0 year', '-1 year'));
$this->assertTrue($this->Time->wasWithinLast('13 month', '-1 month'));
$this->assertTrue($this->Time->wasWithinLast('2 days', '-1 day'));
$this->assertFalse($this->Time->wasWithinLast('1 week', '-2 weeks'));
$this->assertFalse($this->Time->wasWithinLast('1 second', '-2 seconds'));
$this->assertFalse($this->Time->wasWithinLast('1 day', '-2 days'));
$this->assertFalse($this->Time->wasWithinLast('1 hour', '-2 hours'));
$this->assertFalse($this->Time->wasWithinLast('1 month', '-2 months'));
$this->assertFalse($this->Time->wasWithinLast('1 year', '-2 years'));
$this->assertFalse($this->Time->wasWithinLast('1 day', '-2 weeks'));
$this->assertFalse($this->Time->wasWithinLast('1 day', '-2 days'));
$this->assertFalse($this->Time->wasWithinLast('0 days', '-2 days'));
$this->assertTrue($this->Time->wasWithinLast('1 hour', '-20 seconds'));
$this->assertTrue($this->Time->wasWithinLast('1 year', '-60 minutes -30 seconds'));
$this->assertTrue($this->Time->wasWithinLast('3 years', '-2 months'));
$this->assertTrue($this->Time->wasWithinLast('5 months', '-4 months'));
$this->assertTrue($this->Time->wasWithinLast('5 ', '-3 days'));
$this->assertTrue($this->Time->wasWithinLast('1 ', '-1 hour'));
$this->assertTrue($this->Time->wasWithinLast('1 ', '-1 minute'));
$this->assertTrue($this->Time->wasWithinLast('1 ', '-23 hours -59 minutes -59 seconds'));
}
/**
* testUserOffset method
*
* @return void
*/
public function testUserOffset() {
$timezoneServer = new DateTimeZone(date_default_timezone_get());
$timeServer = new DateTime('now', $timezoneServer);
$yourTimezone = $timezoneServer->getOffset($timeServer) / HOUR;
$expected = time();
$result = $this->Time->fromString(time(), $yourTimezone);
$this->assertEqual($expected, $result);
}
/**
* test fromString()
*
* @return void
*/
public function testFromString() {
$result = $this->Time->fromString('');
$this->assertFalse($result);
$result = $this->Time->fromString(0, 0);
$this->assertFalse($result);
$result = $this->Time->fromString('+1 hour');
$expected = strtotime('+1 hour');
$this->assertEqual($expected, $result);
$timezone = date('Z', time());
$result = $this->Time->fromString('+1 hour', $timezone);
$expected = $this->Time->convert(strtotime('+1 hour'), $timezone);
$this->assertEqual($expected, $result);
}
/**
* test converting time specifiers using a time definition localfe file
*
* @return void
*/
public function testConvertSpecifiers() {
App::build(array(
'locales' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Locale' . DS)
), true);
Configure::write('Config.language', 'time_test');
$time = strtotime('Thu Jan 14 11:43:39 2010');
$result = $this->Time->convertSpecifiers('%a', $time);
$expected = 'jue';
$this->assertEqual($expected, $result);
$result = $this->Time->convertSpecifiers('%A', $time);
$expected = 'jueves';
$this->assertEqual($expected, $result);
$result = $this->Time->convertSpecifiers('%c', $time);
$expected = 'jue %d ene %Y %H:%M:%S %Z';
$this->assertEqual($expected, $result);
$result = $this->Time->convertSpecifiers('%C', $time);
$expected = '20';
$this->assertEqual($expected, $result);
$result = $this->Time->convertSpecifiers('%D', $time);
$expected = '%m/%d/%y';
$this->assertEqual($expected, $result);
$result = $this->Time->convertSpecifiers('%b', $time);
$expected = 'ene';
$this->assertEqual($expected, $result);
$result = $this->Time->convertSpecifiers('%h', $time);
$expected = 'ene';
$this->assertEqual($expected, $result);
$result = $this->Time->convertSpecifiers('%B', $time);
$expected = 'enero';
$this->assertEqual($expected, $result);
$result = $this->Time->convertSpecifiers('%n', $time);
$expected = "\n";
$this->assertEqual($expected, $result);
$result = $this->Time->convertSpecifiers('%n', $time);
$expected = "\n";
$this->assertEqual($expected, $result);
$result = $this->Time->convertSpecifiers('%p', $time);
$expected = 'AM';
$this->assertEqual($expected, $result);
$result = $this->Time->convertSpecifiers('%P', $time);
$expected = 'am';
$this->assertEqual($expected, $result);
$result = $this->Time->convertSpecifiers('%r', $time);
$expected = '%I:%M:%S AM';
$this->assertEqual($expected, $result);
$result = $this->Time->convertSpecifiers('%R', $time);
$expected = '11:43';
$this->assertEqual($expected, $result);
$result = $this->Time->convertSpecifiers('%t', $time);
$expected = "\t";
$this->assertEqual($expected, $result);
$result = $this->Time->convertSpecifiers('%T', $time);
$expected = '%H:%M:%S';
$this->assertEqual($expected, $result);
$result = $this->Time->convertSpecifiers('%u', $time);
$expected = 4;
$this->assertEqual($expected, $result);
$result = $this->Time->convertSpecifiers('%x', $time);
$expected = '%d/%m/%y';
$this->assertEqual($expected, $result);
$result = $this->Time->convertSpecifiers('%X', $time);
$expected = '%H:%M:%S';
$this->assertEqual($expected, $result);
}
/**
* test convert %e on windows.
*
* @return void
*/
public function testConvertPercentE() {
$this->skipIf(DIRECTORY_SEPARATOR !== '\\', 'Cannot run windows tests on non-windows OS.');
$time = strtotime('Thu Jan 14 11:43:39 2010');
$result = $this->Time->convertSpecifiers('%e', $time);
$expected = '14';
$this->assertEqual($expected, $result);
$result = $this->Time->convertSpecifiers('%e', strtotime('2011-01-01'));
$expected = ' 1';
$this->assertEqual($expected, $result);
}
/**
* test formatting dates taking in account preferred i18n locale file
*
* @return void
*/
public function testI18nFormat() {
App::build(array(
'locales' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Locale' . DS)
), true);
Configure::write('Config.language', 'time_test');
$time = strtotime('Thu Jan 14 13:59:28 2010');
$result = $this->Time->i18nFormat($time);
$expected = '14/01/10';
$this->assertEqual($expected, $result);
$result = $this->Time->i18nFormat($time, '%c');
$expected = 'jue 14 ene 2010 13:59:28 ' . strftime('%Z', $time);
$this->assertEqual($expected, $result);
$result = $this->Time->i18nFormat($time, 'Time is %r, and date is %x');
$expected = 'Time is 01:59:28 PM, and date is 14/01/10';
$this->assertEqual($expected, $result);
$result = $this->Time->i18nFormat('invalid date', '%x', 'Date invalid');
$expected = 'Date invalid';
$this->assertEqual($expected, $result);
}
/**
* test new format() syntax which inverts first and secod parameters
*
* @return void
*/
public function testFormatNewSyntax() {
$time = time();
$this->assertEqual($this->Time->format($time), $this->Time->i18nFormat($time));
$this->assertEqual($this->Time->format($time, '%c'), $this->Time->i18nFormat($time, '%c'));
}
}
| 0001-bee | trunk/cakephp2/lib/Cake/Test/Case/View/Helper/TimeHelperTest.php | PHP | gpl3 | 27,847 |
<?php
/**
* NumberHelperTest file
*
* PHP 5
*
* CakePHP(tm) Tests <http://book.cakephp.org/view/1196/Testing>
* Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice
*
* @copyright Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://book.cakephp.org/view/1196/Testing CakePHP(tm) Tests
* @package Cake.Test.Case.View.Helper
* @since CakePHP(tm) v 1.2.0.4206
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
App::uses('View', 'View');
App::uses('NumberHelper', 'View/Helper');
/**
* NumberHelperTest class
*
* @package Cake.Test.Case.View.Helper
*/
class NumberHelperTest extends CakeTestCase {
/**
* helper property
*
* @var mixed null
*/
public $helper = null;
/**
* setUp method
*
* @return void
*/
public function setUp() {
parent::setUp();
$view = $this->getMock('View', array(), array(), '', false);
$this->Number = new NumberHelper($view);
}
/**
* tearDown method
*
* @return void
*/
public function tearDown() {
parent::tearDown();
unset($this->Number);
}
/**
* testFormatAndCurrency method
*
* @return void
*/
public function testFormat() {
$value = '100100100';
$result = $this->Number->format($value, '#');
$expected = '#100,100,100';
$this->assertEqual($expected, $result);
$result = $this->Number->format($value, 3);
$expected = '100,100,100.000';
$this->assertEqual($expected, $result);
$result = $this->Number->format($value);
$expected = '100,100,100';
$this->assertEqual($expected, $result);
$result = $this->Number->format($value, '-');
$expected = '100-100-100';
$this->assertEqual($expected, $result);
}
/**
* Test currency method.
*
* @return void
*/
public function testCurrency() {
$value = '100100100';
$result = $this->Number->currency($value);
$expected = '$100,100,100.00';
$this->assertEqual($expected, $result);
$result = $this->Number->currency($value, '#');
$expected = '#100,100,100.00';
$this->assertEqual($expected, $result);
$result = $this->Number->currency($value, false);
$expected = '100,100,100.00';
$this->assertEqual($expected, $result);
$result = $this->Number->currency($value, 'USD');
$expected = '$100,100,100.00';
$this->assertEqual($expected, $result);
$result = $this->Number->currency($value, 'EUR');
$expected = '€100.100.100,00';
$this->assertEqual($expected, $result);
$result = $this->Number->currency($value, 'GBP');
$expected = '£100,100,100.00';
$this->assertEqual($expected, $result);
$result = $this->Number->currency($value, '', array('thousands' =>' ', 'wholeSymbol' => '€', 'wholePosition' => 'after', 'decimals' => ',', 'zero' => 'Gratuit'));
$expected = '100 100 100,00€';
$this->assertEqual($expected, $result);
$result = $this->Number->currency(1000.45, NULL, array('after'=>'øre','before'=>'Kr. ','decimals'=>',','thousands'=>'.'));
$expected = 'Kr. 1.000,45';
$this->assertEqual($expected,$result);
$result = $this->Number->currency(0.5, 'USD');
$expected = '50c';
$this->assertEqual($expected,$result);
$result = $this->Number->currency(0.5, NULL, array('after'=>'øre'));
$expected = '50øre';
$this->assertEqual($expected,$result);
$result = $this->Number->currency(1, null, array('wholeSymbol' => '$ '));
$expected = '$ 1.00';
$this->assertEqual($expected, $result);
$result = $this->Number->currency(1, null, array('wholeSymbol' => ' $', 'wholePosition' => 'after'));
$expected = '1.00 $';
$this->assertEqual($expected, $result);
$result = $this->Number->currency(.2, null, array('wholeSymbol' => ' $', 'wholePosition' => 'after', 'fractionSymbol' => 'cents'));
$expected = '20cents';
$this->assertEqual($expected, $result);
$result = $this->Number->currency(.2, null, array('wholeSymbol' => ' $', 'wholePosition' => 'after', 'fractionSymbol' => 'cents', 'fractionPosition' => 'before'));
$expected = 'cents20';
$this->assertEqual($expected, $result);
$result = $this->Number->currency(311, 'USD', array('wholePosition' => 'after'));
$expected = '311.00$';
$this->assertEqual($expected, $result);
$result = $this->Number->currency(.2, 'EUR');
$expected = '€0,20';
$this->assertEqual($expected, $result);
$result = $this->Number->currency(12, null, array('wholeSymbol' => ' dollars', 'wholePosition' => 'after', 'fractionSymbol' => ' cents', 'fractionPosition' => 'after'));
$expected = '12.00 dollars';
$this->assertEqual($expected, $result);
$result = $this->Number->currency(.12, null, array('wholeSymbol' => ' dollars', 'wholePosition' => 'after', 'fractionSymbol' => ' cents', 'fractionPosition' => 'after'));
$expected = '12 cents';
$this->assertEqual($expected, $result);
$result = $this->Number->currency(.5, null, array('fractionSymbol' => false, 'fractionPosition' => 'before', 'wholeSymbol' => '$'));
$expected = '$0.50';
$this->assertEqual($expected, $result);
}
/**
* Test adding currency format options to the number helper
*
* @return void
*/
public function testCurrencyAddFormat() {
$this->Number->addFormat('NOK', array('before' => 'Kr. '));
$result = $this->Number->currency(1000, 'NOK');
$expected = 'Kr. 1,000.00';
$this->assertEqual($expected,$result);
$this->Number->addFormat('Other', array('before' => '$$ ', 'after' => 'c!'));
$result = $this->Number->currency(0.22, 'Other');
$expected = '22c!';
$this->assertEqual($expected,$result);
$result = $this->Number->currency(-10, 'Other');
$expected = '($$ 10.00)';
$this->assertEqual($expected,$result);
}
/**
* testCurrencyPositive method
*
* @return void
*/
public function testCurrencyPositive() {
$value = '100100100';
$result = $this->Number->currency($value);
$expected = '$100,100,100.00';
$this->assertEqual($expected, $result);
$result = $this->Number->currency($value, 'USD', array('before'=> '#'));
$expected = '#100,100,100.00';
$this->assertEqual($expected, $result);
$result = $this->Number->currency($value, false);
$expected = '100,100,100.00';
$this->assertEqual($expected, $result);
$result = $this->Number->currency($value, 'USD');
$expected = '$100,100,100.00';
$this->assertEqual($expected, $result);
$result = $this->Number->currency($value, 'EUR');
$expected = '€100.100.100,00';
$this->assertEqual($expected, $result);
$result = $this->Number->currency($value, 'GBP');
$expected = '£100,100,100.00';
$this->assertEqual($expected, $result);
}
/**
* testCurrencyNegative method
*
* @return void
*/
public function testCurrencyNegative() {
$value = '-100100100';
$result = $this->Number->currency($value);
$expected = '($100,100,100.00)';
$this->assertEqual($expected, $result);
$result = $this->Number->currency($value, 'EUR');
$expected = '(€100.100.100,00)';
$this->assertEqual($expected, $result);
$result = $this->Number->currency($value, 'GBP');
$expected = '(£100,100,100.00)';
$this->assertEqual($expected, $result);
$result = $this->Number->currency($value, 'USD', array('negative'=>'-'));
$expected = '-$100,100,100.00';
$this->assertEqual($expected, $result);
$result = $this->Number->currency($value, 'EUR', array('negative'=>'-'));
$expected = '-€100.100.100,00';
$this->assertEqual($expected, $result);
$result = $this->Number->currency($value, 'GBP', array('negative'=>'-'));
$expected = '-£100,100,100.00';
$this->assertEqual($expected, $result);
}
/**
* testCurrencyCentsPositive method
*
* @return void
*/
public function testCurrencyCentsPositive() {
$value = '0.99';
$result = $this->Number->currency($value, 'USD');
$expected = '99c';
$this->assertEqual($expected, $result);
$result = $this->Number->currency($value, 'EUR');
$expected = '€0,99';
$this->assertEqual($expected, $result);
$result = $this->Number->currency($value, 'GBP');
$expected = '99p';
$this->assertEqual($expected, $result);
}
/**
* testCurrencyCentsNegative method
*
* @return void
*/
public function testCurrencyCentsNegative() {
$value = '-0.99';
$result = $this->Number->currency($value, 'USD');
$expected = '(99c)';
$this->assertEqual($expected, $result);
$result = $this->Number->currency($value, 'EUR');
$expected = '(€0,99)';
$this->assertEqual($expected, $result);
$result = $this->Number->currency($value, 'GBP');
$expected = '(99p)';
$this->assertEqual($expected, $result);
$result = $this->Number->currency($value, 'USD', array('negative'=>'-'));
$expected = '-99c';
$this->assertEqual($expected, $result);
$result = $this->Number->currency($value, 'EUR', array('negative'=>'-'));
$expected = '-€0,99';
$this->assertEqual($expected, $result);
$result = $this->Number->currency($value, 'GBP', array('negative'=>'-'));
$expected = '-99p';
$this->assertEqual($expected, $result);
}
/**
* testCurrencyZero method
*
* @return void
*/
public function testCurrencyZero() {
$value = '0';
$result = $this->Number->currency($value, 'USD');
$expected = '$0.00';
$this->assertEqual($expected, $result);
$result = $this->Number->currency($value, 'EUR');
$expected = '€0,00';
$this->assertEqual($expected, $result);
$result = $this->Number->currency($value, 'GBP');
$expected = '£0.00';
$this->assertEqual($expected, $result);
$result = $this->Number->currency($value, 'GBP', array('zero' => 'FREE!'));
$expected = 'FREE!';
$this->assertEqual($expected, $result);
}
/**
* testCurrencyOptions method
*
* @return void
*/
public function testCurrencyOptions() {
$value = '1234567.89';
$result = $this->Number->currency($value, null, array('before' => 'GBP'));
$expected = 'GBP1,234,567.89';
$this->assertEqual($expected, $result);
$result = $this->Number->currency($value, 'GBP', array('places' => 0));
$expected = '£1,234,568';
$this->assertEqual($expected, $result);
$result = $this->Number->currency('1234567.8912345', null, array('before' => 'GBP', 'places' => 3));
$expected = 'GBP1,234,567.891';
$this->assertEqual($expected, $result);
$result = $this->Number->currency('650.120001', null, array('before' => 'GBP', 'places' => 4));
$expected = 'GBP650.1200';
$this->assertEqual($expected, $result);
$result = $this->Number->currency($value, 'GBP', array('escape' => true));
$expected = '&#163;1,234,567.89';
$this->assertEqual($expected, $result);
$result = $this->Number->currency('0.35', 'USD', array('after' => false));
$expected = '$0.35';
$this->assertEqual($expected, $result);
$result = $this->Number->currency('0.35', 'GBP', array('after' => false));
$expected = '£0.35';
$this->assertEqual($expected, $result);
$result = $this->Number->currency('0.35', 'GBP');
$expected = '35p';
$this->assertEqual($expected, $result);
$result = $this->Number->currency('0.35', 'EUR');
$expected = '€0,35';
$this->assertEqual($expected, $result);
}
/**
* testToReadableSize method
*
* @return void
*/
public function testToReadableSize() {
$result = $this->Number->toReadableSize(0);
$expected = '0 Bytes';
$this->assertEqual($expected, $result);
$result = $this->Number->toReadableSize(1);
$expected = '1 Byte';
$this->assertEqual($expected, $result);
$result = $this->Number->toReadableSize(45);
$expected = '45 Bytes';
$this->assertEqual($expected, $result);
$result = $this->Number->toReadableSize(1023);
$expected = '1023 Bytes';
$this->assertEqual($expected, $result);
$result = $this->Number->toReadableSize(1024);
$expected = '1 KB';
$this->assertEqual($expected, $result);
$result = $this->Number->toReadableSize(1024*512);
$expected = '512 KB';
$this->assertEqual($expected, $result);
$result = $this->Number->toReadableSize(1024*1024-1);
$expected = '1.00 MB';
$this->assertEqual($expected, $result);
$result = $this->Number->toReadableSize(1024*1024*512);
$expected = '512.00 MB';
$this->assertEqual($expected, $result);
$result = $this->Number->toReadableSize(1024*1024*1024-1);
$expected = '1.00 GB';
$this->assertEqual($expected, $result);
$result = $this->Number->toReadableSize(1024*1024*1024*512);
$expected = '512.00 GB';
$this->assertEqual($expected, $result);
$result = $this->Number->toReadableSize(1024*1024*1024*1024-1);
$expected = '1.00 TB';
$this->assertEqual($expected, $result);
$result = $this->Number->toReadableSize(1024*1024*1024*1024*512);
$expected = '512.00 TB';
$this->assertEqual($expected, $result);
$result = $this->Number->toReadableSize(1024*1024*1024*1024*1024-1);
$expected = '1024.00 TB';
$this->assertEqual($expected, $result);
$result = $this->Number->toReadableSize(1024*1024*1024*1024*1024*1024);
$expected = (1024 * 1024) . '.00 TB';
$this->assertEqual($expected, $result);
}
/**
* testToPercentage method
*
* @return void
*/
public function testToPercentage() {
$result = $this->Number->toPercentage(45, 0);
$expected = '45%';
$this->assertEqual($expected, $result);
$result = $this->Number->toPercentage(45, 2);
$expected = '45.00%';
$this->assertEqual($expected, $result);
$result = $this->Number->toPercentage(0, 0);
$expected = '0%';
$this->assertEqual($expected, $result);
$result = $this->Number->toPercentage(0, 4);
$expected = '0.0000%';
$this->assertEqual($expected, $result);
}
}
| 0001-bee | trunk/cakephp2/lib/Cake/Test/Case/View/Helper/NumberHelperTest.php | PHP | gpl3 | 13,626 |
<?php
/**
* PaginatorHelperTest file
*
* PHP 5
*
* CakePHP(tm) Tests <http://book.cakephp.org/view/1196/Testing>
* Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice
*
* @copyright Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://book.cakephp.org/view/1196/Testing CakePHP(tm) Tests
* @package Cake.Test.Case.View.Helper
* @since CakePHP(tm) v 1.2.0.4206
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
App::uses('View', 'View');
App::uses('HtmlHelper', 'View/Helper');
App::uses('JsHelper', 'View/Helper');
App::uses('PaginatorHelper', 'View/Helper');
App::uses('FormHelper', 'View/Helper');
if (!defined('FULL_BASE_URL')) {
define('FULL_BASE_URL', 'http://cakephp.org');
}
/**
* PaginatorHelperTest class
*
* @package Cake.Test.Case.View.Helper
*/
class PaginatorHelperTest extends CakeTestCase {
/**
* setUp method
*
* @return void
*/
public function setUp() {
$controller = null;
$this->View = new View($controller);
$this->Paginator = new PaginatorHelper($this->View);
$this->Paginator->Js = $this->getMock('PaginatorHelper', array(), array($this->View));
$this->Paginator->request = new CakeRequest(null, false);
$this->Paginator->request->addParams(array(
'paging' => array(
'Article' => array(
'page' => 2,
'current' => 9,
'count' => 62,
'prevPage' => false,
'nextPage' => true,
'pageCount' => 7,
'options' => array(
'page' => 1,
'conditions' => array()
),
'paramType' => 'named'
)
)
));
$this->Paginator->Html = new HtmlHelper($this->View);
Configure::write('Routing.prefixes', array());
Router::reload();
}
/**
* tearDown method
*
* @return void
*/
public function tearDown() {
unset($this->View, $this->Paginator);
}
/**
* testHasPrevious method
*
* @return void
*/
public function testHasPrevious() {
$this->assertIdentical($this->Paginator->hasPrev(), false);
$this->Paginator->request->params['paging']['Article']['prevPage'] = true;
$this->assertIdentical($this->Paginator->hasPrev(), true);
$this->Paginator->request->params['paging']['Article']['prevPage'] = false;
}
/**
* testHasNext method
*
* @return void
*/
public function testHasNext() {
$this->assertIdentical($this->Paginator->hasNext(), true);
$this->Paginator->request->params['paging']['Article']['nextPage'] = false;
$this->assertIdentical($this->Paginator->hasNext(), false);
$this->Paginator->request->params['paging']['Article']['nextPage'] = true;
}
/**
* testDisabledLink method
*
* @return void
*/
public function testDisabledLink() {
$this->Paginator->request->params['paging']['Article']['nextPage'] = false;
$this->Paginator->request->params['paging']['Article']['page'] = 1;
$result = $this->Paginator->next('Next', array(), true);
$expected = '<span class="next">Next</span>';
$this->assertEqual($expected, $result);
$this->Paginator->request->params['paging']['Article']['prevPage'] = false;
$result = $this->Paginator->prev('prev', array('update' => 'theList', 'indicator' => 'loading', 'url' => array('controller' => 'posts')), null, array('class' => 'disabled', 'tag' => 'span'));
$expected = array(
'span' => array('class' => 'disabled'), 'prev', '/span'
);
$this->assertTags($result, $expected);
}
/**
* testSortLinks method
*
* @return void
*/
public function testSortLinks() {
Router::reload();
Router::parse('/');
Router::setRequestInfo(array(
array('plugin' => null, 'controller' => 'accounts', 'action' => 'index', 'pass' => array(), 'url' => array('url' => 'accounts/')),
array('base' => '/officespace', 'here' => '/officespace/accounts/', 'webroot' => '/officespace/')
));
$this->Paginator->options(array('url' => array('param')));
$this->Paginator->request['paging'] = array(
'Article' => array(
'current' => 9,
'count' => 62,
'prevPage' => false,
'nextPage' => true,
'pageCount' => 7,
'options' => array(
'page' => 1,
'order' => array('date' => 'asc'),
'conditions' => array()
),
'paramType' => 'named'
)
);
$result = $this->Paginator->sort('title');
$expected = array(
'a' => array('href' => '/officespace/accounts/index/param/page:1/sort:title/direction:asc'),
'Title',
'/a'
);
$this->assertTags($result, $expected);
$result = $this->Paginator->sort('date');
$expected = array(
'a' => array('href' => '/officespace/accounts/index/param/page:1/sort:date/direction:desc', 'class' => 'asc'),
'Date',
'/a'
);
$this->assertTags($result, $expected);
$result = $this->Paginator->sort('title', 'TestTitle');
$expected = array(
'a' => array('href' => '/officespace/accounts/index/param/page:1/sort:title/direction:asc'),
'TestTitle',
'/a'
);
$this->assertTags($result, $expected);
$result = $this->Paginator->sort('title', array('asc' => 'ascending', 'desc' => 'descending'));
$expected = array(
'a' => array('href' => '/officespace/accounts/index/param/page:1/sort:title/direction:asc'),
'ascending',
'/a'
);
$this->assertTags($result, $expected);
$this->Paginator->request->params['paging']['Article']['options']['sort'] = 'title';
$result = $this->Paginator->sort('title', array('asc' => 'ascending', 'desc' => 'descending'));
$expected = array(
'a' => array('href' => '/officespace/accounts/index/param/page:1/sort:title/direction:desc', 'class' => 'asc'),
'descending',
'/a'
);
$this->assertTags($result, $expected);
$this->Paginator->request->params['paging']['Article']['options']['order'] = array('Article.title' => 'desc');
$this->Paginator->request->params['paging']['Article']['options']['sort'] = null;
$result = $this->Paginator->sort('title');
$this->assertPattern('/\/accounts\/index\/param\/page:1\/sort:title\/direction:asc" class="desc">Title<\/a>$/', $result);
$this->Paginator->request->params['paging']['Article']['options']['order'] = array('Article.title' => 'asc');
$this->Paginator->request->params['paging']['Article']['options']['sort'] = null;
$result = $this->Paginator->sort('title');
$this->assertPattern('/\/accounts\/index\/param\/page:1\/sort:title\/direction:desc" class="asc">Title<\/a>$/', $result);
$this->Paginator->request->params['paging']['Article']['options']['order'] = array('Article.title' => 'desc');
$this->Paginator->request->params['paging']['Article']['options']['sort'] = null;
$result = $this->Paginator->sort('title', 'Title', array('direction' => 'desc'));
$this->assertPattern('/\/accounts\/index\/param\/page:1\/sort:title\/direction:asc" class="desc">Title<\/a>$/', $result);
$this->Paginator->request->params['paging']['Article']['options']['order'] = array('Article.title' => 'desc');
$this->Paginator->request->params['paging']['Article']['options']['sort'] = null;
$result = $this->Paginator->sort('title', 'Title', array('direction' => 'asc'));
$this->assertPattern('/\/accounts\/index\/param\/page:1\/sort:title\/direction:asc" class="desc">Title<\/a>$/', $result);
$this->Paginator->request->params['paging']['Article']['options']['order'] = array('Article.title' => 'asc');
$this->Paginator->request->params['paging']['Article']['options']['sort'] = null;
$result = $this->Paginator->sort('title', 'Title', array('direction' => 'asc'));
$this->assertPattern('/\/accounts\/index\/param\/page:1\/sort:title\/direction:desc" class="asc">Title<\/a>$/', $result);
$this->Paginator->request->params['paging']['Article']['options']['order'] = array('Article.title' => 'asc');
$this->Paginator->request->params['paging']['Article']['options']['sort'] = null;
$result = $this->Paginator->sort('title', 'Title', array('direction' => 'desc'));
$this->assertPattern('/\/accounts\/index\/param\/page:1\/sort:title\/direction:desc" class="asc">Title<\/a>$/', $result);
$this->Paginator->request->params['paging']['Article']['options']['order'] = array('Article.title' => 'asc');
$this->Paginator->request->params['paging']['Article']['options']['sort'] = null;
$result = $this->Paginator->sort('title', 'Title', array('direction' => 'desc', 'class' => 'foo'));
$this->assertPattern('/\/accounts\/index\/param\/page:1\/sort:title\/direction:desc" class="foo asc">Title<\/a>$/', $result);
}
/**
* test that sort() works with virtual field order options.
*
* @return void
*/
public function testSortLinkWithVirtualField() {
Router::setRequestInfo(array(
array('plugin' => null, 'controller' => 'accounts', 'action' => 'index', 'pass' => array(), 'form' => array(), 'url' => array('url' => 'accounts/')),
array('base' => '', 'here' => '/accounts/', 'webroot' => '/')
));
$this->Paginator->request->params['paging']['Article']['options']['order'] = array('full_name' => 'asc');
$result = $this->Paginator->sort('Article.full_name');
$expected = array(
'a' => array('href' => '/accounts/index/page:1/sort:Article.full_name/direction:desc', 'class' => 'asc'),
'Article.full Name',
'/a'
);
$this->assertTags($result, $expected);
$result = $this->Paginator->sort('full_name');
$expected = array(
'a' => array('href' => '/accounts/index/page:1/sort:full_name/direction:desc', 'class' => 'asc'),
'Full Name',
'/a'
);
$this->assertTags($result, $expected);
$this->Paginator->request->params['paging']['Article']['options']['order'] = array('full_name' => 'desc');
$result = $this->Paginator->sort('Article.full_name');
$expected = array(
'a' => array('href' => '/accounts/index/page:1/sort:Article.full_name/direction:asc', 'class' => 'desc'),
'Article.full Name',
'/a'
);
$this->assertTags($result, $expected);
$result = $this->Paginator->sort('full_name');
$expected = array(
'a' => array('href' => '/accounts/index/page:1/sort:full_name/direction:asc', 'class' => 'desc'),
'Full Name',
'/a'
);
$this->assertTags($result, $expected);
}
/**
* testSortLinksUsingDirectionOption method
*
* @return void
*/
public function testSortLinksUsingDirectionOption(){
Router::reload();
Router::parse('/');
Router::setRequestInfo(array(
array('plugin' => null, 'controller' => 'accounts', 'action' => 'index', 'pass' => array(),
'url' => array('url' => 'accounts/', 'mod_rewrite' => 'true')),
array('base' => '/', 'here' => '/accounts/', 'webroot' => '/',)
));
$this->Paginator->options(array('url' => array('param')));
$result = $this->Paginator->sort('title', 'TestTitle', array('direction' => 'desc'));
$expected = array(
'a' => array('href' => '/accounts/index/param/page:1/sort:title/direction:desc'),
'TestTitle',
'/a'
);
$this->assertTags($result, $expected);
$result = $this->Paginator->sort('title', array('asc' => 'ascending', 'desc' => 'descending'), array('direction' => 'desc'));
$expected = array(
'a' => array('href' => '/accounts/index/param/page:1/sort:title/direction:desc'),
'descending',
'/a'
);
$this->assertTags($result, $expected);
}
/**
* testSortLinksUsingDotNotation method
*
* @return void
*/
public function testSortLinksUsingDotNotation() {
Router::reload();
Router::parse('/');
Router::setRequestInfo(array(
array('plugin' => null, 'controller' => 'accounts', 'action' => 'index', 'pass' => array(), 'form' => array(), 'url' => array('url' => 'accounts/', 'mod_rewrite' => 'true'), 'bare' => 0),
array('base' => '/officespace', 'here' => '/officespace/accounts/', 'webroot' => '/officespace/')
));
$this->Paginator->request->params['paging']['Article']['options']['order'] = array('Article.title' => 'desc');
$result = $this->Paginator->sort('Article.title', 'Title');
$expected = array(
'a' => array('href' => '/officespace/accounts/index/page:1/sort:Article.title/direction:asc', 'class' => 'desc'),
'Title',
'/a'
);
$this->assertTags($result, $expected);
$this->Paginator->request->params['paging']['Article']['options']['order'] = array('Article.title' => 'asc');
$result = $this->Paginator->sort('Article.title', 'Title');
$expected = array(
'a' => array('href' => '/officespace/accounts/index/page:1/sort:Article.title/direction:desc', 'class' => 'asc'),
'Title',
'/a'
);
$this->assertTags($result, $expected);
$this->Paginator->request->params['paging']['Article']['options']['order'] = array('Account.title' => 'asc');
$result = $this->Paginator->sort('title');
$expected = array(
'a' => array('href' => '/officespace/accounts/index/page:1/sort:title/direction:asc'),
'Title',
'/a'
);
$this->assertTags($result, $expected);
}
/**
* testSortKey method
*
* @return void
*/
public function testSortKey() {
$result = $this->Paginator->sortKey(null, array(
'order' => array('Article.title' => 'desc'
)));
$this->assertEqual('Article.title', $result);
$result = $this->Paginator->sortKey('Article', array('order' => 'Article.title'));
$this->assertEqual($result, 'Article.title');
$result = $this->Paginator->sortKey('Article', array('sort' => 'Article.title'));
$this->assertEqual($result, 'Article.title');
$result = $this->Paginator->sortKey('Article', array('sort' => 'Article'));
$this->assertEqual($result, 'Article');
}
/**
* testSortDir method
*
* @return void
*/
public function testSortDir() {
$result = $this->Paginator->sortDir();
$expected = 'asc';
$this->assertEqual($expected, $result);
$this->Paginator->request->params['paging']['Article']['options']['order'] = array('Article.title' => 'desc');
$result = $this->Paginator->sortDir();
$expected = 'desc';
$this->assertEqual($expected, $result);
unset($this->Paginator->request->params['paging']['Article']['options']);
$this->Paginator->request->params['paging']['Article']['options']['order'] = array('Article.title' => 'asc');
$result = $this->Paginator->sortDir();
$expected = 'asc';
$this->assertEqual($expected, $result);
unset($this->Paginator->request->params['paging']['Article']['options']);
$this->Paginator->request->params['paging']['Article']['options']['order'] = array('title' => 'desc');
$result = $this->Paginator->sortDir();
$expected = 'desc';
$this->assertEqual($expected, $result);
unset($this->Paginator->request->params['paging']['Article']['options']);
$this->Paginator->request->params['paging']['Article']['options']['order'] = array('title' => 'asc');
$result = $this->Paginator->sortDir();
$expected = 'asc';
$this->assertEqual($expected, $result);
unset($this->Paginator->request->params['paging']['Article']['options']);
$this->Paginator->request->params['paging']['Article']['options']['direction'] = 'asc';
$result = $this->Paginator->sortDir();
$expected = 'asc';
$this->assertEqual($expected, $result);
unset($this->Paginator->request->params['paging']['Article']['options']);
$this->Paginator->request->params['paging']['Article']['options']['direction'] = 'desc';
$result = $this->Paginator->sortDir();
$expected = 'desc';
$this->assertEqual($expected, $result);
unset($this->Paginator->request->params['paging']['Article']['options']);
$result = $this->Paginator->sortDir('Article', array('direction' => 'asc'));
$expected = 'asc';
$this->assertEqual($expected, $result);
$result = $this->Paginator->sortDir('Article', array('direction' => 'desc'));
$expected = 'desc';
$this->assertEqual($expected, $result);
$result = $this->Paginator->sortDir('Article', array('direction' => 'asc'));
$expected = 'asc';
$this->assertEqual($expected, $result);
}
/**
* testSortAdminLinks method
*
* @return void
*/
public function testSortAdminLinks() {
Configure::write('Routing.prefixes', array('admin'));
Router::reload();
Router::setRequestInfo(array(
array('pass' => array(), 'named' => array(), 'controller' => 'users', 'plugin' => null, 'action' => 'admin_index', 'prefix' => 'admin', 'admin' => true, 'url' => array('ext' => 'html', 'url' => 'admin/users')),
array('base' => '', 'here' => '/admin/users', 'webroot' => '/')
));
Router::parse('/admin/users');
$this->Paginator->request->params['paging']['Article']['page'] = 1;
$result = $this->Paginator->next('Next');
$expected = array(
'span' => array('class' => 'next'),
'a' => array('href' => '/admin/users/index/page:2', 'rel' => 'next'),
'Next',
'/a',
'/span'
);
$this->assertTags($result, $expected);
Router::reload();
Router::setRequestInfo(array(
array('plugin' => null, 'controller' => 'test', 'action' => 'admin_index', 'pass' => array(), 'prefix' => 'admin', 'admin' => true, 'url' => array('url' => 'admin/test')),
array('base' => '', 'here' => '/admin/test', 'webroot' => '/')
));
Router::parse('/');
$this->Paginator->options(array('url' => array('param')));
$result = $this->Paginator->sort('title');
$expected = array(
'a' => array('href' => '/admin/test/index/param/page:1/sort:title/direction:asc'),
'Title',
'/a'
);
$this->assertTags($result, $expected);
$this->Paginator->options(array('url' => array('param')));
$result = $this->Paginator->sort('Article.title', 'Title');
$expected = array(
'a' => array('href' => '/admin/test/index/param/page:1/sort:Article.title/direction:asc'),
'Title',
'/a'
);
$this->assertTags($result, $expected);
}
/**
* testUrlGeneration method
*
* @return void
*/
public function testUrlGeneration() {
$result = $this->Paginator->sort('controller');
$expected = array(
'a' => array('href' => '/index/page:1/sort:controller/direction:asc'),
'Controller',
'/a'
);
$this->assertTags($result, $expected);
$result = $this->Paginator->url();
$this->assertEqual($result, '/index/page:1');
$this->Paginator->request->params['paging']['Article']['options']['page'] = 2;
$result = $this->Paginator->url();
$this->assertEqual($result, '/index/page:2');
$options = array('order' => array('Article' => 'desc'));
$result = $this->Paginator->url($options);
$this->assertEqual($result, '/index/page:2/sort:Article/direction:desc');
$this->Paginator->request->params['paging']['Article']['options']['page'] = 3;
$options = array('order' => array('Article.name' => 'desc'));
$result = $this->Paginator->url($options);
$this->assertEqual($result, '/index/page:3/sort:Article.name/direction:desc');
}
/**
* test URL generation with prefix routes
*
* @return void
*/
public function testUrlGenerationWithPrefixes() {
$_back = Configure::read('Routing');
Configure::write('Routing.prefixes', array('members'));
Router::reload();
Router::parse('/');
Router::setRequestInfo( array(
array('controller' => 'posts', 'action' => 'index', 'form' => array(), 'url' => array(), 'plugin' => null),
array('base' => '', 'here' => 'posts/index', 'webroot' => '/')
));
$this->Paginator->request->params['paging']['Article']['options']['page'] = 2;
$this->Paginator->request->params['paging']['Article']['page'] = 2;
$this->Paginator->request->params['paging']['Article']['prevPage'] = true;
$options = array('members' => true);
$result = $this->Paginator->url($options);
$expected = '/members/posts/index/page:2';
$this->assertEqual($expected, $result);
$result = $this->Paginator->sort('name', null, array('url' => $options));
$expected = array(
'a' => array('href' => '/members/posts/index/page:2/sort:name/direction:asc'),
'Name',
'/a'
);
$this->assertTags($result, $expected);
$result = $this->Paginator->next('next', array('url' => $options));
$expected = array(
'span' => array('class' => 'next'),
'a' => array('href' => '/members/posts/index/page:3', 'rel' => 'next'),
'next',
'/a',
'/span'
);
$this->assertTags($result, $expected);
$result = $this->Paginator->prev('prev', array('url' => $options));
$expected = array(
'span' => array('class' => 'prev'),
'a' => array('href' => '/members/posts/index/page:1', 'rel' => 'prev'),
'prev',
'/a',
'/span'
);
$this->assertTags($result, $expected);
$options = array('members' => true, 'controller' => 'posts', 'order' => array('name' => 'desc'));
$result = $this->Paginator->url($options);
$expected = '/members/posts/index/page:2/sort:name/direction:desc';
$this->assertEqual($expected, $result);
$options = array('controller' => 'posts', 'order' => array('Article.name' => 'desc'));
$result = $this->Paginator->url($options);
$expected = '/posts/index/page:2/sort:Article.name/direction:desc';
$this->assertEqual($expected, $result);
Configure::write('Routing', $_back);
}
/**
* testOptions method
*
* @return void
*/
public function testOptions() {
$this->Paginator->options('myDiv');
$this->assertEqual('myDiv', $this->Paginator->options['update']);
$this->Paginator->options = array();
$this->Paginator->request->params = array();
$options = array('paging' => array('Article' => array(
'order' => 'desc',
'sort' => 'title'
)));
$this->Paginator->options($options);
$expected = array('Article' => array(
'order' => 'desc',
'sort' => 'title'
));
$this->assertEqual($expected, $this->Paginator->request->params['paging']);
$this->Paginator->options = array();
$this->Paginator->request->params = array();
$options = array('Article' => array(
'order' => 'desc',
'sort' => 'title'
));
$this->Paginator->options($options);
$this->assertEqual($expected, $this->Paginator->request->params['paging']);
$options = array('paging' => array('Article' => array(
'order' => 'desc',
'sort' => 'Article.title'
)));
$this->Paginator->options($options);
$expected = array('Article' => array(
'order' => 'desc',
'sort' => 'Article.title'
));
$this->assertEqual($expected, $this->Paginator->request->params['paging']);
}
/**
* testPassedArgsMergingWithUrlOptions method
*
* @return void
*/
public function testPassedArgsMergingWithUrlOptions() {
Router::reload();
Router::parse('/');
Router::setRequestInfo(array(
array('plugin' => null, 'controller' => 'articles', 'action' => 'index', 'pass' => array('2'), 'named' => array('foo' => 'bar'), 'url' => array('url' => 'articles/index/2/foo:bar')),
array('base' => '/', 'here' => '/articles/', 'webroot' => '/')
));
$this->Paginator->request->params['paging'] = array(
'Article' => array(
'page' => 1, 'current' => 3, 'count' => 13,
'prevPage' => false, 'nextPage' => true, 'pageCount' => 8,
'options' => array(
'page' => 1,
'order' => array(),
'conditions' => array()
),
'paramType' => 'named'
)
);
$this->Paginator->request->params['pass'] = array(2);
$this->Paginator->request->params['named'] = array('foo' => 'bar');
$this->Paginator->beforeRender('posts/index');
$result = $this->Paginator->sort('title');
$expected = array(
'a' => array('href' => '/articles/index/2/page:1/foo:bar/sort:title/direction:asc'),
'Title',
'/a'
);
$this->assertTags($result, $expected);
$result = $this->Paginator->numbers();
$expected = array(
array('span' => array('class' => 'current')), '1', '/span',
' | ',
array('span' => array()), array('a' => array('href' => '/articles/index/2/page:2/foo:bar')), '2', '/a', '/span',
' | ',
array('span' => array()), array('a' => array('href' => '/articles/index/2/page:3/foo:bar')), '3', '/a', '/span',
' | ',
array('span' => array()), array('a' => array('href' => '/articles/index/2/page:4/foo:bar')), '4', '/a', '/span',
' | ',
array('span' => array()), array('a' => array('href' => '/articles/index/2/page:5/foo:bar')), '5', '/a', '/span',
' | ',
array('span' => array()), array('a' => array('href' => '/articles/index/2/page:6/foo:bar')), '6', '/a', '/span',
' | ',
array('span' => array()), array('a' => array('href' => '/articles/index/2/page:7/foo:bar')), '7', '/a', '/span',
);
$this->assertTags($result, $expected);
$result = $this->Paginator->next('Next');
$expected = array(
'span' => array('class' => 'next'),
'a' => array('href' => '/articles/index/2/page:2/foo:bar', 'rel' => 'next'),
'Next',
'/a',
'/span'
);
$this->assertTags($result, $expected);
}
/**
* testPagingLinks method
*
* @return void
*/
public function testPagingLinks() {
$this->Paginator->request->params['paging'] = array(
'Client' => array(
'page' => 1,
'current' => 3,
'count' => 13,
'prevPage' => false,
'nextPage' => true,
'pageCount' => 5,
'options' => array(
'page' => 1,
),
'paramType' => 'named'
)
);
$result = $this->Paginator->prev('<< Previous', null, null, array('class' => 'disabled'));
$expected = array(
'span' => array('class' => 'disabled'),
'<< Previous',
'/span'
);
$this->assertTags($result, $expected);
$result = $this->Paginator->prev('<< Previous', null, null, array('class' => 'disabled', 'tag' => 'div'));
$expected = array(
'div' => array('class' => 'disabled'),
'<< Previous',
'/div'
);
$this->assertTags($result, $expected);
$this->Paginator->request->params['paging']['Client']['page'] = 2;
$this->Paginator->request->params['paging']['Client']['prevPage'] = true;
$result = $this->Paginator->prev('<< Previous', null, null, array('class' => 'disabled'));
$expected = array(
'span' => array('class' => 'prev'),
'a' => array('href' => '/index/page:1', 'rel' => 'prev'),
'<< Previous',
'/a',
'/span'
);
$this->assertTags($result, $expected);
$result = $this->Paginator->next('Next');
$expected = array(
'span' => array('class' => 'next'),
'a' => array('href' => '/index/page:3', 'rel' => 'next'),
'Next',
'/a',
'/span'
);
$this->assertTags($result, $expected);
$result = $this->Paginator->next('Next', array('tag' => 'li'));
$expected = array(
'li' => array('class' => 'next'),
'a' => array('href' => '/index/page:3', 'rel' => 'next'),
'Next',
'/a',
'/li'
);
$this->assertTags($result, $expected);
$result = $this->Paginator->prev('<< Previous', array('escape' => true));
$expected = array(
'span' => array('class' => 'prev'),
'a' => array('href' => '/index/page:1', 'rel' => 'prev'),
'<< Previous',
'/a',
'/span'
);
$this->assertTags($result, $expected);
$result = $this->Paginator->prev('<< Previous', array('escape' => false));
$expected = array(
'span' => array('class' => 'prev'),
'a' => array('href' => '/index/page:1', 'rel' => 'prev'),
'preg:/<< Previous/',
'/a',
'/span'
);
$this->assertTags($result, $expected);
$this->Paginator->request->params['paging'] = array(
'Client' => array(
'page' => 1,
'current' => 1,
'count' => 13,
'prevPage' => false,
'nextPage' => true,
'pageCount' => 5,
'options' => array(
'page' => 1,
),
'paramType' => 'named'
)
);
$result = $this->Paginator->prev('<< Previous', null, '<strong>Disabled</strong>');
$expected = array(
'span' => array('class' => 'prev'),
'<strong>Disabled</strong>',
'/span'
);
$this->assertTags($result, $expected);
$result = $this->Paginator->prev('<< Previous', null, '<strong>Disabled</strong>', array('escape' => true));
$expected = array(
'span' => array('class' => 'prev'),
'<strong>Disabled</strong>',
'/span'
);
$this->assertTags($result, $expected);
$result = $this->Paginator->prev('<< Previous', null, '<strong>Disabled</strong>', array('escape' => false));
$expected = array(
'span' => array('class' => 'prev'),
'<strong', 'Disabled', '/strong',
'/span'
);
$this->assertTags($result, $expected);
$this->Paginator->request->params['paging'] = array(
'Client' => array(
'page' => 1,
'current' => 3,
'count' => 13,
'prevPage' => false,
'nextPage' => true,
'pageCount' => 5,
'options' => array(
'page' => 1,
'limit' => 3,
'order' => array('Client.name' => 'DESC'),
),
'paramType' => 'named'
)
);
$this->Paginator->request->params['paging']['Client']['page'] = 2;
$this->Paginator->request->params['paging']['Client']['prevPage'] = true;
$result = $this->Paginator->prev('<< Previous', null, null, array('class' => 'disabled'));
$expected = array(
'span' => array('class' => 'prev'),
'a' => array(
'href' => '/index/page:1/limit:3/sort:Client.name/direction:DESC',
'rel' => 'prev'
),
'<< Previous',
'/a',
'/span'
);
$this->assertTags($result, $expected);
$result = $this->Paginator->next('Next');
$expected = array(
'span' => array('class' => 'next'),
'a' => array(
'href' => '/index/page:3/limit:3/sort:Client.name/direction:DESC',
'rel' => 'next'
),
'Next',
'/a',
'/span'
);
$this->assertTags($result, $expected);
$this->Paginator->request->params['paging'] = array(
'Client' => array(
'page' => 2,
'current' => 1,
'count' => 13,
'prevPage' => true,
'nextPage' => false,
'pageCount' => 2,
'options' => array(
'page' => 2,
'limit' => 10,
'order' => array(),
'conditions' => array()
),
'paramType' => 'named'
)
);
$result = $this->Paginator->prev('Prev');
$expected = array(
'span' => array('class' => 'prev'),
'a' => array('href' => '/index/page:1/limit:10', 'rel' => 'prev'),
'Prev',
'/a',
'/span'
);
$this->assertTags($result, $expected);
$this->Paginator->request->params['paging'] = array(
'Client' => array(
'page' => 2, 'current' => 1, 'count' => 13, 'prevPage' => true,
'nextPage' => false, 'pageCount' => 2,
'defaults' => array(),
'options' => array(
'page' => 2, 'limit' => 10, 'order' => array(), 'conditions' => array()
),
'paramType' => 'named'
)
);
$this->Paginator->options(array('url' => array(12, 'page' => 3)));
$result = $this->Paginator->prev('Prev', array('url' => array('foo' => 'bar')));
$expected = array(
'span' => array('class' => 'prev'),
'a' => array('href' => '/index/12/page:1/limit:10/foo:bar', 'rel' => 'prev'),
'Prev',
'/a',
'/span'
);
$this->assertTags($result, $expected);
}
/**
* test that __pagingLink methods use $options when $disabledOptions is an empty value.
* allowing you to use shortcut syntax
*
* @return void
*/
public function testPagingLinksOptionsReplaceEmptyDisabledOptions() {
$this->Paginator->request->params['paging'] = array(
'Client' => array(
'page' => 1,
'current' => 3,
'count' => 13,
'prevPage' => false,
'nextPage' => true,
'pageCount' => 5,
'options' => array(
'page' => 1,
),
'paramType' => 'named'
)
);
$result = $this->Paginator->prev('<< Previous', array('escape' => false));
$expected = array(
'span' => array('class' => 'prev'),
'preg:/<< Previous/',
'/span'
);
$this->assertTags($result, $expected);
$result = $this->Paginator->next('Next >>', array('escape' => false));
$expected = array(
'span' => array('class' => 'next'),
'a' => array('href' => '/index/page:2', 'rel' => 'next'),
'preg:/Next >>/',
'/a',
'/span'
);
$this->assertTags($result, $expected);
}
/**
* testPagingLinksNotDefaultModel
*
* Test the creation of paging links when the non default model is used.
*
* @return void
*/
public function testPagingLinksNotDefaultModel() {
// Multiple Model Paginate
$this->Paginator->request->params['paging'] = array(
'Client' => array(
'page' => 1,
'current' => 3,
'count' => 13,
'prevPage' => false,
'nextPage' => true,
'pageCount' => 5,
'options' => array(
'page' => 1,
),
'paramType' => 'named'
),
'Server' => array(
'page' => 1,
'current' => 1,
'count' => 5,
'prevPage' => false,
'nextPage' => false,
'pageCount' => 5,
'options' => array(
'page' => 1,
),
'paramType' => 'named'
)
);
$result = $this->Paginator->next('Next', array('model' => 'Client'));
$expected = array(
'span' => array('class' => 'next'),
'a' => array('href' => '/index/page:2', 'rel' => 'next'),
'Next',
'/a',
'/span'
);
$this->assertTags($result, $expected);
$result = $this->Paginator->next('Next', array('model' => 'Server'), 'No Next', array('model' => 'Server'));
$expected = array(
'span' => array('class' => 'next'), 'No Next', '/span'
);
$this->assertTags($result, $expected);
}
/**
* testGenericLinks method
*
* @return void
*/
public function testGenericLinks() {
$result = $this->Paginator->link('Sort by title on page 5', array('sort' => 'title', 'page' => 5, 'direction' => 'desc'));
$expected = array(
'a' => array('href' => '/index/page:5/sort:title/direction:desc'),
'Sort by title on page 5',
'/a'
);
$this->assertTags($result, $expected);
$this->Paginator->request->params['paging']['Article']['options']['page'] = 2;
$result = $this->Paginator->link('Sort by title', array('sort' => 'title', 'direction' => 'desc'));
$expected = array(
'a' => array('href' => '/index/page:2/sort:title/direction:desc'),
'Sort by title',
'/a'
);
$this->assertTags($result, $expected);
$this->Paginator->request->params['paging']['Article']['options']['page'] = 4;
$result = $this->Paginator->link('Sort by title on page 4', array('sort' => 'Article.title', 'direction' => 'desc'));
$expected = array(
'a' => array('href' => '/index/page:4/sort:Article.title/direction:desc'),
'Sort by title on page 4',
'/a'
);
$this->assertTags($result, $expected);
}
/**
* Tests generation of generic links with preset options
*
* @return void
*/
public function testGenericLinksWithPresetOptions() {
$result = $this->Paginator->link('Foo!', array('page' => 1));
$this->assertTags($result, array('a' => array('href' => '/index/page:1'), 'Foo!', '/a'));
$this->Paginator->options(array('sort' => 'title', 'direction' => 'desc'));
$result = $this->Paginator->link('Foo!', array('page' => 1));
$this->assertTags($result, array(
'a' => array(
'href' => '/index/page:1',
'sort' => 'title',
'direction' => 'desc'
),
'Foo!',
'/a'
));
$this->Paginator->options(array('sort' => null, 'direction' => null));
$result = $this->Paginator->link('Foo!', array('page' => 1));
$this->assertTags($result, array('a' => array('href' => '/index/page:1'), 'Foo!', '/a'));
$this->Paginator->options(array('url' => array(
'sort' => 'title',
'direction' => 'desc'
)));
$result = $this->Paginator->link('Foo!', array('page' => 1));
$this->assertTags($result, array(
'a' => array('href' => '/index/page:1/sort:title/direction:desc'),
'Foo!',
'/a'
));
}
/**
* testNumbers method
*
* @return void
*/
public function testNumbers() {
$this->Paginator->request->params['paging'] = array(
'Client' => array(
'page' => 8,
'current' => 3,
'count' => 30,
'prevPage' => false,
'nextPage' => 2,
'pageCount' => 15,
'options' => array(
'page' => 1,
),
'paramType' => 'named'
)
);
$result = $this->Paginator->numbers();
$expected = array(
array('span' => array()), array('a' => array('href' => '/index/page:4')), '4', '/a', '/span',
' | ',
array('span' => array()), array('a' => array('href' => '/index/page:5')), '5', '/a', '/span',
' | ',
array('span' => array()), array('a' => array('href' => '/index/page:6')), '6', '/a', '/span',
' | ',
array('span' => array()), array('a' => array('href' => '/index/page:7')), '7', '/a', '/span',
' | ',
array('span' => array('class' => 'current')), '8', '/span',
' | ',
array('span' => array()), array('a' => array('href' => '/index/page:9')), '9', '/a', '/span',
' | ',
array('span' => array()), array('a' => array('href' => '/index/page:10')), '10', '/a', '/span',
' | ',
array('span' => array()), array('a' => array('href' => '/index/page:11')), '11', '/a', '/span',
' | ',
array('span' => array()), array('a' => array('href' => '/index/page:12')), '12', '/a', '/span',
);
$this->assertTags($result, $expected);
$result = $this->Paginator->numbers(array('tag' => 'li'));
$expected = array(
array('li' => array()), array('a' => array('href' => '/index/page:4')), '4', '/a', '/li',
' | ',
array('li' => array()), array('a' => array('href' => '/index/page:5')), '5', '/a', '/li',
' | ',
array('li' => array()), array('a' => array('href' => '/index/page:6')), '6', '/a', '/li',
' | ',
array('li' => array()), array('a' => array('href' => '/index/page:7')), '7', '/a', '/li',
' | ',
array('li' => array('class' => 'current')), '8', '/li',
' | ',
array('li' => array()), array('a' => array('href' => '/index/page:9')), '9', '/a', '/li',
' | ',
array('li' => array()), array('a' => array('href' => '/index/page:10')), '10', '/a', '/li',
' | ',
array('li' => array()), array('a' => array('href' => '/index/page:11')), '11', '/a', '/li',
' | ',
array('li' => array()), array('a' => array('href' => '/index/page:12')), '12', '/a', '/li',
);
$this->assertTags($result, $expected);
$result = $this->Paginator->numbers(array('tag' => 'li', 'separator' => false));
$expected = array(
array('li' => array()), array('a' => array('href' => '/index/page:4')), '4', '/a', '/li',
array('li' => array()), array('a' => array('href' => '/index/page:5')), '5', '/a', '/li',
array('li' => array()), array('a' => array('href' => '/index/page:6')), '6', '/a', '/li',
array('li' => array()), array('a' => array('href' => '/index/page:7')), '7', '/a', '/li',
array('li' => array('class' => 'current')), '8', '/li',
array('li' => array()), array('a' => array('href' => '/index/page:9')), '9', '/a', '/li',
array('li' => array()), array('a' => array('href' => '/index/page:10')), '10', '/a', '/li',
array('li' => array()), array('a' => array('href' => '/index/page:11')), '11', '/a', '/li',
array('li' => array()), array('a' => array('href' => '/index/page:12')), '12', '/a', '/li',
);
$this->assertTags($result, $expected);
$result = $this->Paginator->numbers(true);
$expected = array(
array('span' => array()), array('a' => array('href' => '/index/page:1', 'rel' => 'first')), 'first', '/a', '/span',
' | ',
array('span' => array()), array('a' => array('href' => '/index/page:4')), '4', '/a', '/span',
' | ',
array('span' => array()), array('a' => array('href' => '/index/page:5')), '5', '/a', '/span',
' | ',
array('span' => array()), array('a' => array('href' => '/index/page:6')), '6', '/a', '/span',
' | ',
array('span' => array()), array('a' => array('href' => '/index/page:7')), '7', '/a', '/span',
' | ',
array('span' => array('class' => 'current')), '8', '/span',
' | ',
array('span' => array()), array('a' => array('href' => '/index/page:9')), '9', '/a', '/span',
' | ',
array('span' => array()), array('a' => array('href' => '/index/page:10')), '10', '/a', '/span',
' | ',
array('span' => array()), array('a' => array('href' => '/index/page:11')), '11', '/a', '/span',
' | ',
array('span' => array()), array('a' => array('href' => '/index/page:12')), '12', '/a', '/span',
' | ',
array('span' => array()), array('a' => array('href' => '/index/page:15', 'rel' => 'last')), 'last', '/a', '/span',
);
$this->assertTags($result, $expected);
$this->Paginator->request->params['paging'] = array(
'Client' => array(
'page' => 1,
'current' => 3,
'count' => 30,
'prevPage' => false,
'nextPage' => 2,
'pageCount' => 15,
'options' => array(
'page' => 1,
),
'paramType' => 'named'
)
);
$result = $this->Paginator->numbers();
$expected = array(
array('span' => array('class' => 'current')), '1', '/span',
' | ',
array('span' => array()), array('a' => array('href' => '/index/page:2')), '2', '/a', '/span',
' | ',
array('span' => array()), array('a' => array('href' => '/index/page:3')), '3', '/a', '/span',
' | ',
array('span' => array()), array('a' => array('href' => '/index/page:4')), '4', '/a', '/span',
' | ',
array('span' => array()), array('a' => array('href' => '/index/page:5')), '5', '/a', '/span',
' | ',
array('span' => array()), array('a' => array('href' => '/index/page:6')), '6', '/a', '/span',
' | ',
array('span' => array()), array('a' => array('href' => '/index/page:7')), '7', '/a', '/span',
' | ',
array('span' => array()), array('a' => array('href' => '/index/page:8')), '8', '/a', '/span',
' | ',
array('span' => array()), array('a' => array('href' => '/index/page:9')), '9', '/a', '/span',
);
$this->assertTags($result, $expected);
$this->Paginator->request->params['paging'] = array(
'Client' => array(
'page' => 14,
'current' => 3,
'count' => 30,
'prevPage' => false,
'nextPage' => 2,
'pageCount' => 15,
'options' => array(
'page' => 1,
),
'paramType' => 'named'
)
);
$result = $this->Paginator->numbers();
$expected = array(
array('span' => array()), array('a' => array('href' => '/index/page:7')), '7', '/a', '/span',
' | ',
array('span' => array()), array('a' => array('href' => '/index/page:8')), '8', '/a', '/span',
' | ',
array('span' => array()), array('a' => array('href' => '/index/page:9')), '9', '/a', '/span',
' | ',
array('span' => array()), array('a' => array('href' => '/index/page:10')), '10', '/a', '/span',
' | ',
array('span' => array()), array('a' => array('href' => '/index/page:11')), '11', '/a', '/span',
' | ',
array('span' => array()), array('a' => array('href' => '/index/page:12')), '12', '/a', '/span',
' | ',
array('span' => array()), array('a' => array('href' => '/index/page:13')), '13', '/a', '/span',
' | ',
array('span' => array('class' => 'current')), '14', '/span',
' | ',
array('span' => array()), array('a' => array('href' => '/index/page:15')), '15', '/a', '/span',
);
$this->assertTags($result, $expected);
$this->Paginator->request->params['paging'] = array(
'Client' => array(
'page' => 2,
'current' => 3,
'count' => 27,
'prevPage' => false,
'nextPage' => 2,
'pageCount' => 9,
'options' => array(
'page' => 1,
),
'paramType' => 'named'
)
);
$result = $this->Paginator->numbers(array('first' => 1, 'class' => 'page-link'));
$expected = array(
array('span' => array('class' => 'page-link')), array('a' => array('href' => '/index/page:1')), '1', '/a', '/span',
' | ',
array('span' => array('class' => 'current page-link')), '2', '/span',
' | ',
array('span' => array('class' => 'page-link')), array('a' => array('href' => '/index/page:3')), '3', '/a', '/span',
' | ',
array('span' => array('class' => 'page-link')), array('a' => array('href' => '/index/page:4')), '4', '/a', '/span',
' | ',
array('span' => array('class' => 'page-link')), array('a' => array('href' => '/index/page:5')), '5', '/a', '/span',
' | ',
array('span' => array('class' => 'page-link')), array('a' => array('href' => '/index/page:6')), '6', '/a', '/span',
' | ',
array('span' => array('class' => 'page-link')), array('a' => array('href' => '/index/page:7')), '7', '/a', '/span',
' | ',
array('span' => array('class' => 'page-link')), array('a' => array('href' => '/index/page:8')), '8', '/a', '/span',
' | ',
array('span' => array('class' => 'page-link')), array('a' => array('href' => '/index/page:9')), '9', '/a', '/span',
);
$this->assertTags($result, $expected);
$result = $this->Paginator->numbers(array('last' => 1));
$expected = array(
array('span' => array()), array('a' => array('href' => '/index/page:1')), '1', '/a', '/span',
' | ',
array('span' => array('class' => 'current')), '2', '/span',
' | ',
array('span' => array()), array('a' => array('href' => '/index/page:3')), '3', '/a', '/span',
' | ',
array('span' => array()), array('a' => array('href' => '/index/page:4')), '4', '/a', '/span',
' | ',
array('span' => array()), array('a' => array('href' => '/index/page:5')), '5', '/a', '/span',
' | ',
array('span' => array()), array('a' => array('href' => '/index/page:6')), '6', '/a', '/span',
' | ',
array('span' => array()), array('a' => array('href' => '/index/page:7')), '7', '/a', '/span',
' | ',
array('span' => array()), array('a' => array('href' => '/index/page:8')), '8', '/a', '/span',
' | ',
array('span' => array()), array('a' => array('href' => '/index/page:9')), '9', '/a', '/span',
);
$this->assertTags($result, $expected);
$this->Paginator->request->params['paging'] = array(
'Client' => array(
'page' => 15,
'current' => 3,
'count' => 30,
'prevPage' => false,
'nextPage' => 2,
'pageCount' => 15,
'options' => array(
'page' => 1,
),
'paramType' => 'named'
)
);
$result = $this->Paginator->numbers(array('first' => 1));
$expected = array(
array('span' => array()), array('a' => array('href' => '/index/page:1')), '1', '/a', '/span',
'...',
array('span' => array()), array('a' => array('href' => '/index/page:7')), '7', '/a', '/span',
' | ',
array('span' => array()), array('a' => array('href' => '/index/page:8')), '8', '/a', '/span',
' | ',
array('span' => array()), array('a' => array('href' => '/index/page:9')), '9', '/a', '/span',
' | ',
array('span' => array()), array('a' => array('href' => '/index/page:10')), '10', '/a', '/span',
' | ',
array('span' => array()), array('a' => array('href' => '/index/page:11')), '11', '/a', '/span',
' | ',
array('span' => array()), array('a' => array('href' => '/index/page:12')), '12', '/a', '/span',
' | ',
array('span' => array()), array('a' => array('href' => '/index/page:13')), '13', '/a', '/span',
' | ',
array('span' => array()), array('a' => array('href' => '/index/page:14')), '14', '/a', '/span',
' | ',
array('span' => array('class' => 'current')), '15', '/span',
);
$this->assertTags($result, $expected);
$this->Paginator->request->params['paging'] = array(
'Client' => array(
'page' => 10,
'current' => 3,
'count' => 30,
'prevPage' => false,
'nextPage' => 2,
'pageCount' => 15,
'options' => array(
'page' => 1,
),
'paramType' => 'named'
)
);
$result = $this->Paginator->numbers(array('first' => 1, 'last' => 1));
$expected = array(
array('span' => array()), array('a' => array('href' => '/index/page:1')), '1', '/a', '/span',
'...',
array('span' => array()), array('a' => array('href' => '/index/page:6')), '6', '/a', '/span',
' | ',
array('span' => array()), array('a' => array('href' => '/index/page:7')), '7', '/a', '/span',
' | ',
array('span' => array()), array('a' => array('href' => '/index/page:8')), '8', '/a', '/span',
' | ',
array('span' => array()), array('a' => array('href' => '/index/page:9')), '9', '/a', '/span',
' | ',
array('span' => array('class' => 'current')), '10', '/span',
' | ',
array('span' => array()), array('a' => array('href' => '/index/page:11')), '11', '/a', '/span',
' | ',
array('span' => array()), array('a' => array('href' => '/index/page:12')), '12', '/a', '/span',
' | ',
array('span' => array()), array('a' => array('href' => '/index/page:13')), '13', '/a', '/span',
' | ',
array('span' => array()), array('a' => array('href' => '/index/page:14')), '14', '/a', '/span',
' | ',
array('span' => array()), array('a' => array('href' => '/index/page:15')), '15', '/a', '/span',
);
$this->assertTags($result, $expected);
$this->Paginator->request->params['paging'] = array(
'Client' => array(
'page' => 6,
'current' => 15,
'count' => 623,
'prevPage' => 1,
'nextPage' => 1,
'pageCount' => 42,
'options' => array(
'page' => 6,
),
'paramType' => 'named'
)
);
$result = $this->Paginator->numbers(array('first' => 1, 'last' => 1));
$expected = array(
array('span' => array()), array('a' => array('href' => '/index/page:1')), '1', '/a', '/span',
' | ',
array('span' => array()), array('a' => array('href' => '/index/page:2')), '2', '/a', '/span',
' | ',
array('span' => array()), array('a' => array('href' => '/index/page:3')), '3', '/a', '/span',
' | ',
array('span' => array()), array('a' => array('href' => '/index/page:4')), '4', '/a', '/span',
' | ',
array('span' => array()), array('a' => array('href' => '/index/page:5')), '5', '/a', '/span',
' | ',
array('span' => array('class' => 'current')), '6', '/span',
' | ',
array('span' => array()), array('a' => array('href' => '/index/page:7')), '7', '/a', '/span',
' | ',
array('span' => array()), array('a' => array('href' => '/index/page:8')), '8', '/a', '/span',
' | ',
array('span' => array()), array('a' => array('href' => '/index/page:9')), '9', '/a', '/span',
' | ',
array('span' => array()), array('a' => array('href' => '/index/page:10')), '10', '/a', '/span',
'...',
array('span' => array()), array('a' => array('href' => '/index/page:42')), '42', '/a', '/span',
);
$this->assertTags($result, $expected);
$this->Paginator->request->params['paging'] = array(
'Client' => array(
'page' => 37,
'current' => 15,
'count' => 623,
'prevPage' => 1,
'nextPage' => 1,
'pageCount' => 42,
'options' => array(
'page' => 37,
),
'paramType' => 'named'
)
);
$result = $this->Paginator->numbers(array('first' => 1, 'last' => 1));
$expected = array(
array('span' => array()), array('a' => array('href' => '/index/page:1')), '1', '/a', '/span',
'...',
array('span' => array()), array('a' => array('href' => '/index/page:33')), '33', '/a', '/span',
' | ',
array('span' => array()), array('a' => array('href' => '/index/page:34')), '34', '/a', '/span',
' | ',
array('span' => array()), array('a' => array('href' => '/index/page:35')), '35', '/a', '/span',
' | ',
array('span' => array()), array('a' => array('href' => '/index/page:36')), '36', '/a', '/span',
' | ',
array('span' => array('class' => 'current')), '37', '/span',
' | ',
array('span' => array()), array('a' => array('href' => '/index/page:38')), '38', '/a', '/span',
' | ',
array('span' => array()), array('a' => array('href' => '/index/page:39')), '39', '/a', '/span',
' | ',
array('span' => array()), array('a' => array('href' => '/index/page:40')), '40', '/a', '/span',
' | ',
array('span' => array()), array('a' => array('href' => '/index/page:41')), '41', '/a', '/span',
' | ',
array('span' => array()), array('a' => array('href' => '/index/page:42')), '42', '/a', '/span',
);
$this->assertTags($result, $expected);
$this->Paginator->request->params['paging'] = array(
'Client' => array(
'page' => 1,
'current' => 10,
'count' => 30,
'prevPage' => false,
'nextPage' => 2,
'pageCount' => 3,
'options' => array(
'page' => 1,
),
'paramType' => 'named'
)
);
$options = array('modulus' => 10);
$result = $this->Paginator->numbers($options);
$expected = array(
array('span' => array('class' => 'current')), '1', '/span',
' | ',
array('span' => array()), array('a' => array('href' => '/index/page:2')), '2', '/a', '/span',
' | ',
array('span' => array()), array('a' => array('href' => '/index/page:3')), '3', '/a', '/span',
);
$this->assertTags($result, $expected);
$this->Paginator->request->params['paging'] = array(
'Client' => array(
'page' => 2,
'current' => 10,
'count' => 31,
'prevPage' => true,
'nextPage' => true,
'pageCount' => 4,
'options' => array(
'page' => 1,
'order' => array('Client.name' => 'DESC'),
),
'paramType' => 'named'
)
);
$result = $this->Paginator->numbers(array('class' => 'page-link'));
$expected = array(
array('span' => array('class' => 'page-link')), array('a' => array('href' => '/index/page:1/sort:Client.name/direction:DESC')), '1', '/a', '/span',
' | ',
array('span' => array('class' => 'current page-link')), '2', '/span',
' | ',
array('span' => array('class' => 'page-link')), array('a' => array('href' => '/index/page:3/sort:Client.name/direction:DESC')), '3', '/a', '/span',
' | ',
array('span' => array('class' => 'page-link')), array('a' => array('href' => '/index/page:4/sort:Client.name/direction:DESC')), '4', '/a', '/span',
);
$this->assertTags($result, $expected);
$this->Paginator->request->params['paging'] = array(
'Client' => array(
'page' => 4895,
'current' => 10,
'count' => 48962,
'prevPage' => 1,
'nextPage' => 1,
'pageCount' => 4897,
'options' => array(
'page' => 4894,
),
'paramType' => 'named'
)
);
$result = $this->Paginator->numbers(array('first' => 2, 'modulus' => 2, 'last' => 2));
$expected = array(
array('span' => array()), array('a' => array('href' => '/index/page:1')), '1', '/a', '/span',
' | ',
array('span' => array()), array('a' => array('href' => '/index/page:2')), '2', '/a', '/span',
'...',
array('span' => array()), array('a' => array('href' => '/index/page:4894')), '4894', '/a', '/span',
' | ',
array('span' => array('class' => 'current')), '4895', '/span',
' | ',
array('span' => array()), array('a' => array('href' => '/index/page:4896')), '4896', '/a', '/span',
' | ',
array('span' => array()), array('a' => array('href' => '/index/page:4897')), '4897', '/a', '/span',
);
$this->assertTags($result, $expected);
$this->Paginator->request->params['paging']['Client']['page'] = 3;
$result = $this->Paginator->numbers(array('first' => 2, 'modulus' => 2, 'last' => 2));
$expected = array(
array('span' => array()), array('a' => array('href' => '/index/page:1')), '1', '/a', '/span',
' | ',
array('span' => array()), array('a' => array('href' => '/index/page:2')), '2', '/a', '/span',
' | ',
array('span' => array('class' => 'current')), '3', '/span',
' | ',
array('span' => array()), array('a' => array('href' => '/index/page:4')), '4', '/a', '/span',
'...',
array('span' => array()), array('a' => array('href' => '/index/page:4896')), '4896', '/a', '/span',
' | ',
array('span' => array()), array('a' => array('href' => '/index/page:4897')), '4897', '/a', '/span',
);
$this->assertTags($result, $expected);
$result = $this->Paginator->numbers(array('first' => 2, 'modulus' => 2, 'last' => 2, 'separator' => ' - '));
$expected = array(
array('span' => array()), array('a' => array('href' => '/index/page:1')), '1', '/a', '/span',
' - ',
array('span' => array()), array('a' => array('href' => '/index/page:2')), '2', '/a', '/span',
' - ',
array('span' => array('class' => 'current')), '3', '/span',
' - ',
array('span' => array()), array('a' => array('href' => '/index/page:4')), '4', '/a', '/span',
'...',
array('span' => array()), array('a' => array('href' => '/index/page:4896')), '4896', '/a', '/span',
' - ',
array('span' => array()), array('a' => array('href' => '/index/page:4897')), '4897', '/a', '/span',
);
$this->assertTags($result, $expected);
$result = $this->Paginator->numbers(array('first' => 5, 'modulus' => 5, 'last' => 5, 'separator' => ' - '));
$expected = array(
array('span' => array()), array('a' => array('href' => '/index/page:1')), '1', '/a', '/span',
' - ',
array('span' => array()), array('a' => array('href' => '/index/page:2')), '2', '/a', '/span',
' - ',
array('span' => array('class' => 'current')), '3', '/span',
' - ',
array('span' => array()), array('a' => array('href' => '/index/page:4')), '4', '/a', '/span',
' - ',
array('span' => array()), array('a' => array('href' => '/index/page:5')), '5', '/a', '/span',
' - ',
array('span' => array()), array('a' => array('href' => '/index/page:6')), '6', '/a', '/span',
'...',
array('span' => array()), array('a' => array('href' => '/index/page:4893')), '4893', '/a', '/span',
' - ',
array('span' => array()), array('a' => array('href' => '/index/page:4894')), '4894', '/a', '/span',
' - ',
array('span' => array()), array('a' => array('href' => '/index/page:4895')), '4895', '/a', '/span',
' - ',
array('span' => array()), array('a' => array('href' => '/index/page:4896')), '4896', '/a', '/span',
' - ',
array('span' => array()), array('a' => array('href' => '/index/page:4897')), '4897', '/a', '/span',
);
$this->assertTags($result, $expected);
$this->Paginator->request->params['paging']['Client']['page'] = 4893;
$result = $this->Paginator->numbers(array('first' => 5, 'modulus' => 4, 'last' => 5, 'separator' => ' - '));
$expected = array(
array('span' => array()), array('a' => array('href' => '/index/page:1')), '1', '/a', '/span',
' - ',
array('span' => array()), array('a' => array('href' => '/index/page:2')), '2', '/a', '/span',
' - ',
array('span' => array()), array('a' => array('href' => '/index/page:3')), '3', '/a', '/span',
' - ',
array('span' => array()), array('a' => array('href' => '/index/page:4')), '4', '/a', '/span',
' - ',
array('span' => array()), array('a' => array('href' => '/index/page:5')), '5', '/a', '/span',
'...',
array('span' => array()), array('a' => array('href' => '/index/page:4891')), '4891', '/a', '/span',
' - ',
array('span' => array()), array('a' => array('href' => '/index/page:4892')), '4892', '/a', '/span',
' - ',
array('span' => array('class' => 'current')), '4893', '/span',
' - ',
array('span' => array()), array('a' => array('href' => '/index/page:4894')), '4894', '/a', '/span',
' - ',
array('span' => array()), array('a' => array('href' => '/index/page:4895')), '4895', '/a', '/span',
' - ',
array('span' => array()), array('a' => array('href' => '/index/page:4896')), '4896', '/a', '/span',
' - ',
array('span' => array()), array('a' => array('href' => '/index/page:4897')), '4897', '/a', '/span',
);
$this->assertTags($result, $expected);
$this->Paginator->request->params['paging']['Client']['page'] = 58;
$result = $this->Paginator->numbers(array('first' => 5, 'modulus' => 4, 'last' => 5, 'separator' => ' - '));
$expected = array(
array('span' => array()), array('a' => array('href' => '/index/page:1')), '1', '/a', '/span',
' - ',
array('span' => array()), array('a' => array('href' => '/index/page:2')), '2', '/a', '/span',
' - ',
array('span' => array()), array('a' => array('href' => '/index/page:3')), '3', '/a', '/span',
' - ',
array('span' => array()), array('a' => array('href' => '/index/page:4')), '4', '/a', '/span',
' - ',
array('span' => array()), array('a' => array('href' => '/index/page:5')), '5', '/a', '/span',
'...',
array('span' => array()), array('a' => array('href' => '/index/page:56')), '56', '/a', '/span',
' - ',
array('span' => array()), array('a' => array('href' => '/index/page:57')), '57', '/a', '/span',
' - ',
array('span' => array('class' => 'current')), '58', '/span',
' - ',
array('span' => array()), array('a' => array('href' => '/index/page:59')), '59', '/a', '/span',
' - ',
array('span' => array()), array('a' => array('href' => '/index/page:60')), '60', '/a', '/span',
'...',
array('span' => array()), array('a' => array('href' => '/index/page:4893')), '4893', '/a', '/span',
' - ',
array('span' => array()), array('a' => array('href' => '/index/page:4894')), '4894', '/a', '/span',
' - ',
array('span' => array()), array('a' => array('href' => '/index/page:4895')), '4895', '/a', '/span',
' - ',
array('span' => array()), array('a' => array('href' => '/index/page:4896')), '4896', '/a', '/span',
' - ',
array('span' => array()), array('a' => array('href' => '/index/page:4897')), '4897', '/a', '/span',
);
$this->assertTags($result, $expected);
$this->Paginator->request->params['paging']['Client']['page'] = 5;
$result = $this->Paginator->numbers(array('first' => 5, 'modulus' => 4, 'last' => 5, 'separator' => ' - '));
$expected = array(
array('span' => array()), array('a' => array('href' => '/index/page:1')), '1', '/a', '/span',
' - ',
array('span' => array()), array('a' => array('href' => '/index/page:2')), '2', '/a', '/span',
' - ',
array('span' => array()), array('a' => array('href' => '/index/page:3')), '3', '/a', '/span',
' - ',
array('span' => array()), array('a' => array('href' => '/index/page:4')), '4', '/a', '/span',
' - ',
array('span' => array('class' => 'current')), '5', '/span',
' - ',
array('span' => array()), array('a' => array('href' => '/index/page:6')), '6', '/a', '/span',
' - ',
array('span' => array()), array('a' => array('href' => '/index/page:7')), '7', '/a', '/span',
'...',
array('span' => array()), array('a' => array('href' => '/index/page:4893')), '4893', '/a', '/span',
' - ',
array('span' => array()), array('a' => array('href' => '/index/page:4894')), '4894', '/a', '/span',
' - ',
array('span' => array()), array('a' => array('href' => '/index/page:4895')), '4895', '/a', '/span',
' - ',
array('span' => array()), array('a' => array('href' => '/index/page:4896')), '4896', '/a', '/span',
' - ',
array('span' => array()), array('a' => array('href' => '/index/page:4897')), '4897', '/a', '/span',
);
$this->assertTags($result, $expected);
$this->Paginator->request->params['paging']['Client']['page'] = 3;
$result = $this->Paginator->numbers(array('first' => 2, 'modulus' => 2, 'last' => 2, 'separator' => ' - ', 'ellipsis' => ' ~~~ '));
$expected = array(
array('span' => array()), array('a' => array('href' => '/index/page:1')), '1', '/a', '/span',
' - ',
array('span' => array()), array('a' => array('href' => '/index/page:2')), '2', '/a', '/span',
' - ',
array('span' => array('class' => 'current')), '3', '/span',
' - ',
array('span' => array()), array('a' => array('href' => '/index/page:4')), '4', '/a', '/span',
' ~~~ ',
array('span' => array()), array('a' => array('href' => '/index/page:4896')), '4896', '/a', '/span',
' - ',
array('span' => array()), array('a' => array('href' => '/index/page:4897')), '4897', '/a', '/span',
);
$this->assertTags($result, $expected);
$this->Paginator->request->params['paging']['Client']['page'] = 3;
$result = $this->Paginator->numbers(array('first' => 2, 'modulus' => 2, 'last' => 2, 'separator' => ' - ', 'ellipsis' => '<span class="ellipsis">...</span>'));
$expected = array(
array('span' => array()), array('a' => array('href' => '/index/page:1')), '1', '/a', '/span',
' - ',
array('span' => array()), array('a' => array('href' => '/index/page:2')), '2', '/a', '/span',
' - ',
array('span' => array('class' => 'current')), '3', '/span',
' - ',
array('span' => array()), array('a' => array('href' => '/index/page:4')), '4', '/a', '/span',
array('span' => array('class' => 'ellipsis')), '...', '/span',
array('span' => array()), array('a' => array('href' => '/index/page:4896')), '4896', '/a', '/span',
' - ',
array('span' => array()), array('a' => array('href' => '/index/page:4897')), '4897', '/a', '/span',
);
$this->assertTags($result, $expected);
}
/**
* test first() and last() with tag options
*
* @return void
*/
public function testFirstAndLastTag() {
$result = $this->Paginator->first('<<', array('tag' => 'li', 'class' => 'first'));
$expected = array(
'li' => array('class' => 'first'),
'a' => array('href' => '/index/page:1', 'rel' => 'first'),
'<<',
'/a',
'/li'
);
$this->assertTags($result, $expected);
$result = $this->Paginator->last(2, array('tag' => 'li', 'class' => 'last'));
$expected = array(
'...',
'li' => array('class' => 'last'),
array('a' => array('href' => '/index/page:6')), '6', '/a',
'/li',
' | ',
array('li' => array('class' => 'last')),
array('a' => array('href' => '/index/page:7')), '7', '/a',
'/li',
);
$this->assertTags($result, $expected);
}
/**
* test that on the last page you don't get a link ot the last page.
*
* @return void
*/
public function testLastNoOutput() {
$this->Paginator->request->params['paging']['Article']['page'] = 15;
$this->Paginator->request->params['paging']['Article']['pageCount'] = 15;
$result = $this->Paginator->last();
$expected = '';
$this->assertEqual($expected, $result);
}
/**
* test first() on the first page.
*
* @return void
*/
public function testFirstEmpty() {
$this->Paginator->request->params['paging']['Article']['page'] = 1;
$result = $this->Paginator->first();
$expected = '';
$this->assertEqual($expected, $result);
}
/**
* test first() and options()
*
* @return void
*/
public function testFirstFullBaseUrl() {
$this->Paginator->request->params['paging']['Article']['options']['order'] = array('Article.title' => 'DESC');
$this->Paginator->options(array('url' => array('full_base' => true)));
$result = $this->Paginator->first();
$expected = array(
'<span',
array('a' => array(
'href' => FULL_BASE_URL . '/index/page:1/sort:Article.title/direction:DESC', 'rel' => 'first'
)),
'<< first',
'/a',
'/span',
);
$this->assertTags($result, $expected);
}
/**
* test first() on the fence-post
*
* @return void
*/
public function testFirstBoundaries() {
$result = $this->Paginator->first();
$expected = array(
'<span',
'a' => array('href' => '/index/page:1', 'rel' => 'first'),
'<< first',
'/a',
'/span'
);
$this->assertTags($result, $expected);
$result = $this->Paginator->first(2);
$expected = array(
'<span',
array('a' => array('href' => '/index/page:1')), '1', '/a',
'/span',
' | ',
'<span',
array('a' => array('href' => '/index/page:2')), '2', '/a',
'/span'
);
$this->assertTags($result, $expected);
$this->Paginator->request->params['paging']['Article']['page'] = 2;
$result = $this->Paginator->first(3);
$this->assertEquals('', $result, 'When inside the first links range, no links should be made');
}
/**
* test Last method
*
* @return void
*/
public function testLast() {
$result = $this->Paginator->last();
$expected = array(
'<span',
'a' => array('href' => '/index/page:7', 'rel' => 'last'),
'last >>',
'/a',
'/span'
);
$this->assertTags($result, $expected);
$result = $this->Paginator->last(1);
$expected = array(
'...',
'<span',
'a' => array('href' => '/index/page:7'),
'7',
'/a',
'/span'
);
$this->assertTags($result, $expected);
$this->Paginator->request->params['paging']['Article']['page'] = 6;
$result = $this->Paginator->last(2);
$expected = array(
'...',
'<span',
array('a' => array('href' => '/index/page:6')), '6', '/a',
'/span',
' | ',
'<span',
array('a' => array('href' => '/index/page:7')), '7', '/a',
'/span',
);
$this->assertTags($result, $expected);
$result = $this->Paginator->last(3);
$this->assertEquals('', $result, 'When inside the last links range, no links should be made');
}
/**
* undocumented function
*
* @return void
*/
public function testLastOptions() {
$this->Paginator->request->params['paging'] = array(
'Client' => array(
'page' => 4,
'current' => 3,
'count' => 30,
'prevPage' => false,
'nextPage' => 2,
'pageCount' => 15,
'options' => array(
'page' => 1,
'order' => array('Client.name' => 'DESC'),
),
'paramType' => 'named'
)
);
$result = $this->Paginator->last();
$expected = array(
'<span',
array('a' => array(
'href' => '/index/page:15/sort:Client.name/direction:DESC',
'rel' => 'last'
)),
'last >>', '/a',
'/span',
);
$this->assertTags($result, $expected);
$result = $this->Paginator->last(1);
$expected = array(
'...',
'<span',
array('a' => array('href' => '/index/page:15/sort:Client.name/direction:DESC')), '15', '/a',
'/span',
);
$this->assertTags($result, $expected);
$result = $this->Paginator->last(2);
$expected = array(
'...',
'<span',
array('a' => array('href' => '/index/page:14/sort:Client.name/direction:DESC')), '14', '/a',
'/span',
' | ',
'<span',
array('a' => array('href' => '/index/page:15/sort:Client.name/direction:DESC')), '15', '/a',
'/span',
);
$this->assertTags($result, $expected);
$result = $this->Paginator->last(2, array('ellipsis' => '<span class="ellipsis">...</span>'));
$expected = array(
array('span' => array('class' => 'ellipsis')), '...', '/span',
'<span',
array('a' => array('href' => '/index/page:14/sort:Client.name/direction:DESC')), '14', '/a',
'/span',
' | ',
'<span',
array('a' => array('href' => '/index/page:15/sort:Client.name/direction:DESC')), '15', '/a',
'/span',
);
$this->assertTags($result, $expected);
}
/**
* testCounter method
*
* @return void
*/
public function testCounter() {
$this->Paginator->request->params['paging'] = array(
'Client' => array(
'page' => 1,
'current' => 3,
'count' => 13,
'prevPage' => false,
'nextPage' => true,
'pageCount' => 5,
'limit' => 3,
'options' => array(
'page' => 1,
'order' => array('Client.name' => 'DESC'),
),
'paramType' => 'named'
)
);
$input = 'Page %page% of %pages%, showing %current% records out of %count% total, ';
$input .= 'starting on record %start%, ending on %end%';
$result = $this->Paginator->counter($input);
$expected = 'Page 1 of 5, showing 3 records out of 13 total, starting on record 1, ';
$expected .= 'ending on 3';
$this->assertEqual($expected, $result);
$input = 'Page {:page} of {:pages}, showing {:current} records out of {:count} total, ';
$input .= 'starting on record {:start}, ending on {:end}';
$result = $this->Paginator->counter($input);
$this->assertEqual($expected, $result);
$input = 'Page %page% of %pages%';
$result = $this->Paginator->counter($input);
$expected = 'Page 1 of 5';
$this->assertEqual($expected, $result);
$result = $this->Paginator->counter(array('format' => $input));
$expected = 'Page 1 of 5';
$this->assertEqual($expected, $result);
$result = $this->Paginator->counter(array('format' => 'pages'));
$expected = '1 of 5';
$this->assertEqual($expected, $result);
$result = $this->Paginator->counter(array('format' => 'range'));
$expected = '1 - 3 of 13';
$this->assertEqual($expected, $result);
$result = $this->Paginator->counter('Showing %page% of %pages% %model%');
$this->assertEquals('Showing 1 of 5 clients', $result);
}
/**
* testHasPage method
*
* @return void
*/
public function testHasPage() {
$result = $this->Paginator->hasPage('Article', 15);
$this->assertFalse($result);
$result = $this->Paginator->hasPage('UndefinedModel', 2);
$this->assertFalse($result);
$result = $this->Paginator->hasPage('Article', 2);
$this->assertTrue($result);
$result = $this->Paginator->hasPage(2);
$this->assertTrue($result);
}
/**
* testWithPlugin method
*
* @return void
*/
public function testWithPlugin() {
Router::reload();
Router::setRequestInfo(array(
array(
'pass' => array(), 'named' => array(), 'prefix' => null, 'form' => array(),
'controller' => 'magazines', 'plugin' => 'my_plugin', 'action' => 'index',
'url' => array('ext' => 'html', 'url' => 'my_plugin/magazines')),
array('base' => '', 'here' => '/my_plugin/magazines', 'webroot' => '/')
));
$result = $this->Paginator->link('Page 3', array('page' => 3));
$expected = array(
'a' => array('href' => '/my_plugin/magazines/index/page:3'), 'Page 3', '/a'
);
$this->assertTags($result, $expected);
$this->Paginator->options(array('url' => array('action' => 'another_index')));
$result = $this->Paginator->link('Page 3', array('page' => 3));
$expected = array(
'a' => array('href' => '/my_plugin/magazines/another_index/page:3'), 'Page 3', '/a'
);
$this->assertTags($result, $expected);
$this->Paginator->options(array('url' => array('controller' => 'issues')));
$result = $this->Paginator->link('Page 3', array('page' => 3));
$expected = array(
'a' => array('href' => '/my_plugin/issues/index/page:3'), 'Page 3', '/a'
);
$this->assertTags($result, $expected);
$this->Paginator->options(array('url' => array('plugin' => null)));
$result = $this->Paginator->link('Page 3', array('page' => 3));
$expected = array(
'a' => array('/magazines/index/page:3'), 'Page 3', '/a'
);
$this->Paginator->options(array('url' => array('plugin' => null, 'controller' => 'issues')));
$result = $this->Paginator->link('Page 3', array('page' => 3));
$expected = array(
'a' => array('href' => '/issues/index/page:3'), 'Page 3', '/a'
);
$this->assertTags($result, $expected);
}
/**
* testNextLinkUsingDotNotation method
*
* @return void
*/
public function testNextLinkUsingDotNotation() {
Router::reload();
Router::parse('/');
Router::setRequestInfo(array(
array('plugin' => null, 'controller' => 'accounts', 'action' => 'index', 'pass' => array(), 'url' => array('url' => 'accounts/')),
array('base' => '/officespace', 'here' => '/officespace/accounts/', 'webroot' => '/officespace/', 'passedArgs' => array())
));
$this->Paginator->request->params['paging']['Article']['options']['order'] = array('Article.title' => 'asc');
$this->Paginator->request->params['paging']['Article']['page'] = 1;
$test = array('url'=> array(
'page'=> '1',
'sort'=>'Article.title',
'direction'=>'asc',
));
$this->Paginator->options($test);
$result = $this->Paginator->next('Next');
$expected = array(
'span' => array('class' => 'next'),
'a' => array(
'href' => '/officespace/accounts/index/page:2/sort:Article.title/direction:asc',
'rel' => 'next'
),
'Next',
'/a',
'/span',
);
$this->assertTags($result, $expected);
}
/**
* Ensure that the internal link class object is called when the update key is present
*
* @return void
*/
public function testAjaxLinkGenerationNumbers() {
$this->Paginator->Js->expectCallCount('link', 2);
$result = $this->Paginator->numbers(array(
'modulus'=> '2',
'url'=> array('controller' => 'projects', 'action' => 'sort'),
'update' => 'list'
));
}
/**
* test that paginatorHelper::link() uses JsHelper to make links when 'update' key is present
*
* @return void
*/
public function testAjaxLinkGenerationLink() {
$this->Paginator->Js->expects($this->once())
->method('link')
->will($this->returnValue('I am a link'));
$result = $this->Paginator->link('test', array('controller' => 'posts'), array('update' => '#content'));
$this->assertEqual($result, 'I am a link');
}
/**
* test that mock classes injected into paginatorHelper are called when using link()
*
* @return void
*/
public function testMockAjaxProviderClassInjection() {
$mock = $this->getMock('PaginatorHelper', array(), array($this->View), 'PaginatorMockJsHelper');
$Paginator = new PaginatorHelper($this->View, array('ajax' => 'PaginatorMockJs'));
$Paginator->request->params['paging'] = array(
'Article' => array(
'current' => 9,
'count' => 62,
'prevPage' => false,
'nextPage' => true,
'pageCount' => 7,
'defaults' => array(),
'options' => array(),
'paramType' => 'named'
)
);
$Paginator->PaginatorMockJs = $mock;
$Paginator->PaginatorMockJs->expects($this->once())->method('link');
$result = $Paginator->link('Page 2', array('page' => 2), array('update' => '#content'));
$this->expectException();
$Paginator = new PaginatorHelper($this->View, array('ajax' => 'Form'));
}
/**
* test that querystring urls can be generated.
*
* @return void
*/
public function testQuerystringUrlGeneration() {
$this->Paginator->request->params['paging']['Article']['paramType'] = 'querystring';
$result = $this->Paginator->url(array('page' => '4'));
$expected = '/?page=4';
$this->assertEquals($expected, $result);
$result = $this->Paginator->url(array('page' => '4', 'limit' => 10, 'something' => 'else'));
$expected = '/index/something:else?page=4&limit=10';
$this->assertEquals($expected, $result);
}
/**
* test querystring paging link.
*
* @return void
*/
public function testQuerystringNextAndPrev() {
$this->Paginator->request->params['paging']['Article']['paramType'] = 'querystring';
$this->Paginator->request->params['paging']['Article']['page'] = 2;
$this->Paginator->request->params['paging']['Article']['nextPage'] = true;
$this->Paginator->request->params['paging']['Article']['prevPage'] = true;
$result = $this->Paginator->next('Next');
$expected = array(
'span' => array('class' => 'next'),
'a' => array('href' => '/?page=3', 'rel' => 'next'),
'Next',
'/a',
'/span'
);
$this->assertTags($result, $expected);
$result = $this->Paginator->prev('Prev');
$expected = array(
'span' => array('class' => 'prev'),
'a' => array('href' => '/?page=1', 'rel' => 'prev'),
'Prev',
'/a',
'/span'
);
$this->assertTags($result, $expected);
}
/**
* test that additional keys can be flagged as query string args.
*
* @return void
*/
public function testOptionsConvertKeys() {
$this->Paginator->options(array(
'convertKeys' => array('something'),
'Article' => array('paramType' => 'querystring')
));
$result = $this->Paginator->url(array('page' => '4', 'something' => 'bar'));
$expected = '/?page=4&something=bar';
$this->assertEquals($expected, $result);
}
/**
* test the current() method
*
* @return void
*/
public function testCurrent() {
$result = $this->Paginator->current();
$this->assertEquals($this->Paginator->request->params['paging']['Article']['page'], $result);
$result = $this->Paginator->current('Incorrect');
$this->assertEquals(1, $result);
}
/**
* test the defaultModel() method
*
* @return void
*/
public function testNoDefaultModel() {
$this->Paginator->request = new CakeRequest(null, false);
$this->assertNull($this->Paginator->defaultModel());
}
/**
* test the numbers() method when there is only one page
*
* @return void
*/
public function testWithOnePage() {
$this->Paginator->request['paging'] = array(
'Article' => array(
'page' => 1,
'current' => 2,
'count' => 2,
'prevPage' => false,
'nextPage' => true,
'pageCount' => 1,
'options' => array(
'page' => 1,
),
'paramType' => 'named',
)
);
$this->assertFalse($this->Paginator->numbers());
$this->assertFalse($this->Paginator->first());
$this->assertFalse($this->Paginator->last());
}
/**
* test the numbers() method when there is only one page
*
* @return void
*/
public function testWithZeroPages() {
$this->Paginator->request['paging'] = array(
'Article' => array(
'page' => 0,
'current' => 0,
'count' => 0,
'prevPage' => false,
'nextPage' => false,
'pageCount' => 0,
'limit' => 10,
'options' => array(
'page' => 0,
'conditions' => array()
),
'paramType' => 'named',
)
);
$result = $this->Paginator->counter(array('format' => 'pages'));
$expected = '0 of 1';
$this->assertEqual($expected, $result);
}
}
| 0001-bee | trunk/cakephp2/lib/Cake/Test/Case/View/Helper/PaginatorHelperTest.php | PHP | gpl3 | 79,549 |
<?php
/**
* RssHelperTest file
*
* PHP 5
*
* CakePHP(tm) Tests <http://book.cakephp.org/view/1196/Testing>
* Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice
*
* @copyright Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://book.cakephp.org/view/1196/Testing CakePHP(tm) Tests
* @package Cake.Test.Case.View.Helper
* @since CakePHP(tm) v 1.2.0.4206
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
App::uses('View', 'View');
App::uses('RssHelper', 'View/Helper');
App::uses('TimeHelper', 'View/Helper');
App::uses('File', 'Utility');
/**
* RssHelperTest class
*
* @package Cake.Test.Case.View.Helper
*/
class RssHelperTest extends CakeTestCase {
/**
* setUp method
*
* @return void
*/
public function setUp() {
parent::setUp();
$controller = null;
$this->View = new View($controller);
$this->Rss = new RssHelper($this->View);
}
/**
* tearDown method
*
* @return void
*/
public function tearDown() {
parent::tearDown();
unset($this->Rss);
}
/**
* testDocument method
*
* @return void
*/
public function testDocument() {
$result = $this->Rss->document();
$expected = array(
'rss' => array(
'version' => '2.0'
)
);
$this->assertTags($result, $expected);
$result = $this->Rss->document(null, 'content');
$expected = array(
'rss' => array(
'version' => '2.0'
),
'content'
);
$this->assertTags($result, $expected);
$result = $this->Rss->document(array('contrived' => 'parameter'), 'content');
$expected = array(
'rss' => array(
'contrived' => 'parameter',
'version' => '2.0'
),
'content'
);
$this->assertTags($result, $expected);
}
/**
* testChannel method
*
* @return void
*/
public function testChannel() {
$attrib = array('a' => '1', 'b' => '2');
$elements = array('title' => 'title');
$content = 'content';
$result = $this->Rss->channel($attrib, $elements, $content);
$expected = array(
'channel' => array(
'a' => '1',
'b' => '2'
),
'<title',
'title',
'/title',
'<link',
$this->Rss->url('/', true),
'/link',
'<description',
'content',
'/channel'
);
$this->assertTags($result, $expected);
$this->View->pageTitle = 'title';
$attrib = array('a' => '1', 'b' => '2');
$elements = array();
$content = 'content';
$result = $this->Rss->channel($attrib, $elements, $content);
$expected = array(
'channel' => array(
'a' => '1',
'b' => '2'
),
'<title',
'title',
'/title',
'<link',
$this->Rss->url('/', true),
'/link',
'<description',
'content',
'/channel'
);
$this->assertTags($result, $expected);
}
/**
* test correct creation of channel sub elements.
*
* @return void
*/
public function testChannelElements() {
$attrib = array();
$elements = array(
'title' => 'Title of RSS Feed',
'link' => 'http://example.com',
'description' => 'Description of RSS Feed',
'image' => array(
'title' => 'Title of image',
'url' => 'http://example.com/example.png',
'link' => 'http://example.com'
),
'cloud' => array(
'domain' => "rpc.sys.com",
'port' => "80",
'path' =>"/RPC2",
'registerProcedure' => "myCloud.rssPleaseNotify",
'protocol' => "xml-rpc"
)
);
$content = 'content-here';
$result = $this->Rss->channel($attrib, $elements, $content);
$expected = array(
'<channel',
'<title', 'Title of RSS Feed', '/title',
'<link', 'http://example.com', '/link',
'<description', 'Description of RSS Feed', '/description',
'<image',
'<title', 'Title of image', '/title',
'<url', 'http://example.com/example.png', '/url',
'<link', 'http://example.com', '/link',
'/image',
'cloud' => array(
'domain' => "rpc.sys.com",
'port' => "80",
'path' =>"/RPC2",
'registerProcedure' => "myCloud.rssPleaseNotify",
'protocol' => "xml-rpc"
),
'content-here',
'/channel',
);
$this->assertTags($result, $expected);
}
public function testChannelElementAttributes() {
$attrib = array();
$elements = array(
'title' => 'Title of RSS Feed',
'link' => 'http://example.com',
'description' => 'Description of RSS Feed',
'image' => array(
'title' => 'Title of image',
'url' => 'http://example.com/example.png',
'link' => 'http://example.com'
),
'atom:link' => array(
'attrib' => array(
'href' => 'http://www.example.com/rss.xml',
'rel' => 'self',
'type' => 'application/rss+xml')
)
);
$content = 'content-here';
$result = $this->Rss->channel($attrib, $elements, $content);
$expected = array(
'<channel',
'<title', 'Title of RSS Feed', '/title',
'<link', 'http://example.com', '/link',
'<description', 'Description of RSS Feed', '/description',
'<image',
'<title', 'Title of image', '/title',
'<url', 'http://example.com/example.png', '/url',
'<link', 'http://example.com', '/link',
'/image',
'atom:link' => array(
'xmlns:atom' => 'http://www.w3.org/2005/Atom',
'href' => "http://www.example.com/rss.xml",
'rel' => "self",
'type' =>"application/rss+xml"
),
'content-here',
'/channel',
);
$this->assertTags($result, $expected);
}
/**
* testItems method
*
* @return void
*/
public function testItems() {
$items = array(
array('title' => 'title1', 'guid' => 'http://www.example.com/guid1', 'link' => 'http://www.example.com/link1', 'description' => 'description1'),
array('title' => 'title2', 'guid' => 'http://www.example.com/guid2', 'link' => 'http://www.example.com/link2', 'description' => 'description2'),
array('title' => 'title3', 'guid' => 'http://www.example.com/guid3', 'link' => 'http://www.example.com/link3', 'description' => 'description3')
);
$result = $this->Rss->items($items);
$expected = array(
'<item',
'<title', 'title1', '/title',
'<guid', 'http://www.example.com/guid1', '/guid',
'<link', 'http://www.example.com/link1', '/link',
'<description', 'description1', '/description',
'/item',
'<item',
'<title', 'title2', '/title',
'<guid', 'http://www.example.com/guid2', '/guid',
'<link', 'http://www.example.com/link2', '/link',
'<description', 'description2', '/description',
'/item',
'<item',
'<title', 'title3', '/title',
'<guid', 'http://www.example.com/guid3', '/guid',
'<link', 'http://www.example.com/link3', '/link',
'<description', 'description3', '/description',
'/item'
);
$this->assertTags($result, $expected);
$items = array(
array('title' => 'title1', 'guid' => 'http://www.example.com/guid1', 'link' => 'http://www.example.com/link1', 'description' => 'description1'),
array('title' => 'title2', 'guid' => 'http://www.example.com/guid2', 'link' => 'http://www.example.com/link2', 'description' => 'description2'),
array('title' => 'title3', 'guid' => 'http://www.example.com/guid3', 'link' => 'http://www.example.com/link3', 'description' => 'description3')
);
$result = $this->Rss->items($items, create_function('$v', '$v[\'title\'] = $v[\'title\'] . \'-transformed\'; return $v;'));
$expected = array(
'<item',
'<title', 'title1-transformed', '/title',
'<guid', 'http://www.example.com/guid1', '/guid',
'<link', 'http://www.example.com/link1', '/link',
'<description', 'description1', '/description',
'/item',
'<item',
'<title', 'title2-transformed', '/title',
'<guid', 'http://www.example.com/guid2', '/guid',
'<link', 'http://www.example.com/link2', '/link',
'<description', 'description2', '/description',
'/item',
'<item',
'<title', 'title3-transformed', '/title',
'<guid', 'http://www.example.com/guid3', '/guid',
'<link', 'http://www.example.com/link3', '/link',
'<description', 'description3', '/description',
'/item'
);
$this->assertTags($result, $expected);
$result = $this->Rss->items(array());
$expected = '';
$this->assertEqual($expected, $result);
}
/**
* testItem method
*
* @return void
*/
public function testItem() {
$item = array(
'title' => 'My title',
'description' => 'My description',
'link' => 'http://www.google.com/'
);
$result = $this->Rss->item(null, $item);
$expected = array(
'<item',
'<title',
'My title',
'/title',
'<description',
'My description',
'/description',
'<link',
'http://www.google.com/',
'/link',
'<guid',
'http://www.google.com/',
'/guid',
'/item'
);
$this->assertTags($result, $expected);
$item = array(
'title' => 'My Title',
'link' => 'http://www.example.com/1',
'description' => 'descriptive words',
'pubDate' => '2008-05-31 12:00:00',
'source' => array('http://www.google.com/', 'Google'),
'guid' => 'http://www.example.com/1'
);
$result = $this->Rss->item(null, $item);
$expected = array(
'<item',
'<title',
'My Title',
'/title',
'<link',
'http://www.example.com/1',
'/link',
'<description',
'descriptive words',
'/description',
'<pubDate',
date('r', strtotime('2008-05-31 12:00:00')),
'/pubDate',
'source' => array('url' => 'http://www.google.com/'),
'Google',
'/source',
'<guid',
'http://www.example.com/1',
'/guid',
'/item'
);
$this->assertTags($result, $expected);
$item = array(
'title' => 'My Title & more'
);
$result = $this->Rss->item(null, $item);
$expected = array(
'<item',
'<title', 'My Title & more', '/title',
'/item'
);
$this->assertTags($result, $expected);
$item = array(
'title' => 'Foo bar',
'link' => array(
'url' => 'http://example.com/foo?a=1&b=2',
'convertEntities' => false
),
'description' => array(
'value' => 'descriptive words',
'cdata' => true,
),
'pubDate' => '2008-05-31 12:00:00',
'source' => 'http://www.google.com/'
);
$result = $this->Rss->item(null, $item);
$expected = array(
'<item',
'<title',
'Foo bar',
'/title',
'<link',
'http://example.com/foo?a=1&b=2',
'/link',
'<description',
'<![CDATA[descriptive words]]',
'/description',
'<pubDate',
date('r', strtotime('2008-05-31 12:00:00')),
'/pubDate',
'<source',
'http://www.google.com/',
'/source',
'<guid',
'http://example.com/foo?a=1&b=2',
'/guid',
'/item'
);
$this->assertTags($result, $expected);
$item = array(
'title' => 'My title',
'description' => 'My description',
'link' => 'http://www.google.com/',
'source' => array('url' => 'http://www.example.com/', 'title' => 'Example website')
);
$result = $this->Rss->item(null, $item);
$expected = array(
'<item',
'<title',
'My title',
'/title',
'<description',
'My description',
'/description',
'<link',
'http://www.google.com/',
'/link',
'source' => array('url' => 'http://www.example.com/'),
'Example website',
'/source',
'<guid',
'http://www.google.com/',
'/guid',
'/item'
);
$this->assertTags($result, $expected);
}
/**
* test item() with cdata blocks.
*
* @return void
*/
public function testItemCdata() {
$item = array(
'title' => array(
'value' => 'My Title & more',
'cdata' => true,
'convertEntities' => false,
)
);
$result = $this->Rss->item(null, $item);
$expected = array(
'<item',
'<title',
'<![CDATA[My Title & more]]',
'/title',
'/item'
);
$this->assertTags($result, $expected);
$item = array(
'category' => array(
'value' => 'CakePHP',
'cdata' => true,
'domain' => 'http://www.cakephp.org',
)
);
$result = $this->Rss->item(null, $item);
$expected = array(
'<item',
'category' => array('domain' => 'http://www.cakephp.org'),
'<![CDATA[CakePHP]]',
'/category',
'/item'
);
$this->assertTags($result, $expected);
$item = array(
'category' => array(
array(
'value' => 'CakePHP',
'cdata' => true,
'domain' => 'http://www.cakephp.org'
),
array(
'value' => 'Bakery',
'cdata' => true
)
)
);
$result = $this->Rss->item(null, $item);
$expected = array(
'<item',
'category' => array('domain' => 'http://www.cakephp.org'),
'<![CDATA[CakePHP]]',
'/category',
'<category',
'<![CDATA[Bakery]]',
'/category',
'/item'
);
$this->assertTags($result, $expected);
$item = array(
'title' => array(
'value' => 'My Title',
'cdata' => true,
),
'link' => 'http://www.example.com/1',
'description' => array(
'value' => 'descriptive words',
'cdata' => true,
),
'enclosure' => array(
'url' => '/test.flv'
),
'pubDate' => '2008-05-31 12:00:00',
'guid' => 'http://www.example.com/1',
'category' => array(
array(
'value' => 'CakePHP',
'cdata' => true,
'domain' => 'http://www.cakephp.org'
),
array(
'value' => 'Bakery',
'cdata' => true
)
)
);
$result = $this->Rss->item(null, $item);
$expected = array(
'<item',
'<title',
'<![CDATA[My Title]]',
'/title',
'<link',
'http://www.example.com/1',
'/link',
'<description',
'<![CDATA[descriptive words]]',
'/description',
'enclosure' => array('url' => $this->Rss->url('/test.flv', true)),
'<pubDate',
date('r', strtotime('2008-05-31 12:00:00')),
'/pubDate',
'<guid',
'http://www.example.com/1',
'/guid',
'category' => array('domain' => 'http://www.cakephp.org'),
'<![CDATA[CakePHP]]',
'/category',
'<category',
'<![CDATA[Bakery]]',
'/category',
'/item'
);
$this->assertTags($result, $expected);
}
/**
* test item() with enclosure data.
*
* @return void
*/
public function testItemEnclosureLength() {
$tmpFile = $this->_getWwwTmpFile();
if (file_exists($tmpFile)) {
unlink($tmpFile);
}
$File = new File($tmpFile, true, '0777');
$this->assertTrue($File->write('123'), 'Could not write to ' . $tmpFile);
clearstatcache(true, $tmpFile);
$item = array(
'title' => array(
'value' => 'My Title',
'cdata' => true,
),
'link' => 'http://www.example.com/1',
'description' => array(
'value' => 'descriptive words',
'cdata' => true,
),
'enclosure' => array(
'url' => '/tests/cakephp.file.test.tmp'
),
'pubDate' => '2008-05-31 12:00:00',
'guid' => 'http://www.example.com/1',
'category' => array(
array(
'value' => 'CakePHP',
'cdata' => true,
'domain' => 'http://www.cakephp.org'
),
array(
'value' => 'Bakery',
'cdata' => true
)
)
);
$result = $this->Rss->item(null, $item);
$expected = array(
'<item',
'<title',
'<![CDATA[My Title]]',
'/title',
'<link',
'http://www.example.com/1',
'/link',
'<description',
'<![CDATA[descriptive words]]',
'/description',
'enclosure' => array(
'url' => $this->Rss->url('/tests/cakephp.file.test.tmp', true),
'length' => filesize($tmpFile),
'type' => 'text/plain'
),
'<pubDate',
date('r', strtotime('2008-05-31 12:00:00')),
'/pubDate',
'<guid',
'http://www.example.com/1',
'/guid',
'category' => array('domain' => 'http://www.cakephp.org'),
'<![CDATA[CakePHP]]',
'/category',
'<category',
'<![CDATA[Bakery]]',
'/category',
'/item'
);
$this->assertTags($result, $expected);
unlink($tmpFile);
}
/**
* testTime method
*
* @return void
*/
public function testTime() {
}
/**
* testElementAttrNotInParent method
*
* @return void
*/
public function testElementAttrNotInParent() {
$attributes = array(
'title' => 'Some Title',
'link' => 'http://link.com',
'description' => 'description'
);
$elements = array('enclosure' => array('url' => 'http://test.com'));
$result = $this->Rss->item($attributes, $elements);
$expected = array(
'item' => array(
'title' => 'Some Title',
'link' => 'http://link.com',
'description' => 'description'
),
'enclosure' => array(
'url' => 'http://test.com'
),
'/item'
);
$this->assertTags($result, $expected);
}
/**
* getWwwTmpFile method
*
* @param bool $paintSkip
* @return void
*/
function _getWwwTmpFile() {
$path = WWW_ROOT . 'tests' . DS;
$tmpFile = $path. 'cakephp.file.test.tmp';
if (is_writable(dirname($tmpFile)) && (!file_exists($tmpFile) || is_writable($tmpFile))) {
return $tmpFile;
};
$message = __d('cake_dev', '%s is not writeable', $path );
$this->markTestSkipped($message);
return false;
}
}
| 0001-bee | trunk/cakephp2/lib/Cake/Test/Case/View/Helper/RssHelperTest.php | PHP | gpl3 | 16,672 |
<?php
/**
* MooEngineTestCase
*
* PHP 5
*
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
* Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright 2005-2011, Cake Software Foundation, Inc.
* @link http://cakephp.org CakePHP Project
* @package Cake.Test.Case.View.Helper
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
App::uses('View', 'View');
App::uses('HtmlHelper', 'View/Helper');
App::uses('JsHelper', 'View/Helper');
App::uses('MootoolsEngineHelper', 'View/Helper');
class MootoolsEngineHelperTest extends CakeTestCase {
/**
* setUp
*
* @return void
*/
public function setUp() {
parent::setUp();
$controller = null;
$this->View = $this->getMock('View', array('addScript'), array(&$controller));
$this->Moo = new MootoolsEngineHelper($this->View);
}
/**
* tearDown
*
* @return void
*/
public function tearDown() {
parent::tearDown();
unset($this->Moo);
}
/**
* test selector method
*
* @return void
*/
public function testSelector() {
$result = $this->Moo->get('#content');
$this->assertEqual($result, $this->Moo);
$this->assertEqual($this->Moo->selection, '$("content")');
$result = $this->Moo->get('a .remove');
$this->assertEqual($result, $this->Moo);
$this->assertEqual($this->Moo->selection, '$$("a .remove")');
$result = $this->Moo->get('document');
$this->assertEqual($result, $this->Moo);
$this->assertEqual($this->Moo->selection, "$(document)");
$result = $this->Moo->get('window');
$this->assertEqual($result, $this->Moo);
$this->assertEqual($this->Moo->selection, "$(window)");
$result = $this->Moo->get('ul');
$this->assertEqual($result, $this->Moo);
$this->assertEqual($this->Moo->selection, '$$("ul")');
$result = $this->Moo->get('#some_long-id.class');
$this->assertEqual($result, $this->Moo);
$this->assertEqual($this->Moo->selection, '$$("#some_long-id.class")');
}
/**
* test event binding
*
* @return void
*/
public function testEvent() {
$this->Moo->get('#myLink');
$result = $this->Moo->event('click', 'doClick', array('wrap' => false));
$expected = '$("myLink").addEvent("click", doClick);';
$this->assertEqual($expected, $result);
$result = $this->Moo->event('click', 'this.setStyle("display", "");', array('stop' => false));
$expected = '$("myLink").addEvent("click", function (event) {this.setStyle("display", "");});';
$this->assertEqual($expected, $result);
$result = $this->Moo->event('click', 'this.setStyle("display", "none");');
$expected = "\$(\"myLink\").addEvent(\"click\", function (event) {event.stop();\nthis.setStyle(\"display\", \"none\");});";
$this->assertEqual($expected, $result);
}
/**
* test dom ready event creation
*
* @return void
*/
public function testDomReady() {
$result = $this->Moo->domReady('foo.name = "bar";');
$expected = 'window.addEvent("domready", function (event) {foo.name = "bar";});';
$this->assertEqual($expected, $result);
}
/**
* test Each method
*
* @return void
*/
public function testEach() {
$this->Moo->get('#foo');
$result = $this->Moo->each('item.setStyle("display", "none");');
$expected = '$("foo").each(function (item, index) {item.setStyle("display", "none");});';
$this->assertEqual($expected, $result);
}
/**
* test Effect generation
*
* @return void
*/
public function testEffect() {
$this->Moo->get('#foo');
$result = $this->Moo->effect('show');
$expected = '$("foo").setStyle("display", "");';
$this->assertEqual($expected, $result);
$result = $this->Moo->effect('hide');
$expected = '$("foo").setStyle("display", "none");';
$this->assertEqual($expected, $result);
$result = $this->Moo->effect('fadeIn');
$expected = '$("foo").fade("in");';
$this->assertEqual($expected, $result);
$result = $this->Moo->effect('fadeOut');
$expected = '$("foo").fade("out");';
$this->assertEqual($expected, $result);
$result = $this->Moo->effect('slideIn');
$expected = '$("foo").slide("in");';
$this->assertEqual($expected, $result);
$result = $this->Moo->effect('slideOut');
$expected = '$("foo").slide("out");';
$this->assertEqual($expected, $result);
$result = $this->Moo->effect('slideOut', array('speed' => 'fast'));
$expected = '$("foo").set("slide", {duration:"short"}).slide("out");';
$this->assertEqual($expected, $result);
$result = $this->Moo->effect('slideOut', array('speed' => 'slow'));
$expected = '$("foo").set("slide", {duration:"long"}).slide("out");';
$this->assertEqual($expected, $result);
}
/**
* Test Request Generation
*
* @return void
*/
public function testRequest() {
$result = $this->Moo->request(array('controller' => 'posts', 'action' => 'view', 1));
$expected = 'var jsRequest = new Request({url:"\\/posts\\/view\\/1"}).send();';
$this->assertEqual($expected, $result);
$result = $this->Moo->request('/posts/view/1', array('update' => 'content'));
$expected = 'var jsRequest = new Request.HTML({update:"content", url:"\\/posts\\/view\\/1"}).send();';
$this->assertEqual($expected, $result);
$result = $this->Moo->request('/people/edit/1', array(
'method' => 'post',
'complete' => 'doSuccess',
'error' => 'handleError',
'type' => 'json',
'data' => array('name' => 'jim', 'height' => '185cm'),
'wrapCallbacks' => false
));
$expected = 'var jsRequest = new Request.JSON({method:"post", onComplete:doSuccess, onFailure:handleError, url:"\\/people\\/edit\\/1"}).send({"name":"jim","height":"185cm"});';
$this->assertEqual($expected, $result);
$result = $this->Moo->request('/people/edit/1', array(
'method' => 'post',
'complete' => 'doSuccess',
'update' => '#update-zone',
'wrapCallbacks' => false
));
$expected = 'var jsRequest = new Request.HTML({method:"post", onComplete:doSuccess, update:"update-zone", url:"\\/people\\/edit\\/1"}).send();';
$this->assertEqual($expected, $result);
$result = $this->Moo->request('/people/edit/1', array(
'method' => 'post',
'complete' => 'doComplete',
'success' => 'doSuccess',
'error' => 'doFailure',
'before' => 'doBefore',
'update' => 'update-zone',
'wrapCallbacks' => false
));
$expected = 'var jsRequest = new Request.HTML({method:"post", onComplete:doComplete, onFailure:doFailure, onRequest:doBefore, onSuccess:doSuccess, update:"update-zone", url:"\\/people\\/edit\\/1"}).send();';
$this->assertEqual($expected, $result);
$result = $this->Moo->request('/people/edit/1', array(
'method' => 'post',
'complete' => 'doComplete',
'success' => 'doSuccess',
'error' => 'doFailure',
'before' => 'doBefore',
'update' => 'update-zone',
'dataExpression' => true,
'data' => '$("foo").toQueryString()',
'wrapCallbacks' => false
));
$expected = 'var jsRequest = new Request.HTML({method:"post", onComplete:doComplete, onFailure:doFailure, onRequest:doBefore, onSuccess:doSuccess, update:"update-zone", url:"\\/people\\/edit\\/1"}).send($("foo").toQueryString());';
$this->assertEqual($expected, $result);
$result = $this->Moo->request('/people/edit/1', array(
'method' => 'post',
'before' => 'doBefore',
'success' => 'doSuccess',
'complete' => 'doComplete',
'update' => '#update-zone',
));
$expected = 'var jsRequest = new Request.HTML({method:"post", onComplete:function () {doComplete}, onRequest:function () {doBefore}, onSuccess:function (responseText, responseXML) {doSuccess}, update:"update-zone", url:"\\/people\\/edit\\/1"}).send();';
$this->assertEqual($expected, $result);
}
/**
* test sortable list generation
*
* @return void
*/
public function testSortable() {
$this->Moo->get('#myList');
$result = $this->Moo->sortable(array(
'distance' => 5,
'containment' => 'parent',
'start' => 'onStart',
'complete' => 'onStop',
'sort' => 'onSort',
'wrapCallbacks' => false
));
$expected = 'var jsSortable = new Sortables($("myList"), {constrain:"parent", onComplete:onStop, onSort:onSort, onStart:onStart, snap:5});';
$this->assertEqual($expected, $result);
}
/**
* test drag() method
*
* @return void
*/
public function testDrag() {
$this->Moo->get('#drag-me');
$result = $this->Moo->drag(array(
'start' => 'onStart',
'drag' => 'onDrag',
'stop' => 'onStop',
'snapGrid' => array(10,10),
'wrapCallbacks' => false
));
$expected = '$("drag-me").makeDraggable({onComplete:onStop, onDrag:onDrag, onStart:onStart, snap:[10,10]});';
$this->assertEqual($expected, $result);
}
/**
* test drop() method with the required drag option missing
*
* @expectedException PHPUnit_Framework_Error_Warning
* @return void
*/
public function testDropWithMissingOption() {
$this->Moo->get('#drop-me');
$this->Moo->drop(array(
'drop' => 'onDrop',
'leave' => 'onLeave',
'hover' => 'onHover',
));
}
/**
* test drop() method
*
* @return void
*/
public function testDrop() {
$this->Moo->get('#drop-me');
$result = $this->Moo->drop(array(
'drop' => 'onDrop',
'leave' => 'onLeave',
'hover' => 'onHover',
'drag' => '#my-drag',
'wrapCallbacks' => false
));
$expected = '$("my-drag").makeDraggable({droppables:$("drop-me"), onDrop:onDrop, onEnter:onHover, onLeave:onLeave});';
$this->assertEqual($expected, $result);
$this->assertEqual($this->Moo->selection, '$("drop-me")');
$result = $this->Moo->drop(array(
'drop' => 'onDrop',
'leave' => 'onLeave',
'hover' => 'onHover',
'drag' => '#my-drag',
));
$expected = '$("my-drag").makeDraggable({droppables:$("drop-me"), onDrop:function (element, droppable, event) {onDrop}, onEnter:function (element, droppable) {onHover}, onLeave:function (element, droppable) {onLeave}});';
$this->assertEqual($expected, $result);
}
/**
* test slider generation
*
* @return void
*/
public function testSlider() {
$this->Moo->get('#slider');
$result = $this->Moo->slider(array(
'handle' => '#my-handle',
'complete' => 'onComplete',
'change' => 'onChange',
'direction' => 'horizontal',
'wrapCallbacks' => false
));
$expected = 'var jsSlider = new Slider($("slider"), $("my-handle"), {mode:"horizontal", onChange:onChange, onComplete:onComplete});';
$this->assertEqual($expected, $result);
$this->assertEqual($this->Moo->selection, '$("slider")');
$this->Moo->get('#slider');
$result = $this->Moo->slider(array(
'handle' => '#my-handle',
'complete' => 'onComplete',
'change' => 'onChange',
'direction' => 'horizontal',
'min' => 10,
'max' => 40,
'wrapCallbacks' => false
));
$expected = 'var jsSlider = new Slider($("slider"), $("my-handle"), {mode:"horizontal", onChange:onChange, onComplete:onComplete, range:[10,40]});';
$this->assertEqual($expected, $result);
$this->Moo->get('#slider');
$result = $this->Moo->slider(array(
'handle' => '#my-handle',
'complete' => 'complete;',
'change' => 'change;',
'direction' => 'horizontal',
));
$expected = 'var jsSlider = new Slider($("slider"), $("my-handle"), {mode:"horizontal", onChange:function (step) {change;}, onComplete:function (event) {complete;}});';
$this->assertEqual($expected, $result);
}
/**
* test the serializeForm implementation.
*
* @return void
*/
public function testSerializeForm() {
$this->Moo->get('#element');
$result = $this->Moo->serializeForm(array('isForm' => true));
$expected = '$("element").toQueryString();';
$this->assertEqual($expected, $result);
$result = $this->Moo->serializeForm(array('isForm' => true, 'inline' => true));
$expected = '$("element").toQueryString()';
$this->assertEqual($expected, $result);
$result = $this->Moo->serializeForm(array('isForm' => false));
$expected = '$($("element").form).toQueryString();';
$this->assertEqual($expected, $result);
$result = $this->Moo->serializeForm(array('isForm' => false, 'inline' => true));
$expected = '$($("element").form).toQueryString()';
$this->assertEqual($expected, $result);
}
}
| 0001-bee | trunk/cakephp2/lib/Cake/Test/Case/View/Helper/MootoolsEngineHelperTest.php | PHP | gpl3 | 12,111 |
<?php
/**
* JqueryEngineTestCase
*
* PHP 5
*
* CakePHP(tm) Tests <http://book.cakephp.org/view/1196/Testing>
* Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice
*
* @copyright Copyright 2005-2011, Cake Software Foundation, Inc.
* @link http://cakephp.org CakePHP Project
* @package Cake.Test.Case.View.Helper
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
App::uses('HtmlHelper', 'View/Helper');
App::uses('JsHelper', 'View/Helper');
App::uses('JqueryEngineHelper', 'View/Helper');
App::uses('View', 'View');
class JqueryEngineHelperTest extends CakeTestCase {
/**
* setUp
*
* @return void
*/
public function setUp() {
parent::setUp();
$controller = null;
$this->View = $this->getMock('View', array('addScript'), array(&$controller));
$this->Jquery = new JqueryEngineHelper($this->View);
}
/**
* tearDown
*
* @return void
*/
public function tearDown() {
parent::tearDown();
unset($this->Jquery);
}
/**
* test selector method
*
* @return void
*/
public function testSelector() {
$result = $this->Jquery->get('#content');
$this->assertEqual($result, $this->Jquery);
$this->assertEqual($this->Jquery->selection, '$("#content")');
$result = $this->Jquery->get('document');
$this->assertEqual($result, $this->Jquery);
$this->assertEqual($this->Jquery->selection, '$(document)');
$result = $this->Jquery->get('window');
$this->assertEqual($result, $this->Jquery);
$this->assertEqual($this->Jquery->selection, '$(window)');
$result = $this->Jquery->get('ul');
$this->assertEqual($result, $this->Jquery);
$this->assertEqual($this->Jquery->selection, '$("ul")');
}
/**
* test event binding
*
* @return void
*/
public function testEvent() {
$this->Jquery->get('#myLink');
$result = $this->Jquery->event('click', 'doClick', array('wrap' => false));
$expected = '$("#myLink").bind("click", doClick);';
$this->assertEqual($expected, $result);
$result = $this->Jquery->event('click', '$(this).show();', array('stop' => false));
$expected = '$("#myLink").bind("click", function (event) {$(this).show();});';
$this->assertEqual($expected, $result);
$result = $this->Jquery->event('click', '$(this).hide();');
$expected = '$("#myLink").bind("click", function (event) {$(this).hide();'."\n".'return false;});';
$this->assertEqual($expected, $result);
}
/**
* test dom ready event creation
*
* @return void
*/
public function testDomReady() {
$result = $this->Jquery->domReady('foo.name = "bar";');
$expected = '$(document).ready(function () {foo.name = "bar";});';
$this->assertEqual($expected, $result);
}
/**
* test Each method
*
* @return void
*/
public function testEach() {
$this->Jquery->get('#foo');
$result = $this->Jquery->each('$(this).hide();');
$expected = '$("#foo").each(function () {$(this).hide();});';
$this->assertEqual($expected, $result);
}
/**
* test Effect generation
*
* @return void
*/
public function testEffect() {
$this->Jquery->get('#foo');
$result = $this->Jquery->effect('show');
$expected = '$("#foo").show();';
$this->assertEqual($expected, $result);
$result = $this->Jquery->effect('hide');
$expected = '$("#foo").hide();';
$this->assertEqual($expected, $result);
$result = $this->Jquery->effect('hide', array('speed' => 'fast'));
$expected = '$("#foo").hide("fast");';
$this->assertEqual($expected, $result);
$result = $this->Jquery->effect('fadeIn');
$expected = '$("#foo").fadeIn();';
$this->assertEqual($expected, $result);
$result = $this->Jquery->effect('fadeOut');
$expected = '$("#foo").fadeOut();';
$this->assertEqual($expected, $result);
$result = $this->Jquery->effect('slideIn');
$expected = '$("#foo").slideDown();';
$this->assertEqual($expected, $result);
$result = $this->Jquery->effect('slideOut');
$expected = '$("#foo").slideUp();';
$this->assertEqual($expected, $result);
$result = $this->Jquery->effect('slideDown');
$expected = '$("#foo").slideDown();';
$this->assertEqual($expected, $result);
$result = $this->Jquery->effect('slideUp');
$expected = '$("#foo").slideUp();';
$this->assertEqual($expected, $result);
}
/**
* Test Request Generation
*
* @return void
*/
public function testRequest() {
$result = $this->Jquery->request(array('controller' => 'posts', 'action' => 'view', 1));
$expected = '$.ajax({url:"\\/posts\\/view\\/1"});';
$this->assertEqual($expected, $result);
$result = $this->Jquery->request(array('controller' => 'posts', 'action' => 'view', 1), array(
'update' => '#content'
));
$expected = '$.ajax({dataType:"html", success:function (data, textStatus) {$("#content").html(data);}, url:"\/posts\/view\/1"});';
$this->assertEqual($expected, $result);
$result = $this->Jquery->request('/people/edit/1', array(
'method' => 'post',
'before' => 'doBefore',
'complete' => 'doComplete',
'success' => 'doSuccess',
'error' => 'handleError',
'type' => 'json',
'data' => array('name' => 'jim', 'height' => '185cm'),
'wrapCallbacks' => false
));
$expected = '$.ajax({beforeSend:doBefore, complete:doComplete, data:"name=jim&height=185cm", dataType:"json", error:handleError, success:doSuccess, type:"post", url:"\\/people\\/edit\\/1"});';
$this->assertEqual($expected, $result);
$result = $this->Jquery->request('/people/edit/1', array(
'update' => '#updated',
'success' => 'doFoo',
'method' => 'post',
'wrapCallbacks' => false
));
$expected = '$.ajax({dataType:"html", success:function (data, textStatus) {doFoo$("#updated").html(data);}, type:"post", url:"\\/people\\/edit\\/1"});';
$this->assertEqual($expected, $result);
$result = $this->Jquery->request('/people/edit/1', array(
'update' => '#updated',
'success' => 'doFoo',
'method' => 'post',
'dataExpression' => true,
'data' => '$("#someId").serialize()',
'wrapCallbacks' => false
));
$expected = '$.ajax({data:$("#someId").serialize(), dataType:"html", success:function (data, textStatus) {doFoo$("#updated").html(data);}, type:"post", url:"\\/people\\/edit\\/1"});';
$this->assertEqual($expected, $result);
$result = $this->Jquery->request('/people/edit/1', array(
'success' => 'doFoo',
'before' => 'doBefore',
'method' => 'post',
'dataExpression' => true,
'data' => '$("#someId").serialize()',
));
$expected = '$.ajax({beforeSend:function (XMLHttpRequest) {doBefore}, data:$("#someId").serialize(), success:function (data, textStatus) {doFoo}, type:"post", url:"\\/people\\/edit\\/1"});';
$this->assertEqual($expected, $result);
}
/**
* test that alternate jQuery object values work for request()
*
* @return void
*/
public function testRequestWithAlternateJqueryObject() {
$this->Jquery->jQueryObject = '$j';
$result = $this->Jquery->request('/people/edit/1', array(
'update' => '#updated',
'success' => 'doFoo',
'method' => 'post',
'dataExpression' => true,
'data' => '$j("#someId").serialize()',
'wrapCallbacks' => false
));
$expected = '$j.ajax({data:$j("#someId").serialize(), dataType:"html", success:function (data, textStatus) {doFoo$j("#updated").html(data);}, type:"post", url:"\\/people\\/edit\\/1"});';
$this->assertEqual($expected, $result);
}
/**
* test sortable list generation
*
* @return void
*/
public function testSortable() {
$this->Jquery->get('#myList');
$result = $this->Jquery->sortable(array(
'distance' => 5,
'containment' => 'parent',
'start' => 'onStart',
'complete' => 'onStop',
'sort' => 'onSort',
'wrapCallbacks' => false
));
$expected = '$("#myList").sortable({containment:"parent", distance:5, sort:onSort, start:onStart, stop:onStop});';
$this->assertEqual($expected, $result);
$result = $this->Jquery->sortable(array(
'distance' => 5,
'containment' => 'parent',
'start' => 'onStart',
'complete' => 'onStop',
'sort' => 'onSort',
));
$expected = '$("#myList").sortable({containment:"parent", distance:5, sort:function (event, ui) {onSort}, start:function (event, ui) {onStart}, stop:function (event, ui) {onStop}});';
$this->assertEqual($expected, $result);
}
/**
* test drag() method
*
* @return void
*/
public function testDrag() {
$this->Jquery->get('#element');
$result = $this->Jquery->drag(array(
'container' => '#content',
'start' => 'onStart',
'drag' => 'onDrag',
'stop' => 'onStop',
'snapGrid' => array(10, 10),
'wrapCallbacks' => false
));
$expected = '$("#element").draggable({containment:"#content", drag:onDrag, grid:[10,10], start:onStart, stop:onStop});';
$this->assertEqual($expected, $result);
$result = $this->Jquery->drag(array(
'container' => '#content',
'start' => 'onStart',
'drag' => 'onDrag',
'stop' => 'onStop',
'snapGrid' => array(10, 10),
));
$expected = '$("#element").draggable({containment:"#content", drag:function (event, ui) {onDrag}, grid:[10,10], start:function (event, ui) {onStart}, stop:function (event, ui) {onStop}});';
$this->assertEqual($expected, $result);
}
/**
* test drop() method
*
* @return void
*/
public function testDrop() {
$this->Jquery->get('#element');
$result = $this->Jquery->drop(array(
'accept' => '.items',
'hover' => 'onHover',
'leave' => 'onExit',
'drop' => 'onDrop',
'wrapCallbacks' => false
));
$expected = '$("#element").droppable({accept:".items", drop:onDrop, out:onExit, over:onHover});';
$this->assertEqual($expected, $result);
$result = $this->Jquery->drop(array(
'accept' => '.items',
'hover' => 'onHover',
'leave' => 'onExit',
'drop' => 'onDrop',
));
$expected = '$("#element").droppable({accept:".items", drop:function (event, ui) {onDrop}, out:function (event, ui) {onExit}, over:function (event, ui) {onHover}});';
$this->assertEqual($expected, $result);
}
/**
* test slider generation
*
* @return void
*/
public function testSlider() {
$this->Jquery->get('#element');
$result = $this->Jquery->slider(array(
'complete' => 'onComplete',
'change' => 'onChange',
'min' => 0,
'max' => 10,
'value' => 2,
'direction' => 'vertical',
'wrapCallbacks' => false
));
$expected = '$("#element").slider({change:onChange, max:10, min:0, orientation:"vertical", stop:onComplete, value:2});';
$this->assertEqual($expected, $result);
$result = $this->Jquery->slider(array(
'complete' => 'onComplete',
'change' => 'onChange',
'min' => 0,
'max' => 10,
'value' => 2,
'direction' => 'vertical',
));
$expected = '$("#element").slider({change:function (event, ui) {onChange}, max:10, min:0, orientation:"vertical", stop:function (event, ui) {onComplete}, value:2});';
$this->assertEqual($expected, $result);
}
/**
* test the serializeForm method
*
* @return void
*/
public function testSerializeForm() {
$this->Jquery->get('#element');
$result = $this->Jquery->serializeForm(array('isForm' => false));
$expected = '$("#element").closest("form").serialize();';
$this->assertEqual($expected, $result);
$result = $this->Jquery->serializeForm(array('isForm' => true));
$expected = '$("#element").serialize();';
$this->assertEqual($expected, $result);
$result = $this->Jquery->serializeForm(array('isForm' => false, 'inline' => true));
$expected = '$("#element").closest("form").serialize()';
$this->assertEqual($expected, $result);
}
}
| 0001-bee | trunk/cakephp2/lib/Cake/Test/Case/View/Helper/JqueryEngineHelperTest.php | PHP | gpl3 | 11,551 |
<?php
/**
* ThemeViewTest file
*
* PHP 5
*
* CakePHP(tm) Tests <http://book.cakephp.org/view/1196/Testing>
* Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice
*
* @copyright Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://book.cakephp.org/view/1196/Testing CakePHP(tm) Tests
* @package Cake.Test.Case.View
* @since CakePHP(tm) v 1.2.0.4206
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
App::uses('View', 'View');
App::uses('ThemeView', 'View');
App::uses('Controller', 'Controller');
/**
* ThemePostsController class
*
* @package Cake.Test.Case.View
*/
class ThemePostsController extends Controller {
/**
* name property
*
* @var string 'ThemePosts'
*/
public $name = 'ThemePosts';
public $theme = null;
/**
* index method
*
* @return void
*/
public function index() {
$this->set('testData', 'Some test data');
$test2 = 'more data';
$test3 = 'even more data';
$this->set(compact('test2', 'test3'));
}
}
/**
* TestThemeView class
*
* @package Cake.Test.Case.View
*/
class TestThemeView extends ThemeView {
/**
* renderElement method
*
* @param mixed $name
* @param array $params
* @return void
*/
public function renderElement($name, $params = array()) {
return $name;
}
/**
* getViewFileName method
*
* @param mixed $name
* @return void
*/
public function getViewFileName($name = null) {
return $this->_getViewFileName($name);
}
/**
* getLayoutFileName method
*
* @param mixed $name
* @return void
*/
public function getLayoutFileName($name = null) {
return $this->_getLayoutFileName($name);
}
}
/**
* ThemeViewTest class
*
* @package Cake.Test.Case.View
*/
class ThemeViewTest extends CakeTestCase {
/**
* setUp method
*
* @return void
*/
public function setUp() {
parent::setUp();
$request = new CakeRequest('posts/index');
$this->Controller = new Controller($request);
$this->PostsController = new ThemePostsController($request);
$this->PostsController->viewPath = 'posts';
$this->PostsController->index();
$this->ThemeView = new ThemeView($this->PostsController);
App::build(array(
'plugins' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS),
'View' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'View'. DS)
));
App::objects('plugins', null, false);
CakePlugin::loadAll();
}
/**
* tearDown method
*
* @return void
*/
public function tearDown() {
parent::tearDown();
unset($this->ThemeView);
unset($this->PostsController);
unset($this->Controller);
CakePlugin::unload();
}
/**
* testPluginGetTemplate method
*
* @return void
*/
public function testPluginThemedGetTemplate() {
$this->Controller->plugin = 'TestPlugin';
$this->Controller->name = 'TestPlugin';
$this->Controller->viewPath = 'Tests';
$this->Controller->action = 'index';
$this->Controller->theme = 'TestTheme';
$ThemeView = new TestThemeView($this->Controller);
$expected = CAKE . 'Test' . DS . 'test_app' . DS . 'View' . DS . 'Themed' . DS . 'TestTheme' . DS . 'Plugin' . DS . 'TestPlugin' . DS . 'Tests' . DS .'index.ctp';
$result = $ThemeView->getViewFileName('index');
$this->assertEqual($expected, $result);
$expected = CAKE . 'Test' . DS . 'test_app' . DS . 'View' . DS . 'Themed' . DS . 'TestTheme' . DS . 'Plugin' . DS . 'TestPlugin' . DS . 'Layouts' . DS .'plugin_default.ctp';
$result = $ThemeView->getLayoutFileName('plugin_default');
$this->assertEqual($expected, $result);
$expected = CAKE . 'Test' . DS . 'test_app' . DS . 'View' . DS . 'Themed' . DS . 'TestTheme' . DS . 'Layouts' . DS .'default.ctp';
$result = $ThemeView->getLayoutFileName('default');
$this->assertEqual($expected, $result);
}
/**
* testGetTemplate method
*
* @return void
*/
public function testGetTemplate() {
$this->Controller->plugin = null;
$this->Controller->name = 'Pages';
$this->Controller->viewPath = 'Pages';
$this->Controller->action = 'display';
$this->Controller->params['pass'] = array('home');
$ThemeView = new TestThemeView($this->Controller);
$ThemeView->theme = 'TestTheme';
$expected = CAKE . 'Test' . DS . 'test_app' . DS . 'View' . DS .'Pages' . DS .'home.ctp';
$result = $ThemeView->getViewFileName('home');
$this->assertEqual($expected, $result);
$expected = CAKE . 'Test' . DS . 'test_app' . DS . 'View' . DS . 'Themed' . DS . 'TestTheme' . DS . 'Posts' . DS .'index.ctp';
$result = $ThemeView->getViewFileName('/Posts/index');
$this->assertEqual($expected, $result);
$expected = CAKE . 'Test' . DS . 'test_app' . DS . 'View' . DS . 'Themed' . DS . 'TestTheme' . DS . 'Layouts' . DS .'default.ctp';
$result = $ThemeView->getLayoutFileName();
$this->assertEqual($expected, $result);
$ThemeView->layoutPath = 'rss';
$expected = CAKE . 'Test' . DS . 'test_app' . DS . 'View' . DS . 'Layouts' . DS . 'rss' . DS . 'default.ctp';
$result = $ThemeView->getLayoutFileName();
$this->assertEqual($expected, $result);
$ThemeView->layoutPath = 'Emails' . DS . 'html';
$expected = CAKE . 'Test' . DS . 'test_app' . DS . 'View' . DS . 'Layouts' . DS . 'Emails' . DS . 'html' . DS . 'default.ctp';
$result = $ThemeView->getLayoutFileName();
$this->assertEqual($expected, $result);
}
/**
* testMissingView method
*
* @expectedException MissingViewException
* @return void
*/
public function testMissingView() {
$this->Controller->plugin = null;
$this->Controller->name = 'Pages';
$this->Controller->viewPath = 'Pages';
$this->Controller->action = 'display';
$this->Controller->theme = 'my_theme';
$this->Controller->params['pass'] = array('home');
$View = new TestThemeView($this->Controller);
ob_start();
$result = $View->getViewFileName('does_not_exist');
$expected = str_replace(array("\t", "\r\n", "\n"), "", ob_get_clean());
$this->assertPattern("/PagesController::/", $expected);
$this->assertPattern("/views(\/|\\\)themed(\/|\\\)my_theme(\/|\\\)pages(\/|\\\)does_not_exist.ctp/", $expected);
}
/**
* testMissingLayout method
*
* @expectedException MissingLayoutException
* @return void
*/
public function testMissingLayout() {
$this->Controller->plugin = null;
$this->Controller->name = 'Posts';
$this->Controller->viewPath = 'posts';
$this->Controller->layout = 'whatever';
$this->Controller->theme = 'my_theme';
$View = new TestThemeView($this->Controller);
ob_start();
$result = $View->getLayoutFileName();
$expected = str_replace(array("\t", "\r\n", "\n"), "", ob_get_clean());
$this->assertPattern("/Missing Layout/", $expected);
$this->assertPattern("/views(\/|\\\)themed(\/|\\\)my_theme(\/|\\\)layouts(\/|\\\)whatever.ctp/", $expected);
}
/**
* test memory leaks that existed in _paths at one point.
*
* @return void
*/
public function testMemoryLeakInPaths() {
$this->Controller->plugin = null;
$this->Controller->name = 'Posts';
$this->Controller->viewPath = 'posts';
$this->Controller->layout = 'whatever';
$this->Controller->theme = 'TestTheme';
$View = new ThemeView($this->Controller);
$View->element('test_element');
$start = memory_get_usage();
for ($i = 0; $i < 10; $i++) {
$View->element('test_element');
}
$end = memory_get_usage();
$this->assertLessThanOrEqual($start + 5000, $end);
}
}
| 0001-bee | trunk/cakephp2/lib/Cake/Test/Case/View/ThemeViewTest.php | PHP | gpl3 | 7,489 |
<?php
/**
* AllModelTest file
*
* PHP 5
*
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
* Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://cakephp.org CakePHP(tm) Project
* @package Cake.Test.Case
* @since CakePHP(tm) v 2.0
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
/**
* AllModelTest class
*
* This test group will run model class tests
*
* @package Cake.Test.Case
*/
class AllModelTest extends PHPUnit_Framework_TestSuite {
/**
* suite method, defines tests for this suite.
*
* @return void
*/
public static function suite() {
$suite = new PHPUnit_Framework_TestSuite('All Model related class tests');
$suite->addTestFile(CORE_TEST_CASES . DS . 'Model' . DS . 'ModelReadTest.php');
$suite->addTestFile(CORE_TEST_CASES . DS . 'Model' . DS . 'ModelWriteTest.php');
$suite->addTestFile(CORE_TEST_CASES . DS . 'Model' . DS . 'ModelDeleteTest.php');
$suite->addTestFile(CORE_TEST_CASES . DS . 'Model' . DS . 'ModelValidationTest.php');
$suite->addTestFile(CORE_TEST_CASES . DS . 'Model' . DS . 'ModelIntegrationTest.php');
return $suite;
}
} | 0001-bee | trunk/cakephp2/lib/Cake/Test/Case/AllModelTest.php | PHP | gpl3 | 1,421 |
<?php
/**
* ObjectCollectionTest file
*
* PHP 5
*
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
* Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://book.cakephp.org/view/1196/Testing CakePHP(tm) Tests
* @package Cake.Test.Case.Utility
* @since CakePHP(tm) v 2.0
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
App::uses('ObjectCollection', 'Utility');
/**
* A generic object class
*/
class GenericObject {
}
/**
* First Extension of Generic Object
*/
class FirstGenericObject extends GenericObject {
/**
* A generic callback
*/
public function callback() {
}
}
/**
* Second Extension of Generic Object
*/
class SecondGenericObject extends GenericObject {
public function callback() {
}
}
/**
* A collection of Generic objects
*/
class GenericObjectCollection extends ObjectCollection {
/**
* Loads a generic object
*
* @param string $object Object name
* @param array $settings Settings array
* @return array List of loaded objects
*/
public function load($object, $settings = array()) {
list($plugin, $name) = pluginSplit($object);
if (isset($this->_loaded[$name])) {
return $this->_loaded[$name];
}
$objectClass = $name . 'GenericObject';
$this->_loaded[$name] = new $objectClass($this, $settings);
$enable = isset($settings['enabled']) ? $settings['enabled'] : true;
if ($enable === true) {
$this->_enabled[] = $name;
}
return $this->_loaded[$name];
}
}
class ObjectCollectionTest extends CakeTestCase {
/**
* setup
*
* @return void
*/
public function setup() {
$this->Objects = new GenericObjectCollection();
}
/**
* teardown
*
* @return void
*/
public function teardown() {
unset($this->Objects);
}
/**
* test triggering callbacks on loaded helpers
*
* @return void
*/
public function testLoad() {
$result = $this->Objects->load('First');
$this->assertInstanceOf('FirstGenericObject', $result);
$this->assertInstanceOf('FirstGenericObject', $this->Objects->First);
$result = $this->Objects->attached();
$this->assertEquals(array('First'), $result, 'attached() results are wrong.');
$this->assertTrue($this->Objects->enabled('First'));
$result = $this->Objects->load('First');
$this->assertSame($result, $this->Objects->First);
}
/**
* test unload()
*
* @return void
*/
public function testUnload() {
$this->Objects->load('First');
$this->Objects->load('Second');
$result = $this->Objects->attached();
$this->assertEquals(array('First', 'Second'), $result, 'loaded objects are wrong');
$this->Objects->unload('First');
$this->assertFalse(isset($this->Objects->First));
$this->assertTrue(isset($this->Objects->Second));
$result = $this->Objects->attached();
$this->assertEquals(array('Second'), $result, 'loaded objects are wrong');
$result = $this->Objects->enabled();
$this->assertEquals(array('Second'), $result, 'enabled objects are wrong');
}
/**
* Tests set()
*
* @return void
*/
public function testSet() {
$this->Objects->load('First');
$result = $this->Objects->attached();
$this->assertEquals(array('First'), $result, 'loaded objects are wrong');
$result = $this->Objects->set('First', new SecondGenericObject());
$this->assertIsA($result['First'], 'SecondGenericObject', 'set failed');
$result = $this->Objects->set('Second', new SecondGenericObject());
$this->assertIsA($result['Second'], 'SecondGenericObject', 'set failed');
$this->assertEquals(count($result), 2);
}
/**
* creates mock classes for testing
*
* @return void
*/
protected function _makeMockClasses() {
if (!class_exists('TriggerMockFirstGenericObject')) {
$this->getMock('FirstGenericObject', array(), array(), 'TriggerMockFirstGenericObject', false);
}
if (!class_exists('TriggerMockSecondGenericObject')) {
$this->getMock('SecondGenericObject', array(), array(), 'TriggerMockSecondGenericObject', false);
}
}
/**
* test triggering callbacks.
*
* @return void
*/
public function testTrigger() {
$this->_makeMockClasses();
$this->Objects->load('TriggerMockFirst');
$this->Objects->load('TriggerMockSecond');
$this->mockObjects[] = $this->Objects->TriggerMockFirst;
$this->mockObjects[] = $this->Objects->TriggerMockSecond;
$this->Objects->TriggerMockFirst->expects($this->once())
->method('callback')
->will($this->returnValue(true));
$this->Objects->TriggerMockSecond->expects($this->once())
->method('callback')
->will($this->returnValue(true));
$this->assertTrue($this->Objects->trigger('callback'));
}
/**
* test that the initalize callback is triggered on all components even those that are disabled.
*
* @return void
*/
public function testTriggerWithTriggerDisabledObjects() {
$this->_makeMockClasses();
$this->Objects->load('TriggerMockFirst', array(), false);
$this->Objects->load('TriggerMockSecond');
$this->mockObjects[] = $this->Objects->TriggerMockFirst;
$this->mockObjects[] = $this->Objects->TriggerMockSecond;
$this->Objects->TriggerMockFirst->expects($this->once())
->method('callback')
->will($this->returnValue(true));
$this->Objects->TriggerMockSecond->expects($this->once())
->method('callback')
->will($this->returnValue(true));
$result = $this->Objects->trigger('callback', array(), array('triggerDisabled' => true));
$this->assertTrue($result);
}
/**
* test trigger and disabled objects
*
* @return void
*/
public function testTriggerWithDisabledObjects() {
$this->_makeMockClasses();
$this->Objects->load('TriggerMockFirst');
$this->Objects->load('TriggerMockSecond');
$this->mockObjects[] = $this->Objects->TriggerMockFirst;
$this->mockObjects[] = $this->Objects->TriggerMockSecond;
$this->Objects->TriggerMockFirst->expects($this->once())
->method('callback')
->will($this->returnValue(true));
$this->Objects->TriggerMockSecond->expects($this->never())
->method('callback')
->will($this->returnValue(true));
$this->Objects->disable('TriggerMockSecond');
$this->assertTrue($this->Objects->trigger('callback', array()));
}
/**
* test that the collectReturn option works.
*
* @return void
*/
public function testTriggerWithCollectReturn() {
$this->_makeMockClasses();
$this->Objects->load('TriggerMockFirst');
$this->Objects->load('TriggerMockSecond');
$this->mockObjects[] = $this->Objects->TriggerMockFirst;
$this->mockObjects[] = $this->Objects->TriggerMockSecond;
$this->Objects->TriggerMockFirst->expects($this->once())
->method('callback')
->will($this->returnValue(array('one', 'two')));
$this->Objects->TriggerMockSecond->expects($this->once())
->method('callback')
->will($this->returnValue(array('three', 'four')));
$result = $this->Objects->trigger('callback', array(), array('collectReturn' => true));
$expected = array(
array('one', 'two'),
array('three', 'four')
);
$this->assertEquals($expected, $result);
}
/**
* test that trigger with break & breakOn works.
*
* @return void
*/
public function testTriggerWithBreak() {
$this->_makeMockClasses();
$this->Objects->load('TriggerMockFirst');
$this->Objects->load('TriggerMockSecond');
$this->mockObjects[] = $this->Objects->TriggerMockFirst;
$this->mockObjects[] = $this->Objects->TriggerMockSecond;
$this->Objects->TriggerMockFirst->expects($this->once())
->method('callback')
->will($this->returnValue(false));
$this->Objects->TriggerMockSecond->expects($this->never())
->method('callback');
$result = $this->Objects->trigger(
'callback',
array(),
array('break' => true, 'breakOn' => false)
);
$this->assertFalse($result);
}
/**
* test that trigger with modParams works.
*
* @return void
*/
public function testTriggerWithModParams() {
$this->_makeMockClasses();
$this->Objects->load('TriggerMockFirst');
$this->Objects->load('TriggerMockSecond');
$this->mockObjects[] = $this->Objects->TriggerMockFirst;
$this->mockObjects[] = $this->Objects->TriggerMockSecond;
$this->Objects->TriggerMockFirst->expects($this->once())
->method('callback')
->with(array('value'))
->will($this->returnValue(array('new value')));
$this->Objects->TriggerMockSecond->expects($this->once())
->method('callback')
->with(array('new value'))
->will($this->returnValue(array('newer value')));
$result = $this->Objects->trigger(
'callback',
array(array('value')),
array('modParams' => 0)
);
$this->assertEquals(array('newer value'), $result);
}
/**
* test that setting modParams to an index that doesn't exist doesn't cause errors.
*
* @expectedException CakeException
* @return void
*/
public function testTriggerModParamsInvalidIndex() {
$this->_makeMockClasses();
$this->Objects->load('TriggerMockFirst');
$this->Objects->load('TriggerMockSecond');
$this->mockObjects[] = $this->Objects->TriggerMockFirst;
$this->mockObjects[] = $this->Objects->TriggerMockSecond;
$this->Objects->TriggerMockFirst->expects($this->never())
->method('callback');
$this->Objects->TriggerMockSecond->expects($this->never())
->method('callback');
$result = $this->Objects->trigger(
'callback',
array(array('value')),
array('modParams' => 2)
);
}
/**
* test that returrning null doesn't modify parameters.
*
* @return void
*/
public function testTriggerModParamsNullIgnored() {
$this->_makeMockClasses();
$this->Objects->load('TriggerMockFirst');
$this->Objects->load('TriggerMockSecond');
$this->mockObjects[] = $this->Objects->TriggerMockFirst;
$this->mockObjects[] = $this->Objects->TriggerMockSecond;
$this->Objects->TriggerMockFirst->expects($this->once())
->method('callback')
->with(array('value'))
->will($this->returnValue(null));
$this->Objects->TriggerMockSecond->expects($this->once())
->method('callback')
->with(array('value'))
->will($this->returnValue(array('new value')));
$result = $this->Objects->trigger(
'callback',
array(array('value')),
array('modParams' => 0)
);
$this->assertEquals(array('new value'), $result);
}
/**
* test normalizeObjectArray
*
* @return void
*/
public function testnormalizeObjectArray() {
$components = array(
'Html',
'Foo.Bar' => array('one', 'two'),
'Something',
'Banana.Apple' => array('foo' => 'bar')
);
$result = ObjectCollection::normalizeObjectArray($components);
$expected = array(
'Html' => array('class' => 'Html', 'settings' => array()),
'Bar' => array('class' => 'Foo.Bar', 'settings' => array('one', 'two')),
'Something' => array('class' => 'Something', 'settings' => array()),
'Apple' => array('class' => 'Banana.Apple', 'settings' => array('foo' => 'bar')),
);
$this->assertEquals($expected, $result);
// This is the result after Controller::_mergeVars
$components = array(
'Html' => null,
'Foo.Bar' => array('one', 'two'),
'Something' => null,
'Banana.Apple' => array('foo' => 'bar')
);
$result = ObjectCollection::normalizeObjectArray($components);
$this->assertEquals($expected, $result);
}
} | 0001-bee | trunk/cakephp2/lib/Cake/Test/Case/Utility/ObjectCollectionTest.php | PHP | gpl3 | 11,348 |
<?php
/**
* InflectorTest
*
* InflectorTest is used to test cases on the Inflector class
*
* PHP 5
*
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
* Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The Open Group Test Suite License
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://book.cakephp.org/view/1196/Testing
* @package Cake.Test.Case.Utility
* @since CakePHP(tm) v 1.2.0.4206
* @license Open Group Test Suite License (http://www.opensource.org/licenses/opengroup.php)
*/
/**
* Included libraries.
*
*/
App::uses('Inflector', 'Utility');
/**
* Short description for class.
*
* @package cake.tests
* @package Cake.Test.Case.Utility
*/
class InflectorTest extends CakeTestCase {
/**
* teardown
*
* @return void
*/
public function tearDown() {
parent::tearDown();
Inflector::reset();
}
/**
* testInflectingSingulars method
*
* @return void
*/
public function testInflectingSingulars() {
$this->assertEqual(Inflector::singularize('categorias'), 'categoria');
$this->assertEqual(Inflector::singularize('menus'), 'menu');
$this->assertEqual(Inflector::singularize('news'), 'news');
$this->assertEqual(Inflector::singularize('food_menus'), 'food_menu');
$this->assertEqual(Inflector::singularize('Menus'), 'Menu');
$this->assertEqual(Inflector::singularize('FoodMenus'), 'FoodMenu');
$this->assertEqual(Inflector::singularize('houses'), 'house');
$this->assertEqual(Inflector::singularize('powerhouses'), 'powerhouse');
$this->assertEqual(Inflector::singularize('quizzes'), 'quiz');
$this->assertEqual(Inflector::singularize('Buses'), 'Bus');
$this->assertEqual(Inflector::singularize('buses'), 'bus');
$this->assertEqual(Inflector::singularize('matrix_rows'), 'matrix_row');
$this->assertEqual(Inflector::singularize('matrices'), 'matrix');
$this->assertEqual(Inflector::singularize('vertices'), 'vertex');
$this->assertEqual(Inflector::singularize('indices'), 'index');
$this->assertEqual(Inflector::singularize('Aliases'), 'Alias');
$this->assertEqual(Inflector::singularize('Alias'), 'Alias');
$this->assertEqual(Inflector::singularize('Media'), 'Media');
$this->assertEqual(Inflector::singularize('alumni'), 'alumnus');
$this->assertEqual(Inflector::singularize('bacilli'), 'bacillus');
$this->assertEqual(Inflector::singularize('cacti'), 'cactus');
$this->assertEqual(Inflector::singularize('foci'), 'focus');
$this->assertEqual(Inflector::singularize('fungi'), 'fungus');
$this->assertEqual(Inflector::singularize('nuclei'), 'nucleus');
$this->assertEqual(Inflector::singularize('octopuses'), 'octopus');
$this->assertEqual(Inflector::singularize('radii'), 'radius');
$this->assertEqual(Inflector::singularize('stimuli'), 'stimulus');
$this->assertEqual(Inflector::singularize('syllabi'), 'syllabus');
$this->assertEqual(Inflector::singularize('termini'), 'terminus');
$this->assertEqual(Inflector::singularize('viri'), 'virus');
$this->assertEqual(Inflector::singularize('people'), 'person');
$this->assertEqual(Inflector::singularize('gloves'), 'glove');
$this->assertEqual(Inflector::singularize('doves'), 'dove');
$this->assertEqual(Inflector::singularize('lives'), 'life');
$this->assertEqual(Inflector::singularize('knives'), 'knife');
$this->assertEqual(Inflector::singularize('wolves'), 'wolf');
$this->assertEqual(Inflector::singularize('slaves'), 'slave');
$this->assertEqual(Inflector::singularize('shelves'), 'shelf');
$this->assertEqual(Inflector::singularize('taxis'), 'taxi');
$this->assertEqual(Inflector::singularize('taxes'), 'tax');
$this->assertEqual(Inflector::singularize('Taxes'), 'Tax');
$this->assertEqual(Inflector::singularize('AwesomeTaxes'), 'AwesomeTax');
$this->assertEqual(Inflector::singularize('faxes'), 'fax');
$this->assertEqual(Inflector::singularize('waxes'), 'wax');
$this->assertEqual(Inflector::singularize('niches'), 'niche');
$this->assertEqual(Inflector::singularize('waves'), 'wave');
$this->assertEqual(Inflector::singularize('bureaus'), 'bureau');
$this->assertEqual(Inflector::singularize('genetic_analyses'), 'genetic_analysis');
$this->assertEqual(Inflector::singularize('doctor_diagnoses'), 'doctor_diagnosis');
$this->assertEqual(Inflector::singularize('parantheses'), 'paranthesis');
$this->assertEqual(Inflector::singularize('Causes'), 'Cause');
$this->assertEqual(Inflector::singularize('colossuses'), 'colossus');
$this->assertEqual(Inflector::singularize('diagnoses'), 'diagnosis');
$this->assertEqual(Inflector::singularize('bases'), 'basis');
$this->assertEqual(Inflector::singularize('analyses'), 'analysis');
$this->assertEqual(Inflector::singularize('curves'), 'curve');
$this->assertEqual(Inflector::singularize('cafes'), 'cafe');
$this->assertEqual(Inflector::singularize('roofs'), 'roof');
$this->assertEqual(Inflector::singularize(''), '');
}
/**
* testInflectingPlurals method
*
* @return void
*/
public function testInflectingPlurals() {
$this->assertEqual(Inflector::pluralize('categoria'), 'categorias');
$this->assertEqual(Inflector::pluralize('house'), 'houses');
$this->assertEqual(Inflector::pluralize('powerhouse'), 'powerhouses');
$this->assertEqual(Inflector::pluralize('Bus'), 'Buses');
$this->assertEqual(Inflector::pluralize('bus'), 'buses');
$this->assertEqual(Inflector::pluralize('menu'), 'menus');
$this->assertEqual(Inflector::pluralize('news'), 'news');
$this->assertEqual(Inflector::pluralize('food_menu'), 'food_menus');
$this->assertEqual(Inflector::pluralize('Menu'), 'Menus');
$this->assertEqual(Inflector::pluralize('FoodMenu'), 'FoodMenus');
$this->assertEqual(Inflector::pluralize('quiz'), 'quizzes');
$this->assertEqual(Inflector::pluralize('matrix_row'), 'matrix_rows');
$this->assertEqual(Inflector::pluralize('matrix'), 'matrices');
$this->assertEqual(Inflector::pluralize('vertex'), 'vertices');
$this->assertEqual(Inflector::pluralize('index'), 'indices');
$this->assertEqual(Inflector::pluralize('Alias'), 'Aliases');
$this->assertEqual(Inflector::pluralize('Aliases'), 'Aliases');
$this->assertEqual(Inflector::pluralize('Media'), 'Media');
$this->assertEqual(Inflector::pluralize('alumnus'), 'alumni');
$this->assertEqual(Inflector::pluralize('bacillus'), 'bacilli');
$this->assertEqual(Inflector::pluralize('cactus'), 'cacti');
$this->assertEqual(Inflector::pluralize('focus'), 'foci');
$this->assertEqual(Inflector::pluralize('fungus'), 'fungi');
$this->assertEqual(Inflector::pluralize('nucleus'), 'nuclei');
$this->assertEqual(Inflector::pluralize('octopus'), 'octopuses');
$this->assertEqual(Inflector::pluralize('radius'), 'radii');
$this->assertEqual(Inflector::pluralize('stimulus'), 'stimuli');
$this->assertEqual(Inflector::pluralize('syllabus'), 'syllabi');
$this->assertEqual(Inflector::pluralize('terminus'), 'termini');
$this->assertEqual(Inflector::pluralize('virus'), 'viri');
$this->assertEqual(Inflector::pluralize('person'), 'people');
$this->assertEqual(Inflector::pluralize('people'), 'people');
$this->assertEqual(Inflector::pluralize('glove'), 'gloves');
$this->assertEqual(Inflector::pluralize('crisis'), 'crises');
$this->assertEqual(Inflector::pluralize('tax'), 'taxes');
$this->assertEqual(Inflector::pluralize('wave'), 'waves');
$this->assertEqual(Inflector::pluralize('bureau'), 'bureaus');
$this->assertEqual(Inflector::pluralize('cafe'), 'cafes');
$this->assertEqual(Inflector::pluralize('roof'), 'roofs');
$this->assertEqual(Inflector::pluralize(''), '');
}
/**
* testInflectorSlug method
*
* @return void
*/
public function testInflectorSlug() {
$result = Inflector::slug('Foo Bar: Not just for breakfast any-more');
$expected = 'Foo_Bar_Not_just_for_breakfast_any_more';
$this->assertEqual($expected, $result);
$result = Inflector::slug('this/is/a/path');
$expected = 'this_is_a_path';
$this->assertEqual($expected, $result);
$result = Inflector::slug('Foo Bar: Not just for breakfast any-more', "-");
$expected = 'Foo-Bar-Not-just-for-breakfast-any-more';
$this->assertEqual($expected, $result);
$result = Inflector::slug('Foo Bar: Not just for breakfast any-more', "+");
$expected = 'Foo+Bar+Not+just+for+breakfast+any+more';
$this->assertEqual($expected, $result);
$result = Inflector::slug('Äpfel Über Öl grün ärgert groß öko', '-');
$expected = 'Aepfel-Ueber-Oel-gruen-aergert-gross-oeko';
$this->assertEqual($expected, $result);
$result = Inflector::slug('The truth - and- more- news', '-');
$expected = 'The-truth-and-more-news';
$this->assertEqual($expected, $result);
$result = Inflector::slug('The truth: and more news', '-');
$expected = 'The-truth-and-more-news';
$this->assertEqual($expected, $result);
$result = Inflector::slug('La langue française est un attribut de souveraineté en France', '-');
$expected = 'La-langue-francaise-est-un-attribut-de-souverainete-en-France';
$this->assertEqual($expected, $result);
$result = Inflector::slug('!@$#exciting stuff! - what !@-# was that?', '-');
$expected = 'exciting-stuff-what-was-that';
$this->assertEqual($expected, $result);
$result = Inflector::slug('20% of profits went to me!', '-');
$expected = '20-of-profits-went-to-me';
$this->assertEqual($expected, $result);
$result = Inflector::slug('#this melts your face1#2#3', '-');
$expected = 'this-melts-your-face1-2-3';
$this->assertEqual($expected, $result);
$result = Inflector::slug('controller/action/りんご/1');
$expected = 'controller_action_りんご_1';
$this->assertEqual($expected, $result);
$result = Inflector::slug('の話が出たので大丈夫かなあと');
$expected = 'の話が出たので大丈夫かなあと';
$this->assertEqual($expected, $result);
$result = Inflector::slug('posts/view/한국어/page:1/sort:asc');
$expected = 'posts_view_한국어_page_1_sort_asc';
$this->assertEqual($expected, $result);
}
/**
* testInflectorSlugWithMap method
*
* @return void
*/
public function testInflectorSlugWithMap() {
Inflector::rules('transliteration', array('/r/' => '1'));
$result = Inflector::slug('replace every r');
$expected = '1eplace_eve1y_1';
$this->assertEqual($expected, $result);
$result = Inflector::slug('replace every r', '_');
$expected = '1eplace_eve1y_1';
$this->assertEqual($expected, $result);
}
/**
* testInflectorSlugWithMapOverridingDefault method
*
* @return void
*/
public function testInflectorSlugWithMapOverridingDefault() {
Inflector::rules('transliteration', array('/å/' => 'aa', '/ø/' => 'oe'));
$result = Inflector::slug('Testing æ ø å', '-');
$expected = 'Testing-ae-oe-aa';
$this->assertEqual($expected, $result);
}
/**
* testInflectorUnderscore method
*
* @return void
*/
public function testInflectorUnderscore() {
$this->assertIdentical(Inflector::underscore('TestThing'), 'test_thing');
$this->assertIdentical(Inflector::underscore('testThing'), 'test_thing');
$this->assertIdentical(Inflector::underscore('TestThingExtra'), 'test_thing_extra');
$this->assertIdentical(Inflector::underscore('testThingExtra'), 'test_thing_extra');
// Identical checks test the cache code path.
$this->assertIdentical(Inflector::underscore('TestThing'), 'test_thing');
$this->assertIdentical(Inflector::underscore('testThing'), 'test_thing');
$this->assertIdentical(Inflector::underscore('TestThingExtra'), 'test_thing_extra');
$this->assertIdentical(Inflector::underscore('testThingExtra'), 'test_thing_extra');
// Test stupid values
$this->assertIdentical(Inflector::underscore(''), '');
$this->assertIdentical(Inflector::underscore(0), '0');
$this->assertIdentical(Inflector::underscore(false), '');
}
/**
* testVariableNaming method
*
* @return void
*/
public function testVariableNaming() {
$this->assertEqual(Inflector::variable('test_field'), 'testField');
$this->assertEqual(Inflector::variable('test_fieLd'), 'testFieLd');
$this->assertEqual(Inflector::variable('test field'), 'testField');
$this->assertEqual(Inflector::variable('Test_field'), 'testField');
}
/**
* testClassNaming method
*
* @return void
*/
public function testClassNaming() {
$this->assertEqual(Inflector::classify('artists_genres'), 'ArtistsGenre');
$this->assertEqual(Inflector::classify('file_systems'), 'FileSystem');
$this->assertEqual(Inflector::classify('news'), 'News');
$this->assertEqual(Inflector::classify('bureaus'), 'Bureau');
}
/**
* testTableNaming method
*
* @return void
*/
public function testTableNaming() {
$this->assertEqual(Inflector::tableize('ArtistsGenre'), 'artists_genres');
$this->assertEqual(Inflector::tableize('FileSystem'), 'file_systems');
$this->assertEqual(Inflector::tableize('News'), 'news');
$this->assertEqual(Inflector::tableize('Bureau'), 'bureaus');
}
/**
* testHumanization method
*
* @return void
*/
public function testHumanization() {
$this->assertEqual(Inflector::humanize('posts'), 'Posts');
$this->assertEqual(Inflector::humanize('posts_tags'), 'Posts Tags');
$this->assertEqual(Inflector::humanize('file_systems'), 'File Systems');
}
/**
* testCustomPluralRule method
*
* @return void
*/
public function testCustomPluralRule() {
Inflector::rules('plural', array('/^(custom)$/i' => '\1izables'));
$this->assertEqual(Inflector::pluralize('custom'), 'customizables');
Inflector::rules('plural', array('uninflected' => array('uninflectable')));
$this->assertEqual(Inflector::pluralize('uninflectable'), 'uninflectable');
Inflector::rules('plural', array(
'rules' => array('/^(alert)$/i' => '\1ables'),
'uninflected' => array('noflect', 'abtuse'),
'irregular' => array('amaze' => 'amazable', 'phone' => 'phonezes')
));
$this->assertEqual(Inflector::pluralize('noflect'), 'noflect');
$this->assertEqual(Inflector::pluralize('abtuse'), 'abtuse');
$this->assertEqual(Inflector::pluralize('alert'), 'alertables');
$this->assertEqual(Inflector::pluralize('amaze'), 'amazable');
$this->assertEqual(Inflector::pluralize('phone'), 'phonezes');
}
/**
* testCustomSingularRule method
*
* @return void
*/
public function testCustomSingularRule() {
Inflector::rules('singular', array('/(eple)r$/i' => '\1', '/(jente)r$/i' => '\1'));
$this->assertEqual(Inflector::singularize('epler'), 'eple');
$this->assertEqual(Inflector::singularize('jenter'), 'jente');
Inflector::rules('singular', array(
'rules' => array('/^(bil)er$/i' => '\1', '/^(inflec|contribu)tors$/i' => '\1ta'),
'uninflected' => array('singulars'),
'irregular' => array('spins' => 'spinor')
));
$this->assertEqual(Inflector::singularize('inflectors'), 'inflecta');
$this->assertEqual(Inflector::singularize('contributors'), 'contributa');
$this->assertEqual(Inflector::singularize('spins'), 'spinor');
$this->assertEqual(Inflector::singularize('singulars'), 'singulars');
}
/**
* testCustomTransliterationRule method
*
* @return void
*/
public function testCustomTransliterationRule() {
$this->assertEqual(Inflector::slug('Testing æ ø å'), 'Testing_ae_o_a');
Inflector::rules('transliteration', array('/å/' => 'aa', '/ø/' => 'oe'));
$this->assertEqual(Inflector::slug('Testing æ ø å'), 'Testing_ae_oe_aa');
Inflector::rules('transliteration', array('/ä|æ/' => 'ae', '/å/' => 'aa'), true);
$this->assertEqual(Inflector::slug('Testing æ ø å'), 'Testing_ae_ø_aa');
}
/**
* test that setting new rules clears the inflector caches.
*
* @return void
*/
public function testRulesClearsCaches() {
$this->assertEqual(Inflector::singularize('Bananas'), 'Banana');
$this->assertEqual(Inflector::tableize('Banana'), 'bananas');
$this->assertEqual(Inflector::pluralize('Banana'), 'Bananas');
Inflector::rules('singular', array(
'rules' => array('/(.*)nas$/i' => '\1zzz')
));
$this->assertEquals('Banazzz', Inflector::singularize('Bananas'), 'Was inflected with old rules.');
Inflector::rules('plural', array(
'rules' => array('/(.*)na$/i' => '\1zzz'),
'irregular' => array('corpus' => 'corpora')
));
$this->assertEqual(Inflector::pluralize('Banana'), 'Banazzz', 'Was inflected with old rules.');
$this->assertEqual(Inflector::pluralize('corpus'), 'corpora', 'Was inflected with old irregular form.');
}
/**
* Test resetting inflection rules.
*
* @return void
*/
public function testCustomRuleWithReset() {
$uninflected = array('atlas', 'lapis', 'onibus', 'pires', 'virus', '.*x');
$pluralIrregular = array('as' => 'ases');
Inflector::rules('singular', array(
'rules' => array('/^(.*)(a|e|o|u)is$/i' => '\1\2l'),
'uninflected' => $uninflected,
), true);
Inflector::rules('plural', array(
'rules' => array(
'/^(.*)(a|e|o|u)l$/i' => '\1\2is',
),
'uninflected' => $uninflected,
'irregular' => $pluralIrregular
), true);
$this->assertEqual(Inflector::pluralize('Alcool'), 'Alcoois');
$this->assertEqual(Inflector::pluralize('Atlas'), 'Atlas');
$this->assertEqual(Inflector::singularize('Alcoois'), 'Alcool');
$this->assertEqual(Inflector::singularize('Atlas'), 'Atlas');
}
}
| 0001-bee | trunk/cakephp2/lib/Cake/Test/Case/Utility/InflectorTest.php | PHP | gpl3 | 17,383 |
<?php
/**
* ValidationTest file
*
* PHP Version 5.x
*
* CakePHP(tm) Tests <http://book.cakephp.org/view/1196/Testing>
* Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The Open Group Test Suite License
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://book.cakephp.org/view/1196/Testing CakePHP(tm) Tests
* @package Cake.Test.Case.Utility
* @since CakePHP(tm) v 1.2.0.4206
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
App::uses('Validation', 'Utility');
/**
* CustomValidator class
*
* @package Cake.Test.Case.Utility
*/
class CustomValidator {
/**
* Makes sure that a given $email address is valid and unique
*
* @param string $email
* @return boolean
*/
static function customValidate($check) {
return (bool)preg_match('/^[0-9]{3}$/', $check);
}
}
/**
* TestNlValidation class
*
* Used to test pass through of Validation
*
* @package Cake.Test.Case.Utility
*/
class TestNlValidation {
/**
* postal function, for testing postal pass through.
*
* @param string $check
* @return void
*/
static function postal($check) {
return true;
}
/**
* ssn function for testing ssn pass through
*
* @return void
*/
static function ssn($check) {
return true;
}
}
/**
* TestDeValidation class
*
* Used to test pass through of Validation
*
* @package Cake.Test.Case.Utility
*/
class TestDeValidation {
/**
* phone function, for testing phone pass through.
*
* @param string $check
* @return void
*/
static function phone($check) {
return true;
}
}
/**
* Test Case for Validation Class
*
* @package Cake.Test.Case.Utility
*/
class ValidationTest extends CakeTestCase {
/**
* setup method
*
* @return void
*/
public function setUp() {
parent::setup();
$this->_appEncoding = Configure::read('App.encoding');
}
/**
* tearDown method
*
* @return void
*/
public function tearDown() {
parent::tearDown();
Configure::write('App.encoding', $this->_appEncoding);
}
/**
* testNotEmpty method
*
* @return void
*/
public function testNotEmpty() {
$this->assertTrue(Validation::notEmpty('abcdefg'));
$this->assertTrue(Validation::notEmpty('fasdf '));
$this->assertTrue(Validation::notEmpty('fooo'.chr(243).'blabla'));
$this->assertTrue(Validation::notEmpty('abçďĕʑʘπй'));
$this->assertTrue(Validation::notEmpty('José'));
$this->assertTrue(Validation::notEmpty('é'));
$this->assertTrue(Validation::notEmpty('π'));
$this->assertFalse(Validation::notEmpty("\t "));
$this->assertFalse(Validation::notEmpty(""));
}
/**
* testNotEmptyISO88591Encoding method
*
* @return void
*/
public function testNotEmptyISO88591AppEncoding() {
Configure::write('App.encoding', 'ISO-8859-1');
$this->assertTrue(Validation::notEmpty('abcdefg'));
$this->assertTrue(Validation::notEmpty('fasdf '));
$this->assertTrue(Validation::notEmpty('fooo'.chr(243).'blabla'));
$this->assertTrue(Validation::notEmpty('abçďĕʑʘπй'));
$this->assertTrue(Validation::notEmpty('José'));
$this->assertTrue(Validation::notEmpty(utf8_decode('José')));
$this->assertFalse(Validation::notEmpty("\t "));
$this->assertFalse(Validation::notEmpty(""));
}
/**
* testAlphaNumeric method
*
* @return void
*/
public function testAlphaNumeric() {
$this->assertTrue(Validation::alphaNumeric('frferrf'));
$this->assertTrue(Validation::alphaNumeric('12234'));
$this->assertTrue(Validation::alphaNumeric('1w2e2r3t4y'));
$this->assertTrue(Validation::alphaNumeric('0'));
$this->assertTrue(Validation::alphaNumeric('abçďĕʑʘπй'));
$this->assertTrue(Validation::alphaNumeric('ˇˆๆゞ'));
$this->assertTrue(Validation::alphaNumeric('אกあアꀀ豈'));
$this->assertTrue(Validation::alphaNumeric('Džᾈᾨ'));
$this->assertTrue(Validation::alphaNumeric('ÆΔΩЖÇ'));
$this->assertFalse(Validation::alphaNumeric('12 234'));
$this->assertFalse(Validation::alphaNumeric('dfd 234'));
$this->assertFalse(Validation::alphaNumeric("\n"));
$this->assertFalse(Validation::alphaNumeric("\t"));
$this->assertFalse(Validation::alphaNumeric("\r"));
$this->assertFalse(Validation::alphaNumeric(' '));
$this->assertFalse(Validation::alphaNumeric(''));
}
/**
* testAlphaNumericPassedAsArray method
*
* @return void
*/
public function testAlphaNumericPassedAsArray() {
$this->assertTrue(Validation::alphaNumeric(array('check' => 'frferrf')));
$this->assertTrue(Validation::alphaNumeric(array('check' => '12234')));
$this->assertTrue(Validation::alphaNumeric(array('check' => '1w2e2r3t4y')));
$this->assertTrue(Validation::alphaNumeric(array('check' => '0')));
$this->assertFalse(Validation::alphaNumeric(array('check' => '12 234')));
$this->assertFalse(Validation::alphaNumeric(array('check' => 'dfd 234')));
$this->assertFalse(Validation::alphaNumeric(array('check' => "\n")));
$this->assertFalse(Validation::alphaNumeric(array('check' => "\t")));
$this->assertFalse(Validation::alphaNumeric(array('check' => "\r")));
$this->assertFalse(Validation::alphaNumeric(array('check' => ' ')));
$this->assertFalse(Validation::alphaNumeric(array('check' => '')));
}
/**
* testBetween method
*
* @return void
*/
public function testBetween() {
$this->assertTrue(Validation::between('abcdefg', 1, 7));
$this->assertTrue(Validation::between('', 0, 7));
$this->assertTrue(Validation::between('אกあアꀀ豈', 1, 7));
$this->assertFalse(Validation::between('abcdefg', 1, 6));
$this->assertFalse(Validation::between('ÆΔΩЖÇ', 1, 3));
}
/**
* testBlank method
*
* @return void
*/
public function testBlank() {
$this->assertTrue(Validation::blank(''));
$this->assertTrue(Validation::blank(' '));
$this->assertTrue(Validation::blank("\n"));
$this->assertTrue(Validation::blank("\t"));
$this->assertTrue(Validation::blank("\r"));
$this->assertFalse(Validation::blank(' Blank'));
$this->assertFalse(Validation::blank('Blank'));
}
/**
* testBlankAsArray method
*
* @return void
*/
public function testBlankAsArray() {
$this->assertTrue(Validation::blank(array('check' => '')));
$this->assertTrue(Validation::blank(array('check' => ' ')));
$this->assertTrue(Validation::blank(array('check' => "\n")));
$this->assertTrue(Validation::blank(array('check' => "\t")));
$this->assertTrue(Validation::blank(array('check' => "\r")));
$this->assertFalse(Validation::blank(array('check' => ' Blank')));
$this->assertFalse(Validation::blank(array('check' => 'Blank')));
}
/**
* testcc method
*
* @return void
*/
public function testCc() {
//American Express
$this->assertTrue(Validation::cc('370482756063980', array('amex')));
$this->assertTrue(Validation::cc('349106433773483', array('amex')));
$this->assertTrue(Validation::cc('344671486204764', array('amex')));
$this->assertTrue(Validation::cc('344042544509943', array('amex')));
$this->assertTrue(Validation::cc('377147515754475', array('amex')));
$this->assertTrue(Validation::cc('375239372816422', array('amex')));
$this->assertTrue(Validation::cc('376294341957707', array('amex')));
$this->assertTrue(Validation::cc('341779292230411', array('amex')));
$this->assertTrue(Validation::cc('341646919853372', array('amex')));
$this->assertTrue(Validation::cc('348498616319346', array('amex')));
//BankCard
$this->assertTrue(Validation::cc('5610745867413420', array('bankcard')));
$this->assertTrue(Validation::cc('5610376649499352', array('bankcard')));
$this->assertTrue(Validation::cc('5610091936000694', array('bankcard')));
$this->assertTrue(Validation::cc('5602248780118788', array('bankcard')));
$this->assertTrue(Validation::cc('5610631567676765', array('bankcard')));
$this->assertTrue(Validation::cc('5602238211270795', array('bankcard')));
$this->assertTrue(Validation::cc('5610173951215470', array('bankcard')));
$this->assertTrue(Validation::cc('5610139705753702', array('bankcard')));
$this->assertTrue(Validation::cc('5602226032150551', array('bankcard')));
$this->assertTrue(Validation::cc('5602223993735777', array('bankcard')));
//Diners Club 14
$this->assertTrue(Validation::cc('30155483651028', array('diners')));
$this->assertTrue(Validation::cc('36371312803821', array('diners')));
$this->assertTrue(Validation::cc('38801277489875', array('diners')));
$this->assertTrue(Validation::cc('30348560464296', array('diners')));
$this->assertTrue(Validation::cc('30349040317708', array('diners')));
$this->assertTrue(Validation::cc('36567413559978', array('diners')));
$this->assertTrue(Validation::cc('36051554732702', array('diners')));
$this->assertTrue(Validation::cc('30391842198191', array('diners')));
$this->assertTrue(Validation::cc('30172682197745', array('diners')));
$this->assertTrue(Validation::cc('30162056566641', array('diners')));
$this->assertTrue(Validation::cc('30085066927745', array('diners')));
$this->assertTrue(Validation::cc('36519025221976', array('diners')));
$this->assertTrue(Validation::cc('30372679371044', array('diners')));
$this->assertTrue(Validation::cc('38913939150124', array('diners')));
$this->assertTrue(Validation::cc('36852899094637', array('diners')));
$this->assertTrue(Validation::cc('30138041971120', array('diners')));
$this->assertTrue(Validation::cc('36184047836838', array('diners')));
$this->assertTrue(Validation::cc('30057460264462', array('diners')));
$this->assertTrue(Validation::cc('38980165212050', array('diners')));
$this->assertTrue(Validation::cc('30356516881240', array('diners')));
$this->assertTrue(Validation::cc('38744810033182', array('diners')));
$this->assertTrue(Validation::cc('30173638706621', array('diners')));
$this->assertTrue(Validation::cc('30158334709185', array('diners')));
$this->assertTrue(Validation::cc('30195413721186', array('diners')));
$this->assertTrue(Validation::cc('38863347694793', array('diners')));
$this->assertTrue(Validation::cc('30275627009113', array('diners')));
$this->assertTrue(Validation::cc('30242860404971', array('diners')));
$this->assertTrue(Validation::cc('30081877595151', array('diners')));
$this->assertTrue(Validation::cc('38053196067461', array('diners')));
$this->assertTrue(Validation::cc('36520379984870', array('diners')));
//2004 MasterCard/Diners Club Alliance International 14
$this->assertTrue(Validation::cc('36747701998969', array('diners')));
$this->assertTrue(Validation::cc('36427861123159', array('diners')));
$this->assertTrue(Validation::cc('36150537602386', array('diners')));
$this->assertTrue(Validation::cc('36582388820610', array('diners')));
$this->assertTrue(Validation::cc('36729045250216', array('diners')));
//2004 MasterCard/Diners Club Alliance US & Canada 16
$this->assertTrue(Validation::cc('5597511346169950', array('diners')));
$this->assertTrue(Validation::cc('5526443162217562', array('diners')));
$this->assertTrue(Validation::cc('5577265786122391', array('diners')));
$this->assertTrue(Validation::cc('5534061404676989', array('diners')));
$this->assertTrue(Validation::cc('5545313588374502', array('diners')));
//Discover
$this->assertTrue(Validation::cc('6011802876467237', array('disc')));
$this->assertTrue(Validation::cc('6506432777720955', array('disc')));
$this->assertTrue(Validation::cc('6011126265283942', array('disc')));
$this->assertTrue(Validation::cc('6502187151579252', array('disc')));
$this->assertTrue(Validation::cc('6506600836002298', array('disc')));
$this->assertTrue(Validation::cc('6504376463615189', array('disc')));
$this->assertTrue(Validation::cc('6011440907005377', array('disc')));
$this->assertTrue(Validation::cc('6509735979634270', array('disc')));
$this->assertTrue(Validation::cc('6011422366775856', array('disc')));
$this->assertTrue(Validation::cc('6500976374623323', array('disc')));
//enRoute
$this->assertTrue(Validation::cc('201496944158937', array('enroute')));
$this->assertTrue(Validation::cc('214945833739665', array('enroute')));
$this->assertTrue(Validation::cc('214982692491187', array('enroute')));
$this->assertTrue(Validation::cc('214901395949424', array('enroute')));
$this->assertTrue(Validation::cc('201480676269187', array('enroute')));
$this->assertTrue(Validation::cc('214911922887807', array('enroute')));
$this->assertTrue(Validation::cc('201485025457250', array('enroute')));
$this->assertTrue(Validation::cc('201402662758866', array('enroute')));
$this->assertTrue(Validation::cc('214981579370225', array('enroute')));
$this->assertTrue(Validation::cc('201447595859877', array('enroute')));
//JCB 15 digit
$this->assertTrue(Validation::cc('210034762247893', array('jcb')));
$this->assertTrue(Validation::cc('180078671678892', array('jcb')));
$this->assertTrue(Validation::cc('180010559353736', array('jcb')));
$this->assertTrue(Validation::cc('210095474464258', array('jcb')));
$this->assertTrue(Validation::cc('210006675562188', array('jcb')));
$this->assertTrue(Validation::cc('210063299662662', array('jcb')));
$this->assertTrue(Validation::cc('180032506857825', array('jcb')));
$this->assertTrue(Validation::cc('210057919192738', array('jcb')));
$this->assertTrue(Validation::cc('180031358949367', array('jcb')));
$this->assertTrue(Validation::cc('180033802147846', array('jcb')));
//JCB 16 digit
$this->assertTrue(Validation::cc('3096806857839939', array('jcb')));
$this->assertTrue(Validation::cc('3158699503187091', array('jcb')));
$this->assertTrue(Validation::cc('3112549607186579', array('jcb')));
$this->assertTrue(Validation::cc('3112332922425604', array('jcb')));
$this->assertTrue(Validation::cc('3112001541159239', array('jcb')));
$this->assertTrue(Validation::cc('3112162495317841', array('jcb')));
$this->assertTrue(Validation::cc('3337562627732768', array('jcb')));
$this->assertTrue(Validation::cc('3337107161330775', array('jcb')));
$this->assertTrue(Validation::cc('3528053736003621', array('jcb')));
$this->assertTrue(Validation::cc('3528915255020360', array('jcb')));
$this->assertTrue(Validation::cc('3096786059660921', array('jcb')));
$this->assertTrue(Validation::cc('3528264799292320', array('jcb')));
$this->assertTrue(Validation::cc('3096469164130136', array('jcb')));
$this->assertTrue(Validation::cc('3112127443822853', array('jcb')));
$this->assertTrue(Validation::cc('3096849995802328', array('jcb')));
$this->assertTrue(Validation::cc('3528090735127407', array('jcb')));
$this->assertTrue(Validation::cc('3112101006819234', array('jcb')));
$this->assertTrue(Validation::cc('3337444428040784', array('jcb')));
$this->assertTrue(Validation::cc('3088043154151061', array('jcb')));
$this->assertTrue(Validation::cc('3088295969414866', array('jcb')));
$this->assertTrue(Validation::cc('3158748843158575', array('jcb')));
$this->assertTrue(Validation::cc('3158709206148538', array('jcb')));
$this->assertTrue(Validation::cc('3158365159575324', array('jcb')));
$this->assertTrue(Validation::cc('3158671691305165', array('jcb')));
$this->assertTrue(Validation::cc('3528523028771093', array('jcb')));
$this->assertTrue(Validation::cc('3096057126267870', array('jcb')));
$this->assertTrue(Validation::cc('3158514047166834', array('jcb')));
$this->assertTrue(Validation::cc('3528274546125962', array('jcb')));
$this->assertTrue(Validation::cc('3528890967705733', array('jcb')));
$this->assertTrue(Validation::cc('3337198811307545', array('jcb')));
//Maestro (debit card)
$this->assertTrue(Validation::cc('5020147409985219', array('maestro')));
$this->assertTrue(Validation::cc('5020931809905616', array('maestro')));
$this->assertTrue(Validation::cc('5020412965470224', array('maestro')));
$this->assertTrue(Validation::cc('5020129740944022', array('maestro')));
$this->assertTrue(Validation::cc('5020024696747943', array('maestro')));
$this->assertTrue(Validation::cc('5020581514636509', array('maestro')));
$this->assertTrue(Validation::cc('5020695008411987', array('maestro')));
$this->assertTrue(Validation::cc('5020565359718977', array('maestro')));
$this->assertTrue(Validation::cc('6339931536544062', array('maestro')));
$this->assertTrue(Validation::cc('6465028615704406', array('maestro')));
//Mastercard
$this->assertTrue(Validation::cc('5580424361774366', array('mc')));
$this->assertTrue(Validation::cc('5589563059318282', array('mc')));
$this->assertTrue(Validation::cc('5387558333690047', array('mc')));
$this->assertTrue(Validation::cc('5163919215247175', array('mc')));
$this->assertTrue(Validation::cc('5386742685055055', array('mc')));
$this->assertTrue(Validation::cc('5102303335960674', array('mc')));
$this->assertTrue(Validation::cc('5526543403964565', array('mc')));
$this->assertTrue(Validation::cc('5538725892618432', array('mc')));
$this->assertTrue(Validation::cc('5119543573129778', array('mc')));
$this->assertTrue(Validation::cc('5391174753915767', array('mc')));
$this->assertTrue(Validation::cc('5510994113980714', array('mc')));
$this->assertTrue(Validation::cc('5183720260418091', array('mc')));
$this->assertTrue(Validation::cc('5488082196086704', array('mc')));
$this->assertTrue(Validation::cc('5484645164161834', array('mc')));
$this->assertTrue(Validation::cc('5171254350337031', array('mc')));
$this->assertTrue(Validation::cc('5526987528136452', array('mc')));
$this->assertTrue(Validation::cc('5504148941409358', array('mc')));
$this->assertTrue(Validation::cc('5240793507243615', array('mc')));
$this->assertTrue(Validation::cc('5162114693017107', array('mc')));
$this->assertTrue(Validation::cc('5163104807404753', array('mc')));
$this->assertTrue(Validation::cc('5590136167248365', array('mc')));
$this->assertTrue(Validation::cc('5565816281038948', array('mc')));
$this->assertTrue(Validation::cc('5467639122779531', array('mc')));
$this->assertTrue(Validation::cc('5297350261550024', array('mc')));
$this->assertTrue(Validation::cc('5162739131368058', array('mc')));
//Solo 16
$this->assertTrue(Validation::cc('6767432107064987', array('solo')));
$this->assertTrue(Validation::cc('6334667758225411', array('solo')));
$this->assertTrue(Validation::cc('6767037421954068', array('solo')));
$this->assertTrue(Validation::cc('6767823306394854', array('solo')));
$this->assertTrue(Validation::cc('6334768185398134', array('solo')));
$this->assertTrue(Validation::cc('6767286729498589', array('solo')));
$this->assertTrue(Validation::cc('6334972104431261', array('solo')));
$this->assertTrue(Validation::cc('6334843427400616', array('solo')));
$this->assertTrue(Validation::cc('6767493947881311', array('solo')));
$this->assertTrue(Validation::cc('6767194235798817', array('solo')));
//Solo 18
$this->assertTrue(Validation::cc('676714834398858593', array('solo')));
$this->assertTrue(Validation::cc('676751666435130857', array('solo')));
$this->assertTrue(Validation::cc('676781908573924236', array('solo')));
$this->assertTrue(Validation::cc('633488724644003240', array('solo')));
$this->assertTrue(Validation::cc('676732252338067316', array('solo')));
$this->assertTrue(Validation::cc('676747520084495821', array('solo')));
$this->assertTrue(Validation::cc('633465488901381957', array('solo')));
$this->assertTrue(Validation::cc('633487484858610484', array('solo')));
$this->assertTrue(Validation::cc('633453764680740694', array('solo')));
$this->assertTrue(Validation::cc('676768613295414451', array('solo')));
//Solo 19
$this->assertTrue(Validation::cc('6767838565218340113', array('solo')));
$this->assertTrue(Validation::cc('6767760119829705181', array('solo')));
$this->assertTrue(Validation::cc('6767265917091593668', array('solo')));
$this->assertTrue(Validation::cc('6767938856947440111', array('solo')));
$this->assertTrue(Validation::cc('6767501945697390076', array('solo')));
$this->assertTrue(Validation::cc('6334902868716257379', array('solo')));
$this->assertTrue(Validation::cc('6334922127686425532', array('solo')));
$this->assertTrue(Validation::cc('6334933119080706440', array('solo')));
$this->assertTrue(Validation::cc('6334647959628261714', array('solo')));
$this->assertTrue(Validation::cc('6334527312384101382', array('solo')));
//Switch 16
$this->assertTrue(Validation::cc('5641829171515733', array('switch')));
$this->assertTrue(Validation::cc('5641824852820809', array('switch')));
$this->assertTrue(Validation::cc('6759129648956909', array('switch')));
$this->assertTrue(Validation::cc('6759626072268156', array('switch')));
$this->assertTrue(Validation::cc('5641822698388957', array('switch')));
$this->assertTrue(Validation::cc('5641827123105470', array('switch')));
$this->assertTrue(Validation::cc('5641823755819553', array('switch')));
$this->assertTrue(Validation::cc('5641821939587682', array('switch')));
$this->assertTrue(Validation::cc('4936097148079186', array('switch')));
$this->assertTrue(Validation::cc('5641829739125009', array('switch')));
$this->assertTrue(Validation::cc('5641822860725507', array('switch')));
$this->assertTrue(Validation::cc('4936717688865831', array('switch')));
$this->assertTrue(Validation::cc('6759487613615441', array('switch')));
$this->assertTrue(Validation::cc('5641821346840617', array('switch')));
$this->assertTrue(Validation::cc('5641825793417126', array('switch')));
$this->assertTrue(Validation::cc('5641821302759595', array('switch')));
$this->assertTrue(Validation::cc('6759784969918837', array('switch')));
$this->assertTrue(Validation::cc('5641824910667036', array('switch')));
$this->assertTrue(Validation::cc('6759139909636173', array('switch')));
$this->assertTrue(Validation::cc('6333425070638022', array('switch')));
$this->assertTrue(Validation::cc('5641823910382067', array('switch')));
$this->assertTrue(Validation::cc('4936295218139423', array('switch')));
$this->assertTrue(Validation::cc('6333031811316199', array('switch')));
$this->assertTrue(Validation::cc('4936912044763198', array('switch')));
$this->assertTrue(Validation::cc('4936387053303824', array('switch')));
$this->assertTrue(Validation::cc('6759535838760523', array('switch')));
$this->assertTrue(Validation::cc('6333427174594051', array('switch')));
$this->assertTrue(Validation::cc('5641829037102700', array('switch')));
$this->assertTrue(Validation::cc('5641826495463046', array('switch')));
$this->assertTrue(Validation::cc('6333480852979946', array('switch')));
$this->assertTrue(Validation::cc('5641827761302876', array('switch')));
$this->assertTrue(Validation::cc('5641825083505317', array('switch')));
$this->assertTrue(Validation::cc('6759298096003991', array('switch')));
$this->assertTrue(Validation::cc('4936119165483420', array('switch')));
$this->assertTrue(Validation::cc('4936190990500993', array('switch')));
$this->assertTrue(Validation::cc('4903356467384927', array('switch')));
$this->assertTrue(Validation::cc('6333372765092554', array('switch')));
$this->assertTrue(Validation::cc('5641821330950570', array('switch')));
$this->assertTrue(Validation::cc('6759841558826118', array('switch')));
$this->assertTrue(Validation::cc('4936164540922452', array('switch')));
//Switch 18
$this->assertTrue(Validation::cc('493622764224625174', array('switch')));
$this->assertTrue(Validation::cc('564182823396913535', array('switch')));
$this->assertTrue(Validation::cc('675917308304801234', array('switch')));
$this->assertTrue(Validation::cc('675919890024220298', array('switch')));
$this->assertTrue(Validation::cc('633308376862556751', array('switch')));
$this->assertTrue(Validation::cc('564182377633208779', array('switch')));
$this->assertTrue(Validation::cc('564182870014926787', array('switch')));
$this->assertTrue(Validation::cc('675979788553829819', array('switch')));
$this->assertTrue(Validation::cc('493668394358130935', array('switch')));
$this->assertTrue(Validation::cc('493637431790930965', array('switch')));
$this->assertTrue(Validation::cc('633321438601941513', array('switch')));
$this->assertTrue(Validation::cc('675913800898840986', array('switch')));
$this->assertTrue(Validation::cc('564182592016841547', array('switch')));
$this->assertTrue(Validation::cc('564182428380440899', array('switch')));
$this->assertTrue(Validation::cc('493696376827623463', array('switch')));
$this->assertTrue(Validation::cc('675977939286485757', array('switch')));
$this->assertTrue(Validation::cc('490302699502091579', array('switch')));
$this->assertTrue(Validation::cc('564182085013662230', array('switch')));
$this->assertTrue(Validation::cc('493693054263310167', array('switch')));
$this->assertTrue(Validation::cc('633321755966697525', array('switch')));
$this->assertTrue(Validation::cc('675996851719732811', array('switch')));
$this->assertTrue(Validation::cc('493699211208281028', array('switch')));
$this->assertTrue(Validation::cc('493697817378356614', array('switch')));
$this->assertTrue(Validation::cc('675968224161768150', array('switch')));
$this->assertTrue(Validation::cc('493669416873337627', array('switch')));
$this->assertTrue(Validation::cc('564182439172549714', array('switch')));
$this->assertTrue(Validation::cc('675926914467673598', array('switch')));
$this->assertTrue(Validation::cc('564182565231977809', array('switch')));
$this->assertTrue(Validation::cc('675966282607849002', array('switch')));
$this->assertTrue(Validation::cc('493691609704348548', array('switch')));
$this->assertTrue(Validation::cc('675933118546065120', array('switch')));
$this->assertTrue(Validation::cc('493631116677238592', array('switch')));
$this->assertTrue(Validation::cc('675921142812825938', array('switch')));
$this->assertTrue(Validation::cc('633338311815675113', array('switch')));
$this->assertTrue(Validation::cc('633323539867338621', array('switch')));
$this->assertTrue(Validation::cc('675964912740845663', array('switch')));
$this->assertTrue(Validation::cc('633334008833727504', array('switch')));
$this->assertTrue(Validation::cc('493631941273687169', array('switch')));
$this->assertTrue(Validation::cc('564182971729706785', array('switch')));
$this->assertTrue(Validation::cc('633303461188963496', array('switch')));
//Switch 19
$this->assertTrue(Validation::cc('6759603460617628716', array('switch')));
$this->assertTrue(Validation::cc('4936705825268647681', array('switch')));
$this->assertTrue(Validation::cc('5641829846600479183', array('switch')));
$this->assertTrue(Validation::cc('6759389846573792530', array('switch')));
$this->assertTrue(Validation::cc('4936189558712637603', array('switch')));
$this->assertTrue(Validation::cc('5641822217393868189', array('switch')));
$this->assertTrue(Validation::cc('4903075563780057152', array('switch')));
$this->assertTrue(Validation::cc('4936510653566569547', array('switch')));
$this->assertTrue(Validation::cc('4936503083627303364', array('switch')));
$this->assertTrue(Validation::cc('4936777334398116272', array('switch')));
$this->assertTrue(Validation::cc('5641823876900554860', array('switch')));
$this->assertTrue(Validation::cc('6759619236903407276', array('switch')));
$this->assertTrue(Validation::cc('6759011470269978117', array('switch')));
$this->assertTrue(Validation::cc('6333175833997062502', array('switch')));
$this->assertTrue(Validation::cc('6759498728789080439', array('switch')));
$this->assertTrue(Validation::cc('4903020404168157841', array('switch')));
$this->assertTrue(Validation::cc('6759354334874804313', array('switch')));
$this->assertTrue(Validation::cc('6759900856420875115', array('switch')));
$this->assertTrue(Validation::cc('5641827269346868860', array('switch')));
$this->assertTrue(Validation::cc('5641828995047453870', array('switch')));
$this->assertTrue(Validation::cc('6333321884754806543', array('switch')));
$this->assertTrue(Validation::cc('6333108246283715901', array('switch')));
$this->assertTrue(Validation::cc('6759572372800700102', array('switch')));
$this->assertTrue(Validation::cc('4903095096797974933', array('switch')));
$this->assertTrue(Validation::cc('6333354315797920215', array('switch')));
$this->assertTrue(Validation::cc('6759163746089433755', array('switch')));
$this->assertTrue(Validation::cc('6759871666634807647', array('switch')));
$this->assertTrue(Validation::cc('5641827883728575248', array('switch')));
$this->assertTrue(Validation::cc('4936527975051407847', array('switch')));
$this->assertTrue(Validation::cc('5641823318396882141', array('switch')));
$this->assertTrue(Validation::cc('6759123772311123708', array('switch')));
$this->assertTrue(Validation::cc('4903054736148271088', array('switch')));
$this->assertTrue(Validation::cc('4936477526808883952', array('switch')));
$this->assertTrue(Validation::cc('4936433964890967966', array('switch')));
$this->assertTrue(Validation::cc('6333245128906049344', array('switch')));
$this->assertTrue(Validation::cc('4936321036970553134', array('switch')));
$this->assertTrue(Validation::cc('4936111816358702773', array('switch')));
$this->assertTrue(Validation::cc('4936196077254804290', array('switch')));
$this->assertTrue(Validation::cc('6759558831206830183', array('switch')));
$this->assertTrue(Validation::cc('5641827998830403137', array('switch')));
//VISA 13 digit
$this->assertTrue(Validation::cc('4024007174754', array('visa')));
$this->assertTrue(Validation::cc('4104816460717', array('visa')));
$this->assertTrue(Validation::cc('4716229700437', array('visa')));
$this->assertTrue(Validation::cc('4539305400213', array('visa')));
$this->assertTrue(Validation::cc('4728260558665', array('visa')));
$this->assertTrue(Validation::cc('4929100131792', array('visa')));
$this->assertTrue(Validation::cc('4024007117308', array('visa')));
$this->assertTrue(Validation::cc('4539915491024', array('visa')));
$this->assertTrue(Validation::cc('4539790901139', array('visa')));
$this->assertTrue(Validation::cc('4485284914909', array('visa')));
$this->assertTrue(Validation::cc('4782793022350', array('visa')));
$this->assertTrue(Validation::cc('4556899290685', array('visa')));
$this->assertTrue(Validation::cc('4024007134774', array('visa')));
$this->assertTrue(Validation::cc('4333412341316', array('visa')));
$this->assertTrue(Validation::cc('4539534204543', array('visa')));
$this->assertTrue(Validation::cc('4485640373626', array('visa')));
$this->assertTrue(Validation::cc('4929911445746', array('visa')));
$this->assertTrue(Validation::cc('4539292550806', array('visa')));
$this->assertTrue(Validation::cc('4716523014030', array('visa')));
$this->assertTrue(Validation::cc('4024007125152', array('visa')));
$this->assertTrue(Validation::cc('4539758883311', array('visa')));
$this->assertTrue(Validation::cc('4024007103258', array('visa')));
$this->assertTrue(Validation::cc('4916933155767', array('visa')));
$this->assertTrue(Validation::cc('4024007159672', array('visa')));
$this->assertTrue(Validation::cc('4716935544871', array('visa')));
$this->assertTrue(Validation::cc('4929415177779', array('visa')));
$this->assertTrue(Validation::cc('4929748547896', array('visa')));
$this->assertTrue(Validation::cc('4929153468612', array('visa')));
$this->assertTrue(Validation::cc('4539397132104', array('visa')));
$this->assertTrue(Validation::cc('4485293435540', array('visa')));
$this->assertTrue(Validation::cc('4485799412720', array('visa')));
$this->assertTrue(Validation::cc('4916744757686', array('visa')));
$this->assertTrue(Validation::cc('4556475655426', array('visa')));
$this->assertTrue(Validation::cc('4539400441625', array('visa')));
$this->assertTrue(Validation::cc('4485437129173', array('visa')));
$this->assertTrue(Validation::cc('4716253605320', array('visa')));
$this->assertTrue(Validation::cc('4539366156589', array('visa')));
$this->assertTrue(Validation::cc('4916498061392', array('visa')));
$this->assertTrue(Validation::cc('4716127163779', array('visa')));
$this->assertTrue(Validation::cc('4024007183078', array('visa')));
$this->assertTrue(Validation::cc('4041553279654', array('visa')));
$this->assertTrue(Validation::cc('4532380121960', array('visa')));
$this->assertTrue(Validation::cc('4485906062491', array('visa')));
$this->assertTrue(Validation::cc('4539365115149', array('visa')));
$this->assertTrue(Validation::cc('4485146516702', array('visa')));
//VISA 16 digit
$this->assertTrue(Validation::cc('4916375389940009', array('visa')));
$this->assertTrue(Validation::cc('4929167481032610', array('visa')));
$this->assertTrue(Validation::cc('4485029969061519', array('visa')));
$this->assertTrue(Validation::cc('4485573845281759', array('visa')));
$this->assertTrue(Validation::cc('4485669810383529', array('visa')));
$this->assertTrue(Validation::cc('4929615806560327', array('visa')));
$this->assertTrue(Validation::cc('4556807505609535', array('visa')));
$this->assertTrue(Validation::cc('4532611336232890', array('visa')));
$this->assertTrue(Validation::cc('4532201952422387', array('visa')));
$this->assertTrue(Validation::cc('4485073797976290', array('visa')));
$this->assertTrue(Validation::cc('4024007157580969', array('visa')));
$this->assertTrue(Validation::cc('4053740470212274', array('visa')));
$this->assertTrue(Validation::cc('4716265831525676', array('visa')));
$this->assertTrue(Validation::cc('4024007100222966', array('visa')));
$this->assertTrue(Validation::cc('4539556148303244', array('visa')));
$this->assertTrue(Validation::cc('4532449879689709', array('visa')));
$this->assertTrue(Validation::cc('4916805467840986', array('visa')));
$this->assertTrue(Validation::cc('4532155644440233', array('visa')));
$this->assertTrue(Validation::cc('4467977802223781', array('visa')));
$this->assertTrue(Validation::cc('4539224637000686', array('visa')));
$this->assertTrue(Validation::cc('4556629187064965', array('visa')));
$this->assertTrue(Validation::cc('4532970205932943', array('visa')));
$this->assertTrue(Validation::cc('4821470132041850', array('visa')));
$this->assertTrue(Validation::cc('4916214267894485', array('visa')));
$this->assertTrue(Validation::cc('4024007169073284', array('visa')));
$this->assertTrue(Validation::cc('4716783351296122', array('visa')));
$this->assertTrue(Validation::cc('4556480171913795', array('visa')));
$this->assertTrue(Validation::cc('4929678411034997', array('visa')));
$this->assertTrue(Validation::cc('4682061913519392', array('visa')));
$this->assertTrue(Validation::cc('4916495481746474', array('visa')));
$this->assertTrue(Validation::cc('4929007108460499', array('visa')));
$this->assertTrue(Validation::cc('4539951357838586', array('visa')));
$this->assertTrue(Validation::cc('4716482691051558', array('visa')));
$this->assertTrue(Validation::cc('4916385069917516', array('visa')));
$this->assertTrue(Validation::cc('4929020289494641', array('visa')));
$this->assertTrue(Validation::cc('4532176245263774', array('visa')));
$this->assertTrue(Validation::cc('4556242273553949', array('visa')));
$this->assertTrue(Validation::cc('4481007485188614', array('visa')));
$this->assertTrue(Validation::cc('4716533372139623', array('visa')));
$this->assertTrue(Validation::cc('4929152038152632', array('visa')));
$this->assertTrue(Validation::cc('4539404037310550', array('visa')));
$this->assertTrue(Validation::cc('4532800925229140', array('visa')));
$this->assertTrue(Validation::cc('4916845885268360', array('visa')));
$this->assertTrue(Validation::cc('4394514669078434', array('visa')));
$this->assertTrue(Validation::cc('4485611378115042', array('visa')));
//Visa Electron
$this->assertTrue(Validation::cc('4175003346287100', array('electron')));
$this->assertTrue(Validation::cc('4913042516577228', array('electron')));
$this->assertTrue(Validation::cc('4917592325659381', array('electron')));
$this->assertTrue(Validation::cc('4917084924450511', array('electron')));
$this->assertTrue(Validation::cc('4917994610643999', array('electron')));
$this->assertTrue(Validation::cc('4175005933743585', array('electron')));
$this->assertTrue(Validation::cc('4175008373425044', array('electron')));
$this->assertTrue(Validation::cc('4913119763664154', array('electron')));
$this->assertTrue(Validation::cc('4913189017481812', array('electron')));
$this->assertTrue(Validation::cc('4913085104968622', array('electron')));
$this->assertTrue(Validation::cc('4175008803122021', array('electron')));
$this->assertTrue(Validation::cc('4913294453962489', array('electron')));
$this->assertTrue(Validation::cc('4175009797419290', array('electron')));
$this->assertTrue(Validation::cc('4175005028142917', array('electron')));
$this->assertTrue(Validation::cc('4913940802385364', array('electron')));
//Voyager
$this->assertTrue(Validation::cc('869940697287073', array('voyager')));
$this->assertTrue(Validation::cc('869934523596112', array('voyager')));
$this->assertTrue(Validation::cc('869958670174621', array('voyager')));
$this->assertTrue(Validation::cc('869921250068209', array('voyager')));
$this->assertTrue(Validation::cc('869972521242198', array('voyager')));
}
/**
* testLuhn method
*
* @return void
*/
public function testLuhn() {
//American Express
$this->assertTrue(Validation::luhn('370482756063980', true));
//BankCard
$this->assertTrue(Validation::luhn('5610745867413420', true));
//Diners Club 14
$this->assertTrue(Validation::luhn('30155483651028', true));
//2004 MasterCard/Diners Club Alliance International 14
$this->assertTrue(Validation::luhn('36747701998969', true));
//2004 MasterCard/Diners Club Alliance US & Canada 16
$this->assertTrue(Validation::luhn('5597511346169950', true));
//Discover
$this->assertTrue(Validation::luhn('6011802876467237', true));
//enRoute
$this->assertTrue(Validation::luhn('201496944158937', true));
//JCB 15 digit
$this->assertTrue(Validation::luhn('210034762247893', true));
//JCB 16 digit
$this->assertTrue(Validation::luhn('3096806857839939', true));
//Maestro (debit card)
$this->assertTrue(Validation::luhn('5020147409985219', true));
//Mastercard
$this->assertTrue(Validation::luhn('5580424361774366', true));
//Solo 16
$this->assertTrue(Validation::luhn('6767432107064987', true));
//Solo 18
$this->assertTrue(Validation::luhn('676714834398858593', true));
//Solo 19
$this->assertTrue(Validation::luhn('6767838565218340113', true));
//Switch 16
$this->assertTrue(Validation::luhn('5641829171515733', true));
//Switch 18
$this->assertTrue(Validation::luhn('493622764224625174', true));
//Switch 19
$this->assertTrue(Validation::luhn('6759603460617628716', true));
//VISA 13 digit
$this->assertTrue(Validation::luhn('4024007174754', true));
//VISA 16 digit
$this->assertTrue(Validation::luhn('4916375389940009', true));
//Visa Electron
$this->assertTrue(Validation::luhn('4175003346287100', true));
//Voyager
$this->assertTrue(Validation::luhn('869940697287073', true));
$this->assertFalse(Validation::luhn('0000000000000000', true));
$this->assertFalse(Validation::luhn('869940697287173', true));
}
/**
* testCustomRegexForCc method
*
* @return void
*/
public function testCustomRegexForCc() {
$this->assertTrue(Validation::cc('12332105933743585', null, null, '/123321\\d{11}/'));
$this->assertFalse(Validation::cc('1233210593374358', null, null, '/123321\\d{11}/'));
$this->assertFalse(Validation::cc('12312305933743585', null, null, '/123321\\d{11}/'));
}
/**
* testCustomRegexForCcWithLuhnCheck method
*
* @return void
*/
public function testCustomRegexForCcWithLuhnCheck() {
$this->assertTrue(Validation::cc('12332110426226941', null, true, '/123321\\d{11}/'));
$this->assertFalse(Validation::cc('12332105933743585', null, true, '/123321\\d{11}/'));
$this->assertFalse(Validation::cc('12332105933743587', null, true, '/123321\\d{11}/'));
$this->assertFalse(Validation::cc('12312305933743585', null, true, '/123321\\d{11}/'));
}
/**
* testFastCc method
*
* @return void
*/
public function testFastCc() {
// too short
$this->assertFalse(Validation::cc('123456789012'));
//American Express
$this->assertTrue(Validation::cc('370482756063980'));
//Diners Club 14
$this->assertTrue(Validation::cc('30155483651028'));
//2004 MasterCard/Diners Club Alliance International 14
$this->assertTrue(Validation::cc('36747701998969'));
//2004 MasterCard/Diners Club Alliance US & Canada 16
$this->assertTrue(Validation::cc('5597511346169950'));
//Discover
$this->assertTrue(Validation::cc('6011802876467237'));
//Mastercard
$this->assertTrue(Validation::cc('5580424361774366'));
//VISA 13 digit
$this->assertTrue(Validation::cc('4024007174754'));
//VISA 16 digit
$this->assertTrue(Validation::cc('4916375389940009'));
//Visa Electron
$this->assertTrue(Validation::cc('4175003346287100'));
}
/**
* testAllCc method
*
* @return void
*/
public function testAllCc() {
//American Express
$this->assertTrue(Validation::cc('370482756063980', 'all'));
//BankCard
$this->assertTrue(Validation::cc('5610745867413420', 'all'));
//Diners Club 14
$this->assertTrue(Validation::cc('30155483651028', 'all'));
//2004 MasterCard/Diners Club Alliance International 14
$this->assertTrue(Validation::cc('36747701998969', 'all'));
//2004 MasterCard/Diners Club Alliance US & Canada 16
$this->assertTrue(Validation::cc('5597511346169950', 'all'));
//Discover
$this->assertTrue(Validation::cc('6011802876467237', 'all'));
//enRoute
$this->assertTrue(Validation::cc('201496944158937', 'all'));
//JCB 15 digit
$this->assertTrue(Validation::cc('210034762247893', 'all'));
//JCB 16 digit
$this->assertTrue(Validation::cc('3096806857839939', 'all'));
//Maestro (debit card)
$this->assertTrue(Validation::cc('5020147409985219', 'all'));
//Mastercard
$this->assertTrue(Validation::cc('5580424361774366', 'all'));
//Solo 16
$this->assertTrue(Validation::cc('6767432107064987', 'all'));
//Solo 18
$this->assertTrue(Validation::cc('676714834398858593', 'all'));
//Solo 19
$this->assertTrue(Validation::cc('6767838565218340113', 'all'));
//Switch 16
$this->assertTrue(Validation::cc('5641829171515733', 'all'));
//Switch 18
$this->assertTrue(Validation::cc('493622764224625174', 'all'));
//Switch 19
$this->assertTrue(Validation::cc('6759603460617628716', 'all'));
//VISA 13 digit
$this->assertTrue(Validation::cc('4024007174754', 'all'));
//VISA 16 digit
$this->assertTrue(Validation::cc('4916375389940009', 'all'));
//Visa Electron
$this->assertTrue(Validation::cc('4175003346287100', 'all'));
//Voyager
$this->assertTrue(Validation::cc('869940697287073', 'all'));
}
/**
* testAllCcDeep method
*
* @return void
*/
public function testAllCcDeep() {
//American Express
$this->assertTrue(Validation::cc('370482756063980', 'all', true));
//BankCard
$this->assertTrue(Validation::cc('5610745867413420', 'all', true));
//Diners Club 14
$this->assertTrue(Validation::cc('30155483651028', 'all', true));
//2004 MasterCard/Diners Club Alliance International 14
$this->assertTrue(Validation::cc('36747701998969', 'all', true));
//2004 MasterCard/Diners Club Alliance US & Canada 16
$this->assertTrue(Validation::cc('5597511346169950', 'all', true));
//Discover
$this->assertTrue(Validation::cc('6011802876467237', 'all', true));
//enRoute
$this->assertTrue(Validation::cc('201496944158937', 'all', true));
//JCB 15 digit
$this->assertTrue(Validation::cc('210034762247893', 'all', true));
//JCB 16 digit
$this->assertTrue(Validation::cc('3096806857839939', 'all', true));
//Maestro (debit card)
$this->assertTrue(Validation::cc('5020147409985219', 'all', true));
//Mastercard
$this->assertTrue(Validation::cc('5580424361774366', 'all', true));
//Solo 16
$this->assertTrue(Validation::cc('6767432107064987', 'all', true));
//Solo 18
$this->assertTrue(Validation::cc('676714834398858593', 'all', true));
//Solo 19
$this->assertTrue(Validation::cc('6767838565218340113', 'all', true));
//Switch 16
$this->assertTrue(Validation::cc('5641829171515733', 'all', true));
//Switch 18
$this->assertTrue(Validation::cc('493622764224625174', 'all', true));
//Switch 19
$this->assertTrue(Validation::cc('6759603460617628716', 'all', true));
//VISA 13 digit
$this->assertTrue(Validation::cc('4024007174754', 'all', true));
//VISA 16 digit
$this->assertTrue(Validation::cc('4916375389940009', 'all', true));
//Visa Electron
$this->assertTrue(Validation::cc('4175003346287100', 'all', true));
//Voyager
$this->assertTrue(Validation::cc('869940697287073', 'all', true));
}
/**
* testComparison method
*
* @return void
*/
public function testComparison() {
$this->assertFalse(Validation::comparison(7, null, 6));
$this->assertTrue(Validation::comparison(7, 'is greater', 6));
$this->assertTrue(Validation::comparison(7, '>', 6));
$this->assertTrue(Validation::comparison(6, 'is less', 7));
$this->assertTrue(Validation::comparison(6, '<', 7));
$this->assertTrue(Validation::comparison(7, 'greater or equal', 7));
$this->assertTrue(Validation::comparison(7, '>=', 7));
$this->assertTrue(Validation::comparison(7, 'greater or equal', 6));
$this->assertTrue(Validation::comparison(7, '>=', 6));
$this->assertTrue(Validation::comparison(6, 'less or equal', 7));
$this->assertTrue(Validation::comparison(6, '<=', 7));
$this->assertTrue(Validation::comparison(7, 'equal to', 7));
$this->assertTrue(Validation::comparison(7, '==', 7));
$this->assertTrue(Validation::comparison(7, 'not equal', 6));
$this->assertTrue(Validation::comparison(7, '!=', 6));
$this->assertFalse(Validation::comparison(6, 'is greater', 7));
$this->assertFalse(Validation::comparison(6, '>', 7));
$this->assertFalse(Validation::comparison(7, 'is less', 6));
$this->assertFalse(Validation::comparison(7, '<', 6));
$this->assertFalse(Validation::comparison(6, 'greater or equal', 7));
$this->assertFalse(Validation::comparison(6, '>=', 7));
$this->assertFalse(Validation::comparison(6, 'greater or equal', 7));
$this->assertFalse(Validation::comparison(6, '>=', 7));
$this->assertFalse(Validation::comparison(7, 'less or equal', 6));
$this->assertFalse(Validation::comparison(7, '<=', 6));
$this->assertFalse(Validation::comparison(7, 'equal to', 6));
$this->assertFalse(Validation::comparison(7, '==', 6));
$this->assertFalse(Validation::comparison(7, 'not equal', 7));
$this->assertFalse(Validation::comparison(7, '!=', 7));
}
/**
* testComparisonAsArray method
*
* @return void
*/
public function testComparisonAsArray() {
$this->assertTrue(Validation::comparison(array('check1' => 7, 'operator' => 'is greater', 'check2' => 6)));
$this->assertTrue(Validation::comparison(array('check1' => 7, 'operator' => '>', 'check2' => 6)));
$this->assertTrue(Validation::comparison(array('check1' => 6, 'operator' => 'is less', 'check2' => 7)));
$this->assertTrue(Validation::comparison(array('check1' => 6, 'operator' => '<', 'check2' => 7)));
$this->assertTrue(Validation::comparison(array('check1' => 7, 'operator' => 'greater or equal', 'check2' => 7)));
$this->assertTrue(Validation::comparison(array('check1' => 7, 'operator' => '>=', 'check2' => 7)));
$this->assertTrue(Validation::comparison(array('check1' => 7, 'operator' => 'greater or equal','check2' => 6)));
$this->assertTrue(Validation::comparison(array('check1' => 7, 'operator' => '>=', 'check2' => 6)));
$this->assertTrue(Validation::comparison(array('check1' => 6, 'operator' => 'less or equal', 'check2' => 7)));
$this->assertTrue(Validation::comparison(array('check1' => 6, 'operator' => '<=', 'check2' => 7)));
$this->assertTrue(Validation::comparison(array('check1' => 7, 'operator' => 'equal to', 'check2' => 7)));
$this->assertTrue(Validation::comparison(array('check1' => 7, 'operator' => '==', 'check2' => 7)));
$this->assertTrue(Validation::comparison(array('check1' => 7, 'operator' => 'not equal', 'check2' => 6)));
$this->assertTrue(Validation::comparison(array('check1' => 7, 'operator' => '!=', 'check2' => 6)));
$this->assertFalse(Validation::comparison(array('check1' => 6, 'operator' => 'is greater', 'check2' => 7)));
$this->assertFalse(Validation::comparison(array('check1' => 6, 'operator' => '>', 'check2' => 7)));
$this->assertFalse(Validation::comparison(array('check1' => 7, 'operator' => 'is less', 'check2' => 6)));
$this->assertFalse(Validation::comparison(array('check1' => 7, 'operator' => '<', 'check2' => 6)));
$this->assertFalse(Validation::comparison(array('check1' => 6, 'operator' => 'greater or equal', 'check2' => 7)));
$this->assertFalse(Validation::comparison(array('check1' => 6, 'operator' => '>=', 'check2' => 7)));
$this->assertFalse(Validation::comparison(array('check1' => 6, 'operator' => 'greater or equal', 'check2' => 7)));
$this->assertFalse(Validation::comparison(array('check1' => 6, 'operator' => '>=', 'check2' => 7)));
$this->assertFalse(Validation::comparison(array('check1' => 7, 'operator' => 'less or equal', 'check2' => 6)));
$this->assertFalse(Validation::comparison(array('check1' => 7, 'operator' => '<=', 'check2' => 6)));
$this->assertFalse(Validation::comparison(array('check1' => 7, 'operator' => 'equal to', 'check2' => 6)));
$this->assertFalse(Validation::comparison(array('check1' => 7, 'operator' => '==','check2' => 6)));
$this->assertFalse(Validation::comparison(array('check1' => 7, 'operator' => 'not equal', 'check2' => 7)));
$this->assertFalse(Validation::comparison(array('check1' => 7, 'operator' => '!=', 'check2' => 7)));
}
/**
* testCustom method
*
* @return void
*/
public function testCustom() {
$this->assertTrue(Validation::custom('12345', '/(?<!\\S)\\d++(?!\\S)/'));
$this->assertFalse(Validation::custom('Text', '/(?<!\\S)\\d++(?!\\S)/'));
$this->assertFalse(Validation::custom('123.45', '/(?<!\\S)\\d++(?!\\S)/'));
$this->assertFalse(Validation::custom('missing regex'));
}
/**
* testCustomAsArray method
*
* @return void
*/
public function testCustomAsArray() {
$this->assertTrue(Validation::custom(array('check' => '12345', 'regex' => '/(?<!\\S)\\d++(?!\\S)/')));
$this->assertFalse(Validation::custom(array('check' => 'Text', 'regex' => '/(?<!\\S)\\d++(?!\\S)/')));
$this->assertFalse(Validation::custom(array('check' => '123.45', 'regex' => '/(?<!\\S)\\d++(?!\\S)/')));
}
/**
* testDateDdmmyyyy method
*
* @return void
*/
public function testDateDdmmyyyy() {
$this->assertTrue(Validation::date('27-12-2006', array('dmy')));
$this->assertTrue(Validation::date('27.12.2006', array('dmy')));
$this->assertTrue(Validation::date('27/12/2006', array('dmy')));
$this->assertTrue(Validation::date('27 12 2006', array('dmy')));
$this->assertFalse(Validation::date('00-00-0000', array('dmy')));
$this->assertFalse(Validation::date('00.00.0000', array('dmy')));
$this->assertFalse(Validation::date('00/00/0000', array('dmy')));
$this->assertFalse(Validation::date('00 00 0000', array('dmy')));
$this->assertFalse(Validation::date('31-11-2006', array('dmy')));
$this->assertFalse(Validation::date('31.11.2006', array('dmy')));
$this->assertFalse(Validation::date('31/11/2006', array('dmy')));
$this->assertFalse(Validation::date('31 11 2006', array('dmy')));
}
/**
* testDateDdmmyyyyLeapYear method
*
* @return void
*/
public function testDateDdmmyyyyLeapYear() {
$this->assertTrue(Validation::date('29-02-2004', array('dmy')));
$this->assertTrue(Validation::date('29.02.2004', array('dmy')));
$this->assertTrue(Validation::date('29/02/2004', array('dmy')));
$this->assertTrue(Validation::date('29 02 2004', array('dmy')));
$this->assertFalse(Validation::date('29-02-2006', array('dmy')));
$this->assertFalse(Validation::date('29.02.2006', array('dmy')));
$this->assertFalse(Validation::date('29/02/2006', array('dmy')));
$this->assertFalse(Validation::date('29 02 2006', array('dmy')));
}
/**
* testDateDdmmyy method
*
* @return void
*/
public function testDateDdmmyy() {
$this->assertTrue(Validation::date('27-12-06', array('dmy')));
$this->assertTrue(Validation::date('27.12.06', array('dmy')));
$this->assertTrue(Validation::date('27/12/06', array('dmy')));
$this->assertTrue(Validation::date('27 12 06', array('dmy')));
$this->assertFalse(Validation::date('00-00-00', array('dmy')));
$this->assertFalse(Validation::date('00.00.00', array('dmy')));
$this->assertFalse(Validation::date('00/00/00', array('dmy')));
$this->assertFalse(Validation::date('00 00 00', array('dmy')));
$this->assertFalse(Validation::date('31-11-06', array('dmy')));
$this->assertFalse(Validation::date('31.11.06', array('dmy')));
$this->assertFalse(Validation::date('31/11/06', array('dmy')));
$this->assertFalse(Validation::date('31 11 06', array('dmy')));
}
/**
* testDateDdmmyyLeapYear method
*
* @return void
*/
public function testDateDdmmyyLeapYear() {
$this->assertTrue(Validation::date('29-02-04', array('dmy')));
$this->assertTrue(Validation::date('29.02.04', array('dmy')));
$this->assertTrue(Validation::date('29/02/04', array('dmy')));
$this->assertTrue(Validation::date('29 02 04', array('dmy')));
$this->assertFalse(Validation::date('29-02-06', array('dmy')));
$this->assertFalse(Validation::date('29.02.06', array('dmy')));
$this->assertFalse(Validation::date('29/02/06', array('dmy')));
$this->assertFalse(Validation::date('29 02 06', array('dmy')));
}
/**
* testDateDmyy method
*
* @return void
*/
public function testDateDmyy() {
$this->assertTrue(Validation::date('7-2-06', array('dmy')));
$this->assertTrue(Validation::date('7.2.06', array('dmy')));
$this->assertTrue(Validation::date('7/2/06', array('dmy')));
$this->assertTrue(Validation::date('7 2 06', array('dmy')));
$this->assertFalse(Validation::date('0-0-00', array('dmy')));
$this->assertFalse(Validation::date('0.0.00', array('dmy')));
$this->assertFalse(Validation::date('0/0/00', array('dmy')));
$this->assertFalse(Validation::date('0 0 00', array('dmy')));
$this->assertFalse(Validation::date('32-2-06', array('dmy')));
$this->assertFalse(Validation::date('32.2.06', array('dmy')));
$this->assertFalse(Validation::date('32/2/06', array('dmy')));
$this->assertFalse(Validation::date('32 2 06', array('dmy')));
}
/**
* testDateDmyyLeapYear method
*
* @return void
*/
public function testDateDmyyLeapYear() {
$this->assertTrue(Validation::date('29-2-04', array('dmy')));
$this->assertTrue(Validation::date('29.2.04', array('dmy')));
$this->assertTrue(Validation::date('29/2/04', array('dmy')));
$this->assertTrue(Validation::date('29 2 04', array('dmy')));
$this->assertFalse(Validation::date('29-2-06', array('dmy')));
$this->assertFalse(Validation::date('29.2.06', array('dmy')));
$this->assertFalse(Validation::date('29/2/06', array('dmy')));
$this->assertFalse(Validation::date('29 2 06', array('dmy')));
}
/**
* testDateDmyyyy method
*
* @return void
*/
public function testDateDmyyyy() {
$this->assertTrue(Validation::date('7-2-2006', array('dmy')));
$this->assertTrue(Validation::date('7.2.2006', array('dmy')));
$this->assertTrue(Validation::date('7/2/2006', array('dmy')));
$this->assertTrue(Validation::date('7 2 2006', array('dmy')));
$this->assertFalse(Validation::date('0-0-0000', array('dmy')));
$this->assertFalse(Validation::date('0.0.0000', array('dmy')));
$this->assertFalse(Validation::date('0/0/0000', array('dmy')));
$this->assertFalse(Validation::date('0 0 0000', array('dmy')));
$this->assertFalse(Validation::date('32-2-2006', array('dmy')));
$this->assertFalse(Validation::date('32.2.2006', array('dmy')));
$this->assertFalse(Validation::date('32/2/2006', array('dmy')));
$this->assertFalse(Validation::date('32 2 2006', array('dmy')));
}
/**
* testDateDmyyyyLeapYear method
*
* @return void
*/
public function testDateDmyyyyLeapYear() {
$this->assertTrue(Validation::date('29-2-2004', array('dmy')));
$this->assertTrue(Validation::date('29.2.2004', array('dmy')));
$this->assertTrue(Validation::date('29/2/2004', array('dmy')));
$this->assertTrue(Validation::date('29 2 2004', array('dmy')));
$this->assertFalse(Validation::date('29-2-2006', array('dmy')));
$this->assertFalse(Validation::date('29.2.2006', array('dmy')));
$this->assertFalse(Validation::date('29/2/2006', array('dmy')));
$this->assertFalse(Validation::date('29 2 2006', array('dmy')));
}
/**
* testDateMmddyyyy method
*
* @return void
*/
public function testDateMmddyyyy() {
$this->assertTrue(Validation::date('12-27-2006', array('mdy')));
$this->assertTrue(Validation::date('12.27.2006', array('mdy')));
$this->assertTrue(Validation::date('12/27/2006', array('mdy')));
$this->assertTrue(Validation::date('12 27 2006', array('mdy')));
$this->assertFalse(Validation::date('00-00-0000', array('mdy')));
$this->assertFalse(Validation::date('00.00.0000', array('mdy')));
$this->assertFalse(Validation::date('00/00/0000', array('mdy')));
$this->assertFalse(Validation::date('00 00 0000', array('mdy')));
$this->assertFalse(Validation::date('11-31-2006', array('mdy')));
$this->assertFalse(Validation::date('11.31.2006', array('mdy')));
$this->assertFalse(Validation::date('11/31/2006', array('mdy')));
$this->assertFalse(Validation::date('11 31 2006', array('mdy')));
}
/**
* testDateMmddyyyyLeapYear method
*
* @return void
*/
public function testDateMmddyyyyLeapYear() {
$this->assertTrue(Validation::date('02-29-2004', array('mdy')));
$this->assertTrue(Validation::date('02.29.2004', array('mdy')));
$this->assertTrue(Validation::date('02/29/2004', array('mdy')));
$this->assertTrue(Validation::date('02 29 2004', array('mdy')));
$this->assertFalse(Validation::date('02-29-2006', array('mdy')));
$this->assertFalse(Validation::date('02.29.2006', array('mdy')));
$this->assertFalse(Validation::date('02/29/2006', array('mdy')));
$this->assertFalse(Validation::date('02 29 2006', array('mdy')));
}
/**
* testDateMmddyy method
*
* @return void
*/
public function testDateMmddyy() {
$this->assertTrue(Validation::date('12-27-06', array('mdy')));
$this->assertTrue(Validation::date('12.27.06', array('mdy')));
$this->assertTrue(Validation::date('12/27/06', array('mdy')));
$this->assertTrue(Validation::date('12 27 06', array('mdy')));
$this->assertFalse(Validation::date('00-00-00', array('mdy')));
$this->assertFalse(Validation::date('00.00.00', array('mdy')));
$this->assertFalse(Validation::date('00/00/00', array('mdy')));
$this->assertFalse(Validation::date('00 00 00', array('mdy')));
$this->assertFalse(Validation::date('11-31-06', array('mdy')));
$this->assertFalse(Validation::date('11.31.06', array('mdy')));
$this->assertFalse(Validation::date('11/31/06', array('mdy')));
$this->assertFalse(Validation::date('11 31 06', array('mdy')));
}
/**
* testDateMmddyyLeapYear method
*
* @return void
*/
public function testDateMmddyyLeapYear() {
$this->assertTrue(Validation::date('02-29-04', array('mdy')));
$this->assertTrue(Validation::date('02.29.04', array('mdy')));
$this->assertTrue(Validation::date('02/29/04', array('mdy')));
$this->assertTrue(Validation::date('02 29 04', array('mdy')));
$this->assertFalse(Validation::date('02-29-06', array('mdy')));
$this->assertFalse(Validation::date('02.29.06', array('mdy')));
$this->assertFalse(Validation::date('02/29/06', array('mdy')));
$this->assertFalse(Validation::date('02 29 06', array('mdy')));
}
/**
* testDateMdyy method
*
* @return void
*/
public function testDateMdyy() {
$this->assertTrue(Validation::date('2-7-06', array('mdy')));
$this->assertTrue(Validation::date('2.7.06', array('mdy')));
$this->assertTrue(Validation::date('2/7/06', array('mdy')));
$this->assertTrue(Validation::date('2 7 06', array('mdy')));
$this->assertFalse(Validation::date('0-0-00', array('mdy')));
$this->assertFalse(Validation::date('0.0.00', array('mdy')));
$this->assertFalse(Validation::date('0/0/00', array('mdy')));
$this->assertFalse(Validation::date('0 0 00', array('mdy')));
$this->assertFalse(Validation::date('2-32-06', array('mdy')));
$this->assertFalse(Validation::date('2.32.06', array('mdy')));
$this->assertFalse(Validation::date('2/32/06', array('mdy')));
$this->assertFalse(Validation::date('2 32 06', array('mdy')));
}
/**
* testDateMdyyLeapYear method
*
* @return void
*/
public function testDateMdyyLeapYear() {
$this->assertTrue(Validation::date('2-29-04', array('mdy')));
$this->assertTrue(Validation::date('2.29.04', array('mdy')));
$this->assertTrue(Validation::date('2/29/04', array('mdy')));
$this->assertTrue(Validation::date('2 29 04', array('mdy')));
$this->assertFalse(Validation::date('2-29-06', array('mdy')));
$this->assertFalse(Validation::date('2.29.06', array('mdy')));
$this->assertFalse(Validation::date('2/29/06', array('mdy')));
$this->assertFalse(Validation::date('2 29 06', array('mdy')));
}
/**
* testDateMdyyyy method
*
* @return void
*/
public function testDateMdyyyy() {
$this->assertTrue(Validation::date('2-7-2006', array('mdy')));
$this->assertTrue(Validation::date('2.7.2006', array('mdy')));
$this->assertTrue(Validation::date('2/7/2006', array('mdy')));
$this->assertTrue(Validation::date('2 7 2006', array('mdy')));
$this->assertFalse(Validation::date('0-0-0000', array('mdy')));
$this->assertFalse(Validation::date('0.0.0000', array('mdy')));
$this->assertFalse(Validation::date('0/0/0000', array('mdy')));
$this->assertFalse(Validation::date('0 0 0000', array('mdy')));
$this->assertFalse(Validation::date('2-32-2006', array('mdy')));
$this->assertFalse(Validation::date('2.32.2006', array('mdy')));
$this->assertFalse(Validation::date('2/32/2006', array('mdy')));
$this->assertFalse(Validation::date('2 32 2006', array('mdy')));
}
/**
* testDateMdyyyyLeapYear method
*
* @return void
*/
public function testDateMdyyyyLeapYear() {
$this->assertTrue(Validation::date('2-29-2004', array('mdy')));
$this->assertTrue(Validation::date('2.29.2004', array('mdy')));
$this->assertTrue(Validation::date('2/29/2004', array('mdy')));
$this->assertTrue(Validation::date('2 29 2004', array('mdy')));
$this->assertFalse(Validation::date('2-29-2006', array('mdy')));
$this->assertFalse(Validation::date('2.29.2006', array('mdy')));
$this->assertFalse(Validation::date('2/29/2006', array('mdy')));
$this->assertFalse(Validation::date('2 29 2006', array('mdy')));
}
/**
* testDateYyyymmdd method
*
* @return void
*/
public function testDateYyyymmdd() {
$this->assertTrue(Validation::date('2006-12-27', array('ymd')));
$this->assertTrue(Validation::date('2006.12.27', array('ymd')));
$this->assertTrue(Validation::date('2006/12/27', array('ymd')));
$this->assertTrue(Validation::date('2006 12 27', array('ymd')));
$this->assertFalse(Validation::date('2006-11-31', array('ymd')));
$this->assertFalse(Validation::date('2006.11.31', array('ymd')));
$this->assertFalse(Validation::date('2006/11/31', array('ymd')));
$this->assertFalse(Validation::date('2006 11 31', array('ymd')));
}
/**
* testDateYyyymmddLeapYear method
*
* @return void
*/
public function testDateYyyymmddLeapYear() {
$this->assertTrue(Validation::date('2004-02-29', array('ymd')));
$this->assertTrue(Validation::date('2004.02.29', array('ymd')));
$this->assertTrue(Validation::date('2004/02/29', array('ymd')));
$this->assertTrue(Validation::date('2004 02 29', array('ymd')));
$this->assertFalse(Validation::date('2006-02-29', array('ymd')));
$this->assertFalse(Validation::date('2006.02.29', array('ymd')));
$this->assertFalse(Validation::date('2006/02/29', array('ymd')));
$this->assertFalse(Validation::date('2006 02 29', array('ymd')));
}
/**
* testDateYymmdd method
*
* @return void
*/
public function testDateYymmdd() {
$this->assertTrue(Validation::date('06-12-27', array('ymd')));
$this->assertTrue(Validation::date('06.12.27', array('ymd')));
$this->assertTrue(Validation::date('06/12/27', array('ymd')));
$this->assertTrue(Validation::date('06 12 27', array('ymd')));
$this->assertFalse(Validation::date('12/27/2600', array('ymd')));
$this->assertFalse(Validation::date('12.27.2600', array('ymd')));
$this->assertFalse(Validation::date('12/27/2600', array('ymd')));
$this->assertFalse(Validation::date('12 27 2600', array('ymd')));
$this->assertFalse(Validation::date('06-11-31', array('ymd')));
$this->assertFalse(Validation::date('06.11.31', array('ymd')));
$this->assertFalse(Validation::date('06/11/31', array('ymd')));
$this->assertFalse(Validation::date('06 11 31', array('ymd')));
}
/**
* testDateYymmddLeapYear method
*
* @return void
*/
public function testDateYymmddLeapYear() {
$this->assertTrue(Validation::date('2004-02-29', array('ymd')));
$this->assertTrue(Validation::date('2004.02.29', array('ymd')));
$this->assertTrue(Validation::date('2004/02/29', array('ymd')));
$this->assertTrue(Validation::date('2004 02 29', array('ymd')));
$this->assertFalse(Validation::date('2006-02-29', array('ymd')));
$this->assertFalse(Validation::date('2006.02.29', array('ymd')));
$this->assertFalse(Validation::date('2006/02/29', array('ymd')));
$this->assertFalse(Validation::date('2006 02 29', array('ymd')));
}
/**
* testDateDdMMMMyyyy method
*
* @return void
*/
public function testDateDdMMMMyyyy() {
$this->assertTrue(Validation::date('27 December 2006', array('dMy')));
$this->assertTrue(Validation::date('27 Dec 2006', array('dMy')));
$this->assertFalse(Validation::date('2006 Dec 27', array('dMy')));
$this->assertFalse(Validation::date('2006 December 27', array('dMy')));
}
/**
* testDateDdMMMMyyyyLeapYear method
*
* @return void
*/
public function testDateDdMMMMyyyyLeapYear() {
$this->assertTrue(Validation::date('29 February 2004', array('dMy')));
$this->assertFalse(Validation::date('29 February 2006', array('dMy')));
}
/**
* testDateMmmmDdyyyy method
*
* @return void
*/
public function testDateMmmmDdyyyy() {
$this->assertTrue(Validation::date('December 27, 2006', array('Mdy')));
$this->assertTrue(Validation::date('Dec 27, 2006', array('Mdy')));
$this->assertTrue(Validation::date('December 27 2006', array('Mdy')));
$this->assertTrue(Validation::date('Dec 27 2006', array('Mdy')));
$this->assertFalse(Validation::date('27 Dec 2006', array('Mdy')));
$this->assertFalse(Validation::date('2006 December 27', array('Mdy')));
$this->assertTrue(Validation::date('Sep 12, 2011', array('Mdy')));
}
/**
* testDateMmmmDdyyyyLeapYear method
*
* @return void
*/
public function testDateMmmmDdyyyyLeapYear() {
$this->assertTrue(Validation::date('February 29, 2004', array('Mdy')));
$this->assertTrue(Validation::date('Feb 29, 2004', array('Mdy')));
$this->assertTrue(Validation::date('February 29 2004', array('Mdy')));
$this->assertTrue(Validation::date('Feb 29 2004', array('Mdy')));
$this->assertFalse(Validation::date('February 29, 2006', array('Mdy')));
}
/**
* testDateMy method
*
* @return void
*/
public function testDateMy() {
$this->assertTrue(Validation::date('December 2006', array('My')));
$this->assertTrue(Validation::date('Dec 2006', array('My')));
$this->assertTrue(Validation::date('December/2006', array('My')));
$this->assertTrue(Validation::date('Dec/2006', array('My')));
}
/**
* testDateMyNumeric method
*
* @return void
*/
public function testDateMyNumeric() {
$this->assertTrue(Validation::date('12/2006', array('my')));
$this->assertTrue(Validation::date('12-2006', array('my')));
$this->assertTrue(Validation::date('12.2006', array('my')));
$this->assertTrue(Validation::date('12 2006', array('my')));
$this->assertFalse(Validation::date('12/06', array('my')));
$this->assertFalse(Validation::date('12-06', array('my')));
$this->assertFalse(Validation::date('12.06', array('my')));
$this->assertFalse(Validation::date('12 06', array('my')));
}
/**
* testTime method
*
* @return void
*/
public function testTime() {
$this->assertTrue(Validation::time('00:00'));
$this->assertTrue(Validation::time('23:59'));
$this->assertFalse(Validation::time('24:00'));
$this->assertTrue(Validation::time('12:00'));
$this->assertTrue(Validation::time('12:01'));
$this->assertTrue(Validation::time('12:01am'));
$this->assertTrue(Validation::time('12:01pm'));
$this->assertTrue(Validation::time('1pm'));
$this->assertTrue(Validation::time('1 pm'));
$this->assertTrue(Validation::time('1 PM'));
$this->assertTrue(Validation::time('01:00'));
$this->assertFalse(Validation::time('1:00'));
$this->assertTrue(Validation::time('1:00pm'));
$this->assertFalse(Validation::time('13:00pm'));
$this->assertFalse(Validation::time('9:00'));
}
/**
* testBoolean method
*
* @return void
*/
public function testBoolean() {
$this->assertTrue(Validation::boolean('0'));
$this->assertTrue(Validation::boolean('1'));
$this->assertTrue(Validation::boolean(0));
$this->assertTrue(Validation::boolean(1));
$this->assertTrue(Validation::boolean(true));
$this->assertTrue(Validation::boolean(false));
$this->assertFalse(Validation::boolean('true'));
$this->assertFalse(Validation::boolean('false'));
$this->assertFalse(Validation::boolean('-1'));
$this->assertFalse(Validation::boolean('2'));
$this->assertFalse(Validation::boolean('Boo!'));
}
/**
* testDateCustomRegx method
*
* @return void
*/
public function testDateCustomRegx() {
$this->assertTrue(Validation::date('2006-12-27', null, '%^(19|20)[0-9]{2}[- /.](0[1-9]|1[012])[- /.](0[1-9]|[12][0-9]|3[01])$%'));
$this->assertFalse(Validation::date('12-27-2006', null, '%^(19|20)[0-9]{2}[- /.](0[1-9]|1[012])[- /.](0[1-9]|[12][0-9]|3[01])$%'));
}
/**
* testDecimal method
*
* @return void
*/
public function testDecimal() {
$this->assertTrue(Validation::decimal('+1234.54321'));
$this->assertTrue(Validation::decimal('-1234.54321'));
$this->assertTrue(Validation::decimal('1234.54321'));
$this->assertTrue(Validation::decimal('+0123.45e6'));
$this->assertTrue(Validation::decimal('-0123.45e6'));
$this->assertTrue(Validation::decimal('0123.45e6'));
$this->assertFalse(Validation::decimal('string'));
$this->assertFalse(Validation::decimal('1234'));
$this->assertFalse(Validation::decimal('-1234'));
$this->assertFalse(Validation::decimal('+1234'));
}
/**
* testDecimalWithPlaces method
*
* @return void
*/
public function testDecimalWithPlaces() {
$this->assertTrue(Validation::decimal('.27', '2'));
$this->assertTrue(Validation::decimal(.27, 2));
$this->assertTrue(Validation::decimal(-.27, 2));
$this->assertTrue(Validation::decimal(+.27, 2));
$this->assertTrue(Validation::decimal('.277', '3'));
$this->assertTrue(Validation::decimal(.277, 3));
$this->assertTrue(Validation::decimal(-.277, 3));
$this->assertTrue(Validation::decimal(+.277, 3));
$this->assertTrue(Validation::decimal('1234.5678', '4'));
$this->assertTrue(Validation::decimal(1234.5678, 4));
$this->assertTrue(Validation::decimal(-1234.5678, 4));
$this->assertTrue(Validation::decimal(+1234.5678, 4));
$this->assertFalse(Validation::decimal('1234.5678', '3'));
$this->assertFalse(Validation::decimal(1234.5678, 3));
$this->assertFalse(Validation::decimal(-1234.5678, 3));
$this->assertFalse(Validation::decimal(+1234.5678, 3));
}
/**
* testDecimalCustomRegex method
*
* @return void
*/
public function testDecimalCustomRegex() {
$this->assertTrue(Validation::decimal('1.54321', null, '/^[-+]?[0-9]+(\\.[0-9]+)?$/s'));
$this->assertFalse(Validation::decimal('.54321', null, '/^[-+]?[0-9]+(\\.[0-9]+)?$/s'));
}
/**
* testEmail method
*
* @return void
*/
public function testEmail() {
$this->assertTrue(Validation::email('abc.efg@domain.com'));
$this->assertTrue(Validation::email('efg@domain.com'));
$this->assertTrue(Validation::email('abc-efg@domain.com'));
$this->assertTrue(Validation::email('abc_efg@domain.com'));
$this->assertTrue(Validation::email('raw@test.ra.ru'));
$this->assertTrue(Validation::email('abc-efg@domain-hyphened.com'));
$this->assertTrue(Validation::email("p.o'malley@domain.com"));
$this->assertTrue(Validation::email('abc+efg@domain.com'));
$this->assertTrue(Validation::email('abc&efg@domain.com'));
$this->assertTrue(Validation::email('abc.efg@12345.com'));
$this->assertTrue(Validation::email('abc.efg@12345.co.jp'));
$this->assertTrue(Validation::email('abc@g.cn'));
$this->assertTrue(Validation::email('abc@x.com'));
$this->assertTrue(Validation::email('henrik@sbcglobal.net'));
$this->assertTrue(Validation::email('sani@sbcglobal.net'));
// all ICANN TLDs
$this->assertTrue(Validation::email('abc@example.aero'));
$this->assertTrue(Validation::email('abc@example.asia'));
$this->assertTrue(Validation::email('abc@example.biz'));
$this->assertTrue(Validation::email('abc@example.cat'));
$this->assertTrue(Validation::email('abc@example.com'));
$this->assertTrue(Validation::email('abc@example.coop'));
$this->assertTrue(Validation::email('abc@example.edu'));
$this->assertTrue(Validation::email('abc@example.gov'));
$this->assertTrue(Validation::email('abc@example.info'));
$this->assertTrue(Validation::email('abc@example.int'));
$this->assertTrue(Validation::email('abc@example.jobs'));
$this->assertTrue(Validation::email('abc@example.mil'));
$this->assertTrue(Validation::email('abc@example.mobi'));
$this->assertTrue(Validation::email('abc@example.museum'));
$this->assertTrue(Validation::email('abc@example.name'));
$this->assertTrue(Validation::email('abc@example.net'));
$this->assertTrue(Validation::email('abc@example.org'));
$this->assertTrue(Validation::email('abc@example.pro'));
$this->assertTrue(Validation::email('abc@example.tel'));
$this->assertTrue(Validation::email('abc@example.travel'));
$this->assertTrue(Validation::email('someone@st.t-com.hr'));
// strange, but technically valid email addresses
$this->assertTrue(Validation::email('S=postmaster/OU=rz/P=uni-frankfurt/A=d400/C=de@gateway.d400.de'));
$this->assertTrue(Validation::email('customer/department=shipping@example.com'));
$this->assertTrue(Validation::email('$A12345@example.com'));
$this->assertTrue(Validation::email('!def!xyz%abc@example.com'));
$this->assertTrue(Validation::email('_somename@example.com'));
// invalid addresses
$this->assertFalse(Validation::email('abc@example'));
$this->assertFalse(Validation::email('abc@example.c'));
$this->assertFalse(Validation::email('abc@example.com.'));
$this->assertFalse(Validation::email('abc.@example.com'));
$this->assertFalse(Validation::email('abc@example..com'));
$this->assertFalse(Validation::email('abc@example.com.a'));
$this->assertFalse(Validation::email('abc@example.toolong'));
$this->assertFalse(Validation::email('abc;@example.com'));
$this->assertFalse(Validation::email('abc@example.com;'));
$this->assertFalse(Validation::email('abc@efg@example.com'));
$this->assertFalse(Validation::email('abc@@example.com'));
$this->assertFalse(Validation::email('abc efg@example.com'));
$this->assertFalse(Validation::email('abc,efg@example.com'));
$this->assertFalse(Validation::email('abc@sub,example.com'));
$this->assertFalse(Validation::email("abc@sub'example.com"));
$this->assertFalse(Validation::email('abc@sub/example.com'));
$this->assertFalse(Validation::email('abc@yahoo!.com'));
$this->assertFalse(Validation::email("Nyrée.surname@example.com"));
$this->assertFalse(Validation::email('abc@example_underscored.com'));
$this->assertFalse(Validation::email('raw@test.ra.ru....com'));
}
/**
* testEmailDeep method
*
* @return void
*/
public function testEmailDeep() {
$this->skipIf(gethostbynamel('example.abcd'), 'Your DNS service responds for non-existant domains, skipping deep email checks.');
$this->assertTrue(Validation::email('abc.efg@cakephp.org', true));
$this->assertFalse(Validation::email('abc.efg@caphpkeinvalid.com', true));
$this->assertFalse(Validation::email('abc@example.abcd', true));
}
/**
* testEmailCustomRegex method
*
* @return void
*/
public function testEmailCustomRegex() {
$this->assertTrue(Validation::email('abc.efg@cakephp.org', null, '/^[A-Z0-9._%-]+@[A-Z0-9.-]+\\.[A-Z]{2,4}$/i'));
$this->assertFalse(Validation::email('abc.efg@com.caphpkeinvalid', null, '/^[A-Z0-9._%-]+@[A-Z0-9.-]+\\.[A-Z]{2,4}$/i'));
}
/**
* testEqualTo method
*
* @return void
*/
public function testEqualTo() {
$this->assertTrue(Validation::equalTo("1", "1"));
$this->assertFalse(Validation::equalTo(1, "1"));
$this->assertFalse(Validation::equalTo("", null));
$this->assertFalse(Validation::equalTo("", false));
$this->assertFalse(Validation::equalTo(0, false));
$this->assertFalse(Validation::equalTo(null, false));
}
/**
* testIpV4 method
*
* @return void
*/
public function testIpV4() {
$this->assertTrue(Validation::ip('0.0.0.0'));
$this->assertTrue(Validation::ip('192.168.1.156'));
$this->assertTrue(Validation::ip('255.255.255.255'));
$this->assertFalse(Validation::ip('127.0.0'));
$this->assertFalse(Validation::ip('127.0.0.a'));
$this->assertFalse(Validation::ip('127.0.0.256'));
}
/**
* testIp v6
*
* @return void
*/
public function testIpv6() {
$this->assertTrue(Validation::ip('2001:0db8:85a3:0000:0000:8a2e:0370:7334', 'IPv6'));
$this->assertTrue(Validation::ip('2001:db8:85a3:0:0:8a2e:370:7334', 'IPv6'));
$this->assertTrue(Validation::ip('2001:db8:85a3::8a2e:370:7334', 'IPv6'));
$this->assertTrue(Validation::ip('2001:0db8:0000:0000:0000:0000:1428:57ab', 'IPv6'));
$this->assertTrue(Validation::ip('2001:0db8:0000:0000:0000::1428:57ab', 'IPv6'));
$this->assertTrue(Validation::ip('2001:0db8:0:0:0:0:1428:57ab', 'IPv6'));
$this->assertTrue(Validation::ip('2001:0db8:0:0::1428:57ab', 'IPv6'));
$this->assertTrue(Validation::ip('2001:0db8::1428:57ab', 'IPv6'));
$this->assertTrue(Validation::ip('2001:db8::1428:57ab', 'IPv6'));
$this->assertTrue(Validation::ip('0000:0000:0000:0000:0000:0000:0000:0001', 'IPv6'));
$this->assertTrue(Validation::ip('::1', 'IPv6'));
$this->assertTrue(Validation::ip('::ffff:12.34.56.78', 'IPv6'));
$this->assertTrue(Validation::ip('::ffff:0c22:384e', 'IPv6'));
$this->assertTrue(Validation::ip('2001:0db8:1234:0000:0000:0000:0000:0000', 'IPv6'));
$this->assertTrue(Validation::ip('2001:0db8:1234:ffff:ffff:ffff:ffff:ffff', 'IPv6'));
$this->assertTrue(Validation::ip('2001:db8:a::123', 'IPv6'));
$this->assertTrue(Validation::ip('fe80::', 'IPv6'));
$this->assertTrue(Validation::ip('::ffff:192.0.2.128', 'IPv6'));
$this->assertTrue(Validation::ip('::ffff:c000:280', 'IPv6'));
$this->assertFalse(Validation::ip('123', 'IPv6'));
$this->assertFalse(Validation::ip('ldkfj', 'IPv6'));
$this->assertFalse(Validation::ip('2001::FFD3::57ab', 'IPv6'));
$this->assertFalse(Validation::ip('2001:db8:85a3::8a2e:37023:7334', 'IPv6'));
$this->assertFalse(Validation::ip('2001:db8:85a3::8a2e:370k:7334', 'IPv6'));
$this->assertFalse(Validation::ip('1:2:3:4:5:6:7:8:9', 'IPv6'));
$this->assertFalse(Validation::ip('1::2::3', 'IPv6'));
$this->assertFalse(Validation::ip('1:::3:4:5', 'IPv6'));
$this->assertFalse(Validation::ip('1:2:3::4:5:6:7:8:9', 'IPv6'));
$this->assertFalse(Validation::ip('::ffff:2.3.4', 'IPv6'));
$this->assertFalse(Validation::ip('::ffff:257.1.2.3', 'IPv6'));
}
/**
* testMaxLength method
*
* @return void
*/
public function testMaxLength() {
$this->assertTrue(Validation::maxLength('ab', 3));
$this->assertTrue(Validation::maxLength('abc', 3));
$this->assertTrue(Validation::maxLength('ÆΔΩЖÇ', 10));
$this->assertFalse(Validation::maxLength('abcd', 3));
$this->assertFalse(Validation::maxLength('ÆΔΩЖÇ', 3));
}
/**
* testMinLength method
*
* @return void
*/
public function testMinLength() {
$this->assertFalse(Validation::minLength('ab', 3));
$this->assertFalse(Validation::minLength('ÆΔΩЖÇ', 10));
$this->assertTrue(Validation::minLength('abc', 3));
$this->assertTrue(Validation::minLength('abcd', 3));
$this->assertTrue(Validation::minLength('ÆΔΩЖÇ', 2));
}
/**
* testUrl method
*
* @return void
*/
public function testUrl() {
$this->assertTrue(Validation::url('http://www.cakephp.org'));
$this->assertTrue(Validation::url('http://cakephp.org'));
$this->assertTrue(Validation::url('http://www.cakephp.org/somewhere#anchor'));
$this->assertTrue(Validation::url('http://192.168.0.1'));
$this->assertTrue(Validation::url('https://www.cakephp.org'));
$this->assertTrue(Validation::url('https://cakephp.org'));
$this->assertTrue(Validation::url('https://www.cakephp.org/somewhere#anchor'));
$this->assertTrue(Validation::url('https://192.168.0.1'));
$this->assertTrue(Validation::url('ftps://www.cakephp.org/pub/cake'));
$this->assertTrue(Validation::url('ftps://cakephp.org/pub/cake'));
$this->assertTrue(Validation::url('ftps://192.168.0.1/pub/cake'));
$this->assertTrue(Validation::url('ftp://www.cakephp.org/pub/cake'));
$this->assertTrue(Validation::url('ftp://cakephp.org/pub/cake'));
$this->assertTrue(Validation::url('ftp://192.168.0.1/pub/cake'));
$this->assertFalse(Validation::url('ftps://256.168.0.1/pub/cake'));
$this->assertFalse(Validation::url('ftp://256.168.0.1/pub/cake'));
$this->assertTrue(Validation::url('https://my.domain.com/gizmo/app?class=MySip;proc=start'));
$this->assertTrue(Validation::url('www.domain.tld'));
$this->assertFalse(Validation::url('http://w_w.domain.co_m'));
$this->assertFalse(Validation::url('http://www.domain.12com'));
$this->assertFalse(Validation::url('http://www.domain.longttldnotallowed'));
$this->assertFalse(Validation::url('http://www.-invaliddomain.tld'));
$this->assertFalse(Validation::url('http://www.domain.-invalidtld'));
$this->assertTrue(Validation::url('http://123456789112345678921234567893123456789412345678951234567896123.com'));
$this->assertFalse(Validation::url('http://this-domain-is-too-loooooong-by-icann-rules-maximum-length-is-63.com'));
$this->assertTrue(Validation::url('http://www.domain.com/blogs/index.php?blog=6&tempskin=_rss2'));
$this->assertTrue(Validation::url('http://www.domain.com/blogs/parenth()eses.php'));
$this->assertTrue(Validation::url('http://www.domain.com/index.php?get=params&get2=params'));
$this->assertTrue(Validation::url('http://www.domain.com/ndex.php?get=params&get2=params#anchor'));
$this->assertFalse(Validation::url('http://www.domain.com/fakeenco%ode'));
$this->assertTrue(Validation::url('http://www.domain.com/real%20url%20encodeing'));
$this->assertTrue(Validation::url('http://en.wikipedia.org/wiki/Architectural_pattern_(computer_science)'));
$this->assertFalse(Validation::url('http://en.(wikipedia).org/'));
$this->assertFalse(Validation::url('www.cakephp.org', true));
$this->assertTrue(Validation::url('http://www.cakephp.org', true));
$this->assertTrue(Validation::url('http://example.com/~userdir/'));
$this->assertTrue(Validation::url('http://example.com/~userdir/subdir/index.html'));
$this->assertTrue(Validation::url('http://www.zwischenraume.de'));
$this->assertTrue(Validation::url('http://www.zwischenraume.cz'));
$this->assertTrue(Validation::url('http://www.last.fm/music/浜崎あゆみ'), 'utf8 path failed');
$this->assertTrue(Validation::url('http://www.electrohome.ro/images/239537750-284232-215_300[1].jpg'));
$this->assertTrue(Validation::url('http://cakephp.org:80'));
$this->assertTrue(Validation::url('http://cakephp.org:443'));
$this->assertTrue(Validation::url('http://cakephp.org:2000'));
$this->assertTrue(Validation::url('http://cakephp.org:27000'));
$this->assertTrue(Validation::url('http://cakephp.org:65000'));
$this->assertTrue(Validation::url('[2001:0db8::1428:57ab]'));
$this->assertTrue(Validation::url('[::1]'));
$this->assertTrue(Validation::url('[2001:0db8::1428:57ab]:80'));
$this->assertTrue(Validation::url('[::1]:80'));
$this->assertTrue(Validation::url('http://[2001:0db8::1428:57ab]'));
$this->assertTrue(Validation::url('http://[::1]'));
$this->assertTrue(Validation::url('http://[2001:0db8::1428:57ab]:80'));
$this->assertTrue(Validation::url('http://[::1]:80'));
$this->assertFalse(Validation::url('[1::2::3]'));
}
public function testUuid() {
$this->assertTrue(Validation::uuid('550e8400-e29b-11d4-a716-446655440000'));
$this->assertFalse(Validation::uuid('BRAP-e29b-11d4-a716-446655440000'));
$this->assertTrue(Validation::uuid('550E8400-e29b-11D4-A716-446655440000'));
$this->assertFalse(Validation::uuid('550e8400-e29b11d4-a716-446655440000'));
$this->assertFalse(Validation::uuid('550e8400-e29b-11d4-a716-4466440000'));
$this->assertFalse(Validation::uuid('550e8400-e29b-11d4-a71-446655440000'));
$this->assertFalse(Validation::uuid('550e8400-e29b-11d-a716-446655440000'));
$this->assertFalse(Validation::uuid('550e8400-e29-11d4-a716-446655440000'));
}
/**
* testInList method
*
* @return void
*/
public function testInList() {
$this->assertTrue(Validation::inList('one', array('one', 'two')));
$this->assertTrue(Validation::inList('two', array('one', 'two')));
$this->assertFalse(Validation::inList('three', array('one', 'two')));
}
/**
* testRange method
*
* @return void
*/
public function testRange() {
$this->assertFalse(Validation::range(20, 100, 1));
$this->assertTrue(Validation::range(20, 1, 100));
$this->assertFalse(Validation::range(.5, 1, 100));
$this->assertTrue(Validation::range(.5, 0, 100));
$this->assertTrue(Validation::range(5));
$this->assertTrue(Validation::range(-5, -10, 1));
$this->assertFalse(Validation::range('word'));
}
/**
* testExtension method
*
* @return void
*/
public function testExtension() {
$this->assertTrue(Validation::extension('extension.jpeg'));
$this->assertTrue(Validation::extension('extension.JPEG'));
$this->assertTrue(Validation::extension('extension.gif'));
$this->assertTrue(Validation::extension('extension.GIF'));
$this->assertTrue(Validation::extension('extension.png'));
$this->assertTrue(Validation::extension('extension.jpg'));
$this->assertTrue(Validation::extension('extension.JPG'));
$this->assertFalse(Validation::extension('noextension'));
$this->assertTrue(Validation::extension('extension.pdf', array('PDF')));
$this->assertFalse(Validation::extension('extension.jpg', array('GIF')));
$this->assertTrue(Validation::extension(array('extension.JPG', 'extension.gif', 'extension.png')));
$this->assertTrue(Validation::extension(array('file' => array('name' => 'file.jpg'))));
$this->assertTrue(Validation::extension(array('file1' => array('name' => 'file.jpg'),
'file2' => array('name' => 'file.jpg'),
'file3' => array('name' => 'file.jpg'))));
$this->assertFalse(Validation::extension(array('file1' => array('name' => 'file.jpg'),
'file2' => array('name' => 'file.jpg'),
'file3' => array('name' => 'file.jpg')), array('gif')));
$this->assertFalse(Validation::extension(array('noextension', 'extension.JPG', 'extension.gif', 'extension.png')));
$this->assertFalse(Validation::extension(array('extension.pdf', 'extension.JPG', 'extension.gif', 'extension.png')));
}
/**
* testMoney method
*
* @return void
*/
public function testMoney() {
$this->assertTrue(Validation::money('$100'));
$this->assertTrue(Validation::money('$100.11'));
$this->assertTrue(Validation::money('$100.112'));
$this->assertFalse(Validation::money('$100.1'));
$this->assertFalse(Validation::money('$100.1111'));
$this->assertFalse(Validation::money('text'));
$this->assertTrue(Validation::money('100', 'right'));
$this->assertTrue(Validation::money('100.11$', 'right'));
$this->assertTrue(Validation::money('100.112$', 'right'));
$this->assertFalse(Validation::money('100.1$', 'right'));
$this->assertFalse(Validation::money('100.1111$', 'right'));
$this->assertTrue(Validation::money('€100'));
$this->assertTrue(Validation::money('€100.11'));
$this->assertTrue(Validation::money('€100.112'));
$this->assertFalse(Validation::money('€100.1'));
$this->assertFalse(Validation::money('€100.1111'));
$this->assertTrue(Validation::money('100', 'right'));
$this->assertTrue(Validation::money('100.11€', 'right'));
$this->assertTrue(Validation::money('100.112€', 'right'));
$this->assertFalse(Validation::money('100.1€', 'right'));
$this->assertFalse(Validation::money('100.1111€', 'right'));
}
/**
* Test Multiple Select Validation
*
* @return void
*/
public function testMultiple() {
$this->assertTrue(Validation::multiple(array(0, 1, 2, 3)));
$this->assertTrue(Validation::multiple(array(50, 32, 22, 0)));
$this->assertTrue(Validation::multiple(array('str', 'var', 'enum', 0)));
$this->assertFalse(Validation::multiple(''));
$this->assertFalse(Validation::multiple(null));
$this->assertFalse(Validation::multiple(array()));
$this->assertFalse(Validation::multiple(array(0)));
$this->assertFalse(Validation::multiple(array('0')));
$this->assertTrue(Validation::multiple(array(0, 3, 4, 5), array('in' => range(0, 10))));
$this->assertFalse(Validation::multiple(array(0, 15, 20, 5), array('in' => range(0, 10))));
$this->assertFalse(Validation::multiple(array(0, 5, 10, 11), array('in' => range(0, 10))));
$this->assertFalse(Validation::multiple(array('boo', 'foo', 'bar'), array('in' => array('foo', 'bar', 'baz'))));
$this->assertTrue(Validation::multiple(array(0, 5, 10, 11), array('max' => 3)));
$this->assertFalse(Validation::multiple(array(0, 5, 10, 11, 55), array('max' => 3)));
$this->assertTrue(Validation::multiple(array('foo', 'bar', 'baz'), array('max' => 3)));
$this->assertFalse(Validation::multiple(array('foo', 'bar', 'baz', 'squirrel'), array('max' => 3)));
$this->assertTrue(Validation::multiple(array(0, 5, 10, 11), array('min' => 3)));
$this->assertTrue(Validation::multiple(array(0, 5, 10, 11, 55), array('min' => 3)));
$this->assertFalse(Validation::multiple(array('foo', 'bar', 'baz'), array('min' => 5)));
$this->assertFalse(Validation::multiple(array('foo', 'bar', 'baz', 'squirrel'), array('min' => 10)));
$this->assertTrue(Validation::multiple(array(0, 5, 9), array('in' => range(0, 10), 'max' => 5)));
$this->assertFalse(Validation::multiple(array(0, 5, 9, 8, 6, 2, 1), array('in' => range(0, 10), 'max' => 5)));
$this->assertFalse(Validation::multiple(array(0, 5, 9, 8, 11), array('in' => range(0, 10), 'max' => 5)));
$this->assertFalse(Validation::multiple(array(0, 5, 9), array('in' => range(0, 10), 'max' => 5, 'min' => 3)));
$this->assertFalse(Validation::multiple(array(0, 5, 9, 8, 6, 2, 1), array('in' => range(0, 10), 'max' => 5, 'min' => 2)));
$this->assertFalse(Validation::multiple(array(0, 5, 9, 8, 11), array('in' => range(0, 10), 'max' => 5, 'min' => 2)));
}
/**
* testNumeric method
*
* @return void
*/
public function testNumeric() {
$this->assertFalse(Validation::numeric('teststring'));
$this->assertFalse(Validation::numeric('1.1test'));
$this->assertFalse(Validation::numeric('2test'));
$this->assertTrue(Validation::numeric('2'));
$this->assertTrue(Validation::numeric(2));
$this->assertTrue(Validation::numeric(2.2));
$this->assertTrue(Validation::numeric('2.2'));
}
/**
* testPhone method
*
* @return void
*/
public function testPhone() {
$this->assertFalse(Validation::phone('teststring'));
$this->assertFalse(Validation::phone('1-(33)-(333)-(4444)'));
$this->assertFalse(Validation::phone('1-(33)-3333-4444'));
$this->assertFalse(Validation::phone('1-(33)-33-4444'));
$this->assertFalse(Validation::phone('1-(33)-3-44444'));
$this->assertFalse(Validation::phone('1-(33)-3-444'));
$this->assertFalse(Validation::phone('1-(33)-3-44'));
$this->assertFalse(Validation::phone('(055) 999-9999'));
$this->assertFalse(Validation::phone('(155) 999-9999'));
$this->assertFalse(Validation::phone('(595) 999-9999'));
$this->assertFalse(Validation::phone('(555) 099-9999'));
$this->assertFalse(Validation::phone('(555) 199-9999'));
$this->assertTrue(Validation::phone('1 (222) 333 4444'));
$this->assertTrue(Validation::phone('+1 (222) 333 4444'));
$this->assertTrue(Validation::phone('(222) 333 4444'));
$this->assertTrue(Validation::phone('1-(333)-333-4444'));
$this->assertTrue(Validation::phone('1.(333)-333-4444'));
$this->assertTrue(Validation::phone('1.(333).333-4444'));
$this->assertTrue(Validation::phone('1.(333).333.4444'));
$this->assertTrue(Validation::phone('1-333-333-4444'));
}
/**
* testPostal method
*
* @return void
*/
public function testPostal() {
$this->assertFalse(Validation::postal('111', null, 'de'));
$this->assertFalse(Validation::postal('1111', null, 'de'));
$this->assertTrue(Validation::postal('13089', null, 'de'));
$this->assertFalse(Validation::postal('111', null, 'be'));
$this->assertFalse(Validation::postal('0123', null, 'be'));
$this->assertTrue(Validation::postal('1204', null, 'be'));
$this->assertFalse(Validation::postal('111', null, 'it'));
$this->assertFalse(Validation::postal('1111', null, 'it'));
$this->assertTrue(Validation::postal('13089', null, 'it'));
$this->assertFalse(Validation::postal('111', null, 'uk'));
$this->assertFalse(Validation::postal('1111', null, 'uk'));
$this->assertFalse(Validation::postal('AZA 0AB', null, 'uk'));
$this->assertFalse(Validation::postal('X0A 0ABC', null, 'uk'));
$this->assertTrue(Validation::postal('X0A 0AB', null, 'uk'));
$this->assertTrue(Validation::postal('AZ0A 0AA', null, 'uk'));
$this->assertTrue(Validation::postal('A89 2DD', null, 'uk'));
$this->assertFalse(Validation::postal('111', null, 'ca'));
$this->assertFalse(Validation::postal('1111', null, 'ca'));
$this->assertFalse(Validation::postal('D2A 0A0', null, 'ca'));
$this->assertFalse(Validation::postal('BAA 0ABC', null, 'ca'));
$this->assertFalse(Validation::postal('B2A AABC', null, 'ca'));
$this->assertFalse(Validation::postal('B2A 2AB', null, 'ca'));
$this->assertTrue(Validation::postal('X0A 0A2', null, 'ca'));
$this->assertTrue(Validation::postal('G4V 4C3', null, 'ca'));
$this->assertFalse(Validation::postal('111', null, 'us'));
$this->assertFalse(Validation::postal('1111', null, 'us'));
$this->assertFalse(Validation::postal('130896', null, 'us'));
$this->assertFalse(Validation::postal('13089-33333', null, 'us'));
$this->assertFalse(Validation::postal('13089-333', null, 'us'));
$this->assertFalse(Validation::postal('13A89-4333', null, 'us'));
$this->assertTrue(Validation::postal('13089-3333', null, 'us'));
$this->assertFalse(Validation::postal('111'));
$this->assertFalse(Validation::postal('1111'));
$this->assertFalse(Validation::postal('130896'));
$this->assertFalse(Validation::postal('13089-33333'));
$this->assertFalse(Validation::postal('13089-333'));
$this->assertFalse(Validation::postal('13A89-4333'));
$this->assertTrue(Validation::postal('13089-3333'));
}
/**
* test that phone and postal pass to other classes.
*
* @return void
*/
public function testPhonePostalSsnPass() {
$this->assertTrue(Validation::postal('text', null, 'testNl'));
$this->assertTrue(Validation::phone('text', null, 'testDe'));
$this->assertTrue(Validation::ssn('text', null, 'testNl'));
}
/**
* test pass through failure on postal
*
* @expectedException PHPUnit_Framework_Error
* @return void
*/
public function testPassThroughMethodFailure() {
Validation::phone('text', null, 'testNl');
}
/**
* test the pass through calling of an alternate locale with postal()
*
* @expectedException PHPUnit_Framework_Error
* @return void
**/
public function testPassThroughClassFailure() {
Validation::postal('text', null, 'AUTOFAIL');
}
/**
* test pass through method
*
* @return void
*/
public function testPassThroughMethod() {
$this->assertTrue(Validation::postal('text', null, 'testNl'));
}
/**
* testSsn method
*
* @return void
*/
public function testSsn() {
$this->assertFalse(Validation::ssn('111-333', null, 'dk'));
$this->assertFalse(Validation::ssn('111111-333', null, 'dk'));
$this->assertTrue(Validation::ssn('111111-3334', null, 'dk'));
$this->assertFalse(Validation::ssn('1118333', null, 'nl'));
$this->assertFalse(Validation::ssn('1234567890', null, 'nl'));
$this->assertFalse(Validation::ssn('12345A789', null, 'nl'));
$this->assertTrue(Validation::ssn('123456789', null, 'nl'));
$this->assertFalse(Validation::ssn('11-33-4333', null, 'us'));
$this->assertFalse(Validation::ssn('113-3-4333', null, 'us'));
$this->assertFalse(Validation::ssn('111-33-333', null, 'us'));
$this->assertTrue(Validation::ssn('111-33-4333', null, 'us'));
}
/**
* testUserDefined method
*
* @return void
*/
public function testUserDefined() {
$validator = new CustomValidator;
$this->assertFalse(Validation::userDefined('33', $validator, 'customValidate'));
$this->assertFalse(Validation::userDefined('3333', $validator, 'customValidate'));
$this->assertTrue(Validation::userDefined('333', $validator, 'customValidate'));
}
/**
* testDatetime method
*
* @return void
*/
function testDatetime() {
$this->assertTrue(Validation::datetime('27-12-2006 01:00', 'dmy'));
$this->assertTrue(Validation::datetime('27-12-2006 01:00', array('dmy')));
$this->assertFalse(Validation::datetime('27-12-2006 1:00', 'dmy'));
$this->assertTrue(Validation::datetime('27.12.2006 1:00pm', 'dmy'));
$this->assertFalse(Validation::datetime('27.12.2006 13:00pm', 'dmy'));
$this->assertTrue(Validation::datetime('27/12/2006 1:00pm', 'dmy'));
$this->assertFalse(Validation::datetime('27/12/2006 9:00', 'dmy'));
$this->assertTrue(Validation::datetime('27 12 2006 1:00pm', 'dmy'));
$this->assertFalse(Validation::datetime('27 12 2006 24:00', 'dmy'));
$this->assertFalse(Validation::datetime('00-00-0000 1:00pm', 'dmy'));
$this->assertFalse(Validation::datetime('00.00.0000 1:00pm', 'dmy'));
$this->assertFalse(Validation::datetime('00/00/0000 1:00pm', 'dmy'));
$this->assertFalse(Validation::datetime('00 00 0000 1:00pm', 'dmy'));
$this->assertFalse(Validation::datetime('31-11-2006 1:00pm', 'dmy'));
$this->assertFalse(Validation::datetime('31.11.2006 1:00pm', 'dmy'));
$this->assertFalse(Validation::datetime('31/11/2006 1:00pm', 'dmy'));
$this->assertFalse(Validation::datetime('31 11 2006 1:00pm', 'dmy'));
}
}
| 0001-bee | trunk/cakephp2/lib/Cake/Test/Case/Utility/ValidationTest.php | PHP | gpl3 | 98,976 |
<?php
/**
* XmlTest file
*
* PHP 5
*
* CakePHP(tm) Tests <http://book.cakephp.org/view/1196/Testing>
* Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice
*
* @copyright Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://book.cakephp.org/view/1196/Testing CakePHP(tm) Tests
* @package Cake.Test.Case.Utility
* @since CakePHP(tm) v 1.2.0.5432
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
App::uses('Xml', 'Utility');
App::uses('CakeTestModel', 'TestSuite/Fixture');
/**
* Article class
*
* @package Cake.Test.Case.Utility
*/
class XmlArticle extends CakeTestModel {
/**
* name property
*
* @var string 'Article'
*/
public $name = 'Article';
/**
* belongsTo property
*
* @var array
*/
public $belongsTo = array(
'XmlUser' => array(
'className' => 'XmlArticle',
'foreignKey' => 'user_id'
)
);
}
/**
* User class
*
* @package Cake.Test.Case.Utility
*/
class XmlUser extends CakeTestModel {
/**
* name property
*
* @var string 'User'
*/
public $name = 'User';
/**
* hasMany property
*
* @var array
*/
public $hasMany = array('Article');
}
/**
* XmlTest class
*
* @package Cake.Test.Case.Utility
*/
class XmlTest extends CakeTestCase {
/**
* autoFixtures property
*
* @var bool false
*/
public $autoFixtures = false;
/**
* fixtures property
* @var array
*/
public $fixtures = array(
'core.article', 'core.user'
);
/**
* setup method
*
* @return void
*/
public function setUp() {
parent::setup();
$this->_appEncoding = Configure::read('App.encoding');
Configure::write('App.encoding', 'UTF-8');
}
/**
* tearDown method
*
* @return void
*/
public function tearDown() {
parent::tearDown();
Configure::write('App.encoding', $this->_appEncoding);
}
/**
* testBuild method
*
* @return void
*/
public function testBuild() {
$xml = '<tag>value</tag>';
$obj = Xml::build($xml);
$this->assertTrue($obj instanceof SimpleXMLElement);
$this->assertEqual((string)$obj->getName(), 'tag');
$this->assertEqual((string)$obj, 'value');
$xml = '<?xml version="1.0" encoding="UTF-8"?><tag>value</tag>';
$this->assertEqual($obj, Xml::build($xml));
$obj = Xml::build($xml, array('return' => 'domdocument'));
$this->assertTrue($obj instanceof DOMDocument);
$this->assertEqual($obj->firstChild->nodeName, 'tag');
$this->assertEqual($obj->firstChild->nodeValue, 'value');
$xml = CAKE . 'Test' . DS . 'Fixture' . DS . 'sample.xml';
$obj = Xml::build($xml);
$this->assertEqual($obj->getName(), 'tags');
$this->assertEqual(count($obj), 2);
$this->assertEqual(Xml::build($xml), Xml::build(file_get_contents($xml)));
$obj = Xml::build($xml, array('return' => 'domdocument'));
$this->assertEqual($obj->firstChild->nodeName, 'tags');
$this->assertEqual(Xml::build($xml, array('return' => 'domdocument')), Xml::build(file_get_contents($xml), array('return' => 'domdocument')));
$this->assertEqual(Xml::build($xml, array('return' => 'simplexml')), Xml::build($xml, 'simplexml'));
$xml = array('tag' => 'value');
$obj = Xml::build($xml);
$this->assertEqual($obj->getName(), 'tag');
$this->assertEqual((string)$obj, 'value');
$obj = Xml::build($xml, array('return' => 'domdocument'));
$this->assertEqual($obj->firstChild->nodeName, 'tag');
$this->assertEqual($obj->firstChild->nodeValue, 'value');
$obj = Xml::build($xml, array('return' => 'domdocument', 'encoding' => null));
$this->assertNoPattern('/encoding/', $obj->saveXML());
}
/**
* data provider function for testBuildInvalidData
*
* @return array
*/
public static function invalidDataProvider() {
return array(
array(null),
array(false),
array(''),
array('<tag>')
);
}
/**
* testBuildInvalidData
*
* @dataProvider invalidDataProvider
* @expectedException Exception
* return void
*/
public function testBuildInvalidData($value) {
Xml::build($value);
}
/**
* testFromArray method
*
* @return void
*/
public function testFromArray() {
$xml = array('tag' => 'value');
$obj = Xml::fromArray($xml);
$this->assertEqual($obj->getName(), 'tag');
$this->assertEqual((string)$obj, 'value');
$xml = array('tag' => null);
$obj = Xml::fromArray($xml);
$this->assertEqual($obj->getName(), 'tag');
$this->assertEqual((string)$obj, '');
$xml = array('tag' => array('@' => 'value'));
$obj = Xml::fromArray($xml);
$this->assertEqual($obj->getName(), 'tag');
$this->assertEqual((string)$obj, 'value');
$xml = array(
'tags' => array(
'tag' => array(
array(
'id' => '1',
'name' => 'defect'
),
array(
'id' => '2',
'name' => 'enhancement'
)
)
)
);
$obj = Xml::fromArray($xml, 'attributes');
$this->assertTrue($obj instanceof SimpleXMLElement);
$this->assertEqual($obj->getName(), 'tags');
$this->assertEqual(count($obj), 2);
$xmlText = '<' . '?xml version="1.0" encoding="UTF-8"?><tags><tag id="1" name="defect"/><tag id="2" name="enhancement"/></tags>';
$this->assertEqual(str_replace(array("\r", "\n"), '', $obj->asXML()), $xmlText);
$obj = Xml::fromArray($xml);
$this->assertTrue($obj instanceof SimpleXMLElement);
$this->assertEqual($obj->getName(), 'tags');
$this->assertEqual(count($obj), 2);
$xmlText = '<' . '?xml version="1.0" encoding="UTF-8"?><tags><tag><id>1</id><name>defect</name></tag><tag><id>2</id><name>enhancement</name></tag></tags>';
$this->assertEqual(str_replace(array("\r", "\n"), '', $obj->asXML()), $xmlText);
$xml = array(
'tags' => array(
)
);
$obj = Xml::fromArray($xml);
$this->assertEqual($obj->getName(), 'tags');
$this->assertEqual((string)$obj, '');
$xml = array(
'tags' => array(
'bool' => true,
'int' => 1,
'float' => 10.2,
'string' => 'ok',
'null' => null,
'array' => array()
)
);
$obj = Xml::fromArray($xml, 'tags');
$this->assertEqual(count($obj), 6);
$this->assertIdentical((string)$obj->bool, '1');
$this->assertIdentical((string)$obj->int, '1');
$this->assertIdentical((string)$obj->float, '10.2');
$this->assertIdentical((string)$obj->string, 'ok');
$this->assertIdentical((string)$obj->null, '');
$this->assertIdentical((string)$obj->array, '');
$xml = array(
'tags' => array(
'tag' => array(
array(
'@id' => '1',
'name' => 'defect'
),
array(
'@id' => '2',
'name' => 'enhancement'
)
)
)
);
$obj = Xml::fromArray($xml, 'tags');
$xmlText = '<' . '?xml version="1.0" encoding="UTF-8"?><tags><tag id="1"><name>defect</name></tag><tag id="2"><name>enhancement</name></tag></tags>';
$this->assertEqual(str_replace(array("\r", "\n"), '', $obj->asXML()), $xmlText);
$xml = array(
'tags' => array(
'tag' => array(
array(
'@id' => '1',
'name' => 'defect',
'@' => 'Tag 1'
),
array(
'@id' => '2',
'name' => 'enhancement'
),
),
'@' => 'All tags'
)
);
$obj = Xml::fromArray($xml, 'tags');
$xmlText = '<' . '?xml version="1.0" encoding="UTF-8"?><tags>All tags<tag id="1">Tag 1<name>defect</name></tag><tag id="2"><name>enhancement</name></tag></tags>';
$this->assertEqual(str_replace(array("\r", "\n"), '', $obj->asXML()), $xmlText);
$xml = array(
'tags' => array(
'tag' => array(
'id' => 1,
'@' => 'defect'
)
)
);
$obj = Xml::fromArray($xml, 'attributes');
$xmlText = '<' . '?xml version="1.0" encoding="UTF-8"?><tags><tag id="1">defect</tag></tags>';
$this->assertEqual(str_replace(array("\r", "\n"), '', $obj->asXML()), $xmlText);
}
/**
* data provider for fromArray() failures
*
* @return array
*/
public static function invalidArrayDataProvider() {
return array(
array(''),
array(null),
array(false),
array(array()),
array(array('numeric key as root')),
array(array('item1' => '', 'item2' => '')),
array(array('items' => array('item1', 'item2'))),
array(array(
'tags' => array(
'tag' => array(
array(
array(
'string'
)
)
)
)
)),
array(array(
'tags' => array(
'@tag' => array(
array(
'@id' => '1',
'name' => 'defect'
),
array(
'@id' => '2',
'name' => 'enhancement'
)
)
)
)),
array(new DateTime())
);
}
/**
* testFromArrayFail method
*
* @dataProvider invalidArrayDataProvider
* @expectedException Exception
*/
public function testFromArrayFail($value) {
Xml::fromArray($value);
}
/**
* testToArray method
*
* @return void
*/
public function testToArray() {
$xml = '<tag>name</tag>';
$obj = Xml::build($xml);
$this->assertEqual(Xml::toArray($obj), array('tag' => 'name'));
$xml = CAKE . 'Test' . DS . 'Fixture' . DS . 'sample.xml';
$obj = Xml::build($xml);
$expected = array(
'tags' => array(
'tag' => array(
array(
'@id' => '1',
'name' => 'defect'
),
array(
'@id' => '2',
'name' => 'enhancement'
)
)
)
);
$this->assertEqual(Xml::toArray($obj), $expected);
$array = array(
'tags' => array(
'tag' => array(
array(
'id' => '1',
'name' => 'defect'
),
array(
'id' => '2',
'name' => 'enhancement'
)
)
)
);
$this->assertEqual(Xml::toArray(Xml::fromArray($array, 'tags')), $array);
$expected = array(
'tags' => array(
'tag' => array(
array(
'@id' => '1',
'@name' => 'defect'
),
array(
'@id' => '2',
'@name' => 'enhancement'
)
)
)
);
$this->assertEqual(Xml::toArray(Xml::fromArray($array, 'attributes')), $expected);
$this->assertEqual(Xml::toArray(Xml::fromArray($array, array('return' => 'domdocument', 'format' => 'attributes'))), $expected);
$this->assertEqual(Xml::toArray(Xml::fromArray($array)), $array);
$this->assertEqual(Xml::toArray(Xml::fromArray($array, array('return' => 'domdocument'))), $array);
$array = array(
'tags' => array(
'tag' => array(
'id' => '1',
'posts' => array(
array('id' => '1'),
array('id' => '2')
)
),
'tagOther' => array(
'subtag' => array(
'id' => '1'
)
)
)
);
$expected = array(
'tags' => array(
'tag' => array(
'@id' => '1',
'posts' => array(
array('@id' => '1'),
array('@id' => '2')
)
),
'tagOther' => array(
'subtag' => array(
'@id' => '1'
)
)
)
);
$this->assertEqual(Xml::toArray(Xml::fromArray($array, 'attributes')), $expected);
$this->assertEqual(Xml::toArray(Xml::fromArray($array, array('format' => 'attributes', 'return' => 'domdocument'))), $expected);
$xml = '<root>';
$xml .= '<tag id="1">defect</tag>';
$xml .= '</root>';
$obj = Xml::build($xml);
$expected = array(
'root' => array(
'tag' => array(
'@id' => 1,
'@' => 'defect'
)
)
);
$this->assertEqual(Xml::toArray($obj), $expected);
$xml = '<root>';
$xml .= '<table xmlns="http://www.w3.org/TR/html4/"><tr><td>Apples</td><td>Bananas</td></tr></table>';
$xml .= '<table xmlns="http://www.cakephp.org"><name>CakePHP</name><license>MIT</license></table>';
$xml .= '<table>The book is on the table.</table>';
$xml .= '</root>';
$obj = Xml::build($xml);
$expected = array(
'root' => array(
'table' => array(
array('tr' => array('td' => array('Apples', 'Bananas'))),
array('name' => 'CakePHP', 'license' => 'MIT'),
'The book is on the table.'
)
)
);
$this->assertEqual(Xml::toArray($obj), $expected);
$xml = '<root xmlns:cake="http://www.cakephp.org/">';
$xml .= '<tag>defect</tag>';
$xml .= '<cake:bug>1</cake:bug>';
$xml .= '</root>';
$obj = Xml::build($xml);
$expected = array(
'root' => array(
'tag' => 'defect',
'cake:bug' => 1
)
);
$this->assertEqual(Xml::toArray($obj), $expected);
}
/**
* testRss
*
* @return void
*/
public function testRss() {
$rss = file_get_contents(CAKE . 'Test' . DS . 'Fixture' . DS . 'rss.xml');
$rssAsArray = Xml::toArray(Xml::build($rss));
$this->assertEqual($rssAsArray['rss']['@version'], '2.0');
$this->assertEqual(count($rssAsArray['rss']['channel']['item']), 2);
$atomLink = array('@href' => 'http://bakery.cakephp.org/articles/rss', '@rel' => 'self', '@type' => 'application/rss+xml');
$this->assertEqual($rssAsArray['rss']['channel']['atom:link'], $atomLink);
$this->assertEqual($rssAsArray['rss']['channel']['link'], 'http://bakery.cakephp.org/');
$expected = array(
'title' => 'Alertpay automated sales via IPN',
'link' => 'http://bakery.cakephp.org/articles/view/alertpay-automated-sales-via-ipn',
'description' => 'I\'m going to show you how I implemented a payment module via the Alertpay payment processor.',
'pubDate' => 'Tue, 31 Aug 2010 01:42:00 -0500',
'guid' => 'http://bakery.cakephp.org/articles/view/alertpay-automated-sales-via-ipn'
);
$this->assertIdentical($rssAsArray['rss']['channel']['item'][1], $expected);
$rss = array(
'rss' => array(
'xmlns:atom' => 'http://www.w3.org/2005/Atom',
'@version' => '2.0',
'channel' => array(
'atom:link' => array(
'@href' => 'http://bakery.cakephp.org/articles/rss',
'@rel' => 'self',
'@type' => 'application/rss+xml'
),
'title' => 'The Bakery: ',
'link' => 'http://bakery.cakephp.org/',
'description' => 'Recent Articles at The Bakery.',
'pubDate' => 'Sun, 12 Sep 2010 04:18:26 -0500',
'item' => array(
array(
'title' => 'CakePHP 1.3.4 released',
'link' => 'http://bakery.cakephp.org/articles/view/cakephp-1-3-4-released'
),
array(
'title' => 'Wizard Component 1.2 Tutorial',
'link' => 'http://bakery.cakephp.org/articles/view/wizard-component-1-2-tutorial'
)
)
)
)
);
$rssAsSimpleXML = Xml::fromArray($rss);
$xmlText = '<' . '?xml version="1.0" encoding="UTF-8"?>';
$xmlText .= '<rss xmlns:atom="http://www.w3.org/2005/Atom" version="2.0">';
$xmlText .= '<channel>';
$xmlText .= '<atom:link href="http://bakery.cakephp.org/articles/rss" rel="self" type="application/rss+xml"/>';
$xmlText .= '<title>The Bakery: </title>';
$xmlText .= '<link>http://bakery.cakephp.org/</link>';
$xmlText .= '<description>Recent Articles at The Bakery.</description>';
$xmlText .= '<pubDate>Sun, 12 Sep 2010 04:18:26 -0500</pubDate>';
$xmlText .= '<item><title>CakePHP 1.3.4 released</title><link>http://bakery.cakephp.org/articles/view/cakephp-1-3-4-released</link></item>';
$xmlText .= '<item><title>Wizard Component 1.2 Tutorial</title><link>http://bakery.cakephp.org/articles/view/wizard-component-1-2-tutorial</link></item>';
$xmlText .= '</channel></rss>';
$this->assertEqual(str_replace(array("\r", "\n"), '', $rssAsSimpleXML->asXML()), $xmlText);
}
/**
* testXmlRpc
*
* @return void
*/
public function testXmlRpc() {
$xml = Xml::build('<methodCall><methodName>test</methodName><params /></methodCall>');
$expected = array(
'methodCall' => array(
'methodName' => 'test',
'params' => ''
)
);
$this->assertIdentical(Xml::toArray($xml), $expected);
$xml = Xml::build('<methodCall><methodName>test</methodName><params><param><value><array><data><value><int>12</int></value><value><string>Egypt</string></value><value><boolean>0</boolean></value><value><int>-31</int></value></data></array></value></param></params></methodCall>');
$expected = array(
'methodCall' => array(
'methodName' => 'test',
'params' => array(
'param' => array(
'value' => array(
'array' => array(
'data' => array(
'value' => array(
array('int' => '12'),
array('string' => 'Egypt'),
array('boolean' => '0'),
array('int' => '-31')
)
)
)
)
)
)
)
);
$this->assertIdentical(Xml::toArray($xml), $expected);
$xmlText = '<?xml version="1.0" encoding="UTF-8"?><methodResponse><params><param><value><array><data><value><int>1</int></value><value><string>testing</string></value></data></array></value></param></params></methodResponse>';
$xml = Xml::build($xmlText);
$expected = array(
'methodResponse' => array(
'params' => array(
'param' => array(
'value' => array(
'array' => array(
'data' => array(
'value' => array(
array('int' => '1'),
array('string' => 'testing')
)
)
)
)
)
)
)
);
$this->assertIdentical(Xml::toArray($xml), $expected);
$xml = Xml::fromArray($expected, 'tags');
$this->assertEqual(str_replace(array("\r", "\n"), '', $xml->asXML()), $xmlText);
}
/**
* testSoap
*
* @return void
*/
public function testSoap() {
$xmlRequest = Xml::build(CAKE . 'Test' . DS . 'Fixture' . DS . 'soap_request.xml');
$expected = array(
'Envelope' => array(
'@soap:encodingStyle' => 'http://www.w3.org/2001/12/soap-encoding',
'soap:Body' => array(
'm:GetStockPrice' => array(
'm:StockName' => 'IBM'
)
)
)
);
$this->assertEqual(Xml::toArray($xmlRequest), $expected);
$xmlResponse = Xml::build(CAKE . 'Test' . DS . 'Fixture' . DS . 'soap_response.xml');
$expected = array(
'Envelope' => array(
'@soap:encodingStyle' => 'http://www.w3.org/2001/12/soap-encoding',
'soap:Body' => array(
'm:GetStockPriceResponse' => array(
'm:Price' => '34.5'
)
)
)
);
$this->assertEqual(Xml::toArray($xmlResponse), $expected);
$xml = array(
'soap:Envelope' => array(
'xmlns:soap' => 'http://www.w3.org/2001/12/soap-envelope',
'@soap:encodingStyle' => 'http://www.w3.org/2001/12/soap-encoding',
'soap:Body' => array(
'xmlns:m' => 'http://www.example.org/stock',
'm:GetStockPrice' => array(
'm:StockName' => 'IBM'
)
)
)
);
$xmlRequest = Xml::fromArray($xml, array('encoding' => null));
$xmlText = '<' . '?xml version="1.0"?>';
$xmlText .= '<soap:Envelope xmlns:soap="http://www.w3.org/2001/12/soap-envelope" soap:encodingStyle="http://www.w3.org/2001/12/soap-encoding">';
$xmlText .= '<soap:Body xmlns:m="http://www.example.org/stock">';
$xmlText .= '<m:GetStockPrice><m:StockName>IBM</m:StockName></m:GetStockPrice>';
$xmlText .= '</soap:Body></soap:Envelope>';
$this->assertEqual(str_replace(array("\r", "\n"), '', $xmlRequest->asXML()), $xmlText);
}
/**
* testNamespace
*
* @retun void
*/
public function testNamespace() {
$xmlResponse = Xml::build('<root xmlns:ns="http://cakephp.org"><ns:tag id="1"><child>good</child><otherchild>bad</otherchild></ns:tag><tag>Tag without ns</tag></root>');
$expected = array(
'root' => array(
'ns:tag' => array(
'@id' => '1',
'child' => 'good',
'otherchild' => 'bad'
),
'tag' => 'Tag without ns'
)
);
$this->assertEqual(Xml::toArray($xmlResponse), $expected);
$xmlResponse = Xml::build('<root xmlns:ns="http://cakephp.org"><ns:tag id="1" /><tag><id>1</id></tag></root>');
$expected = array(
'root' => array(
'ns:tag' => array(
'@id' => '1'
),
'tag' => array(
'id' => '1'
)
)
);
$this->assertEqual(Xml::toArray($xmlResponse), $expected);
$xmlResponse = Xml::build('<root xmlns:ns="http://cakephp.org"><ns:attr>1</ns:attr></root>');
$expected = array(
'root' => array(
'ns:attr' => '1'
)
);
$this->assertEqual(Xml::toArray($xmlResponse), $expected);
$xmlResponse = Xml::build('<root><ns:attr xmlns:ns="http://cakephp.org">1</ns:attr></root>');
$this->assertEqual(Xml::toArray($xmlResponse), $expected);
$xml = array(
'root' => array(
'ns:attr' => array(
'xmlns:ns' => 'http://cakephp.org',
'@' => 1
)
)
);
$expected = '<' . '?xml version="1.0" encoding="UTF-8"?><root><ns:attr xmlns:ns="http://cakephp.org">1</ns:attr></root>';
$xmlResponse = Xml::fromArray($xml);
$this->assertEqual(str_replace(array("\r", "\n"), '', $xmlResponse->asXML()), $expected);
$xml = array(
'root' => array(
'tag' => array(
'xmlns:pref' => 'http://cakephp.org',
'pref:item' => array(
'item 1',
'item 2'
)
)
)
);
$expected = '<' . '?xml version="1.0" encoding="UTF-8"?><root><tag xmlns:pref="http://cakephp.org"><pref:item>item 1</pref:item><pref:item>item 2</pref:item></tag></root>';
$xmlResponse = Xml::fromArray($xml);
$this->assertEqual(str_replace(array("\r", "\n"), '', $xmlResponse->asXML()), $expected);
$xml = array(
'root' => array(
'tag' => array(
'xmlns:' => 'http://cakephp.org'
)
)
);
$expected = '<' . '?xml version="1.0" encoding="UTF-8"?><root><tag xmlns="http://cakephp.org"/></root>';
$xmlResponse = Xml::fromArray($xml);
$this->assertEqual(str_replace(array("\r", "\n"), '', $xmlResponse->asXML()), $expected);
$xml = array(
'root' => array(
'xmlns:' => 'http://cakephp.org'
)
);
$expected = '<' . '?xml version="1.0" encoding="UTF-8"?><root xmlns="http://cakephp.org"/>';
$xmlResponse = Xml::fromArray($xml);
$this->assertEqual(str_replace(array("\r", "\n"), '', $xmlResponse->asXML()), $expected);
$xml = array(
'root' => array(
'xmlns:ns' => 'http://cakephp.org'
)
);
$expected = '<' . '?xml version="1.0" encoding="UTF-8"?><root xmlns:ns="http://cakephp.org"/>';
$xmlResponse = Xml::fromArray($xml);
$this->assertEqual(str_replace(array("\r", "\n"), '', $xmlResponse->asXML()), $expected);
}
/**
* test that CDATA blocks don't get screwed up by SimpleXml
*
* @return void
*/
public function testCdata() {
$xml = '<' . '?xml version="1.0" encoding="UTF-8"?>' .
'<people><name><![CDATA[ Mark ]]></name></people>';
$result = Xml::build($xml);
$this->assertEquals(' Mark ', (string)$result->name);
}
/**
* data provider for toArray() failures
*
* @return array
*/
public static function invalidToArrayDataProvider() {
return array(
array(new DateTime()),
array(array())
);
}
/**
* testToArrayFail method
*
* @dataProvider invalidToArrayDataProvider
* @expectedException Exception
*/
public function testToArrayFail($value) {
Xml::toArray($value);
}
/**
* testWithModel method
*
* @return void
*/
public function testWithModel() {
$this->loadFixtures('User', 'Article');
$user = new XmlUser();
$data = $user->read(null, 1);
$obj = Xml::build(compact('data'));
$expected = '<' . '?xml version="1.0" encoding="UTF-8"?><data>';
$expected .= '<User><id>1</id><user>mariano</user><password>5f4dcc3b5aa765d61d8327deb882cf99</password>';
$expected .= '<created>2007-03-17 01:16:23</created><updated>2007-03-17 01:18:31</updated></User>';
$expected .= '<Article><id>1</id><user_id>1</user_id><title>First Article</title><body>First Article Body</body>';
$expected .= '<published>Y</published><created>2007-03-18 10:39:23</created><updated>2007-03-18 10:41:31</updated></Article>';
$expected .= '<Article><id>3</id><user_id>1</user_id><title>Third Article</title><body>Third Article Body</body>';
$expected .= '<published>Y</published><created>2007-03-18 10:43:23</created><updated>2007-03-18 10:45:31</updated></Article>';
$expected .= '</data>';
$this->assertEqual(str_replace(array("\r", "\n"), '', $obj->asXML()), $expected);
}
}
| 0001-bee | trunk/cakephp2/lib/Cake/Test/Case/Utility/XmlTest.php | PHP | gpl3 | 23,495 |
<?php
/**
* FileTest file
*
* PHP 5
*
* CakePHP(tm) Tests <http://book.cakephp.org/view/1196/Testing>
* Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice
*
* @copyright Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://book.cakephp.org/view/1196/Testing CakePHP(tm) Tests
* @package Cake.Test.Case.Utility
* @since CakePHP(tm) v 1.2.0.4206
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
App::uses('File', 'Utility');
App::uses('Folder', 'Utility');
/**
* FileTest class
*
* @package Cake.Test.Case.Utility
*/
class FileTest extends CakeTestCase {
/**
* File property
*
* @var mixed null
*/
public $File = null;
/**
* setup the test case
*
* @return void
*/
public function setUp() {
parent::setUp();
$file = __FILE__;
$this->File = new File($file);
}
/**
* tear down for test.
*
* @return void
*/
public function teardown() {
parent::teardown();
$this->File->close();
unset($this->File);
}
/**
* testBasic method
*
* @return void
*/
public function testBasic() {
$file = __FILE__;
$result = $this->File->pwd();
$expecting = $file;
$this->assertEquals($expecting, $result);
$result = $this->File->name;
$expecting = basename(__FILE__);
$this->assertEquals($expecting, $result);
$result = $this->File->info();
$expecting = array(
'dirname' => dirname(__FILE__), 'basename' => basename(__FILE__),
'extension' => 'php', 'filename' =>'FileTest'
);
$this->assertEquals($expecting, $result);
$result = $this->File->ext();
$expecting = 'php';
$this->assertEquals($expecting, $result);
$result = $this->File->name();
$expecting = 'FileTest';
$this->assertEquals($expecting, $result);
$result = $this->File->md5();
$expecting = md5_file($file);
$this->assertEquals($expecting, $result);
$result = $this->File->md5(true);
$expecting = md5_file($file);
$this->assertEquals($expecting, $result);
$result = $this->File->size();
$expecting = filesize($file);
$this->assertEquals($expecting, $result);
$result = $this->File->owner();
$expecting = fileowner($file);
$this->assertEquals($expecting, $result);
$result = $this->File->group();
$expecting = filegroup($file);
$this->assertEquals($expecting, $result);
$result = $this->File->Folder();
$this->assertIsA($result, 'Folder');
$this->skipIf(DIRECTORY_SEPARATOR === '\\', 'File permissions tests not supported on Windows.');
$result = $this->File->perms();
$expecting = decoct(0644 & ~umask());
$this->assertEquals($expecting, $result);
}
/**
* testRead method
*
* @return void
*/
public function testRead() {
$file = __FILE__;
$this->File = new File($file);
$result = $this->File->read();
$expecting = file_get_contents(__FILE__);
$this->assertEquals($expecting, $result);
$this->assertTrue(!is_resource($this->File->handle));
$this->File->lock = true;
$result = $this->File->read();
$expecting = file_get_contents(__FILE__);
$this->assertEqual($result, trim($expecting));
$this->File->lock = null;
$data = $expecting;
$expecting = substr($data, 0, 3);
$result = $this->File->read(3);
$this->assertEquals($expecting, $result);
$this->assertTrue(is_resource($this->File->handle));
$expecting = substr($data, 3, 3);
$result = $this->File->read(3);
$this->assertEquals($expecting, $result);
}
/**
* testOffset method
*
* @return void
*/
public function testOffset() {
$this->File->close();
$result = $this->File->offset();
$this->assertFalse($result);
$this->assertFalse(is_resource($this->File->handle));
$success = $this->File->offset(0);
$this->assertTrue($success);
$this->assertTrue(is_resource($this->File->handle));
$result = $this->File->offset();
$expecting = 0;
$this->assertIdentical($result, $expecting);
$data = file_get_contents(__FILE__);
$success = $this->File->offset(5);
$expecting = substr($data, 5, 3);
$result = $this->File->read(3);
$this->assertTrue($success);
$this->assertEquals($expecting, $result);
$result = $this->File->offset();
$expecting = 5+3;
$this->assertIdentical($result, $expecting);
}
/**
* testOpen method
*
* @return void
*/
public function testOpen() {
$this->File->handle = null;
$r = $this->File->open();
$this->assertTrue(is_resource($this->File->handle));
$this->assertTrue($r);
$handle = $this->File->handle;
$r = $this->File->open();
$this->assertTrue($r);
$this->assertTrue($handle === $this->File->handle);
$this->assertTrue(is_resource($this->File->handle));
$r = $this->File->open('r', true);
$this->assertTrue($r);
$this->assertFalse($handle === $this->File->handle);
$this->assertTrue(is_resource($this->File->handle));
}
/**
* testClose method
*
* @return void
*/
public function testClose() {
$this->File->handle = null;
$this->assertFalse(is_resource($this->File->handle));
$this->assertTrue($this->File->close());
$this->assertFalse(is_resource($this->File->handle));
$this->File->handle = fopen(__FILE__, 'r');
$this->assertTrue(is_resource($this->File->handle));
$this->assertTrue($this->File->close());
$this->assertFalse(is_resource($this->File->handle));
}
/**
* testCreate method
*
* @return void
*/
public function testCreate() {
$tmpFile = TMP.'tests'.DS.'cakephp.file.test.tmp';
$File = new File($tmpFile, true, 0777);
$this->assertTrue($File->exists());
}
/**
* testOpeningNonExistantFileCreatesIt method
*
* @return void
*/
public function testOpeningNonExistantFileCreatesIt() {
$someFile = new File(TMP . 'some_file.txt', false);
$this->assertTrue($someFile->open());
$this->assertEquals('', $someFile->read());
$someFile->close();
$someFile->delete();
}
/**
* testPrepare method
*
* @return void
*/
public function testPrepare() {
$string = "some\nvery\ncool\r\nteststring here\n\n\nfor\r\r\n\n\r\n\nhere";
if (DS == '\\') {
$expected = "some\r\nvery\r\ncool\r\nteststring here\r\n\r\n\r\n";
$expected .= "for\r\n\r\n\r\n\r\n\r\nhere";
} else {
$expected = "some\nvery\ncool\nteststring here\n\n\nfor\n\n\n\n\nhere";
}
$this->assertIdentical(File::prepare($string), $expected);
$expected = "some\r\nvery\r\ncool\r\nteststring here\r\n\r\n\r\n";
$expected .= "for\r\n\r\n\r\n\r\n\r\nhere";
$this->assertIdentical(File::prepare($string, true), $expected);
}
/**
* testReadable method
*
* @return void
*/
public function testReadable() {
$someFile = new File(TMP . 'some_file.txt', false);
$this->assertTrue($someFile->open());
$this->assertTrue($someFile->readable());
$someFile->close();
$someFile->delete();
}
/**
* testWritable method
*
* @return void
*/
public function testWritable() {
$someFile = new File(TMP . 'some_file.txt', false);
$this->assertTrue($someFile->open());
$this->assertTrue($someFile->writable());
$someFile->close();
$someFile->delete();
}
/**
* testExecutable method
*
* @return void
*/
public function testExecutable() {
$someFile = new File(TMP . 'some_file.txt', false);
$this->assertTrue($someFile->open());
$this->assertFalse($someFile->executable());
$someFile->close();
$someFile->delete();
}
/**
* testLastAccess method
*
* @return void
*/
public function testLastAccess() {
$someFile = new File(TMP . 'some_file.txt', false);
$this->assertFalse($someFile->lastAccess());
$this->assertTrue($someFile->open());
$this->assertEqual($someFile->lastAccess(), time());
$someFile->close();
$someFile->delete();
}
/**
* testLastChange method
*
* @return void
*/
public function testLastChange() {
$someFile = new File(TMP . 'some_file.txt', false);
$this->assertFalse($someFile->lastChange());
$this->assertTrue($someFile->open('r+'));
$this->assertEqual($someFile->lastChange(), time());
$someFile->write('something');
$this->assertEqual($someFile->lastChange(), time());
$someFile->close();
$someFile->delete();
}
/**
* testWrite method
*
* @return void
*/
public function testWrite() {
if (!$tmpFile = $this->_getTmpFile()) {
return false;
};
if (file_exists($tmpFile)) {
unlink($tmpFile);
}
$TmpFile = new File($tmpFile);
$this->assertFalse(file_exists($tmpFile));
$this->assertFalse(is_resource($TmpFile->handle));
$testData = array('CakePHP\'s', ' test suite', ' was here ...', '');
foreach ($testData as $data) {
$r = $TmpFile->write($data);
$this->assertTrue($r);
$this->assertTrue(file_exists($tmpFile));
$this->assertEqual($data, file_get_contents($tmpFile));
$this->assertTrue(is_resource($TmpFile->handle));
$TmpFile->close();
}
unlink($tmpFile);
}
/**
* testAppend method
*
* @return void
*/
public function testAppend() {
if (!$tmpFile = $this->_getTmpFile()) {
return false;
};
if (file_exists($tmpFile)) {
unlink($tmpFile);
}
$TmpFile = new File($tmpFile);
$this->assertFalse(file_exists($tmpFile));
$fragments = array('CakePHP\'s', ' test suite', ' was here ...', '');
$data = null;
foreach ($fragments as $fragment) {
$r = $TmpFile->append($fragment);
$this->assertTrue($r);
$this->assertTrue(file_exists($tmpFile));
$data = $data.$fragment;
$this->assertEqual($data, file_get_contents($tmpFile));
$TmpFile->close();
}
}
/**
* testDelete method
*
* @return void
*/
public function testDelete() {
if (!$tmpFile = $this->_getTmpFile()) {
return false;
}
if (!file_exists($tmpFile)) {
touch($tmpFile);
}
$TmpFile = new File($tmpFile);
$this->assertTrue(file_exists($tmpFile));
$result = $TmpFile->delete();
$this->assertTrue($result);
$this->assertFalse(file_exists($tmpFile));
$TmpFile = new File('/this/does/not/exist');
$result = $TmpFile->delete();
$this->assertFalse($result);
}
/**
* Windows has issues unlinking files if there are
* active filehandles open.
*
* @return void
*/
function testDeleteAfterRead() {
if (!$tmpFile = $this->_getTmpFile()) {
return false;
}
if (!file_exists($tmpFile)) {
touch($tmpFile);
}
$file =& new File($tmpFile);
$file->read();
$this->assertTrue($file->delete());
}
/**
* testCopy method
*
* @return void
*/
public function testCopy() {
$dest = TMP . 'tests' . DS . 'cakephp.file.test.tmp';
$file = __FILE__;
$this->File = new File($file);
$result = $this->File->copy($dest);
$this->assertTrue($result);
$result = $this->File->copy($dest, true);
$this->assertTrue($result);
$result = $this->File->copy($dest, false);
$this->assertFalse($result);
$this->File->close();
unlink($dest);
$TmpFile = new File('/this/does/not/exist');
$result = $TmpFile->copy($dest);
$this->assertFalse($result);
$TmpFile->close();
}
/**
* getTmpFile method
*
* @param bool $paintSkip
* @return void
*/
function _getTmpFile($paintSkip = true) {
$tmpFile = TMP . 'tests' . DS . 'cakephp.file.test.tmp';
if (is_writable(dirname($tmpFile)) && (!file_exists($tmpFile) || is_writable($tmpFile))) {
return $tmpFile;
};
if ($paintSkip) {
$trace = debug_backtrace();
$caller = $trace[0]['function'];
$shortPath = dirname($tmpFile);
$message = __d('cake_dev', '[FileTest] Skipping %s because "%s" not writeable!', $caller, $shortPath);
$this->markTestSkipped($message);
}
return false;
}
}
| 0001-bee | trunk/cakephp2/lib/Cake/Test/Case/Utility/FileTest.php | PHP | gpl3 | 11,520 |
<?php
/**
* DebuggerTest file
*
* PHP 5
*
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
* Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://cakephp.org CakePHP Project
* @package Cake.Test.Case.Utility
* @since CakePHP(tm) v 1.2.0.5432
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
App::uses('Debugger', 'Utility');
/**
* DebugggerTestCaseDebuggger class
*
* @package Cake.Test.Case.Utility
*/
class DebuggerTestCaseDebugger extends Debugger {
}
/**
* DebuggerTest class
*
* @package Cake.Test.Case.Utility
*/
class DebuggerTest extends CakeTestCase {
// !!!
// !!! Be careful with changing code below as it may
// !!! change line numbers which are used in the tests
// !!!
protected $_restoreError = false;
/**
* setUp method
*
* @return void
*/
public function setUp() {
parent::setup();
Configure::write('debug', 2);
Configure::write('log', false);
}
/**
* tearDown method
*
* @return void
*/
public function tearDown() {
parent::teardown();
Configure::write('log', true);
if ($this->_restoreError) {
restore_error_handler();
}
}
/**
* testDocRef method
*
* @return void
*/
public function testDocRef() {
ini_set('docref_root', '');
$this->assertEqual(ini_get('docref_root'), '');
$debugger = new Debugger();
$this->assertEqual(ini_get('docref_root'), 'http://php.net/');
}
/**
* test Excerpt writing
*
* @return void
*/
public function testExcerpt() {
$result = Debugger::excerpt(__FILE__, __LINE__, 2);
$this->assertTrue(is_array($result));
$this->assertEqual(count($result), 5);
$this->assertPattern('/function(.+)testExcerpt/', $result[1]);
$result = Debugger::excerpt(__FILE__, 2, 2);
$this->assertTrue(is_array($result));
$this->assertEqual(count($result), 4);
$pattern = '/<code><span style\="color\: \#\d+">.*?<\?php/';
$this->assertRegExp($pattern, $result[0]);
$return = Debugger::excerpt('[internal]', 2, 2);
$this->assertTrue(empty($return));
}
/**
* testOutput method
*
* @return void
*/
public function testOutput() {
set_error_handler('Debugger::showError');
$this->_restoreError = true;
$result = Debugger::output(false);
$this->assertEqual($result, '');
$out .= '';
$result = Debugger::output(true);
$this->assertEqual($result[0]['error'], 'Notice');
$this->assertPattern('/Undefined variable\:\s+out/', $result[0]['description']);
$this->assertPattern('/DebuggerTest::testOutput/i', $result[0]['trace']);
ob_start();
Debugger::output('txt');
$other .= '';
$result = ob_get_clean();
$this->assertPattern('/Undefined variable:\s+other/', $result);
$this->assertPattern('/Context:/', $result);
$this->assertPattern('/DebuggerTest::testOutput/i', $result);
ob_start();
Debugger::output('html');
$wrong .= '';
$result = ob_get_clean();
$this->assertPattern('/<pre class="cake-error">.+<\/pre>/', $result);
$this->assertPattern('/<b>Notice<\/b>/', $result);
$this->assertPattern('/variable:\s+wrong/', $result);
ob_start();
Debugger::output('js');
$buzz .= '';
$result = explode('</a>', ob_get_clean());
$this->assertTags($result[0], array(
'pre' => array('class' => 'cake-error'),
'a' => array(
'href' => "javascript:void(0);",
'onclick' => "preg:/document\.getElementById\('cakeErr[a-z0-9]+\-trace'\)\.style\.display = " .
"\(document\.getElementById\('cakeErr[a-z0-9]+\-trace'\)\.style\.display == 'none'" .
" \? '' \: 'none'\);/"
),
'b' => array(), 'Notice', '/b', ' (8)',
));
$this->assertPattern('/Undefined variable:\s+buzz/', $result[1]);
$this->assertPattern('/<a[^>]+>Code/', $result[1]);
$this->assertPattern('/<a[^>]+>Context/', $result[2]);
}
/**
* Tests that changes in output formats using Debugger::output() change the templates used.
*
* @return void
*/
public function testChangeOutputFormats() {
set_error_handler('Debugger::showError');
$this->_restoreError = true;
Debugger::output('js', array(
'traceLine' => '{:reference} - <a href="txmt://open?url=file://{:file}' .
'&line={:line}">{:path}</a>, line {:line}'
));
$result = Debugger::trace();
$this->assertPattern('/' . preg_quote('txmt://open?url=file://', '/') . '(\/|[A-Z]:\\\\)' . '/', $result);
Debugger::output('xml', array(
'error' => '<error><code>{:code}</code><file>{:file}</file><line>{:line}</line>' .
'{:description}</error>',
'context' => "<context>{:context}</context>",
'trace' => "<stack>{:trace}</stack>",
));
Debugger::output('xml');
ob_start();
$foo .= '';
$result = ob_get_clean();
$data = array(
'error' => array(),
'code' => array(), '8', '/code',
'file' => array(), 'preg:/[^<]+/', '/file',
'line' => array(), '' . (intval(__LINE__) - 7), '/line',
'preg:/Undefined variable:\s+foo/',
'/error'
);
$this->assertTags($result, $data, true);
}
/**
* Test that outputAs works.
*
* @return void
*/
public function testOutputAs() {
Debugger::outputAs('html');
$this->assertEquals('html', Debugger::outputAs());
}
/**
* Test that choosing a non-existant format causes an exception
*
* @expectedException CakeException
* @return void
*/
public function testOutputAsException() {
Debugger::outputAs('Invalid junk');
}
/**
* Tests that changes in output formats using Debugger::output() change the templates used.
*
* @return void
*/
public function testAddFormat() {
set_error_handler('Debugger::showError');
$this->_restoreError = true;
Debugger::addFormat('js', array(
'traceLine' => '{:reference} - <a href="txmt://open?url=file://{:file}' .
'&line={:line}">{:path}</a>, line {:line}'
));
Debugger::outputAs('js');
$result = Debugger::trace();
$this->assertPattern('/' . preg_quote('txmt://open?url=file://', '/') . '(\/|[A-Z]:\\\\)' . '/', $result);
Debugger::addFormat('xml', array(
'error' => '<error><code>{:code}</code><file>{:file}</file><line>{:line}</line>' .
'{:description}</error>',
));
Debugger::outputAs('xml');
ob_start();
$foo .= '';
$result = ob_get_clean();
$data = array(
'<error',
'<code', '8', '/code',
'<file', 'preg:/[^<]+/', '/file',
'<line', '' . (intval(__LINE__) - 7), '/line',
'preg:/Undefined variable:\s+foo/',
'/error'
);
$this->assertTags($result, $data, true);
}
/**
* Test adding a format that is handled by a callback.
*
* @return void
*/
public function testAddFormatCallback() {
set_error_handler('Debugger::showError');
$this->_restoreError = true;
Debugger::addFormat('callback', array('callback' => array($this, 'customFormat')));
Debugger::outputAs('callback');
ob_start();
$foo .= '';
$result = ob_get_clean();
$this->assertContains('Notice: I eated an error', $result);
$this->assertContains('DebuggerTest.php', $result);
}
/**
* Test method for testing addFormat with callbacks.
*/
public function customFormat($error, $strings) {
return $error['error'] . ': I eated an error ' . $error['path'];
}
/**
* testTrimPath method
*
* @return void
*/
public function testTrimPath() {
$this->assertEqual(Debugger::trimPath(APP), 'APP' . DS);
$this->assertEqual(Debugger::trimPath(CAKE_CORE_INCLUDE_PATH), 'CORE');
}
/**
* testExportVar method
*
* @return void
*/
public function testExportVar() {
App::uses('Controller', 'Controller');
$Controller = new Controller();
$Controller->helpers = array('Html', 'Form');
$View = new View($Controller);
$result = Debugger::exportVar($View);
$expected = 'View
View::$Helpers = HelperCollection object
View::$plugin = NULL
View::$name = ""
View::$passedArgs = array
View::$helpers = array
View::$viewPath = ""
View::$viewVars = array
View::$view = NULL
View::$layout = "default"
View::$layoutPath = NULL
View::$autoLayout = true
View::$ext = ".ctp"
View::$subDir = NULL
View::$theme = NULL
View::$cacheAction = false
View::$validationErrors = array
View::$hasRendered = false
View::$uuids = array
View::$output = false
View::$request = NULL
View::$elementCache = "default"';
$result = str_replace(array("\t", "\r\n", "\n"), "", $result);
$expected = str_replace(array("\t", "\r\n", "\n"), "", $expected);
$this->assertEqual($expected, $result);
}
/**
* testLog method
*
* @return void
*/
public function testLog() {
if (file_exists(LOGS . 'debug.log')) {
unlink(LOGS . 'debug.log');
}
Debugger::log('cool');
$result = file_get_contents(LOGS . 'debug.log');
$this->assertPattern('/DebuggerTest\:\:testLog/i', $result);
$this->assertPattern('/"cool"/', $result);
unlink(TMP . 'logs' . DS . 'debug.log');
Debugger::log(array('whatever', 'here'));
$result = file_get_contents(TMP . 'logs' . DS . 'debug.log');
$this->assertPattern('/DebuggerTest\:\:testLog/i', $result);
$this->assertPattern('/\[main\]/', $result);
$this->assertPattern('/array/', $result);
$this->assertPattern('/"whatever",/', $result);
$this->assertPattern('/"here"/', $result);
}
/**
* testDump method
*
* @return void
*/
public function testDump() {
$var = array('People' => array(
array(
'name' => 'joeseph',
'coat' => 'technicolor',
'hair_color' => 'brown'
),
array(
'name' => 'Shaft',
'coat' => 'black',
'hair' => 'black'
)
)
);
ob_start();
Debugger::dump($var);
$result = ob_get_clean();
$expected = "<pre>array(\n\t\"People\" => array()\n)</pre>";
$this->assertEqual($expected, $result);
}
/**
* test getInstance.
*
* @return void
*/
public function testGetInstance() {
$result = Debugger::getInstance();
$this->assertIsA($result, 'Debugger');
$result = Debugger::getInstance('DebuggerTestCaseDebugger');
$this->assertIsA($result, 'DebuggerTestCaseDebugger');
$result = Debugger::getInstance();
$this->assertIsA($result, 'DebuggerTestCaseDebugger');
$result = Debugger::getInstance('Debugger');
$this->assertIsA($result, 'Debugger');
}
/**
* testNoDbCredentials
*
* If a connection error occurs, the config variable is passed through exportVar
* *** our database login credentials such that they are never visible
*
* @return void
*/
function testNoDbCredentials() {
$config = array(
'driver' => 'mysql',
'persistent' => false,
'host' => 'void.cakephp.org',
'login' => 'cakephp-user',
'password' => 'cakephp-password',
'database' => 'cakephp-database',
'prefix' => ''
);
$output = Debugger::exportVar($config);
$expectedArray = array(
'driver' => 'mysql',
'persistent' => false,
'host' => '*****',
'login' => '*****',
'password' => '*****',
'database' => '*****',
'prefix' => ''
);
$expected = Debugger::exportVar($expectedArray);
$this->assertEqual($expected, $output);
}
}
| 0001-bee | trunk/cakephp2/lib/Cake/Test/Case/Utility/DebuggerTest.php | PHP | gpl3 | 11,156 |
<?php
/**
* StringTest file
*
* PHP 5
*
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
* Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://book.cakephp.org/view/1196/Testing CakePHP(tm) Tests
* @package Cake.Test.Case.Utility
* @since CakePHP(tm) v 1.2.0.5432
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
App::uses('String', 'Utility');
/**
* StringTest class
*
* @package Cake.Test.Case.Utility
*/
class StringTest extends CakeTestCase {
/**
* testUuidGeneration method
*
* @return void
*/
public function testUuidGeneration() {
$result = String::uuid();
$pattern = "/^[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$/";
$match = (bool) preg_match($pattern, $result);
$this->assertTrue($match);
}
/**
* testMultipleUuidGeneration method
*
* @return void
*/
public function testMultipleUuidGeneration() {
$check = array();
$count = mt_rand(10, 1000);
$pattern = "/^[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$/";
for($i = 0; $i < $count; $i++) {
$result = String::uuid();
$match = (bool) preg_match($pattern, $result);
$this->assertTrue($match);
$this->assertFalse(in_array($result, $check));
$check[] = $result;
}
}
/**
* testInsert method
*
* @return void
*/
public function testInsert() {
$string = 'some string';
$expected = 'some string';
$result = String::insert($string, array());
$this->assertEqual($expected, $result);
$string = '2 + 2 = :sum. Cake is :adjective.';
$expected = '2 + 2 = 4. Cake is yummy.';
$result = String::insert($string, array('sum' => '4', 'adjective' => 'yummy'));
$this->assertEqual($expected, $result);
$string = '2 + 2 = %sum. Cake is %adjective.';
$result = String::insert($string, array('sum' => '4', 'adjective' => 'yummy'), array('before' => '%'));
$this->assertEqual($expected, $result);
$string = '2 + 2 = 2sum2. Cake is 9adjective9.';
$result = String::insert($string, array('sum' => '4', 'adjective' => 'yummy'), array('format' => '/([\d])%s\\1/'));
$this->assertEqual($expected, $result);
$string = '2 + 2 = 12sum21. Cake is 23adjective45.';
$expected = '2 + 2 = 4. Cake is 23adjective45.';
$result = String::insert($string, array('sum' => '4', 'adjective' => 'yummy'), array('format' => '/([\d])([\d])%s\\2\\1/'));
$this->assertEqual($expected, $result);
$string = ':web :web_site';
$expected = 'www http';
$result = String::insert($string, array('web' => 'www', 'web_site' => 'http'));
$this->assertEqual($expected, $result);
$string = '2 + 2 = <sum. Cake is <adjective>.';
$expected = '2 + 2 = <sum. Cake is yummy.';
$result = String::insert($string, array('sum' => '4', 'adjective' => 'yummy'), array('before' => '<', 'after' => '>'));
$this->assertEqual($expected, $result);
$string = '2 + 2 = \:sum. Cake is :adjective.';
$expected = '2 + 2 = :sum. Cake is yummy.';
$result = String::insert($string, array('sum' => '4', 'adjective' => 'yummy'));
$this->assertEqual($expected, $result);
$string = '2 + 2 = !:sum. Cake is :adjective.';
$result = String::insert($string, array('sum' => '4', 'adjective' => 'yummy'), array('escape' => '!'));
$this->assertEqual($expected, $result);
$string = '2 + 2 = \%sum. Cake is %adjective.';
$expected = '2 + 2 = %sum. Cake is yummy.';
$result = String::insert($string, array('sum' => '4', 'adjective' => 'yummy'), array('before' => '%'));
$this->assertEqual($expected, $result);
$string = ':a :b \:a :a';
$expected = '1 2 :a 1';
$result = String::insert($string, array('a' => 1, 'b' => 2));
$this->assertEqual($expected, $result);
$string = ':a :b :c';
$expected = '2 3';
$result = String::insert($string, array('b' => 2, 'c' => 3), array('clean' => true));
$this->assertEqual($expected, $result);
$string = ':a :b :c';
$expected = '1 3';
$result = String::insert($string, array('a' => 1, 'c' => 3), array('clean' => true));
$this->assertEqual($expected, $result);
$string = ':a :b :c';
$expected = '2 3';
$result = String::insert($string, array('b' => 2, 'c' => 3), array('clean' => true));
$this->assertEqual($expected, $result);
$string = ':a, :b and :c';
$expected = '2 and 3';
$result = String::insert($string, array('b' => 2, 'c' => 3), array('clean' => true));
$this->assertEqual($expected, $result);
$string = '":a, :b and :c"';
$expected = '"1, 2"';
$result = String::insert($string, array('a' => 1, 'b' => 2), array('clean' => true));
$this->assertEqual($expected, $result);
$string = '"${a}, ${b} and ${c}"';
$expected = '"1, 2"';
$result = String::insert($string, array('a' => 1, 'b' => 2), array('before' => '${', 'after' => '}', 'clean' => true));
$this->assertEqual($expected, $result);
$string = '<img src=":src" alt=":alt" class="foo :extra bar"/>';
$expected = '<img src="foo" class="foo bar"/>';
$result = String::insert($string, array('src' => 'foo'), array('clean' => 'html'));
$this->assertEqual($expected, $result);
$string = '<img src=":src" class=":no :extra"/>';
$expected = '<img src="foo"/>';
$result = String::insert($string, array('src' => 'foo'), array('clean' => 'html'));
$this->assertEqual($expected, $result);
$string = '<img src=":src" class=":no :extra"/>';
$expected = '<img src="foo" class="bar"/>';
$result = String::insert($string, array('src' => 'foo', 'extra' => 'bar'), array('clean' => 'html'));
$this->assertEqual($expected, $result);
$result = String::insert("this is a ? string", "test");
$expected = "this is a test string";
$this->assertEqual($expected, $result);
$result = String::insert("this is a ? string with a ? ? ?", array('long', 'few?', 'params', 'you know'));
$expected = "this is a long string with a few? params you know";
$this->assertEqual($expected, $result);
$result = String::insert('update saved_urls set url = :url where id = :id', array('url' => 'http://www.testurl.com/param1:url/param2:id','id' => 1));
$expected = "update saved_urls set url = http://www.testurl.com/param1:url/param2:id where id = 1";
$this->assertEqual($expected, $result);
$result = String::insert('update saved_urls set url = :url where id = :id', array('id' => 1, 'url' => 'http://www.testurl.com/param1:url/param2:id'));
$expected = "update saved_urls set url = http://www.testurl.com/param1:url/param2:id where id = 1";
$this->assertEqual($expected, $result);
$result = String::insert(':me cake. :subject :verb fantastic.', array('me' => 'I :verb', 'subject' => 'cake', 'verb' => 'is'));
$expected = "I :verb cake. cake is fantastic.";
$this->assertEqual($expected, $result);
$result = String::insert(':I.am: :not.yet: passing.', array('I.am' => 'We are'), array('before' => ':', 'after' => ':', 'clean' => array('replacement' => ' of course', 'method' => 'text')));
$expected = "We are of course passing.";
$this->assertEqual($expected, $result);
$result = String::insert(
':I.am: :not.yet: passing.',
array('I.am' => 'We are'),
array('before' => ':', 'after' => ':', 'clean' => true)
);
$expected = "We are passing.";
$this->assertEqual($expected, $result);
$result = String::insert('?-pended result', array('Pre'));
$expected = "Pre-pended result";
$this->assertEqual($expected, $result);
$string = 'switching :timeout / :timeout_count';
$expected = 'switching 5 / 10';
$result = String::insert($string, array('timeout' => 5, 'timeout_count' => 10));
$this->assertEqual($expected, $result);
$string = 'switching :timeout / :timeout_count';
$expected = 'switching 5 / 10';
$result = String::insert($string, array('timeout_count' => 10, 'timeout' => 5));
$this->assertEqual($expected, $result);
$string = 'switching :timeout_count by :timeout';
$expected = 'switching 10 by 5';
$result = String::insert($string, array('timeout' => 5, 'timeout_count' => 10));
$this->assertEqual($expected, $result);
$string = 'switching :timeout_count by :timeout';
$expected = 'switching 10 by 5';
$result = String::insert($string, array('timeout_count' => 10, 'timeout' => 5));
$this->assertEqual($expected, $result);
}
/**
* test Clean Insert
*
* @return void
*/
public function testCleanInsert() {
$result = String::cleanInsert(':incomplete', array(
'clean' => true, 'before' => ':', 'after' => ''
));
$this->assertEqual($result, '');
$result = String::cleanInsert(':incomplete', array(
'clean' => array('method' => 'text', 'replacement' => 'complete'),
'before' => ':', 'after' => '')
);
$this->assertEqual($result, 'complete');
$result = String::cleanInsert(':in.complete', array(
'clean' => true, 'before' => ':', 'after' => ''
));
$this->assertEqual($result, '');
$result = String::cleanInsert(':in.complete and', array(
'clean' => true, 'before' => ':', 'after' => '')
);
$this->assertEqual($result, '');
$result = String::cleanInsert(':in.complete or stuff', array(
'clean' => true, 'before' => ':', 'after' => ''
));
$this->assertEqual($result, 'stuff');
$result = String::cleanInsert(
'<p class=":missing" id=":missing">Text here</p>',
array('clean' => 'html', 'before' => ':', 'after' => '')
);
$this->assertEqual($result, '<p>Text here</p>');
}
/**
* Tests that non-insertable variables (i.e. arrays) are skipped when used as values in
* String::insert().
*
* @return void
*/
public function testAutoIgnoreBadInsertData() {
$data = array('foo' => 'alpha', 'bar' => 'beta', 'fale' => array());
$result = String::insert('(:foo > :bar || :fale!)', $data, array('clean' => 'text'));
$this->assertEqual($result, '(alpha > beta || !)');
}
/**
* testTokenize method
*
* @return void
*/
public function testTokenize() {
$result = String::tokenize('A,(short,boring test)');
$expected = array('A', '(short,boring test)');
$this->assertEqual($expected, $result);
$result = String::tokenize('A,(short,more interesting( test)');
$expected = array('A', '(short,more interesting( test)');
$this->assertEqual($expected, $result);
$result = String::tokenize('A,(short,very interesting( test))');
$expected = array('A', '(short,very interesting( test))');
$this->assertEqual($expected, $result);
$result = String::tokenize('"single tag"', ' ', '"', '"');
$expected = array('"single tag"');
$this->assertEqual($expected, $result);
$result = String::tokenize('tagA "single tag" tagB', ' ', '"', '"');
$expected = array('tagA', '"single tag"', 'tagB');
$this->assertEqual($expected, $result);
}
public function testReplaceWithQuestionMarkInString() {
$string = ':a, :b and :c?';
$expected = '2 and 3?';
$result = String::insert($string, array('b' => 2, 'c' => 3), array('clean' => true));
$this->assertEqual($expected, $result);
}
/**
* test wrap method.
*
* @return void
*/
public function testWrap() {
$text = 'This is the song that never ends. This is the song that never ends. This is the song that never ends.';
$result = String::wrap($text, 33);
$expected = <<<TEXT
This is the song that never ends.
This is the song that never ends.
This is the song that never ends.
TEXT;
$this->assertEquals($expected, $result, 'Text not wrapped.');
$result = String::wrap($text, array('width' => 20, 'wordWrap' => false));
$expected = <<<TEXT
This is the song th
at never ends. This
is the song that n
ever ends. This is
the song that never
ends.
TEXT;
$this->assertEquals($expected, $result, 'Text not wrapped.');
}
/**
* test wrap() indenting
*
* @return void
*/
public function testWrapIndent() {
$text = 'This is the song that never ends. This is the song that never ends. This is the song that never ends.';
$result = String::wrap($text, array('width' => 33, 'indent' => "\t", 'indentAt' => 1));
$expected = <<<TEXT
This is the song that never ends.
This is the song that never ends.
This is the song that never ends.
TEXT;
}
}
| 0001-bee | trunk/cakephp2/lib/Cake/Test/Case/Utility/StringTest.php | PHP | gpl3 | 12,227 |
<?php
/**
* FolderTest file
*
* PHP 5
*
* CakePHP(tm) Tests <http://book.cakephp.org/view/1196/Testing>
* Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice
*
* @copyright Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://book.cakephp.org/view/1196/Testing CakePHP(tm) Tests
* @package Cake.Test.Case.Utility
* @since CakePHP(tm) v 1.2.0.4206
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
App::uses('Folder', 'Utility');
App::uses('File', 'Utility');
/**
* FolderTest class
*
* @package Cake.Test.Case.Utility
*/
class FolderTest extends CakeTestCase {
protected static $_tmp = array();
/**
* Save the directory names in TMP
*
* @return void
*/
public static function setUpBeforeClass() {
foreach (scandir(TMP) as $file) {
if (is_dir(TMP . $file) && !in_array($file, array('.', '..'))) {
self::$_tmp[] = $file;
}
}
}
/**
* setUp clearstatcache() to flush file descriptors.
*
* @return void
*/
public function setUp() {
parent::setUp();
clearstatcache();
}
/**
* Restore the TMP directory to its original state.
*
* @return void
*/
public function tearDown() {
$exclude = array_merge(self::$_tmp, array('.', '..'));
foreach (scandir(TMP) as $file) {
if (is_dir(TMP . $file) && !in_array($file, $exclude)) {
unlink(TMP . $file);
}
}
}
/**
* testBasic method
*
* @return void
*/
public function testBasic() {
$path = dirname(__FILE__);
$Folder = new Folder($path);
$result = $Folder->pwd();
$this->assertEqual($result, $path);
$result = Folder::addPathElement($path, 'test');
$expected = $path . DS . 'test';
$this->assertEqual($expected, $result);
$result = $Folder->cd(ROOT);
$expected = ROOT;
$this->assertEqual($expected, $result);
$result = $Folder->cd(ROOT . DS . 'non-existent');
$this->assertFalse($result);
}
/**
* testInPath method
*
* @return void
*/
public function testInPath() {
$path = dirname(dirname(__FILE__));
$inside = dirname($path) . DS;
$Folder = new Folder($path);
$result = $Folder->pwd();
$this->assertEqual($result, $path);
$result = Folder::isSlashTerm($inside);
$this->assertTrue($result);
$result = $Folder->realpath('Test/');
$this->assertEqual($result, $path . DS .'Test' . DS);
$result = $Folder->inPath('Test' . DS);
$this->assertTrue($result);
$result = $Folder->inPath(DS . 'non-existing' . $inside);
$this->assertFalse($result);
}
/**
* test creation of single and mulitple paths.
*
* @return void
*/
public function testCreation() {
$folder = new Folder(TMP . 'tests');
$result = $folder->create(TMP . 'tests' . DS . 'first' . DS . 'second' . DS . 'third');
$this->assertTrue($result);
rmdir(TMP . 'tests' . DS . 'first' . DS . 'second' . DS . 'third');
rmdir(TMP . 'tests' . DS . 'first' . DS . 'second');
rmdir(TMP . 'tests' . DS . 'first');
$folder = new Folder(TMP . 'tests');
$result = $folder->create(TMP . 'tests' . DS . 'first');
$this->assertTrue($result);
rmdir(TMP . 'tests' . DS . 'first');
}
/**
* test that creation of folders with trailing ds works
*
* @return void
*/
public function testCreateWithTrailingDs() {
$folder = new Folder(TMP);
$path = TMP . 'tests' . DS . 'trailing' . DS . 'dir' . DS;
$result = $folder->create($path);
$this->assertTrue($result);
$this->assertTrue(is_dir($path), 'Folder was not made');
$folder = new Folder(TMP . 'tests' . DS . 'trailing');
$this->assertTrue($folder->delete());
}
/**
* test recurisve directory create failure.
*
* @return void
*/
public function testRecursiveCreateFailure() {
$this->skipIf(DIRECTORY_SEPARATOR === '\\', 'Cant perform operations using permissions on windows.');
$path = TMP . 'tests' . DS . 'one';
mkdir($path);
chmod($path, '0444');
try {
$folder = new Folder($path);
$result = $folder->create($path . DS . 'two' . DS . 'three');
$this->assertFalse($result);
} catch (PHPUnit_Framework_Error $e) {
$this->assertTrue(true);
}
chmod($path, '0777');
rmdir($path);
}
/**
* testOperations method
*
* @return void
*/
public function testOperations() {
$path = CAKE . 'Console' . DS . 'Templates' . DS . 'skel';
$Folder = new Folder($path);
$result = is_dir($Folder->pwd());
$this->assertTrue($result);
$new = TMP . 'test_folder_new';
$result = $Folder->create($new);
$this->assertTrue($result);
$copy = TMP . 'test_folder_copy';
$result = $Folder->copy($copy);
$this->assertTrue($result);
$copy = TMP . 'test_folder_copy';
$result = $Folder->copy($copy);
$this->assertTrue($result);
$copy = TMP . 'test_folder_copy';
$result = $Folder->chmod($copy, 0755, false);
$this->assertTrue($result);
$result = $Folder->cd($copy);
$this->assertTrue((bool)$result);
$mv = TMP . 'test_folder_mv';
$result = $Folder->move($mv);
$this->assertTrue($result);
$mv = TMP . 'test_folder_mv_2';
$result = $Folder->move($mv);
$this->assertTrue($result);
$result = $Folder->delete($new);
$this->assertTrue($result);
$result = $Folder->delete($mv);
$this->assertTrue($result);
$result = $Folder->delete($mv);
$this->assertTrue($result);
$new = APP . 'index.php';
$result = $Folder->create($new);
$this->assertFalse($result);
$expected = $new . ' is a file';
$result = $Folder->errors();
$this->assertEqual($result[0], $expected);
$new = TMP . 'test_folder_new';
$result = $Folder->create($new);
$this->assertTrue($result);
$result = $Folder->cd($new);
$this->assertTrue((bool)$result);
$result = $Folder->delete();
$this->assertTrue($result);
$Folder = new Folder('non-existent');
$result = $Folder->pwd();
$this->assertNull($result);
}
/**
* testChmod method
*
* @return void
*/
public function testChmod() {
$this->skipIf(DIRECTORY_SEPARATOR === '\\', 'Folder permissions tests not supported on Windows.');
$path = CAKE . 'Console' . DS . 'Templates' . DS . 'skel';
$Folder = new Folder($path);
$subdir = 'test_folder_new';
$new = TMP . $subdir;
$this->assertTrue($Folder->create($new));
$this->assertTrue($Folder->create($new . DS . 'test1'));
$this->assertTrue($Folder->create($new . DS . 'test2'));
$filePath = $new . DS . 'test1.php';
$File = new File($filePath);
$this->assertTrue($File->create());
$copy = TMP . 'test_folder_copy';
$this->assertTrue($Folder->chmod($new, 0777, true));
$this->assertEqual($File->perms(), '0777');
$Folder->delete($new);
}
/**
* testRealPathForWebroot method
*
* @return void
*/
public function testRealPathForWebroot() {
$Folder = new Folder('files/');
$this->assertEqual(realpath('files/'), $Folder->path);
}
/**
* testZeroAsDirectory method
*
* @return void
*/
public function testZeroAsDirectory() {
$Folder = new Folder(TMP);
$new = TMP . '0';
$this->assertTrue($Folder->create($new));
$result = $Folder->read(true, true);
$expected = array('0', 'cache', 'logs', 'sessions', 'tests');
$this->assertEqual($expected, $result[0]);
$result = $Folder->read(true, array('logs'));
$expected = array('0', 'cache', 'sessions', 'tests');
$this->assertEqual($expected, $result[0]);
$result = $Folder->delete($new);
$this->assertTrue($result);
}
/**
* test Adding path elements to a path
*
* @return void
*/
public function testAddPathElement() {
$result = Folder::addPathElement(DS . 'some' . DS . 'dir', 'another_path');
$this->assertEqual($result, DS . 'some' . DS . 'dir' . DS . 'another_path');
$result = Folder::addPathElement(DS . 'some' . DS . 'dir' . DS, 'another_path');
$this->assertEqual($result, DS . 'some' . DS . 'dir' . DS . 'another_path');
}
/**
* testFolderRead method
*
* @return void
*/
public function testFolderRead() {
$Folder = new Folder(TMP);
$expected = array('cache', 'logs', 'sessions', 'tests');
$result = $Folder->read(true, true);
$this->assertEqual($result[0], $expected);
$Folder->path = TMP . 'non-existent';
$expected = array(array(), array());
$result = $Folder->read(true, true);
$this->assertEqual($expected, $result);
}
/**
* testFolderTree method
*
* @return void
*/
public function testFolderTree() {
$Folder = new Folder();
$expected = array(
array(
CAKE . 'Config',
CAKE . 'Config' . DS . 'unicode',
CAKE . 'Config' . DS . 'unicode' . DS . 'casefolding'
),
array(
CAKE . 'Config' . DS . 'config.php',
CAKE . 'Config' . DS . 'unicode' . DS . 'casefolding' . DS . '0080_00ff.php',
CAKE . 'Config' . DS . 'unicode' . DS . 'casefolding' . DS . '0100_017f.php',
CAKE . 'Config' . DS . 'unicode' . DS . 'casefolding' . DS . '0180_024F.php',
CAKE . 'Config' . DS . 'unicode' . DS . 'casefolding' . DS . '0250_02af.php',
CAKE . 'Config' . DS . 'unicode' . DS . 'casefolding' . DS . '0370_03ff.php',
CAKE . 'Config' . DS . 'unicode' . DS . 'casefolding' . DS . '0400_04ff.php',
CAKE . 'Config' . DS . 'unicode' . DS . 'casefolding' . DS . '0500_052f.php',
CAKE . 'Config' . DS . 'unicode' . DS . 'casefolding' . DS . '0530_058f.php',
CAKE . 'Config' . DS . 'unicode' . DS . 'casefolding' . DS . '1e00_1eff.php',
CAKE . 'Config' . DS . 'unicode' . DS . 'casefolding' . DS . '1f00_1fff.php',
CAKE . 'Config' . DS . 'unicode' . DS . 'casefolding' . DS . '2100_214f.php',
CAKE . 'Config' . DS . 'unicode' . DS . 'casefolding' . DS . '2150_218f.php',
CAKE . 'Config' . DS . 'unicode' . DS . 'casefolding' . DS . '2460_24ff.php',
CAKE . 'Config' . DS . 'unicode' . DS . 'casefolding' . DS . '2c00_2c5f.php',
CAKE . 'Config' . DS . 'unicode' . DS . 'casefolding' . DS . '2c60_2c7f.php',
CAKE . 'Config' . DS . 'unicode' . DS . 'casefolding' . DS . '2c80_2cff.php',
CAKE . 'Config' . DS . 'unicode' . DS . 'casefolding' . DS . 'ff00_ffef.php'
)
);
$result = $Folder->tree(CAKE . 'Config', false);
$this->assertSame(array_diff($expected[0], $result[0]), array());
$this->assertSame(array_diff($result[0], $expected[0]), array());
$result = $Folder->tree(CAKE . 'Config', false, 'dir');
$this->assertSame(array_diff($expected[0], $result), array());
$this->assertSame(array_diff($expected[0], $result), array());
$result = $Folder->tree(CAKE . 'Config', false, 'files');
$this->assertSame(array_diff($expected[1], $result), array());
$this->assertSame(array_diff($expected[1], $result), array());
}
/**
* testWindowsPath method
*
* @return void
*/
public function testWindowsPath() {
$this->assertFalse(Folder::isWindowsPath('0:\\cake\\is\\awesome'));
$this->assertTrue(Folder::isWindowsPath('C:\\cake\\is\\awesome'));
$this->assertTrue(Folder::isWindowsPath('d:\\cake\\is\\awesome'));
$this->assertTrue(Folder::isWindowsPath('\\\\vmware-host\\Shared Folders\\file'));
}
/**
* testIsAbsolute method
*
* @return void
*/
public function testIsAbsolute() {
$this->assertFalse(Folder::isAbsolute('path/to/file'));
$this->assertFalse(Folder::isAbsolute('cake/'));
$this->assertFalse(Folder::isAbsolute('path\\to\\file'));
$this->assertFalse(Folder::isAbsolute('0:\\path\\to\\file'));
$this->assertFalse(Folder::isAbsolute('\\path/to/file'));
$this->assertFalse(Folder::isAbsolute('\\path\\to\\file'));
$this->assertTrue(Folder::isAbsolute('/usr/local'));
$this->assertTrue(Folder::isAbsolute('//path/to/file'));
$this->assertTrue(Folder::isAbsolute('C:\\cake'));
$this->assertTrue(Folder::isAbsolute('C:\\path\\to\\file'));
$this->assertTrue(Folder::isAbsolute('d:\\path\\to\\file'));
$this->assertTrue(Folder::isAbsolute('\\\\vmware-host\\Shared Folders\\file'));
}
/**
* testIsSlashTerm method
*
* @return void
*/
public function testIsSlashTerm() {
$this->assertFalse(Folder::isSlashTerm('cake'));
$this->assertTrue(Folder::isSlashTerm('C:\\cake\\'));
$this->assertTrue(Folder::isSlashTerm('/usr/local/'));
}
/**
* testStatic method
*
* @return void
*/
public function testSlashTerm() {
$result = Folder::slashTerm('/path/to/file');
$this->assertEqual($result, '/path/to/file/');
}
/**
* testNormalizePath method
*
* @return void
*/
public function testNormalizePath() {
$path = '/path/to/file';
$result = Folder::normalizePath($path);
$this->assertEqual($result, '/');
$path = '\\path\\\to\\\file';
$result = Folder::normalizePath($path);
$this->assertEqual($result, '/');
$path = 'C:\\path\\to\\file';
$result = Folder::normalizePath($path);
$this->assertEqual($result, '\\');
}
/**
* correctSlashFor method
*
* @return void
*/
public function testCorrectSlashFor() {
$path = '/path/to/file';
$result = Folder::correctSlashFor($path);
$this->assertEqual($result, '/');
$path = '\\path\\to\\file';
$result = Folder::correctSlashFor($path);
$this->assertEqual($result, '/');
$path = 'C:\\path\to\\file';
$result = Folder::correctSlashFor($path);
$this->assertEqual($result, '\\');
}
/**
* testInCakePath method
*
* @return void
*/
public function testInCakePath() {
$Folder = new Folder();
$Folder->cd(ROOT);
$path = 'C:\\path\\to\\file';
$result = $Folder->inCakePath($path);
$this->assertFalse($result);
$path = ROOT;
$Folder->cd(ROOT);
$result = $Folder->inCakePath($path);
$this->assertFalse($result);
$path = DS . 'lib' . DS . 'Cake' . DS . 'Config';
$Folder->cd(ROOT . DS . 'lib' . DS . 'Cake' . DS . 'Config');
$result = $Folder->inCakePath($path);
$this->assertTrue($result);
}
/**
* testFind method
*
* @return void
*/
public function testFind() {
$Folder = new Folder();
$Folder->cd(CAKE . 'Config');
$result = $Folder->find();
$expected = array('config.php');
$this->assertSame(array_diff($expected, $result), array());
$this->assertSame(array_diff($expected, $result), array());
$result = $Folder->find('.*', true);
$expected = array('config.php', 'routes.php');
$this->assertSame($expected, $result);
$result = $Folder->find('.*\.php');
$expected = array('config.php');
$this->assertSame(array_diff($expected, $result), array());
$this->assertSame(array_diff($expected, $result), array());
$result = $Folder->find('.*\.php', true);
$expected = array('config.php', 'routes.php');
$this->assertSame($expected, $result);
$result = $Folder->find('.*ig\.php');
$expected = array('config.php');
$this->assertSame($expected, $result);
$result = $Folder->find('config\.php');
$expected = array('config.php');
$this->assertSame($expected, $result);
$Folder->cd(TMP);
$file = new File($Folder->pwd() . DS . 'paths.php', true);
$Folder->create($Folder->pwd() . DS . 'testme');
$Folder->cd('testme');
$result = $Folder->find('paths\.php');
$expected = array();
$this->assertSame($expected, $result);
$Folder->cd($Folder->pwd() . '/..');
$result = $Folder->find('paths\.php');
$expected = array('paths.php');
$this->assertSame($expected, $result);
$Folder->cd(TMP);
$Folder->delete($Folder->pwd() . DS . 'testme');
$file->delete();
}
/**
* testFindRecursive method
*
* @return void
*/
public function testFindRecursive() {
$Folder = new Folder();
$Folder->cd(CAKE);
$result = $Folder->findRecursive('(config|paths)\.php');
$expected = array(
CAKE . 'Config' . DS . 'config.php'
);
$this->assertSame(array_diff($expected, $result), array());
$this->assertSame(array_diff($expected, $result), array());
$result = $Folder->findRecursive('(config|paths)\.php', true);
$expected = array(
CAKE . 'Config' . DS . 'config.php'
);
$this->assertSame($expected, $result);
$Folder->cd(TMP);
$Folder->create($Folder->pwd() . DS . 'testme');
$Folder->cd('testme');
$File = new File($Folder->pwd() . DS . 'paths.php');
$File->create();
$Folder->cd(TMP . 'sessions');
$result = $Folder->findRecursive('paths\.php');
$expected = array();
$this->assertSame($expected, $result);
$Folder->cd(TMP . 'testme');
$File = new File($Folder->pwd() . DS . 'my.php');
$File->create();
$Folder->cd($Folder->pwd() . '/../..');
$result = $Folder->findRecursive('(paths|my)\.php');
$expected = array(
TMP . 'testme' . DS . 'my.php',
TMP . 'testme' . DS . 'paths.php'
);
$this->assertSame(array_diff($expected, $result), array());
$this->assertSame(array_diff($expected, $result), array());
$result = $Folder->findRecursive('(paths|my)\.php', true);
$expected = array(
TMP . 'testme' . DS . 'my.php',
TMP . 'testme' . DS . 'paths.php'
);
$this->assertSame($expected, $result);
$Folder->cd(CAKE . 'Config');
$Folder->cd(TMP);
$Folder->delete($Folder->pwd() . DS . 'testme');
$File->delete();
}
/**
* testConstructWithNonExistantPath method
*
* @return void
*/
public function testConstructWithNonExistantPath() {
$Folder = new Folder(TMP . 'config_non_existant', true);
$this->assertTrue(is_dir(TMP . 'config_non_existant'));
$Folder->cd(TMP);
$Folder->delete($Folder->pwd() . 'config_non_existant');
}
/**
* testDirSize method
*
* @return void
*/
public function testDirSize() {
$Folder = new Folder(TMP . 'config_non_existant', true);
$this->assertEqual($Folder->dirSize(), 0);
$File = new File($Folder->pwd() . DS . 'my.php', true, 0777);
$File->create();
$File->write('something here');
$File->close();
$this->assertEqual($Folder->dirSize(), 14);
$Folder->cd(TMP);
$Folder->delete($Folder->pwd() . 'config_non_existant');
}
/**
* testDelete method
*
* @return void
*/
public function testDelete() {
$path = TMP . 'folder_delete_test';
$Folder = new Folder($path, true);
touch(TMP . 'folder_delete_test' . DS . 'file1');
touch(TMP . 'folder_delete_test' . DS . 'file2');
$return = $Folder->delete();
$this->assertTrue($return);
$messages = $Folder->messages();
$errors = $Folder->errors();
$this->assertEquals($errors, array());
$expected = array(
$path . ' created',
$path . DS . 'file1 removed',
$path . DS . 'file2 removed',
$path . ' removed'
);
$this->assertEqual($expected, $messages);
}
/**
* testCopy method
*
* Verify that directories and files are copied recursively
* even if the destination directory already exists.
* Subdirectories existing in both destination and source directory
* are skipped and not merged or overwritten.
*
* @return void
*/
public function testCopy() {
$path = TMP . 'folder_test';
$folder1 = $path . DS . 'folder1';
$folder2 = $folder1 . DS . 'folder2';
$folder3 = $path . DS . 'folder3';
$file1 = $folder1 . DS . 'file1.php';
$file2 = $folder2 . DS . 'file2.php';
new Folder($path, true);
new Folder($folder1, true);
new Folder($folder2, true);
new Folder($folder3, true);
touch($file1);
touch($file2);
$Folder = new Folder($folder1);
$result = $Folder->copy($folder3);
$this->assertTrue($result);
$this->assertTrue(file_exists($folder3 . DS . 'file1.php'));
$this->assertTrue(file_exists($folder3 . DS . 'folder2' . DS . 'file2.php'));
$Folder = new Folder($folder3);
$Folder->delete();
$Folder = new Folder($folder1);
$result = $Folder->copy($folder3);
$this->assertTrue($result);
$this->assertTrue(file_exists($folder3 . DS . 'file1.php'));
$this->assertTrue(file_exists($folder3 . DS . 'folder2' . DS . 'file2.php'));
$Folder = new Folder($folder3);
$Folder->delete();
new Folder($folder3, true);
new Folder($folder3 . DS . 'folder2', true);
file_put_contents($folder3 . DS . 'folder2' . DS . 'file2.php', 'untouched');
$Folder = new Folder($folder1);
$result = $Folder->copy($folder3);
$this->assertTrue($result);
$this->assertTrue(file_exists($folder3 . DS . 'file1.php'));
$this->assertEqual(file_get_contents($folder3 . DS . 'folder2' . DS . 'file2.php'), 'untouched');
$Folder = new Folder($path);
$Folder->delete();
}
/**
* testMove method
*
* Verify that directories and files are moved recursively
* even if the destination directory already exists.
* Subdirectories existing in both destination and source directory
* are skipped and not merged or overwritten.
*
* @return void
*/
public function testMove() {
$path = TMP . 'folder_test';
$folder1 = $path . DS . 'folder1';
$folder2 = $folder1 . DS . 'folder2';
$folder3 = $path . DS . 'folder3';
$file1 = $folder1 . DS . 'file1.php';
$file2 = $folder2 . DS . 'file2.php';
new Folder($path, true);
new Folder($folder1, true);
new Folder($folder2, true);
new Folder($folder3, true);
touch($file1);
touch($file2);
$Folder = new Folder($folder1);
$result = $Folder->move($folder3);
$this->assertTrue($result);
$this->assertTrue(file_exists($folder3 . DS . 'file1.php'));
$this->assertTrue(is_dir($folder3 . DS . 'folder2'));
$this->assertTrue(file_exists($folder3 . DS . 'folder2' . DS . 'file2.php'));
$this->assertFalse(file_exists($file1));
$this->assertFalse(file_exists($folder2));
$this->assertFalse(file_exists($file2));
$Folder = new Folder($folder3);
$Folder->delete();
new Folder($folder1, true);
new Folder($folder2, true);
touch($file1);
touch($file2);
$Folder = new Folder($folder1);
$result = $Folder->move($folder3);
$this->assertTrue($result);
$this->assertTrue(file_exists($folder3 . DS . 'file1.php'));
$this->assertTrue(is_dir($folder3 . DS . 'folder2'));
$this->assertTrue(file_exists($folder3 . DS . 'folder2' . DS . 'file2.php'));
$this->assertFalse(file_exists($file1));
$this->assertFalse(file_exists($folder2));
$this->assertFalse(file_exists($file2));
$Folder = new Folder($folder3);
$Folder->delete();
new Folder($folder1, true);
new Folder($folder2, true);
new Folder($folder3, true);
new Folder($folder3 . DS . 'folder2', true);
touch($file1);
touch($file2);
file_put_contents($folder3 . DS . 'folder2' . DS . 'file2.php', 'untouched');
$Folder = new Folder($folder1);
$result = $Folder->move($folder3);
$this->assertTrue($result);
$this->assertTrue(file_exists($folder3 . DS . 'file1.php'));
$this->assertEqual(file_get_contents($folder3 . DS . 'folder2' . DS . 'file2.php'), 'untouched');
$this->assertFalse(file_exists($file1));
$this->assertFalse(file_exists($folder2));
$this->assertFalse(file_exists($file2));
$Folder = new Folder($path);
$Folder->delete();
}
}
| 0001-bee | trunk/cakephp2/lib/Cake/Test/Case/Utility/FolderTest.php | PHP | gpl3 | 22,454 |
<?php
/**
* SetTest file
*
* PHP 5
*
* CakePHP(tm) Tests <http://book.cakephp.org/view/1196/Testing>
* Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice
*
* @copyright Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://book.cakephp.org/view/1196/Testing CakePHP(tm) Tests
* @package Cake.Test.Case.Utility
* @since CakePHP(tm) v 1.2.0.4206
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
App::uses('Set', 'Utility');
App::uses('Model', 'Model');
/**
* SetTest class
*
* @package Cake.Test.Case.Utility
*/
class SetTest extends CakeTestCase {
/**
* testNumericKeyExtraction method
*
* @return void
*/
public function testNumericKeyExtraction() {
$data = array('plugin' => null, 'controller' => '', 'action' => '', 1, 'whatever');
$this->assertEquals(Set::extract($data, '{n}'), array(1, 'whatever'));
$this->assertEquals(Set::diff($data, Set::extract($data, '{n}')), array('plugin' => null, 'controller' => '', 'action' => ''));
}
/**
* testEnum method
*
* @return void
*/
public function testEnum() {
$result = Set::enum(1, 'one, two');
$this->assertEquals($result, 'two');
$result = Set::enum(2, 'one, two');
$this->assertNull($result);
$set = array('one', 'two');
$result = Set::enum(0, $set);
$this->assertEquals($result, 'one');
$result = Set::enum(1, $set);
$this->assertEquals($result, 'two');
$result = Set::enum(1, array('one', 'two'));
$this->assertEquals($result, 'two');
$result = Set::enum(2, array('one', 'two'));
$this->assertNull($result);
$result = Set::enum('first', array('first' => 'one', 'second' => 'two'));
$this->assertEquals($result, 'one');
$result = Set::enum('third', array('first' => 'one', 'second' => 'two'));
$this->assertNull($result);
$result = Set::enum('no', array('no' => 0, 'yes' => 1));
$this->assertEquals($result, 0);
$result = Set::enum('not sure', array('no' => 0, 'yes' => 1));
$this->assertNull($result);
$result = Set::enum(0);
$this->assertEquals($result, 'no');
$result = Set::enum(1);
$this->assertEquals($result, 'yes');
$result = Set::enum(2);
$this->assertNull($result);
}
/**
* testFilter method
*
* @return void
*/
public function testFilter() {
$result = Set::filter(array('0', false, true, 0, array('one thing', 'I can tell you', 'is you got to be', false)));
$expected = array('0', 2 => true, 3 => 0, 4 => array('one thing', 'I can tell you', 'is you got to be'));
$this->assertSame($expected, $result);
$result = Set::filter(array(1, array(false)));
$expected = array(1);
$this->assertEqual($expected, $result);
$result = Set::filter(array(1, array(false, false)));
$expected = array(1);
$this->assertEqual($expected, $result);
$result = Set::filter(array(1, array('empty', false)));
$expected = array(1, array('empty'));
$this->assertEqual($expected, $result);
$result = Set::filter(array(1, array('2', false, array(3, null))));
$expected = array(1, array('2', 2 => array(3)));
$this->assertEqual($expected, $result);
$this->assertSame(array(), Set::filter(array()));
}
/**
* testNumericArrayCheck method
*
* @return void
*/
public function testNumericArrayCheck() {
$data = array('one');
$this->assertTrue(Set::numeric(array_keys($data)));
$data = array(1 => 'one');
$this->assertFalse(Set::numeric($data));
$data = array('one');
$this->assertFalse(Set::numeric($data));
$data = array('one' => 'two');
$this->assertFalse(Set::numeric($data));
$data = array('one' => 1);
$this->assertTrue(Set::numeric($data));
$data = array(0);
$this->assertTrue(Set::numeric($data));
$data = array('one', 'two', 'three', 'four', 'five');
$this->assertTrue(Set::numeric(array_keys($data)));
$data = array(1 => 'one', 2 => 'two', 3 => 'three', 4 => 'four', 5 => 'five');
$this->assertTrue(Set::numeric(array_keys($data)));
$data = array('1' => 'one', 2 => 'two', 3 => 'three', 4 => 'four', 5 => 'five');
$this->assertTrue(Set::numeric(array_keys($data)));
$data = array('one', 2 => 'two', 3 => 'three', 4 => 'four', 'a' => 'five');
$this->assertFalse(Set::numeric(array_keys($data)));
}
/**
* testKeyCheck method
*
* @return void
*/
public function testKeyCheck() {
$data = array('Multi' => array('dimensonal' => array('array')));
$this->assertTrue(Set::check($data, 'Multi.dimensonal'));
$this->assertFalse(Set::check($data, 'Multi.dimensonal.array'));
$data = array(
array(
'Article' => array('id' => '1', 'user_id' => '1', 'title' => 'First Article', 'body' => 'First Article Body', 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31'),
'User' => array('id' => '1', 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31'),
'Comment' => array(
array('id' => '1', 'article_id' => '1', 'user_id' => '2', 'comment' => 'First Comment for First Article', 'published' => 'Y', 'created' => '2007-03-18 10:45:23', 'updated' => '2007-03-18 10:47:31'),
array('id' => '2', 'article_id' => '1', 'user_id' => '4', 'comment' => 'Second Comment for First Article', 'published' => 'Y', 'created' => '2007-03-18 10:47:23', 'updated' => '2007-03-18 10:49:31'),
),
'Tag' => array(
array('id' => '1', 'tag' => 'tag1', 'created' => '2007-03-18 12:22:23', 'updated' => '2007-03-18 12:24:31'),
array('id' => '2', 'tag' => 'tag2', 'created' => '2007-03-18 12:24:23', 'updated' => '2007-03-18 12:26:31')
)
),
array(
'Article' => array('id' => '3', 'user_id' => '1', 'title' => 'Third Article', 'body' => 'Third Article Body', 'published' => 'Y', 'created' => '2007-03-18 10:43:23', 'updated' => '2007-03-18 10:45:31'),
'User' => array('id' => '1', 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31'),
'Comment' => array(),
'Tag' => array()
)
);
$this->assertTrue(Set::check($data, '0.Article.user_id'));
$this->assertTrue(Set::check($data, '0.Comment.0.id'));
$this->assertFalse(Set::check($data, '0.Comment.0.id.0'));
$this->assertTrue(Set::check($data, '0.Article.user_id'));
$this->assertFalse(Set::check($data, '0.Article.user_id.a'));
}
/**
* testMerge method
*
* @return void
*/
public function testMerge() {
$r = Set::merge(array('foo'));
$this->assertEquals($r, array('foo'));
$r = Set::merge('foo');
$this->assertEquals($r, array('foo'));
$r = Set::merge('foo', 'bar');
$this->assertEquals($r, array('foo', 'bar'));
if (substr(PHP_VERSION, 0, 1) >= 5) {
$r = eval('class StaticSetCaller{static function merge($a, $b){return Set::merge($a, $b);}} return StaticSetCaller::merge("foo", "bar");');
$this->assertEquals($r, array('foo', 'bar'));
}
$r = Set::merge('foo', array('user' => 'bob', 'no-bar'), 'bar');
$this->assertEquals($r, array('foo', 'user' => 'bob', 'no-bar', 'bar'));
$a = array('foo', 'foo2');
$b = array('bar', 'bar2');
$this->assertEquals(Set::merge($a, $b), array('foo', 'foo2', 'bar', 'bar2'));
$a = array('foo' => 'bar', 'bar' => 'foo');
$b = array('foo' => 'no-bar', 'bar' => 'no-foo');
$this->assertEquals(Set::merge($a, $b), array('foo' => 'no-bar', 'bar' => 'no-foo'));
$a = array('users' => array('bob', 'jim'));
$b = array('users' => array('lisa', 'tina'));
$this->assertEquals(Set::merge($a, $b), array('users' => array('bob', 'jim', 'lisa', 'tina')));
$a = array('users' => array('jim', 'bob'));
$b = array('users' => 'none');
$this->assertEquals(Set::merge($a, $b), array('users' => 'none'));
$a = array('users' => array('lisa' => array('id' => 5, 'pw' => 'secret')), 'cakephp');
$b = array('users' => array('lisa' => array('pw' => 'new-pass', 'age' => 23)), 'ice-cream');
$this->assertEquals(Set::merge($a, $b), array('users' => array('lisa' => array('id' => 5, 'pw' => 'new-pass', 'age' => 23)), 'cakephp', 'ice-cream'));
$c = array('users' => array('lisa' => array('pw' => 'you-will-never-guess', 'age' => 25, 'pet' => 'dog')), 'chocolate');
$expected = array('users' => array('lisa' => array('id' => 5, 'pw' => 'you-will-never-guess', 'age' => 25, 'pet' => 'dog')), 'cakephp', 'ice-cream', 'chocolate');
$this->assertEquals(Set::merge($a, $b, $c), $expected);
$this->assertEquals(Set::merge($a, $b, array(), $c), $expected);
$r = Set::merge($a, $b, $c);
$this->assertEquals($r, $expected);
$a = array('Tree', 'CounterCache',
'Upload' => array('folder' => 'products',
'fields' => array('image_1_id', 'image_2_id', 'image_3_id', 'image_4_id', 'image_5_id')));
$b = array('Cacheable' => array('enabled' => false),
'Limit',
'Bindable',
'Validator',
'Transactional');
$expected = array('Tree', 'CounterCache',
'Upload' => array('folder' => 'products',
'fields' => array('image_1_id', 'image_2_id', 'image_3_id', 'image_4_id', 'image_5_id')),
'Cacheable' => array('enabled' => false),
'Limit',
'Bindable',
'Validator',
'Transactional');
$this->assertEquals(Set::merge($a, $b), $expected);
$expected = array('Tree' => null, 'CounterCache' => null,
'Upload' => array('folder' => 'products',
'fields' => array('image_1_id', 'image_2_id', 'image_3_id', 'image_4_id', 'image_5_id')),
'Cacheable' => array('enabled' => false),
'Limit' => null,
'Bindable' => null,
'Validator' => null,
'Transactional' => null);
$this->assertEquals(Set::normalize(Set::merge($a, $b)), $expected);
}
/**
* testSort method
*
* @return void
*/
public function testSort() {
$a = array(
0 => array('Person' => array('name' => 'Jeff'), 'Friend' => array(array('name' => 'Nate'))),
1 => array('Person' => array('name' => 'Tracy'),'Friend' => array(array('name' => 'Lindsay')))
);
$b = array(
0 => array('Person' => array('name' => 'Tracy'),'Friend' => array(array('name' => 'Lindsay'))),
1 => array('Person' => array('name' => 'Jeff'), 'Friend' => array(array('name' => 'Nate')))
);
$a = Set::sort($a, '{n}.Friend.{n}.name', 'asc');
$this->assertEquals($a, $b);
$b = array(
0 => array('Person' => array('name' => 'Jeff'), 'Friend' => array(array('name' => 'Nate'))),
1 => array('Person' => array('name' => 'Tracy'),'Friend' => array(array('name' => 'Lindsay')))
);
$a = array(
0 => array('Person' => array('name' => 'Tracy'),'Friend' => array(array('name' => 'Lindsay'))),
1 => array('Person' => array('name' => 'Jeff'), 'Friend' => array(array('name' => 'Nate')))
);
$a = Set::sort($a, '{n}.Friend.{n}.name', 'desc');
$this->assertEquals($a, $b);
$a = array(
0 => array('Person' => array('name' => 'Jeff'), 'Friend' => array(array('name' => 'Nate'))),
1 => array('Person' => array('name' => 'Tracy'),'Friend' => array(array('name' => 'Lindsay'))),
2 => array('Person' => array('name' => 'Adam'),'Friend' => array(array('name' => 'Bob')))
);
$b = array(
0 => array('Person' => array('name' => 'Adam'),'Friend' => array(array('name' => 'Bob'))),
1 => array('Person' => array('name' => 'Jeff'), 'Friend' => array(array('name' => 'Nate'))),
2 => array('Person' => array('name' => 'Tracy'),'Friend' => array(array('name' => 'Lindsay')))
);
$a = Set::sort($a, '{n}.Person.name', 'asc');
$this->assertEquals($a, $b);
$a = array(
array(7,6,4),
array(3,4,5),
array(3,2,1),
);
$b = array(
array(3,2,1),
array(3,4,5),
array(7,6,4),
);
$a = Set::sort($a, '{n}.{n}', 'asc');
$this->assertEquals($a, $b);
$a = array(
array(7,6,4),
array(3,4,5),
array(3,2,array(1,1,1)),
);
$b = array(
array(3,2,array(1,1,1)),
array(3,4,5),
array(7,6,4),
);
$a = Set::sort($a, '{n}', 'asc');
$this->assertEquals($a, $b);
$a = array(
0 => array('Person' => array('name' => 'Jeff')),
1 => array('Shirt' => array('color' => 'black'))
);
$b = array(
0 => array('Shirt' => array('color' => 'black')),
1 => array('Person' => array('name' => 'Jeff')),
);
$a = Set::sort($a, '{n}.Person.name', 'ASC');
$this->assertEquals($a, $b);
$names = array(
array('employees' => array(array('name' => array('first' => 'John', 'last' => 'Doe')))),
array('employees' => array(array('name' => array('first' => 'Jane', 'last' => 'Doe')))),
array('employees' => array(array('name' => array()))),
array('employees' => array(array('name' => array())))
);
$result = Set::sort($names, '{n}.employees.0.name', 'asc', 1);
$expected = array(
array('employees' => array(array('name' => array('first' => 'John', 'last' => 'Doe')))),
array('employees' => array(array('name' => array('first' => 'Jane', 'last' => 'Doe')))),
array('employees' => array(array('name' => array()))),
array('employees' => array(array('name' => array())))
);
$this->assertEqual($expected, $result);
}
/**
* test sorting with out of order keys.
*
* @return void
*/
public function testSortWithOutOfOrderKeys() {
$data = array(
9 => array('class' => 510, 'test2' => 2),
1 => array('class' => 500, 'test2' => 1),
2 => array('class' => 600, 'test2' => 2),
5 => array('class' => 625, 'test2' => 4),
0 => array('class' => 605, 'test2' => 3),
);
$expected = array(
array('class' => 500, 'test2' => 1),
array('class' => 510, 'test2' => 2),
array('class' => 600, 'test2' => 2),
array('class' => 605, 'test2' => 3),
array('class' => 625, 'test2' => 4),
);
$result = Set::sort($data, '{n}.class', 'asc');
$this->assertEqual($expected, $result);
$result = Set::sort($data, '{n}.test2', 'asc');
$this->assertEqual($expected, $result);
}
/**
* testExtract method
*
* @return void
*/
public function testExtract() {
$a = array(
array(
'Article' => array('id' => '1', 'user_id' => '1', 'title' => 'First Article', 'body' => 'First Article Body', 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31'),
'User' => array('id' => '1', 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31'),
'Comment' => array(
array('id' => '1', 'article_id' => '1', 'user_id' => '2', 'comment' => 'First Comment for First Article', 'published' => 'Y', 'created' => '2007-03-18 10:45:23', 'updated' => '2007-03-18 10:47:31'),
array('id' => '2', 'article_id' => '1', 'user_id' => '4', 'comment' => 'Second Comment for First Article', 'published' => 'Y', 'created' => '2007-03-18 10:47:23', 'updated' => '2007-03-18 10:49:31'),
),
'Tag' => array(
array('id' => '1', 'tag' => 'tag1', 'created' => '2007-03-18 12:22:23', 'updated' => '2007-03-18 12:24:31'),
array('id' => '2', 'tag' => 'tag2', 'created' => '2007-03-18 12:24:23', 'updated' => '2007-03-18 12:26:31')
),
'Deep' => array(
'Nesting' => array(
'test' => array(
1 => 'foo',
2 => array(
'and' => array('more' => 'stuff')
)
)
)
)
),
array(
'Article' => array('id' => '3', 'user_id' => '1', 'title' => 'Third Article', 'body' => 'Third Article Body', 'published' => 'Y', 'created' => '2007-03-18 10:43:23', 'updated' => '2007-03-18 10:45:31'),
'User' => array('id' => '2', 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31'),
'Comment' => array(),
'Tag' => array()
),
array(
'Article' => array('id' => '3', 'user_id' => '1', 'title' => 'Third Article', 'body' => 'Third Article Body', 'published' => 'Y', 'created' => '2007-03-18 10:43:23', 'updated' => '2007-03-18 10:45:31'),
'User' => array('id' => '3', 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31'),
'Comment' => array(),
'Tag' => array()
),
array(
'Article' => array('id' => '3', 'user_id' => '1', 'title' => 'Third Article', 'body' => 'Third Article Body', 'published' => 'Y', 'created' => '2007-03-18 10:43:23', 'updated' => '2007-03-18 10:45:31'),
'User' => array('id' => '4', 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31'),
'Comment' => array(),
'Tag' => array()
),
array(
'Article' => array('id' => '3', 'user_id' => '1', 'title' => 'Third Article', 'body' => 'Third Article Body', 'published' => 'Y', 'created' => '2007-03-18 10:43:23', 'updated' => '2007-03-18 10:45:31'),
'User' => array('id' => '5', 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31'),
'Comment' => array(),
'Tag' => array()
)
);
$b = array('Deep' => $a[0]['Deep']);
$c = array(
array('a' => array('I' => array('a' => 1))),
array(
'a' => array(
2
)
),
array('a' => array('II' => array('a' => 3, 'III' => array('a' => array('foo' => 4))))),
);
$expected = array(array('a' => $c[2]['a']));
$r = Set::extract('/a/II[a=3]/..', $c);
$this->assertEqual($r, $expected);
$expected = array(1, 2, 3, 4, 5);
$this->assertEqual(Set::extract('/User/id', $a), $expected);
$expected = array(1, 2, 3, 4, 5);
$this->assertEqual(Set::extract('/User/id', $a), $expected);
$expected = array(
array('id' => 1), array('id' => 2), array('id' => 3), array('id' => 4), array('id' => 5)
);
$r = Set::extract('/User/id', $a, array('flatten' => false));
$this->assertEqual($r, $expected);
$expected = array(array('test' => $a[0]['Deep']['Nesting']['test']));
$this->assertEqual(Set::extract('/Deep/Nesting/test', $a), $expected);
$this->assertEqual(Set::extract('/Deep/Nesting/test', $b), $expected);
$expected = array(array('test' => $a[0]['Deep']['Nesting']['test']));
$r = Set::extract('/Deep/Nesting/test/1/..', $a);
$this->assertEqual($r, $expected);
$expected = array(array('test' => $a[0]['Deep']['Nesting']['test']));
$r = Set::extract('/Deep/Nesting/test/2/and/../..', $a);
$this->assertEqual($r, $expected);
$expected = array(array('test' => $a[0]['Deep']['Nesting']['test']));
$r = Set::extract('/Deep/Nesting/test/2/../../../Nesting/test/2/..', $a);
$this->assertEqual($r, $expected);
$expected = array(2);
$r = Set::extract('/User[2]/id', $a);
$this->assertEqual($r, $expected);
$expected = array(4, 5);
$r = Set::extract('/User[id>3]/id', $a);
$this->assertEqual($r, $expected);
$expected = array(2, 3);
$r = Set::extract('/User[id>1][id<=3]/id', $a);
$this->assertEqual($r, $expected);
$expected = array(array('I'), array('II'));
$r = Set::extract('/a/@*', $c);
$this->assertEqual($r, $expected);
$single = array(
'User' => array(
'id' => 4,
'name' => 'Neo',
)
);
$tricky = array(
0 => array(
'User' => array(
'id' => 1,
'name' => 'John',
)
),
1 => array(
'User' => array(
'id' => 2,
'name' => 'Bob',
)
),
2 => array(
'User' => array(
'id' => 3,
'name' => 'Tony',
)
),
'User' => array(
'id' => 4,
'name' => 'Neo',
)
);
$expected = array(1, 2, 3, 4);
$r = Set::extract('/User/id', $tricky);
$this->assertEqual($r, $expected);
$expected = array(4);
$r = Set::extract('/User/id', $single);
$this->assertEqual($r, $expected);
$expected = array(1, 3);
$r = Set::extract('/User[name=/n/]/id', $tricky);
$this->assertEqual($r, $expected);
$expected = array(4);
$r = Set::extract('/User[name=/N/]/id', $tricky);
$this->assertEqual($r, $expected);
$expected = array(1, 3, 4);
$r = Set::extract('/User[name=/N/i]/id', $tricky);
$this->assertEqual($r, $expected);
$expected = array(array('id', 'name'), array('id', 'name'), array('id', 'name'), array('id', 'name'));
$r = Set::extract('/User/@*', $tricky);
$this->assertEqual($r, $expected);
$common = array(
array(
'Article' => array(
'id' => 1,
'name' => 'Article 1',
),
'Comment' => array(
array(
'id' => 1,
'user_id' => 5,
'article_id' => 1,
'text' => 'Comment 1',
),
array(
'id' => 2,
'user_id' => 23,
'article_id' => 1,
'text' => 'Comment 2',
),
array(
'id' => 3,
'user_id' => 17,
'article_id' => 1,
'text' => 'Comment 3',
),
),
),
array(
'Article' => array(
'id' => 2,
'name' => 'Article 2',
),
'Comment' => array(
array(
'id' => 4,
'user_id' => 2,
'article_id' => 2,
'text' => 'Comment 4',
'addition' => '',
),
array(
'id' => 5,
'user_id' => 23,
'article_id' => 2,
'text' => 'Comment 5',
'addition' => 'foo',
),
),
),
array(
'Article' => array(
'id' => 3,
'name' => 'Article 3',
),
'Comment' => array(),
)
);
$r = Set::extract('/Comment/id', $common);
$expected = array(1, 2, 3, 4, 5);
$this->assertEqual($r, $expected);
$expected = array(1, 2, 4, 5);
$r = Set::extract('/Comment[id!=3]/id', $common);
$this->assertEqual($r, $expected);
$r = Set::extract('/', $common);
$this->assertEqual($r, $common);
$expected = array(1, 2, 4, 5);
$r = Set::extract($common, '/Comment[id!=3]/id');
$this->assertEqual($r, $expected);
$expected = array($common[0]['Comment'][2]);
$r = Set::extract($common, '/Comment/2');
$this->assertEqual($r, $expected);
$expected = array($common[0]['Comment'][0]);
$r = Set::extract($common, '/Comment[1]/.[id=1]');
$this->assertEqual($r, $expected);
$expected = array($common[1]['Comment'][1]);
$r = Set::extract($common, '/1/Comment/.[2]');
$this->assertEqual($r, $expected);
$expected = array();
$r = Set::extract('/User/id', array());
$this->assertEqual($r, $expected);
$expected = array(5);
$r = Set::extract('/Comment/id[:last]', $common);
$this->assertEqual($r, $expected);
$expected = array(1);
$r = Set::extract('/Comment/id[:first]', $common);
$this->assertEqual($r, $expected);
$expected = array(3);
$r = Set::extract('/Article[:last]/id', $common);
$this->assertEqual($r, $expected);
$expected = array(array('Comment' => $common[1]['Comment'][0]));
$r = Set::extract('/Comment[addition=]', $common);
$this->assertEqual($r, $expected);
$habtm = array(
array(
'Post' => array(
'id' => 1,
'title' => 'great post',
),
'Comment' => array(
array(
'id' => 1,
'text' => 'foo',
'User' => array(
'id' => 1,
'name' => 'bob'
),
),
array(
'id' => 2,
'text' => 'bar',
'User' => array(
'id' => 2,
'name' => 'tod'
),
),
),
),
array(
'Post' => array(
'id' => 2,
'title' => 'fun post',
),
'Comment' => array(
array(
'id' => 3,
'text' => '123',
'User' => array(
'id' => 3,
'name' => 'dan'
),
),
array(
'id' => 4,
'text' => '987',
'User' => array(
'id' => 4,
'name' => 'jim'
),
),
),
),
);
$r = Set::extract('/Comment/User[name=/bob|dan/]/..', $habtm);
$this->assertEqual($r[0]['Comment']['User']['name'], 'bob');
$this->assertEqual($r[1]['Comment']['User']['name'], 'dan');
$this->assertEqual(count($r), 2);
$r = Set::extract('/Comment/User[name=/bob|tod/]/..', $habtm);
$this->assertEqual($r[0]['Comment']['User']['name'], 'bob');
$this->assertEqual($r[1]['Comment']['User']['name'], 'tod');
$this->assertEqual(count($r), 2);
$tree = array(
array(
'Category' => array('name' => 'Category 1'),
'children' => array(array('Category' => array('name' => 'Category 1.1')))
),
array(
'Category' => array('name' => 'Category 2'),
'children' => array(
array('Category' => array('name' => 'Category 2.1')),
array('Category' => array('name' => 'Category 2.2'))
)
),
array(
'Category' => array('name' => 'Category 3'),
'children' => array(array('Category' => array('name' => 'Category 3.1')))
)
);
$expected = array(array('Category' => $tree[1]['Category']));
$r = Set::extract('/Category[name=Category 2]', $tree);
$this->assertEqual($r, $expected);
$expected = array(
array('Category' => $tree[1]['Category'], 'children' => $tree[1]['children'])
);
$r = Set::extract('/Category[name=Category 2]/..', $tree);
$this->assertEqual($r, $expected);
$expected = array(
array('children' => $tree[1]['children'][0]),
array('children' => $tree[1]['children'][1])
);
$r = Set::extract('/Category[name=Category 2]/../children', $tree);
$this->assertEqual($r, $expected);
$habtm = array(
array(
'Post' => array(
'id' => 1,
'title' => 'great post',
),
'Comment' => array(
array(
'id' => 1,
'text' => 'foo',
'User' => array(
'id' => 1,
'name' => 'bob'
),
),
array(
'id' => 2,
'text' => 'bar',
'User' => array(
'id' => 2,
'name' => 'tod'
),
),
),
),
array(
'Post' => array(
'id' => 2,
'title' => 'fun post',
),
'Comment' => array(
array(
'id' => 3,
'text' => '123',
'User' => array(
'id' => 3,
'name' => 'dan'
),
),
array(
'id' => 4,
'text' => '987',
'User' => array(
'id' => 4,
'name' => 'jim'
),
),
),
),
);
$r = Set::extract('/Comment/User[name=/\w+/]/..', $habtm);
$this->assertEqual($r[0]['Comment']['User']['name'], 'bob');
$this->assertEqual($r[1]['Comment']['User']['name'], 'tod');
$this->assertEqual($r[2]['Comment']['User']['name'], 'dan');
$this->assertEqual($r[3]['Comment']['User']['name'], 'dan');
$this->assertEqual(count($r), 4);
$r = Set::extract('/Comment/User[name=/[a-z]+/]/..', $habtm);
$this->assertEqual($r[0]['Comment']['User']['name'], 'bob');
$this->assertEqual($r[1]['Comment']['User']['name'], 'tod');
$this->assertEqual($r[2]['Comment']['User']['name'], 'dan');
$this->assertEqual($r[3]['Comment']['User']['name'], 'dan');
$this->assertEqual(count($r), 4);
$r = Set::extract('/Comment/User[name=/bob|dan/]/..', $habtm);
$this->assertEqual($r[0]['Comment']['User']['name'], 'bob');
$this->assertEqual($r[1]['Comment']['User']['name'], 'dan');
$this->assertEqual(count($r), 2);
$r = Set::extract('/Comment/User[name=/bob|tod/]/..', $habtm);
$this->assertEqual($r[0]['Comment']['User']['name'], 'bob');
$this->assertEqual($r[1]['Comment']['User']['name'], 'tod');
$this->assertEqual(count($r), 2);
$mixedKeys = array(
'User' => array(
0 => array(
'id' => 4,
'name' => 'Neo'
),
1 => array(
'id' => 5,
'name' => 'Morpheus'
),
'stringKey' => array()
)
);
$expected = array('Neo', 'Morpheus');
$r = Set::extract('/User/name', $mixedKeys);
$this->assertEqual($r, $expected);
$f = array(
array(
'file' => array(
'name' => 'zipfile.zip',
'type' => 'application/zip',
'tmp_name' => '/tmp/php178.tmp',
'error' => 0,
'size' => '564647'
)
),
array(
'file' => array(
'name' => 'zipfile2.zip',
'type' => 'application/x-zip-compressed',
'tmp_name' => '/tmp/php179.tmp',
'error' => 0,
'size' => '354784'
)
),
array(
'file' => array(
'name' => 'picture.jpg',
'type' => 'image/jpeg',
'tmp_name' => '/tmp/php180.tmp',
'error' => 0,
'size' => '21324'
)
)
);
$expected = array(array('name' => 'zipfile2.zip','type' => 'application/x-zip-compressed','tmp_name' => '/tmp/php179.tmp','error' => 0,'size' => '354784'));
$r = Set::extract('/file/.[type=application/x-zip-compressed]', $f);
$this->assertEqual($r, $expected);
$expected = array(array('name' => 'zipfile.zip','type' => 'application/zip','tmp_name' => '/tmp/php178.tmp','error' => 0,'size' => '564647'));
$r = Set::extract('/file/.[type=application/zip]', $f);
$this->assertEqual($r, $expected);
$f = array(
array(
'file' => array(
'name' => 'zipfile.zip',
'type' => 'application/zip',
'tmp_name' => '/tmp/php178.tmp',
'error' => 0,
'size' => '564647'
)
),
array(
'file' => array(
'name' => 'zipfile2.zip',
'type' => 'application/x zip compressed',
'tmp_name' => '/tmp/php179.tmp',
'error' => 0,
'size' => '354784'
)
),
array(
'file' => array(
'name' => 'picture.jpg',
'type' => 'image/jpeg',
'tmp_name' => '/tmp/php180.tmp',
'error' => 0,
'size' => '21324'
)
)
);
$expected = array(array('name' => 'zipfile2.zip','type' => 'application/x zip compressed','tmp_name' => '/tmp/php179.tmp','error' => 0,'size' => '354784'));
$r = Set::extract('/file/.[type=application/x zip compressed]', $f);
$this->assertEqual($r, $expected);
$expected = array(
array('name' => 'zipfile.zip','type' => 'application/zip','tmp_name' => '/tmp/php178.tmp','error' => 0,'size' => '564647'),
array('name' => 'zipfile2.zip','type' => 'application/x zip compressed','tmp_name' => '/tmp/php179.tmp','error' => 0,'size' => '354784')
);
$r = Set::extract('/file/.[tmp_name=/tmp\/php17/]', $f);
$this->assertEqual($r, $expected);
$hasMany = array(
'Node' => array(
'id' => 1,
'name' => 'First',
'state' => 50
),
'ParentNode' => array(
0 => array(
'id' => 2,
'name' => 'Second',
'state' => 60,
)
)
);
$result = Set::extract('/ParentNode/name', $hasMany);
$expected = array('Second');
$this->assertEquals($expected, $result);
$data = array(
array(
'Category' => array(
'id' => 1,
'name' => 'First'
),
0 => array(
'value' => 50
)
),
array(
'Category' => array(
'id' => 2,
'name' => 'Second'
),
0 => array(
'value' => 60
)
)
);
$expected = array(
array(
'Category' => array(
'id' => 1,
'name' => 'First'
),
0 => array(
'value' => 50
)
)
);
$result = Set::extract('/Category[id=1]/..', $data);
$this->assertEquals($expected, $result);
$data = array(
array(
'ChildNode' => array('id' => 1),
array('name' => 'Item 1')
),
array(
'ChildNode' => array('id' => 2),
array('name' => 'Item 2')
),
);
$expected = array(
'Item 1',
'Item 2'
);
$result = Set::extract('/0/name', $data);
$this->assertEquals($expected, $result);
$data = array(
array('A1', 'B1'),
array('A2', 'B2')
);
$expected = array('A1', 'A2');
$result = Set::extract('/0', $data);
$this->assertEquals($expected, $result);
}
/**
* test parent selectors with extract
*
* @return void
*/
public function testExtractParentSelector() {
$tree = array(
array(
'Category' => array(
'name' => 'Category 1'
),
'children' => array(
array(
'Category' => array(
'name' => 'Category 1.1'
)
)
)
),
array(
'Category' => array(
'name' => 'Category 2'
),
'children' => array(
array(
'Category' => array(
'name' => 'Category 2.1'
)
),
array(
'Category' => array(
'name' => 'Category 2.2'
)
),
)
),
array(
'Category' => array(
'name' => 'Category 3'
),
'children' => array(
array(
'Category' => array(
'name' => 'Category 3.1'
)
)
)
)
);
$expected = array(array('Category' => $tree[1]['Category']));
$r = Set::extract('/Category[name=Category 2]', $tree);
$this->assertEqual($r, $expected);
$expected = array(array('Category' => $tree[1]['Category'], 'children' => $tree[1]['children']));
$r = Set::extract('/Category[name=Category 2]/..', $tree);
$this->assertEqual($r, $expected);
$expected = array(array('children' => $tree[1]['children'][0]), array('children' => $tree[1]['children'][1]));
$r = Set::extract('/Category[name=Category 2]/../children', $tree);
$this->assertEqual($r, $expected);
$single = array(
array(
'CallType' => array(
'name' => 'Internal Voice'
),
'x' => array(
'hour' => 7
)
)
);
$expected = array(7);
$r = Set::extract('/CallType[name=Internal Voice]/../x/hour', $single);
$this->assertEqual($r, $expected);
$multiple = array(
array(
'CallType' => array(
'name' => 'Internal Voice'
),
'x' => array(
'hour' => 7
)
),
array(
'CallType' => array(
'name' => 'Internal Voice'
),
'x' => array(
'hour' => 2
)
),
array(
'CallType' => array(
'name' => 'Internal Voice'
),
'x' => array(
'hour' => 1
)
)
);
$expected = array(7,2,1);
$r = Set::extract('/CallType[name=Internal Voice]/../x/hour', $multiple);
$this->assertEqual($r, $expected);
$a = array(
'Model' => array(
'0' => array(
'id' => 18,
'SubModelsModel' => array(
'id' => 1,
'submodel_id' => 66,
'model_id' => 18,
'type' => 1
),
),
'1' => array(
'id' => 0,
'SubModelsModel' => array(
'id' => 2,
'submodel_id' => 66,
'model_id' => 0,
'type' => 1
),
),
'2' => array(
'id' => 17,
'SubModelsModel' => array(
'id' => 3,
'submodel_id' => 66,
'model_id' => 17,
'type' => 2
),
),
'3' => array(
'id' => 0,
'SubModelsModel' => array(
'id' => 4,
'submodel_id' => 66,
'model_id' => 0,
'type' => 2
)
)
)
);
$expected = array(
array(
'Model' => array(
'id' => 17,
'SubModelsModel' => array(
'id' => 3,
'submodel_id' => 66,
'model_id' => 17,
'type' => 2
),
)
),
array(
'Model' => array(
'id' => 0,
'SubModelsModel' => array(
'id' => 4,
'submodel_id' => 66,
'model_id' => 0,
'type' => 2
)
)
)
);
$r = Set::extract('/Model/SubModelsModel[type=2]/..', $a);
$this->assertEqual($r, $expected);
}
/**
* test that extract() still works when arrays don't contain a 0 index.
*
* @return void
*/
public function testExtractWithNonZeroArrays() {
$nonZero = array(
1 => array(
'User' => array(
'id' => 1,
'name' => 'John',
)
),
2 => array(
'User' => array(
'id' => 2,
'name' => 'Bob',
)
),
3 => array(
'User' => array(
'id' => 3,
'name' => 'Tony',
)
)
);
$expected = array(1, 2, 3);
$r = Set::extract('/User/id', $nonZero);
$this->assertEqual($r, $expected);
$expected = array(
array('User' => array('id' => 1, 'name' => 'John')),
array('User' => array('id' => 2, 'name' => 'Bob')),
array('User' => array('id' => 3, 'name' => 'Tony')),
);
$result = Set::extract('/User', $nonZero);
$this->assertEqual($expected, $result);
$nonSequential = array(
'User' => array(
0 => array('id' => 1),
2 => array('id' => 2),
6 => array('id' => 3),
9 => array('id' => 4),
3 => array('id' => 5),
),
);
$nonZero = array(
'User' => array(
2 => array('id' => 1),
4 => array('id' => 2),
6 => array('id' => 3),
9 => array('id' => 4),
3 => array('id' => 5),
),
);
$expected = array(1, 2, 3, 4, 5);
$this->assertEqual(Set::extract('/User/id', $nonSequential), $expected);
$result = Set::extract('/User/id', $nonZero);
$this->assertEqual($expected, $result, 'Failed non zero array key extract');
$expected = array(1, 2, 3, 4, 5);
$this->assertEqual(Set::extract('/User/id', $nonSequential), $expected);
$result = Set::extract('/User/id', $nonZero);
$this->assertEqual($expected, $result, 'Failed non zero array key extract');
$startingAtOne = array(
'Article' => array(
1 => array(
'id' => 1,
'approved' => 1,
),
)
);
$expected = array(0 => array('Article' => array('id' => 1, 'approved' => 1)));
$result = Set::extract('/Article[approved=1]', $startingAtOne);
$this->assertEqual($expected, $result);
$items = array(
240 => array(
'A' => array(
'field1' => 'a240',
'field2' => 'a240',
),
'B' => array(
'field1' => 'b240',
'field2' => 'b240'
),
)
);
$expected = array(
0 => 'b240'
);
$result = Set::extract('/B/field1', $items);
$this->assertIdentical($expected, $result);
$this->assertIdentical($result, Set::extract('{n}.B.field1', $items));
}
/**
* testExtractWithArrays method
*
* @return void
*/
public function testExtractWithArrays() {
$data = array(
'Level1' => array(
'Level2' => array('test1', 'test2'),
'Level2bis' => array('test3', 'test4')
)
);
$this->assertEqual(Set::extract('/Level1/Level2', $data), array(array('Level2' => array('test1', 'test2'))));
$this->assertEqual(Set::extract('/Level1/Level2bis', $data), array(array('Level2bis' => array('test3', 'test4'))));
}
/**
* test extract() with elements that have non-array children.
*
* @return void
*/
public function testExtractWithNonArrayElements() {
$data = array(
'node' => array(
array('foo'),
'bar'
)
);
$result = Set::extract('/node', $data);
$expected = array(
array('node' => array('foo')),
'bar'
);
$this->assertEqual($expected, $result);
$data = array(
'node' => array(
'foo' => array('bar'),
'bar' => array('foo')
)
);
$result = Set::extract('/node', $data);
$expected = array(
array('foo' => array('bar')),
array('bar' => array('foo')),
);
$this->assertEqual($expected, $result);
$data = array(
'node' => array(
'foo' => array(
'bar'
),
'bar' => 'foo'
)
);
$result = Set::extract('/node', $data);
$expected = array(
array('foo' => array('bar')),
'foo'
);
$this->assertEqual($expected, $result);
}
/**
* testMatches method
*
* @return void
*/
public function testMatches() {
$a = array(
array('Article' => array('id' => 1, 'title' => 'Article 1')),
array('Article' => array('id' => 2, 'title' => 'Article 2')),
array('Article' => array('id' => 3, 'title' => 'Article 3'))
);
$this->assertTrue(Set::matches(array('id=2'), $a[1]['Article']));
$this->assertFalse(Set::matches(array('id>2'), $a[1]['Article']));
$this->assertTrue(Set::matches(array('id>=2'), $a[1]['Article']));
$this->assertFalse(Set::matches(array('id>=3'), $a[1]['Article']));
$this->assertTrue(Set::matches(array('id<=2'), $a[1]['Article']));
$this->assertFalse(Set::matches(array('id<2'), $a[1]['Article']));
$this->assertTrue(Set::matches(array('id>1'), $a[1]['Article']));
$this->assertTrue(Set::matches(array('id>1', 'id<3', 'id!=0'), $a[1]['Article']));
$this->assertTrue(Set::matches(array('3'), null, 3));
$this->assertTrue(Set::matches(array('5'), null, 5));
$this->assertTrue(Set::matches(array('id'), $a[1]['Article']));
$this->assertTrue(Set::matches(array('id', 'title'), $a[1]['Article']));
$this->assertFalse(Set::matches(array('non-existant'), $a[1]['Article']));
$this->assertTrue(Set::matches('/Article[id=2]', $a));
$this->assertFalse(Set::matches('/Article[id=4]', $a));
$this->assertTrue(Set::matches(array(), $a));
$r = array(
'Attachment' => array(
'keep' => array()
),
'Comment' => array(
'keep' => array(
'Attachment' => array(
'fields' => array(
0 => 'attachment',
),
),
)
),
'User' => array(
'keep' => array()
),
'Article' => array(
'keep' => array(
'Comment' => array(
'fields' => array(
0 => 'comment',
1 => 'published',
),
),
'User' => array(
'fields' => array(
0 => 'user',
),
),
)
)
);
$this->assertTrue(Set::matches('/Article/keep/Comment', $r));
$this->assertEqual(Set::extract('/Article/keep/Comment/fields', $r), array('comment', 'published'));
$this->assertEqual(Set::extract('/Article/keep/User/fields', $r), array('user'));
}
/**
* testSetExtractReturnsEmptyArray method
*
* @return void
*/
public function testSetExtractReturnsEmptyArray() {
$this->assertEquals(Set::extract(array(), '/Post/id'), array());
$this->assertEquals(Set::extract('/Post/id', array()), array());
$this->assertEquals(Set::extract('/Post/id', array(
array('Post' => array('name' => 'bob')),
array('Post' => array('name' => 'jim'))
)), array());
$this->assertEquals(Set::extract(array(), 'Message.flash'), null);
}
/**
* testClassicExtract method
*
* @return void
*/
public function testClassicExtract() {
$a = array(
array('Article' => array('id' => 1, 'title' => 'Article 1')),
array('Article' => array('id' => 2, 'title' => 'Article 2')),
array('Article' => array('id' => 3, 'title' => 'Article 3'))
);
$result = Set::extract($a, '{n}.Article.id');
$expected = array( 1, 2, 3 );
$this->assertEquals($expected, $result);
$result = Set::extract($a, '{n}.Article.title');
$expected = array( 'Article 1', 'Article 2', 'Article 3' );
$this->assertEquals($expected, $result);
$result = Set::extract($a, '1.Article.title');
$expected = 'Article 2';
$this->assertEquals($expected, $result);
$result = Set::extract($a, '3.Article.title');
$expected = null;
$this->assertEquals($expected, $result);
$a = array(
array(
'Article' => array('id' => 1, 'title' => 'Article 1',
'User' => array('id' => 1, 'username' => 'mariano.iglesias'))
),
array(
'Article' => array('id' => 2, 'title' => 'Article 2',
'User' => array('id' => 1, 'username' => 'mariano.iglesias'))
),
array(
'Article' => array('id' => 3, 'title' => 'Article 3',
'User' => array('id' => 2, 'username' => 'phpnut'))
)
);
$result = Set::extract($a, '{n}.Article.User.username');
$expected = array( 'mariano.iglesias', 'mariano.iglesias', 'phpnut' );
$this->assertEquals($expected, $result);
$a = array(
array(
'Article' => array(
'id' => 1, 'title' => 'Article 1',
'Comment' => array(
array('id' => 10, 'title' => 'Comment 10'),
array('id' => 11, 'title' => 'Comment 11'),
array('id' => 12, 'title' => 'Comment 12')
)
)
),
array(
'Article' => array(
'id' => 2, 'title' => 'Article 2',
'Comment' => array(
array('id' => 13, 'title' => 'Comment 13'),
array('id' => 14, 'title' => 'Comment 14')
)
)
),
array('Article' => array('id' => 3, 'title' => 'Article 3'))
);
$result = Set::extract($a, '{n}.Article.Comment.{n}.id');
$expected = array (array(10, 11, 12), array(13, 14), null);
$this->assertEquals($expected, $result);
$result = Set::extract($a, '{n}.Article.Comment.{n}.title');
$expected = array(
array('Comment 10', 'Comment 11', 'Comment 12'),
array('Comment 13', 'Comment 14'),
null
);
$this->assertEquals($expected, $result);
$a = array(array('1day' => '20 sales'), array('1day' => '2 sales'));
$result = Set::extract($a, '{n}.1day');
$expected = array('20 sales', '2 sales');
$this->assertEquals($expected, $result);
$a = array(
'pages' => array('name' => 'page'),
'fruites' => array('name' => 'fruit'),
0 => array('name' => 'zero')
);
$result = Set::extract($a, '{s}.name');
$expected = array('page','fruit');
$this->assertEquals($expected, $result);
$a = array(
0 => array('pages' => array('name' => 'page')),
1 => array('fruites'=> array('name' => 'fruit')),
'test' => array(array('name' => 'jippi')),
'dot.test' => array(array('name' => 'jippi'))
);
$result = Set::extract($a, '{n}.{s}.name');
$expected = array(0 => array('page'), 1 => array('fruit'));
$this->assertEquals($expected, $result);
$result = Set::extract($a, '{s}.{n}.name');
$expected = array(array('jippi'), array('jippi'));
$this->assertEquals($expected, $result);
$result = Set::extract($a, '{\w+}.{\w+}.name');
$expected = array(
array('pages' => 'page'),
array('fruites' => 'fruit'),
'test' => array('jippi'),
'dot.test' => array('jippi')
);
$this->assertEquals($expected, $result);
$result = Set::extract($a, '{\d+}.{\w+}.name');
$expected = array(array('pages' => 'page'), array('fruites' => 'fruit'));
$this->assertEquals($expected, $result);
$result = Set::extract($a, '{n}.{\w+}.name');
$expected = array(array('pages' => 'page'), array('fruites' => 'fruit'));
$this->assertEquals($expected, $result);
$result = Set::extract($a, '{s}.{\d+}.name');
$expected = array(array('jippi'), array('jippi'));
$this->assertEquals($expected, $result);
$result = Set::extract($a, '{s}');
$expected = array(array(array('name' => 'jippi')), array(array('name' => 'jippi')));
$this->assertEquals($expected, $result);
$result = Set::extract($a, '{[a-z]}');
$expected = array(
'test' => array(array('name' => 'jippi')),
'dot.test' => array(array('name' => 'jippi'))
);
$this->assertEquals($expected, $result);
$result = Set::extract($a, '{dot\.test}.{n}');
$expected = array('dot.test' => array(array('name' => 'jippi')));
$this->assertEquals($expected, $result);
$a = new stdClass();
$a->articles = array(
array('Article' => array('id' => 1, 'title' => 'Article 1')),
array('Article' => array('id' => 2, 'title' => 'Article 2')),
array('Article' => array('id' => 3, 'title' => 'Article 3'))
);
$result = Set::extract($a, 'articles.{n}.Article.id');
$expected = array(1, 2, 3);
$this->assertEquals($expected, $result);
$result = Set::extract($a, 'articles.{n}.Article.title');
$expected = array('Article 1', 'Article 2', 'Article 3');
$this->assertEquals($expected, $result);
$a = new ArrayObject();
$a['articles'] = array(
array('Article' => array('id' => 1, 'title' => 'Article 1')),
array('Article' => array('id' => 2, 'title' => 'Article 2')),
array('Article' => array('id' => 3, 'title' => 'Article 3'))
);
$result = Set::extract($a, 'articles.{n}.Article.id');
$expected = array(1, 2, 3);
$this->assertEquals($expected, $result);
$result = Set::extract($a, 'articles.{n}.Article.title');
$expected = array('Article 1', 'Article 2', 'Article 3');
$this->assertEquals($expected, $result);
$result = Set::extract($a, 'articles.0.Article.title');
$expected = 'Article 1';
$this->assertEquals($expected, $result);
}
/**
* testInsert method
*
* @return void
*/
public function testInsert() {
$a = array(
'pages' => array('name' => 'page')
);
$result = Set::insert($a, 'files', array('name' => 'files'));
$expected = array(
'pages' => array('name' => 'page'),
'files' => array('name' => 'files')
);
$this->assertEquals($expected, $result);
$a = array(
'pages' => array('name' => 'page')
);
$result = Set::insert($a, 'pages.name', array());
$expected = array(
'pages' => array('name' => array()),
);
$this->assertEquals($expected, $result);
$a = array(
'pages' => array(
0 => array('name' => 'main'),
1 => array('name' => 'about')
)
);
$result = Set::insert($a, 'pages.1.vars', array('title' => 'page title'));
$expected = array(
'pages' => array(
0 => array('name' => 'main'),
1 => array('name' => 'about', 'vars' => array('title' => 'page title'))
)
);
$this->assertEquals($expected, $result);
}
/**
* testRemove method
*
* @return void
*/
public function testRemove() {
$a = array(
'pages' => array('name' => 'page'),
'files' => array('name' => 'files')
);
$result = Set::remove($a, 'files', array('name' => 'files'));
$expected = array(
'pages' => array('name' => 'page')
);
$this->assertEquals($expected, $result);
$a = array(
'pages' => array(
0 => array('name' => 'main'),
1 => array('name' => 'about', 'vars' => array('title' => 'page title'))
)
);
$result = Set::remove($a, 'pages.1.vars', array('title' => 'page title'));
$expected = array(
'pages' => array(
0 => array('name' => 'main'),
1 => array('name' => 'about')
)
);
$this->assertEquals($expected, $result);
$result = Set::remove($a, 'pages.2.vars', array('title' => 'page title'));
$expected = $a;
$this->assertEquals($expected, $result);
}
/**
* testCheck method
*
* @return void
*/
public function testCheck() {
$set = array(
'My Index 1' => array('First' => 'The first item')
);
$this->assertTrue(Set::check($set, 'My Index 1.First'));
$this->assertTrue(Set::check($set, 'My Index 1'));
$this->assertEquals(Set::check($set, array()), $set);
$set = array(
'My Index 1' => array('First' => array('Second' => array('Third' => array('Fourth' => 'Heavy. Nesting.'))))
);
$this->assertTrue(Set::check($set, 'My Index 1.First.Second'));
$this->assertTrue(Set::check($set, 'My Index 1.First.Second.Third'));
$this->assertTrue(Set::check($set, 'My Index 1.First.Second.Third.Fourth'));
$this->assertFalse(Set::check($set, 'My Index 1.First.Seconds.Third.Fourth'));
}
/**
* testWritingWithFunkyKeys method
*
* @return void
*/
public function testWritingWithFunkyKeys() {
$set = Set::insert(array(), 'Session Test', "test");
$this->assertEqual(Set::extract($set, 'Session Test'), 'test');
$set = Set::remove($set, 'Session Test');
$this->assertFalse(Set::check($set, 'Session Test'));
$expected = array('Session Test' => array('Test Case' => 'test'));
$this->assertEquals(Set::insert(array(), 'Session Test.Test Case', "test"), $expected);
$this->assertTrue(Set::check($expected, 'Session Test.Test Case'));
}
/**
* testDiff method
*
* @return void
*/
public function testDiff() {
$a = array(
0 => array('name' => 'main'),
1 => array('name' => 'about')
);
$b = array(
0 => array('name' => 'main'),
1 => array('name' => 'about'),
2 => array('name' => 'contact')
);
$result = Set::diff($a, $b);
$expected = array(
2 => array('name' => 'contact')
);
$this->assertEquals($expected, $result);
$result = Set::diff($a, array());
$expected = $a;
$this->assertEquals($expected, $result);
$result = Set::diff(array(), $b);
$expected = $b;
$this->assertEquals($expected, $result);
$b = array(
0 => array('name' => 'me'),
1 => array('name' => 'about')
);
$result = Set::diff($a, $b);
$expected = array(
0 => array('name' => 'main')
);
$this->assertEquals($expected, $result);
$a = array();
$b = array('name' => 'bob', 'address' => 'home');
$result = Set::diff($a, $b);
$this->assertEquals($result, $b);
$a = array('name' => 'bob', 'address' => 'home');
$b = array();
$result = Set::diff($a, $b);
$this->assertEquals($result, $a);
$a = array('key' => true, 'another' => false, 'name' => 'me');
$b = array('key' => 1, 'another' => 0);
$expected = array('name' => 'me');
$result = Set::diff($a, $b);
$this->assertEquals($expected, $result);
$a = array('key' => 'value', 'another' => null, 'name' => 'me');
$b = array('key' => 'differentValue', 'another' => null);
$expected = array('key' => 'value', 'name' => 'me');
$result = Set::diff($a, $b);
$this->assertEquals($expected, $result);
$a = array('key' => 'value', 'another' => null, 'name' => 'me');
$b = array('key' => 'differentValue', 'another' => 'value');
$expected = array('key' => 'value', 'another' => null, 'name' => 'me');
$result = Set::diff($a, $b);
$this->assertEquals($expected, $result);
$a = array('key' => 'value', 'another' => null, 'name' => 'me');
$b = array('key' => 'differentValue', 'another' => 'value');
$expected = array('key' => 'differentValue', 'another' => 'value', 'name' => 'me');
$result = Set::diff($b, $a);
$this->assertEquals($expected, $result);
$a = array('key' => 'value', 'another' => null, 'name' => 'me');
$b = array(0 => 'differentValue', 1 => 'value');
$expected = $a + $b;
$result = Set::diff($a, $b);
$this->assertEquals($expected, $result);
}
/**
* testContains method
*
* @return void
*/
public function testContains() {
$a = array(
0 => array('name' => 'main'),
1 => array('name' => 'about')
);
$b = array(
0 => array('name' => 'main'),
1 => array('name' => 'about'),
2 => array('name' => 'contact'),
'a' => 'b'
);
$this->assertTrue(Set::contains($a, $a));
$this->assertFalse(Set::contains($a, $b));
$this->assertTrue(Set::contains($b, $a));
}
/**
* testCombine method
*
* @return void
*/
public function testCombine() {
$result = Set::combine(array(), '{n}.User.id', '{n}.User.Data');
$this->assertTrue(empty($result));
$result = Set::combine('', '{n}.User.id', '{n}.User.Data');
$this->assertTrue(empty($result));
$a = array(
array('User' => array('id' => 2, 'group_id' => 1,
'Data' => array('user' => 'mariano.iglesias','name' => 'Mariano Iglesias'))),
array('User' => array('id' => 14, 'group_id' => 2,
'Data' => array('user' => 'phpnut', 'name' => 'Larry E. Masters'))),
array('User' => array('id' => 25, 'group_id' => 1,
'Data' => array('user' => 'gwoo','name' => 'The Gwoo'))));
$result = Set::combine($a, '{n}.User.id');
$expected = array(2 => null, 14 => null, 25 => null);
$this->assertEquals($expected, $result);
$result = Set::combine($a, '{n}.User.id', '{n}.User.non-existant');
$expected = array(2 => null, 14 => null, 25 => null);
$this->assertEquals($expected, $result);
$result = Set::combine($a, '{n}.User.id', '{n}.User.Data');
$expected = array(
2 => array('user' => 'mariano.iglesias', 'name' => 'Mariano Iglesias'),
14 => array('user' => 'phpnut', 'name' => 'Larry E. Masters'),
25 => array('user' => 'gwoo', 'name' => 'The Gwoo'));
$this->assertEquals($expected, $result);
$result = Set::combine($a, '{n}.User.id', '{n}.User.Data.name');
$expected = array(
2 => 'Mariano Iglesias',
14 => 'Larry E. Masters',
25 => 'The Gwoo');
$this->assertEquals($expected, $result);
$result = Set::combine($a, '{n}.User.id', '{n}.User.Data', '{n}.User.group_id');
$expected = array(
1 => array(
2 => array('user' => 'mariano.iglesias', 'name' => 'Mariano Iglesias'),
25 => array('user' => 'gwoo', 'name' => 'The Gwoo')),
2 => array(
14 => array('user' => 'phpnut', 'name' => 'Larry E. Masters')));
$this->assertEquals($expected, $result);
$result = Set::combine($a, '{n}.User.id', '{n}.User.Data.name', '{n}.User.group_id');
$expected = array(
1 => array(
2 => 'Mariano Iglesias',
25 => 'The Gwoo'),
2 => array(
14 => 'Larry E. Masters'));
$this->assertEquals($expected, $result);
$result = Set::combine($a, '{n}.User.id');
$expected = array(2 => null, 14 => null, 25 => null);
$this->assertEquals($expected, $result);
$result = Set::combine($a, '{n}.User.id', '{n}.User.Data');
$expected = array(
2 => array('user' => 'mariano.iglesias', 'name' => 'Mariano Iglesias'),
14 => array('user' => 'phpnut', 'name' => 'Larry E. Masters'),
25 => array('user' => 'gwoo', 'name' => 'The Gwoo'));
$this->assertEquals($expected, $result);
$result = Set::combine($a, '{n}.User.id', '{n}.User.Data.name');
$expected = array(2 => 'Mariano Iglesias', 14 => 'Larry E. Masters', 25 => 'The Gwoo');
$this->assertEquals($expected, $result);
$result = Set::combine($a, '{n}.User.id', '{n}.User.Data', '{n}.User.group_id');
$expected = array(
1 => array(
2 => array('user' => 'mariano.iglesias', 'name' => 'Mariano Iglesias'),
25 => array('user' => 'gwoo', 'name' => 'The Gwoo')),
2 => array(
14 => array('user' => 'phpnut', 'name' => 'Larry E. Masters')));
$this->assertEquals($expected, $result);
$result = Set::combine($a, '{n}.User.id', '{n}.User.Data.name', '{n}.User.group_id');
$expected = array(
1 => array(
2 => 'Mariano Iglesias',
25 => 'The Gwoo'),
2 => array(
14 => 'Larry E. Masters'));
$this->assertEquals($expected, $result);
$result = Set::combine($a, '{n}.User.id', array('{0}: {1}', '{n}.User.Data.user', '{n}.User.Data.name'), '{n}.User.group_id');
$expected = array (
1 => array (
2 => 'mariano.iglesias: Mariano Iglesias',
25 => 'gwoo: The Gwoo'),
2 => array (14 => 'phpnut: Larry E. Masters'));
$this->assertEquals($expected, $result);
$result = Set::combine($a, array('{0}: {1}', '{n}.User.Data.user', '{n}.User.Data.name'), '{n}.User.id');
$expected = array('mariano.iglesias: Mariano Iglesias' => 2, 'phpnut: Larry E. Masters' => 14, 'gwoo: The Gwoo' => 25);
$this->assertEquals($expected, $result);
$result = Set::combine($a, array('{1}: {0}', '{n}.User.Data.user', '{n}.User.Data.name'), '{n}.User.id');
$expected = array('Mariano Iglesias: mariano.iglesias' => 2, 'Larry E. Masters: phpnut' => 14, 'The Gwoo: gwoo' => 25);
$this->assertEquals($expected, $result);
$result = Set::combine($a, array('%1$s: %2$d', '{n}.User.Data.user', '{n}.User.id'), '{n}.User.Data.name');
$expected = array('mariano.iglesias: 2' => 'Mariano Iglesias', 'phpnut: 14' => 'Larry E. Masters', 'gwoo: 25' => 'The Gwoo');
$this->assertEquals($expected, $result);
$result = Set::combine($a, array('%2$d: %1$s', '{n}.User.Data.user', '{n}.User.id'), '{n}.User.Data.name');
$expected = array('2: mariano.iglesias' => 'Mariano Iglesias', '14: phpnut' => 'Larry E. Masters', '25: gwoo' => 'The Gwoo');
$this->assertEquals($expected, $result);
$b = new stdClass();
$b->users = array(
array('User' => array('id' => 2, 'group_id' => 1,
'Data' => array('user' => 'mariano.iglesias','name' => 'Mariano Iglesias'))),
array('User' => array('id' => 14, 'group_id' => 2,
'Data' => array('user' => 'phpnut', 'name' => 'Larry E. Masters'))),
array('User' => array('id' => 25, 'group_id' => 1,
'Data' => array('user' => 'gwoo','name' => 'The Gwoo'))));
$result = Set::combine($b, 'users.{n}.User.id');
$expected = array(2 => null, 14 => null, 25 => null);
$this->assertEquals($expected, $result);
$result = Set::combine($b, 'users.{n}.User.id', 'users.{n}.User.non-existant');
$expected = array(2 => null, 14 => null, 25 => null);
$this->assertEquals($expected, $result);
$result = Set::combine($a, 'fail', 'fail');
$this->assertEqual($result, array());
}
/**
* testMapReverse method
*
* @return void
*/
public function testMapReverse() {
$result = Set::reverse(null);
$this->assertEqual($result, null);
$result = Set::reverse(false);
$this->assertEqual($result, false);
$expected = array(
'Array1' => array(
'Array1Data1' => 'Array1Data1 value 1', 'Array1Data2' => 'Array1Data2 value 2'),
'Array2' => array(
0 => array('Array2Data1' => 1, 'Array2Data2' => 'Array2Data2 value 2', 'Array2Data3' => 'Array2Data3 value 2', 'Array2Data4' => 'Array2Data4 value 4'),
1 => array('Array2Data1' => 2, 'Array2Data2' => 'Array2Data2 value 2', 'Array2Data3' => 'Array2Data3 value 2', 'Array2Data4' => 'Array2Data4 value 4'),
2 => array('Array2Data1' => 3, 'Array2Data2' => 'Array2Data2 value 2', 'Array2Data3' => 'Array2Data3 value 2', 'Array2Data4' => 'Array2Data4 value 4'),
3 => array('Array2Data1' => 4, 'Array2Data2' => 'Array2Data2 value 2', 'Array2Data3' => 'Array2Data3 value 2', 'Array2Data4' => 'Array2Data4 value 4'),
4 => array('Array2Data1' => 5, 'Array2Data2' => 'Array2Data2 value 2', 'Array2Data3' => 'Array2Data3 value 2', 'Array2Data4' => 'Array2Data4 value 4')),
'Array3' => array(
0 => array('Array3Data1' => 1, 'Array3Data2' => 'Array3Data2 value 2', 'Array3Data3' => 'Array3Data3 value 2', 'Array3Data4' => 'Array3Data4 value 4'),
1 => array('Array3Data1' => 2, 'Array3Data2' => 'Array3Data2 value 2', 'Array3Data3' => 'Array3Data3 value 2', 'Array3Data4' => 'Array3Data4 value 4'),
2 => array('Array3Data1' => 3, 'Array3Data2' => 'Array3Data2 value 2', 'Array3Data3' => 'Array3Data3 value 2', 'Array3Data4' => 'Array3Data4 value 4'),
3 => array('Array3Data1' => 4, 'Array3Data2' => 'Array3Data2 value 2', 'Array3Data3' => 'Array3Data3 value 2', 'Array3Data4' => 'Array3Data4 value 4'),
4 => array('Array3Data1' => 5, 'Array3Data2' => 'Array3Data2 value 2', 'Array3Data3' => 'Array3Data3 value 2', 'Array3Data4' => 'Array3Data4 value 4')));
$map = Set::map($expected, true);
$this->assertEqual($map->Array1->Array1Data1, $expected['Array1']['Array1Data1']);
$this->assertEqual($map->Array2[0]->Array2Data1, $expected['Array2'][0]['Array2Data1']);
$result = Set::reverse($map);
$this->assertEquals($expected, $result);
$expected = array(
'Post' => array('id'=> 1, 'title' => 'First Post'),
'Comment' => array(
array('id'=> 1, 'title' => 'First Comment'),
array('id'=> 2, 'title' => 'Second Comment')
),
'Tag' => array(
array('id'=> 1, 'title' => 'First Tag'),
array('id'=> 2, 'title' => 'Second Tag')
),
);
$map = Set::map($expected);
$this->assertEquals($map->title, $expected['Post']['title']);
foreach ($map->Comment as $comment) {
$ids[] = $comment->id;
}
$this->assertEquals($ids, array(1, 2));
$expected = array(
'Array1' => array(
'Array1Data1' => 'Array1Data1 value 1', 'Array1Data2' => 'Array1Data2 value 2', 'Array1Data3' => 'Array1Data3 value 3','Array1Data4' => 'Array1Data4 value 4',
'Array1Data5' => 'Array1Data5 value 5', 'Array1Data6' => 'Array1Data6 value 6', 'Array1Data7' => 'Array1Data7 value 7', 'Array1Data8' => 'Array1Data8 value 8'),
'string' => 1,
'another' => 'string',
'some' => 'thing else',
'Array2' => array(
0 => array('Array2Data1' => 1, 'Array2Data2' => 'Array2Data2 value 2', 'Array2Data3' => 'Array2Data3 value 2', 'Array2Data4' => 'Array2Data4 value 4'),
1 => array('Array2Data1' => 2, 'Array2Data2' => 'Array2Data2 value 2', 'Array2Data3' => 'Array2Data3 value 2', 'Array2Data4' => 'Array2Data4 value 4'),
2 => array('Array2Data1' => 3, 'Array2Data2' => 'Array2Data2 value 2', 'Array2Data3' => 'Array2Data3 value 2', 'Array2Data4' => 'Array2Data4 value 4'),
3 => array('Array2Data1' => 4, 'Array2Data2' => 'Array2Data2 value 2', 'Array2Data3' => 'Array2Data3 value 2', 'Array2Data4' => 'Array2Data4 value 4'),
4 => array('Array2Data1' => 5, 'Array2Data2' => 'Array2Data2 value 2', 'Array2Data3' => 'Array2Data3 value 2', 'Array2Data4' => 'Array2Data4 value 4')),
'Array3' => array(
0 => array('Array3Data1' => 1, 'Array3Data2' => 'Array3Data2 value 2', 'Array3Data3' => 'Array3Data3 value 2', 'Array3Data4' => 'Array3Data4 value 4'),
1 => array('Array3Data1' => 2, 'Array3Data2' => 'Array3Data2 value 2', 'Array3Data3' => 'Array3Data3 value 2', 'Array3Data4' => 'Array3Data4 value 4'),
2 => array('Array3Data1' => 3, 'Array3Data2' => 'Array3Data2 value 2', 'Array3Data3' => 'Array3Data3 value 2', 'Array3Data4' => 'Array3Data4 value 4'),
3 => array('Array3Data1' => 4, 'Array3Data2' => 'Array3Data2 value 2', 'Array3Data3' => 'Array3Data3 value 2', 'Array3Data4' => 'Array3Data4 value 4'),
4 => array('Array3Data1' => 5, 'Array3Data2' => 'Array3Data2 value 2', 'Array3Data3' => 'Array3Data3 value 2', 'Array3Data4' => 'Array3Data4 value 4')));
$map = Set::map($expected, true);
$result = Set::reverse($map);
$this->assertEquals($expected, $result);
$expected = array(
'Array1' => array(
'Array1Data1' => 'Array1Data1 value 1', 'Array1Data2' => 'Array1Data2 value 2', 'Array1Data3' => 'Array1Data3 value 3','Array1Data4' => 'Array1Data4 value 4',
'Array1Data5' => 'Array1Data5 value 5', 'Array1Data6' => 'Array1Data6 value 6', 'Array1Data7' => 'Array1Data7 value 7', 'Array1Data8' => 'Array1Data8 value 8'),
'string' => 1,
'another' => 'string',
'some' => 'thing else',
'Array2' => array(
0 => array('Array2Data1' => 1, 'Array2Data2' => 'Array2Data2 value 2', 'Array2Data3' => 'Array2Data3 value 2', 'Array2Data4' => 'Array2Data4 value 4'),
1 => array('Array2Data1' => 2, 'Array2Data2' => 'Array2Data2 value 2', 'Array2Data3' => 'Array2Data3 value 2', 'Array2Data4' => 'Array2Data4 value 4'),
2 => array('Array2Data1' => 3, 'Array2Data2' => 'Array2Data2 value 2', 'Array2Data3' => 'Array2Data3 value 2', 'Array2Data4' => 'Array2Data4 value 4'),
3 => array('Array2Data1' => 4, 'Array2Data2' => 'Array2Data2 value 2', 'Array2Data3' => 'Array2Data3 value 2', 'Array2Data4' => 'Array2Data4 value 4'),
4 => array('Array2Data1' => 5, 'Array2Data2' => 'Array2Data2 value 2', 'Array2Data3' => 'Array2Data3 value 2', 'Array2Data4' => 'Array2Data4 value 4')),
'string2' => 1,
'another2' => 'string',
'some2' => 'thing else',
'Array3' => array(
0 => array('Array3Data1' => 1, 'Array3Data2' => 'Array3Data2 value 2', 'Array3Data3' => 'Array3Data3 value 2', 'Array3Data4' => 'Array3Data4 value 4'),
1 => array('Array3Data1' => 2, 'Array3Data2' => 'Array3Data2 value 2', 'Array3Data3' => 'Array3Data3 value 2', 'Array3Data4' => 'Array3Data4 value 4'),
2 => array('Array3Data1' => 3, 'Array3Data2' => 'Array3Data2 value 2', 'Array3Data3' => 'Array3Data3 value 2', 'Array3Data4' => 'Array3Data4 value 4'),
3 => array('Array3Data1' => 4, 'Array3Data2' => 'Array3Data2 value 2', 'Array3Data3' => 'Array3Data3 value 2', 'Array3Data4' => 'Array3Data4 value 4'),
4 => array('Array3Data1' => 5, 'Array3Data2' => 'Array3Data2 value 2', 'Array3Data3' => 'Array3Data3 value 2', 'Array3Data4' => 'Array3Data4 value 4')),
'string3' => 1,
'another3' => 'string',
'some3' => 'thing else');
$map = Set::map($expected, true);
$result = Set::reverse($map);
$this->assertEquals($expected, $result);
$expected = array('User' => array('psword'=> 'whatever', 'Icon' => array('id'=> 851)));
$map = Set::map($expected);
$result = Set::reverse($map);
$this->assertEquals($expected, $result);
$expected = array('User' => array('psword'=> 'whatever', 'Icon' => array('id'=> 851)));
$class = new stdClass;
$class->User = new stdClass;
$class->User->psword = 'whatever';
$class->User->Icon = new stdClass;
$class->User->Icon->id = 851;
$result = Set::reverse($class);
$this->assertEquals($expected, $result);
$expected = array('User' => array('psword'=> 'whatever', 'Icon' => array('id'=> 851), 'Profile' => array('name' => 'Some Name', 'address' => 'Some Address')));
$class = new stdClass;
$class->User = new stdClass;
$class->User->psword = 'whatever';
$class->User->Icon = new stdClass;
$class->User->Icon->id = 851;
$class->User->Profile = new stdClass;
$class->User->Profile->name = 'Some Name';
$class->User->Profile->address = 'Some Address';
$result = Set::reverse($class);
$this->assertEquals($expected, $result);
$expected = array('User' => array('psword'=> 'whatever',
'Icon' => array('id'=> 851),
'Profile' => array('name' => 'Some Name', 'address' => 'Some Address'),
'Comment' => array(
array('id' => 1, 'article_id' => 1, 'user_id' => 1, 'comment' => 'First Comment for First Article', 'published' => 'Y', 'created' => '2007-03-18 10:47:23', 'updated' => '2007-03-18 10:49:31'),
array('id' => 2, 'article_id' => 1, 'user_id' => 2, 'comment' => 'Second Comment for First Article', 'published' => 'Y', 'created' => '2007-03-18 10:47:23', 'updated' => '2007-03-18 10:49:31'))));
$class = new stdClass;
$class->User = new stdClass;
$class->User->psword = 'whatever';
$class->User->Icon = new stdClass;
$class->User->Icon->id = 851;
$class->User->Profile = new stdClass;
$class->User->Profile->name = 'Some Name';
$class->User->Profile->address = 'Some Address';
$class->User->Comment = new stdClass;
$class->User->Comment->{'0'} = new stdClass;
$class->User->Comment->{'0'}->id = 1;
$class->User->Comment->{'0'}->article_id = 1;
$class->User->Comment->{'0'}->user_id = 1;
$class->User->Comment->{'0'}->comment = 'First Comment for First Article';
$class->User->Comment->{'0'}->published = 'Y';
$class->User->Comment->{'0'}->created = '2007-03-18 10:47:23';
$class->User->Comment->{'0'}->updated = '2007-03-18 10:49:31';
$class->User->Comment->{'1'} = new stdClass;
$class->User->Comment->{'1'}->id = 2;
$class->User->Comment->{'1'}->article_id = 1;
$class->User->Comment->{'1'}->user_id = 2;
$class->User->Comment->{'1'}->comment = 'Second Comment for First Article';
$class->User->Comment->{'1'}->published = 'Y';
$class->User->Comment->{'1'}->created = '2007-03-18 10:47:23';
$class->User->Comment->{'1'}->updated = '2007-03-18 10:49:31';
$result = Set::reverse($class);
$this->assertEquals($expected, $result);
$expected = array('User' => array('psword'=> 'whatever',
'Icon' => array('id'=> 851),
'Profile' => array('name' => 'Some Name', 'address' => 'Some Address'),
'Comment' => array(
array('id' => 1, 'article_id' => 1, 'user_id' => 1, 'comment' => 'First Comment for First Article', 'published' => 'Y', 'created' => '2007-03-18 10:47:23', 'updated' => '2007-03-18 10:49:31'),
array('id' => 2, 'article_id' => 1, 'user_id' => 2, 'comment' => 'Second Comment for First Article', 'published' => 'Y', 'created' => '2007-03-18 10:47:23', 'updated' => '2007-03-18 10:49:31'))));
$class = new stdClass;
$class->User = new stdClass;
$class->User->psword = 'whatever';
$class->User->Icon = new stdClass;
$class->User->Icon->id = 851;
$class->User->Profile = new stdClass;
$class->User->Profile->name = 'Some Name';
$class->User->Profile->address = 'Some Address';
$class->User->Comment = array();
$comment = new stdClass;
$comment->id = 1;
$comment->article_id = 1;
$comment->user_id = 1;
$comment->comment = 'First Comment for First Article';
$comment->published = 'Y';
$comment->created = '2007-03-18 10:47:23';
$comment->updated = '2007-03-18 10:49:31';
$comment2 = new stdClass;
$comment2->id = 2;
$comment2->article_id = 1;
$comment2->user_id = 2;
$comment2->comment = 'Second Comment for First Article';
$comment2->published = 'Y';
$comment2->created = '2007-03-18 10:47:23';
$comment2->updated = '2007-03-18 10:49:31';
$class->User->Comment = array($comment, $comment2);
$result = Set::reverse($class);
$this->assertEquals($expected, $result);
$class = new stdClass;
$class->User = new stdClass;
$class->User->id = 100;
$class->someString = 'this is some string';
$class->Profile = new stdClass;
$class->Profile->name = 'Joe Mamma';
$result = Set::reverse($class);
$expected = array('User' => array('id' => '100'), 'someString'=> 'this is some string', 'Profile' => array('name' => 'Joe Mamma'));
$this->assertEqual($expected, $result);
$class = new stdClass;
$class->User = new stdClass;
$class->User->id = 100;
$class->User->_name_ = 'User';
$class->Profile = new stdClass;
$class->Profile->name = 'Joe Mamma';
$class->Profile->_name_ = 'Profile';
$result = Set::reverse($class);
$expected = array('User' => array('id' => '100'), 'Profile' => array('name' => 'Joe Mamma'));
$this->assertEqual($expected, $result);
}
/**
* testFormatting method
*
* @return void
*/
public function testFormatting() {
$data = array(
array('Person' => array('first_name' => 'Nate', 'last_name' => 'Abele', 'city' => 'Boston', 'state' => 'MA', 'something' => '42')),
array('Person' => array('first_name' => 'Larry', 'last_name' => 'Masters', 'city' => 'Boondock', 'state' => 'TN', 'something' => '{0}')),
array('Person' => array('first_name' => 'Garrett', 'last_name' => 'Woodworth', 'city' => 'Venice Beach', 'state' => 'CA', 'something' => '{1}')));
$result = Set::format($data, '{1}, {0}', array('{n}.Person.first_name', '{n}.Person.last_name'));
$expected = array('Abele, Nate', 'Masters, Larry', 'Woodworth, Garrett');
$this->assertEqual($expected, $result);
$result = Set::format($data, '{0}, {1}', array('{n}.Person.last_name', '{n}.Person.first_name'));
$this->assertEqual($expected, $result);
$result = Set::format($data, '{0}, {1}', array('{n}.Person.city', '{n}.Person.state'));
$expected = array('Boston, MA', 'Boondock, TN', 'Venice Beach, CA');
$this->assertEqual($expected, $result);
$result = Set::format($data, '{{0}, {1}}', array('{n}.Person.city', '{n}.Person.state'));
$expected = array('{Boston, MA}', '{Boondock, TN}', '{Venice Beach, CA}');
$this->assertEqual($expected, $result);
$result = Set::format($data, '{{0}, {1}}', array('{n}.Person.something', '{n}.Person.something'));
$expected = array('{42, 42}', '{{0}, {0}}', '{{1}, {1}}');
$this->assertEqual($expected, $result);
$result = Set::format($data, '{%2$d, %1$s}', array('{n}.Person.something', '{n}.Person.something'));
$expected = array('{42, 42}', '{0, {0}}', '{0, {1}}');
$this->assertEqual($expected, $result);
$result = Set::format($data, '{%1$s, %1$s}', array('{n}.Person.something', '{n}.Person.something'));
$expected = array('{42, 42}', '{{0}, {0}}', '{{1}, {1}}');
$this->assertEqual($expected, $result);
$result = Set::format($data, '%2$d, %1$s', array('{n}.Person.first_name', '{n}.Person.something'));
$expected = array('42, Nate', '0, Larry', '0, Garrett');
$this->assertEqual($expected, $result);
$result = Set::format($data, '%1$s, %2$d', array('{n}.Person.first_name', '{n}.Person.something'));
$expected = array('Nate, 42', 'Larry, 0', 'Garrett, 0');
$this->assertEqual($expected, $result);
}
/**
* testFormattingNullValues method
*
* @return void
*/
public function testFormattingNullValues() {
$data = array(
array('Person' => array('first_name' => 'Nate', 'last_name' => 'Abele', 'city' => 'Boston', 'state' => 'MA', 'something' => '42')),
array('Person' => array('first_name' => 'Larry', 'last_name' => 'Masters', 'city' => 'Boondock', 'state' => 'TN', 'something' => null)),
array('Person' => array('first_name' => 'Garrett', 'last_name' => 'Woodworth', 'city' => 'Venice Beach', 'state' => 'CA', 'something' => null)));
$result = Set::format($data, '%s', array('{n}.Person.something'));
$expected = array('42', '', '');
$this->assertEqual($expected, $result);
$result = Set::format($data, '{0}, {1}', array('{n}.Person.city', '{n}.Person.something'));
$expected = array('Boston, 42', 'Boondock, ', 'Venice Beach, ');
$this->assertEqual($expected, $result);
}
/**
* testCountDim method
*
* @return void
*/
public function testCountDim() {
$data = array('one', '2', 'three');
$result = Set::countDim($data);
$this->assertEqual($result, 1);
$data = array('1' => '1.1', '2', '3');
$result = Set::countDim($data);
$this->assertEqual($result, 1);
$data = array('1' => array('1.1' => '1.1.1'), '2', '3' => array('3.1' => '3.1.1'));
$result = Set::countDim($data);
$this->assertEqual($result, 2);
$data = array('1' => '1.1', '2', '3' => array('3.1' => '3.1.1'));
$result = Set::countDim($data);
$this->assertEqual($result, 1);
$data = array('1' => '1.1', '2', '3' => array('3.1' => '3.1.1'));
$result = Set::countDim($data, true);
$this->assertEqual($result, 2);
$data = array('1' => array('1.1' => '1.1.1'), '2', '3' => array('3.1' => array('3.1.1' => '3.1.1.1')));
$result = Set::countDim($data);
$this->assertEqual($result, 2);
$data = array('1' => array('1.1' => '1.1.1'), '2', '3' => array('3.1' => array('3.1.1' => '3.1.1.1')));
$result = Set::countDim($data, true);
$this->assertEqual($result, 3);
$data = array('1' => array('1.1' => '1.1.1'), array('2' => array('2.1' => array('2.1.1' => '2.1.1.1'))), '3' => array('3.1' => array('3.1.1' => '3.1.1.1')));
$result = Set::countDim($data, true);
$this->assertEqual($result, 4);
$data = array('1' => array('1.1' => '1.1.1'), array('2' => array('2.1' => array('2.1.1' => array('2.1.1.1')))), '3' => array('3.1' => array('3.1.1' => '3.1.1.1')));
$result = Set::countDim($data, true);
$this->assertEqual($result, 5);
$data = array('1' => array('1.1' => '1.1.1'), array('2' => array('2.1' => array('2.1.1' => array('2.1.1.1' => '2.1.1.1.1')))), '3' => array('3.1' => array('3.1.1' => '3.1.1.1')));
$result = Set::countDim($data, true);
$this->assertEqual($result, 5);
$set = array('1' => array('1.1' => '1.1.1'), array('2' => array('2.1' => array('2.1.1' => array('2.1.1.1' => '2.1.1.1.1')))), '3' => array('3.1' => array('3.1.1' => '3.1.1.1')));
$result = Set::countDim($set, false, 0);
$this->assertEqual($result, 2);
$result = Set::countDim($set, true);
$this->assertEqual($result, 5);
}
/**
* testMapNesting method
*
* @return void
*/
public function testMapNesting() {
$expected = array(
array(
"IndexedPage" => array(
"id" => 1,
"url" => 'http://blah.com/',
'hash' => '68a9f053b19526d08e36c6a9ad150737933816a5',
'headers' => array(
'Date' => "Wed, 14 Nov 2007 15:51:42 GMT",
'Server' => "Apache",
'Expires' => "Thu, 19 Nov 1981 08:52:00 GMT",
'Cache-Control' => "private",
'Pragma' => "no-cache",
'Content-Type' => "text/html; charset=UTF-8",
'X-Original-Transfer-Encoding' => "chunked",
'Content-Length' => "50210",
),
'meta' => array(
'keywords' => array('testing','tests'),
'description'=>'describe me',
),
'get_vars' => '',
'post_vars' => array(),
'cookies' => array('PHPSESSID' => "dde9896ad24595998161ffaf9e0dbe2d"),
'redirect' => '',
'created' => "1195055503",
'updated' => "1195055503",
)
),
array(
"IndexedPage" => array(
"id" => 2,
"url" => 'http://blah.com/',
'hash' => '68a9f053b19526d08e36c6a9ad150737933816a5',
'headers' => array(
'Date' => "Wed, 14 Nov 2007 15:51:42 GMT",
'Server' => "Apache",
'Expires' => "Thu, 19 Nov 1981 08:52:00 GMT",
'Cache-Control' => "private",
'Pragma' => "no-cache",
'Content-Type' => "text/html; charset=UTF-8",
'X-Original-Transfer-Encoding' => "chunked",
'Content-Length' => "50210",
),
'meta' => array(
'keywords' => array('testing','tests'),
'description'=>'describe me',
),
'get_vars' => '',
'post_vars' => array(),
'cookies' => array('PHPSESSID' => "dde9896ad24595998161ffaf9e0dbe2d"),
'redirect' => '',
'created' => "1195055503",
'updated' => "1195055503",
),
)
);
$mapped = Set::map($expected);
$ids = array();
foreach($mapped as $object) {
$ids[] = $object->id;
}
$this->assertEqual($ids, array(1, 2));
$this->assertEqual(get_object_vars($mapped[0]->headers), $expected[0]['IndexedPage']['headers']);
$result = Set::reverse($mapped);
$this->assertEquals($expected, $result);
$data = array(
array(
"IndexedPage" => array(
"id" => 1,
"url" => 'http://blah.com/',
'hash' => '68a9f053b19526d08e36c6a9ad150737933816a5',
'get_vars' => '',
'redirect' => '',
'created' => "1195055503",
'updated' => "1195055503",
)
),
array(
"IndexedPage" => array(
"id" => 2,
"url" => 'http://blah.com/',
'hash' => '68a9f053b19526d08e36c6a9ad150737933816a5',
'get_vars' => '',
'redirect' => '',
'created' => "1195055503",
'updated' => "1195055503",
),
)
);
$mapped = Set::map($data);
$expected = new stdClass();
$expected->_name_ = 'IndexedPage';
$expected->id = 2;
$expected->url = 'http://blah.com/';
$expected->hash = '68a9f053b19526d08e36c6a9ad150737933816a5';
$expected->get_vars = '';
$expected->redirect = '';
$expected->created = "1195055503";
$expected->updated = "1195055503";
$this->assertEquals($mapped[1], $expected);
$ids = array();
foreach($mapped as $object) {
$ids[] = $object->id;
}
$this->assertEqual($ids, array(1, 2));
$result = Set::map(null);
$expected = null;
$this->assertEqual($expected, $result);
}
/**
* testNestedMappedData method
*
* @return void
*/
public function testNestedMappedData() {
$result = Set::map(array(
array(
'Post' => array('id' => '1', 'author_id' => '1', 'title' => 'First Post', 'body' => 'First Post Body', 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31'),
'Author' => array('id' => '1', 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31', 'test' => 'working'),
)
, array(
'Post' => array('id' => '2', 'author_id' => '3', 'title' => 'Second Post', 'body' => 'Second Post Body', 'published' => 'Y', 'created' => '2007-03-18 10:41:23', 'updated' => '2007-03-18 10:43:31'),
'Author' => array('id' => '3', 'user' => 'larry', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:20:23', 'updated' => '2007-03-17 01:22:31', 'test' => 'working'),
)
));
$expected = new stdClass;
$expected->_name_ = 'Post';
$expected->id = '1';
$expected->author_id = '1';
$expected->title = 'First Post';
$expected->body = 'First Post Body';
$expected->published = 'Y';
$expected->created = "2007-03-18 10:39:23";
$expected->updated = "2007-03-18 10:41:31";
$expected->Author = new stdClass;
$expected->Author->id = '1';
$expected->Author->user = 'mariano';
$expected->Author->password = '5f4dcc3b5aa765d61d8327deb882cf99';
$expected->Author->created = "2007-03-17 01:16:23";
$expected->Author->updated = "2007-03-17 01:18:31";
$expected->Author->test = "working";
$expected->Author->_name_ = 'Author';
$expected2 = new stdClass;
$expected2->_name_ = 'Post';
$expected2->id = '2';
$expected2->author_id = '3';
$expected2->title = 'Second Post';
$expected2->body = 'Second Post Body';
$expected2->published = 'Y';
$expected2->created = "2007-03-18 10:41:23";
$expected2->updated = "2007-03-18 10:43:31";
$expected2->Author = new stdClass;
$expected2->Author->id = '3';
$expected2->Author->user = 'larry';
$expected2->Author->password = '5f4dcc3b5aa765d61d8327deb882cf99';
$expected2->Author->created = "2007-03-17 01:20:23";
$expected2->Author->updated = "2007-03-17 01:22:31";
$expected2->Author->test = "working";
$expected2->Author->_name_ = 'Author';
$test = array();
$test[0] = $expected;
$test[1] = $expected2;
$this->assertEquals($test, $result);
$result = Set::map(
array(
'Post' => array('id' => '1', 'author_id' => '1', 'title' => 'First Post', 'body' => 'First Post Body', 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31'),
'Author' => array('id' => '1', 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31', 'test' => 'working'),
)
);
$expected = new stdClass;
$expected->_name_ = 'Post';
$expected->id = '1';
$expected->author_id = '1';
$expected->title = 'First Post';
$expected->body = 'First Post Body';
$expected->published = 'Y';
$expected->created = "2007-03-18 10:39:23";
$expected->updated = "2007-03-18 10:41:31";
$expected->Author = new stdClass;
$expected->Author->id = '1';
$expected->Author->user = 'mariano';
$expected->Author->password = '5f4dcc3b5aa765d61d8327deb882cf99';
$expected->Author->created = "2007-03-17 01:16:23";
$expected->Author->updated = "2007-03-17 01:18:31";
$expected->Author->test = "working";
$expected->Author->_name_ = 'Author';
$this->assertEquals($expected, $result);
//Case where extra HABTM fields come back in a result
$data = array(
'User' => array(
'id' => 1,
'email' => 'user@example.com',
'first_name' => 'John',
'last_name' => 'Smith',
),
'Piece' => array(
array(
'id' => 1,
'title' => 'Moonlight Sonata',
'composer' => 'Ludwig van Beethoven',
'PiecesUser' => array(
'id' => 1,
'created' => '2008-01-01 00:00:00',
'modified' => '2008-01-01 00:00:00',
'piece_id' => 1,
'user_id' => 2,
)
),
array(
'id' => 2,
'title' => 'Moonlight Sonata 2',
'composer' => 'Ludwig van Beethoven',
'PiecesUser' => array(
'id' => 2,
'created' => '2008-01-01 00:00:00',
'modified' => '2008-01-01 00:00:00',
'piece_id' => 2,
'user_id' => 2,
)
)
)
);
$result = Set::map($data);
$expected = new stdClass();
$expected->_name_ = 'User';
$expected->id = 1;
$expected->email = 'user@example.com';
$expected->first_name = 'John';
$expected->last_name = 'Smith';
$piece = new stdClass();
$piece->id = 1;
$piece->title = 'Moonlight Sonata';
$piece->composer = 'Ludwig van Beethoven';
$piece->PiecesUser = new stdClass();
$piece->PiecesUser->id = 1;
$piece->PiecesUser->created = '2008-01-01 00:00:00';
$piece->PiecesUser->modified = '2008-01-01 00:00:00';
$piece->PiecesUser->piece_id = 1;
$piece->PiecesUser->user_id = 2;
$piece->PiecesUser->_name_ = 'PiecesUser';
$piece->_name_ = 'Piece';
$piece2 = new stdClass();
$piece2->id = 2;
$piece2->title = 'Moonlight Sonata 2';
$piece2->composer = 'Ludwig van Beethoven';
$piece2->PiecesUser = new stdClass();
$piece2->PiecesUser->id = 2;
$piece2->PiecesUser->created = '2008-01-01 00:00:00';
$piece2->PiecesUser->modified = '2008-01-01 00:00:00';
$piece2->PiecesUser->piece_id = 2;
$piece2->PiecesUser->user_id = 2;
$piece2->PiecesUser->_name_ = 'PiecesUser';
$piece2->_name_ = 'Piece';
$expected->Piece = array($piece, $piece2);
$this->assertEquals($expected, $result);
//Same data, but should work if _name_ has been manually defined:
$data = array(
'User' => array(
'id' => 1,
'email' => 'user@example.com',
'first_name' => 'John',
'last_name' => 'Smith',
'_name_' => 'FooUser',
),
'Piece' => array(
array(
'id' => 1,
'title' => 'Moonlight Sonata',
'composer' => 'Ludwig van Beethoven',
'_name_' => 'FooPiece',
'PiecesUser' => array(
'id' => 1,
'created' => '2008-01-01 00:00:00',
'modified' => '2008-01-01 00:00:00',
'piece_id' => 1,
'user_id' => 2,
'_name_' => 'FooPiecesUser',
)
),
array(
'id' => 2,
'title' => 'Moonlight Sonata 2',
'composer' => 'Ludwig van Beethoven',
'_name_' => 'FooPiece',
'PiecesUser' => array(
'id' => 2,
'created' => '2008-01-01 00:00:00',
'modified' => '2008-01-01 00:00:00',
'piece_id' => 2,
'user_id' => 2,
'_name_' => 'FooPiecesUser',
)
)
)
);
$result = Set::map($data);
$expected = new stdClass();
$expected->_name_ = 'FooUser';
$expected->id = 1;
$expected->email = 'user@example.com';
$expected->first_name = 'John';
$expected->last_name = 'Smith';
$piece = new stdClass();
$piece->id = 1;
$piece->title = 'Moonlight Sonata';
$piece->composer = 'Ludwig van Beethoven';
$piece->_name_ = 'FooPiece';
$piece->PiecesUser = new stdClass();
$piece->PiecesUser->id = 1;
$piece->PiecesUser->created = '2008-01-01 00:00:00';
$piece->PiecesUser->modified = '2008-01-01 00:00:00';
$piece->PiecesUser->piece_id = 1;
$piece->PiecesUser->user_id = 2;
$piece->PiecesUser->_name_ = 'FooPiecesUser';
$piece2 = new stdClass();
$piece2->id = 2;
$piece2->title = 'Moonlight Sonata 2';
$piece2->composer = 'Ludwig van Beethoven';
$piece2->_name_ = 'FooPiece';
$piece2->PiecesUser = new stdClass();
$piece2->PiecesUser->id = 2;
$piece2->PiecesUser->created = '2008-01-01 00:00:00';
$piece2->PiecesUser->modified = '2008-01-01 00:00:00';
$piece2->PiecesUser->piece_id = 2;
$piece2->PiecesUser->user_id = 2;
$piece2->PiecesUser->_name_ = 'FooPiecesUser';
$expected->Piece = array($piece, $piece2);
$this->assertEquals($expected, $result);
}
/**
* testPushDiff method
*
* @return void
*/
public function testPushDiff() {
$array1 = array('ModelOne' => array('id'=>1001, 'field_one'=>'a1.m1.f1', 'field_two'=>'a1.m1.f2'));
$array2 = array('ModelTwo' => array('id'=>1002, 'field_one'=>'a2.m2.f1', 'field_two'=>'a2.m2.f2'));
$result = Set::pushDiff($array1, $array2);
$this->assertEquals($result, $array1 + $array2);
$array3 = array('ModelOne' => array('id'=>1003, 'field_one'=>'a3.m1.f1', 'field_two'=>'a3.m1.f2', 'field_three'=>'a3.m1.f3'));
$result = Set::pushDiff($array1, $array3);
$expected = array('ModelOne' => array('id'=>1001, 'field_one'=>'a1.m1.f1', 'field_two'=>'a1.m1.f2', 'field_three'=>'a3.m1.f3'));
$this->assertEquals($expected, $result);
$array1 = array(
0 => array('ModelOne' => array('id'=>1001, 'field_one'=>'s1.0.m1.f1', 'field_two'=>'s1.0.m1.f2')),
1 => array('ModelTwo' => array('id'=>1002, 'field_one'=>'s1.1.m2.f2', 'field_two'=>'s1.1.m2.f2')));
$array2 = array(
0 => array('ModelOne' => array('id'=>1001, 'field_one'=>'s2.0.m1.f1', 'field_two'=>'s2.0.m1.f2')),
1 => array('ModelTwo' => array('id'=>1002, 'field_one'=>'s2.1.m2.f2', 'field_two'=>'s2.1.m2.f2')));
$result = Set::pushDiff($array1, $array2);
$this->assertEquals($result, $array1);
$array3 = array(0 => array('ModelThree' => array('id'=>1003, 'field_one'=>'s3.0.m3.f1', 'field_two'=>'s3.0.m3.f2')));
$result = Set::pushDiff($array1, $array3);
$expected = array(
0 => array('ModelOne' => array('id'=>1001, 'field_one'=>'s1.0.m1.f1', 'field_two'=>'s1.0.m1.f2'),
'ModelThree' => array('id'=>1003, 'field_one'=>'s3.0.m3.f1', 'field_two'=>'s3.0.m3.f2')),
1 => array('ModelTwo' => array('id'=>1002, 'field_one'=>'s1.1.m2.f2', 'field_two'=>'s1.1.m2.f2')));
$this->assertEquals($expected, $result);
$result = Set::pushDiff($array1, null);
$this->assertEquals($result, $array1);
$result = Set::pushDiff($array1, $array2);
$this->assertEquals($result, $array1+$array2);
}
/**
* testSetApply method
* @return void
*
*/
public function testApply() {
$data = array(
array('Movie' => array('id' => 1, 'title' => 'movie 3', 'rating' => 5)),
array('Movie' => array('id' => 1, 'title' => 'movie 1', 'rating' => 1)),
array('Movie' => array('id' => 1, 'title' => 'movie 2', 'rating' => 3))
);
$result = Set::apply('/Movie/rating', $data, 'array_sum');
$expected = 9;
$this->assertEqual($expected, $result);
$result = Set::apply('/Movie/rating', $data, 'array_product');
$expected = 15;
$this->assertEqual($expected, $result);
$result = Set::apply('/Movie/title', $data, 'ucfirst', array('type' => 'map'));
$expected = array('Movie 3', 'Movie 1', 'Movie 2');
$this->assertEqual($expected, $result);
$result = Set::apply('/Movie/title', $data, 'strtoupper', array('type' => 'map'));
$expected = array('MOVIE 3', 'MOVIE 1', 'MOVIE 2');
$this->assertEqual($expected, $result);
$result = Set::apply('/Movie/rating', $data, array('SetTest', '_method'), array('type' => 'reduce'));
$expected = 9;
$this->assertEqual($expected, $result);
$result = Set::apply('/Movie/rating', $data, 'strtoupper', array('type' => 'non existing type'));
$expected = null;
$this->assertEqual($expected, $result);
}
/**
* Helper method to test Set::apply()
*
* @return void
*/
static function _method($val1, $val2) {
$val1 += $val2;
return $val1;
}
/**
* testXmlSetReverse method
*
* @return void
*/
public function testXmlSetReverse() {
App::uses('Xml', 'Utility');
$string = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<rss version="2.0">
<channel>
<title>Cake PHP Google Group</title>
<link>http://groups.google.com/group/cake-php</link>
<description>Search this group before posting anything. There are over 20,000 posts and it&#39;s very likely your question was answered before. Visit the IRC channel #cakephp at irc.freenode.net for live chat with users and developers of Cake. If you post, tell us the version of Cake, PHP, and database.</description>
<language>en</language>
<item>
<title>constructng result array when using findall</title>
<link>http://groups.google.com/group/cake-php/msg/49bc00f3bc651b4f</link>
<description>i'm using cakephp to construct a logical data model array that will be <br> passed to a flex app. I have the following model association: <br> ServiceDay-&gt;(hasMany)ServiceTi me-&gt;(hasMany)ServiceTimePrice. So what <br> the current output from my findall is something like this example: <br> <p>Array( <br> [0] =&gt; Array(</description>
<guid isPermaLink="true">http://groups.google.com/group/cake-php/msg/49bc00f3bc651b4f</guid>
<author>bmil...@gmail.com(bpscrugs)</author>
<pubDate>Fri, 28 Dec 2007 00:44:14 UT</pubDate>
</item>
<item>
<title>Re: share views between actions?</title>
<link>http://groups.google.com/group/cake-php/msg/8b350d898707dad8</link>
<description>Then perhaps you might do us all a favour and refrain from replying to <br> things you do not understand. That goes especially for asinine comments. <br> Indeed. <br> To sum up: <br> No comment. <br> In my day, a simple &quot;RTFM&quot; would suffice. I'll keep in mind to ignore any <br> further responses from you. <br> You (and I) were referring to the *online documentation*, not other</description>
<guid isPermaLink="true">http://groups.google.com/group/cake-php/msg/8b350d898707dad8</guid>
<author>subtropolis.z...@gmail.com(subtropolis zijn)</author>
<pubDate>Fri, 28 Dec 2007 00:45:01 UT</pubDate>
</item>
</channel>
</rss>';
$xml = Xml::build($string);
$result = Set::reverse($xml);
$expected = array('rss' => array(
'@version' => '2.0',
'channel' => array(
'title' => 'Cake PHP Google Group',
'link' => 'http://groups.google.com/group/cake-php',
'description' => 'Search this group before posting anything. There are over 20,000 posts and it's very likely your question was answered before. Visit the IRC channel #cakephp at irc.freenode.net for live chat with users and developers of Cake. If you post, tell us the version of Cake, PHP, and database.',
'language' => 'en',
'item' => array(
array(
'title' => 'constructng result array when using findall',
'link' => 'http://groups.google.com/group/cake-php/msg/49bc00f3bc651b4f',
'description' => "i'm using cakephp to construct a logical data model array that will be <br> passed to a flex app. I have the following model association: <br> ServiceDay->(hasMany)ServiceTi me->(hasMany)ServiceTimePrice. So what <br> the current output from my findall is something like this example: <br> <p>Array( <br> [0] => Array(",
'guid' => array('@isPermaLink' => 'true', '@' => 'http://groups.google.com/group/cake-php/msg/49bc00f3bc651b4f'),
'author' => 'bmil...@gmail.com(bpscrugs)',
'pubDate' => 'Fri, 28 Dec 2007 00:44:14 UT',
),
array(
'title' => 'Re: share views between actions?',
'link' => 'http://groups.google.com/group/cake-php/msg/8b350d898707dad8',
'description' => 'Then perhaps you might do us all a favour and refrain from replying to <br> things you do not understand. That goes especially for asinine comments. <br> Indeed. <br> To sum up: <br> No comment. <br> In my day, a simple "RTFM" would suffice. I\'ll keep in mind to ignore any <br> further responses from you. <br> You (and I) were referring to the *online documentation*, not other',
'guid' => array('@isPermaLink' => 'true', '@' => 'http://groups.google.com/group/cake-php/msg/8b350d898707dad8'),
'author' => 'subtropolis.z...@gmail.com(subtropolis zijn)',
'pubDate' => 'Fri, 28 Dec 2007 00:45:01 UT'
)
)
)
));
$this->assertEqual($expected, $result);
$string ='<data><post title="Title of this post" description="cool"/></data>';
$xml = Xml::build($string);
$result = Set::reverse($xml);
$expected = array('data' => array('post' => array('@title' => 'Title of this post', '@description' => 'cool')));
$this->assertEqual($expected, $result);
$xml = Xml::build('<example><item><title>An example of a correctly reversed SimpleXMLElement</title><desc/></item></example>');
$result = Set::reverse($xml);
$expected = array('example' =>
array(
'item' => array(
'title' => 'An example of a correctly reversed SimpleXMLElement',
'desc' => '',
)
)
);
$this->assertEquals($expected, $result);
$xml = Xml::build('<example><item attr="123"><titles><title>title1</title><title>title2</title></titles></item></example>');
$result = Set::reverse($xml);
$expected =
array('example' => array(
'item' => array(
'@attr' => '123',
'titles' => array(
'title' => array('title1', 'title2')
)
)
)
);
$this->assertEquals($expected, $result);
$xml = Xml::build('<example attr="ex_attr"><item attr="123"><titles>list</titles>textforitems</item></example>');
$result = Set::reverse($xml);
$expected =
array('example' => array(
'@attr' => 'ex_attr',
'item' => array(
'@attr' => '123',
'titles' => 'list',
'@' => 'textforitems'
)
)
);
$this->assertEquals($expected, $result);
$string = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<rss version="2.0" xmlns:dc="http://www.cakephp.org/">
<channel>
<title>Cake PHP Google Group</title>
<link>http://groups.google.com/group/cake-php</link>
<description>Search this group before posting anything. There are over 20,000 posts and it&#39;s very likely your question was answered before. Visit the IRC channel #cakephp at irc.freenode.net for live chat with users and developers of Cake. If you post, tell us the version of Cake, PHP, and database.</description>
<language>en</language>
<item>
<title>constructng result array when using findall</title>
<link>http://groups.google.com/group/cake-php/msg/49bc00f3bc651b4f</link>
<description>i'm using cakephp to construct a logical data model array that will be <br> passed to a flex app. I have the following model association: <br> ServiceDay-&gt;(hasMany)ServiceTi me-&gt;(hasMany)ServiceTimePrice. So what <br> the current output from my findall is something like this example: <br> <p>Array( <br> [0] =&gt; Array(</description>
<dc:creator>cakephp</dc:creator>
<category><![CDATA[cakephp]]></category>
<category><![CDATA[model]]></category>
<guid isPermaLink="true">http://groups.google.com/group/cake-php/msg/49bc00f3bc651b4f</guid>
<author>bmil...@gmail.com(bpscrugs)</author>
<pubDate>Fri, 28 Dec 2007 00:44:14 UT</pubDate>
</item>
<item>
<title>Re: share views between actions?</title>
<link>http://groups.google.com/group/cake-php/msg/8b350d898707dad8</link>
<description>Then perhaps you might do us all a favour and refrain from replying to <br> things you do not understand. That goes especially for asinine comments. <br> Indeed. <br> To sum up: <br> No comment. <br> In my day, a simple &quot;RTFM&quot; would suffice. I'll keep in mind to ignore any <br> further responses from you. <br> You (and I) were referring to the *online documentation*, not other</description>
<dc:creator>cakephp</dc:creator>
<category><![CDATA[cakephp]]></category>
<category><![CDATA[model]]></category>
<guid isPermaLink="true">http://groups.google.com/group/cake-php/msg/8b350d898707dad8</guid>
<author>subtropolis.z...@gmail.com(subtropolis zijn)</author>
<pubDate>Fri, 28 Dec 2007 00:45:01 UT</pubDate>
</item>
</channel>
</rss>';
$xml = Xml::build($string);
$result = Set::reverse($xml);
$expected = array('rss' => array(
'@version' => '2.0',
'channel' => array(
'title' => 'Cake PHP Google Group',
'link' => 'http://groups.google.com/group/cake-php',
'description' => 'Search this group before posting anything. There are over 20,000 posts and it's very likely your question was answered before. Visit the IRC channel #cakephp at irc.freenode.net for live chat with users and developers of Cake. If you post, tell us the version of Cake, PHP, and database.',
'language' => 'en',
'item' => array(
array(
'title' => 'constructng result array when using findall',
'link' => 'http://groups.google.com/group/cake-php/msg/49bc00f3bc651b4f',
'description' => "i'm using cakephp to construct a logical data model array that will be <br> passed to a flex app. I have the following model association: <br> ServiceDay->(hasMany)ServiceTi me->(hasMany)ServiceTimePrice. So what <br> the current output from my findall is something like this example: <br> <p>Array( <br> [0] => Array(",
'dc:creator' => 'cakephp',
'category' => array('cakephp', 'model'),
'guid' => array('@isPermaLink' => 'true', '@' => 'http://groups.google.com/group/cake-php/msg/49bc00f3bc651b4f'),
'author' => 'bmil...@gmail.com(bpscrugs)',
'pubDate' => 'Fri, 28 Dec 2007 00:44:14 UT',
),
array(
'title' => 'Re: share views between actions?',
'link' => 'http://groups.google.com/group/cake-php/msg/8b350d898707dad8',
'description' => 'Then perhaps you might do us all a favour and refrain from replying to <br> things you do not understand. That goes especially for asinine comments. <br> Indeed. <br> To sum up: <br> No comment. <br> In my day, a simple "RTFM" would suffice. I\'ll keep in mind to ignore any <br> further responses from you. <br> You (and I) were referring to the *online documentation*, not other',
'dc:creator' => 'cakephp',
'category' => array('cakephp', 'model'),
'guid' => array('@isPermaLink' => 'true', '@' => 'http://groups.google.com/group/cake-php/msg/8b350d898707dad8'),
'author' => 'subtropolis.z...@gmail.com(subtropolis zijn)',
'pubDate' => 'Fri, 28 Dec 2007 00:45:01 UT'
)
)
)
));
$this->assertEqual($expected, $result);
$text = '<?xml version="1.0" encoding="UTF-8"?>
<XRDS xmlns="xri://$xrds">
<XRD xml:id="oauth" xmlns="xri://$XRD*($v*2.0)" version="2.0">
<Type>xri://$xrds*simple</Type>
<Expires>2008-04-13T07:34:58Z</Expires>
<Service>
<Type>http://oauth.net/core/1.0/endpoint/authorize</Type>
<Type>http://oauth.net/core/1.0/parameters/auth-header</Type>
<Type>http://oauth.net/core/1.0/parameters/uri-query</Type>
<URI priority="10">https://ma.gnolia.com/oauth/authorize</URI>
<URI priority="20">http://ma.gnolia.com/oauth/authorize</URI>
</Service>
</XRD>
<XRD xmlns="xri://$XRD*($v*2.0)" version="2.0">
<Type>xri://$xrds*simple</Type>
<Service priority="10">
<Type>http://oauth.net/discovery/1.0</Type>
<URI>#oauth</URI>
</Service>
</XRD>
</XRDS>';
$xml = Xml::build($text);
$result = Set::reverse($xml);
$expected = array('XRDS' => array(
'XRD' => array(
array(
'@xml:id' => 'oauth',
'@version' => '2.0',
'Type' => 'xri://$xrds*simple',
'Expires' => '2008-04-13T07:34:58Z',
'Service' => array(
'Type' => array(
'http://oauth.net/core/1.0/endpoint/authorize',
'http://oauth.net/core/1.0/parameters/auth-header',
'http://oauth.net/core/1.0/parameters/uri-query'
),
'URI' => array(
array(
'@' => 'https://ma.gnolia.com/oauth/authorize',
'@priority' => '10',
),
array(
'@' => 'http://ma.gnolia.com/oauth/authorize',
'@priority' => '20'
)
)
)
),
array(
'@version' => '2.0',
'Type' => 'xri://$xrds*simple',
'Service' => array(
'@priority' => '10',
'Type' => 'http://oauth.net/discovery/1.0',
'URI' => '#oauth'
)
)
)
));
$this->assertEqual($expected, $result);
}
/**
* testStrictKeyCheck method
*
* @return void
*/
public function testStrictKeyCheck() {
$set = array('a' => 'hi');
$this->assertFalse(Set::check($set, 'a.b'));
}
/**
* Tests Set::flatten
*
* @return void
*/
public function testFlatten() {
$data = array('Larry', 'Curly', 'Moe');
$result = Set::flatten($data);
$this->assertEqual($result, $data);
$data[9] = 'Shemp';
$result = Set::flatten($data);
$this->assertEqual($result, $data);
$data = array(
array(
'Post' => array('id' => '1', 'author_id' => '1', 'title' => 'First Post'),
'Author' => array('id' => '1', 'user' => 'nate', 'password' => 'foo'),
),
array(
'Post' => array('id' => '2', 'author_id' => '3', 'title' => 'Second Post', 'body' => 'Second Post Body'),
'Author' => array('id' => '3', 'user' => 'larry', 'password' => null),
)
);
$result = Set::flatten($data);
$expected = array(
'0.Post.id' => '1', '0.Post.author_id' => '1', '0.Post.title' => 'First Post', '0.Author.id' => '1',
'0.Author.user' => 'nate', '0.Author.password' => 'foo', '1.Post.id' => '2', '1.Post.author_id' => '3',
'1.Post.title' => 'Second Post', '1.Post.body' => 'Second Post Body', '1.Author.id' => '3',
'1.Author.user' => 'larry', '1.Author.password' => null
);
$this->assertEqual($expected, $result);
}
/**
* test normalization
*
* @return void
*/
public function testNormalizeStrings() {
$result = Set::normalize('one,two,three');
$expected = array('one' => null, 'two' => null, 'three' => null);
$this->assertEqual($expected, $result);
$result = Set::normalize('one two three', true, ' ');
$expected = array('one' => null, 'two' => null, 'three' => null);
$this->assertEqual($expected, $result);
$result = Set::normalize('one , two , three ', true, ',', true);
$expected = array('one' => null, 'two' => null, 'three' => null);
$this->assertEqual($expected, $result);
}
/**
* test normalizing arrays
*
* @return void
*/
public function testNormalizeArrays() {
$result = Set::normalize(array('one', 'two', 'three'));
$expected = array('one' => null, 'two' => null, 'three' => null);
$this->assertEqual($expected, $result);
$result = Set::normalize(array('one', 'two', 'three'), false);
$expected = array('one', 'two', 'three');
$this->assertEqual($expected, $result);
$result = Set::normalize(array('one' => 1, 'two' => 2, 'three' => 3, 'four'), false);
$expected = array('one' => 1, 'two' => 2, 'three' => 3, 'four' => null);
$this->assertEqual($expected, $result);
$result = Set::normalize(array('one' => 1, 'two' => 2, 'three' => 3, 'four'));
$expected = array('one' => 1, 'two' => 2, 'three' => 3, 'four' => null);
$this->assertEqual($expected, $result);
$result = Set::normalize(array('one' => array('a', 'b', 'c' => 'cee'), 'two' => 2, 'three'));
$expected = array('one' => array('a', 'b', 'c' => 'cee'), 'two' => 2, 'three' => null);
$this->assertEqual($expected, $result);
}
}
| 0001-bee | trunk/cakephp2/lib/Cake/Test/Case/Utility/SetTest.php | PHP | gpl3 | 106,873 |
<?php
/**
* SanitizeTest file
*
* PHP 5
*
* CakePHP(tm) Tests <http://book.cakephp.org/view/1196/Testing>
* Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice
*
* @copyright Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://book.cakephp.org/view/1196/Testing CakePHP(tm) Tests
* @package Cake.Test.Case.Utility
* @since CakePHP(tm) v 1.2.0.5428
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
App::uses('Sanitize', 'Utility');
/**
* DataTest class
*
* @package Cake.Test.Case.Utility
*/
class SanitizeDataTest extends CakeTestModel {
/**
* name property
*
* @var string 'SanitizeDataTest'
*/
public $name = 'SanitizeDataTest';
/**
* useTable property
*
* @var string 'data_tests'
*/
public $useTable = 'data_tests';
}
/**
* Article class
*
* @package Cake.Test.Case.Utility
*/
class SanitizeArticle extends CakeTestModel {
/**
* name property
*
* @var string 'Article'
*/
public $name = 'SanitizeArticle';
/**
* useTable property
*
* @var string 'articles'
*/
public $useTable = 'articles';
}
/**
* SanitizeTest class
*
* @package Cake.Test.Case.Utility
*/
class SanitizeTest extends CakeTestCase {
/**
* autoFixtures property
*
* @var bool false
*/
public $autoFixtures = false;
/**
* fixtures property
*
* @var array
*/
public $fixtures = array('core.data_test', 'core.article');
/**
* testEscapeAlphaNumeric method
*
* @return void
*/
public function testEscapeAlphaNumeric() {
$resultAlpha = Sanitize::escape('abc', 'test');
$this->assertEqual($resultAlpha, 'abc');
$resultNumeric = Sanitize::escape('123', 'test');
$this->assertEqual($resultNumeric, '123');
$resultNumeric = Sanitize::escape(1234, 'test');
$this->assertEqual($resultNumeric, 1234);
$resultNumeric = Sanitize::escape(1234.23, 'test');
$this->assertEqual($resultNumeric, 1234.23);
$resultNumeric = Sanitize::escape('#1234.23', 'test');
$this->assertEqual($resultNumeric, '#1234.23');
$resultNull = Sanitize::escape(null, 'test');
$this->assertEqual($resultNull, null);
$resultNull = Sanitize::escape(false, 'test');
$this->assertEqual($resultNull, false);
$resultNull = Sanitize::escape(true, 'test');
$this->assertEqual($resultNull, true);
}
/**
* testClean method
*
* @return void
*/
public function testClean() {
$string = 'test & "quote" \'other\' ;.$ symbol.' . "\r" . 'another line';
$expected = 'test & "quote" 'other' ;.$ symbol.another line';
$result = Sanitize::clean($string, array('connection' => 'test'));
$this->assertEqual($expected, $result);
$string = 'test & "quote" \'other\' ;.$ symbol.' . "\r" . 'another line';
$expected = 'test & ' . Sanitize::escape('"quote"', 'test') . ' ' . Sanitize::escape('\'other\'', 'test') . ' ;.$ symbol.another line';
$result = Sanitize::clean($string, array('encode' => false, 'connection' => 'test'));
$this->assertEqual($expected, $result);
$string = 'test & "quote" \'other\' ;.$ \\$ symbol.' . "\r" . 'another line';
$expected = 'test & "quote" \'other\' ;.$ $ symbol.another line';
$result = Sanitize::clean($string, array('encode' => false, 'escape' => false, 'connection' => 'test'));
$this->assertEqual($expected, $result);
$string = 'test & "quote" \'other\' ;.$ \\$ symbol.' . "\r" . 'another line';
$expected = 'test & "quote" \'other\' ;.$ \\$ symbol.another line';
$result = Sanitize::clean($string, array('encode' => false, 'escape' => false, 'dollar' => false, 'connection' => 'test'));
$this->assertEqual($expected, $result);
$string = 'test & "quote" \'other\' ;.$ symbol.' . "\r" . 'another line';
$expected = 'test & "quote" \'other\' ;.$ symbol.' . "\r" . 'another line';
$result = Sanitize::clean($string, array('encode' => false, 'escape' => false, 'carriage' => false, 'connection' => 'test'));
$this->assertEqual($expected, $result);
$array = array(array('test & "quote" \'other\' ;.$ symbol.' . "\r" . 'another line'));
$expected = array(array('test & "quote" 'other' ;.$ symbol.another line'));
$result = Sanitize::clean($array, array('connection' => 'test'));
$this->assertEqual($expected, $result);
$array = array(array('test & "quote" \'other\' ;.$ \\$ symbol.' . "\r" . 'another line'));
$expected = array(array('test & "quote" \'other\' ;.$ $ symbol.another line'));
$result = Sanitize::clean($array, array('encode' => false, 'escape' => false, 'connection' => 'test'));
$this->assertEqual($expected, $result);
$array = array(array('test odd Ä spacesé'));
$expected = array(array('test odd Ä spacesé'));
$result = Sanitize::clean($array, array('odd_spaces' => false, 'escape' => false, 'connection' => 'test'));
$this->assertEqual($expected, $result);
$array = array(array('\\$', array('key' => 'test & "quote" \'other\' ;.$ \\$ symbol.' . "\r" . 'another line')));
$expected = array(array('$', array('key' => 'test & "quote" \'other\' ;.$ $ symbol.another line')));
$result = Sanitize::clean($array, array('encode' => false, 'escape' => false, 'connection' => 'test'));
$this->assertEqual($expected, $result);
$string = '';
$expected = '';
$result = Sanitize::clean($string, array('connection' => 'test'));
$this->assertEqual($string, $expected);
$data = array(
'Grant' => array(
'title' => '2 o clock grant',
'grant_peer_review_id' => 3,
'institution_id' => 5,
'created_by' => 1,
'modified_by' => 1,
'created' => '2010-07-15 14:11:00',
'modified' => '2010-07-19 10:45:41'
),
'GrantsMember' => array(
0 => array(
'id' => 68,
'grant_id' => 120,
'member_id' => 16,
'program_id' => 29,
'pi_percent_commitment' => 1
)
)
);
$result = Sanitize::clean($data, array('connection' => 'test'));
$this->assertEqual($result, $data);
}
/**
* testHtml method
*
* @return void
*/
public function testHtml() {
$string = '<p>This is a <em>test string</em> & so is this</p>';
$expected = 'This is a test string & so is this';
$result = Sanitize::html($string, array('remove' => true));
$this->assertEqual($expected, $result);
$string = 'The "lazy" dog \'jumped\' & flew over the moon. If (1+1) = 2 <em>is</em> true, (2-1) = 1 is also true';
$expected = 'The "lazy" dog 'jumped' & flew over the moon. If (1+1) = 2 <em>is</em> true, (2-1) = 1 is also true';
$result = Sanitize::html($string);
$this->assertEqual($expected, $result);
$string = 'The "lazy" dog \'jumped\'';
$expected = 'The "lazy" dog \'jumped\'';
$result = Sanitize::html($string, array('quotes' => ENT_COMPAT));
$this->assertEqual($expected, $result);
$string = 'The "lazy" dog \'jumped\'';
$result = Sanitize::html($string, array('quotes' => ENT_NOQUOTES));
$this->assertEqual($result, $string);
$string = 'The "lazy" dog \'jumped\' & flew over the moon. If (1+1) = 2 <em>is</em> true, (2-1) = 1 is also true';
$expected = 'The "lazy" dog 'jumped' & flew over the moon. If (1+1) = 2 <em>is</em> true, (2-1) = 1 is also true';
$result = Sanitize::html($string);
$this->assertEqual($expected, $result);
$string = 'The "lazy" dog & his friend Apple® conquered the world';
$expected = 'The "lazy" dog & his friend Apple&reg; conquered the world';
$result = Sanitize::html($string);
$this->assertEqual($expected, $result);
$string = 'The "lazy" dog & his friend Apple® conquered the world';
$expected = 'The "lazy" dog & his friend Apple® conquered the world';
$result = Sanitize::html($string, array('double' => false));
$this->assertEqual($expected, $result);
}
/**
* testStripWhitespace method
*
* @return void
*/
public function testStripWhitespace() {
$string = "This sentence \t\t\t has lots of \n\n white\nspace \rthat \r\n needs to be \t \n trimmed.";
$expected = "This sentence has lots of whitespace that needs to be trimmed.";
$result = Sanitize::stripWhitespace($string);
$this->assertEquals($expected, $result);
$text = 'I love ßá†ö√ letters.';
$result = Sanitize::stripWhitespace($text);
$expected = 'I love ßá†ö√ letters.';
$this->assertEqual($result, $expected);
}
/**
* testParanoid method
*
* @return void
*/
public function testParanoid() {
$string = 'I would like to !%@#% & dance & sing ^$&*()-+';
$expected = 'Iwouldliketodancesing';
$result = Sanitize::paranoid($string);
$this->assertEqual($expected, $result);
$string = array('This |s th% s0ng that never ends it g*es',
'on and on my friends, b^ca#use it is the',
'so&g th===t never ends.');
$expected = array('This s th% s0ng that never ends it g*es',
'on and on my friends bcause it is the',
'sog tht never ends.');
$result = Sanitize::paranoid($string, array('%', '*', '.', ' '));
$this->assertEqual($expected, $result);
$string = "anything' OR 1 = 1";
$expected = 'anythingOR11';
$result = Sanitize::paranoid($string);
$this->assertEqual($expected, $result);
$string = "x' AND email IS NULL; --";
$expected = 'xANDemailISNULL';
$result = Sanitize::paranoid($string);
$this->assertEqual($expected, $result);
$string = "x' AND 1=(SELECT COUNT(*) FROM users); --";
$expected = "xAND1SELECTCOUNTFROMusers";
$result = Sanitize::paranoid($string);
$this->assertEqual($expected, $result);
$string = "x'; DROP TABLE members; --";
$expected = "xDROPTABLEmembers";
$result = Sanitize::paranoid($string);
$this->assertEqual($expected, $result);
}
/**
* testStripImages method
*
* @return void
*/
public function testStripImages() {
$string = '<img src="/img/test.jpg" alt="my image" />';
$expected = 'my image<br />';
$result = Sanitize::stripImages($string);
$this->assertEqual($expected, $result);
$string = '<img src="javascript:alert(\'XSS\');" />';
$expected = '';
$result = Sanitize::stripImages($string);
$this->assertEqual($expected, $result);
$string = '<a href="http://www.badsite.com/phising"><img src="/img/test.jpg" alt="test image alt" title="test image title" id="myImage" class="image-left"/></a>';
$expected = '<a href="http://www.badsite.com/phising">test image alt</a><br />';
$result = Sanitize::stripImages($string);
$this->assertEqual($expected, $result);
$string = '<a onclick="medium()" href="http://example.com"><img src="foobar.png" onclick="evilFunction(); return false;"/></a>';
$expected = '<a onclick="medium()" href="http://example.com"></a>';
$result = Sanitize::stripImages($string);
$this->assertEqual($expected, $result);
}
/**
* testStripScripts method
*
* @return void
*/
public function testStripScripts() {
$string = '<link href="/css/styles.css" media="screen" rel="stylesheet" />';
$expected = '';
$result = Sanitize::stripScripts($string);
$this->assertEqual($expected, $result);
$string = '<link href="/css/styles.css" media="screen" rel="stylesheet" />' . "\n" . '<link rel="icon" href="/favicon.ico" type="image/x-icon" />' . "\n" . '<link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" />' . "\n" . '<link rel="alternate" href="/feed.xml" title="RSS Feed" type="application/rss+xml" />';
$expected = "\n" . '<link rel="icon" href="/favicon.ico" type="image/x-icon" />' . "\n" . '<link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" />'."\n".'<link rel="alternate" href="/feed.xml" title="RSS Feed" type="application/rss+xml" />';
$result = Sanitize::stripScripts($string);
$this->assertEqual($expected, $result);
$string = '<script type="text/javascript"> alert("hacked!");</script>';
$expected = '';
$result = Sanitize::stripScripts($string);
$this->assertEqual($expected, $result);
$string = '<script> alert("hacked!");</script>';
$expected = '';
$result = Sanitize::stripScripts($string);
$this->assertEqual($expected, $result);
$string = '<style>#content { display:none; }</style>';
$expected = '';
$result = Sanitize::stripScripts($string);
$this->assertEqual($expected, $result);
$string = '<style type="text/css"><!-- #content { display:none; } --></style>';
$expected = '';
$result = Sanitize::stripScripts($string);
$this->assertEqual($expected, $result);
$string = <<<HTML
text
<style type="text/css">
<!--
#content { display:none; }
-->
</style>
text
HTML;
$expected = "text\n\ntext";
$result = Sanitize::stripScripts($string);
$this->assertEqual($expected, $result);
$string = <<<HTML
text
<script type="text/javascript">
<!--
alert('wooo');
-->
</script>
text
HTML;
$expected = "text\n\ntext";
$result = Sanitize::stripScripts($string);
$this->assertEqual($expected, $result);
}
/**
* testStripAll method
*
* @return void
*/
public function testStripAll() {
$string = '<img """><script>alert("xss")</script>"/>';
$expected ='"/>';
$result = Sanitize::stripAll($string);
$this->assertEqual($expected, $result);
$string = '<IMG SRC=javascript:alert('XSS')>';
$expected = '';
$result = Sanitize::stripAll($string);
$this->assertEqual($expected, $result);
$string = '<<script>alert("XSS");//<</script>';
$expected = '<';
$result = Sanitize::stripAll($string);
$this->assertEqual($expected, $result);
$string = '<img src="http://google.com/images/logo.gif" onload="window.location=\'http://sam.com/\'" />'."\n".
"<p>This is ok \t\n text</p>\n".
'<link rel="stylesheet" href="/css/master.css" type="text/css" media="screen" title="my sheet" charset="utf-8">'."\n".
'<script src="xss.js" type="text/javascript" charset="utf-8"></script>';
$expected = '<p>This is ok text</p>';
$result = Sanitize::stripAll($string);
$this->assertEqual($expected, $result);
}
/**
* testStripTags method
*
* @return void
*/
public function testStripTags() {
$string = '<h2>Headline</h2><p><a href="http://example.com">My Link</a> could go to a bad site</p>';
$expected = 'Headline<p>My Link could go to a bad site</p>';
$result = Sanitize::stripTags($string, 'h2', 'a');
$this->assertEqual($expected, $result);
$string = '<script type="text/javascript" src="http://evildomain.com"> </script>';
$expected = ' ';
$result = Sanitize::stripTags($string, 'script');
$this->assertEqual($expected, $result);
$string = '<h2>Important</h2><p>Additional information here <a href="/about"><img src="/img/test.png" /></a>. Read even more here</p>';
$expected = 'Important<p>Additional information here <img src="/img/test.png" />. Read even more here</p>';
$result = Sanitize::stripTags($string, 'h2', 'a');
$this->assertEqual($expected, $result);
$string = '<h2>Important</h2><p>Additional information here <a href="/about"><img src="/img/test.png" /></a>. Read even more here</p>';
$expected = 'Important<p>Additional information here . Read even more here</p>';
$result = Sanitize::stripTags($string, 'h2', 'a', 'img');
$this->assertEqual($expected, $result);
$string = '<b>Important message!</b><br>This message will self destruct!';
$expected = 'Important message!<br>This message will self destruct!';
$result = Sanitize::stripTags($string, 'b');
$this->assertEqual($expected, $result);
$string = '<b>Important message!</b><br />This message will self destruct!';
$expected = 'Important message!<br />This message will self destruct!';
$result = Sanitize::stripTags($string, 'b');
$this->assertEqual($expected, $result);
$string = '<h2 onclick="alert(\'evil\'); onmouseover="badness()">Important</h2><p>Additional information here <a href="/about"><img src="/img/test.png" /></a>. Read even more here</p>';
$expected = 'Important<p>Additional information here . Read even more here</p>';
$result = Sanitize::stripTags($string, 'h2', 'a', 'img');
$this->assertEqual($expected, $result);
}
}
| 0001-bee | trunk/cakephp2/lib/Cake/Test/Case/Utility/SanitizeTest.php | PHP | gpl3 | 16,291 |
<?php
/**
* SecurityTest file
*
* PHP 5
*
* CakePHP(tm) Tests <http://book.cakephp.org/view/1196/Testing>
* Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice
*
* @copyright Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://book.cakephp.org/view/1196/Testing CakePHP(tm) Tests
* @package Cake.Test.Case.Utility
* @since CakePHP(tm) v 1.2.0.5432
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
App::uses('Security', 'Utility');
/**
* SecurityTest class
*
* @package Cake.Test.Case.Utility
*/
class SecurityTest extends CakeTestCase {
/**
* sut property
*
* @var mixed null
*/
public $sut = null;
/**
* testInactiveMins method
*
* @return void
*/
public function testInactiveMins() {
Configure::write('Security.level', 'high');
$this->assertEqual(10, Security::inactiveMins());
Configure::write('Security.level', 'medium');
$this->assertEqual(100, Security::inactiveMins());
Configure::write('Security.level', 'low');
$this->assertEqual(300, Security::inactiveMins());
}
/**
* testGenerateAuthkey method
*
* @return void
*/
public function testGenerateAuthkey() {
$this->assertEqual(strlen(Security::generateAuthKey()), 40);
}
/**
* testValidateAuthKey method
*
* @return void
*/
public function testValidateAuthKey() {
$authKey = Security::generateAuthKey();
$this->assertTrue(Security::validateAuthKey($authKey));
}
/**
* testHash method
*
* @return void
*/
public function testHash() {
$_hashType = Security::$hashType;
$key = 'someKey';
$hash = 'someHash';
$this->assertIdentical(strlen(Security::hash($key, null, false)), 40);
$this->assertIdentical(strlen(Security::hash($key, 'sha1', false)), 40);
$this->assertIdentical(strlen(Security::hash($key, null, true)), 40);
$this->assertIdentical(strlen(Security::hash($key, 'sha1', true)), 40);
$result = Security::hash($key, null, $hash);
$this->assertIdentical($result, 'e38fcb877dccb6a94729a81523851c931a46efb1');
$result = Security::hash($key, 'sha1', $hash);
$this->assertIdentical($result, 'e38fcb877dccb6a94729a81523851c931a46efb1');
$hashType = 'sha1';
Security::setHash($hashType);
$this->assertIdentical(Security::$hashType, $hashType);
$this->assertIdentical(strlen(Security::hash($key, null, true)), 40);
$this->assertIdentical(strlen(Security::hash($key, null, false)), 40);
$this->assertIdentical(strlen(Security::hash($key, 'md5', false)), 32);
$this->assertIdentical(strlen(Security::hash($key, 'md5', true)), 32);
$hashType = 'md5';
Security::setHash($hashType);
$this->assertIdentical(Security::$hashType, $hashType);
$this->assertIdentical(strlen(Security::hash($key, null, false)), 32);
$this->assertIdentical(strlen(Security::hash($key, null, true)), 32);
if (!function_exists('hash') && !function_exists('mhash')) {
$this->assertIdentical(strlen(Security::hash($key, 'sha256', false)), 32);
$this->assertIdentical(strlen(Security::hash($key, 'sha256', true)), 32);
} else {
$this->assertIdentical(strlen(Security::hash($key, 'sha256', false)), 64);
$this->assertIdentical(strlen(Security::hash($key, 'sha256', true)), 64);
}
Security::setHash($_hashType);
}
/**
* testCipher method
*
* @return void
*/
public function testCipher() {
$length = 10;
$txt = '';
for ($i = 0; $i < $length; $i++) {
$txt .= mt_rand(0, 255);
}
$key = 'my_key';
$result = Security::cipher($txt, $key);
$this->assertEqual(Security::cipher($result, $key), $txt);
$txt = '';
$key = 'my_key';
$result = Security::cipher($txt, $key);
$this->assertEqual(Security::cipher($result, $key), $txt);
$txt = 123456;
$key = 'my_key';
$result = Security::cipher($txt, $key);
$this->assertEqual(Security::cipher($result, $key), $txt);
$txt = '123456';
$key = 'my_key';
$result = Security::cipher($txt, $key);
$this->assertEqual(Security::cipher($result, $key), $txt);
}
/**
* testCipherEmptyKey method
*
* @expectedException PHPUnit_Framework_Error
* @return void
*/
public function testCipherEmptyKey() {
$txt = 'some_text';
$key = '';
$result = Security::cipher($txt, $key);
}
}
| 0001-bee | trunk/cakephp2/lib/Cake/Test/Case/Utility/SecurityTest.php | PHP | gpl3 | 4,374 |
<?php
/**
* ClassRegistryTest file
*
* PHP 5
*
* CakePHP(tm) Tests <http://book.cakephp.org/view/1196/Testing>
* Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice
*
* @copyright Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://book.cakephp.org/view/1196/Testing CakePHP(tm) Tests
* @package Cake.Test.Case.Utility
* @since CakePHP(tm) v 1.2.0.5432
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
App::uses('ClassRegistry', 'Utility');
/**
* ClassRegisterModel class
*
* @package Cake.Test.Case.Utility
*/
class ClassRegisterModel extends CakeTestModel {
/**
* useTable property
*
* @var bool false
*/
public $useTable = false;
}
/**
* RegisterArticle class
*
* @package Cake.Test.Case.Utility
*/
class RegisterArticle extends ClassRegisterModel {
/**
* name property
*
* @var string 'RegisterArticle'
*/
public $name = 'RegisterArticle';
}
/**
* RegisterArticleFeatured class
*
* @package Cake.Test.Case.Utility
*/
class RegisterArticleFeatured extends ClassRegisterModel {
/**
* name property
*
* @var string 'RegisterArticleFeatured'
*/
public $name = 'RegisterArticleFeatured';
}
/**
* RegisterArticleTag class
*
* @package Cake.Test.Case.Utility
*/
class RegisterArticleTag extends ClassRegisterModel {
/**
* name property
*
* @var string 'RegisterArticleTag'
*/
public $name = 'RegisterArticleTag';
}
/**
* RegistryPluginAppModel class
*
* @package Cake.Test.Case.Utility
*/
class RegistryPluginAppModel extends ClassRegisterModel {
/**
* tablePrefix property
*
* @var string 'something_'
*/
public $tablePrefix = 'something_';
}
/**
* TestRegistryPluginModel class
*
* @package Cake.Test.Case.Utility
*/
class TestRegistryPluginModel extends RegistryPluginAppModel {
/**
* name property
*
* @var string 'TestRegistryPluginModel'
*/
public $name = 'TestRegistryPluginModel';
}
/**
* RegisterCategory class
*
* @package Cake.Test.Case.Utility
*/
class RegisterCategory extends ClassRegisterModel {
/**
* name property
*
* @var string 'RegisterCategory'
*/
public $name = 'RegisterCategory';
}
/**
* ClassRegistryTest class
*
* @package Cake.Test.Case.Utility
*/
class ClassRegistryTest extends CakeTestCase {
/**
* testAddModel method
*
* @return void
*/
public function testAddModel() {
$Tag = ClassRegistry::init('RegisterArticleTag');
$this->assertTrue(is_a($Tag, 'RegisterArticleTag'));
$TagCopy = ClassRegistry::isKeySet('RegisterArticleTag');
$this->assertTrue($TagCopy);
$Tag->name = 'SomeNewName';
$TagCopy = ClassRegistry::getObject('RegisterArticleTag');
$this->assertTrue(is_a($TagCopy, 'RegisterArticleTag'));
$this->assertSame($Tag, $TagCopy);
$NewTag = ClassRegistry::init(array('class' => 'RegisterArticleTag', 'alias' => 'NewTag'));
$this->assertTrue(is_a($Tag, 'RegisterArticleTag'));
$NewTagCopy = ClassRegistry::init(array('class' => 'RegisterArticleTag', 'alias' => 'NewTag'));
$this->assertNotSame($Tag, $NewTag);
$this->assertSame($NewTag, $NewTagCopy);
$NewTag->name = 'SomeOtherName';
$this->assertNotSame($Tag, $NewTag);
$this->assertSame($NewTag, $NewTagCopy);
$Tag->name = 'SomeOtherName';
$this->assertNotSame($Tag, $NewTag);
$this->assertTrue($TagCopy->name === 'SomeOtherName');
$User = ClassRegistry::init(array('class' => 'RegisterUser', 'alias' => 'User', 'table' => false));
$this->assertTrue(is_a($User, 'AppModel'));
$UserCopy = ClassRegistry::init(array('class' => 'RegisterUser', 'alias' => 'User', 'table' => false));
$this->assertTrue(is_a($UserCopy, 'AppModel'));
$this->assertEquals($User, $UserCopy);
$Category = ClassRegistry::init(array('class' => 'RegisterCategory'));
$this->assertTrue(is_a($Category, 'RegisterCategory'));
$ParentCategory = ClassRegistry::init(array('class' => 'RegisterCategory', 'alias' => 'ParentCategory'));
$this->assertTrue(is_a($ParentCategory, 'RegisterCategory'));
$this->assertNotSame($Category, $ParentCategory);
$this->assertNotEqual($Category->alias, $ParentCategory->alias);
$this->assertEqual('RegisterCategory', $Category->alias);
$this->assertEqual('ParentCategory', $ParentCategory->alias);
}
/**
* testClassRegistryFlush method
*
* @return void
*/
public function testClassRegistryFlush() {
$Tag = ClassRegistry::init('RegisterArticleTag');
$ArticleTag = ClassRegistry::getObject('RegisterArticleTag');
$this->assertTrue(is_a($ArticleTag, 'RegisterArticleTag'));
ClassRegistry::flush();
$NoArticleTag = ClassRegistry::isKeySet('RegisterArticleTag');
$this->assertFalse($NoArticleTag);
$this->assertTrue(is_a($ArticleTag, 'RegisterArticleTag'));
}
/**
* testAddMultipleModels method
*
* @return void
*/
public function testAddMultipleModels() {
$Article = ClassRegistry::isKeySet('Article');
$this->assertFalse($Article);
$Featured = ClassRegistry::isKeySet('Featured');
$this->assertFalse($Featured);
$Tag = ClassRegistry::isKeySet('Tag');
$this->assertFalse($Tag);
$models = array(array('class' => 'RegisterArticle', 'alias' => 'Article'),
array('class' => 'RegisterArticleFeatured', 'alias' => 'Featured'),
array('class' => 'RegisterArticleTag', 'alias' => 'Tag'));
$added = ClassRegistry::init($models);
$this->assertTrue($added);
$Article = ClassRegistry::isKeySet('Article');
$this->assertTrue($Article);
$Featured = ClassRegistry::isKeySet('Featured');
$this->assertTrue($Featured);
$Tag = ClassRegistry::isKeySet('Tag');
$this->assertTrue($Tag);
$Article = ClassRegistry::getObject('Article');
$this->assertTrue(is_a($Article, 'RegisterArticle'));
$Featured = ClassRegistry::getObject('Featured');
$this->assertTrue(is_a($Featured, 'RegisterArticleFeatured'));
$Tag = ClassRegistry::getObject('Tag');
$this->assertTrue(is_a($Tag, 'RegisterArticleTag'));
}
/**
* testPluginAppModel method
*
* @return void
*/
public function testPluginAppModel() {
$TestRegistryPluginModel = ClassRegistry::isKeySet('TestRegistryPluginModel');
$this->assertFalse($TestRegistryPluginModel);
//Faking a plugin
CakePlugin::load('RegistryPlugin', array('path' => '/fake/path'));
$TestRegistryPluginModel = ClassRegistry::init('RegistryPlugin.TestRegistryPluginModel');
$this->assertTrue(is_a($TestRegistryPluginModel, 'TestRegistryPluginModel'));
$this->assertEqual($TestRegistryPluginModel->tablePrefix, 'something_');
$PluginUser = ClassRegistry::init(array('class' => 'RegistryPlugin.RegisterUser', 'alias' => 'RegistryPluginUser', 'table' => false));
$this->assertTrue(is_a($PluginUser, 'RegistryPluginAppModel'));
$PluginUserCopy = ClassRegistry::getObject('RegistryPluginUser');
$this->assertTrue(is_a($PluginUserCopy, 'RegistryPluginAppModel'));
$this->assertSame($PluginUser, $PluginUserCopy);
CakePlugin::unload();
}
/**
* Tests that passing the string parameter to init() will return false if the model does not exists
*
*/
public function testInitStrict() {
$this->assertFalse(ClassRegistry::init('NonExistent', true));
}
}
| 0001-bee | trunk/cakephp2/lib/Cake/Test/Case/Utility/ClassRegistryTest.php | PHP | gpl3 | 7,318 |
<?php
/**
* AllControllersTest file
*
* PHP 5
*
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
* Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://cakephp.org CakePHP(tm) Project
* @package Cake.Test.Case
* @since CakePHP(tm) v 2.0
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
/**
* AllControllersTest class
*
* This test group will run Controller related tests.
*
* @package Cake.Test.Case
*/
class AllControllersTest extends PHPUnit_Framework_TestSuite {
/**
* suite method, defines tests for this suite.
*
* @return void
*/
public static function suite() {
$suite = new CakeTestSuite('All Controller related class tests');
$suite->addTestFile(CORE_TEST_CASES . DS . 'Controller' . DS . 'ControllerTest.php');
$suite->addTestFile(CORE_TEST_CASES . DS . 'Controller' . DS . 'ScaffoldTest.php');
$suite->addTestFile(CORE_TEST_CASES . DS . 'Controller' . DS . 'PagesControllerTest.php');
$suite->addTestFile(CORE_TEST_CASES . DS . 'Controller' . DS . 'ComponentTest.php');
$suite->addTestFile(CORE_TEST_CASES . DS . 'Controller' . DS . 'ControllerMergeVarsTest.php');
return $suite;
}
} | 0001-bee | trunk/cakephp2/lib/Cake/Test/Case/AllControllerTest.php | PHP | gpl3 | 1,463 |
<?php
/**
* AllBehaviorsTest file
*
* PHP 5
*
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
* Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://cakephp.org CakePHP(tm) Project
* @package Cake.Test.Case
* @since CakePHP(tm) v 2.0
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
/**
* AllBehaviorsTest class
*
* This test group will run all test in the Case/Model/Behavior directory
*
* @package Cake.Test.Case
*/
class AllBehaviorsTest extends PHPUnit_Framework_TestSuite {
/**
* Suite define the tests for this suite
*
* @return void
*/
public static function suite() {
$suite = new CakeTestSuite('Model Behavior and all behaviors');
$path = CORE_TEST_CASES . DS . 'Model' . DS . 'Behavior' . DS;
$suite->addTestFile(CORE_TEST_CASES . DS . 'Model' . DS . 'BehaviorCollectionTest.php');
$suite->addTestDirectory($path);
return $suite;
}
}
| 0001-bee | trunk/cakephp2/lib/Cake/Test/Case/AllBehaviorsTest.php | PHP | gpl3 | 1,210 |
<?php
/**
* AllLogTest file
*
* PHP 5
*
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
* Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://cakephp.org CakePHP(tm) Project
* @package Cake.Test.Case
* @since CakePHP(tm) v 2.0
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
/**
* AllLogTest class
*
* This test group will run log tests.
*
* @package Cake.Test.Case
*/
class AllLogTest extends PHPUnit_Framework_TestSuite {
/**
* suite method, defines tests for this suite.
*
* @return void
*/
public static function suite() {
$suite = new CakeTestSuite('All Logging related class tests');
$suite->addTestDirectory(CORE_TEST_CASES . DS . 'Log');
$suite->addTestDirectory(CORE_TEST_CASES . DS . 'Log' . DS . 'Engine');
return $suite;
}
}
| 0001-bee | trunk/cakephp2/lib/Cake/Test/Case/AllLogTest.php | PHP | gpl3 | 1,103 |
<?php
/**
* ControllerTest file
*
* PHP 5
*
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
* Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://cakephp.org CakePHP Project
* @package Cake.Test.Case.Controller
* @since CakePHP(tm) v 1.2.0.5436
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
App::uses('Controller', 'Controller');
App::uses('Router', 'Routing');
App::uses('CakeRequest', 'Network');
App::uses('CakeResponse', 'Network');
App::uses('SecurityComponent', 'Controller/Component');
App::uses('CookieComponent', 'Controller/Component');
/**
* AppController class
*
* @package Cake.Test.Case.Controller
*/
class ControllerTestAppController extends Controller {
/**
* helpers property
*
* @var array
*/
public $helpers = array('Html');
/**
* uses property
*
* @var array
*/
public $uses = array('ControllerPost');
/**
* components property
*
* @var array
*/
public $components = array('Cookie');
}
/**
* ControllerPost class
*
* @package Cake.Test.Case.Controller
*/
class ControllerPost extends CakeTestModel {
/**
* name property
*
* @var string 'ControllerPost'
*/
public $name = 'ControllerPost';
/**
* useTable property
*
* @var string 'posts'
*/
public $useTable = 'posts';
/**
* invalidFields property
*
* @var array
*/
public $invalidFields = array('name' => 'error_msg');
/**
* lastQuery property
*
* @var mixed null
*/
public $lastQuery = null;
/**
* beforeFind method
*
* @param mixed $query
* @return void
*/
public function beforeFind($query) {
$this->lastQuery = $query;
}
/**
* find method
*
* @param mixed $type
* @param array $options
* @return void
*/
public function find($type, $options = array()) {
if ($type == 'popular') {
$conditions = array($this->name . '.' . $this->primaryKey .' > ' => '1');
$options = Set::merge($options, compact('conditions'));
return parent::find('all', $options);
}
return parent::find($type, $options);
}
}
/**
* ControllerPostsController class
*
* @package Cake.Test.Case.Controller
*/
class ControllerCommentsController extends ControllerTestAppController {
/**
* name property
*
* @var string 'ControllerPost'
*/
public $name = 'ControllerComments';
protected $_mergeParent = 'ControllerTestAppController';
}
/**
* ControllerComment class
*
* @package Cake.Test.Case.Controller
*/
class ControllerComment extends CakeTestModel {
/**
* name property
*
* @var string 'ControllerComment'
*/
public $name = 'Comment';
/**
* useTable property
*
* @var string 'comments'
*/
public $useTable = 'comments';
/**
* data property
*
* @var array
*/
public $data = array('name' => 'Some Name');
/**
* alias property
*
* @var string 'ControllerComment'
*/
public $alias = 'ControllerComment';
}
/**
* ControllerAlias class
*
* @package Cake.Test.Case.Controller
*/
class ControllerAlias extends CakeTestModel {
/**
* name property
*
* @var string 'ControllerAlias'
*/
public $name = 'ControllerAlias';
/**
* alias property
*
* @var string 'ControllerSomeAlias'
*/
public $alias = 'ControllerSomeAlias';
/**
* useTable property
*
* @var string 'posts'
*/
public $useTable = 'posts';
}
/**
* NameTest class
*
* @package Cake.Test.Case.Controller
*/
class NameTest extends CakeTestModel {
/**
* name property
* @var string 'Name'
*/
public $name = 'Name';
/**
* useTable property
* @var string 'names'
*/
public $useTable = 'comments';
/**
* alias property
*
* @var string 'ControllerComment'
*/
public $alias = 'Name';
}
/**
* TestController class
*
* @package Cake.Test.Case.Controller
*/
class TestController extends ControllerTestAppController {
/**
* name property
* @var string 'Name'
*/
public $name = 'Test';
/**
* helpers property
*
* @var array
*/
public $helpers = array('Session');
/**
* components property
*
* @var array
*/
public $components = array('Security');
/**
* uses property
*
* @var array
*/
public $uses = array('ControllerComment', 'ControllerAlias');
protected $_mergeParent = 'ControllerTestAppController';
/**
* index method
*
* @param mixed $testId
* @param mixed $test2Id
* @return void
*/
public function index($testId, $test2Id) {
$this->data = array(
'testId' => $testId,
'test2Id' => $test2Id
);
}
public function returner() {
return 'I am from the controller.';
}
protected function protected_m() {
}
private function private_m() {
}
public function _hidden() {
}
public function admin_add() {
}
}
/**
* TestComponent class
*
* @package Cake.Test.Case.Controller
*/
class TestComponent extends Object {
/**
* beforeRedirect method
*
* @return void
*/
public function beforeRedirect() {
}
/**
* initialize method
*
* @return void
*/
public function initialize(&$controller) {
}
/**
* startup method
*
* @return void
*/
public function startup(&$controller) {
}
/**
* shutdown method
*
* @return void
*/
public function shutdown(&$controller) {
}
/**
* beforeRender callback
*
* @return void
*/
public function beforeRender(&$controller) {
if ($this->viewclass) {
$controller->viewClass = $this->viewclass;
}
}
}
/**
* AnotherTestController class
*
* @package Cake.Test.Case.Controller
*/
class AnotherTestController extends ControllerTestAppController {
/**
* name property
* @var string 'Name'
*/
public $name = 'AnotherTest';
/**
* uses property
*
* @var array
*/
public $uses = null;
protected $_mergeParent = 'ControllerTestAppController';
}
/**
* ControllerTest class
*
* @package Cake.Test.Case.Controller
*/
class ControllerTest extends CakeTestCase {
/**
* fixtures property
*
* @var array
*/
public $fixtures = array('core.post', 'core.comment', 'core.name');
/**
* reset environment.
*
* @return void
*/
public function setUp() {
App::objects('plugin', null, false);
App::build();
Router::reload();
}
/**
* teardown
*
* @return void
*/
public function teardown() {
CakePlugin::unload();
App::build();
}
/**
* testLoadModel method
*
* @return void
*/
public function testLoadModel() {
$request = new CakeRequest('controller_posts/index');
$response = $this->getMock('CakeResponse');
$Controller = new Controller($request, $response);
$this->assertFalse(isset($Controller->ControllerPost));
$result = $Controller->loadModel('ControllerPost');
$this->assertTrue($result);
$this->assertTrue(is_a($Controller->ControllerPost, 'ControllerPost'));
$this->assertTrue(in_array('ControllerPost', $Controller->uses));
ClassRegistry::flush();
unset($Controller);
}
/**
* testLoadModel method from a plugin controller
*
* @return void
*/
public function testLoadModelInPlugins() {
App::build(array(
'plugins' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS),
'Controller' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Controller' . DS),
'Model' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Model' . DS)
));
CakePlugin::load('TestPlugin');
App::uses('TestPluginAppController', 'TestPlugin.Controller');
App::uses('TestPluginController', 'TestPlugin.Controller');
$Controller = new TestPluginController();
$Controller->plugin = 'TestPlugin';
$Controller->uses = false;
$this->assertFalse(isset($Controller->Comment));
$result = $Controller->loadModel('Comment');
$this->assertTrue($result);
$this->assertInstanceOf('Comment', $Controller->Comment);
$this->assertTrue(in_array('Comment', $Controller->uses));
ClassRegistry::flush();
unset($Controller);
}
/**
* testConstructClasses method
*
* @return void
*/
public function testConstructClasses() {
$request = new CakeRequest('controller_posts/index');
$Controller = new Controller($request);
$Controller = new Controller($request);
$Controller->uses = array('ControllerPost', 'ControllerComment');
$Controller->constructClasses();
$this->assertTrue(is_a($Controller->ControllerPost, 'ControllerPost'));
$this->assertTrue(is_a($Controller->ControllerComment, 'ControllerComment'));
$this->assertEqual($Controller->ControllerComment->name, 'Comment');
unset($Controller);
App::build(array('plugins' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS)));
CakePlugin::load('TestPlugin');
$Controller = new Controller($request);
$Controller->uses = array('TestPlugin.TestPluginPost');
$Controller->constructClasses();
$this->assertTrue(isset($Controller->TestPluginPost));
$this->assertTrue(is_a($Controller->TestPluginPost, 'TestPluginPost'));
unset($Controller);
}
/**
* testAliasName method
*
* @return void
*/
public function testAliasName() {
$request = new CakeRequest('controller_posts/index');
$Controller = new Controller($request);
$Controller->uses = array('NameTest');
$Controller->constructClasses();
$this->assertEqual($Controller->NameTest->name, 'Name');
$this->assertEqual($Controller->NameTest->alias, 'Name');
unset($Controller);
}
/**
* testFlash method
*
* @return void
*/
public function testFlash() {
$request = new CakeRequest('controller_posts/index');
$request->webroot = '/';
$request->base = '/';
$Controller = new Controller($request, $this->getMock('CakeResponse', array('_sendHeader')));
$Controller->flash('this should work', '/flash');
$result = $Controller->response->body();
$expected = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>this should work</title>
<style><!--
P { text-align:center; font:bold 1.1em sans-serif }
A { color:#444; text-decoration:none }
A:HOVER { text-decoration: underline; color:#44E }
--></style>
</head>
<body>
<p><a href="/flash">this should work</a></p>
</body>
</html>';
$result = str_replace(array("\t", "\r\n", "\n"), "", $result);
$expected = str_replace(array("\t", "\r\n", "\n"), "", $expected);
$this->assertEqual($expected, $result);
App::build(array(
'View' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'View'. DS)
));
$Controller = new Controller($request);
$Controller->response = $this->getMock('CakeResponse', array('_sendHeader'));
$Controller->flash('this should work', '/flash', 1, 'ajax2');
$result = $Controller->response->body();
$this->assertPattern('/Ajax!/', $result);
App::build();
}
/**
* testControllerSet method
*
* @return void
*/
public function testControllerSet() {
$request = new CakeRequest('controller_posts/index');
$Controller = new Controller($request);
$Controller->set('variable_with_underscores', null);
$this->assertTrue(array_key_exists('variable_with_underscores', $Controller->viewVars));
$Controller->viewVars = array();
$viewVars = array('ModelName' => array('id' => 1, 'name' => 'value'));
$Controller->set($viewVars);
$this->assertTrue(array_key_exists('ModelName', $Controller->viewVars));
$Controller->viewVars = array();
$Controller->set('variable_with_underscores', 'value');
$this->assertTrue(array_key_exists('variable_with_underscores', $Controller->viewVars));
$Controller->viewVars = array();
$viewVars = array('ModelName' => 'name');
$Controller->set($viewVars);
$this->assertTrue(array_key_exists('ModelName', $Controller->viewVars));
$Controller->set('title', 'someTitle');
$this->assertIdentical($Controller->viewVars['title'], 'someTitle');
$this->assertTrue(empty($Controller->pageTitle));
$Controller->viewVars = array();
$expected = array('ModelName' => 'name', 'ModelName2' => 'name2');
$Controller->set(array('ModelName', 'ModelName2'), array('name', 'name2'));
$this->assertIdentical($Controller->viewVars, $expected);
$Controller->viewVars = array();
$Controller->set(array(3 => 'three', 4 => 'four'));
$Controller->set(array(1 => 'one', 2 => 'two'));
$expected = array(3 => 'three', 4 => 'four', 1 => 'one', 2 => 'two');
$this->assertEqual($Controller->viewVars, $expected);
}
/**
* testRender method
*
* @return void
*/
public function testRender() {
App::build(array(
'View' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'View'. DS)
), true);
ClassRegistry::flush();
$request = new CakeRequest('controller_posts/index');
$request->params['action'] = 'index';
$Controller = new Controller($request, new CakeResponse());
$Controller->viewPath = 'Posts';
$result = $Controller->render('index');
$this->assertPattern('/posts index/', (string)$result);
$Controller->view = 'index';
$result = $Controller->render();
$this->assertPattern('/posts index/', (string)$result);
$result = $Controller->render('/Elements/test_element');
$this->assertPattern('/this is the test element/', (string)$result);
$Controller->view = null;
$Controller = new TestController($request, new CakeResponse());
$Controller->uses = array('ControllerAlias', 'TestPlugin.ControllerComment', 'ControllerPost');
$Controller->helpers = array('Html');
$Controller->constructClasses();
$Controller->ControllerComment->validationErrors = array('title' => 'tooShort');
$expected = $Controller->ControllerComment->validationErrors;
$Controller->viewPath = 'Posts';
$result = $Controller->render('index');
$View = $Controller->View;
$this->assertTrue(isset($View->validationErrors['ControllerComment']));
$this->assertEqual($expected, $View->validationErrors['ControllerComment']);
$expectedModels = array(
'ControllerAlias' => array('plugin' => null, 'className' => 'ControllerAlias'),
'ControllerComment' => array('plugin' => 'TestPlugin', 'className' => 'ControllerComment'),
'ControllerPost' => array('plugin' => null, 'className' => 'ControllerPost')
);
$this->assertEqual($expectedModels, $Controller->request->params['models']);
ClassRegistry::flush();
App::build();
}
/**
* test that a component beforeRender can change the controller view class.
*
* @return void
*/
public function testComponentBeforeRenderChangingViewClass() {
App::build(array(
'View' => array(
CAKE . 'Test' . DS . 'test_app' . DS . 'View'. DS
)
), true);
$Controller = new Controller($this->getMock('CakeRequest'), new CakeResponse());
$Controller->uses = array();
$Controller->components = array('Test');
$Controller->constructClasses();
$Controller->Test->viewclass = 'Theme';
$Controller->viewPath = 'Posts';
$Controller->theme = 'TestTheme';
$result = $Controller->render('index');
$this->assertPattern('/default test_theme layout/', (string)$result);
App::build();
}
/**
* testToBeInheritedGuardmethods method
*
* @return void
*/
public function testToBeInheritedGuardmethods() {
$request = new CakeRequest('controller_posts/index');
$Controller = new Controller($request, $this->getMock('CakeResponse'));
$this->assertTrue($Controller->beforeScaffold(''));
$this->assertTrue($Controller->afterScaffoldSave(''));
$this->assertTrue($Controller->afterScaffoldSaveError(''));
$this->assertFalse($Controller->scaffoldError(''));
}
/**
* Generates status codes for redirect test.
*
* @return void
*/
public static function statusCodeProvider() {
return array(
array(300, "Multiple Choices"),
array(301, "Moved Permanently"),
array(302, "Found"),
array(303, "See Other"),
array(304, "Not Modified"),
array(305, "Use Proxy"),
array(307, "Temporary Redirect")
);
}
/**
* testRedirect method
*
* @dataProvider statusCodeProvider
* @return void
*/
public function testRedirectByCode($code, $msg) {
$Controller = new Controller(null);
$Controller->response = $this->getMock('CakeResponse', array('header', 'statusCode'));
$Controller->Components = $this->getMock('ComponentCollection');
$Controller->response->expects($this->once())->method('statusCode')
->with($code);
$Controller->response->expects($this->once())->method('header')
->with('Location', 'http://cakephp.org');
$Controller->redirect('http://cakephp.org', (int)$code, false);
$this->assertFalse($Controller->autoRender);
}
/**
* test redirecting by message
*
* @dataProvider statusCodeProvider
* @return void
*/
public function testRedirectByMessage($code, $msg) {
$Controller = new Controller(null);
$Controller->response = $this->getMock('CakeResponse', array('header', 'statusCode'));
$Controller->Components = $this->getMock('ComponentCollection');
$Controller->response->expects($this->once())->method('statusCode')
->with($code);
$Controller->response->expects($this->once())->method('header')
->with('Location', 'http://cakephp.org');
$Controller->redirect('http://cakephp.org', $msg, false);
$this->assertFalse($Controller->autoRender);
}
/**
* test that redirect triggers methods on the components.
*
* @return void
*/
public function testRedirectTriggeringComponentsReturnNull() {
$Controller = new Controller(null);
$Controller->response = $this->getMock('CakeResponse', array('header', 'statusCode'));
$Controller->Components = $this->getMock('ComponentCollection');
$Controller->Components->expects($this->once())->method('trigger')
->will($this->returnValue(null));
$Controller->response->expects($this->once())->method('statusCode')
->with(301);
$Controller->response->expects($this->once())->method('header')
->with('Location', 'http://cakephp.org');
$Controller->redirect('http://cakephp.org', 301, false);
}
/**
* test that beforeRedirect callback returnning null doesn't affect things.
*
* @return void
*/
public function testRedirectBeforeRedirectModifyingParams() {
$Controller = new Controller(null);
$Controller->response = $this->getMock('CakeResponse', array('header', 'statusCode'));
$Controller->Components = $this->getMock('ComponentCollection');
$Controller->Components->expects($this->once())->method('trigger')
->will($this->returnValue(array('http://book.cakephp.org')));
$Controller->response->expects($this->once())->method('statusCode')
->with(301);
$Controller->response->expects($this->once())->method('header')
->with('Location', 'http://book.cakephp.org');
$Controller->redirect('http://cakephp.org', 301, false);
}
/**
* test that beforeRedirect callback returnning null doesn't affect things.
*
* @return void
*/
public function testRedirectBeforeRedirectModifyingParamsArrayReturn() {
$Controller = $this->getMock('Controller', array('header', '_stop'));
$Controller->response = $this->getMock('CakeResponse');
$Controller->Components = $this->getMock('ComponentCollection');
$return = array(
array(
'url' => 'http://example.com/test/1',
'exit' => false,
'status' => 302
),
array(
'url' => 'http://example.com/test/2',
),
);
$Controller->Components->expects($this->once())->method('trigger')
->will($this->returnValue($return));
$Controller->response->expects($this->at(0))->method('header')
->with('Location', 'http://example.com/test/2');
$Controller->response->expects($this->at(1))->method('statusCode')
->with(302);
$Controller->expects($this->never())->method('_stop');
$Controller->redirect('http://cakephp.org', 301);
}
/**
* test that beforeRedirect callback returnning false in controller
*
* @return void
*/
public function testRedirectBeforeRedirectInController() {
$Controller = $this->getMock('Controller', array('_stop', 'beforeRedirect'));
$Controller->response = $this->getMock('CakeResponse', array('header'));
$Controller->Components = $this->getMock('ComponentCollection');
$Controller->expects($this->once())->method('beforeRedirect')
->will($this->returnValue(false));
$Controller->response->expects($this->never())->method('header');
$Controller->expects($this->never())->method('_stop');
$Controller->redirect('http://cakephp.org');
}
/**
* testMergeVars method
*
* @return void
*/
public function testMergeVars() {
$request = new CakeRequest('controller_posts/index');
$TestController = new TestController($request);
$TestController->constructClasses();
$testVars = get_class_vars('TestController');
$appVars = get_class_vars('ControllerTestAppController');
$components = is_array($appVars['components'])
? array_merge($appVars['components'], $testVars['components'])
: $testVars['components'];
if (!in_array('Session', $components)) {
$components[] = 'Session';
}
$helpers = is_array($appVars['helpers'])
? array_merge($appVars['helpers'], $testVars['helpers'])
: $testVars['helpers'];
$uses = is_array($appVars['uses'])
? array_merge($appVars['uses'], $testVars['uses'])
: $testVars['uses'];
$this->assertEqual(count(array_diff_key($TestController->helpers, array_flip($helpers))), 0);
$this->assertEqual(count(array_diff($TestController->uses, $uses)), 0);
$this->assertEqual(count(array_diff_assoc(Set::normalize($TestController->components), Set::normalize($components))), 0);
$expected = array('ControllerComment', 'ControllerAlias', 'ControllerPost');
$this->assertEquals($expected, $TestController->uses, '$uses was merged incorrectly, ControllerTestAppController models should be last.');
$TestController = new AnotherTestController($request);
$TestController->constructClasses();
$appVars = get_class_vars('ControllerTestAppController');
$testVars = get_class_vars('AnotherTestController');
$this->assertTrue(in_array('ControllerPost', $appVars['uses']));
$this->assertNull($testVars['uses']);
$this->assertFalse(property_exists($TestController, 'ControllerPost'));
$TestController = new ControllerCommentsController($request);
$TestController->constructClasses();
$appVars = get_class_vars('ControllerTestAppController');
$testVars = get_class_vars('ControllerCommentsController');
$this->assertTrue(in_array('ControllerPost', $appVars['uses']));
$this->assertEqual(array('ControllerPost'), $testVars['uses']);
$this->assertTrue(isset($TestController->ControllerPost));
$this->assertTrue(isset($TestController->ControllerComment));
}
/**
* test that options from child classes replace those in the parent classes.
*
* @return void
*/
public function testChildComponentOptionsSupercedeParents() {
$request = new CakeRequest('controller_posts/index');
$TestController = new TestController($request);
$expected = array('foo');
$TestController->components = array('Cookie' => $expected);
$TestController->constructClasses();
$this->assertEqual($TestController->components['Cookie'], $expected);
}
/**
* Ensure that _mergeControllerVars is not being greedy and merging with
* ControllerTestAppController when you make an instance of Controller
*
* @return void
*/
public function testMergeVarsNotGreedy() {
$request = new CakeRequest('controller_posts/index');
$Controller = new Controller($request);
$Controller->components = array();
$Controller->uses = array();
$Controller->constructClasses();
$this->assertFalse(isset($Controller->Session));
}
/**
* testReferer method
*
* @return void
*/
public function testReferer() {
$request = $this->getMock('CakeRequest');
$request->expects($this->any())->method('referer')
->with(true)
->will($this->returnValue('/posts/index'));
$Controller = new Controller($request);
$result = $Controller->referer(null, true);
$this->assertEqual($result, '/posts/index');
$Controller = new Controller($request);
$request->setReturnValue('referer', '/', array(true));
$result = $Controller->referer(array('controller' => 'posts', 'action' => 'index'), true);
$this->assertEqual($result, '/posts/index');
$request = $this->getMock('CakeRequest');
$request->expects($this->any())->method('referer')
->with(false)
->will($this->returnValue('http://localhost/posts/index'));
$Controller = new Controller($request);
$result = $Controller->referer();
$this->assertEqual($result, 'http://localhost/posts/index');
$Controller = new Controller(null);
$result = $Controller->referer();
$this->assertEqual($result, '/');
}
/**
* testSetAction method
*
* @return void
*/
public function testSetAction() {
$request = new CakeRequest('controller_posts/index');
$TestController = new TestController($request);
$TestController->setAction('index', 1, 2);
$expected = array('testId' => 1, 'test2Id' => 2);
$this->assertidentical($TestController->data, $expected);
}
/**
* testValidateErrors method
*
* @return void
*/
public function testValidateErrors() {
ClassRegistry::flush();
$request = new CakeRequest('controller_posts/index');
$TestController = new TestController($request);
$TestController->constructClasses();
$this->assertFalse($TestController->validateErrors());
$this->assertEqual($TestController->validate(), 0);
$TestController->ControllerComment->invalidate('some_field', 'error_message');
$TestController->ControllerComment->invalidate('some_field2', 'error_message2');
$comment = new ControllerComment($request);
$comment->set('someVar', 'data');
$result = $TestController->validateErrors($comment);
$expected = array('some_field' => array('error_message'), 'some_field2' => array('error_message2'));
$this->assertIdentical($expected, $result);
$this->assertEqual($TestController->validate($comment), 2);
}
/**
* test that validateErrors works with any old model.
*
* @return void
*/
public function testValidateErrorsOnArbitraryModels() {
$TestController = new TestController();
$Post = new ControllerPost();
$Post->validate = array('title' => 'notEmpty');
$Post->set('title', '');
$result = $TestController->validateErrors($Post);
$expected = array('title' => array('This field cannot be left blank'));
$this->assertEqual($expected, $result);
}
/**
* testPostConditions method
*
* @return void
*/
public function testPostConditions() {
$request = new CakeRequest('controller_posts/index');
$Controller = new Controller($request);
$data = array(
'Model1' => array('field1' => '23'),
'Model2' => array('field2' => 'string'),
'Model3' => array('field3' => '23'),
);
$expected = array(
'Model1.field1' => '23',
'Model2.field2' => 'string',
'Model3.field3' => '23',
);
$result = $Controller->postConditions($data);
$this->assertIdentical($expected, $result);
$data = array();
$Controller->data = array(
'Model1' => array('field1' => '23'),
'Model2' => array('field2' => 'string'),
'Model3' => array('field3' => '23'),
);
$expected = array(
'Model1.field1' => '23',
'Model2.field2' => 'string',
'Model3.field3' => '23',
);
$result = $Controller->postConditions($data);
$this->assertIdentical($expected, $result);
$data = array();
$Controller->data = array();
$result = $Controller->postConditions($data);
$this->assertNull($result);
$data = array();
$Controller->data = array(
'Model1' => array('field1' => '23'),
'Model2' => array('field2' => 'string'),
'Model3' => array('field3' => '23'),
);
$ops = array(
'Model1.field1' => '>',
'Model2.field2' => 'LIKE',
'Model3.field3' => '<=',
);
$expected = array(
'Model1.field1 >' => '23',
'Model2.field2 LIKE' => "%string%",
'Model3.field3 <=' => '23',
);
$result = $Controller->postConditions($data, $ops);
$this->assertIdentical($expected, $result);
}
/**
* testControllerHttpCodes method
*
* @return void
*/
public function testControllerHttpCodes() {
$response = $this->getMock('CakeResponse', array('httpCodes'));
$Controller = new Controller(null, $response);
$Controller->response->expects($this->at(0))->method('httpCodes')->with(null);
$Controller->response->expects($this->at(1))->method('httpCodes')->with(100);
$Controller->httpCodes();
$Controller->httpCodes(100);
}
/**
* Tests that the startup process calls the correct functions
*
* @return void
*/
public function testStartupProcess() {
$Controller = $this->getMock('Controller', array('beforeFilter', 'afterFilter'));
$Controller->components = array('MockStartup');
$Controller->Components = $this->getMock('ComponentCollection');
$Controller->expects($this->once())->method('beforeFilter');
$Controller->Components->expects($this->at(0))->method('trigger')
->with('initialize', array(&$Controller));
$Controller->Components->expects($this->at(1))->method('trigger')
->with('startup', array(&$Controller));
$Controller->startupProcess();
}
/**
* Tests that the shutdown process calls the correct functions
*
* @return void
*/
public function testShutdownProcess() {
$Controller = $this->getMock('Controller', array('beforeFilter', 'afterFilter'));
$Controller->components = array('MockShutdown');
$Controller->Components = $this->getMock('ComponentCollection');
$Controller->expects($this->once())->method('afterFilter');
$Controller->Components->expects($this->once())->method('trigger')
->with('shutdown', array(&$Controller));
$Controller->shutdownProcess();
}
/**
* test that BC works for attributes on the request object.
*
* @return void
*/
public function testPropertyBackwardsCompatibility() {
$request = new CakeRequest('posts/index', null);
$request->addParams(array('controller' => 'posts', 'action' => 'index'));
$request->data = array('Post' => array('id' => 1));
$request->here = '/posts/index';
$request->webroot = '/';
$Controller = new TestController($request);
$this->assertEquals($request->data, $Controller->data);
$this->assertEquals($request->webroot, $Controller->webroot);
$this->assertEquals($request->here, $Controller->here);
$this->assertEquals($request->action, $Controller->action);
$this->assertFalse(empty($Controller->data));
$this->assertTrue(isset($Controller->data));
$this->assertTrue(empty($Controller->something));
$this->assertFalse(isset($Controller->something));
$this->assertEquals($request, $Controller->params);
$this->assertEquals($request->params['controller'], $Controller->params['controller']);
}
/**
* test that the BC wrapper doesn't interfere with models and components.
*
* @return void
*/
public function testPropertyCompatibilityAndModelsComponents() {
$request = new CakeRequest('controller_posts/index');
$Controller = new TestController($request);
$Controller->constructClasses();
$this->assertInstanceOf('SecurityComponent', $Controller->Security);
$this->assertInstanceOf('ControllerComment', $Controller->ControllerComment);
}
/**
* test that using Controller::paginate() falls back to PaginatorComponent
*
* @return void
*/
public function testPaginateBackwardsCompatibility() {
$request = new CakeRequest('controller_posts/index');
$request->params['pass'] = $request->params['named'] = array();
$response = $this->getMock('CakeResponse', array('httpCodes'));
$Controller = new Controller($request, $response);
$Controller->uses = array('ControllerPost', 'ControllerComment');
$Controller->passedArgs[] = '1';
$Controller->params['url'] = array();
$Controller->constructClasses();
$expected = array('page' => 1, 'limit' => 20, 'maxLimit' => 100, 'paramType' => 'named');
$this->assertEqual($Controller->paginate, $expected);
$results = Set::extract($Controller->paginate('ControllerPost'), '{n}.ControllerPost.id');
$this->assertEqual($results, array(1, 2, 3));
$Controller->passedArgs = array();
$Controller->paginate = array('limit' => '-1');
$this->assertEqual($Controller->paginate, array('limit' => '-1'));
$Controller->paginate('ControllerPost');
$this->assertIdentical($Controller->params['paging']['ControllerPost']['page'], 1);
$this->assertIdentical($Controller->params['paging']['ControllerPost']['pageCount'], 3);
$this->assertIdentical($Controller->params['paging']['ControllerPost']['prevPage'], false);
$this->assertIdentical($Controller->params['paging']['ControllerPost']['nextPage'], true);
}
/**
* testMissingAction method
*
* @expectedException MissingActionException
* @expectedExceptionMessage Action TestController::missing() could not be found.
* @return void
*/
public function testInvokeActionMissingAction() {
$url = new CakeRequest('test/missing');
$url->addParams(array('controller' => 'test_controller', 'action' => 'missing'));
$response = $this->getMock('CakeResponse');
$Controller = new TestController($url, $response);
$Controller->invokeAction($url);
}
/**
* test invoking private methods.
*
* @expectedException PrivateActionException
* @expectedExceptionMessage Private Action TestController::private_m() is not directly accessible.
* @return void
*/
public function testInvokeActionPrivate() {
$url = new CakeRequest('test/private_m/');
$url->addParams(array('controller' => 'test_controller', 'action' => 'private_m'));
$response = $this->getMock('CakeResponse');
$Controller = new TestController($url, $response);
$Controller->invokeAction($url);
}
/**
* test invoking protected methods.
*
* @expectedException PrivateActionException
* @expectedExceptionMessage Private Action TestController::protected_m() is not directly accessible.
* @return void
*/
public function testInvokeActionProtected() {
$url = new CakeRequest('test/protected_m/');
$url->addParams(array('controller' => 'test_controller', 'action' => 'protected_m'));
$response = $this->getMock('CakeResponse');
$Controller = new TestController($url, $response);
$Controller->invokeAction($url);
}
/**
* test invoking hidden methods.
*
* @expectedException PrivateActionException
* @expectedExceptionMessage Private Action TestController::_hidden() is not directly accessible.
* @return void
*/
public function testInvokeActionHidden() {
$url = new CakeRequest('test/_hidden/');
$url->addParams(array('controller' => 'test_controller', 'action' => '_hidden'));
$response = $this->getMock('CakeResponse');
$Controller = new TestController($url, $response);
$Controller->invokeAction($url);
}
/**
* test invoking controller methods.
*
* @expectedException PrivateActionException
* @expectedExceptionMessage Private Action TestController::redirect() is not directly accessible.
* @return void
*/
public function testInvokeActionBaseMethods() {
$url = new CakeRequest('test/redirect/');
$url->addParams(array('controller' => 'test_controller', 'action' => 'redirect'));
$response = $this->getMock('CakeResponse');
$Controller = new TestController($url, $response);
$Controller->invokeAction($url);
}
/**
* test invoking controller methods.
*
* @expectedException PrivateActionException
* @expectedExceptionMessage Private Action TestController::admin_add() is not directly accessible.
* @return void
*/
public function testInvokeActionPrefixProtection() {
Router::reload();
Router::connect('/admin/:controller/:action/*', array('prefix'=>'admin'));
$url = new CakeRequest('test/admin_add/');
$url->addParams(array('controller' => 'test_controller', 'action' => 'admin_add'));
$response = $this->getMock('CakeResponse');
$Controller = new TestController($url, $response);
$Controller->invokeAction($url);
}
/**
* test invoking controller methods.
*
* @return void
*/
public function testInvokeActionReturnValue() {
$url = new CakeRequest('test/returner/');
$url->addParams(array(
'controller' => 'test_controller',
'action' => 'returner',
'pass' => array()
));
$response = $this->getMock('CakeResponse');
$Controller = new TestController($url, $response);
$result = $Controller->invokeAction($url);
$this->assertEquals('I am from the controller.', $result);
}
}
| 0001-bee | trunk/cakephp2/lib/Cake/Test/Case/Controller/ControllerTest.php | PHP | gpl3 | 36,154 |
<?php
/**
* ScaffoldTest file
*
* PHP 5
*
* CakePHP(tm) Tests <http://book.cakephp.org/view/1196/Testing>
* Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice
*
* @copyright Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://book.cakephp.org/view/1196/Testing CakePHP(tm) Tests
* @package Cake.Test.Case.Controller
* @since CakePHP(tm) v 1.2.0.5436
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
App::uses('Router', 'Routing');
App::uses('Controller', 'Controller');
App::uses('Scaffold', 'Controller');
App::uses('ScaffoldView', 'View');
App::uses('AppModel', 'Model');
require_once dirname(dirname(__FILE__)) . DS . 'Model' . DS . 'models.php';
/**
* ScaffoldMockController class
*
* @package Cake.Test.Case.Controller
*/
class ScaffoldMockController extends Controller {
/**
* name property
*
* @var string 'ScaffoldMock'
*/
public $name = 'ScaffoldMock';
/**
* scaffold property
*
* @var mixed
*/
public $scaffold;
}
/**
* ScaffoldMockControllerWithFields class
*
* @package Cake.Test.Case.Controller
*/
class ScaffoldMockControllerWithFields extends Controller {
/**
* name property
*
* @var string 'ScaffoldMock'
*/
public $name = 'ScaffoldMock';
/**
* scaffold property
*
* @var mixed
*/
public $scaffold;
/**
* function beforeScaffold
*
* @param string method
*/
public function beforeScaffold($method) {
$this->set('scaffoldFields', array('title'));
return true;
}
}
/**
* TestScaffoldMock class
*
* @package Cake.Test.Case.Controller
*/
class TestScaffoldMock extends Scaffold {
/**
* Overload __scaffold
*
* @param unknown_type $params
*/
function _scaffold($params) {
$this->_params = $params;
}
/**
* Get Params from the Controller.
*
* @return unknown
*/
function getParams() {
return $this->_params;
}
}
/**
* Scaffold Test class
*
* @package Cake.Test.Case.Controller
*/
class ScaffoldTest extends CakeTestCase {
/**
* Controller property
*
* @var SecurityTestController
*/
public $Controller;
/**
* fixtures property
*
* @var array
*/
public $fixtures = array('core.article', 'core.user', 'core.comment', 'core.join_thing', 'core.tag');
/**
* setUp method
*
* @return void
*/
public function setUp() {
parent::setUp();
$request = new CakeRequest(null, false);
$this->Controller = new ScaffoldMockController($request);
$this->Controller->response = $this->getMock('CakeResponse', array('_sendHeader'));
}
/**
* tearDown method
*
* @return void
*/
public function tearDown() {
parent::tearDown();
unset($this->Controller);
}
/**
* Test the correct Generation of Scaffold Params.
* This ensures that the correct action and view will be generated
*
* @return void
*/
public function testScaffoldParams() {
$params = array(
'plugin' => null,
'pass' => array(),
'form' => array(),
'named' => array(),
'url' => array('url' =>'admin/scaffold_mock/edit'),
'controller' => 'scaffold_mock',
'action' => 'admin_edit',
'admin' => true,
);
$this->Controller->request->base = '';
$this->Controller->request->webroot = '/';
$this->Controller->request->here = '/admin/scaffold_mock/edit';
$this->Controller->request->addParams($params);
//set router.
Router::setRequestInfo($this->Controller->request);
$this->Controller->constructClasses();
$Scaffold = new TestScaffoldMock($this->Controller, $this->Controller->request);
$result = $Scaffold->getParams();
$this->assertEqual($result['action'], 'admin_edit');
}
/**
* test that the proper names and variable values are set by Scaffold
*
* @return void
*/
public function testScaffoldVariableSetting() {
$params = array(
'plugin' => null,
'pass' => array(),
'form' => array(),
'named' => array(),
'url' => array('url' =>'admin/scaffold_mock/edit'),
'controller' => 'scaffold_mock',
'action' => 'admin_edit',
'admin' => true,
);
$this->Controller->request->base = '';
$this->Controller->request->webroot = '/';
$this->Controller->request->here = '/admin/scaffold_mock/edit';
$this->Controller->request->addParams($params);
//set router.
Router::setRequestInfo($this->Controller->request);
$this->Controller->constructClasses();
$Scaffold = new TestScaffoldMock($this->Controller, $this->Controller->request);
$result = $Scaffold->controller->viewVars;
$this->assertEqual($result['title_for_layout'], 'Scaffold :: Admin Edit :: Scaffold Mock');
$this->assertEqual($result['singularHumanName'], 'Scaffold Mock');
$this->assertEqual($result['pluralHumanName'], 'Scaffold Mock');
$this->assertEqual($result['modelClass'], 'ScaffoldMock');
$this->assertEqual($result['primaryKey'], 'id');
$this->assertEqual($result['displayField'], 'title');
$this->assertEqual($result['singularVar'], 'scaffoldMock');
$this->assertEqual($result['pluralVar'], 'scaffoldMock');
$this->assertEqual($result['scaffoldFields'], array('id', 'user_id', 'title', 'body', 'published', 'created', 'updated'));
}
/**
* test that Scaffold overrides the view property even if its set to 'Theme'
*
* @return void
*/
public function testScaffoldChangingViewProperty() {
$this->Controller->action = 'edit';
$this->Controller->theme = 'TestTheme';
$this->Controller->viewClass = 'Theme';
$this->Controller->constructClasses();
$Scaffold = new TestScaffoldMock($this->Controller, $this->Controller->request);
$this->assertEqual($this->Controller->viewClass, 'Scaffold');
}
/**
* test that scaffold outputs flash messages when sessions are unset.
*
* @return void
*/
public function testScaffoldFlashMessages() {
$params = array(
'plugin' => null,
'pass' => array(1),
'form' => array(),
'named' => array(),
'url' => array('url' =>'scaffold_mock'),
'controller' => 'scaffold_mock',
'action' => 'edit',
);
$this->Controller->request->base = '';
$this->Controller->request->webroot = '/';
$this->Controller->request->here = '/scaffold_mock/edit';
$this->Controller->request->addParams($params);
//set router.
Router::reload();
Router::setRequestInfo($this->Controller->request);
$this->Controller->request->data = array(
'ScaffoldMock' => array(
'id' => 1,
'title' => 'New title',
'body' => 'new body'
)
);
$this->Controller->constructClasses();
unset($this->Controller->Session);
ob_start();
new Scaffold($this->Controller, $this->Controller->request);
$this->Controller->response->send();
$result = ob_get_clean();
$this->assertPattern('/Scaffold Mock has been updated/', $result);
}
/**
* test that habtm relationship keys get added to scaffoldFields.
*
* @return void
*/
function testHabtmFieldAdditionWithScaffoldForm() {
CakePlugin::unload();
$params = array(
'plugin' => null,
'pass' => array(1),
'form' => array(),
'named' => array(),
'url' => array('url' =>'scaffold_mock'),
'controller' => 'scaffold_mock',
'action' => 'edit',
);
$this->Controller->request->base = '';
$this->Controller->request->webroot = '/';
$this->Controller->request->here = '/scaffold_mock/edit';
$this->Controller->request->addParams($params);
//set router.
Router::reload();
Router::setRequestInfo($this->Controller->request);
$this->Controller->constructClasses();
ob_start();
$Scaffold = new Scaffold($this->Controller, $this->Controller->request);
$this->Controller->response->send();
$result = ob_get_clean();
$this->assertPattern('/name="data\[ScaffoldTag\]\[ScaffoldTag\]"/', $result);
$result = $Scaffold->controller->viewVars;
$this->assertEqual($result['scaffoldFields'], array('id', 'user_id', 'title', 'body', 'published', 'created', 'updated', 'ScaffoldTag'));
}
/**
* test that the proper names and variable values are set by Scaffold
*
* @return void
*/
public function testEditScaffoldWithScaffoldFields() {
$request = new CakeRequest(null, false);
$this->Controller = new ScaffoldMockControllerWithFields($request);
$this->Controller->response = $this->getMock('CakeResponse', array('_sendHeader'));
$params = array(
'plugin' => null,
'pass' => array(1),
'form' => array(),
'named' => array(),
'url' => array('url' =>'scaffold_mock/edit'),
'controller' => 'scaffold_mock',
'action' => 'edit',
);
$this->Controller->request->base = '';
$this->Controller->request->webroot = '/';
$this->Controller->request->here = '/scaffold_mock/edit';
$this->Controller->request->addParams($params);
//set router.
Router::reload();
Router::setRequestInfo($this->Controller->request);
$this->Controller->constructClasses();
ob_start();
new Scaffold($this->Controller, $this->Controller->request);
$this->Controller->response->send();
$result = ob_get_clean();
$this->assertNoPattern('/textarea name="data\[ScaffoldMock\]\[body\]" cols="30" rows="6" id="ScaffoldMockBody"/', $result);
}
}
| 0001-bee | trunk/cakephp2/lib/Cake/Test/Case/Controller/ScaffoldTest.php | PHP | gpl3 | 9,163 |
<?php
/**
* Controller Merge vars Test file
*
* Isolated from the Controller and Component test as to not pollute their AppController class
*
* PHP 5
*
* CakePHP(tm) Tests <http://book.cakephp.org/view/1196/Testing>
* Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice
*
* @copyright Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://book.cakephp.org/view/1196/Testing CakePHP(tm) Tests
* @package Cake.Test.Case.Controller
* @since CakePHP(tm) v 1.2.3
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
App::uses('Controller', 'Controller');
/**
* Test case AppController
*
* @package Cake.Test.Case.Controller
* @package Cake.Test.Case.Controller
*/
class MergeVarsAppController extends Controller {
/**
* components
*
* @var array
*/
public $components = array('MergeVar' => array('flag', 'otherFlag', 'redirect' => false));
/**
* helpers
*
* @var array
*/
public $helpers = array('MergeVar' => array('format' => 'html', 'terse'));
}
/**
* MergeVar Component
*
* @package Cake.Test.Case.Controller
*/
class MergeVarComponent extends Object {
}
/**
* Additional controller for testing
*
* @package Cake.Test.Case.Controller
*/
class MergeVariablesController extends MergeVarsAppController {
/**
* name
*
* @var string
*/
public $name = 'MergeVariables';
/**
* uses
*
* @var arrays
*/
public $uses = array();
/**
* parent for mergeVars
*
* @var string
*/
protected $_mergeParent = 'MergeVarsAppController';
}
/**
* MergeVarPlugin App Controller
*
* @package Cake.Test.Case.Controller
*/
class MergeVarPluginAppController extends MergeVarsAppController {
/**
* components
*
* @var array
*/
public $components = array('Auth' => array('setting' => 'val', 'otherVal'));
/**
* helpers
*
* @var array
*/
public $helpers = array('Javascript');
/**
* parent for mergeVars
*
* @var string
*/
protected $_mergeParent = 'MergeVarsAppController';
}
/**
* MergePostsController
*
* @package Cake.Test.Case.Controller
*/
class MergePostsController extends MergeVarPluginAppController {
/**
* name
*
* @var string
*/
public $name = 'MergePosts';
/**
* uses
*
* @var array
*/
public $uses = array();
}
/**
* Test Case for Controller Merging of Vars.
*
* @package Cake.Test.Case.Controller
*/
class ControllerMergeVarsTest extends CakeTestCase {
/**
* test that component settings are not duplicated when merging component settings
*
* @return void
*/
public function testComponentParamMergingNoDuplication() {
$Controller = new MergeVariablesController();
$Controller->constructClasses();
$expected = array('MergeVar' => array('flag', 'otherFlag', 'redirect' => false));
$this->assertEqual($Controller->components, $expected, 'Duplication of settings occured. %s');
}
/**
* test component merges with redeclared components
*
* @return void
*/
public function testComponentMergingWithRedeclarations() {
$Controller = new MergeVariablesController();
$Controller->components['MergeVar'] = array('remote', 'redirect' => true);
$Controller->constructClasses();
$expected = array('MergeVar' => array('flag', 'otherFlag', 'redirect' => true, 'remote'));
$this->assertEqual($Controller->components, $expected, 'Merging of settings is wrong. %s');
}
/**
* test merging of helpers array, ensure no duplication occurs
*
* @return void
*/
public function testHelperSettingMergingNoDuplication() {
$Controller = new MergeVariablesController();
$Controller->constructClasses();
$expected = array('MergeVar' => array('format' => 'html', 'terse'));
$this->assertEqual($Controller->helpers, $expected, 'Duplication of settings occured. %s');
}
/**
* Test that helpers declared in appcontroller come before those in the subclass
* orderwise
*
* @return void
*/
public function testHelperOrderPrecedence() {
$Controller = new MergeVariablesController();
$Controller->helpers = array('Custom', 'Foo' => array('something'));
$Controller->constructClasses();
$expected = array(
'MergeVar' => array('format' => 'html', 'terse'),
'Custom' => null,
'Foo' => array('something')
);
$this->assertSame($Controller->helpers, $expected, 'Order is incorrect.');
}
/**
* test merging of vars with plugin
*
* @return void
*/
public function testMergeVarsWithPlugin() {
$Controller = new MergePostsController();
$Controller->components = array('Email' => array('ports' => 'open'));
$Controller->plugin = 'MergeVarPlugin';
$Controller->constructClasses();
$expected = array(
'MergeVar' => array('flag', 'otherFlag', 'redirect' => false),
'Auth' => array('setting' => 'val', 'otherVal'),
'Email' => array('ports' => 'open')
);
$this->assertEquals($expected, $Controller->components, 'Components are unexpected.');
$expected = array(
'MergeVar' => array('format' => 'html', 'terse'),
'Javascript' => null
);
$this->assertEquals($expected, $Controller->helpers, 'Helpers are unexpected.');
$Controller = new MergePostsController();
$Controller->components = array();
$Controller->plugin = 'MergeVarPlugin';
$Controller->constructClasses();
$expected = array(
'MergeVar' => array('flag', 'otherFlag', 'redirect' => false),
'Auth' => array('setting' => 'val', 'otherVal'),
);
$this->assertEquals($expected, $Controller->components, 'Components are unexpected.');
}
/**
* Ensure that _mergeControllerVars is not being greedy and merging with
* AppController when you make an instance of Controller
*
* @return void
*/
public function testMergeVarsNotGreedy() {
$Controller = new Controller();
$Controller->components = array();
$Controller->uses = array();
$Controller->constructClasses();
$this->assertFalse(isset($Controller->Session));
}
}
| 0001-bee | trunk/cakephp2/lib/Cake/Test/Case/Controller/ControllerMergeVarsTest.php | PHP | gpl3 | 6,039 |
<?php
/**
* EmailComponentTest file
*
* Series of tests for email component.
*
* PHP 5
*
* CakePHP(tm) Tests <http://book.cakephp.org/view/1196/Testing>
* Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice
*
* @copyright Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://book.cakephp.org/view/1196/Testing CakePHP(tm) Tests
* @package Cake.Test.Case.Controller.Component
* @since CakePHP(tm) v 1.2.0.5347
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
App::uses('Controller', 'Controller');
App::uses('EmailComponent', 'Controller/Component');
App::uses('AbstractTransport', 'Network/Email');
/**
* EmailTestComponent class
*
* @package Cake.Test.Case.Controller.Component
*/
class EmailTestComponent extends EmailComponent {
/**
* Convenience method for testing.
*
* @return string
*/
public function strip($content, $message = false) {
return parent::_strip($content, $message);
}
}
/**
* DebugCompTransport class
*
* @package Cake.Test.Case.Controller.Component
*/
class DebugCompTransport extends AbstractTransport {
/**
* Last email
*
* @var string
*/
public static $lastEmail = null;
/**
* Send mail
*
* @params object $email CakeEmail
* @return boolean
*/
public function send(CakeEmail $email) {
$headers = $email->getHeaders(array_fill_keys(array('from', 'replyTo', 'readReceipt', 'returnPath', 'to', 'cc', 'bcc', 'subject'), true));
$to = $headers['To'];
$subject = $headers['Subject'];
unset($headers['To'], $headers['Subject']);
$message = implode("\n", $email->message());
$last = '<pre>';
$last .= sprintf("%s %s\n", 'To:', $to);
$last .= sprintf("%s %s\n", 'From:', $headers['From']);
$last .= sprintf("%s %s\n", 'Subject:', $subject);
$last .= sprintf("%s\n\n%s", 'Header:', $this->_headersToString($headers, "\n"));
$last .= sprintf("%s\n\n%s", 'Message:', $message);
$last .= '</pre>';
self::$lastEmail = $last;
return true;
}
}
/**
* EmailTestController class
*
* @package Cake.Test.Case.Controller.Component
*/
class EmailTestController extends Controller {
/**
* name property
*
* @var string 'EmailTest'
*/
public $name = 'EmailTest';
/**
* uses property
*
* @var mixed null
*/
public $uses = null;
/**
* components property
*
* @var array
*/
public $components = array('Session', 'EmailTest');
}
/**
* EmailTest class
*
* @package Cake.Test.Case.Controller.Component
*/
class EmailComponentTest extends CakeTestCase {
/**
* Controller property
*
* @var EmailTestController
*/
public $Controller;
/**
* name property
*
* @var string 'Email'
*/
public $name = 'Email';
/**
* setUp method
*
* @return void
*/
public function setUp() {
$this->_appEncoding = Configure::read('App.encoding');
Configure::write('App.encoding', 'UTF-8');
$this->Controller = new EmailTestController();
$this->Controller->Components->init($this->Controller);
$this->Controller->EmailTest->initialize($this->Controller, array());
App::build(array(
'View' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'View'. DS)
));
}
/**
* tearDown method
*
* @return void
*/
public function tearDown() {
Configure::write('App.encoding', $this->_appEncoding);
App::build();
ClassRegistry::flush();
}
/**
* osFix method
*
* @param string $string
* @return string
*/
function __osFix($string) {
return str_replace(array("\r\n", "\r"), "\n", $string);
}
/**
* testSendFormats method
*
* @return void
*/
public function testSendFormats() {
$this->Controller->EmailTest->to = 'postmaster@example.com';
$this->Controller->EmailTest->from = 'noreply@example.com';
$this->Controller->EmailTest->subject = 'Cake SMTP test';
$this->Controller->EmailTest->replyTo = 'noreply@example.com';
$this->Controller->EmailTest->template = null;
$this->Controller->EmailTest->delivery = 'DebugComp';
$this->Controller->EmailTest->messageId = false;
$date = date(DATE_RFC2822);
$message = <<<MSGBLOC
<pre>To: postmaster@example.com
From: noreply@example.com
Subject: Cake SMTP test
Header:
From: noreply@example.com
Reply-To: noreply@example.com
X-Mailer: CakePHP Email Component
Date: $date
MIME-Version: 1.0
Content-Type: {CONTENTTYPE}
Content-Transfer-Encoding: 7bitMessage:
This is the body of the message
</pre>
MSGBLOC;
$this->Controller->EmailTest->sendAs = 'text';
$expect = str_replace('{CONTENTTYPE}', 'text/plain; charset=UTF-8', $message);
$this->assertTrue($this->Controller->EmailTest->send('This is the body of the message'));
$this->assertEqual(DebugCompTransport::$lastEmail, $this->__osFix($expect));
$this->Controller->EmailTest->sendAs = 'html';
$expect = str_replace('{CONTENTTYPE}', 'text/html; charset=UTF-8', $message);
$this->assertTrue($this->Controller->EmailTest->send('This is the body of the message'));
$this->assertEqual(DebugCompTransport::$lastEmail, $this->__osFix($expect));
// TODO: better test for format of message sent?
$this->Controller->EmailTest->sendAs = 'both';
$expect = str_replace('{CONTENTTYPE}', 'multipart/alternative; boundary="alt-"', $message);
$this->assertTrue($this->Controller->EmailTest->send('This is the body of the message'));
$this->assertEqual(preg_replace('/alt-[a-z0-9]{32}/i', 'alt-', DebugCompTransport::$lastEmail), $this->__osFix($expect));
}
/**
* testTemplates method
*
* @return void
*/
public function testTemplates() {
ClassRegistry::flush();
$this->Controller->EmailTest->to = 'postmaster@example.com';
$this->Controller->EmailTest->from = 'noreply@example.com';
$this->Controller->EmailTest->subject = 'Cake SMTP test';
$this->Controller->EmailTest->replyTo = 'noreply@example.com';
$this->Controller->EmailTest->delivery = 'DebugComp';
$this->Controller->EmailTest->messageId = false;
$date = date(DATE_RFC2822);
$header = <<<HEADBLOC
To: postmaster@example.com
From: noreply@example.com
Subject: Cake SMTP test
Header:
From: noreply@example.com
Reply-To: noreply@example.com
X-Mailer: CakePHP Email Component
Date: $date
MIME-Version: 1.0
Content-Type: {CONTENTTYPE}
Content-Transfer-Encoding: 7bitMessage:
HEADBLOC;
$this->Controller->EmailTest->layout = 'default';
$this->Controller->EmailTest->template = 'default';
$this->Controller->set('title_for_layout', 'Email Test');
$text = <<<TEXTBLOC
This is the body of the message
This email was sent using the CakePHP Framework, http://cakephp.org.
TEXTBLOC;
$html = <<<HTMLBLOC
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN">
<html>
<head>
<title>Email Test</title>
</head>
<body>
<p> This is the body of the message</p><p> </p>
<p>This email was sent using the <a href="http://cakephp.org">CakePHP Framework</a></p>
</body>
</html>
HTMLBLOC;
$this->Controller->EmailTest->sendAs = 'text';
$expect = '<pre>' . str_replace('{CONTENTTYPE}', 'text/plain; charset=UTF-8', $header) . $text . "\n" . '</pre>';
$this->assertTrue($this->Controller->EmailTest->send('This is the body of the message'));
$this->assertEqual(DebugCompTransport::$lastEmail, $this->__osFix($expect));
$this->Controller->EmailTest->sendAs = 'html';
$expect = '<pre>' . str_replace('{CONTENTTYPE}', 'text/html; charset=UTF-8', $header) . $html . "\n" . '</pre>';
$this->assertTrue($this->Controller->EmailTest->send('This is the body of the message'));
$this->assertEqual(DebugCompTransport::$lastEmail, $this->__osFix($expect));
$this->Controller->EmailTest->sendAs = 'both';
$expect = str_replace('{CONTENTTYPE}', 'multipart/alternative; boundary="alt-"', $header);
$expect .= '--alt-' . "\n" . 'Content-Type: text/plain; charset=UTF-8' . "\n" . 'Content-Transfer-Encoding: 7bit' . "\n\n" . $text . "\n\n";
$expect .= '--alt-' . "\n" . 'Content-Type: text/html; charset=UTF-8' . "\n" . 'Content-Transfer-Encoding: 7bit' . "\n\n" . $html . "\n\n";
$expect = '<pre>' . $expect . '--alt---' . "\n\n" . '</pre>';
$this->assertTrue($this->Controller->EmailTest->send('This is the body of the message'));
$this->assertEqual(preg_replace('/alt-[a-z0-9]{32}/i', 'alt-', DebugCompTransport::$lastEmail), $this->__osFix($expect));
$html = <<<HTMLBLOC
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN">
<html>
<head>
<title>Email Test</title>
</head>
<body>
<p> This is the body of the message</p><p> </p>
<p>This email was sent using the CakePHP Framework</p>
</body>
</html>
HTMLBLOC;
$this->Controller->EmailTest->sendAs = 'html';
$expect = '<pre>' . str_replace('{CONTENTTYPE}', 'text/html; charset=UTF-8', $header) . $html . '</pre>';
$this->assertTrue($this->Controller->EmailTest->send('This is the body of the message', 'default', 'thin'));
$this->assertEqual(DebugCompTransport::$lastEmail, $this->__osFix($expect));
}
/**
* test that elements used in email templates get helpers.
*
* @return void
*/
public function testTemplateNestedElements() {
$this->Controller->EmailTest->to = 'postmaster@example.com';
$this->Controller->EmailTest->from = 'noreply@example.com';
$this->Controller->EmailTest->subject = 'Cake SMTP test';
$this->Controller->EmailTest->replyTo = 'noreply@example.com';
$this->Controller->EmailTest->delivery = 'DebugComp';
$this->Controller->EmailTest->messageId = false;
$this->Controller->EmailTest->layout = 'default';
$this->Controller->EmailTest->template = 'nested_element';
$this->Controller->EmailTest->sendAs = 'html';
$this->Controller->helpers = array('Html');
$this->Controller->EmailTest->send();
$result = DebugCompTransport::$lastEmail;
$this->assertPattern('/Test/', $result);
$this->assertPattern('/http\:\/\/example\.com/', $result);
}
/**
* testSendDebug method
*
* @return void
*/
public function testSendDebug() {
$this->Controller->EmailTest->to = 'postmaster@example.com';
$this->Controller->EmailTest->from = 'noreply@example.com';
$this->Controller->EmailTest->cc = 'cc@example.com';
$this->Controller->EmailTest->bcc = 'bcc@example.com';
$this->Controller->EmailTest->subject = 'Cake Debug Test';
$this->Controller->EmailTest->replyTo = 'noreply@example.com';
$this->Controller->EmailTest->template = null;
$this->Controller->EmailTest->delivery = 'DebugComp';
$this->assertTrue($this->Controller->EmailTest->send('This is the body of the message'));
$result = DebugCompTransport::$lastEmail;
$this->assertPattern('/To: postmaster@example.com\n/', $result);
$this->assertPattern('/Subject: Cake Debug Test\n/', $result);
$this->assertPattern('/Reply-To: noreply@example.com\n/', $result);
$this->assertPattern('/From: noreply@example.com\n/', $result);
$this->assertPattern('/Cc: cc@example.com\n/', $result);
$this->assertPattern('/Bcc: bcc@example.com\n/', $result);
$this->assertPattern('/Date: ' . preg_quote(date(DATE_RFC2822)) . '\n/', $result);
$this->assertPattern('/X-Mailer: CakePHP Email Component\n/', $result);
$this->assertPattern('/Content-Type: text\/plain; charset=UTF-8\n/', $result);
$this->assertPattern('/Content-Transfer-Encoding: 7bitMessage:\n/', $result);
$this->assertPattern('/This is the body of the message/', $result);
}
/**
* test send with delivery = debug and not using sessions.
*
* @return void
*/
public function testSendDebugWithNoSessions() {
$session = $this->Controller->Session;
unset($this->Controller->Session);
$this->Controller->EmailTest->to = 'postmaster@example.com';
$this->Controller->EmailTest->from = 'noreply@example.com';
$this->Controller->EmailTest->subject = 'Cake Debug Test';
$this->Controller->EmailTest->replyTo = 'noreply@example.com';
$this->Controller->EmailTest->template = null;
$this->Controller->EmailTest->delivery = 'DebugComp';
$this->Controller->EmailTest->send('This is the body of the message');
$result = DebugCompTransport::$lastEmail;
$this->assertPattern('/To: postmaster@example.com\n/', $result);
$this->assertPattern('/Subject: Cake Debug Test\n/', $result);
$this->assertPattern('/Reply-To: noreply@example.com\n/', $result);
$this->assertPattern('/From: noreply@example.com\n/', $result);
$this->assertPattern('/Date: ' . preg_quote(date(DATE_RFC2822)) . '\n/', $result);
$this->assertPattern('/X-Mailer: CakePHP Email Component\n/', $result);
$this->assertPattern('/Content-Type: text\/plain; charset=UTF-8\n/', $result);
$this->assertPattern('/Content-Transfer-Encoding: 7bitMessage:\n/', $result);
$this->assertPattern('/This is the body of the message/', $result);
$this->Controller->Session = $session;
}
/**
* testMessageRetrievalWithoutTemplate method
*
* @return void
*/
public function testMessageRetrievalWithoutTemplate() {
App::build(array(
'View' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'View'. DS)
));
$this->Controller->EmailTest->to = 'postmaster@example.com';
$this->Controller->EmailTest->from = 'noreply@example.com';
$this->Controller->EmailTest->subject = 'Cake Debug Test';
$this->Controller->EmailTest->replyTo = 'noreply@example.com';
$this->Controller->EmailTest->layout = 'default';
$this->Controller->EmailTest->template = null;
$this->Controller->EmailTest->delivery = 'DebugComp';
$text = $html = 'This is the body of the message';
$this->Controller->EmailTest->sendAs = 'both';
$this->assertTrue($this->Controller->EmailTest->send('This is the body of the message'));
$this->assertEqual($this->Controller->EmailTest->textMessage, $this->__osFix($text));
$this->assertEqual($this->Controller->EmailTest->htmlMessage, $this->__osFix($html));
$this->Controller->EmailTest->sendAs = 'text';
$this->assertTrue($this->Controller->EmailTest->send('This is the body of the message'));
$this->assertEqual($this->Controller->EmailTest->textMessage, $this->__osFix($text));
$this->assertNull($this->Controller->EmailTest->htmlMessage);
$this->Controller->EmailTest->sendAs = 'html';
$this->assertTrue($this->Controller->EmailTest->send('This is the body of the message'));
$this->assertNull($this->Controller->EmailTest->textMessage);
$this->assertEqual($this->Controller->EmailTest->htmlMessage, $this->__osFix($html));
}
/**
* testMessageRetrievalWithTemplate method
*
* @return void
*/
public function testMessageRetrievalWithTemplate() {
App::build(array(
'View' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'View'. DS)
));
$this->Controller->set('value', 22091985);
$this->Controller->set('title_for_layout', 'EmailTest');
$this->Controller->EmailTest->to = 'postmaster@example.com';
$this->Controller->EmailTest->from = 'noreply@example.com';
$this->Controller->EmailTest->subject = 'Cake Debug Test';
$this->Controller->EmailTest->replyTo = 'noreply@example.com';
$this->Controller->EmailTest->layout = 'default';
$this->Controller->EmailTest->template = 'custom';
$this->Controller->EmailTest->delivery = 'DebugComp';
$text = <<<TEXTBLOC
Here is your value: 22091985
This email was sent using the CakePHP Framework, http://cakephp.org.
TEXTBLOC;
$html = <<<HTMLBLOC
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN">
<html>
<head>
<title>EmailTest</title>
</head>
<body>
<p>Here is your value: <b>22091985</b></p>
<p>This email was sent using the <a href="http://cakephp.org">CakePHP Framework</a></p>
</body>
</html>
HTMLBLOC;
$this->Controller->EmailTest->sendAs = 'both';
$this->assertTrue($this->Controller->EmailTest->send());
$this->assertEqual($this->Controller->EmailTest->textMessage, $this->__osFix($text));
$this->assertEqual($this->Controller->EmailTest->htmlMessage, $this->__osFix($html));
$this->Controller->EmailTest->sendAs = 'text';
$this->assertTrue($this->Controller->EmailTest->send());
$this->assertEqual($this->Controller->EmailTest->textMessage, $this->__osFix($text));
$this->assertNull($this->Controller->EmailTest->htmlMessage);
$this->Controller->EmailTest->sendAs = 'html';
$this->assertTrue($this->Controller->EmailTest->send());
$this->assertNull($this->Controller->EmailTest->textMessage);
$this->assertEqual($this->Controller->EmailTest->htmlMessage, $this->__osFix($html));
}
/**
* testMessageRetrievalWithHelper method
*
* @return void
*/
public function testMessageRetrievalWithHelper() {
App::build(array(
'View' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'View'. DS)
));
$timestamp = time();
$this->Controller->set('time', $timestamp);
$this->Controller->set('title_for_layout', 'EmailTest');
$this->Controller->helpers = array('Time');
$this->Controller->EmailTest->to = 'postmaster@example.com';
$this->Controller->EmailTest->from = 'noreply@example.com';
$this->Controller->EmailTest->subject = 'Cake Debug Test';
$this->Controller->EmailTest->replyTo = 'noreply@example.com';
$this->Controller->EmailTest->layout = 'default';
$this->Controller->EmailTest->template = 'custom_helper';
$this->Controller->EmailTest->sendAs = 'text';
$this->Controller->EmailTest->delivery = 'DebugComp';
$this->assertTrue($this->Controller->EmailTest->send());
$this->assertTrue((bool)strpos($this->Controller->EmailTest->textMessage, 'Right now: ' . date('Y-m-d\TH:i:s\Z', $timestamp)));
}
/**
* testContentArray method
*
* @return void
*/
public function testSendContentArray() {
$this->Controller->EmailTest->to = 'postmaster@example.com';
$this->Controller->EmailTest->from = 'noreply@example.com';
$this->Controller->EmailTest->subject = 'Cake Debug Test';
$this->Controller->EmailTest->replyTo = 'noreply@example.com';
$this->Controller->EmailTest->template = null;
$this->Controller->EmailTest->delivery = 'DebugComp';
$content = array('First line', 'Second line', 'Third line');
$this->assertTrue($this->Controller->EmailTest->send($content));
$result = DebugCompTransport::$lastEmail;
$this->assertPattern('/To: postmaster@example.com\n/', $result);
$this->assertPattern('/Subject: Cake Debug Test\n/', $result);
$this->assertPattern('/Reply-To: noreply@example.com\n/', $result);
$this->assertPattern('/From: noreply@example.com\n/', $result);
$this->assertPattern('/X-Mailer: CakePHP Email Component\n/', $result);
$this->assertPattern('/Content-Type: text\/plain; charset=UTF-8\n/', $result);
$this->assertPattern('/Content-Transfer-Encoding: 7bitMessage:\n/', $result);
$this->assertPattern('/First line\n/', $result);
$this->assertPattern('/Second line\n/', $result);
$this->assertPattern('/Third line\n/', $result);
}
/**
* test setting a custom date.
*
* @return void
*/
public function testDateProperty() {
$this->Controller->EmailTest->to = 'postmaster@example.com';
$this->Controller->EmailTest->from = 'noreply@example.com';
$this->Controller->EmailTest->subject = 'Cake Debug Test';
$this->Controller->EmailTest->date = 'Today!';
$this->Controller->EmailTest->template = null;
$this->Controller->EmailTest->delivery = 'DebugComp';
$this->assertTrue($this->Controller->EmailTest->send('test message'));
$result = DebugCompTransport::$lastEmail;
$this->assertPattern('/Date: Today!\n/', $result);
}
/**
* testContentStripping method
*
* @return void
*/
public function testContentStripping() {
$content = "Previous content\n--alt-\nContent-TypeContent-Type:: text/html; charsetcharset==utf-8\nContent-Transfer-Encoding: 7bit";
$content .= "\n\n<p>My own html content</p>";
$result = $this->Controller->EmailTest->strip($content, true);
$expected = "Previous content\n--alt-\n text/html; utf-8\n 7bit\n\n<p>My own html content</p>";
$this->assertEqual($expected, $result);
$content = '<p>Some HTML content with an <a href="mailto:test@example.com">email link</a>';
$result = $this->Controller->EmailTest->strip($content, true);
$expected = $content;
$this->assertEqual($expected, $result);
$content = '<p>Some HTML content with an ';
$content .= '<a href="mailto:test@example.com,test2@example.com">email link</a>';
$result = $this->Controller->EmailTest->strip($content, true);
$expected = $content;
$this->assertEqual($expected, $result);
}
/**
* test that the _encode() will set mb_internal_encoding.
*
* @return void
*/
public function test_encodeSettingInternalCharset() {
$this->skipIf(!function_exists('mb_internal_encoding'), 'Missing mb_* functions, cannot run test.');
$restore = mb_internal_encoding();
mb_internal_encoding('ISO-8859-1');
$this->Controller->charset = 'UTF-8';
$this->Controller->EmailTest->to = 'postmaster@example.com';
$this->Controller->EmailTest->from = 'noreply@example.com';
$this->Controller->EmailTest->subject = 'هذه رسالة بعنوان طويل مرسل للمستلم';
$this->Controller->EmailTest->replyTo = 'noreply@example.com';
$this->Controller->EmailTest->template = null;
$this->Controller->EmailTest->delivery = 'DebugComp';
$this->Controller->EmailTest->sendAs = 'text';
$this->assertTrue($this->Controller->EmailTest->send('This is the body of the message'));
$subject = '=?UTF-8?B?2YfYsNmHINix2LPYp9mE2Kkg2KjYudmG2YjYp9mGINi32YjZitmEINmF2LE=?=' . "\r\n" . ' =?UTF-8?B?2LPZhCDZhNmE2YXYs9iq2YTZhQ==?=';
preg_match('/Subject: (.*)Header:/s', DebugCompTransport::$lastEmail, $matches);
$this->assertEqual(trim($matches[1]), $subject);
$result = mb_internal_encoding();
$this->assertEqual($result, 'ISO-8859-1');
mb_internal_encoding($restore);
}
/**
* testMultibyte method
*
* @return void
*/
public function testMultibyte() {
$this->Controller->charset = 'UTF-8';
$this->Controller->EmailTest->to = 'postmaster@example.com';
$this->Controller->EmailTest->from = 'noreply@example.com';
$this->Controller->EmailTest->subject = 'هذه رسالة بعنوان طويل مرسل للمستلم';
$this->Controller->EmailTest->replyTo = 'noreply@example.com';
$this->Controller->EmailTest->template = null;
$this->Controller->EmailTest->delivery = 'DebugComp';
$subject = '=?UTF-8?B?2YfYsNmHINix2LPYp9mE2Kkg2KjYudmG2YjYp9mGINi32YjZitmEINmF2LE=?=' . "\r\n" . ' =?UTF-8?B?2LPZhCDZhNmE2YXYs9iq2YTZhQ==?=';
$this->Controller->EmailTest->sendAs = 'text';
$this->assertTrue($this->Controller->EmailTest->send('This is the body of the message'));
preg_match('/Subject: (.*)Header:/s', DebugCompTransport::$lastEmail, $matches);
$this->assertEqual(trim($matches[1]), $subject);
$this->Controller->EmailTest->sendAs = 'html';
$this->assertTrue($this->Controller->EmailTest->send('This is the body of the message'));
preg_match('/Subject: (.*)Header:/s', DebugCompTransport::$lastEmail, $matches);
$this->assertEqual(trim($matches[1]), $subject);
$this->Controller->EmailTest->sendAs = 'both';
$this->assertTrue($this->Controller->EmailTest->send('This is the body of the message'));
preg_match('/Subject: (.*)Header:/s', DebugCompTransport::$lastEmail, $matches);
$this->assertEqual(trim($matches[1]), $subject);
}
/**
* undocumented function
*
* @return void
*/
public function testSendWithAttachments() {
$this->Controller->EmailTest->to = 'postmaster@example.com';
$this->Controller->EmailTest->from = 'noreply@example.com';
$this->Controller->EmailTest->subject = 'Attachment Test';
$this->Controller->EmailTest->replyTo = 'noreply@example.com';
$this->Controller->EmailTest->template = null;
$this->Controller->EmailTest->delivery = 'DebugComp';
$this->Controller->EmailTest->attachments = array(
__FILE__,
'some-name.php' => __FILE__
);
$body = '<p>This is the body of the message</p>';
$this->Controller->EmailTest->sendAs = 'text';
$this->assertTrue($this->Controller->EmailTest->send($body));
$msg = DebugCompTransport::$lastEmail;
$this->assertPattern('/' . preg_quote('Content-Disposition: attachment; filename="EmailComponentTest.php"') . '/', $msg);
$this->assertPattern('/' . preg_quote('Content-Disposition: attachment; filename="some-name.php"') . '/', $msg);
}
/**
* testSendAsIsNotIgnoredIfAttachmentsPresent method
*
* @return void
*/
public function testSendAsIsNotIgnoredIfAttachmentsPresent() {
$this->Controller->EmailTest->to = 'postmaster@example.com';
$this->Controller->EmailTest->from = 'noreply@example.com';
$this->Controller->EmailTest->subject = 'Attachment Test';
$this->Controller->EmailTest->replyTo = 'noreply@example.com';
$this->Controller->EmailTest->template = null;
$this->Controller->EmailTest->delivery = 'DebugComp';
$this->Controller->EmailTest->attachments = array(__FILE__);
$body = '<p>This is the body of the message</p>';
$this->Controller->EmailTest->sendAs = 'html';
$this->assertTrue($this->Controller->EmailTest->send($body));
$msg = DebugCompTransport::$lastEmail;
$this->assertNoPattern('/text\/plain/', $msg);
$this->assertPattern('/text\/html/', $msg);
$this->Controller->EmailTest->sendAs = 'text';
$this->assertTrue($this->Controller->EmailTest->send($body));
$msg = DebugCompTransport::$lastEmail;
$this->assertPattern('/text\/plain/', $msg);
$this->assertNoPattern('/text\/html/', $msg);
$this->Controller->EmailTest->sendAs = 'both';
$this->assertTrue($this->Controller->EmailTest->send($body));
$msg = DebugCompTransport::$lastEmail;
$this->assertNoPattern('/text\/plain/', $msg);
$this->assertNoPattern('/text\/html/', $msg);
$this->assertPattern('/multipart\/alternative/', $msg);
}
/**
* testNoDoubleNewlinesInHeaders function
*
* @return void
*/
public function testNoDoubleNewlinesInHeaders() {
$this->Controller->EmailTest->to = 'postmaster@example.com';
$this->Controller->EmailTest->from = 'noreply@example.com';
$this->Controller->EmailTest->subject = 'Attachment Test';
$this->Controller->EmailTest->replyTo = 'noreply@example.com';
$this->Controller->EmailTest->template = null;
$this->Controller->EmailTest->delivery = 'DebugComp';
$body = '<p>This is the body of the message</p>';
$this->Controller->EmailTest->sendAs = 'both';
$this->assertTrue($this->Controller->EmailTest->send($body));
$msg = DebugCompTransport::$lastEmail;
$this->assertNoPattern('/\n\nContent-Transfer-Encoding/', $msg);
$this->assertPattern('/\nContent-Transfer-Encoding/', $msg);
}
/**
* testReset method
*
* @return void
*/
public function testReset() {
$this->Controller->EmailTest->template = 'default';
$this->Controller->EmailTest->to = 'test.recipient@example.com';
$this->Controller->EmailTest->from = 'test.sender@example.com';
$this->Controller->EmailTest->replyTo = 'test.replyto@example.com';
$this->Controller->EmailTest->return = 'test.return@example.com';
$this->Controller->EmailTest->cc = array('cc1@example.com', 'cc2@example.com');
$this->Controller->EmailTest->bcc = array('bcc1@example.com', 'bcc2@example.com');
$this->Controller->EmailTest->date = 'Today!';
$this->Controller->EmailTest->subject = 'Test subject';
$this->Controller->EmailTest->additionalParams = 'X-additional-header';
$this->Controller->EmailTest->delivery = 'smtp';
$this->Controller->EmailTest->smtpOptions['host'] = 'blah';
$this->Controller->EmailTest->smtpOptions['timeout'] = 0.2;
$this->Controller->EmailTest->attachments = array('attachment1', 'attachment2');
$this->Controller->EmailTest->textMessage = 'This is the body of the message';
$this->Controller->EmailTest->htmlMessage = 'This is the body of the message';
$this->Controller->EmailTest->messageId = false;
try {
$this->Controller->EmailTest->send('Should not work');
$this->fail('No exception');
} catch (SocketException $e) {
$this->assertTrue(true, 'SocketException raised');
}
$this->Controller->EmailTest->reset();
$this->assertNull($this->Controller->EmailTest->template);
$this->assertIdentical($this->Controller->EmailTest->to, array());
$this->assertNull($this->Controller->EmailTest->from);
$this->assertNull($this->Controller->EmailTest->replyTo);
$this->assertNull($this->Controller->EmailTest->return);
$this->assertIdentical($this->Controller->EmailTest->cc, array());
$this->assertIdentical($this->Controller->EmailTest->bcc, array());
$this->assertNull($this->Controller->EmailTest->date);
$this->assertNull($this->Controller->EmailTest->subject);
$this->assertNull($this->Controller->EmailTest->additionalParams);
$this->assertNull($this->Controller->EmailTest->smtpError);
$this->assertIdentical($this->Controller->EmailTest->attachments, array());
$this->assertNull($this->Controller->EmailTest->textMessage);
$this->assertTrue($this->Controller->EmailTest->messageId);
}
public function testPluginCustomViewClass() {
App::build(array(
'plugins' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS),
'View' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'View'. DS)
));
$this->Controller->view = 'TestPlugin.Email';
$this->Controller->EmailTest->to = 'postmaster@example.com';
$this->Controller->EmailTest->from = 'noreply@example.com';
$this->Controller->EmailTest->subject = 'CustomViewClass test';
$this->Controller->EmailTest->delivery = 'DebugComp';
$body = 'Body of message';
$this->assertTrue($this->Controller->EmailTest->send($body));
$result = DebugCompTransport::$lastEmail;
$this->assertPattern('/Body of message/', $result);
}
/**
* testStartup method
*
* @return void
*/
public function testStartup() {
$this->assertNull($this->Controller->EmailTest->startup($this->Controller));
}
/**
* testMessageId method
*
* @return void
*/
public function testMessageId() {
$this->Controller->EmailTest->to = 'postmaster@example.com';
$this->Controller->EmailTest->from = 'noreply@example.com';
$this->Controller->EmailTest->subject = 'Cake Debug Test';
$this->Controller->EmailTest->replyTo = 'noreply@example.com';
$this->Controller->EmailTest->template = null;
$this->Controller->EmailTest->delivery = 'DebugComp';
$this->assertTrue($this->Controller->EmailTest->send('This is the body of the message'));
$result = DebugCompTransport::$lastEmail;
$this->assertPattern('/Message-ID: \<[a-f0-9]{8}[a-f0-9]{4}[a-f0-9]{4}[a-f0-9]{4}[a-f0-9]{12}@' . env('HTTP_HOST') . '\>\n/', $result);
$this->Controller->EmailTest->messageId = '<22091985.998877@example.com>';
$this->assertTrue($this->Controller->EmailTest->send('This is the body of the message'));
$result = DebugCompTransport::$lastEmail;
$this->assertPattern('/Message-ID: <22091985.998877@example.com>\n/', $result);
$this->Controller->EmailTest->messageId = false;
$this->assertTrue($this->Controller->EmailTest->send('This is the body of the message'));
$result = DebugCompTransport::$lastEmail;
$this->assertNoPattern('/Message-ID:/', $result);
}
}
| 0001-bee | trunk/cakephp2/lib/Cake/Test/Case/Controller/Component/EmailComponentTest.php | PHP | gpl3 | 30,819 |
<?php
/**
* CookieComponentTest file
*
* PHP 5
*
* CakePHP(tm) Tests <http://book.cakephp.org/view/1196/Testing>
* Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice
*
* @copyright Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://book.cakephp.org/view/1196/Testing CakePHP(tm) Tests
* @package Cake.Test.Case.Controller.Component
* @since CakePHP(tm) v 1.2.0.5435
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
App::uses('Component', 'Controller');
App::uses('Controller', 'Controller');
App::uses('CookieComponent', 'Controller/Component');
/**
* CookieComponentTestController class
*
* @package Cake.Test.Case.Controller.Component
*/
class CookieComponentTestController extends Controller {
/**
* components property
*
* @var array
*/
public $components = array('Cookie');
/**
* beforeFilter method
*
* @return void
*/
public function beforeFilter() {
$this->Cookie->name = 'CakeTestCookie';
$this->Cookie->time = 10;
$this->Cookie->path = '/';
$this->Cookie->domain = '';
$this->Cookie->secure = false;
$this->Cookie->key = 'somerandomhaskey';
}
}
/**
* CookieComponentTest class
*
* @package Cake.Test.Case.Controller.Component
*/
class CookieComponentTest extends CakeTestCase {
/**
* Controller property
*
* @var CookieComponentTestController
*/
public $Controller;
/**
* start
*
* @return void
*/
public function setUp() {
$_COOKIE = array();
$Collection = new ComponentCollection();
$this->Cookie = $this->getMock('CookieComponent', array('_setcookie'), array($Collection));
$this->Controller = new CookieComponentTestController();
$this->Cookie->initialize($this->Controller);
$this->Cookie->name = 'CakeTestCookie';
$this->Cookie->time = 10;
$this->Cookie->path = '/';
$this->Cookie->domain = '';
$this->Cookie->secure = false;
$this->Cookie->key = 'somerandomhaskey';
$this->Cookie->startup($this->Controller);
}
/**
* end
*
* @return void
*/
public function tearDown() {
$this->Cookie->destroy();
}
/**
* sets up some default cookie data.
*
* @return void
*/
protected function _setCookieData() {
$this->Cookie->write(array('Encrytped_array' => array('name' => 'CakePHP', 'version' => '1.2.0.x', 'tag' =>'CakePHP Rocks!')));
$this->Cookie->write(array('Encrytped_multi_cookies.name' => 'CakePHP'));
$this->Cookie->write(array('Encrytped_multi_cookies.version' => '1.2.0.x'));
$this->Cookie->write(array('Encrytped_multi_cookies.tag' => 'CakePHP Rocks!'));
$this->Cookie->write(array('Plain_array' => array('name' => 'CakePHP', 'version' => '1.2.0.x', 'tag' =>'CakePHP Rocks!')), null, false);
$this->Cookie->write(array('Plain_multi_cookies.name' => 'CakePHP'), null, false);
$this->Cookie->write(array('Plain_multi_cookies.version' => '1.2.0.x'), null, false);
$this->Cookie->write(array('Plain_multi_cookies.tag' => 'CakePHP Rocks!'), null, false);
}
/**
* test that initialize sets settings from components array
*
* @return void
*/
public function testSettings() {
$settings = array(
'time' => '5 days',
'path' => '/'
);
$Cookie = new CookieComponent(new ComponentCollection(), $settings);
$this->assertEqual($Cookie->time, $settings['time']);
$this->assertEqual($Cookie->path, $settings['path']);
}
/**
* testCookieName
*
* @return void
*/
public function testCookieName() {
$this->assertEqual($this->Cookie->name, 'CakeTestCookie');
}
/**
* testReadEncryptedCookieData
*
* @return void
*/
public function testReadEncryptedCookieData() {
$this->_setCookieData();
$data = $this->Cookie->read('Encrytped_array');
$expected = array('name' => 'CakePHP', 'version' => '1.2.0.x', 'tag' =>'CakePHP Rocks!');
$this->assertEqual($data, $expected);
$data = $this->Cookie->read('Encrytped_multi_cookies');
$expected = array('name' => 'CakePHP', 'version' => '1.2.0.x', 'tag' =>'CakePHP Rocks!');
$this->assertEqual($data, $expected);
}
/**
* testReadPlainCookieData
*
* @return void
*/
public function testReadPlainCookieData() {
$this->_setCookieData();
$data = $this->Cookie->read('Plain_array');
$expected = array('name' => 'CakePHP', 'version' => '1.2.0.x', 'tag' =>'CakePHP Rocks!');
$this->assertEqual($data, $expected);
$data = $this->Cookie->read('Plain_multi_cookies');
$expected = array('name' => 'CakePHP', 'version' => '1.2.0.x', 'tag' =>'CakePHP Rocks!');
$this->assertEqual($data, $expected);
}
/**
* test a simple write()
*
* @return void
*/
public function testWriteSimple() {
$this->Cookie->expects($this->once())->method('_setcookie');
$this->Cookie->write('Testing', 'value');
$result = $this->Cookie->read('Testing');
$this->assertEquals('value', $result);
}
/**
* test write with httpOnly cookies
*
* @return void
*/
public function testWriteHttpOnly() {
$this->Cookie->httpOnly = true;
$this->Cookie->secure = false;
$this->Cookie->expects($this->once())->method('_setcookie')
->with('CakeTestCookie[Testing]', 'value', time() + 10, '/', '', false, true);
$this->Cookie->write('Testing', 'value', false);
}
/**
* test delete with httpOnly
*
* @return void
*/
public function testDeleteHttpOnly() {
$this->Cookie->httpOnly = true;
$this->Cookie->secure = false;
$this->Cookie->expects($this->once())->method('_setcookie')
->with('CakeTestCookie[Testing]', '', time() - 42000, '/', '', false, true);
$this->Cookie->delete('Testing', false);
}
/**
* testWritePlainCookieArray
*
* @return void
*/
public function testWritePlainCookieArray() {
$this->Cookie->write(array('name' => 'CakePHP', 'version' => '1.2.0.x', 'tag' => 'CakePHP Rocks!'), null, false);
$this->assertEqual($this->Cookie->read('name'), 'CakePHP');
$this->assertEqual($this->Cookie->read('version'), '1.2.0.x');
$this->assertEqual($this->Cookie->read('tag'), 'CakePHP Rocks!');
$this->Cookie->delete('name');
$this->Cookie->delete('version');
$this->Cookie->delete('tag');
}
/**
* test writing values that are not scalars
*
* @return void
*/
public function testWriteArrayValues() {
$this->Cookie->secure = false;
$this->Cookie->expects($this->once())->method('_setcookie')
->with('CakeTestCookie[Testing]', '[1,2,3]', time() + 10, '/', '', false, false);
$this->Cookie->write('Testing', array(1, 2, 3), false);
}
/**
* testReadingCookieValue
*
* @return void
*/
public function testReadingCookieValue() {
$this->_setCookieData();
$data = $this->Cookie->read();
$expected = array(
'Encrytped_array' => array(
'name' => 'CakePHP',
'version' => '1.2.0.x',
'tag' => 'CakePHP Rocks!'),
'Encrytped_multi_cookies' => array(
'name' => 'CakePHP',
'version' => '1.2.0.x',
'tag' => 'CakePHP Rocks!'),
'Plain_array' => array(
'name' => 'CakePHP',
'version' => '1.2.0.x',
'tag' => 'CakePHP Rocks!'),
'Plain_multi_cookies' => array(
'name' => 'CakePHP',
'version' => '1.2.0.x',
'tag' => 'CakePHP Rocks!'));
$this->assertEqual($data, $expected);
}
/**
* testDeleteCookieValue
*
* @return void
*/
public function testDeleteCookieValue() {
$this->_setCookieData();
$this->Cookie->delete('Encrytped_multi_cookies.name');
$data = $this->Cookie->read('Encrytped_multi_cookies');
$expected = array('version' => '1.2.0.x', 'tag' =>'CakePHP Rocks!');
$this->assertEqual($data, $expected);
$this->Cookie->delete('Encrytped_array');
$data = $this->Cookie->read('Encrytped_array');
$this->assertNull($data);
$this->Cookie->delete('Plain_multi_cookies.name');
$data = $this->Cookie->read('Plain_multi_cookies');
$expected = array('version' => '1.2.0.x', 'tag' =>'CakePHP Rocks!');
$this->assertEqual($data, $expected);
$this->Cookie->delete('Plain_array');
$data = $this->Cookie->read('Plain_array');
$this->assertNull($data);
}
/**
* testReadingCookieArray
*
* @return void
*/
public function testReadingCookieArray() {
$this->_setCookieData();
$data = $this->Cookie->read('Encrytped_array.name');
$expected = 'CakePHP';
$this->assertEqual($data, $expected);
$data = $this->Cookie->read('Encrytped_array.version');
$expected = '1.2.0.x';
$this->assertEqual($data, $expected);
$data = $this->Cookie->read('Encrytped_array.tag');
$expected = 'CakePHP Rocks!';
$this->assertEqual($data, $expected);
$data = $this->Cookie->read('Encrytped_multi_cookies.name');
$expected = 'CakePHP';
$this->assertEqual($data, $expected);
$data = $this->Cookie->read('Encrytped_multi_cookies.version');
$expected = '1.2.0.x';
$this->assertEqual($data, $expected);
$data = $this->Cookie->read('Encrytped_multi_cookies.tag');
$expected = 'CakePHP Rocks!';
$this->assertEqual($data, $expected);
$data = $this->Cookie->read('Plain_array.name');
$expected = 'CakePHP';
$this->assertEqual($data, $expected);
$data = $this->Cookie->read('Plain_array.version');
$expected = '1.2.0.x';
$this->assertEqual($data, $expected);
$data = $this->Cookie->read('Plain_array.tag');
$expected = 'CakePHP Rocks!';
$this->assertEqual($data, $expected);
$data = $this->Cookie->read('Plain_multi_cookies.name');
$expected = 'CakePHP';
$this->assertEqual($data, $expected);
$data = $this->Cookie->read('Plain_multi_cookies.version');
$expected = '1.2.0.x';
$this->assertEqual($data, $expected);
$data = $this->Cookie->read('Plain_multi_cookies.tag');
$expected = 'CakePHP Rocks!';
$this->assertEqual($data, $expected);
}
/**
* testReadingCookieDataOnStartup
*
* @return void
*/
public function testReadingCookieDataOnStartup() {
$data = $this->Cookie->read('Encrytped_array');
$this->assertNull($data);
$data = $this->Cookie->read('Encrytped_multi_cookies');
$this->assertNull($data);
$data = $this->Cookie->read('Plain_array');
$this->assertNull($data);
$data = $this->Cookie->read('Plain_multi_cookies');
$this->assertNull($data);
$_COOKIE['CakeTestCookie'] = array(
'Encrytped_array' => $this->__encrypt(array('name' => 'CakePHP', 'version' => '1.2.0.x', 'tag' =>'CakePHP Rocks!')),
'Encrytped_multi_cookies' => array(
'name' => $this->__encrypt('CakePHP'),
'version' => $this->__encrypt('1.2.0.x'),
'tag' => $this->__encrypt('CakePHP Rocks!')),
'Plain_array' => '{"name":"CakePHP","version":"1.2.0.x","tag":"CakePHP Rocks!"}',
'Plain_multi_cookies' => array(
'name' => 'CakePHP',
'version' => '1.2.0.x',
'tag' => 'CakePHP Rocks!'));
$this->Cookie->startup(null);
$data = $this->Cookie->read('Encrytped_array');
$expected = array('name' => 'CakePHP', 'version' => '1.2.0.x', 'tag' =>'CakePHP Rocks!');
$this->assertEquals($expected, $data);
$data = $this->Cookie->read('Encrytped_multi_cookies');
$expected = array('name' => 'CakePHP', 'version' => '1.2.0.x', 'tag' =>'CakePHP Rocks!');
$this->assertEquals($expected, $data);
$data = $this->Cookie->read('Plain_array');
$expected = array('name' => 'CakePHP', 'version' => '1.2.0.x', 'tag' =>'CakePHP Rocks!');
$this->assertEquals($expected, $data);
$data = $this->Cookie->read('Plain_multi_cookies');
$expected = array('name' => 'CakePHP', 'version' => '1.2.0.x', 'tag' =>'CakePHP Rocks!');
$this->assertEquals($expected, $data);
$this->Cookie->destroy();
unset($_COOKIE['CakeTestCookie']);
}
/**
* testReadingCookieDataWithoutStartup
*
* @return void
*/
public function testReadingCookieDataWithoutStartup() {
$data = $this->Cookie->read('Encrytped_array');
$expected = null;
$this->assertEquals($expected, $data);
$data = $this->Cookie->read('Encrytped_multi_cookies');
$expected = null;
$this->assertEquals($expected, $data);
$data = $this->Cookie->read('Plain_array');
$expected = null;
$this->assertEquals($expected, $data);
$data = $this->Cookie->read('Plain_multi_cookies');
$expected = null;
$this->assertEquals($expected, $data);
$_COOKIE['CakeTestCookie'] = array(
'Encrytped_array' => $this->__encrypt(array('name' => 'CakePHP', 'version' => '1.2.0.x', 'tag' =>'CakePHP Rocks!')),
'Encrytped_multi_cookies' => array(
'name' => $this->__encrypt('CakePHP'),
'version' => $this->__encrypt('1.2.0.x'),
'tag' => $this->__encrypt('CakePHP Rocks!')),
'Plain_array' => '{"name":"CakePHP","version":"1.2.0.x","tag":"CakePHP Rocks!"}',
'Plain_multi_cookies' => array(
'name' => 'CakePHP',
'version' => '1.2.0.x',
'tag' => 'CakePHP Rocks!'));
$data = $this->Cookie->read('Encrytped_array');
$expected = array('name' => 'CakePHP', 'version' => '1.2.0.x', 'tag' =>'CakePHP Rocks!');
$this->assertEquals($expected, $data);
$data = $this->Cookie->read('Encrytped_multi_cookies');
$expected = array('name' => 'CakePHP', 'version' => '1.2.0.x', 'tag' =>'CakePHP Rocks!');
$this->assertEquals($expected, $data);
$data = $this->Cookie->read('Plain_array');
$expected = array('name' => 'CakePHP', 'version' => '1.2.0.x', 'tag' =>'CakePHP Rocks!');
$this->assertEquals($expected, $data);
$data = $this->Cookie->read('Plain_multi_cookies');
$expected = array('name' => 'CakePHP', 'version' => '1.2.0.x', 'tag' =>'CakePHP Rocks!');
$this->assertEquals($expected, $data);
$this->Cookie->destroy();
unset($_COOKIE['CakeTestCookie']);
}
/**
* Test Reading legacy cookie values.
*
* @return void
*/
public function testReadLegacyCookieValue() {
$_COOKIE['CakeTestCookie'] = array(
'Legacy' => array('value' => $this->_oldImplode(array(1, 2, 3)))
);
$result = $this->Cookie->read('Legacy.value');
$expected = array(1, 2, 3);
$this->assertEquals($expected, $result);
}
/**
* test that no error is issued for non array data.
*
* @return void
*/
public function testNoErrorOnNonArrayData() {
$this->Cookie->destroy();
$_COOKIE['CakeTestCookie'] = 'kaboom';
$this->assertNull($this->Cookie->read('value'));
}
/**
* test that deleting a top level keys kills the child elements too.
*
* @return void
*/
public function testDeleteRemovesChildren() {
$_COOKIE['CakeTestCookie'] = array(
'User' => array('email' => 'example@example.com', 'name' => 'mark'),
'other' => 'value'
);
$this->assertEqual('mark', $this->Cookie->read('User.name'));
$this->Cookie->delete('User');
$this->assertNull($this->Cookie->read('User.email'));
$this->Cookie->destroy();
}
/**
* Test deleting recursively with keys that don't exist.
*
* @return void
*/
function testDeleteChildrenNotExist() {
$this->assertNull($this->Cookie->delete('NotFound'));
$this->assertNull($this->Cookie->delete('Not.Found'));
}
/**
* Helper method for generating old style encoded cookie values.
*
* @return string.
*/
protected function _oldImplode(array $array) {
$string = '';
foreach ($array as $key => $value) {
$string .= ',' . $key . '|' . $value;
}
return substr($string, 1);
}
/**
* Implode method to keep keys are multidimensional arrays
*
* @param array $array Map of key and values
* @return string String in the form key1|value1,key2|value2
*/
protected function _implode(array $array) {
return json_encode($array);
}
/**
* encrypt method
*
* @param mixed $value
* @return string
*/
function __encrypt($value) {
if (is_array($value)) {
$value = $this->_implode($value);
}
return "Q2FrZQ==." . base64_encode(Security::cipher($value, $this->Cookie->key));
}
}
| 0001-bee | trunk/cakephp2/lib/Cake/Test/Case/Controller/Component/CookieComponentTest.php | PHP | gpl3 | 15,589 |
<?php
/**
* DbAclTest file.
*
* PHP 5
*
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
* Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://cakephp.org CakePHP(tm) Project
* @package Cake.Test.Case.Controller.Component
* @since CakePHP(tm) v 2.0
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
App::uses('AclComponent', 'Controller/Component');
App::uses('AclNode', 'Model');
class_exists('AclComponent');
/**
* AclNodeTwoTestBase class
*
* @package Cake.Test.Case.Controller.Component
*/
class AclNodeTwoTestBase extends AclNode {
/**
* useDbConfig property
*
* @var string 'test'
*/
public $useDbConfig = 'test';
/**
* cacheSources property
*
* @var bool false
*/
public $cacheSources = false;
}
/**
* AroTwoTest class
*
* @package Cake.Test.Case.Controller.Component
*/
class AroTwoTest extends AclNodeTwoTestBase {
/**
* name property
*
* @var string 'AroTwoTest'
*/
public $name = 'AroTwoTest';
/**
* useTable property
*
* @var string 'aro_twos'
*/
public $useTable = 'aro_twos';
/**
* hasAndBelongsToMany property
*
* @var array
*/
public $hasAndBelongsToMany = array('AcoTwoTest' => array('with' => 'PermissionTwoTest'));
}
/**
* AcoTwoTest class
*
* @package Cake.Test.Case.Controller.Component
*/
class AcoTwoTest extends AclNodeTwoTestBase {
/**
* name property
*
* @var string 'AcoTwoTest'
*/
public $name = 'AcoTwoTest';
/**
* useTable property
*
* @var string 'aco_twos'
*/
public $useTable = 'aco_twos';
/**
* hasAndBelongsToMany property
*
* @var array
*/
public $hasAndBelongsToMany = array('AroTwoTest' => array('with' => 'PermissionTwoTest'));
}
/**
* PermissionTwoTest class
*
* @package Cake.Test.Case.Controller.Component
*/
class PermissionTwoTest extends CakeTestModel {
/**
* name property
*
* @var string 'PermissionTwoTest'
*/
public $name = 'PermissionTwoTest';
/**
* useTable property
*
* @var string 'aros_aco_twos'
*/
public $useTable = 'aros_aco_twos';
/**
* cacheQueries property
*
* @var bool false
*/
public $cacheQueries = false;
/**
* belongsTo property
*
* @var array
*/
public $belongsTo = array('AroTwoTest' => array('foreignKey' => 'aro_id'), 'AcoTwoTest' => array('foreignKey' => 'aco_id'));
/**
* actsAs property
*
* @var mixed null
*/
public $actsAs = null;
}
/**
* DbAclTwoTest class
*
* @package Cake.Test.Case.Controller.Component
*/
class DbAclTwoTest extends DbAcl {
/**
* construct method
*
* @return void
*/
function __construct() {
$this->Aro = new AroTwoTest();
$this->Aro->Permission = new PermissionTwoTest();
$this->Aco = new AcoTwoTest();
$this->Aro->Permission = new PermissionTwoTest();
}
}
/**
* Test case for AclComponent using the DbAcl implementation.
*
* @package Cake.Test.Case.Controller.Component
*/
class DbAclTest extends CakeTestCase {
/**
* fixtures property
*
* @var array
*/
public $fixtures = array('core.aro_two', 'core.aco_two', 'core.aros_aco_two');
/**
* setUp method
*
* @return void
*/
public function setUp() {
parent::setUp();
Configure::write('Acl.classname', 'DbAclTwoTest');
Configure::write('Acl.database', 'test');
$Collection = new ComponentCollection();
$this->Acl = new AclComponent($Collection);
}
/**
* tearDown method
*
* @return void
*/
public function tearDown() {
parent::tearDown();
unset($this->Acl);
}
/**
* testAclCreate method
*
* @return void
*/
public function testCreate() {
$this->Acl->Aro->create(array('alias' => 'Chotchkey'));
$this->assertTrue((bool)$this->Acl->Aro->save());
$parent = $this->Acl->Aro->id;
$this->Acl->Aro->create(array('parent_id' => $parent, 'alias' => 'Joanna'));
$this->assertTrue((bool)$this->Acl->Aro->save());
$this->Acl->Aro->create(array('parent_id' => $parent, 'alias' => 'Stapler'));
$this->assertTrue((bool)$this->Acl->Aro->save());
$root = $this->Acl->Aco->node('ROOT');
$parent = $root[0]['AcoTwoTest']['id'];
$this->Acl->Aco->create(array('parent_id' => $parent, 'alias' => 'Drinks'));
$this->assertTrue((bool)$this->Acl->Aco->save());
$this->Acl->Aco->create(array('parent_id' => $parent, 'alias' => 'PiecesOfFlair'));
$this->assertTrue((bool)$this->Acl->Aco->save());
}
/**
* testAclCreateWithParent method
*
* @return void
*/
public function testCreateWithParent() {
$parent = $this->Acl->Aro->findByAlias('Peter', null, null, -1);
$this->Acl->Aro->create();
$this->Acl->Aro->save(array(
'alias' => 'Subordinate',
'model' => 'User',
'foreign_key' => 7,
'parent_id' => $parent['AroTwoTest']['id']
));
$result = $this->Acl->Aro->findByAlias('Subordinate', null, null, -1);
$this->assertEqual($result['AroTwoTest']['lft'], 16);
$this->assertEqual($result['AroTwoTest']['rght'], 17);
}
/**
* testDbAclAllow method
*
* @return void
*/
public function testAllow() {
$this->assertFalse($this->Acl->check('Micheal', 'tpsReports', 'read'));
$this->assertTrue($this->Acl->allow('Micheal', 'tpsReports', array('read', 'delete', 'update')));
$this->assertTrue($this->Acl->check('Micheal', 'tpsReports', 'update'));
$this->assertTrue($this->Acl->check('Micheal', 'tpsReports', 'read'));
$this->assertTrue($this->Acl->check('Micheal', 'tpsReports', 'delete'));
$this->assertFalse($this->Acl->check('Micheal', 'tpsReports', 'create'));
$this->assertTrue($this->Acl->allow('Micheal', 'ROOT/tpsReports', 'create'));
$this->assertTrue($this->Acl->check('Micheal', 'tpsReports', 'create'));
$this->assertTrue($this->Acl->check('Micheal', 'tpsReports', 'delete'));
$this->assertTrue($this->Acl->allow('Micheal', 'printers', 'create'));
// Michael no longer has his delete permission for tpsReports!
$this->assertTrue($this->Acl->check('Micheal', 'tpsReports', 'delete'));
$this->assertTrue($this->Acl->check('Micheal', 'printers', 'create'));
$this->assertFalse($this->Acl->check('root/users/Samir', 'ROOT/tpsReports/view'));
$this->assertTrue($this->Acl->allow('root/users/Samir', 'ROOT/tpsReports/view', '*'));
$this->assertTrue($this->Acl->check('Samir', 'view', 'read'));
$this->assertTrue($this->Acl->check('root/users/Samir', 'ROOT/tpsReports/view', 'update'));
$this->assertFalse($this->Acl->check('root/users/Samir', 'ROOT/tpsReports/update','*'));
$this->assertTrue($this->Acl->allow('root/users/Samir', 'ROOT/tpsReports/update', '*'));
$this->assertTrue($this->Acl->check('Samir', 'update', 'read'));
$this->assertTrue($this->Acl->check('root/users/Samir', 'ROOT/tpsReports/update', 'update'));
// Samir should still have his tpsReports/view permissions, but does not
$this->assertTrue($this->Acl->check('root/users/Samir', 'ROOT/tpsReports/view', 'update'));
$this->expectError();
$this->assertFalse($this->Acl->allow('Lumbergh', 'ROOT/tpsReports/DoesNotExist', 'create'));
}
/**
* testAllowInvalidNode method
*
* @return void
*/
public function testAllowInvalidNode() {
$this->expectError();
$this->Acl->allow('Homer', 'tpsReports', 'create');
}
/**
* testDbAclCheck method
*
* @return void
*/
public function testCheck() {
$this->assertTrue($this->Acl->check('Samir', 'print', 'read'));
$this->assertTrue($this->Acl->check('Lumbergh', 'current', 'read'));
$this->assertFalse($this->Acl->check('Milton', 'smash', 'read'));
$this->assertFalse($this->Acl->check('Milton', 'current', 'update'));
$this->assertFalse($this->Acl->check(null, 'printers', 'create'));
$this->assertFalse($this->Acl->check('managers', null, 'read'));
$this->assertTrue($this->Acl->check('Bobs', 'ROOT/tpsReports/view/current', 'read'));
$this->assertFalse($this->Acl->check('Samir', 'ROOT/tpsReports/update', 'read'));
$this->assertFalse($this->Acl->check('root/users/Milton', 'smash', 'delete'));
}
/**
* testCheckInvalidNode method
*
* @return void
*/
public function testCheckInvalidNode() {
$this->expectError();
$this->assertFalse($this->Acl->check('WRONG', 'tpsReports', 'read'));
}
/**
* testCheckInvalidPermission method
*
* @return void
*/
public function testCheckInvalidPermission() {
$this->expectError();
$this->assertFalse($this->Acl->check('Lumbergh', 'smash', 'foobar'));
}
/**
* testCheckMissingPermission method
*
* @return void
*/
public function testCheckMissingPermission() {
$this->expectError();
$this->assertFalse($this->Acl->check('users', 'NonExistant', 'read'));
}
/**
* testDbAclCascadingDeny function
*
* Setup the acl permissions such that Bobs inherits from admin.
* deny Admin delete access to a specific resource, check the permisssions are inherited.
*
* @return void
*/
public function testAclCascadingDeny() {
$this->Acl->inherit('Bobs', 'ROOT', '*');
$this->assertTrue($this->Acl->check('admin', 'tpsReports', 'delete'));
$this->assertTrue($this->Acl->check('Bobs', 'tpsReports', 'delete'));
$this->Acl->deny('admin', 'tpsReports', 'delete');
$this->assertFalse($this->Acl->check('admin', 'tpsReports', 'delete'));
$this->assertFalse($this->Acl->check('Bobs', 'tpsReports', 'delete'));
}
/**
* testDbAclDeny method
*
* @return void
*/
public function testDeny() {
$this->assertTrue($this->Acl->check('Micheal', 'smash', 'delete'));
$this->Acl->deny('Micheal', 'smash', 'delete');
$this->assertFalse($this->Acl->check('Micheal', 'smash', 'delete'));
$this->assertTrue($this->Acl->check('Micheal', 'smash', 'read'));
$this->assertTrue($this->Acl->check('Micheal', 'smash', 'create'));
$this->assertTrue($this->Acl->check('Micheal', 'smash', 'update'));
$this->assertFalse($this->Acl->check('Micheal', 'smash', '*'));
$this->assertTrue($this->Acl->check('Samir', 'refill', '*'));
$this->Acl->deny('Samir', 'refill', '*');
$this->assertFalse($this->Acl->check('Samir', 'refill', 'create'));
$this->assertFalse($this->Acl->check('Samir', 'refill', 'update'));
$this->assertFalse($this->Acl->check('Samir', 'refill', 'read'));
$this->assertFalse($this->Acl->check('Samir', 'refill', 'delete'));
$result = $this->Acl->Aro->Permission->find('all', array('conditions' => array('AroTwoTest.alias' => 'Samir')));
$expected = '-1';
$this->assertEqual($result[0]['PermissionTwoTest']['_delete'], $expected);
$this->expectError();
$this->assertFalse($this->Acl->deny('Lumbergh', 'ROOT/tpsReports/DoesNotExist', 'create'));
}
/**
* testAclNodeLookup method
*
* @return void
*/
public function testAclNodeLookup() {
$result = $this->Acl->Aro->node('root/users/Samir');
$expected = array(
array('AroTwoTest' => array('id' => '7', 'parent_id' => '4', 'model' => 'User', 'foreign_key' => 3, 'alias' => 'Samir')),
array('AroTwoTest' => array('id' => '4', 'parent_id' => '1', 'model' => 'Group', 'foreign_key' => 3, 'alias' => 'users')),
array('AroTwoTest' => array('id' => '1', 'parent_id' => null, 'model' => null, 'foreign_key' => null, 'alias' => 'root'))
);
$this->assertEqual($expected, $result);
$result = $this->Acl->Aco->node('ROOT/tpsReports/view/current');
$expected = array(
array('AcoTwoTest' => array('id' => '4', 'parent_id' => '3', 'model' => null, 'foreign_key' => null, 'alias' => 'current')),
array('AcoTwoTest' => array('id' => '3', 'parent_id' => '2', 'model' => null, 'foreign_key' => null, 'alias' => 'view')),
array('AcoTwoTest' => array('id' => '2', 'parent_id' => '1', 'model' => null, 'foreign_key' => null, 'alias' => 'tpsReports')),
array('AcoTwoTest' => array('id' => '1', 'parent_id' => null, 'model' => null, 'foreign_key' => null, 'alias' => 'ROOT')),
);
$this->assertEqual($expected, $result);
}
/**
* testDbInherit method
*
* @return void
*/
public function testInherit() {
//parent doesn't have access inherit should still deny
$this->assertFalse($this->Acl->check('Milton', 'smash', 'delete'));
$this->Acl->inherit('Milton', 'smash', 'delete');
$this->assertFalse($this->Acl->check('Milton', 'smash', 'delete'));
//inherit parent
$this->assertFalse($this->Acl->check('Milton', 'smash', 'read'));
$this->Acl->inherit('Milton', 'smash', 'read');
$this->assertTrue($this->Acl->check('Milton', 'smash', 'read'));
}
/**
* testDbGrant method
*
* @return void
*/
public function testGrant() {
$this->assertFalse($this->Acl->check('Samir', 'tpsReports', 'create'));
$this->Acl->allow('Samir', 'tpsReports', 'create');
$this->assertTrue($this->Acl->check('Samir', 'tpsReports', 'create'));
$this->assertFalse($this->Acl->check('Micheal', 'view', 'read'));
$this->Acl->allow('Micheal', 'view', array('read', 'create', 'update'));
$this->assertTrue($this->Acl->check('Micheal', 'view', 'read'));
$this->assertTrue($this->Acl->check('Micheal', 'view', 'create'));
$this->assertTrue($this->Acl->check('Micheal', 'view', 'update'));
$this->assertFalse($this->Acl->check('Micheal', 'view', 'delete'));
$this->expectError();
$this->assertFalse($this->Acl->allow('Peter', 'ROOT/tpsReports/DoesNotExist', 'create'));
}
/**
* testDbRevoke method
*
* @return void
*/
public function testRevoke() {
$this->assertTrue($this->Acl->check('Bobs', 'tpsReports', 'read'));
$this->Acl->deny('Bobs', 'tpsReports', 'read');
$this->assertFalse($this->Acl->check('Bobs', 'tpsReports', 'read'));
$this->assertTrue($this->Acl->check('users', 'printers', 'read'));
$this->Acl->deny('users', 'printers', 'read');
$this->assertFalse($this->Acl->check('users', 'printers', 'read'));
$this->assertFalse($this->Acl->check('Samir', 'printers', 'read'));
$this->assertFalse($this->Acl->check('Peter', 'printers', 'read'));
$this->expectError();
$this->assertFalse($this->Acl->deny('Bobs', 'ROOT/printers/DoesNotExist', 'create'));
}
/**
* debug function - to help editing/creating test cases for the ACL component
*
* To check the overal ACL status at any time call $this->__debug();
* Generates a list of the current aro and aco structures and a grid dump of the permissions that are defined
* Only designed to work with the db based ACL
*
* @param bool $treesToo
* @return void
*/
function __debug ($printTreesToo = false) {
$this->Acl->Aro->displayField = 'alias';
$this->Acl->Aco->displayField = 'alias';
$aros = $this->Acl->Aro->find('list', array('order' => 'lft'));
$acos = $this->Acl->Aco->find('list', array('order' => 'lft'));
$rights = array('*', 'create', 'read', 'update', 'delete');
$permissions['Aros v Acos >'] = $acos;
foreach ($aros as $aro) {
$row = array();
foreach ($acos as $aco) {
$perms = '';
foreach ($rights as $right) {
if ($this->Acl->check($aro, $aco, $right)) {
if ($right == '*') {
$perms .= '****';
break;
}
$perms .= $right[0];
} elseif ($right != '*') {
$perms .= ' ';
}
}
$row[] = $perms;
}
$permissions[$aro] = $row;
}
foreach ($permissions as $key => $values) {
array_unshift($values, $key);
$values = array_map(array(&$this, '__pad'), $values);
$permissions[$key] = implode (' ', $values);
}
$permisssions = array_map(array(&$this, '__pad'), $permissions);
array_unshift($permissions, 'Current Permissions :');
if ($printTreesToo) {
debug(array('aros' => $this->Acl->Aro->generateTreeList(), 'acos' => $this->Acl->Aco->generateTreeList()));
}
debug(implode("\r\n", $permissions));
}
/**
* pad function
* Used by debug to format strings used in the data dump
*
* @param string $string
* @param int $len
* @return void
*/
function __pad($string = '', $len = 14) {
return str_pad($string, $len);
}
}
| 0001-bee | trunk/cakephp2/lib/Cake/Test/Case/Controller/Component/DbAclTest.php | PHP | gpl3 | 15,835 |
<?php
/**
* IniAclTest file.
*
* PHP 5
*
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
* Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://cakephp.org CakePHP(tm) Project
* @package Cake.Test.Case.Controller.Component
* @since CakePHP(tm) v 2.0
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
App::uses('AclComponent', 'Controller/Component');
class_exists('AclComponent');
/**
* Test case for the IniAcl implementation
*
* @package Cake.Test.Case.Controller.Component
*/
class IniAclTest extends CakeTestCase {
/**
* testIniCheck method
*
* @return void
*/
public function testCheck() {
$iniFile = CAKE . 'Test' . DS . 'test_app' . DS . 'Config'. DS . 'acl.ini.php';
$Ini = new IniAcl();
$Ini->config = $Ini->readConfigFile($iniFile);
$this->assertFalse($Ini->check('admin', 'ads'));
$this->assertTrue($Ini->check('admin', 'posts'));
$this->assertTrue($Ini->check('jenny', 'posts'));
$this->assertTrue($Ini->check('jenny', 'ads'));
$this->assertTrue($Ini->check('paul', 'posts'));
$this->assertFalse($Ini->check('paul', 'ads'));
$this->assertFalse($Ini->check('nobody', 'comments'));
}
/**
* check should accept a user array.
*
* @return void
*/
public function testCheckArray() {
$iniFile = CAKE . 'Test' . DS . 'test_app' . DS . 'Config'. DS . 'acl.ini.php';
$Ini = new IniAcl();
$Ini->config = $Ini->readConfigFile($iniFile);
$Ini->userPath = 'User.username';
$user = array(
'User' => array('username' => 'admin')
);
$this->assertTrue($Ini->check($user, 'posts'));
}
}
| 0001-bee | trunk/cakephp2/lib/Cake/Test/Case/Controller/Component/IniAclTest.php | PHP | gpl3 | 1,885 |
<?php
/**
* SessionComponentTest file
*
* PHP 5
*
* CakePHP(tm) Tests <http://book.cakephp.org/view/1196/Testing>
* Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice
*
* @copyright Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://book.cakephp.org/view/1196/Testing CakePHP(tm) Tests
* @package Cake.Test.Case.Controller.Component
* @since CakePHP(tm) v 1.2.0.5436
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
App::uses('Controller', 'Controller');
App::uses('SessionComponent', 'Controller/Component');
/**
* SessionTestController class
*
* @package Cake.Test.Case.Controller.Component
*/
class SessionTestController extends Controller {
/**
* uses property
*
* @var array
*/
public $uses = array();
/**
* session_id method
*
* @return string
*/
public function session_id() {
return $this->Session->id();
}
}
/**
* OrangeSessionTestController class
*
* @package Cake.Test.Case.Controller.Component
*/
class OrangeSessionTestController extends Controller {
/**
* uses property
*
* @var array
*/
public $uses = array();
/**
* session_id method
*
* @return string
*/
public function session_id() {
return $this->Session->id();
}
}
/**
* SessionComponentTest class
*
* @package Cake.Test.Case.Controller.Component
*/
class SessionComponentTest extends CakeTestCase {
protected static $_sessionBackup;
/**
* fixtures
*
* @var string
*/
public $fixtures = array('core.session');
/**
* test case startup
*
* @return void
*/
public static function setupBeforeClass() {
self::$_sessionBackup = Configure::read('Session');
Configure::write('Session', array(
'defaults' => 'php',
'timeout' => 100,
'cookie' => 'test'
));
}
/**
* cleanup after test case.
*
* @return void
*/
public static function teardownAfterClass() {
Configure::write('Session', self::$_sessionBackup);
}
/**
* setUp method
*
* @return void
*/
public function setUp() {
parent::setUp();
$_SESSION = null;
$this->ComponentCollection = new ComponentCollection();
}
/**
* tearDown method
*
* @return void
*/
public function tearDown() {
parent::tearDown();
CakeSession::destroy();
}
/**
* ensure that session ids don't change when request action is called.
*
* @return void
*/
public function testSessionIdConsistentAcrossRequestAction() {
$Session = new SessionComponent($this->ComponentCollection);
$Session->check('Test');
$this->assertTrue(isset($_SESSION));
$Object = new Object();
$Session = new SessionComponent($this->ComponentCollection);
$expected = $Session->id();
$result = $Object->requestAction('/session_test/session_id');
$this->assertEqual($expected, $result);
$result = $Object->requestAction('/orange_session_test/session_id');
$this->assertEqual($expected, $result);
}
/**
* testSessionValid method
*
* @return void
*/
public function testSessionValid() {
$Session = new SessionComponent($this->ComponentCollection);
$this->assertTrue($Session->valid());
Configure::write('Session.checkAgent', true);
$Session->userAgent('rweerw');
$this->assertFalse($Session->valid());
$Session = new SessionComponent($this->ComponentCollection);
$Session->time = $Session->read('Config.time') + 1;
$this->assertFalse($Session->valid());
}
/**
* testSessionError method
*
* @return void
*/
public function testSessionError() {
$Session = new SessionComponent($this->ComponentCollection);
$this->assertFalse($Session->error());
}
/**
* testSessionReadWrite method
*
* @return void
*/
public function testSessionReadWrite() {
$Session = new SessionComponent($this->ComponentCollection);
$this->assertNull($Session->read('Test'));
$this->assertTrue($Session->write('Test', 'some value'));
$this->assertEqual($Session->read('Test'), 'some value');
$this->assertFalse($Session->write('Test.key', 'some value'));
$Session->delete('Test');
$this->assertTrue($Session->write('Test.key.path', 'some value'));
$this->assertEqual($Session->read('Test.key.path'), 'some value');
$this->assertEqual($Session->read('Test.key'), array('path' => 'some value'));
$this->assertTrue($Session->write('Test.key.path2', 'another value'));
$this->assertEqual($Session->read('Test.key'), array('path' => 'some value', 'path2' => 'another value'));
$Session->delete('Test');
$array = array('key1' => 'val1', 'key2' => 'val2', 'key3' => 'val3');
$this->assertTrue($Session->write('Test', $array));
$this->assertEqual($Session->read('Test'), $array);
$Session->delete('Test');
$this->assertFalse($Session->write(array('Test'), 'some value'));
$this->assertTrue($Session->write(array('Test' => 'some value')));
$this->assertEqual($Session->read('Test'), 'some value');
$Session->delete('Test');
}
/**
* testSessionDelete method
*
* @return void
*/
public function testSessionDelete() {
$Session = new SessionComponent($this->ComponentCollection);
$this->assertFalse($Session->delete('Test'));
$Session->write('Test', 'some value');
$this->assertTrue($Session->delete('Test'));
}
/**
* testSessionCheck method
*
* @return void
*/
public function testSessionCheck() {
$Session = new SessionComponent($this->ComponentCollection);
$this->assertFalse($Session->check('Test'));
$Session->write('Test', 'some value');
$this->assertTrue($Session->check('Test'));
$Session->delete('Test');
}
/**
* testSessionFlash method
*
* @return void
*/
public function testSessionFlash() {
$Session = new SessionComponent($this->ComponentCollection);
$this->assertNull($Session->read('Message.flash'));
$Session->setFlash('This is a test message');
$this->assertEqual($Session->read('Message.flash'), array('message' => 'This is a test message', 'element' => 'default', 'params' => array()));
$Session->setFlash('This is a test message', 'test', array('name' => 'Joel Moss'));
$this->assertEqual($Session->read('Message.flash'), array('message' => 'This is a test message', 'element' => 'test', 'params' => array('name' => 'Joel Moss')));
$Session->setFlash('This is a test message', 'default', array(), 'myFlash');
$this->assertEqual($Session->read('Message.myFlash'), array('message' => 'This is a test message', 'element' => 'default', 'params' => array()));
$Session->setFlash('This is a test message', 'non_existing_layout');
$this->assertEqual($Session->read('Message.myFlash'), array('message' => 'This is a test message', 'element' => 'default', 'params' => array()));
$Session->delete('Message');
}
/**
* testSessionId method
*
* @return void
*/
public function testSessionId() {
unset($_SESSION);
$Session = new SessionComponent($this->ComponentCollection);
$Session->check('test');
$this->assertEquals(session_id(), $Session->id());
}
/**
* testSessionDestroy method
*
* @return void
*/
public function testSessionDestroy() {
$Session = new SessionComponent($this->ComponentCollection);
$Session->write('Test', 'some value');
$this->assertEqual($Session->read('Test'), 'some value');
$Session->destroy('Test');
$this->assertNull($Session->read('Test'));
}
}
| 0001-bee | trunk/cakephp2/lib/Cake/Test/Case/Controller/Component/SessionComponentTest.php | PHP | gpl3 | 7,392 |
<?php
/**
* AuthComponentTest file
*
* PHP 5
*
* CakePHP(tm) Tests <http://book.cakephp.org/view/1196/Testing>
* Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice
*
* @copyright Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://book.cakephp.org/view/1196/Testing CakePHP(tm) Tests
* @package Cake.Test.Case.Controller.Component
* @since CakePHP(tm) v 1.2.0.5347
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
App::uses('Controller', 'Controller');
App::uses('AuthComponent', 'Controller/Component');
App::uses('AclComponent', 'Controller/Component');
App::uses('FormAuthenticate', 'Controller/Component/Auth');
/**
* TestAuthComponent class
*
* @package Cake.Test.Case.Controller.Component
* @package Cake.Test.Case.Controller.Component
*/
class TestAuthComponent extends AuthComponent {
/**
* testStop property
*
* @var bool false
*/
public $testStop = false;
/**
* stop method
*
* @return void
*/
function _stop($status = 0) {
$this->testStop = true;
}
}
/**
* AuthUser class
*
* @package Cake.Test.Case.Controller.Component
* @package Cake.Test.Case.Controller.Component
*/
class AuthUser extends CakeTestModel {
/**
* name property
*
* @var string 'AuthUser'
*/
public $name = 'AuthUser';
/**
* useDbConfig property
*
* @var string 'test'
*/
public $useDbConfig = 'test';
}
/**
* AuthTestController class
*
* @package Cake.Test.Case.Controller.Component
* @package Cake.Test.Case.Controller.Component
*/
class AuthTestController extends Controller {
/**
* name property
*
* @var string 'AuthTest'
*/
public $name = 'AuthTest';
/**
* uses property
*
* @var array
*/
public $uses = array('AuthUser');
/**
* components property
*
* @var array
*/
public $components = array('Session', 'Auth');
/**
* testUrl property
*
* @var mixed null
*/
public $testUrl = null;
/**
* construct method
*
* @return void
*/
function __construct($request, $response) {
$request->addParams(Router::parse('/auth_test'));
$request->here = '/auth_test';
$request->webroot = '/';
Router::setRequestInfo($request);
parent::__construct($request, $response);
}
/**
* login method
*
* @return void
*/
public function login() {
}
/**
* admin_login method
*
* @return void
*/
public function admin_login() {
}
/**
* admin_add method
*
* @return void
*/
public function admin_add() {
}
/**
* logout method
*
* @return void
*/
public function logout() {
}
/**
* add method
*
* @return void
*/
public function add() {
echo "add";
}
/**
* add method
*
* @return void
*/
public function camelCase() {
echo "camelCase";
}
/**
* redirect method
*
* @param mixed $url
* @param mixed $status
* @param mixed $exit
* @return void
*/
public function redirect($url, $status = null, $exit = true) {
$this->testUrl = Router::url($url);
return false;
}
/**
* isAuthorized method
*
* @return void
*/
public function isAuthorized() {
}
}
/**
* AjaxAuthController class
*
* @package Cake.Test.Case.Controller.Component
*/
class AjaxAuthController extends Controller {
/**
* name property
*
* @var string 'AjaxAuth'
*/
public $name = 'AjaxAuth';
/**
* components property
*
* @var array
*/
public $components = array('Session', 'TestAuth');
/**
* uses property
*
* @var array
*/
public $uses = array();
/**
* testUrl property
*
* @var mixed null
*/
public $testUrl = null;
/**
* beforeFilter method
*
* @return void
*/
public function beforeFilter() {
$this->TestAuth->ajaxLogin = 'test_element';
$this->TestAuth->userModel = 'AuthUser';
$this->TestAuth->RequestHandler->ajaxLayout = 'ajax2';
}
/**
* add method
*
* @return void
*/
public function add() {
if ($this->TestAuth->testStop !== true) {
echo 'Added Record';
}
}
/**
* redirect method
*
* @param mixed $url
* @param mixed $status
* @param mixed $exit
* @return void
*/
public function redirect($url, $status = null, $exit = true) {
$this->testUrl = Router::url($url);
return false;
}
}
/**
* AuthComponentTest class
*
* @package Cake.Test.Case.Controller.Component
* @package Cake.Test.Case.Controller.Component
*/
class AuthComponentTest extends CakeTestCase {
/**
* name property
*
* @var string 'Auth'
*/
public $name = 'Auth';
/**
* fixtures property
*
* @var array
*/
public $fixtures = array('core.auth_user');
/**
* initialized property
*
* @var bool false
*/
public $initialized = false;
/**
* setUp method
*
* @return void
*/
public function setUp() {
parent::setUp();
$this->_server = $_SERVER;
$this->_env = $_ENV;
Configure::write('Security.salt', 'YJfIxfs2guVoUubWDYhG93b0qyJfIxfs2guwvniR2G0FgaC9mi');
Configure::write('Security.cipherSeed', 770011223369876);
$request = new CakeRequest(null, false);
$this->Controller = new AuthTestController($request, $this->getMock('CakeResponse'));
$collection = new ComponentCollection();
$collection->init($this->Controller);
$this->Auth = new TestAuthComponent($collection);
$this->Auth->request = $request;
$this->Auth->response = $this->getMock('CakeResponse');
$this->Controller->Components->init($this->Controller);
$this->initialized = true;
Router::reload();
Router::connect('/:controller/:action/*');
$User = ClassRegistry::init('AuthUser');
$User->updateAll(array('password' => $User->getDataSource()->value(Security::hash('cake', null, true))));
}
/**
* tearDown method
*
* @return void
*/
public function tearDown() {
parent::tearDown();
$_SERVER = $this->_server;
$_ENV = $this->_env;
$this->Auth->Session->delete('Auth');
$this->Auth->Session->delete('Message.auth');
unset($this->Controller, $this->Auth);
}
/**
* testNoAuth method
*
* @return void
*/
public function testNoAuth() {
$this->assertFalse($this->Auth->isAuthorized());
}
/**
* testIsErrorOrTests
*
* @return void
*/
public function testIsErrorOrTests() {
$this->Controller->Auth->initialize($this->Controller);
$this->Controller->name = 'CakeError';
$this->assertTrue($this->Controller->Auth->startup($this->Controller));
$this->Controller->name = 'Post';
$this->Controller->request['action'] = 'thisdoesnotexist';
$this->assertTrue($this->Controller->Auth->startup($this->Controller));
$this->Controller->scaffold = null;
$this->Controller->request['action'] = 'index';
$this->assertFalse($this->Controller->Auth->startup($this->Controller));
}
/**
* testLogin method
*
* @return void
*/
public function testLogin() {
$this->getMock('FormAuthenticate', array(), array(), 'AuthLoginFormAuthenticate', false);
$this->Auth->authenticate = array(
'AuthLoginForm' => array(
'userModel' => 'AuthUser'
)
);
$this->Auth->Session = $this->getMock('SessionComponent', array('renew'), array(), '', false);
$mocks = $this->Auth->constructAuthenticate();
$this->mockObjects[] = $mocks[0];
$this->Auth->request->data = array(
'AuthUser' => array(
'username' => 'mark',
'password' => Security::hash('cake', null, true)
)
);
$user = array(
'id' => 1,
'username' => 'mark'
);
$mocks[0]->expects($this->once())
->method('authenticate')
->with($this->Auth->request)
->will($this->returnValue($user));
$this->Auth->Session->expects($this->once())
->method('renew');
$result = $this->Auth->login();
$this->assertTrue($result);
$this->assertTrue($this->Auth->loggedIn());
$this->assertEquals($user, $this->Auth->user());
}
/**
* test that being redirected to the login page, with no post data does
* not set the session value. Saving the session value in this circumstance
* can cause the user to be redirected to an already public page.
*
* @return void
*/
public function testLoginActionNotSettingAuthRedirect() {
$_SERVER['HTTP_REFERER'] = '/pages/display/about';
$this->Controller->data = array();
$this->Controller->request->addParams(Router::parse('auth_test/login'));
$this->Controller->request->url = 'auth_test/login';
$this->Auth->Session->delete('Auth');
$this->Auth->loginRedirect = '/users/dashboard';
$this->Auth->loginAction = 'auth_test/login';
$this->Auth->userModel = 'AuthUser';
$this->Auth->startup($this->Controller);
$redirect = $this->Auth->Session->read('Auth.redirect');
$this->assertNull($redirect);
}
/**
* testAuthorizeFalse method
*
* @return void
*/
public function testAuthorizeFalse() {
$this->AuthUser = new AuthUser();
$user = $this->AuthUser->find();
$this->Auth->Session->write('Auth.User', $user['AuthUser']);
$this->Controller->Auth->userModel = 'AuthUser';
$this->Controller->Auth->authorize = false;
$this->Controller->request->addParams(Router::parse('auth_test/add'));
$result = $this->Controller->Auth->startup($this->Controller);
$this->assertTrue($result);
$this->Auth->Session->delete('Auth');
$result = $this->Controller->Auth->startup($this->Controller);
$this->assertFalse($result);
$this->assertTrue($this->Auth->Session->check('Message.auth'));
$this->Controller->request->addParams(Router::parse('auth_test/camelCase'));
$result = $this->Controller->Auth->startup($this->Controller);
$this->assertFalse($result);
}
/**
* @expectedException CakeException
* @return void
*/
public function testIsAuthorizedMissingFile() {
$this->Controller->Auth->authorize = 'Missing';
$this->Controller->Auth->isAuthorized(array('User' => array('id' => 1)));
}
/**
* test that isAuthroized calls methods correctly
*
* @return void
*/
public function testIsAuthorizedDelegation() {
$this->getMock('BaseAuthorize', array('authorize'), array(), 'AuthMockOneAuthorize', false);
$this->getMock('BaseAuthorize', array('authorize'), array(), 'AuthMockTwoAuthorize', false);
$this->getMock('BaseAuthorize', array('authorize'), array(), 'AuthMockThreeAuthorize', false);
$this->Auth->authorize = array(
'AuthMockOne',
'AuthMockTwo',
'AuthMockThree'
);
$mocks = $this->Auth->constructAuthorize();
$request = $this->Auth->request;
$this->assertEquals(3, count($mocks));
$mocks[0]->expects($this->once())
->method('authorize')
->with(array('User'), $request)
->will($this->returnValue(false));
$mocks[1]->expects($this->once())
->method('authorize')
->with(array('User'), $request)
->will($this->returnValue(true));
$mocks[2]->expects($this->never())
->method('authorize');
$this->assertTrue($this->Auth->isAuthorized(array('User'), $request));
}
/**
* test that isAuthorized will use the session user if none is given.
*
* @return void
*/
public function testIsAuthorizedUsingUserInSession() {
$this->getMock('BaseAuthorize', array('authorize'), array(), 'AuthMockFourAuthorize', false);
$this->Auth->authorize = array('AuthMockFour');
$user = array('user' => 'mark');
$this->Auth->Session->write('Auth.User', $user);
$mocks = $this->Auth->constructAuthorize();
$request = $this->Controller->request;
$mocks[0]->expects($this->once())
->method('authorize')
->with($user, $request)
->will($this->returnValue(true));
$this->assertTrue($this->Auth->isAuthorized(null, $request));
}
/**
* test that loadAuthorize resets the loaded objects each time.
*
* @return void
*/
public function testLoadAuthorizeResets() {
$this->Controller->Auth->authorize = array(
'Controller'
);
$result = $this->Controller->Auth->constructAuthorize();
$this->assertEquals(1, count($result));
$result = $this->Controller->Auth->constructAuthorize();
$this->assertEquals(1, count($result));
}
/**
* @expectedException CakeException
* @return void
*/
public function testLoadAuthenticateNoFile() {
$this->Controller->Auth->authenticate = 'Missing';
$this->Controller->Auth->identify($this->Controller->request, $this->Controller->response);
}
/**
* test the * key with authenticate
*
* @return void
*/
public function testAllConfigWithAuthorize() {
$this->Controller->Auth->authorize = array(
AuthComponent::ALL => array('actionPath' => 'controllers/'),
'Actions'
);
$objects = $this->Controller->Auth->constructAuthorize();
$result = $objects[0];
$this->assertEquals($result->settings['actionPath'], 'controllers/');
}
/**
* test that loadAuthorize resets the loaded objects each time.
*
* @return void
*/
public function testLoadAuthenticateResets() {
$this->Controller->Auth->authenticate = array(
'Form'
);
$result = $this->Controller->Auth->constructAuthenticate();
$this->assertEquals(1, count($result));
$result = $this->Controller->Auth->constructAuthenticate();
$this->assertEquals(1, count($result));
}
/**
* test the * key with authenticate
*
* @return void
*/
public function testAllConfigWithAuthenticate() {
$this->Controller->Auth->authenticate = array(
AuthComponent::ALL => array('userModel' => 'AuthUser'),
'Form'
);
$objects = $this->Controller->Auth->constructAuthenticate();
$result = $objects[0];
$this->assertEquals($result->settings['userModel'], 'AuthUser');
}
/**
* Tests that deny always takes precedence over allow
*
* @return void
*/
public function testAllowDenyAll() {
$this->Controller->Auth->initialize($this->Controller);
$this->Controller->Auth->allow();
$this->Controller->Auth->deny('add', 'camelCase');
$this->Controller->request['action'] = 'delete';
$this->assertTrue($this->Controller->Auth->startup($this->Controller));
$this->Controller->request['action'] = 'add';
$this->assertFalse($this->Controller->Auth->startup($this->Controller));
$this->Controller->request['action'] = 'camelCase';
$this->assertFalse($this->Controller->Auth->startup($this->Controller));
$this->Controller->Auth->allow('*');
$this->Controller->Auth->deny(array('add', 'camelCase'));
$this->Controller->request['action'] = 'delete';
$this->assertTrue($this->Controller->Auth->startup($this->Controller));
$this->Controller->request['action'] = 'camelCase';
$this->assertFalse($this->Controller->Auth->startup($this->Controller));
}
/**
* test that deny() converts camel case inputs to lowercase.
*
* @return void
*/
public function testDenyWithCamelCaseMethods() {
$this->Controller->Auth->initialize($this->Controller);
$this->Controller->Auth->allow('*');
$this->Controller->Auth->deny('add', 'camelCase');
$url = '/auth_test/camelCase';
$this->Controller->request->addParams(Router::parse($url));
$this->Controller->request->query['url'] = Router::normalize($url);
$this->assertFalse($this->Controller->Auth->startup($this->Controller));
}
/**
* test that allow() and allowedActions work with camelCase method names.
*
* @return void
*/
public function testAllowedActionsWithCamelCaseMethods() {
$url = '/auth_test/camelCase';
$this->Controller->request->addParams(Router::parse($url));
$this->Controller->request->query['url'] = Router::normalize($url);
$this->Controller->Auth->initialize($this->Controller);
$this->Controller->Auth->loginAction = array('controller' => 'AuthTest', 'action' => 'login');
$this->Controller->Auth->userModel = 'AuthUser';
$this->Controller->Auth->allow('*');
$result = $this->Controller->Auth->startup($this->Controller);
$this->assertTrue($result, 'startup() should return true, as action is allowed. %s');
$url = '/auth_test/camelCase';
$this->Controller->request->addParams(Router::parse($url));
$this->Controller->request->query['url'] = Router::normalize($url);
$this->Controller->Auth->initialize($this->Controller);
$this->Controller->Auth->loginAction = array('controller' => 'AuthTest', 'action' => 'login');
$this->Controller->Auth->userModel = 'AuthUser';
$this->Controller->Auth->allowedActions = array('delete', 'camelCase', 'add');
$result = $this->Controller->Auth->startup($this->Controller);
$this->assertTrue($result, 'startup() should return true, as action is allowed. %s');
$this->Controller->Auth->allowedActions = array('delete', 'add');
$result = $this->Controller->Auth->startup($this->Controller);
$this->assertFalse($result, 'startup() should return false, as action is not allowed. %s');
$url = '/auth_test/delete';
$this->Controller->request->addParams(Router::parse($url));
$this->Controller->request->query['url'] = Router::normalize($url);
$this->Controller->Auth->initialize($this->Controller);
$this->Controller->Auth->loginAction = array('controller' => 'AuthTest', 'action' => 'login');
$this->Controller->Auth->userModel = 'AuthUser';
$this->Controller->Auth->allow(array('delete', 'add'));
$result = $this->Controller->Auth->startup($this->Controller);
$this->assertTrue($result, 'startup() should return true, as action is allowed. %s');
}
public function testAllowedActionsSetWithAllowMethod() {
$url = '/auth_test/action_name';
$this->Controller->request->addParams(Router::parse($url));
$this->Controller->request->query['url'] = Router::normalize($url);
$this->Controller->Auth->initialize($this->Controller);
$this->Controller->Auth->allow('action_name', 'anotherAction');
$this->assertEqual($this->Controller->Auth->allowedActions, array('action_name', 'anotherAction'));
}
/**
* testLoginRedirect method
*
* @return void
*/
public function testLoginRedirect() {
$_SERVER['HTTP_REFERER'] = false;
$_ENV['HTTP_REFERER'] = false;
putenv('HTTP_REFERER=');
$this->Auth->Session->write('Auth', array(
'AuthUser' => array('id' => '1', 'username' => 'nate')
));
$this->Auth->request->addParams(Router::parse('users/login'));
$this->Auth->request->url = 'users/login';
$this->Auth->initialize($this->Controller);
$this->Auth->loginRedirect = array(
'controller' => 'pages', 'action' => 'display', 'welcome'
);
$this->Auth->startup($this->Controller);
$expected = Router::normalize($this->Auth->loginRedirect);
$this->assertEqual($expected, $this->Auth->redirect());
$this->Auth->Session->delete('Auth');
//empty referer no session
$_SERVER['HTTP_REFERER'] = false;
$_ENV['HTTP_REFERER'] = false;
putenv('HTTP_REFERER=');
$url = '/posts/view/1';
$this->Auth->Session->write('Auth', array(
'AuthUser' => array('id' => '1', 'username' => 'nate'))
);
$this->Controller->testUrl = null;
$this->Auth->request->addParams(Router::parse($url));
array_push($this->Controller->methods, 'view', 'edit', 'index');
$this->Auth->initialize($this->Controller);
$this->Auth->authorize = 'controller';
$this->Auth->loginAction = array(
'controller' => 'AuthTest', 'action' => 'login'
);
$this->Auth->startup($this->Controller);
$expected = Router::normalize('/AuthTest/login');
$this->assertEqual($expected, $this->Controller->testUrl);
$this->Auth->Session->delete('Auth');
$_SERVER['HTTP_REFERER'] = $_ENV['HTTP_REFERER'] = Router::url('/admin', true);
$this->Auth->Session->write('Auth', array(
'AuthUser' => array('id'=>'1', 'username' => 'nate')
));
$this->Auth->request->params['action'] = 'login';
$this->Auth->request->url = 'auth_test/login';
$this->Auth->initialize($this->Controller);
$this->Auth->loginAction = 'auth_test/login';
$this->Auth->loginRedirect = false;
$this->Auth->startup($this->Controller);
$expected = Router::normalize('/admin');
$this->assertEqual($expected, $this->Auth->redirect());
//Ticket #4750
//named params
$this->Auth->Session->delete('Auth');
$url = '/posts/index/year:2008/month:feb';
$this->Auth->request->addParams(Router::parse($url));
$this->Auth->request->url = Router::normalize($url);
$this->Auth->initialize($this->Controller);
$this->Auth->loginAction = array('controller' => 'AuthTest', 'action' => 'login');
$this->Auth->startup($this->Controller);
$expected = Router::normalize('posts/index/year:2008/month:feb');
$this->assertEqual($expected, $this->Auth->Session->read('Auth.redirect'));
//passed args
$this->Auth->Session->delete('Auth');
$url = '/posts/view/1';
$this->Auth->request->addParams(Router::parse($url));
$this->Auth->request->url = Router::normalize($url);
$this->Auth->initialize($this->Controller);
$this->Auth->loginAction = array('controller' => 'AuthTest', 'action' => 'login');
$this->Auth->startup($this->Controller);
$expected = Router::normalize('posts/view/1');
$this->assertEqual($expected, $this->Auth->Session->read('Auth.redirect'));
// QueryString parameters
$_back = $_GET;
$_GET = array(
'url' => '/posts/index/29',
'print' => 'true',
'refer' => 'menu'
);
$this->Auth->Session->delete('Auth');
$url = '/posts/index/29';
$this->Auth->request = $this->Controller->request = new CakeRequest($url);
$this->Auth->request->addParams(Router::parse($url));
$this->Auth->initialize($this->Controller);
$this->Auth->loginAction = array('controller' => 'AuthTest', 'action' => 'login');
$this->Auth->startup($this->Controller);
$expected = Router::normalize('posts/index/29?print=true&refer=menu');
$this->assertEqual($expected, $this->Auth->Session->read('Auth.redirect'));
$_GET = array(
'url' => '/posts/index/29',
'print' => 'true',
'refer' => 'menu'
);
$this->Auth->Session->delete('Auth');
$url = '/posts/index/29';
$this->Auth->request = $this->Controller->request = new CakeRequest($url);
$this->Auth->request->addParams(Router::parse($url));
$this->Auth->initialize($this->Controller);
$this->Auth->loginAction = array('controller' => 'AuthTest', 'action' => 'login');
$this->Auth->startup($this->Controller);
$expected = Router::normalize('posts/index/29?print=true&refer=menu');
$this->assertEqual($expected, $this->Auth->Session->read('Auth.redirect'));
$_GET = $_back;
//external authed action
$_SERVER['HTTP_REFERER'] = 'http://webmail.example.com/view/message';
$_GET = array(
'url' => '/posts/edit/1'
);
$this->Auth->Session->delete('Auth');
$url = '/posts/edit/1';
$this->Auth->request = $this->Controller->request = new CakeRequest($url);
$this->Auth->request->addParams(Router::parse($url));
$this->Auth->request->url = Router::normalize($url);
$this->Auth->initialize($this->Controller);
$this->Auth->loginAction = array('controller' => 'AuthTest', 'action' => 'login');
$this->Auth->startup($this->Controller);
$expected = Router::normalize('/posts/edit/1');
$this->assertEqual($expected, $this->Auth->Session->read('Auth.redirect'));
//external direct login link
$_SERVER['HTTP_REFERER'] = 'http://webmail.example.com/view/message';
$this->Auth->Session->delete('Auth');
$url = '/AuthTest/login';
$this->Auth->request = $this->Controller->request = new CakeRequest($url);
$this->Auth->request->addParams(Router::parse($url));
$this->Auth->request->url = Router::normalize($url);
$this->Auth->initialize($this->Controller);
$this->Auth->loginAction = array('controller' => 'AuthTest', 'action' => 'login');
$this->Auth->startup($this->Controller);
$expected = Router::normalize('/');
$this->assertEqual($expected, $this->Auth->Session->read('Auth.redirect'));
$this->Auth->Session->delete('Auth');
}
/**
* test that no redirects or authoization tests occur on the loginAction
*
* @return void
*/
public function testNoRedirectOnLoginAction() {
$controller = $this->getMock('Controller');
$controller->methods = array('login');
$url = '/AuthTest/login';
$this->Auth->request = $controller->request = new CakeRequest($url);
$this->Auth->request->addParams(Router::parse($url));
$this->Auth->loginAction = array('controller' => 'AuthTest', 'action' => 'login');
$this->Auth->authorize = array('Controller');
$controller->expects($this->never())
->method('redirect');
$this->Auth->startup($controller);
}
/**
* Ensure that no redirect is performed when a 404 is reached
* And the user doesn't have a session.
*
* @return void
*/
public function testNoRedirectOn404() {
$this->Auth->Session->delete('Auth');
$this->Auth->initialize($this->Controller);
$this->Auth->request->addParams(Router::parse('auth_test/something_totally_wrong'));
$result = $this->Auth->startup($this->Controller);
$this->assertTrue($result, 'Auth redirected a missing action %s');
}
/**
* testAdminRoute method
*
* @return void
*/
public function testAdminRoute() {
$pref = Configure::read('Routing.prefixes');
Configure::write('Routing.prefixes', array('admin'));
Router::reload();
require CAKE . 'Config' . DS . 'routes.php';
$url = '/admin/auth_test/add';
$this->Auth->request->addParams(Router::parse($url));
$this->Auth->request->query['url'] = ltrim($url, '/');
$this->Auth->request->base = '';
Router::setRequestInfo($this->Auth->request);
$this->Auth->initialize($this->Controller);
$this->Auth->loginAction = array(
'admin' => true, 'controller' => 'auth_test', 'action' => 'login'
);
$this->Auth->startup($this->Controller);
$this->assertEqual($this->Controller->testUrl, '/admin/auth_test/login');
Configure::write('Routing.prefixes', $pref);
}
/**
* testAjaxLogin method
*
* @return void
*/
public function testAjaxLogin() {
App::build(array(
'View' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'View'. DS)
));
$_SERVER['HTTP_X_REQUESTED_WITH'] = "XMLHttpRequest";
App::uses('Dispatcher', 'Routing');
ob_start();
$Dispatcher = new Dispatcher();
$Dispatcher->dispatch(new CakeRequest('/ajax_auth/add'), new CakeResponse(), array('return' => 1));
$result = ob_get_clean();
$this->assertEqual("Ajax!\nthis is the test element", str_replace("\r\n", "\n", $result));
unset($_SERVER['HTTP_X_REQUESTED_WITH']);
}
/**
* testLoginActionRedirect method
*
* @return void
*/
public function testLoginActionRedirect() {
$admin = Configure::read('Routing.prefixes');
Configure::write('Routing.prefixes', array('admin'));
Router::reload();
require CAKE . 'Config' . DS . 'routes.php';
$url = '/admin/auth_test/login';
$this->Auth->request->addParams(Router::parse($url));
$this->Auth->request->url = ltrim($url, '/');
Router::setRequestInfo(array(
array(
'pass' => array(), 'action' => 'admin_login', 'plugin' => null, 'controller' => 'auth_test',
'admin' => true,
),
array(
'base' => null, 'here' => $url,
'webroot' => '/', 'passedArgs' => array(),
)
));
$this->Auth->initialize($this->Controller);
$this->Auth->loginAction = array('admin' => true, 'controller' => 'auth_test', 'action' => 'login');
$this->Auth->startup($this->Controller);
$this->assertNull($this->Controller->testUrl);
Configure::write('Routing.prefixes', $admin);
}
/**
* Tests that shutdown destroys the redirect session var
*
* @return void
*/
public function testShutDown() {
$this->Auth->Session->write('Auth.User', 'not empty');
$this->Auth->Session->write('Auth.redirect', 'foo');
$this->Controller->Auth->loggedIn(true);
$this->Controller->Auth->shutdown($this->Controller);
$this->assertNull($this->Auth->Session->read('Auth.redirect'));
}
/**
* test $settings in Controller::$components
*
* @return void
*/
public function testComponentSettings() {
$request = new CakeRequest(null, false);
$this->Controller = new AuthTestController($request, $this->getMock('CakeResponse'));
$this->Controller->components = array(
'Auth' => array(
'loginAction' => array('controller' => 'people', 'action' => 'login'),
'logoutRedirect' => array('controller' => 'people', 'action' => 'login'),
),
'Session'
);
$this->Controller->Components->init($this->Controller);
$this->Controller->Components->trigger('initialize', array(&$this->Controller));
Router::reload();
$expected = array(
'loginAction' => array('controller' => 'people', 'action' => 'login'),
'logoutRedirect' => array('controller' => 'people', 'action' => 'login'),
);
$this->assertEqual($expected['loginAction'], $this->Controller->Auth->loginAction);
$this->assertEqual($expected['logoutRedirect'], $this->Controller->Auth->logoutRedirect);
}
/**
* test that logout deletes the session variables. and returns the correct url
*
* @return void
*/
public function testLogout() {
$this->Auth->Session->write('Auth.User.id', '1');
$this->Auth->Session->write('Auth.redirect', '/users/login');
$this->Auth->logoutRedirect = '/';
$result = $this->Auth->logout();
$this->assertEqual($result, '/');
$this->assertNull($this->Auth->Session->read('Auth.AuthUser'));
$this->assertNull($this->Auth->Session->read('Auth.redirect'));
}
public function testLogoutTrigger() {
$this->getMock('BaseAuthenticate', array('authenticate', 'logout'), array(), 'LogoutTriggerMockAuthenticate', false);
$this->Auth->authenticate = array('LogoutTriggerMock');
$mock = $this->Auth->constructAuthenticate();
$mock[0]->expects($this->once())
->method('logout');
$this->Auth->logout();
}
/**
* test mapActions loading and delegating to authorize objects.
*
* @return void
*/
public function testMapActionsDelegation() {
$this->getMock('BaseAuthorize', array('authorize'), array(), 'MapActionMockAuthorize', false);
$this->Auth->authorize = array('MapActionMock');
$mock = $this->Auth->constructAuthorize();
$mock[0]->expects($this->once())
->method('mapActions')
->with(array('create' => array('my_action')));
$this->Auth->mapActions(array('create' => array('my_action')));
}
/**
* test logging in with a request.
*
* @return void
*/
public function testLoginWithRequestData() {
$this->getMock('FormAuthenticate', array(), array(), 'RequestLoginMockAuthenticate', false);
$request = new CakeRequest('users/login', false);
$user = array('username' => 'mark', 'role' => 'admin');
$this->Auth->request = $request;
$this->Auth->authenticate = array('RequestLoginMock');
$mock = $this->Auth->constructAuthenticate();
$mock[0]->expects($this->once())
->method('authenticate')
->with($request)
->will($this->returnValue($user));
$this->assertTrue($this->Auth->login());
$this->assertEquals($user['username'], $this->Auth->user('username'));
}
/**
* test login() with user data
*
* @return void
*/
public function testLoginWithUserData() {
$this->assertFalse($this->Auth->loggedIn());
$user = array(
'username' => 'mariano',
'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
'created' => '2007-03-17 01:16:23',
'updated' => '2007-03-17 01:18:31'
);
$this->assertTrue($this->Auth->login($user));
$this->assertTrue($this->Auth->loggedIn());
$this->assertEquals($user['username'], $this->Auth->user('username'));
}
/**
* test flash settings.
*
* @return void
*/
public function testFlashSettings() {
$this->Auth->Session = $this->getMock('SessionComponent', array(), array(), '', false);
$this->Auth->Session->expects($this->once())
->method('setFlash')
->with('Auth failure', 'custom', array(1), 'auth-key');
$this->Auth->flash = array(
'element' => 'custom',
'params' => array(1),
'key' => 'auth-key'
);
$this->Auth->flash('Auth failure');
}
/**
* test the various states of Auth::redirect()
*
* @return void
*/
public function testRedirectSet() {
$value = array('controller' => 'users', 'action' => 'home');
$result = $this->Auth->redirect($value);
$this->assertEquals('/users/home', $result);
$this->assertEquals($value, $this->Auth->Session->read('Auth.redirect'));
}
/**
* test redirect using Auth.redirect from the session.
*
* @return void
*/
public function testRedirectSessionRead() {
$this->Auth->loginAction = array('controller' => 'users', 'action' => 'login');
$this->Auth->Session->write('Auth.redirect', '/users/home');
$result = $this->Auth->redirect();
$this->assertEquals('/users/home', $result);
$this->assertFalse($this->Auth->Session->check('Auth.redirect'));
}
/**
* test that redirect does not return loginAction if that is what's stored in Auth.redirect.
* instead loginRedirect should be used.
*
* @return void
*/
public function testRedirectSessionReadEqualToLoginAction() {
$this->Auth->loginAction = array('controller' => 'users', 'action' => 'login');
$this->Auth->loginRedirect = array('controller' => 'users', 'action' => 'home');
$this->Auth->Session->write('Auth.redirect', array('controller' => 'users', 'action' => 'login'));
$result = $this->Auth->redirect();
$this->assertEquals('/users/home', $result);
$this->assertFalse($this->Auth->Session->check('Auth.redirect'));
}
/**
* test password hashing
*
* @return void
*/
public function testPassword() {
$result = $this->Auth->password('password');
$expected = Security::hash('password', null, true);
$this->assertEquals($expected, $result);
}
}
| 0001-bee | trunk/cakephp2/lib/Cake/Test/Case/Controller/Component/AuthComponentTest.php | PHP | gpl3 | 32,949 |
<?php
/**
* DigestAuthenticateTest file
*
* PHP 5
*
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
* Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://cakephp.org CakePHP(tm) Project
* @package Cake.Test.Case.Controller.Component.Auth
* @since CakePHP(tm) v 2.0
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
App::uses('DigestAuthenticate', 'Controller/Component/Auth');
App::uses('AppModel', 'Model');
App::uses('CakeRequest', 'Network');
App::uses('CakeResponse', 'Network');
require_once CAKE . 'Test' . DS . 'Case' . DS . 'Model' . DS . 'models.php';
/**
* Test case for DigestAuthentication
*
* @package Cake.Test.Case.Controller.Component.Auth
*/
class DigestAuthenticateTest extends CakeTestCase {
public $fixtures = array('core.user', 'core.auth_user');
/**
* setup
*
* @return void
*/
public function setUp() {
parent::setUp();
$this->Collection = $this->getMock('ComponentCollection');
$this->server = $_SERVER;
$this->auth = new DigestAuthenticate($this->Collection, array(
'fields' => array('username' => 'user', 'password' => 'password'),
'userModel' => 'User',
'realm' => 'localhost',
'nonce' => 123,
'opaque' => '123abc'
));
$password = DigestAuthenticate::password('mariano', 'cake', 'localhost');
$User = ClassRegistry::init('User');
$User->updateAll(array('password' => $User->getDataSource()->value($password)));
$_SERVER['REQUEST_METHOD'] = 'GET';
$this->response = $this->getMock('CakeResponse');
}
/**
* teardown
*
* @return void
*/
public function tearDown() {
parent::tearDown();
$_SERVER = $this->server;
}
/**
* test applying settings in the constructor
*
* @return void
*/
public function testConstructor() {
$object = new DigestAuthenticate($this->Collection, array(
'userModel' => 'AuthUser',
'fields' => array('username' => 'user', 'password' => 'password'),
'nonce' => 123456
));
$this->assertEquals('AuthUser', $object->settings['userModel']);
$this->assertEquals(array('username' => 'user', 'password' => 'password'), $object->settings['fields']);
$this->assertEquals(123456, $object->settings['nonce']);
$this->assertEquals(env('SERVER_NAME'), $object->settings['realm']);
}
/**
* test the authenticate method
*
* @return void
*/
public function testAuthenticateNoData() {
$request = new CakeRequest('posts/index', false);
$this->response->expects($this->once())
->method('header')
->with('WWW-Authenticate: Digest realm="localhost",qop="auth",nonce="123",opaque="123abc"');
$this->assertFalse($this->auth->authenticate($request, $this->response));
}
/**
* test the authenticate method
*
* @return void
*/
public function testAuthenticateWrongUsername() {
$request = new CakeRequest('posts/index', false);
$request->addParams(array('pass' => array(), 'named' => array()));
$_SERVER['PHP_AUTH_DIGEST'] = <<<DIGEST
Digest username="incorrect_user",
realm="localhost",
nonce="123456",
uri="/dir/index.html",
qop=auth,
nc=00000001,
cnonce="0a4f113b",
response="6629fae49393a05397450978507c4ef1",
opaque="123abc"
DIGEST;
$this->response->expects($this->at(0))
->method('header')
->with('WWW-Authenticate: Digest realm="localhost",qop="auth",nonce="123",opaque="123abc"');
$this->response->expects($this->at(1))
->method('statusCode')
->with(401);
$this->response->expects($this->at(2))
->method('send');
$this->assertFalse($this->auth->authenticate($request, $this->response));
}
/**
* test that challenge headers are sent when no credentials are found.
*
* @return void
*/
public function testAuthenticateChallenge() {
$request = new CakeRequest('posts/index', false);
$request->addParams(array('pass' => array(), 'named' => array()));
$this->response->expects($this->at(0))
->method('header')
->with('WWW-Authenticate: Digest realm="localhost",qop="auth",nonce="123",opaque="123abc"');
$this->response->expects($this->at(1))
->method('statusCode')
->with(401);
$this->response->expects($this->at(2))
->method('send');
$result = $this->auth->authenticate($request, $this->response);
$this->assertFalse($result);
}
/**
* test authenticate sucesss
*
* @return void
*/
public function testAuthenticateSuccess() {
$request = new CakeRequest('posts/index', false);
$request->addParams(array('pass' => array(), 'named' => array()));
$_SERVER['PHP_AUTH_DIGEST'] = <<<DIGEST
Digest username="mariano",
realm="localhost",
nonce="123",
uri="/dir/index.html",
qop=auth,
nc=1,
cnonce="123",
response="06b257a54befa2ddfb9bfa134224aa29",
opaque="123abc"
DIGEST;
$result = $this->auth->authenticate($request, $this->response);
$expected = array(
'id' => 1,
'user' => 'mariano',
'created' => '2007-03-17 01:16:23',
'updated' => '2007-03-17 01:18:31'
);
$this->assertEquals($expected, $result);
}
/**
* test scope failure.
*
* @return void
*/
public function testAuthenticateFailReChallenge() {
$this->auth->settings['scope'] = array('user' => 'nate');
$request = new CakeRequest('posts/index', false);
$request->addParams(array('pass' => array(), 'named' => array()));
$_SERVER['PHP_AUTH_DIGEST'] = <<<DIGEST
Digest username="mariano",
realm="localhost",
nonce="123",
uri="/dir/index.html",
qop=auth,
nc=1,
cnonce="123",
response="6629fae49393a05397450978507c4ef1",
opaque="123abc"
DIGEST;
$this->response->expects($this->at(0))
->method('header')
->with('WWW-Authenticate: Digest realm="localhost",qop="auth",nonce="123",opaque="123abc"');
$this->response->expects($this->at(1))
->method('statusCode')
->with(401);
$this->response->expects($this->at(2))
->method('send');
$this->assertFalse($this->auth->authenticate($request, $this->response));
}
/**
* testParseDigestAuthData method
*
* @return void
*/
public function testParseAuthData() {
$digest = <<<DIGEST
Digest username="Mufasa",
realm="testrealm@host.com",
nonce="dcd98b7102dd2f0e8b11d0f600bfb0c093",
uri="/dir/index.html",
qop=auth,
nc=00000001,
cnonce="0a4f113b",
response="6629fae49393a05397450978507c4ef1",
opaque="5ccc069c403ebaf9f0171e9517f40e41"
DIGEST;
$expected = array(
'username' => 'Mufasa',
'realm' => 'testrealm@host.com',
'nonce' => 'dcd98b7102dd2f0e8b11d0f600bfb0c093',
'uri' => '/dir/index.html',
'qop' => 'auth',
'nc' => '00000001',
'cnonce' => '0a4f113b',
'response' => '6629fae49393a05397450978507c4ef1',
'opaque' => '5ccc069c403ebaf9f0171e9517f40e41'
);
$result = $this->auth->parseAuthData($digest);
$this->assertSame($expected, $result);
$result = $this->auth->parseAuthData('');
$this->assertNull($result);
}
/**
* test parsing digest information with email addresses
*
* @return void
*/
public function testParseAuthEmailAddress() {
$digest = <<<DIGEST
Digest username="mark@example.com",
realm="testrealm@host.com",
nonce="dcd98b7102dd2f0e8b11d0f600bfb0c093",
uri="/dir/index.html",
qop=auth,
nc=00000001,
cnonce="0a4f113b",
response="6629fae49393a05397450978507c4ef1",
opaque="5ccc069c403ebaf9f0171e9517f40e41"
DIGEST;
$expected = array(
'username' => 'mark@example.com',
'realm' => 'testrealm@host.com',
'nonce' => 'dcd98b7102dd2f0e8b11d0f600bfb0c093',
'uri' => '/dir/index.html',
'qop' => 'auth',
'nc' => '00000001',
'cnonce' => '0a4f113b',
'response' => '6629fae49393a05397450978507c4ef1',
'opaque' => '5ccc069c403ebaf9f0171e9517f40e41'
);
$result = $this->auth->parseAuthData($digest);
$this->assertIdentical($expected, $result);
}
/**
* test password hashing
*
* @return void
*/
public function testPassword() {
$result = DigestAuthenticate::password('mark', 'password', 'localhost');
$expected = md5('mark:localhost:password');
$this->assertEquals($expected, $result);
}
}
| 0001-bee | trunk/cakephp2/lib/Cake/Test/Case/Controller/Component/Auth/DigestAuthenticateTest.php | PHP | gpl3 | 8,162 |
<?php
/**
* CrudAuthorizeTest file
*
* PHP 5
*
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
* Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://cakephp.org CakePHP(tm) Project
* @package Cake.Test.Case.Controller.Component.Auth
* @since CakePHP(tm) v 2.0
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
App::uses('CrudAuthorize', 'Controller/Component/Auth');
App::uses('ComponentCollection', 'Controller');
App::uses('AclComponent', 'Controller/Component');
App::uses('CakeRequest', 'Network');
App::uses('CakeResponse', 'Network');
class CrudAuthorizeTest extends CakeTestCase {
/**
* setup
*
* @return void
*/
public function setUp() {
Configure::write('Routing.prefixes', array());
parent::setUp();
$this->Acl = $this->getMock('AclComponent', array(), array(), '', false);
$this->Components = $this->getMock('ComponentCollection');
$this->auth = new CrudAuthorize($this->Components);
}
/**
* setup the mock acl.
*
* @return void
*/
protected function _mockAcl() {
$this->Components->expects($this->any())
->method('load')
->with('Acl')
->will($this->returnValue($this->Acl));
}
/**
* test authorize() without a mapped action, ensure an error is generated.
*
* @expectedException Exception
* @return void
*/
public function testAuthorizeNoMappedAction() {
$request = new CakeRequest('/posts/foobar', false);
$request->addParams(array(
'controller' => 'posts',
'action' => 'foobar'
));
$user = array('User' => array('user' => 'mark'));
$this->auth->authorize($user, $request);
}
/**
* test check() passing
*
* @return void
*/
public function testAuthorizeCheckSuccess() {
$request = new CakeRequest('posts/index', false);
$request->addParams(array(
'controller' => 'posts',
'action' => 'index'
));
$user = array('User' => array('user' => 'mark'));
$this->_mockAcl();
$this->Acl->expects($this->once())
->method('check')
->with($user, 'Posts', 'read')
->will($this->returnValue(true));
$this->assertTrue($this->auth->authorize($user['User'], $request));
}
/**
* test check() failing
*
* @return void
*/
public function testAuthorizeCheckFailure() {
$request = new CakeRequest('posts/index', false);
$request->addParams(array(
'controller' => 'posts',
'action' => 'index'
));
$user = array('User' => array('user' => 'mark'));
$this->_mockAcl();
$this->Acl->expects($this->once())
->method('check')
->with($user, 'Posts', 'read')
->will($this->returnValue(false));
$this->assertFalse($this->auth->authorize($user['User'], $request));
}
/**
* test getting actionMap
*
* @return void
*/
public function testMapActionsGet() {
$result = $this->auth->mapActions();
$expected = array(
'create' => 'create',
'read' => 'read',
'update' => 'update',
'delete' => 'delete',
'index' => 'read',
'add' => 'create',
'edit' => 'update',
'view' => 'read',
'remove' => 'delete'
);
$this->assertEquals($expected, $result);
}
/**
* test adding into mapActions
*
* @return void
*/
public function testMapActionsSet() {
$map = array(
'create' => array('generate'),
'read' => array('listing', 'show'),
'update' => array('update'),
'random' => 'custom'
);
$result = $this->auth->mapActions($map);
$this->assertNull($result);
$result = $this->auth->mapActions();
$expected = array(
'add' => 'create',
'create' => 'create',
'read' => 'read',
'index' => 'read',
'add' => 'create',
'edit' => 'update',
'view' => 'read',
'delete' => 'delete',
'remove' => 'delete',
'generate' => 'create',
'listing' => 'read',
'show' => 'read',
'update' => 'update',
'random' => 'custom',
);
$this->assertEquals($expected, $result);
}
/**
* test prefix routes getting auto mapped.
*
* @return void
*/
public function testAutoPrefixMapActions() {
Configure::write('Routing.prefixes', array('admin', 'manager'));
Router::reload();
$auth = new CrudAuthorize($this->Components);
$this->assertTrue(isset($auth->settings['actionMap']['admin_index']));
}
}
| 0001-bee | trunk/cakephp2/lib/Cake/Test/Case/Controller/Component/Auth/CrudAuthorizeTest.php | PHP | gpl3 | 4,427 |
<?php
/**
* ActionsAuthorizeTest file
*
* PHP 5
*
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
* Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://cakephp.org CakePHP(tm) Project
* @package Cake.Test.Case.Controller.Component.Auth
* @since CakePHP(tm) v 2.0
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
App::uses('ActionsAuthorize', 'Controller/Component/Auth');
App::uses('ComponentCollection', 'Controller');
App::uses('AclComponent', 'Controller/Component');
App::uses('CakeRequest', 'Network');
App::uses('CakeResponse', 'Network');
class ActionsAuthorizeTest extends CakeTestCase {
/**
* setup
*
* @return void
*/
public function setUp() {
parent::setUp();
$this->controller = $this->getMock('Controller', array(), array(), '', false);
$this->Acl = $this->getMock('AclComponent', array(), array(), '', false);
$this->Collection = $this->getMock('ComponentCollection');
$this->auth = new ActionsAuthorize($this->Collection);
$this->auth->settings['actionPath'] = '/controllers';
}
/**
* setup the mock acl.
*
* @return void
*/
protected function _mockAcl() {
$this->Collection->expects($this->any())
->method('load')
->with('Acl')
->will($this->returnValue($this->Acl));
}
/**
* test failure
*
* @return void
*/
public function testAuthorizeFailure() {
$user = array(
'User' => array(
'id' => 1,
'user' => 'mariano'
)
);
$request = new CakeRequest('/posts/index', false);
$request->addParams(array(
'plugin' => null,
'controller' => 'posts',
'action' => 'index'
));
$this->_mockAcl();
$this->Acl->expects($this->once())
->method('check')
->with($user, '/controllers/Posts/index')
->will($this->returnValue(false));
$this->assertFalse($this->auth->authorize($user['User'], $request));
}
/**
* test isAuthorized working.
*
* @return void
*/
public function testAuthorizeSuccess() {
$user = array(
'User' => array(
'id' => 1,
'user' => 'mariano'
)
);
$request = new CakeRequest('/posts/index', false);
$request->addParams(array(
'plugin' => null,
'controller' => 'posts',
'action' => 'index'
));
$this->_mockAcl();
$this->Acl->expects($this->once())
->method('check')
->with($user, '/controllers/Posts/index')
->will($this->returnValue(true));
$this->assertTrue($this->auth->authorize($user['User'], $request));
}
/**
* test action()
*
* @return void
*/
public function testActionMethod() {
$request = new CakeRequest('/posts/index', false);
$request->addParams(array(
'plugin' => null,
'controller' => 'posts',
'action' => 'index'
));
$result = $this->auth->action($request);
$this->assertEquals('/controllers/Posts/index', $result);
}
/**
* test action() and plugins
*
* @return void
*/
public function testActionWithPlugin() {
$request = new CakeRequest('/debug_kit/posts/index', false);
$request->addParams(array(
'plugin' => 'debug_kit',
'controller' => 'posts',
'action' => 'index'
));
$result = $this->auth->action($request);
$this->assertEquals('/controllers/DebugKit/Posts/index', $result);
}
}
| 0001-bee | trunk/cakephp2/lib/Cake/Test/Case/Controller/Component/Auth/ActionsAuthorizeTest.php | PHP | gpl3 | 3,464 |
<?php
/**
* BasicAuthenticateTest file
*
* PHP 5
*
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
* Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://cakephp.org CakePHP(tm) Project
* @package Cake.Test.Case.Controller.Component.Auth
* @since CakePHP(tm) v 2.0
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
App::uses('AuthComponent', 'Controller/Component');
App::uses('BasicAuthenticate', 'Controller/Component/Auth');
App::uses('AppModel', 'Model');
App::uses('CakeRequest', 'Network');
App::uses('CakeResponse', 'Network');
require_once CAKE . 'Test' . DS . 'Case' . DS . 'Model' . DS . 'models.php';
/**
* Test case for BasicAuthentication
*
* @package Cake.Test.Case.Controller.Component.Auth
*/
class BasicAuthenticateTest extends CakeTestCase {
public $fixtures = array('core.user', 'core.auth_user');
/**
* setup
*
* @return void
*/
public function setUp() {
parent::setUp();
$this->Collection = $this->getMock('ComponentCollection');
$this->auth = new BasicAuthenticate($this->Collection, array(
'fields' => array('username' => 'user', 'password' => 'password'),
'userModel' => 'User',
'realm' => 'localhost',
));
$password = Security::hash('password', null, true);
$User = ClassRegistry::init('User');
$User->updateAll(array('password' => $User->getDataSource()->value($password)));
$this->server = $_SERVER;
$this->response = $this->getMock('CakeResponse');
}
/**
* teardown
*
* @return void
*/
public function tearDown() {
parent::tearDown();
$_SERVER = $this->server;
}
/**
* test applying settings in the constructor
*
* @return void
*/
public function testConstructor() {
$object = new BasicAuthenticate($this->Collection, array(
'userModel' => 'AuthUser',
'fields' => array('username' => 'user', 'password' => 'password')
));
$this->assertEquals('AuthUser', $object->settings['userModel']);
$this->assertEquals(array('username' => 'user', 'password' => 'password'), $object->settings['fields']);
$this->assertEquals(env('SERVER_NAME'), $object->settings['realm']);
}
/**
* test the authenticate method
*
* @return void
*/
public function testAuthenticateNoData() {
$request = new CakeRequest('posts/index', false);
$this->response->expects($this->once())
->method('header')
->with('WWW-Authenticate: Basic realm="localhost"');
$this->assertFalse($this->auth->authenticate($request, $this->response));
}
/**
* test the authenticate method
*
* @return void
*/
public function testAuthenticateNoUsername() {
$request = new CakeRequest('posts/index', false);
$_SERVER['PHP_AUTH_PW'] = 'foobar';
$this->response->expects($this->once())
->method('header')
->with('WWW-Authenticate: Basic realm="localhost"');
$this->assertFalse($this->auth->authenticate($request, $this->response));
}
/**
* test the authenticate method
*
* @return void
*/
public function testAuthenticateNoPassword() {
$request = new CakeRequest('posts/index', false);
$_SERVER['PHP_AUTH_USER'] = 'mariano';
$_SERVER['PHP_AUTH_PW'] = null;
$this->response->expects($this->once())
->method('header')
->with('WWW-Authenticate: Basic realm="localhost"');
$this->assertFalse($this->auth->authenticate($request, $this->response));
}
/**
* test the authenticate method
*
* @return void
*/
public function testAuthenticateInjection() {
$request = new CakeRequest('posts/index', false);
$request->addParams(array('pass' => array(), 'named' => array()));
$_SERVER['PHP_AUTH_USER'] = '> 1';
$_SERVER['PHP_AUTH_PW'] = "' OR 1 = 1";
$this->assertFalse($this->auth->authenticate($request, $this->response));
}
/**
* test that challenge headers are sent when no credentials are found.
*
* @return void
*/
public function testAuthenticateChallenge() {
$request = new CakeRequest('posts/index', false);
$request->addParams(array('pass' => array(), 'named' => array()));
$this->response->expects($this->at(0))
->method('header')
->with('WWW-Authenticate: Basic realm="localhost"');
$this->response->expects($this->at(1))
->method('send');
$result = $this->auth->authenticate($request, $this->response);
$this->assertFalse($result);
}
/**
* test authenticate sucesss
*
* @return void
*/
public function testAuthenticateSuccess() {
$request = new CakeRequest('posts/index', false);
$request->addParams(array('pass' => array(), 'named' => array()));
$_SERVER['PHP_AUTH_USER'] = 'mariano';
$_SERVER['PHP_AUTH_PW'] = 'password';
$result = $this->auth->authenticate($request, $this->response);
$expected = array(
'id' => 1,
'user' => 'mariano',
'created' => '2007-03-17 01:16:23',
'updated' => '2007-03-17 01:18:31'
);
$this->assertEquals($expected, $result);
}
/**
* test scope failure.
*
* @return void
*/
public function testAuthenticateFailReChallenge() {
$this->auth->settings['scope'] = array('user' => 'nate');
$request = new CakeRequest('posts/index', false);
$request->addParams(array('pass' => array(), 'named' => array()));
$_SERVER['PHP_AUTH_USER'] = 'mariano';
$_SERVER['PHP_AUTH_PW'] = 'password';
$this->response->expects($this->at(0))
->method('header')
->with('WWW-Authenticate: Basic realm="localhost"');
$this->response->expects($this->at(1))
->method('statusCode')
->with(401);
$this->response->expects($this->at(2))
->method('send');
$this->assertFalse($this->auth->authenticate($request, $this->response));
}
}
| 0001-bee | trunk/cakephp2/lib/Cake/Test/Case/Controller/Component/Auth/BasicAuthenticateTest.php | PHP | gpl3 | 5,818 |
<?php
/**
* ControllerAuthorizeTest file
*
* PHP 5
*
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
* Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://cakephp.org CakePHP(tm) Project
* @package Cake.Test.Case.Controller.Component.Auth
* @since CakePHP(tm) v 2.0
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
App::uses('Controller', 'Controller');
App::uses('ControllerAuthorize', 'Controller/Component/Auth');
App::uses('CakeRequest', 'Network');
App::uses('CakeResponse', 'Network');
class ControllerAuthorizeTest extends CakeTestCase {
/**
* setup
*
* @return void
*/
public function setUp() {
parent::setUp();
$this->controller = $this->getMock('Controller', array('isAuthorized'), array(), '', false);
$this->components = $this->getMock('ComponentCollection');
$this->components->expects($this->any())
->method('getController')
->will($this->returnValue($this->controller));
$this->auth = new ControllerAuthorize($this->components);
}
/**
*
* @expectedException CakeException
*/
public function testControllerTypeError() {
$this->auth->controller(new StdClass());
}
/**
* @expectedException CakeException
*/
public function testControllerErrorOnMissingMethod() {
$this->auth->controller(new Controller());
}
/**
* test failure
*
* @return void
*/
public function testAuthorizeFailure() {
$user = array();
$request = new CakeRequest('/posts/index', false);
$this->assertFalse($this->auth->authorize($user, $request));
}
/**
* test isAuthorized working.
*
* @return void
*/
public function testAuthorizeSuccess() {
$user = array('User' => array('username' => 'mark'));
$request = new CakeRequest('/posts/index', false);
$this->controller->expects($this->once())
->method('isAuthorized')
->with($user)
->will($this->returnValue(true));
$this->assertTrue($this->auth->authorize($user, $request));
}
}
| 0001-bee | trunk/cakephp2/lib/Cake/Test/Case/Controller/Component/Auth/ControllerAuthorizeTest.php | PHP | gpl3 | 2,230 |
<?php
/**
* FormAuthenticateTest file
*
* PHP 5
*
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
* Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://cakephp.org CakePHP(tm) Project
* @package Cake.Test.Case.Controller.Component.Auth
* @since CakePHP(tm) v 2.0
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
App::uses('AuthComponent', 'Controller/Component');
App::uses('FormAuthenticate', 'Controller/Component/Auth');
App::uses('AppModel', 'Model');
App::uses('CakeRequest', 'Network');
App::uses('CakeResponse', 'Network');
require_once CAKE . 'Test' . DS . 'Case' . DS . 'Model' . DS . 'models.php';
/**
* Test case for FormAuthentication
*
* @package Cake.Test.Case.Controller.Component.Auth
*/
class FormAuthenticateTest extends CakeTestCase {
public $fixtures = array('core.user', 'core.auth_user');
/**
* setup
*
* @return void
*/
public function setUp() {
parent::setUp();
$this->Collection = $this->getMock('ComponentCollection');
$this->auth = new FormAuthenticate($this->Collection, array(
'fields' => array('username' => 'user', 'password' => 'password'),
'userModel' => 'User'
));
$password = Security::hash('password', null, true);
$User = ClassRegistry::init('User');
$User->updateAll(array('password' => $User->getDataSource()->value($password)));
$this->response = $this->getMock('CakeResponse');
}
/**
* test applying settings in the constructor
*
* @return void
*/
public function testConstructor() {
$object = new FormAuthenticate($this->Collection, array(
'userModel' => 'AuthUser',
'fields' => array('username' => 'user', 'password' => 'password')
));
$this->assertEquals('AuthUser', $object->settings['userModel']);
$this->assertEquals(array('username' => 'user', 'password' => 'password'), $object->settings['fields']);
}
/**
* test the authenticate method
*
* @return void
*/
public function testAuthenticateNoData() {
$request = new CakeRequest('posts/index', false);
$request->data = array();
$this->assertFalse($this->auth->authenticate($request, $this->response));
}
/**
* test the authenticate method
*
* @return void
*/
public function testAuthenticateNoUsername() {
$request = new CakeRequest('posts/index', false);
$request->data = array('User' => array('password' => 'foobar'));
$this->assertFalse($this->auth->authenticate($request, $this->response));
}
/**
* test the authenticate method
*
* @return void
*/
public function testAuthenticateNoPassword() {
$request = new CakeRequest('posts/index', false);
$request->data = array('User' => array('user' => 'mariano'));
$this->assertFalse($this->auth->authenticate($request, $this->response));
}
/**
* test the authenticate method
*
* @return void
*/
public function testAuthenticateInjection() {
$request = new CakeRequest('posts/index', false);
$request->data = array(
'User' => array(
'user' => '> 1',
'password' => "' OR 1 = 1"
));
$this->assertFalse($this->auth->authenticate($request, $this->response));
}
/**
* test authenticate sucesss
*
* @return void
*/
public function testAuthenticateSuccess() {
$request = new CakeRequest('posts/index', false);
$request->data = array('User' => array(
'user' => 'mariano',
'password' => 'password'
));
$result = $this->auth->authenticate($request, $this->response);
$expected = array(
'id' => 1,
'user' => 'mariano',
'created' => '2007-03-17 01:16:23',
'updated' => '2007-03-17 01:18:31'
);
$this->assertEquals($expected, $result);
}
/**
* test scope failure.
*
* @return void
*/
public function testAuthenticateScopeFail() {
$this->auth->settings['scope'] = array('user' => 'nate');
$request = new CakeRequest('posts/index', false);
$request->data = array('User' => array(
'user' => 'mariano',
'password' => 'password'
));
$this->assertFalse($this->auth->authenticate($request, $this->response));
}
/**
* test a model in a plugin.
*
* @return void
*/
public function testPluginModel() {
Cache::delete('object_map', '_cake_core_');
App::build(array(
'plugins' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS),
), true);
CakePlugin::load('TestPlugin');
$PluginModel = ClassRegistry::init('TestPlugin.TestPluginAuthUser');
$user['id'] = 1;
$user['username'] = 'gwoo';
$user['password'] = Security::hash(Configure::read('Security.salt') . 'cake');
$PluginModel->save($user, false);
$this->auth->settings['userModel'] = 'TestPlugin.TestPluginAuthUser';
$this->auth->settings['fields']['username'] = 'username';
$request = new CakeRequest('posts/index', false);
$request->data = array('TestPluginAuthUser' => array(
'username' => 'gwoo',
'password' => 'cake'
));
$result = $this->auth->authenticate($request, $this->response);
$expected = array(
'id' => 1,
'username' => 'gwoo',
'created' => '2007-03-17 01:16:23'
);
$this->assertTrue($result['updated'] >= date('Y-m-d H:i:s'));
unset($result['updated']);
$this->assertEquals($expected, $result);
CakePlugin::unload();
}
}
| 0001-bee | trunk/cakephp2/lib/Cake/Test/Case/Controller/Component/Auth/FormAuthenticateTest.php | PHP | gpl3 | 5,419 |
<?php
/**
* AclComponentTest file
*
* PHP 5
*
* CakePHP(tm) Tests <http://book.cakephp.org/view/1196/Testing>
* Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice
*
* @copyright Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://book.cakephp.org/view/1196/Testing CakePHP(tm) Tests
* @package Cake.Test.Case.Controller.Component
* @since CakePHP(tm) v 1.2.0.5435
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
App::uses('AclComponent', 'Controller/Component');
class_exists('AclComponent');
/**
* Test Case for AclComponent
*
* @package Cake.Test.Case.Controller.Component
*/
class AclComponentTest extends CakeTestCase {
/**
* setUp method
*
* @return void
*/
public function setUp() {
parent::setUp();
if (!class_exists('MockAclImplementation', false)) {
$this->getMock('AclInterface', array(), array(), 'MockAclImplementation');
}
Configure::write('Acl.classname', 'MockAclImplementation');
$Collection = new ComponentCollection();
$this->Acl = new AclComponent($Collection);
}
/**
* tearDown method
*
* @return void
*/
public function tearDown() {
parent::tearDown();
unset($this->Acl);
}
/**
* test that construtor throws an exception when Acl.classname is a
* non-existant class
*
* @expectedException CakeException
* @return void
*/
public function testConstrutorException() {
Configure::write('Acl.classname', 'AclClassNameThatDoesNotExist');
$Collection = new ComponentCollection();
$acl = new AclComponent($Collection);
}
/**
* test that adapter() allows control of the interal implementation AclComponent uses.
*
* @return void
*/
public function testAdapter() {
$implementation = new MockAclImplementation();
$implementation->expects($this->once())->method('initialize')->with($this->Acl);
$this->assertNull($this->Acl->adapter($implementation));
$this->assertEqual($this->Acl->adapter(), $implementation, 'Returned object is different %s');
}
/**
* test that adapter() whines when the class is not an AclBase
*
* @expectedException CakeException
* @return void
*/
public function testAdapterException() {
$thing = new StdClass();
$this->Acl->adapter($thing);
}
}
| 0001-bee | trunk/cakephp2/lib/Cake/Test/Case/Controller/Component/AclComponentTest.php | PHP | gpl3 | 2,418 |
<?php
/**
* RequestHandlerComponentTest file
*
* PHP 5
*
* CakePHP(tm) Tests <http://book.cakephp.org/view/1196/Testing>
* Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice
*
* @copyright Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://book.cakephp.org/view/1196/Testing CakePHP(tm) Tests
* @package Cake.Test.Case.Controller.Component
* @since CakePHP(tm) v 1.2.0.5435
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
App::uses('Controller', 'Controller');
App::uses('RequestHandlerComponent', 'Controller/Component');
App::uses('CakeRequest', 'Network');
App::uses('CakeResponse', 'Network');
App::uses('Router', 'Routing');
/**
* RequestHandlerTestController class
*
* @package Cake.Test.Case.Controller.Component
*/
class RequestHandlerTestController extends Controller {
/**
* name property
*
* @var string
*/
public $name = 'RequestHandlerTest';
/**
* uses property
*
* @var mixed null
*/
public $uses = null;
/**
* test method for ajax redirection
*
* @return void
*/
public function destination() {
$this->viewPath = 'Posts';
$this->render('index');
}
/**
* test method for ajax redirection + parameter parsing
*
* @return void
*/
public function param_method($one = null, $two = null) {
echo "one: $one two: $two";
$this->autoRender = false;
}
/**
* test method for testing layout rendering when isAjax()
*
* @return void
*/
public function ajax2_layout() {
if ($this->autoLayout) {
$this->layout = 'ajax2';
}
$this->destination();
}
}
/**
* RequestHandlerComponentTest class
*
* @package Cake.Test.Case.Controller.Component
*/
class RequestHandlerComponentTest extends CakeTestCase {
/**
* Controller property
*
* @var RequestHandlerTestController
*/
public $Controller;
/**
* RequestHandler property
*
* @var RequestHandlerComponent
*/
public $RequestHandler;
/**
* setUp method
*
* @return void
*/
public function setUp() {
parent::setUp();
$this->_server = $_SERVER;
$this->_init();
}
/**
* init method
*
* @return void
*/
function _init() {
$request = new CakeRequest('controller_posts/index');
$response = new CakeResponse();
$this->Controller = new RequestHandlerTestController($request, $response);
$this->RequestHandler = new RequestHandlerComponent($this->Controller->Components);
$this->RequestHandler->request = $request;
$this->RequestHandler->response = $response;
$this->_extensions = Router::extensions();
}
/**
* endTest method
*
* @return void
*/
public function tearDown() {
parent::tearDown();
unset($this->RequestHandler, $this->Controller);
if (!headers_sent()) {
header('Content-type: text/html'); //reset content type.
}
$_SERVER = $this->_server;
call_user_func_array('Router::parseExtensions', $this->_extensions);
}
/**
* Test that the constructor sets the settings.
*
* @return void
*/
public function testConstructorSettings() {
$settings = array(
'ajaxLayout' => 'test_ajax'
);
$Collection = new ComponentCollection();
$RequestHandler = new RequestHandlerComponent($Collection, $settings);
$this->assertEqual($RequestHandler->ajaxLayout, 'test_ajax');
}
/**
* testInitializeCallback method
*
* @return void
*/
public function testInitializeCallback() {
$this->assertNull($this->RequestHandler->ext);
$this->Controller->request->params['ext'] = 'rss';
$this->RequestHandler->initialize($this->Controller);
$this->assertEqual($this->RequestHandler->ext, 'rss');
}
/**
* test that a mapped Accept-type header will set $this->ext correctly.
*
* @return void
*/
public function testInitializeContentTypeSettingExt() {
$this->assertNull($this->RequestHandler->ext);
$_SERVER['HTTP_ACCEPT'] = 'application/json';
Router::parseExtensions('json');
$this->RequestHandler->initialize($this->Controller);
$this->assertEquals('json', $this->RequestHandler->ext);
}
/**
* Test that RequestHandler sets $this->ext when jQuery sends its wonky-ish headers.
*
* @return void
*/
public function testInitializeContentTypeWithjQueryAccept() {
$_SERVER['HTTP_ACCEPT'] = 'application/json, text/javascript, */*; q=0.01';
$this->assertNull($this->RequestHandler->ext);
Router::parseExtensions('json');
$this->RequestHandler->initialize($this->Controller);
$this->assertEquals('json', $this->RequestHandler->ext);
}
/**
* Test that RequestHandler does not set $this->ext when multple accepts are sent.
*
* @return void
*/
public function testInitializeNoContentTypeWithSingleAccept() {
$_SERVER['HTTP_ACCEPT'] = 'application/json, text/html, */*; q=0.01';
$this->assertNull($this->RequestHandler->ext);
Router::parseExtensions('json');
$this->RequestHandler->initialize($this->Controller);
$this->assertNull($this->RequestHandler->ext);
}
/**
* Test that ext is not set with multiple accepted content types.
*
* @return void
*/
public function testInitializeNoContentTypeWithMultipleAcceptedTypes() {
$_SERVER['HTTP_ACCEPT'] = 'application/json, text/javascript, application/xml, */*; q=0.01';
$this->assertNull($this->RequestHandler->ext);
Router::parseExtensions('xml', 'json');
$this->RequestHandler->initialize($this->Controller);
$this->assertNull($this->RequestHandler->ext);
}
/**
* Test that a type mismatch doesn't incorrectly set the ext
*
* @return void
*/
public function testInitializeContentTypeAndExtensionMismatch() {
$this->assertNull($this->RequestHandler->ext);
$extensions = Router::extensions();
Router::parseExtensions('xml');
$this->Controller->request = $this->getMock('CakeRequest');
$this->Controller->request->expects($this->any())
->method('accepts')
->will($this->returnValue(array('application/json')));
$this->RequestHandler->initialize($this->Controller);
$this->assertNull($this->RequestHandler->ext);
call_user_func_array(array('Router', 'parseExtensions'), $extensions);
}
/**
* testDisabling method
*
* @return void
*/
public function testDisabling() {
$_SERVER['HTTP_X_REQUESTED_WITH'] = 'XMLHttpRequest';
$this->_init();
$this->RequestHandler->initialize($this->Controller);
$this->Controller->beforeFilter();
$this->RequestHandler->startup($this->Controller);
$this->assertEqual($this->Controller->params['isAjax'], true);
}
/**
* testAutoResponseType method
*
* @return void
*/
public function testAutoResponseType() {
$this->Controller->ext = '.thtml';
$this->Controller->request->params['ext'] = 'rss';
$this->RequestHandler->initialize($this->Controller);
$this->RequestHandler->startup($this->Controller);
$this->assertEqual($this->Controller->ext, '.ctp');
}
/**
* testAutoAjaxLayout method
*
* @return void
*/
public function testAutoAjaxLayout() {
$_SERVER['HTTP_X_REQUESTED_WITH'] = 'XMLHttpRequest';
$this->RequestHandler->startup($this->Controller);
$this->assertEquals($this->Controller->layout, $this->RequestHandler->ajaxLayout);
$this->_init();
$this->Controller->request->params['ext'] = 'js';
$this->RequestHandler->initialize($this->Controller);
$this->RequestHandler->startup($this->Controller);
$this->assertNotEqual($this->Controller->layout, 'ajax');
unset($_SERVER['HTTP_X_REQUESTED_WITH']);
}
/**
* testStartupCallback method
*
* @return void
*/
public function testStartupCallback() {
$_SERVER['REQUEST_METHOD'] = 'PUT';
$_SERVER['CONTENT_TYPE'] = 'application/xml';
$this->Controller->request = $this->getMock('CakeRequest', array('_readInput'));
$this->RequestHandler->startup($this->Controller);
$this->assertTrue(is_array($this->Controller->data));
$this->assertFalse(is_object($this->Controller->data));
}
/**
* testStartupCallback with charset.
*
* @return void
*/
public function testStartupCallbackCharset() {
$_SERVER['REQUEST_METHOD'] = 'PUT';
$_SERVER['CONTENT_TYPE'] = 'application/xml; charset=UTF-8';
$this->Controller->request = $this->getMock('CakeRequest', array('_readInput'));
$this->RequestHandler->startup($this->Controller);
$this->assertTrue(is_array($this->Controller->data));
$this->assertFalse(is_object($this->Controller->data));
}
/**
* Test mapping a new type and having startup process it.
*
* @return void
*/
public function testStartupCustomTypeProcess() {
if (!function_exists('str_getcsv')) {
$this->markTestSkipped('Need "str_getcsv" for this test.');
}
$_SERVER['REQUEST_METHOD'] = 'POST';
$_SERVER['CONTENT_TYPE'] = 'text/csv';
$this->Controller->request = $this->getMock('CakeRequest', array('_readInput'));
$this->Controller->request->expects($this->once())
->method('_readInput')
->will($this->returnValue('"A","csv","string"'));
$this->RequestHandler->addInputType('csv', array('str_getcsv'));
$this->RequestHandler->startup($this->Controller);
$expected = array(
'A', 'csv', 'string'
);
$this->assertEquals($expected, $this->Controller->request->data);
}
/**
* testNonAjaxRedirect method
*
* @return void
*/
public function testNonAjaxRedirect() {
$this->RequestHandler->initialize($this->Controller);
$this->RequestHandler->startup($this->Controller);
$this->assertNull($this->RequestHandler->beforeRedirect($this->Controller, '/'));
}
/**
* testRenderAs method
*
* @return void
*/
public function testRenderAs() {
$this->assertFalse(in_array('Rss', $this->Controller->helpers));
$this->RequestHandler->renderAs($this->Controller, 'rss');
$this->assertTrue(in_array('Rss', $this->Controller->helpers));
$this->Controller->viewPath = 'request_handler_test\\rss';
$this->RequestHandler->renderAs($this->Controller, 'js');
$this->assertEqual($this->Controller->viewPath, 'request_handler_test' . DS . 'js');
}
/**
* test that attachment headers work with renderAs
*
* @return void
*/
public function testRenderAsWithAttachment() {
$this->RequestHandler->request = $this->getMock('CakeRequest');
$this->RequestHandler->request->expects($this->any())
->method('parseAccept')
->will($this->returnValue(array('1.0' => array('application/xml'))));
$this->RequestHandler->response = $this->getMock('CakeResponse', array('type', 'download', 'charset'));
$this->RequestHandler->response->expects($this->at(0))
->method('type')
->with('application/xml');
$this->RequestHandler->response->expects($this->at(1))
->method('charset')
->with('UTF-8');
$this->RequestHandler->response->expects($this->at(2))
->method('download')
->with('myfile.xml');
$this->RequestHandler->renderAs($this->Controller, 'xml', array('attachment' => 'myfile.xml'));
$expected = 'RequestHandlerTest' . DS . 'xml';
$this->assertEquals($expected, $this->Controller->viewPath);
}
/**
* test that respondAs works as expected.
*
* @return void
*/
public function testRespondAs() {
$this->RequestHandler->response = $this->getMock('CakeResponse', array('type'));
$this->RequestHandler->response->expects($this->at(0))->method('type')
->with('application/json');
$this->RequestHandler->response->expects($this->at(1))->method('type')
->with('text/xml');
$RequestHandler = $this->getMock('RequestHandlerComponent', array('_header'), array(&$this->Controller->Components));
$result = $this->RequestHandler->respondAs('json');
$this->assertTrue($result);
$result = $this->RequestHandler->respondAs('text/xml');
$this->assertTrue($result);
}
/**
* test that attachment headers work with respondAs
*
* @return void
*/
public function testRespondAsWithAttachment() {
$this->RequestHandler = $this->getMock(
'RequestHandlerComponent',
array('_header'),
array(&$this->Controller->Components)
);
$this->RequestHandler->response = $this->getMock('CakeResponse', array('type', 'download'));
$this->RequestHandler->request = $this->getMock('CakeRequest');
$this->RequestHandler->request->expects($this->once())
->method('parseAccept')
->will($this->returnValue(array('1.0' => array('application/xml'))));
$this->RequestHandler->response->expects($this->once())->method('download')
->with('myfile.xml');
$this->RequestHandler->response->expects($this->once())->method('type')
->with('application/xml');
$result = $this->RequestHandler->respondAs('xml', array('attachment' => 'myfile.xml'));
$this->assertTrue($result);
}
/**
* test that calling renderAs() more than once continues to work.
*
* @link #6466
* @return void
*/
public function testRenderAsCalledTwice() {
$this->RequestHandler->renderAs($this->Controller, 'xml');
$this->assertEqual($this->Controller->viewPath, 'RequestHandlerTest' . DS . 'xml');
$this->assertEqual($this->Controller->layoutPath, 'xml');
$this->RequestHandler->renderAs($this->Controller, 'js');
$this->assertEqual($this->Controller->viewPath, 'RequestHandlerTest' . DS . 'js');
$this->assertEqual($this->Controller->layoutPath, 'js');
$this->assertTrue(in_array('Js', $this->Controller->helpers));
}
/**
* testRequestClientTypes method
*
* @return void
*/
public function testRequestClientTypes() {
$_SERVER['HTTP_X_PROTOTYPE_VERSION'] = '1.5';
$this->assertEqual($this->RequestHandler->getAjaxVersion(), '1.5');
unset($_SERVER['HTTP_X_REQUESTED_WITH'], $_SERVER['HTTP_X_PROTOTYPE_VERSION']);
$this->assertFalse($this->RequestHandler->getAjaxVersion());
}
/**
* Tests the detection of various Flash versions
*
* @return void
*/
public function testFlashDetection() {
$request = $this->getMock('CakeRequest');
$request->expects($this->once())->method('is')
->with('flash')
->will($this->returnValue(true));
$this->RequestHandler->request = $request;
$this->assertTrue($this->RequestHandler->isFlash());
}
/**
* testRequestContentTypes method
*
* @return void
*/
public function testRequestContentTypes() {
$_SERVER['REQUEST_METHOD'] = 'GET';
$this->assertNull($this->RequestHandler->requestedWith());
$_SERVER['REQUEST_METHOD'] = 'POST';
$_SERVER['CONTENT_TYPE'] = 'application/json';
$this->assertEqual($this->RequestHandler->requestedWith(), 'json');
$result = $this->RequestHandler->requestedWith(array('json', 'xml'));
$this->assertEqual($result, 'json');
$result =$this->RequestHandler->requestedWith(array('rss', 'atom'));
$this->assertFalse($result);
$_SERVER['HTTP_ACCEPT'] = 'text/xml,application/xml,application/xhtml+xml,text/html,text/plain,image/png,*/*';
$this->assertTrue($this->RequestHandler->isXml());
$this->assertFalse($this->RequestHandler->isAtom());
$this->assertFalse($this->RequestHandler->isRSS());
$_SERVER['HTTP_ACCEPT'] = 'application/atom+xml,text/xml,application/xml,application/xhtml+xml,text/html,text/plain,image/png,*/*';
$this->assertTrue($this->RequestHandler->isAtom());
$this->assertFalse($this->RequestHandler->isRSS());
$_SERVER['HTTP_ACCEPT'] = 'application/rss+xml,text/xml,application/xml,application/xhtml+xml,text/html,text/plain,image/png,*/*';
$this->assertFalse($this->RequestHandler->isAtom());
$this->assertTrue($this->RequestHandler->isRSS());
$this->assertFalse($this->RequestHandler->isWap());
$_SERVER['HTTP_ACCEPT'] = 'text/vnd.wap.wml,text/html,text/plain,image/png,*/*';
$this->assertTrue($this->RequestHandler->isWap());
$_SERVER['HTTP_ACCEPT'] = 'application/rss+xml,text/xml,application/xml,application/xhtml+xml,text/html,text/plain,image/png,*/*';
}
/**
* testResponseContentType method
*
* @return void
*/
public function testResponseContentType() {
$this->assertEquals('html', $this->RequestHandler->responseType());
$this->assertTrue($this->RequestHandler->respondAs('atom'));
$this->assertEqual($this->RequestHandler->responseType(), 'atom');
}
/**
* testMobileDeviceDetection method
*
* @return void
*/
public function testMobileDeviceDetection() {
$request = $this->getMock('CakeRequest');
$request->expects($this->once())->method('is')
->with('mobile')
->will($this->returnValue(true));
$this->RequestHandler->request = $request;
$this->assertTrue($this->RequestHandler->isMobile());
}
/**
* testRequestProperties method
*
* @return void
*/
public function testRequestProperties() {
$request = $this->getMock('CakeRequest');
$request->expects($this->once())->method('is')
->with('ssl')
->will($this->returnValue(true));
$this->RequestHandler->request = $request;
$this->assertTrue($this->RequestHandler->isSsl());
}
/**
* testRequestMethod method
*
* @return void
*/
public function testRequestMethod() {
$request = $this->getMock('CakeRequest');
$request->expects($this->at(0))->method('is')
->with('get')
->will($this->returnValue(true));
$request->expects($this->at(1))->method('is')
->with('post')
->will($this->returnValue(false));
$request->expects($this->at(2))->method('is')
->with('delete')
->will($this->returnValue(true));
$request->expects($this->at(3))->method('is')
->with('put')
->will($this->returnValue(false));
$this->RequestHandler->request = $request;
$this->assertTrue($this->RequestHandler->isGet());
$this->assertFalse($this->RequestHandler->isPost());
$this->assertTrue($this->RequestHandler->isDelete());
$this->assertFalse($this->RequestHandler->isPut());
}
/**
* test that map alias converts aliases to content types.
*
* @return void
*/
public function testMapAlias() {
$result = $this->RequestHandler->mapAlias('xml');
$this->assertEquals('application/xml', $result);
$result = $this->RequestHandler->mapAlias('text/html');
$this->assertNull($result);
$result = $this->RequestHandler->mapAlias('wap');
$this->assertEquals('text/vnd.wap.wml', $result);
$result = $this->RequestHandler->mapAlias(array('xml', 'js', 'json'));
$expected = array('application/xml', 'text/javascript', 'application/json');
$this->assertEquals($expected, $result);
}
/**
* test accepts() on the component
*
* @return void
*/
public function testAccepts() {
$_SERVER['HTTP_ACCEPT'] = 'text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5';
$this->assertEqual($this->RequestHandler->accepts(array('js', 'xml', 'html')), 'xml');
$this->assertFalse($this->RequestHandler->accepts(array('gif', 'jpeg', 'foo')));
$_SERVER['HTTP_ACCEPT'] = '*/*;q=0.5';
$this->assertFalse($this->RequestHandler->accepts('rss'));
}
/**
* test accepts and prefers methods.
*
* @return void
*/
public function testPrefers() {
$_SERVER['HTTP_ACCEPT'] = 'text/xml,application/xml,application/xhtml+xml,text/html,text/plain,image/png,*/*';
$this->assertNotEqual($this->RequestHandler->prefers(), 'rss');
$this->RequestHandler->ext = 'rss';
$this->assertEqual($this->RequestHandler->prefers(), 'rss');
$this->assertFalse($this->RequestHandler->prefers('xml'));
$this->assertEqual($this->RequestHandler->prefers(array('js', 'xml', 'xhtml')), 'xml');
$this->assertFalse($this->RequestHandler->prefers(array('red', 'blue')));
$this->assertEqual($this->RequestHandler->prefers(array('js', 'json', 'xhtml')), 'xhtml');
$this->assertTrue($this->RequestHandler->prefers(array('rss')), 'Should return true if input matches ext.');
$this->assertFalse($this->RequestHandler->prefers(array('html')), 'No match with ext, return false.');
$_SERVER['HTTP_ACCEPT'] = 'text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5';
$this->_init();
$this->assertEqual($this->RequestHandler->prefers(), 'xml');
$_SERVER['HTTP_ACCEPT'] = '*/*;q=0.5';
$this->assertEqual($this->RequestHandler->prefers(), 'html');
$this->assertFalse($this->RequestHandler->prefers('rss'));
}
/**
* testCustomContent method
*
* @return void
*/
public function testCustomContent() {
$_SERVER['HTTP_ACCEPT'] = 'text/x-mobile,text/html;q=0.9,text/plain;q=0.8,*/*;q=0.5';
$this->RequestHandler->setContent('mobile', 'text/x-mobile');
$this->RequestHandler->startup($this->Controller);
$this->assertEqual($this->RequestHandler->prefers(), 'mobile');
}
/**
* testClientProperties method
*
* @return void
*/
public function testClientProperties() {
$request = $this->getMock('CakeRequest');
$request->expects($this->once())->method('referer');
$request->expects($this->once())->method('clientIp')->will($this->returnValue(false));
$this->RequestHandler->request = $request;
$this->RequestHandler->getReferer();
$this->RequestHandler->getClientIP(false);
}
/**
* test that ajax requests involving redirects trigger requestAction instead.
*
* @return void
*/
public function testAjaxRedirectAsRequestAction() {
App::build(array(
'View' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'View'. DS)
), true);
$this->Controller->RequestHandler = $this->getMock('RequestHandlerComponent', array('_stop'), array(&$this->Controller->Components));
$this->Controller->request = $this->getMock('CakeRequest');
$this->Controller->response = $this->getMock('CakeResponse', array('_sendHeader'));
$this->Controller->RequestHandler->request = $this->Controller->request;
$this->Controller->RequestHandler->response = $this->Controller->response;
$this->Controller->request->expects($this->any())->method('is')->will($this->returnValue(true));
$this->Controller->RequestHandler->expects($this->once())->method('_stop');
ob_start();
$this->Controller->RequestHandler->beforeRedirect(
$this->Controller, array('controller' => 'request_handler_test', 'action' => 'destination')
);
$result = ob_get_clean();
$this->assertPattern('/posts index/', $result, 'RequestAction redirect failed.');
App::build();
}
/**
* test that ajax requests involving redirects don't force no layout
* this would cause the ajax layout to not be rendered.
*
* @return void
*/
public function testAjaxRedirectAsRequestActionStillRenderingLayout() {
App::build(array(
'View' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'View'. DS)
), true);
$this->Controller->RequestHandler = $this->getMock('RequestHandlerComponent', array('_stop'), array(&$this->Controller->Components));
$this->Controller->request = $this->getMock('CakeRequest');
$this->Controller->response = $this->getMock('CakeResponse', array('_sendHeader'));
$this->Controller->RequestHandler->request = $this->Controller->request;
$this->Controller->RequestHandler->response = $this->Controller->response;
$this->Controller->request->expects($this->any())->method('is')->will($this->returnValue(true));
$this->Controller->RequestHandler->expects($this->once())->method('_stop');
ob_start();
$this->Controller->RequestHandler->beforeRedirect(
$this->Controller, array('controller' => 'request_handler_test', 'action' => 'ajax2_layout')
);
$result = ob_get_clean();
$this->assertPattern('/posts index/', $result, 'RequestAction redirect failed.');
$this->assertPattern('/Ajax!/', $result, 'Layout was not rendered.');
App::build();
}
/**
* test that the beforeRedirect callback properly converts
* array urls into their correct string ones, and adds base => false so
* the correct urls are generated.
*
* @link http://cakephp.lighthouseapp.com/projects/42648-cakephp-1x/tickets/276
* @return void
*/
public function testBeforeRedirectCallbackWithArrayUrl() {
$_SERVER['HTTP_X_REQUESTED_WITH'] = 'XMLHttpRequest';
Router::setRequestInfo(array(
array('plugin' => null, 'controller' => 'accounts', 'action' => 'index', 'pass' => array(), 'named' => array(), 'form' => array(), 'url' => array('url' => 'accounts/')),
array('base' => '/officespace', 'here' => '/officespace/accounts/', 'webroot' => '/officespace/')
));
$RequestHandler = $this->getMock('RequestHandlerComponent', array('_stop'), array(&$this->Controller->Components));
$RequestHandler->response = $this->getMock('CakeResponse', array('_sendHeader'));
$RequestHandler->request = new CakeRequest('posts/index');
$RequestHandler->response = $this->getMock('CakeResponse', array('_sendHeader'));
ob_start();
$RequestHandler->beforeRedirect(
$this->Controller,
array('controller' => 'request_handler_test', 'action' => 'param_method', 'first', 'second')
);
$result = ob_get_clean();
$this->assertEqual($result, 'one: first two: second');
}
/**
* assure that beforeRedirect with a status code will correctly set the status header
*
* @return void
*/
public function testBeforeRedirectCallingHeader() {
$_SERVER['HTTP_X_REQUESTED_WITH'] = 'XMLHttpRequest';
$controller = $this->getMock('Controller', array('header'));
$RequestHandler = $this->getMock('RequestHandlerComponent', array('_stop'), array(&$this->Controller->Components));
$RequestHandler->response = $this->getMock('CakeResponse', array('_sendHeader','statusCode'));
$RequestHandler->request = $this->getMock('CakeRequest');
$RequestHandler->request->expects($this->once())->method('is')
->with('ajax')
->will($this->returnValue(true));
$RequestHandler->response->expects($this->once())->method('statusCode')->with(403);
ob_start();
$RequestHandler->beforeRedirect($controller, 'request_handler_test/param_method/first/second', 403);
$result = ob_get_clean();
}
/**
* @expectedException CakeException
* @return void
*/
public function testAddInputTypeException() {
$this->RequestHandler->addInputType('csv', array('I am not callable'));
}
}
| 0001-bee | trunk/cakephp2/lib/Cake/Test/Case/Controller/Component/RequestHandlerComponentTest.php | PHP | gpl3 | 25,542 |
<?php
/**
* PaginatorComponentTest file
*
* Series of tests for paginator component.
*
* PHP 5
*
* CakePHP(tm) Tests <http://book.cakephp.org/view/1196/Testing>
* Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice
*
* @copyright Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://book.cakephp.org/view/1196/Testing CakePHP(tm) Tests
* @package Cake.Test.Case.Controller.Component
* @since CakePHP(tm) v 2.0
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
App::uses('Controller', 'Controller');
App::uses('PaginatorComponent', 'Controller/Component');
App::uses('CakeRequest', 'Network');
App::uses('CakeResponse', 'Network');
/**
* PaginatorTestController class
*
* @package Cake.Test.Case.Controller.Component
*/
class PaginatorTestController extends Controller {
/**
* name property
*
* @var string 'PaginatorTest'
*/
public $name = 'PaginatorTest';
/**
* uses property
*
* @var array
*/
//public $uses = null;
/**
* components property
*
* @var array
*/
public $components = array('Paginator');
}
/**
* PaginatorControllerPost class
*
* @package Cake.Test.Case.Controller.Component
*/
class PaginatorControllerPost extends CakeTestModel {
/**
* name property
*
* @var string 'PaginatorControllerPost'
*/
public $name = 'PaginatorControllerPost';
/**
* useTable property
*
* @var string 'posts'
*/
public $useTable = 'posts';
/**
* invalidFields property
*
* @var array
*/
public $invalidFields = array('name' => 'error_msg');
/**
* lastQueries property
*
* @var array
*/
public $lastQueries = array();
/**
* beforeFind method
*
* @param mixed $query
* @return void
*/
public function beforeFind($query) {
array_unshift($this->lastQueries, $query);
}
/**
* find method
*
* @param mixed $type
* @param array $options
* @return void
*/
public function find($conditions = null, $fields = array(), $order = null, $recursive = null) {
if ($conditions == 'popular') {
$conditions = array($this->name . '.' . $this->primaryKey .' > ' => '1');
$options = Set::merge($fields, compact('conditions'));
return parent::find('all', $options);
}
return parent::find($conditions, $fields);
}
}
/**
* ControllerPaginateModel class
*
* @package Cake.Test.Case.Controller.Component
*/
class ControllerPaginateModel extends CakeTestModel {
/**
* name property
*
* @var string 'ControllerPaginateModel'
*/
public $name = 'ControllerPaginateModel';
/**
* useTable property
*
* @var string 'comments'
*/
public $useTable = 'comments';
/**
* paginate method
*
* @return void
*/
public function paginate($conditions, $fields, $order, $limit, $page, $recursive, $extra) {
$this->extra = $extra;
}
/**
* paginateCount
*
* @return void
*/
public function paginateCount($conditions, $recursive, $extra) {
$this->extraCount = $extra;
}
}
/**
* PaginatorControllerCommentclass
*
* @package Cake.Test.Case.Controller.Component
*/
class PaginatorControllerComment extends CakeTestModel {
/**
* name property
*
* @var string 'Comment'
*/
public $name = 'Comment';
/**
* useTable property
*
* @var string 'comments'
*/
public $useTable = 'comments';
/**
* alias property
*
* @var string 'PaginatorControllerComment'
*/
public $alias = 'PaginatorControllerComment';
}
class PaginatorComponentTest extends CakeTestCase {
/**
* fixtures property
*
* @var array
*/
public $fixtures = array('core.post', 'core.comment');
/**
* setup
*
* @return void
*/
public function setUp() {
parent::setUp();
$this->request = new CakeRequest('controller_posts/index');
$this->request->params['pass'] = $this->request->params['named'] = array();
$this->Controller = new Controller($this->request);
$this->Paginator = new PaginatorComponent($this->getMock('ComponentCollection'), array());
$this->Paginator->Controller = $this->Controller;
$this->Controller->Post = $this->getMock('Model');
$this->Controller->Post->alias = 'Post';
}
/**
* testPaginate method
*
* @return void
*/
public function testPaginate() {
$Controller = new PaginatorTestController($this->request);
$Controller->uses = array('PaginatorControllerPost', 'PaginatorControllerComment');
$Controller->request->params['pass'] = array('1');
$Controller->request->query = array();
$Controller->constructClasses();
$results = Set::extract($Controller->Paginator->paginate('PaginatorControllerPost'), '{n}.PaginatorControllerPost.id');
$this->assertEqual($results, array(1, 2, 3));
$results = Set::extract($Controller->Paginator->paginate('PaginatorControllerComment'), '{n}.PaginatorControllerComment.id');
$this->assertEqual($results, array(1, 2, 3, 4, 5, 6));
$Controller->modelClass = null;
$Controller->uses[0] = 'Plugin.PaginatorControllerPost';
$results = Set::extract($Controller->Paginator->paginate(), '{n}.PaginatorControllerPost.id');
$this->assertEqual($results, array(1, 2, 3));
$Controller->request->params['named'] = array('page' => '-1');
$results = Set::extract($Controller->Paginator->paginate('PaginatorControllerPost'), '{n}.PaginatorControllerPost.id');
$this->assertEqual($Controller->params['paging']['PaginatorControllerPost']['page'], 1);
$this->assertEqual($results, array(1, 2, 3));
$Controller->request->params['named'] = array('sort' => 'PaginatorControllerPost.id', 'direction' => 'asc');
$results = Set::extract($Controller->Paginator->paginate('PaginatorControllerPost'), '{n}.PaginatorControllerPost.id');
$this->assertEqual($Controller->params['paging']['PaginatorControllerPost']['page'], 1);
$this->assertEqual($results, array(1, 2, 3));
$Controller->request->params['named'] = array('sort' => 'PaginatorControllerPost.id', 'direction' => 'desc');
$results = Set::extract($Controller->Paginator->paginate('PaginatorControllerPost'), '{n}.PaginatorControllerPost.id');
$this->assertEqual($Controller->params['paging']['PaginatorControllerPost']['page'], 1);
$this->assertEqual($results, array(3, 2, 1));
$Controller->request->params['named'] = array('sort' => 'id', 'direction' => 'desc');
$results = Set::extract($Controller->Paginator->paginate('PaginatorControllerPost'), '{n}.PaginatorControllerPost.id');
$this->assertEqual($Controller->params['paging']['PaginatorControllerPost']['page'], 1);
$this->assertEqual($results, array(3, 2, 1));
$Controller->request->params['named'] = array('sort' => 'NotExisting.field', 'direction' => 'desc');
$results = Set::extract($Controller->Paginator->paginate('PaginatorControllerPost'), '{n}.PaginatorControllerPost.id');
$this->assertEqual($Controller->params['paging']['PaginatorControllerPost']['page'], 1, 'Invalid field in query %s');
$this->assertEqual($results, array(1, 2, 3));
$Controller->request->params['named'] = array(
'sort' => 'PaginatorControllerPost.author_id', 'direction' => 'allYourBase'
);
$results = Set::extract($Controller->Paginator->paginate('PaginatorControllerPost'), '{n}.PaginatorControllerPost.id');
$this->assertEqual($Controller->PaginatorControllerPost->lastQueries[1]['order'][0], array('PaginatorControllerPost.author_id' => 'asc'));
$this->assertEqual($results, array(1, 3, 2));
$Controller->request->params['named'] = array();
$Controller->Paginator->settings = array('limit' => 0, 'maxLimit' => 10, 'paramType' => 'named');
$Controller->Paginator->paginate('PaginatorControllerPost');
$this->assertIdentical($Controller->params['paging']['PaginatorControllerPost']['page'], 1);
$this->assertIdentical($Controller->params['paging']['PaginatorControllerPost']['pageCount'], 3);
$this->assertIdentical($Controller->params['paging']['PaginatorControllerPost']['prevPage'], false);
$this->assertIdentical($Controller->params['paging']['PaginatorControllerPost']['nextPage'], true);
$Controller->request->params['named'] = array();
$Controller->Paginator->settings = array('limit' => 'garbage!', 'maxLimit' => 10, 'paramType' => 'named');
$Controller->Paginator->paginate('PaginatorControllerPost');
$this->assertIdentical($Controller->params['paging']['PaginatorControllerPost']['page'], 1);
$this->assertIdentical($Controller->params['paging']['PaginatorControllerPost']['pageCount'], 3);
$this->assertIdentical($Controller->params['paging']['PaginatorControllerPost']['prevPage'], false);
$this->assertIdentical($Controller->params['paging']['PaginatorControllerPost']['nextPage'], true);
$Controller->request->params['named'] = array();
$Controller->Paginator->settings = array('limit' => '-1', 'maxLimit' => 10, 'paramType' => 'named');
$Controller->Paginator->paginate('PaginatorControllerPost');
$this->assertIdentical($Controller->params['paging']['PaginatorControllerPost']['limit'], 1);
$this->assertIdentical($Controller->params['paging']['PaginatorControllerPost']['page'], 1);
$this->assertIdentical($Controller->params['paging']['PaginatorControllerPost']['pageCount'], 3);
$this->assertIdentical($Controller->params['paging']['PaginatorControllerPost']['prevPage'], false);
$this->assertIdentical($Controller->params['paging']['PaginatorControllerPost']['nextPage'], true);
}
/**
* Test that non-numeric values are rejected for page, and limit
*
* @return void
*/
public function testPageParamCasting() {
$this->Controller->Post->expects($this->at(0))
->method('hasMethod')
->with('paginate')
->will($this->returnValue(false));
$this->Controller->Post->expects($this->at(1))
->method('find')
->will($this->returnValue(array('stuff')));
$this->Controller->Post->expects($this->at(2))
->method('hasMethod')
->with('paginateCount')
->will($this->returnValue(false));
$this->Controller->Post->expects($this->at(3))
->method('find')
->will($this->returnValue(2));
$this->request->params['named'] = array('page' => '1 " onclick="alert(\'xss\');">');
$this->Paginator->settings = array('limit' => 1, 'maxLimit' => 10, 'paramType' => 'named');
$this->Paginator->paginate('Post');
$this->assertSame(1, $this->request->params['paging']['Post']['page'], 'XSS exploit opened');
}
/**
* testPaginateExtraParams method
*
* @return void
*/
public function testPaginateExtraParams() {
$Controller = new PaginatorTestController($this->request);
$Controller->uses = array('PaginatorControllerPost', 'PaginatorControllerComment');
$Controller->request->params['pass'] = array('1');
$Controller->params['url'] = array();
$Controller->constructClasses();
$Controller->request->params['named'] = array('page' => '-1', 'contain' => array('PaginatorControllerComment'));
$result = $Controller->Paginator->paginate('PaginatorControllerPost');
$this->assertEqual($Controller->params['paging']['PaginatorControllerPost']['page'], 1);
$this->assertEqual(Set::extract($result, '{n}.PaginatorControllerPost.id'), array(1, 2, 3));
$this->assertTrue(!isset($Controller->PaginatorControllerPost->lastQueries[1]['contain']));
$Controller->request->params['named'] = array('page' => '-1');
$Controller->Paginator->settings = array(
'PaginatorControllerPost' => array(
'contain' => array('PaginatorControllerComment'),
'maxLimit' => 10,
'paramType' => 'named'
),
);
$result = $Controller->Paginator->paginate('PaginatorControllerPost');
$this->assertEqual($Controller->params['paging']['PaginatorControllerPost']['page'], 1);
$this->assertEqual(Set::extract($result, '{n}.PaginatorControllerPost.id'), array(1, 2, 3));
$this->assertTrue(isset($Controller->PaginatorControllerPost->lastQueries[1]['contain']));
$Controller->Paginator->settings = array(
'PaginatorControllerPost' => array(
'popular', 'fields' => array('id', 'title'), 'maxLimit' => 10, 'paramType' => 'named'
),
);
$result = $Controller->Paginator->paginate('PaginatorControllerPost');
$this->assertEqual(Set::extract($result, '{n}.PaginatorControllerPost.id'), array(2, 3));
$this->assertEqual($Controller->PaginatorControllerPost->lastQueries[1]['conditions'], array('PaginatorControllerPost.id > ' => '1'));
$Controller->request->params['named'] = array('limit' => 12);
$Controller->Paginator->settings = array('limit' => 30, 'maxLimit' => 100, 'paramType' => 'named');
$result = $Controller->Paginator->paginate('PaginatorControllerPost');
$paging = $Controller->params['paging']['PaginatorControllerPost'];
$this->assertEqual($Controller->PaginatorControllerPost->lastQueries[1]['limit'], 12);
$this->assertEqual($paging['options']['limit'], 12);
$Controller = new PaginatorTestController($this->request);
$Controller->uses = array('ControllerPaginateModel');
$Controller->request->query = array();
$Controller->constructClasses();
$Controller->Paginator->settings = array(
'ControllerPaginateModel' => array(
'contain' => array('ControllerPaginateModel'),
'group' => 'Comment.author_id',
'maxLimit' => 10,
'paramType' => 'named'
)
);
$result = $Controller->Paginator->paginate('ControllerPaginateModel');
$expected = array(
'contain' => array('ControllerPaginateModel'),
'group' => 'Comment.author_id',
'maxLimit' => 10,
'paramType' => 'named'
);
$this->assertEqual($Controller->ControllerPaginateModel->extra, $expected);
$this->assertEqual($Controller->ControllerPaginateModel->extraCount, $expected);
$Controller->Paginator->settings = array(
'ControllerPaginateModel' => array(
'foo', 'contain' => array('ControllerPaginateModel'),
'group' => 'Comment.author_id',
'maxLimit' => 10,
'paramType' => 'named'
)
);
$Controller->Paginator->paginate('ControllerPaginateModel');
$expected = array(
'contain' => array('ControllerPaginateModel'),
'group' => 'Comment.author_id',
'type' => 'foo',
'maxLimit' => 10,
'paramType' => 'named'
);
$this->assertEqual($Controller->ControllerPaginateModel->extra, $expected);
$this->assertEqual($Controller->ControllerPaginateModel->extraCount, $expected);
}
/**
* Test that special paginate types are called and that the type param doesn't leak out into defaults or options.
*
* @return void
*/
public function testPaginateSpecialType() {
$Controller = new PaginatorTestController($this->request);
$Controller->uses = array('PaginatorControllerPost', 'PaginatorControllerComment');
$Controller->passedArgs[] = '1';
$Controller->params['url'] = array();
$Controller->constructClasses();
$Controller->Paginator->settings = array(
'PaginatorControllerPost' => array(
'popular',
'fields' => array('id', 'title'),
'maxLimit' => 10,
'paramType' => 'named'
)
);
$result = $Controller->Paginator->paginate('PaginatorControllerPost');
$this->assertEqual(Set::extract($result, '{n}.PaginatorControllerPost.id'), array(2, 3));
$this->assertEqual(
$Controller->PaginatorControllerPost->lastQueries[1]['conditions'],
array('PaginatorControllerPost.id > ' => '1')
);
$this->assertFalse(isset($Controller->params['paging']['PaginatorControllerPost']['options'][0]));
}
/**
* testDefaultPaginateParams method
*
* @return void
*/
public function testDefaultPaginateParams() {
$Controller = new PaginatorTestController($this->request);
$Controller->modelClass = 'PaginatorControllerPost';
$Controller->params['url'] = array();
$Controller->constructClasses();
$Controller->Paginator->settings = array(
'order' => 'PaginatorControllerPost.id DESC',
'maxLimit' => 10,
'paramType' => 'named'
);
$results = Set::extract($Controller->Paginator->paginate('PaginatorControllerPost'), '{n}.PaginatorControllerPost.id');
$this->assertEqual($Controller->params['paging']['PaginatorControllerPost']['order'], 'PaginatorControllerPost.id DESC');
$this->assertEqual($results, array(3, 2, 1));
}
/**
* test paginate() and virtualField interactions
*
* @return void
*/
public function testPaginateOrderVirtualField() {
$Controller = new PaginatorTestController($this->request);
$Controller->uses = array('PaginatorControllerPost', 'PaginatorControllerComment');
$Controller->params['url'] = array();
$Controller->constructClasses();
$Controller->PaginatorControllerPost->virtualFields = array(
'offset_test' => 'PaginatorControllerPost.id + 1'
);
$Controller->Paginator->settings = array(
'fields' => array('id', 'title', 'offset_test'),
'order' => array('offset_test' => 'DESC'),
'maxLimit' => 10,
'paramType' => 'named'
);
$result = $Controller->Paginator->paginate('PaginatorControllerPost');
$this->assertEqual(Set::extract($result, '{n}.PaginatorControllerPost.offset_test'), array(4, 3, 2));
$Controller->request->params['named'] = array('sort' => 'offset_test', 'direction' => 'asc');
$result = $Controller->Paginator->paginate('PaginatorControllerPost');
$this->assertEqual(Set::extract($result, '{n}.PaginatorControllerPost.offset_test'), array(2, 3, 4));
}
/**
* Tests for missing models
*
* @expectedException MissingModelException
*/
public function testPaginateMissingModel() {
$Controller = new PaginatorTestController($this->request);
$Controller->constructClasses();
$Controller->Paginator->paginate('MissingModel');
}
/**
* test that option merging prefers specific models
*
* @return void
*/
public function testMergeOptionsModelSpecific() {
$this->Paginator->settings = array(
'page' => 1,
'limit' => 20,
'maxLimit' => 100,
'paramType' => 'named',
'Post' => array(
'page' => 1,
'limit' => 10,
'maxLimit' => 50,
'paramType' => 'named',
)
);
$result = $this->Paginator->mergeOptions('Silly');
$this->assertEquals($this->Paginator->settings, $result);
$result = $this->Paginator->mergeOptions('Post');
$expected = array('page' => 1, 'limit' => 10, 'paramType' => 'named', 'maxLimit' => 50);
$this->assertEquals($expected, $result);
}
/**
* test mergeOptions with named params.
*
* @return void
*/
public function testMergeOptionsNamedParams() {
$this->request->params['named'] = array(
'page' => 10,
'limit' => 10
);
$this->Paginator->settings = array(
'page' => 1,
'limit' => 20,
'maxLimit' => 100,
'paramType' => 'named',
);
$result = $this->Paginator->mergeOptions('Post');
$expected = array('page' => 10, 'limit' => 10, 'maxLimit' => 100, 'paramType' => 'named');
$this->assertEquals($expected, $result);
}
/**
* test merging options from the querystring.
*
* @return void
*/
public function testMergeOptionsQueryString() {
$this->request->params['named'] = array(
'page' => 10,
'limit' => 10
);
$this->request->query = array(
'page' => 99,
'limit' => 75
);
$this->Paginator->settings = array(
'page' => 1,
'limit' => 20,
'maxLimit' => 100,
'paramType' => 'querystring',
);
$result = $this->Paginator->mergeOptions('Post');
$expected = array('page' => 99, 'limit' => 75, 'maxLimit' => 100, 'paramType' => 'querystring');
$this->assertEquals($expected, $result);
}
/**
* test that the default whitelist doesn't let people screw with things they should not be allowed to.
*
* @return void
*/
public function testMergeOptionsDefaultWhiteList() {
$this->request->params['named'] = array(
'page' => 10,
'limit' => 10,
'fields' => array('bad.stuff'),
'recursive' => 1000,
'conditions' => array('bad.stuff'),
'contain' => array('bad')
);
$this->Paginator->settings = array(
'page' => 1,
'limit' => 20,
'maxLimit' => 100,
'paramType' => 'named',
);
$result = $this->Paginator->mergeOptions('Post');
$expected = array('page' => 10, 'limit' => 10, 'maxLimit' => 100, 'paramType' => 'named');
$this->assertEquals($expected, $result);
}
/**
* test that modifying the whitelist works.
*
* @return void
*/
public function testMergeOptionsExtraWhitelist() {
$this->request->params['named'] = array(
'page' => 10,
'limit' => 10,
'fields' => array('bad.stuff'),
'recursive' => 1000,
'conditions' => array('bad.stuff'),
'contain' => array('bad')
);
$this->Paginator->settings = array(
'page' => 1,
'limit' => 20,
'maxLimit' => 100,
'paramType' => 'named',
);
$this->Paginator->whitelist[] = 'fields';
$result = $this->Paginator->mergeOptions('Post');
$expected = array(
'page' => 10, 'limit' => 10, 'maxLimit' => 100, 'paramType' => 'named', 'fields' => array('bad.stuff')
);
$this->assertEquals($expected, $result);
}
/**
* test that invalid directions are ignored.
*
* @return void
*/
public function testValidateSortInvalidDirection() {
$model = $this->getMock('Model');
$model->alias = 'model';
$model->expects($this->any())->method('hasField')->will($this->returnValue(true));
$options = array('sort' => 'something', 'direction' => 'boogers');
$result = $this->Paginator->validateSort($model, $options);
$this->assertEquals('asc', $result['order']['model.something']);
}
/**
* test that fields not in whitelist won't be part of order conditions.
*
* @return void
*/
public function testValidateSortWhitelistFailure() {
$model = $this->getMock('Model');
$model->alias = 'model';
$model->expects($this->any())->method('hasField')->will($this->returnValue(true));
$options = array('sort' => 'body', 'direction' => 'asc');
$result = $this->Paginator->validateSort($model, $options, array('title', 'id'));
$this->assertNull($result['order']);
}
/**
* test that virtual fields work.
*
* @return void
*/
public function testValidateSortVirtualField() {
$model = $this->getMock('Model');
$model->alias = 'model';
$model->expects($this->at(0))
->method('hasField')
->with('something')
->will($this->returnValue(false));
$model->expects($this->at(1))
->method('hasField')
->with('something', true)
->will($this->returnValue(true));
$options = array('sort' => 'something', 'direction' => 'desc');
$result = $this->Paginator->validateSort($model, $options);
$this->assertEquals('desc', $result['order']['something']);
}
/**
* test that multiple sort works.
*
* @return void
*/
public function testValidateSortMultiple() {
$model = $this->getMock('Model');
$model->alias = 'model';
$model->expects($this->any())->method('hasField')->will($this->returnValue(true));
$options = array('order' => array(
'author_id' => 'asc',
'title' => 'asc'
));
$result = $this->Paginator->validateSort($model, $options);
$expected = array(
'model.author_id' => 'asc',
'model.title' => 'asc'
);
$this->assertEquals($expected, $result['order']);
}
/**
* test that maxLimit is respected
*
* @return void
*/
public function testCheckLimit() {
$result = $this->Paginator->checkLimit(array('limit' => 1000000, 'maxLimit' => 100));
$this->assertEquals(100, $result['limit']);
$result = $this->Paginator->checkLimit(array('limit' => 'sheep!', 'maxLimit' => 100));
$this->assertEquals(1, $result['limit']);
$result = $this->Paginator->checkLimit(array('limit' => '-1', 'maxLimit' => 100));
$this->assertEquals(1, $result['limit']);
$result = $this->Paginator->checkLimit(array('limit' => null, 'maxLimit' => 100));
$this->assertEquals(1, $result['limit']);
$result = $this->Paginator->checkLimit(array('limit' => 0, 'maxLimit' => 100));
$this->assertEquals(1, $result['limit']);
}
/**
* testPaginateMaxLimit
*
* @return void
*/
public function testPaginateMaxLimit() {
$Controller = new Controller($this->request);
$Controller->uses = array('PaginatorControllerPost', 'ControllerComment');
$Controller->passedArgs[] = '1';
$Controller->constructClasses();
$Controller->request->params['named'] = array(
'contain' => array('ControllerComment'), 'limit' => '1000'
);
$result = $Controller->paginate('PaginatorControllerPost');
$this->assertEqual($Controller->params['paging']['PaginatorControllerPost']['options']['limit'], 100);
$Controller->request->params['named'] = array(
'contain' => array('ControllerComment'), 'limit' => '1000', 'maxLimit' => 1000
);
$result = $Controller->paginate('PaginatorControllerPost');
$this->assertEqual($Controller->params['paging']['PaginatorControllerPost']['options']['limit'], 100);
$Controller->request->params['named'] = array('contain' => array('ControllerComment'), 'limit' => '10');
$result = $Controller->paginate('PaginatorControllerPost');
$this->assertEqual($Controller->params['paging']['PaginatorControllerPost']['options']['limit'], 10);
$Controller->request->params['named'] = array('contain' => array('ControllerComment'), 'limit' => '1000');
$Controller->paginate = array('maxLimit' => 2000, 'paramType' => 'named');
$result = $Controller->paginate('PaginatorControllerPost');
$this->assertEqual($Controller->params['paging']['PaginatorControllerPost']['options']['limit'], 1000);
$Controller->request->params['named'] = array('contain' => array('ControllerComment'), 'limit' => '5000');
$result = $Controller->paginate('PaginatorControllerPost');
$this->assertEqual($Controller->params['paging']['PaginatorControllerPost']['options']['limit'], 2000);
}
/**
* test paginate() and virtualField overlapping with real fields.
*
* @return void
*/
function testPaginateOrderVirtualFieldSharedWithRealField() {
$Controller =& new Controller($this->request);
$Controller->uses = array('PaginatorControllerPost', 'PaginatorControllerComment');
$Controller->constructClasses();
$Controller->PaginatorControllerComment->virtualFields = array(
'title' => 'PaginatorControllerComment.comment'
);
$Controller->PaginatorControllerComment->bindModel(array(
'belongsTo' => array(
'PaginatorControllerPost' => array(
'className' => 'PaginatorControllerPost',
'foreignKey' => 'article_id'
)
)
), false);
$Controller->paginate = array(
'fields' => array('PaginatorControllerComment.id', 'title', 'PaginatorControllerPost.title'),
);
$Controller->passedArgs = array('sort' => 'PaginatorControllerPost.title', 'dir' => 'asc');
$result = $Controller->paginate('PaginatorControllerComment');
$this->assertEqual(Set::extract($result, '{n}.PaginatorControllerComment.id'), array(1, 2, 3, 4, 5, 6));
}
}
| 0001-bee | trunk/cakephp2/lib/Cake/Test/Case/Controller/Component/PaginatorComponentTest.php | PHP | gpl3 | 26,432 |
<?php
/**
* SecurityComponentTest file
*
* PHP 5
*
* CakePHP(tm) Tests <http://book.cakephp.org/view/1196/Testing>
* Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice
*
* @copyright Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://book.cakephp.org/view/1196/Testing CakePHP(tm) Tests
* @package Cake.Test.Case.Controller.Component
* @since CakePHP(tm) v 1.2.0.5435
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
App::uses('SecurityComponent', 'Controller/Component');
App::uses('Controller', 'Controller');
/**
* TestSecurityComponent
*
* @package Cake.Test.Case.Controller.Component
* @package Cake.Test.Case.Controller.Component
*/
class TestSecurityComponent extends SecurityComponent {
/**
* validatePost method
*
* @param Controller $controller
* @return unknown
*/
public function validatePost($controller) {
return $this->_validatePost($controller);
}
}
/**
* SecurityTestController
*
* @package Cake.Test.Case.Controller.Component
* @package Cake.Test.Case.Controller.Component
*/
class SecurityTestController extends Controller {
/**
* name property
*
* @var string 'SecurityTest'
*/
public $name = 'SecurityTest';
/**
* components property
*
* @var array
*/
public $components = array('Session', 'TestSecurity');
/**
* failed property
*
* @var bool false
*/
public $failed = false;
/**
* Used for keeping track of headers in test
*
* @var array
*/
public $testHeaders = array();
/**
* fail method
*
* @return void
*/
public function fail() {
$this->failed = true;
}
/**
* redirect method
*
* @param mixed $option
* @param mixed $code
* @param mixed $exit
* @return void
*/
public function redirect($url, $status = null, $exit = true) {
return $status;
}
/**
* Conveinence method for header()
*
* @param string $status
* @return void
*/
public function header($status) {
$this->testHeaders[] = $status;
}
}
/**
* SecurityComponentTest class
*
* @package Cake.Test.Case.Controller.Component
*/
class SecurityComponentTest extends CakeTestCase {
/**
* Controller property
*
* @var SecurityTestController
*/
public $Controller;
/**
* oldSalt property
*
* @var string
*/
public $oldSalt;
/**
* setUp method
*
* @return void
*/
public function setUp() {
parent::setUp();
$request = new CakeRequest('posts/index', false);
$request->addParams(array('controller' => 'posts', 'action' => 'index'));
$this->Controller = new SecurityTestController($request);
$this->Controller->Components->init($this->Controller);
$this->Controller->Security = $this->Controller->TestSecurity;
$this->Controller->Security->blackHoleCallback = 'fail';
$this->Security = $this->Controller->Security;
$this->Security->csrfCheck = false;
Configure::write('Security.salt', 'foo!');
}
/**
* Tear-down method. Resets environment state.
*
* @return void
*/
public function tearDown() {
parent::tearDown();
$this->Controller->Session->delete('_Token');
unset($this->Controller->Security);
unset($this->Controller->Component);
unset($this->Controller);
}
/**
* test that initalize can set properties.
*
* @return void
*/
public function testConstructorSettingProperties() {
$settings = array(
'requirePost' => array('edit', 'update'),
'requireSecure' => array('update_account'),
'requireGet' => array('index'),
'validatePost' => false,
);
$Security = new SecurityComponent($this->Controller->Components, $settings);
$this->Controller->Security->initialize($this->Controller, $settings);
$this->assertEqual($Security->requirePost, $settings['requirePost']);
$this->assertEqual($Security->requireSecure, $settings['requireSecure']);
$this->assertEqual($Security->requireGet, $settings['requireGet']);
$this->assertEqual($Security->validatePost, $settings['validatePost']);
}
/**
* testStartup method
*
* @return void
*/
public function testStartup() {
$this->Controller->Security->startup($this->Controller);
$result = $this->Controller->params['_Token']['key'];
$this->assertNotNull($result);
$this->assertTrue($this->Controller->Session->check('_Token'));
}
/**
* testRequirePostFail method
*
* @return void
*/
public function testRequirePostFail() {
$_SERVER['REQUEST_METHOD'] = 'GET';
$this->Controller->request['action'] = 'posted';
$this->Controller->Security->requirePost(array('posted'));
$this->Controller->Security->startup($this->Controller);
$this->assertTrue($this->Controller->failed);
}
/**
* testRequirePostSucceed method
*
* @return void
*/
public function testRequirePostSucceed() {
$_SERVER['REQUEST_METHOD'] = 'POST';
$this->Controller->request['action'] = 'posted';
$this->Controller->Security->requirePost('posted');
$this->Security->startup($this->Controller);
$this->assertFalse($this->Controller->failed);
}
/**
* testRequireSecureFail method
*
* @return void
*/
public function testRequireSecureFail() {
$_SERVER['HTTPS'] = 'off';
$_SERVER['REQUEST_METHOD'] = 'POST';
$this->Controller->request['action'] = 'posted';
$this->Controller->Security->requireSecure(array('posted'));
$this->Controller->Security->startup($this->Controller);
$this->assertTrue($this->Controller->failed);
}
/**
* testRequireSecureSucceed method
*
* @return void
*/
public function testRequireSecureSucceed() {
$_SERVER['REQUEST_METHOD'] = 'Secure';
$this->Controller->request['action'] = 'posted';
$_SERVER['HTTPS'] = 'on';
$this->Controller->Security->requireSecure('posted');
$this->Controller->Security->startup($this->Controller);
$this->assertFalse($this->Controller->failed);
}
/**
* testRequireAuthFail method
*
* @return void
*/
public function testRequireAuthFail() {
$_SERVER['REQUEST_METHOD'] = 'AUTH';
$this->Controller->request['action'] = 'posted';
$this->Controller->request->data = array('username' => 'willy', 'password' => 'somePass');
$this->Controller->Security->requireAuth(array('posted'));
$this->Controller->Security->startup($this->Controller);
$this->assertTrue($this->Controller->failed);
$this->Controller->Session->write('_Token', array('allowedControllers' => array()));
$this->Controller->request->data = array('username' => 'willy', 'password' => 'somePass');
$this->Controller->request['action'] = 'posted';
$this->Controller->Security->requireAuth('posted');
$this->Controller->Security->startup($this->Controller);
$this->assertTrue($this->Controller->failed);
$this->Controller->Session->write('_Token', array(
'allowedControllers' => array('SecurityTest'), 'allowedActions' => array('posted2')
));
$this->Controller->request->data = array('username' => 'willy', 'password' => 'somePass');
$this->Controller->request['action'] = 'posted';
$this->Controller->Security->requireAuth('posted');
$this->Controller->Security->startup($this->Controller);
$this->assertTrue($this->Controller->failed);
}
/**
* testRequireAuthSucceed method
*
* @return void
*/
public function testRequireAuthSucceed() {
$_SERVER['REQUEST_METHOD'] = 'AUTH';
$this->Controller->request['action'] = 'posted';
$this->Controller->Security->requireAuth('posted');
$this->Controller->Security->startup($this->Controller);
$this->assertFalse($this->Controller->failed);
$this->Controller->Security->Session->write('_Token', array(
'allowedControllers' => array('SecurityTest'), 'allowedActions' => array('posted')
));
$this->Controller->request['controller'] = 'SecurityTest';
$this->Controller->request['action'] = 'posted';
$this->Controller->request->data = array(
'username' => 'willy', 'password' => 'somePass', '_Token' => ''
);
$this->Controller->action = 'posted';
$this->Controller->Security->requireAuth('posted');
$this->Controller->Security->startup($this->Controller);
$this->assertFalse($this->Controller->failed);
}
/**
* testRequirePostSucceedWrongMethod method
*
* @return void
*/
public function testRequirePostSucceedWrongMethod() {
$_SERVER['REQUEST_METHOD'] = 'GET';
$this->Controller->request['action'] = 'getted';
$this->Controller->Security->requirePost('posted');
$this->Controller->Security->startup($this->Controller);
$this->assertFalse($this->Controller->failed);
}
/**
* testRequireGetFail method
*
* @return void
*/
public function testRequireGetFail() {
$_SERVER['REQUEST_METHOD'] = 'POST';
$this->Controller->request['action'] = 'getted';
$this->Controller->Security->requireGet(array('getted'));
$this->Controller->Security->startup($this->Controller);
$this->assertTrue($this->Controller->failed);
}
/**
* testRequireGetSucceed method
*
* @return void
*/
public function testRequireGetSucceed() {
$_SERVER['REQUEST_METHOD'] = 'GET';
$this->Controller->request['action'] = 'getted';
$this->Controller->Security->requireGet('getted');
$this->Controller->Security->startup($this->Controller);
$this->assertFalse($this->Controller->failed);
}
/**
* testRequireGetSucceedWrongMethod method
*
* @return void
*/
public function testRequireGetSucceedWrongMethod() {
$_SERVER['REQUEST_METHOD'] = 'POST';
$this->Controller->request['action'] = 'posted';
$this->Security->requireGet('getted');
$this->Security->startup($this->Controller);
$this->assertFalse($this->Controller->failed);
}
/**
* testRequirePutFail method
*
* @return void
*/
public function testRequirePutFail() {
$_SERVER['REQUEST_METHOD'] = 'POST';
$this->Controller->request['action'] = 'putted';
$this->Controller->Security->requirePut(array('putted'));
$this->Controller->Security->startup($this->Controller);
$this->assertTrue($this->Controller->failed);
}
/**
* testRequirePutSucceed method
*
* @return void
*/
public function testRequirePutSucceed() {
$_SERVER['REQUEST_METHOD'] = 'PUT';
$this->Controller->request['action'] = 'putted';
$this->Controller->Security->requirePut('putted');
$this->Controller->Security->startup($this->Controller);
$this->assertFalse($this->Controller->failed);
}
/**
* testRequirePutSucceedWrongMethod method
*
* @return void
*/
public function testRequirePutSucceedWrongMethod() {
$_SERVER['REQUEST_METHOD'] = 'POST';
$this->Controller->request['action'] = 'posted';
$this->Controller->Security->requirePut('putted');
$this->Controller->Security->startup($this->Controller);
$this->assertFalse($this->Controller->failed);
}
/**
* testRequireDeleteFail method
*
* @return void
*/
public function testRequireDeleteFail() {
$_SERVER['REQUEST_METHOD'] = 'POST';
$this->Controller->request['action'] = 'deleted';
$this->Controller->Security->requireDelete(array('deleted', 'other_method'));
$this->Controller->Security->startup($this->Controller);
$this->assertTrue($this->Controller->failed);
}
/**
* testRequireDeleteSucceed method
*
* @return void
*/
public function testRequireDeleteSucceed() {
$_SERVER['REQUEST_METHOD'] = 'DELETE';
$this->Controller->request['action'] = 'deleted';
$this->Controller->Security->requireDelete('deleted');
$this->Controller->Security->startup($this->Controller);
$this->assertFalse($this->Controller->failed);
}
/**
* testRequireDeleteSucceedWrongMethod method
*
* @return void
*/
public function testRequireDeleteSucceedWrongMethod() {
$_SERVER['REQUEST_METHOD'] = 'POST';
$this->Controller->request['action'] = 'posted';
$this->Controller->Security->requireDelete('deleted');
$this->Controller->Security->startup($this->Controller);
$this->assertFalse($this->Controller->failed);
}
/**
* Simple hash validation test
*
* @return void
*/
public function testValidatePost() {
$this->Controller->Security->startup($this->Controller);
$key = $this->Controller->request->params['_Token']['key'];
$fields = 'a5475372b40f6e3ccbf9f8af191f20e1642fd877%3AModel.valid';
$unlocked = '';
$this->Controller->request->data = array(
'Model' => array('username' => 'nate', 'password' => 'foo', 'valid' => '0'),
'_Token' => compact('key', 'fields', 'unlocked')
);
$this->assertTrue($this->Controller->Security->validatePost($this->Controller));
}
/**
* Test that validatePost fails if you are missing the session information.
*
* @return void
*/
public function testValidatePostNoSession() {
$this->Controller->Security->startup($this->Controller);
$this->Controller->Session->delete('_Token');
$key = $this->Controller->params['_Token']['key'];
$fields = 'a5475372b40f6e3ccbf9f8af191f20e1642fd877%3AModel.valid';
$this->Controller->data = array(
'Model' => array('username' => 'nate', 'password' => 'foo', 'valid' => '0'),
'_Token' => compact('key', 'fields')
);
$this->assertFalse($this->Controller->Security->validatePost($this->Controller));
}
/**
* test that validatePost fails if any of its required fields are missing.
*
* @return void
*/
public function testValidatePostFormHacking() {
$this->Controller->Security->startup($this->Controller);
$key = $this->Controller->params['_Token']['key'];
$fields = 'a5475372b40f6e3ccbf9f8af191f20e1642fd877%3AModel.valid';
$unlocked = '';
$this->Controller->request->data = array(
'Model' => array('username' => 'nate', 'password' => 'foo', 'valid' => '0'),
'_Token' => compact('key', 'unlocked')
);
$result = $this->Controller->Security->validatePost($this->Controller);
$this->assertFalse($result, 'validatePost passed when fields were missing. %s');
}
/**
* Test that objects can't be passed into the serialized string. This was a vector for RFI and LFI
* attacks. Thanks to Felix Wilhelm
*
* @return void
*/
public function testValidatePostObjectDeserialize() {
$this->Controller->Security->startup($this->Controller);
$key = $this->Controller->request->params['_Token']['key'];
$fields = 'a5475372b40f6e3ccbf9f8af191f20e1642fd877';
$unlocked = '';
// a corrupted serialized object, so we can see if it ever gets to deserialize
$attack = 'O:3:"App":1:{s:5:"__map";a:1:{s:3:"foo";s:7:"Hacked!";s:1:"fail"}}';
$fields .= urlencode(':' . str_rot13($attack));
$this->Controller->request->data = array(
'Model' => array('username' => 'mark', 'password' => 'foo', 'valid' => '0'),
'_Token' => compact('key', 'fields', 'unlocked')
);
$result = $this->Controller->Security->validatePost($this->Controller);
$this->assertFalse($result, 'validatePost passed when key was missing. %s');
}
/**
* Tests validation of checkbox arrays
*
* @return void
*/
public function testValidatePostArray() {
$this->Controller->Security->startup($this->Controller);
$key = $this->Controller->request->params['_Token']['key'];
$fields = 'f7d573650a295b94e0938d32b323fde775e5f32b%3A';
$unlocked = '';
$this->Controller->request->data = array(
'Model' => array('multi_field' => array('1', '3')),
'_Token' => compact('key', 'fields', 'unlocked')
);
$this->assertTrue($this->Controller->Security->validatePost($this->Controller));
}
/**
* testValidatePostNoModel method
*
* @return void
*/
public function testValidatePostNoModel() {
$this->Controller->Security->startup($this->Controller);
$key = $this->Controller->request->params['_Token']['key'];
$fields = '540ac9c60d323c22bafe997b72c0790f39a8bdef%3A';
$unlocked = '';
$this->Controller->request->data = array(
'anything' => 'some_data',
'_Token' => compact('key', 'fields', 'unlocked')
);
$result = $this->Controller->Security->validatePost($this->Controller);
$this->assertTrue($result);
}
/**
* testValidatePostSimple method
*
* @return void
*/
public function testValidatePostSimple() {
$this->Controller->Security->startup($this->Controller);
$key = $this->Controller->request->params['_Token']['key'];
$fields = '69f493434187b867ea14b901fdf58b55d27c935d%3A';
$unlocked = '';
$this->Controller->request->data = $data = array(
'Model' => array('username' => '', 'password' => ''),
'_Token' => compact('key', 'fields', 'unlocked')
);
$result = $this->Controller->Security->validatePost($this->Controller);
$this->assertTrue($result);
}
/**
* Tests hash validation for multiple records, including locked fields
*
* @return void
*/
public function testValidatePostComplex() {
$this->Controller->Security->startup($this->Controller);
$key = $this->Controller->request->params['_Token']['key'];
$fields = 'c9118120e680a7201b543f562e5301006ccfcbe2%3AAddresses.0.id%7CAddresses.1.id';
$unlocked = '';
$this->Controller->request->data = array(
'Addresses' => array(
'0' => array(
'id' => '123456', 'title' => '', 'first_name' => '', 'last_name' => '',
'address' => '', 'city' => '', 'phone' => '', 'primary' => ''
),
'1' => array(
'id' => '654321', 'title' => '', 'first_name' => '', 'last_name' => '',
'address' => '', 'city' => '', 'phone' => '', 'primary' => ''
)
),
'_Token' => compact('key', 'fields', 'unlocked')
);
$result = $this->Controller->Security->validatePost($this->Controller);
$this->assertTrue($result);
}
/**
* test ValidatePost with multiple select elements.
*
* @return void
*/
public function testValidatePostMultipleSelect() {
$this->Controller->Security->startup($this->Controller);
$key = $this->Controller->request->params['_Token']['key'];
$fields = '422cde416475abc171568be690a98cad20e66079%3A';
$unlocked = '';
$this->Controller->request->data = array(
'Tag' => array('Tag' => array(1, 2)),
'_Token' => compact('key', 'fields', 'unlocked'),
);
$result = $this->Controller->Security->validatePost($this->Controller);
$this->assertTrue($result);
$this->Controller->request->data = array(
'Tag' => array('Tag' => array(1, 2, 3)),
'_Token' => compact('key', 'fields', 'unlocked'),
);
$result = $this->Controller->Security->validatePost($this->Controller);
$this->assertTrue($result);
$this->Controller->request->data = array(
'Tag' => array('Tag' => array(1, 2, 3, 4)),
'_Token' => compact('key', 'fields', 'unlocked'),
);
$result = $this->Controller->Security->validatePost($this->Controller);
$this->assertTrue($result);
$fields = '19464422eafe977ee729c59222af07f983010c5f%3A';
$this->Controller->request->data = array(
'User.password' => 'bar', 'User.name' => 'foo', 'User.is_valid' => '1',
'Tag' => array('Tag' => array(1)),
'_Token' => compact('key', 'fields', 'unlocked'),
);
$result = $this->Controller->Security->validatePost($this->Controller);
$this->assertTrue($result);
}
/**
* testValidatePostCheckbox method
*
* First block tests un-checked checkbox
* Second block tests checked checkbox
*
* @return void
*/
public function testValidatePostCheckbox() {
$this->Controller->Security->startup($this->Controller);
$key = $this->Controller->request->params['_Token']['key'];
$fields = 'a5475372b40f6e3ccbf9f8af191f20e1642fd877%3AModel.valid';
$unlocked = '';
$this->Controller->request->data = array(
'Model' => array('username' => '', 'password' => '', 'valid' => '0'),
'_Token' => compact('key', 'fields', 'unlocked')
);
$result = $this->Controller->Security->validatePost($this->Controller);
$this->assertTrue($result);
$fields = '874439ca69f89b4c4a5f50fb9c36ff56a28f5d42%3A';
$this->Controller->request->data = array(
'Model' => array('username' => '', 'password' => '', 'valid' => '0'),
'_Token' => compact('key', 'fields', 'unlocked')
);
$result = $this->Controller->Security->validatePost($this->Controller);
$this->assertTrue($result);
$this->Controller->request->data = array();
$this->Controller->Security->startup($this->Controller);
$key = $this->Controller->request->params['_Token']['key'];
$this->Controller->request->data = $data = array(
'Model' => array('username' => '', 'password' => '', 'valid' => '0'),
'_Token' => compact('key', 'fields', 'unlocked')
);
$result = $this->Controller->Security->validatePost($this->Controller);
$this->assertTrue($result);
}
/**
* testValidatePostHidden method
*
* @return void
*/
public function testValidatePostHidden() {
$this->Controller->Security->startup($this->Controller);
$key = $this->Controller->request->params['_Token']['key'];
$fields = '51ccd8cb0997c7b3d4523ecde5a109318405ef8c%3AModel.hidden%7CModel.other_hidden';
$unlocked = '';
$this->Controller->request->data = array(
'Model' => array(
'username' => '', 'password' => '', 'hidden' => '0',
'other_hidden' => 'some hidden value'
),
'_Token' => compact('key', 'fields', 'unlocked')
);
$result = $this->Controller->Security->validatePost($this->Controller);
$this->assertTrue($result);
}
/**
* testValidatePostWithDisabledFields method
*
* @return void
*/
public function testValidatePostWithDisabledFields() {
$this->Controller->Security->disabledFields = array('Model.username', 'Model.password');
$this->Controller->Security->startup($this->Controller);
$key = $this->Controller->request->params['_Token']['key'];
$fields = 'ef1082968c449397bcd849f963636864383278b1%3AModel.hidden';
$unlocked = '';
$this->Controller->request->data = array(
'Model' => array(
'username' => '', 'password' => '', 'hidden' => '0'
),
'_Token' => compact('fields', 'key', 'unlocked')
);
$result = $this->Controller->Security->validatePost($this->Controller);
$this->assertTrue($result);
}
/**
* test validating post data with posted unlocked fields.
*
* @return void
*/
public function testValidatePostDisabledFieldsInData() {
$this->Controller->Security->startup($this->Controller);
$key = $this->Controller->request->params['_Token']['key'];
$unlocked = 'Model.username';
$fields = array('Model.hidden', 'Model.password');
$fields = urlencode(Security::hash(serialize($fields) . $unlocked . Configure::read('Security.salt')));
$this->Controller->request->data = array(
'Model' => array(
'username' => 'mark',
'password' => 'sekret',
'hidden' => '0'
),
'_Token' => compact('fields', 'key', 'unlocked')
);
$result = $this->Controller->Security->validatePost($this->Controller);
$this->assertTrue($result);
}
/**
* test that missing 'unlocked' input causes failure
*
* @return void
*/
public function testValidatePostFailNoDisabled() {
$this->Controller->Security->startup($this->Controller);
$key = $this->Controller->request->params['_Token']['key'];
$fields = array('Model.hidden', 'Model.password', 'Model.username');
$fields = urlencode(Security::hash(serialize($fields) . Configure::read('Security.salt')));
$this->Controller->request->data = array(
'Model' => array(
'username' => 'mark',
'password' => 'sekret',
'hidden' => '0'
),
'_Token' => compact('fields', 'key')
);
$result = $this->Controller->Security->validatePost($this->Controller);
$this->assertFalse($result);
}
/**
* Test that validatePost fails when unlocked fields are changed.
*
* @return
*/
public function testValidatePostFailDisabledFieldTampering() {
$this->Controller->Security->startup($this->Controller);
$key = $this->Controller->request->params['_Token']['key'];
$unlocked = 'Model.username';
$fields = array('Model.hidden', 'Model.password');
$fields = urlencode(Security::hash(serialize($fields) . $unlocked . Configure::read('Security.salt')));
// Tamper the values.
$unlocked = 'Model.username|Model.password';
$this->Controller->request->data = array(
'Model' => array(
'username' => 'mark',
'password' => 'sekret',
'hidden' => '0'
),
'_Token' => compact('fields', 'key', 'unlocked')
);
$result = $this->Controller->Security->validatePost($this->Controller);
$this->assertFalse($result);
}
/**
* testValidateHiddenMultipleModel method
*
* @return void
*/
public function testValidateHiddenMultipleModel() {
$this->Controller->Security->startup($this->Controller);
$key = $this->Controller->request->params['_Token']['key'];
$fields = 'a2d01072dc4660eea9d15007025f35a7a5b58e18%3AModel.valid%7CModel2.valid%7CModel3.valid';
$unlocked = '';
$this->Controller->request->data = array(
'Model' => array('username' => '', 'password' => '', 'valid' => '0'),
'Model2' => array('valid' => '0'),
'Model3' => array('valid' => '0'),
'_Token' => compact('key', 'fields', 'unlocked')
);
$result = $this->Controller->Security->validatePost($this->Controller);
$this->assertTrue($result);
}
/**
* testValidateHasManyModel method
*
* @return void
*/
public function testValidateHasManyModel() {
$this->Controller->Security->startup($this->Controller);
$key = $this->Controller->request->params['_Token']['key'];
$fields = '51e3b55a6edd82020b3f29c9ae200e14bbeb7ee5%3AModel.0.hidden%7CModel.0.valid';
$fields .= '%7CModel.1.hidden%7CModel.1.valid';
$unlocked = '';
$this->Controller->request->data = array(
'Model' => array(
array(
'username' => 'username', 'password' => 'password',
'hidden' => 'value', 'valid' => '0'
),
array(
'username' => 'username', 'password' => 'password',
'hidden' => 'value', 'valid' => '0'
)
),
'_Token' => compact('key', 'fields', 'unlocked')
);
$result = $this->Controller->Security->validatePost($this->Controller);
$this->assertTrue($result);
}
/**
* testValidateHasManyRecordsPass method
*
* @return void
*/
public function testValidateHasManyRecordsPass() {
$this->Controller->Security->startup($this->Controller);
$key = $this->Controller->request->params['_Token']['key'];
$fields = '7a203edb3d345bbf38fe0dccae960da8842e11d7%3AAddress.0.id%7CAddress.0.primary%7C';
$fields .= 'Address.1.id%7CAddress.1.primary';
$unlocked = '';
$this->Controller->request->data = array(
'Address' => array(
0 => array(
'id' => '123',
'title' => 'home',
'first_name' => 'Bilbo',
'last_name' => 'Baggins',
'address' => '23 Bag end way',
'city' => 'the shire',
'phone' => 'N/A',
'primary' => '1',
),
1 => array(
'id' => '124',
'title' => 'home',
'first_name' => 'Frodo',
'last_name' => 'Baggins',
'address' => '50 Bag end way',
'city' => 'the shire',
'phone' => 'N/A',
'primary' => '1'
)
),
'_Token' => compact('key', 'fields', 'unlocked')
);
$result = $this->Controller->Security->validatePost($this->Controller);
$this->assertTrue($result);
}
/**
* testValidateHasManyRecords method
*
* validatePost should fail, hidden fields have been changed.
*
* @return void
*/
public function testValidateHasManyRecordsFail() {
$this->Controller->Security->startup($this->Controller);
$key = $this->Controller->request->params['_Token']['key'];
$fields = '7a203edb3d345bbf38fe0dccae960da8842e11d7%3AAddress.0.id%7CAddress.0.primary%7C';
$fields .= 'Address.1.id%7CAddress.1.primary';
$unlocked = '';
$this->Controller->request->data = array(
'Address' => array(
0 => array(
'id' => '123',
'title' => 'home',
'first_name' => 'Bilbo',
'last_name' => 'Baggins',
'address' => '23 Bag end way',
'city' => 'the shire',
'phone' => 'N/A',
'primary' => '5',
),
1 => array(
'id' => '124',
'title' => 'home',
'first_name' => 'Frodo',
'last_name' => 'Baggins',
'address' => '50 Bag end way',
'city' => 'the shire',
'phone' => 'N/A',
'primary' => '1'
)
),
'_Token' => compact('key', 'fields', 'unlocked')
);
$result = $this->Controller->Security->validatePost($this->Controller);
$this->assertFalse($result);
}
/**
* testFormDisabledFields method
*
* @return void
*/
public function testFormDisabledFields() {
$this->Controller->Security->startup($this->Controller);
$key = $this->Controller->request->params['_Token']['key'];
$fields = '11842060341b9d0fc3808b90ba29fdea7054d6ad%3An%3A0%3A%7B%7D';
$unlocked = '';
$this->Controller->request->data = array(
'MyModel' => array('name' => 'some data'),
'_Token' => compact('key', 'fields', 'unlocked')
);
$result = $this->Controller->Security->validatePost($this->Controller);
$this->assertFalse($result);
$this->Controller->Security->startup($this->Controller);
$this->Controller->Security->disabledFields = array('MyModel.name');
$key = $this->Controller->request->params['_Token']['key'];
$this->Controller->request->data = array(
'MyModel' => array('name' => 'some data'),
'_Token' => compact('key', 'fields', 'unlocked')
);
$result = $this->Controller->Security->validatePost($this->Controller);
$this->assertTrue($result);
}
/**
* testRadio method
*
* @return void
*/
public function testRadio() {
$this->Controller->Security->startup($this->Controller);
$key = $this->Controller->request->params['_Token']['key'];
$fields = '575ef54ca4fc8cab468d6d898e9acd3a9671c17e%3An%3A0%3A%7B%7D';
$unlocked = '';
$this->Controller->request->data = array(
'_Token' => compact('key', 'fields', 'unlocked')
);
$result = $this->Controller->Security->validatePost($this->Controller);
$this->assertFalse($result);
$this->Controller->request->data = array(
'_Token' => compact('key', 'fields', 'unlocked'),
'Test' => array('test' => '')
);
$result = $this->Controller->Security->validatePost($this->Controller);
$this->assertTrue($result);
$this->Controller->request->data = array(
'_Token' => compact('key', 'fields', 'unlocked'),
'Test' => array('test' => '1')
);
$result = $this->Controller->Security->validatePost($this->Controller);
$this->assertTrue($result);
$this->Controller->request->data = array(
'_Token' => compact('key', 'fields', 'unlocked'),
'Test' => array('test' => '2')
);
$result = $this->Controller->Security->validatePost($this->Controller);
$this->assertTrue($result);
}
/**
* test that a requestAction's controller will have the _Token appended to
* the params.
*
* @return void
* @see http://cakephp.lighthouseapp.com/projects/42648/tickets/68
*/
public function testSettingTokenForRequestAction() {
$this->Controller->Security->startup($this->Controller);
$key = $this->Controller->request->params['_Token']['key'];
$this->Controller->params['requested'] = 1;
unset($this->Controller->request->params['_Token']);
$this->Controller->Security->startup($this->Controller);
$this->assertEqual($this->Controller->request->params['_Token']['key'], $key);
}
/**
* test that blackhole doesn't delete the _Token session key so repeat data submissions
* stay blackholed.
*
* @link http://cakephp.lighthouseapp.com/projects/42648/tickets/214
* @return void
*/
public function testBlackHoleNotDeletingSessionInformation() {
$this->Controller->Security->startup($this->Controller);
$this->Controller->Security->blackHole($this->Controller, 'auth');
$this->assertTrue($this->Controller->Security->Session->check('_Token'), '_Token was deleted by blackHole %s');
}
/**
* test that csrf checks are skipped for request action.
*
* @return void
*/
public function testCsrfSkipRequestAction() {
$_SERVER['REQUEST_METHOD'] = 'POST';
$this->Security->validatePost = false;
$this->Security->csrfCheck = true;
$this->Security->csrfExpires = '+10 minutes';
$this->Controller->request->params['requested'] = 1;
$this->Security->startup($this->Controller);
$this->assertFalse($this->Controller->failed, 'fail() was called.');
}
/**
* test setting
*
* @return void
*/
public function testCsrfSettings() {
$this->Security->validatePost = false;
$this->Security->csrfCheck = true;
$this->Security->csrfExpires = '+10 minutes';
$this->Security->startup($this->Controller);
$token = $this->Security->Session->read('_Token');
$this->assertEquals(count($token['csrfTokens']), 1, 'Missing the csrf token.');
$this->assertEquals(strtotime('+10 minutes'), current($token['csrfTokens']), 'Token expiry does not match');
$this->assertEquals(array('key', 'unlockedFields'), array_keys($this->Controller->request->params['_Token']), 'Keys don not match');
}
/**
* Test setting multiple nonces, when startup() is called more than once, (ie more than one request.)
*
* @return void
*/
public function testCsrfSettingMultipleNonces() {
$this->Security->validatePost = false;
$this->Security->csrfCheck = true;
$this->Security->csrfExpires = '+10 minutes';
$this->Security->startup($this->Controller);
$this->Security->startup($this->Controller);
$token = $this->Security->Session->read('_Token');
$this->assertEquals(count($token['csrfTokens']), 2, 'Missing the csrf token.');
foreach ($token['csrfTokens'] as $key => $expires) {
$this->assertEquals(strtotime('+10 minutes'), $expires, 'Token expiry does not match');
}
}
/**
* test that nonces are consumed by form submits.
*
* @return void
*/
public function testCsrfNonceConsumption() {
$this->Security->validatePost = false;
$this->Security->csrfCheck = true;
$this->Security->csrfExpires = '+10 minutes';
$this->Security->Session->write('_Token.csrfTokens', array('nonce1' => strtotime('+10 minutes')));
$this->Controller->request = $this->getMock('CakeRequest', array('is'));
$this->Controller->request->expects($this->once())->method('is')
->with('post')
->will($this->returnValue(true));
$this->Controller->request->params['action'] = 'index';
$this->Controller->request->data = array(
'_Token' => array(
'key' => 'nonce1'
),
'Post' => array(
'title' => 'Woot'
)
);
$this->Security->startup($this->Controller);
$token = $this->Security->Session->read('_Token');
$this->assertFalse(isset($token['csrfTokens']['nonce1']), 'Token was not consumed');
}
/**
* test that expired values in the csrfTokens are cleaned up.
*
* @return void
*/
public function testCsrfNonceVacuum() {
$this->Security->validatePost = false;
$this->Security->csrfCheck = true;
$this->Security->csrfExpires = '+10 minutes';
$this->Security->Session->write('_Token.csrfTokens', array(
'valid' => strtotime('+30 minutes'),
'poof' => strtotime('-11 minutes'),
'dust' => strtotime('-20 minutes')
));
$this->Security->startup($this->Controller);
$tokens = $this->Security->Session->read('_Token.csrfTokens');
$this->assertEquals(2, count($tokens), 'Too many tokens left behind');
$this->assertNotEmpty('valid', $tokens, 'Valid token was removed.');
}
/**
* test that when the key is missing the request is blackHoled
*
* @return void
*/
public function testCsrfBlackHoleOnKeyMismatch() {
$this->Security->validatePost = false;
$this->Security->csrfCheck = true;
$this->Security->csrfExpires = '+10 minutes';
$this->Security->Session->write('_Token.csrfTokens', array('nonce1' => strtotime('+10 minutes')));
$this->Controller->request = $this->getMock('CakeRequest', array('is'));
$this->Controller->request->expects($this->once())->method('is')
->with('post')
->will($this->returnValue(true));
$this->Controller->request->params['action'] = 'index';
$this->Controller->request->data = array(
'_Token' => array(
'key' => 'not the right value'
),
'Post' => array(
'title' => 'Woot'
)
);
$this->Security->startup($this->Controller);
$this->assertTrue($this->Controller->failed, 'fail() was not called.');
}
/**
* test that when the key is missing the request is blackHoled
*
* @return void
*/
public function testCsrfBlackHoleOnExpiredKey() {
$this->Security->validatePost = false;
$this->Security->csrfCheck = true;
$this->Security->csrfExpires = '+10 minutes';
$this->Security->Session->write('_Token.csrfTokens', array('nonce1' => strtotime('-5 minutes')));
$this->Controller->request = $this->getMock('CakeRequest', array('is'));
$this->Controller->request->expects($this->once())->method('is')
->with('post')
->will($this->returnValue(true));
$this->Controller->request->params['action'] = 'index';
$this->Controller->request->data = array(
'_Token' => array(
'key' => 'nonce1'
),
'Post' => array(
'title' => 'Woot'
)
);
$this->Security->startup($this->Controller);
$this->assertTrue($this->Controller->failed, 'fail() was not called.');
}
/**
* test that csrfUseOnce = false works.
*
* @return void
*/
public function testCsrfNotUseOnce() {
$this->Security->validatePost = false;
$this->Security->csrfCheck = true;
$this->Security->csrfUseOnce = false;
$this->Security->csrfExpires = '+10 minutes';
// Generate one token
$this->Security->startup($this->Controller);
$token = $this->Security->Session->read('_Token.csrfTokens');
$this->assertEquals(1, count($token), 'Should only be one token.');
$this->Security->startup($this->Controller);
$token2 = $this->Security->Session->read('_Token.csrfTokens');
$this->assertEquals(1, count($token2), 'Should only be one token.');
$this->assertEquals($token, $token2, 'Tokens should not be different.');
$key = $this->Controller->request->params['_Token']['key'];
$this->assertEquals(array($key), array_keys($token), '_Token.key and csrfToken do not match request will blackhole.');
}
/**
* ensure that longer session tokens are not consumed
*
* @return void
*/
public function testCsrfNotUseOnceValidationLeavingToken() {
$this->Security->validatePost = false;
$this->Security->csrfCheck = true;
$this->Security->csrfUseOnce = false;
$this->Security->csrfExpires = '+10 minutes';
$this->Security->Session->write('_Token.csrfTokens', array('nonce1' => strtotime('+10 minutes')));
$this->Controller->request = $this->getMock('CakeRequest', array('is'));
$this->Controller->request->expects($this->once())->method('is')
->with('post')
->will($this->returnValue(true));
$this->Controller->request->params['action'] = 'index';
$this->Controller->request->data = array(
'_Token' => array(
'key' => 'nonce1'
),
'Post' => array(
'title' => 'Woot'
)
);
$this->Security->startup($this->Controller);
$token = $this->Security->Session->read('_Token');
$this->assertTrue(isset($token['csrfTokens']['nonce1']), 'Token was consumed');
}
}
| 0001-bee | trunk/cakephp2/lib/Cake/Test/Case/Controller/Component/SecurityComponentTest.php | PHP | gpl3 | 38,421 |
<?php
/**
* ComponentCollectionTest file
*
* PHP 5
*
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
* Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://book.cakephp.org/view/1196/Testing CakePHP(tm) Tests
* @package Cake.Test.Case.Controller
* @since CakePHP(tm) v 2.0
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
App::uses('CookieComponent', 'Controller/Component');
App::uses('SecurityComponent', 'Controller/Component');
App::uses('ComponentCollection', 'Controller');
/**
* Extended CookieComponent
*/
class CookieAliasComponent extends CookieComponent {
}
class ComponentCollectionTest extends CakeTestCase {
/**
* setup
*
* @return void
*/
public function setup() {
$this->Components = new ComponentCollection();
}
/**
* teardown
*
* @return void
*/
public function teardown() {
unset($this->Components);
}
/**
* test triggering callbacks on loaded helpers
*
* @return void
*/
public function testLoad() {
$result = $this->Components->load('Cookie');
$this->assertInstanceOf('CookieComponent', $result);
$this->assertInstanceOf('CookieComponent', $this->Components->Cookie);
$result = $this->Components->attached();
$this->assertEquals(array('Cookie'), $result, 'attached() results are wrong.');
$this->assertTrue($this->Components->enabled('Cookie'));
$result = $this->Components->load('Cookie');
$this->assertSame($result, $this->Components->Cookie);
}
/**
* Tests loading as an alias
*
* @return void
*/
public function testLoadWithAlias() {
$result = $this->Components->load('Cookie', array('className' => 'CookieAlias', 'somesetting' => true));
$this->assertInstanceOf('CookieAliasComponent', $result);
$this->assertInstanceOf('CookieAliasComponent', $this->Components->Cookie);
$this->assertTrue($this->Components->Cookie->settings['somesetting']);
$result = $this->Components->attached();
$this->assertEquals(array('Cookie'), $result, 'attached() results are wrong.');
$this->assertTrue($this->Components->enabled('Cookie'));
$result = $this->Components->load('Cookie');
$this->assertInstanceOf('CookieAliasComponent', $result);
App::build(array('plugins' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS)));
CakePlugin::load('TestPlugin');
$result = $this->Components->load('SomeOther', array('className' => 'TestPlugin.OtherComponent'));
$this->assertInstanceOf('OtherComponentComponent', $result);
$this->assertInstanceOf('OtherComponentComponent', $this->Components->SomeOther);
$result = $this->Components->attached();
$this->assertEquals(array('Cookie', 'SomeOther'), $result, 'attached() results are wrong.');
App::build();
CakePlugin::unload();
}
/**
* test load and enable = false
*
* @return void
*/
public function testLoadWithEnableFalse() {
$result = $this->Components->load('Cookie', array('enabled' => false));
$this->assertInstanceOf('CookieComponent', $result);
$this->assertInstanceOf('CookieComponent', $this->Components->Cookie);
$this->assertFalse($this->Components->enabled('Cookie'), 'Cookie should be disabled');
}
/**
* test missingcomponent exception
*
* @expectedException MissingComponentException
* @return void
*/
public function testLoadMissingComponent() {
$this->Components->load('ThisComponentShouldAlwaysBeMissing');
}
/**
* test loading a plugin component.
*
* @return void
*/
public function testLoadPluginComponent() {
App::build(array(
'plugins' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS),
));
CakePlugin::load('TestPlugin');
$result = $this->Components->load('TestPlugin.OtherComponent');
$this->assertInstanceOf('OtherComponentComponent', $result, 'Component class is wrong.');
$this->assertInstanceOf('OtherComponentComponent', $this->Components->OtherComponent, 'Class is wrong');
App::build();
CakePlugin::unload();
}
/**
* test unload()
*
* @return void
*/
public function testUnload() {
$this->Components->load('Cookie');
$this->Components->load('Security');
$result = $this->Components->attached();
$this->assertEquals(array('Cookie', 'Security'), $result, 'loaded components is wrong');
$this->Components->unload('Cookie');
$this->assertFalse(isset($this->Components->Cookie));
$this->assertTrue(isset($this->Components->Security));
$result = $this->Components->attached();
$this->assertEquals(array('Security'), $result, 'loaded components is wrong');
$result = $this->Components->enabled();
$this->assertEquals(array('Security'), $result, 'enabled components is wrong');
}
/**
* test getting the controller out of the collection
*
* @return void
*/
public function testGetController() {
$controller = $this->getMock('Controller');
$controller->components = array('Security');
$this->Components->init($controller);
$result = $this->Components->getController();
$this->assertSame($controller, $result);
}
}
| 0001-bee | trunk/cakephp2/lib/Cake/Test/Case/Controller/ComponentCollectionTest.php | PHP | gpl3 | 5,242 |
<?php
/**
* PagesControllerTest file
*
* PHP 5
*
* CakePHP(tm) Tests <http://book.cakephp.org/view/1196/Testing>
* Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice
*
* @copyright Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://book.cakephp.org/view/1196/Testing CakePHP(tm) Tests
* @package Cake.Test.Case.Controller
* @since CakePHP(tm) v 1.2.0.5436
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
App::uses('PagesController', 'Controller');
/**
* PagesControllerTest class
*
* @package Cake.Test.Case.Controller
*/
class PagesControllerTest extends CakeTestCase {
/**
* endTest method
*
* @return void
*/
public function endTest() {
App::build();
}
/**
* testDisplay method
*
* @return void
*/
public function testDisplay() {
App::build(array(
'View' => array(
CAKE . 'Test' . DS . 'test_app' . DS . 'View'. DS
)
));
$Pages = new PagesController(new CakeRequest(null, false), new CakeResponse());
$Pages->viewPath = 'Posts';
$Pages->display('index');
$this->assertPattern('/posts index/', $Pages->response->body());
$this->assertEqual($Pages->viewVars['page'], 'index');
$Pages->viewPath = 'Themed';
$Pages->display('TestTheme', 'Posts', 'index');
$this->assertPattern('/posts index themed view/', $Pages->response->body());
$this->assertEqual($Pages->viewVars['page'], 'TestTheme');
$this->assertEqual($Pages->viewVars['subpage'], 'Posts');
}
}
| 0001-bee | trunk/cakephp2/lib/Cake/Test/Case/Controller/PagesControllerTest.php | PHP | gpl3 | 1,671 |
<?php
/**
* ComponentTest file
*
* PHP 5
*
* CakePHP(tm) Tests <http://book.cakephp.org/view/1196/Testing>
* Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice
*
* @copyright Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://book.cakephp.org/view/1196/Testing CakePHP(tm) Tests
* @package Cake.Test.Case.Controller
* @since CakePHP(tm) v 1.2.0.5436
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
App::uses('Controller', 'Controller');
App::uses('Component', 'Controller');
/**
* ParamTestComponent
*
* @package Cake.Test.Case.Controller
*/
class ParamTestComponent extends Component {
/**
* name property
*
* @var string 'ParamTest'
*/
public $name = 'ParamTest';
/**
* components property
*
* @var array
*/
public $components = array('Banana' => array('config' => 'value'));
/**
* initialize method
*
* @param mixed $controller
* @param mixed $settings
* @return void
*/
public function initialize(&$controller, $settings) {
foreach ($settings as $key => $value) {
if (is_numeric($key)) {
$this->{$value} = true;
} else {
$this->{$key} = $value;
}
}
}
}
/**
* ComponentTestController class
*
* @package Cake.Test.Case.Controller
*/
class ComponentTestController extends Controller {
/**
* name property
*
* @var string 'ComponentTest'
*/
public $name = 'ComponentTest';
/**
* uses property
*
* @var array
*/
public $uses = array();
}
/**
* AppleComponent class
*
* @package Cake.Test.Case.Controller
*/
class AppleComponent extends Component {
/**
* components property
*
* @var array
*/
public $components = array('Orange');
/**
* testName property
*
* @var mixed null
*/
public $testName = null;
/**
* startup method
*
* @param mixed $controller
* @return void
*/
public function startup(&$controller) {
$this->testName = $controller->name;
}
}
/**
* OrangeComponent class
*
* @package Cake.Test.Case.Controller
*/
class OrangeComponent extends Component {
/**
* components property
*
* @var array
*/
public $components = array('Banana');
/**
* initialize method
*
* @param mixed $controller
* @return void
*/
public function initialize(&$controller) {
$this->Controller = $controller;
$this->Banana->testField = 'OrangeField';
}
/**
* startup method
*
* @param Controller $controller
* @return string
*/
public function startup(&$controller) {
$controller->foo = 'pass';
}
}
/**
* BananaComponent class
*
* @package Cake.Test.Case.Controller
*/
class BananaComponent extends Component {
/**
* testField property
*
* @var string 'BananaField'
*/
public $testField = 'BananaField';
/**
* startup method
*
* @param Controller $controller
* @return string
*/
public function startup(&$controller) {
$controller->bar = 'fail';
}
}
/**
* MutuallyReferencingOneComponent class
*
* @package Cake.Test.Case.Controller
*/
class MutuallyReferencingOneComponent extends Component {
/**
* components property
*
* @var array
*/
public $components = array('MutuallyReferencingTwo');
}
/**
* MutuallyReferencingTwoComponent class
*
* @package Cake.Test.Case.Controller
*/
class MutuallyReferencingTwoComponent extends Component {
/**
* components property
*
* @var array
*/
public $components = array('MutuallyReferencingOne');
}
/**
* SomethingWithEmailComponent class
*
* @package Cake.Test.Case.Controller
*/
class SomethingWithEmailComponent extends Component {
/**
* components property
*
* @var array
*/
public $components = array('Email');
}
/**
* ComponentTest class
*
* @package Cake.Test.Case.Controller
*/
class ComponentTest extends CakeTestCase {
/**
* setUp method
*
* @return void
*/
public function setUp() {
$this->_pluginPaths = App::path('plugins');
App::build(array(
'plugins' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS)
));
}
/**
* tearDown method
*
* @return void
*/
public function tearDown() {
App::build();
ClassRegistry::flush();
}
/**
* test accessing inner components.
*
* @return void
*/
public function testInnerComponentConstruction() {
$Collection = new ComponentCollection();
$Component = new AppleComponent($Collection);
$this->assertInstanceOf('OrangeComponent', $Component->Orange, 'class is wrong');
}
/**
* test component loading
*
* @return void
*/
public function testNestedComponentLoading() {
$Collection = new ComponentCollection();
$Apple = new AppleComponent($Collection);
$this->assertInstanceOf('OrangeComponent', $Apple->Orange, 'class is wrong');
$this->assertInstanceOf('BananaComponent', $Apple->Orange->Banana, 'class is wrong');
$this->assertTrue(empty($Apple->Session));
$this->assertTrue(empty($Apple->Orange->Session));
}
/**
* test that component components are not enabled in the collection.
*
* @return void
*/
public function testInnerComponentsAreNotEnabled() {
$Collection = new ComponentCollection();
$Apple = $Collection->load('Apple');
$this->assertInstanceOf('OrangeComponent', $Apple->Orange, 'class is wrong');
$result = $Collection->enabled();
$this->assertEquals(array('Apple'), $result, 'Too many components enabled.');
}
/**
* test a component being used more than once.
*
* @return void
*/
public function testMultipleComponentInitialize() {
$Collection = new ComponentCollection();
$Banana = $Collection->load('Banana');
$Orange = $Collection->load('Orange');
$this->assertSame($Banana, $Orange->Banana, 'Should be references');
$Banana->testField = 'OrangeField';
$this->assertSame($Banana->testField, $Orange->Banana->testField, 'References are broken');
}
/**
* Test mutually referencing components.
*
* @return void
*/
public function testSomethingReferencingEmailComponent() {
$Controller = new ComponentTestController();
$Controller->components = array('SomethingWithEmail');
$Controller->uses = false;
$Controller->constructClasses();
$Controller->Components->trigger('initialize', array(&$Controller));
$Controller->beforeFilter();
$Controller->Components->trigger('startup', array(&$Controller));
$this->assertInstanceOf('SomethingWithEmailComponent', $Controller->SomethingWithEmail);
$this->assertInstanceOf('EmailComponent', $Controller->SomethingWithEmail->Email);
}
}
| 0001-bee | trunk/cakephp2/lib/Cake/Test/Case/Controller/ComponentTest.php | PHP | gpl3 | 6,586 |
<?php
/**
* AllUtilityTest file
*
* PHP 5
*
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
* Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://cakephp.org CakePHP(tm) Project
* @package Cake.Test.Case
* @since CakePHP(tm) v 2.0
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
/**
* AllUtilityTest class
*
* This test group will run all non mvc related lib class tests
*
* @package Cake.Test.Case
*/
class AllUtilityTest extends PHPUnit_Framework_TestSuite {
/**
* suite method, defines tests for this suite.
*
* @return void
*/
public static function suite() {
$suite = new CakeTestSuite('All Utility class tests');
$suite->addTestDirectory(CORE_TEST_CASES . DS . 'Utility');
return $suite;
}
}
| 0001-bee | trunk/cakephp2/lib/Cake/Test/Case/AllUtilityTest.php | PHP | gpl3 | 1,061 |
<?php
/**
* BasicsTest file
*
* PHP 5
*
* CakePHP(tm) Tests <http://book.cakephp.org/view/1196/Testing>
* Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice
*
* @copyright Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://book.cakephp.org/view/1196/Testing CakePHP(tm) Tests
* @package Cake.Test.Case
* @since CakePHP(tm) v 1.2.0.4206
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
require_once CAKE . 'basics.php';
App::uses('Folder', 'Utility');
/**
* BasicsTest class
*
* @package Cake.Test.Case
*/
class BasicsTest extends CakeTestCase {
/**
* setUp method
*
* @return void
*/
public function setUp() {
App::build(array(
'locales' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Locale' . DS)
));
$this->_language = Configure::read('Config.language');
}
/**
* tearDown method
*
* @return void
*/
public function tearDown() {
App::build();
Configure::write('Config.language', $this->_language);
}
/**
* test the array_diff_key compatibility function.
*
* @return void
*/
public function testArrayDiffKey() {
$one = array('one' => 1, 'two' => 2, 'three' => 3);
$two = array('one' => 'one', 'two' => 'two');
$result = array_diff_key($one, $two);
$expected = array('three' => 3);
$this->assertEqual($expected, $result);
$one = array('one' => array('value', 'value-two'), 'two' => 2, 'three' => 3);
$two = array('two' => 'two');
$result = array_diff_key($one, $two);
$expected = array('one' => array('value', 'value-two'), 'three' => 3);
$this->assertEqual($expected, $result);
$one = array('one' => null, 'two' => 2, 'three' => '', 'four' => 0);
$two = array('two' => 'two');
$result = array_diff_key($one, $two);
$expected = array('one' => null, 'three' => '', 'four' => 0);
$this->assertEqual($expected, $result);
$one = array('minYear' => null, 'maxYear' => null, 'separator' => '-', 'interval' => 1, 'monthNames' => true);
$two = array('minYear' => null, 'maxYear' => null, 'separator' => '-', 'interval' => 1, 'monthNames' => true);
$result = array_diff_key($one, $two);
$this->assertEqual($result, array());
}
/**
* testHttpBase method
*
* @return void
*/
public function testEnv() {
$this->skipIf(!function_exists('ini_get') || ini_get('safe_mode') === '1', 'Safe mode is on.');
$__SERVER = $_SERVER;
$__ENV = $_ENV;
$_SERVER['HTTP_HOST'] = 'localhost';
$this->assertEqual(env('HTTP_BASE'), '.localhost');
$_SERVER['HTTP_HOST'] = 'com.ar';
$this->assertEqual(env('HTTP_BASE'), '.com.ar');
$_SERVER['HTTP_HOST'] = 'example.ar';
$this->assertEqual(env('HTTP_BASE'), '.example.ar');
$_SERVER['HTTP_HOST'] = 'example.com';
$this->assertEqual(env('HTTP_BASE'), '.example.com');
$_SERVER['HTTP_HOST'] = 'www.example.com';
$this->assertEqual(env('HTTP_BASE'), '.example.com');
$_SERVER['HTTP_HOST'] = 'subdomain.example.com';
$this->assertEqual(env('HTTP_BASE'), '.example.com');
$_SERVER['HTTP_HOST'] = 'example.com.ar';
$this->assertEqual(env('HTTP_BASE'), '.example.com.ar');
$_SERVER['HTTP_HOST'] = 'www.example.com.ar';
$this->assertEqual(env('HTTP_BASE'), '.example.com.ar');
$_SERVER['HTTP_HOST'] = 'subdomain.example.com.ar';
$this->assertEqual(env('HTTP_BASE'), '.example.com.ar');
$_SERVER['HTTP_HOST'] = 'double.subdomain.example.com';
$this->assertEqual(env('HTTP_BASE'), '.subdomain.example.com');
$_SERVER['HTTP_HOST'] = 'double.subdomain.example.com.ar';
$this->assertEqual(env('HTTP_BASE'), '.subdomain.example.com.ar');
$_SERVER = $_ENV = array();
$_SERVER['SCRIPT_NAME'] = '/a/test/test.php';
$this->assertEqual(env('SCRIPT_NAME'), '/a/test/test.php');
$_SERVER = $_ENV = array();
$_ENV['CGI_MODE'] = 'BINARY';
$_ENV['SCRIPT_URL'] = '/a/test/test.php';
$this->assertEqual(env('SCRIPT_NAME'), '/a/test/test.php');
$_SERVER = $_ENV = array();
$this->assertFalse(env('HTTPS'));
$_SERVER['HTTPS'] = 'on';
$this->assertTrue(env('HTTPS'));
$_SERVER['HTTPS'] = '1';
$this->assertTrue(env('HTTPS'));
$_SERVER['HTTPS'] = 'I am not empty';
$this->assertTrue(env('HTTPS'));
$_SERVER['HTTPS'] = 1;
$this->assertTrue(env('HTTPS'));
$_SERVER['HTTPS'] = 'off';
$this->assertFalse(env('HTTPS'));
$_SERVER['HTTPS'] = false;
$this->assertFalse(env('HTTPS'));
$_SERVER['HTTPS'] = '';
$this->assertFalse(env('HTTPS'));
$_SERVER = array();
$_ENV['SCRIPT_URI'] = 'https://domain.test/a/test.php';
$this->assertTrue(env('HTTPS'));
$_ENV['SCRIPT_URI'] = 'http://domain.test/a/test.php';
$this->assertFalse(env('HTTPS'));
$_SERVER = $_ENV = array();
$this->assertNull(env('TEST_ME'));
$_ENV['TEST_ME'] = 'a';
$this->assertEqual(env('TEST_ME'), 'a');
$_SERVER['TEST_ME'] = 'b';
$this->assertEqual(env('TEST_ME'), 'b');
unset($_ENV['TEST_ME']);
$this->assertEqual(env('TEST_ME'), 'b');
$_SERVER = $__SERVER;
$_ENV = $__ENV;
}
/**
* Test h()
*
* @return void
*/
public function testH() {
$string = '<foo>';
$result = h($string);
$this->assertEqual('<foo>', $result);
$in = array('this & that', '<p>Which one</p>');
$result = h($in);
$expected = array('this & that', '<p>Which one</p>');
$this->assertEqual($expected, $result);
$string = '<foo> & ';
$result = h($string);
$this->assertEqual('<foo> & &nbsp;', $result);
$string = '<foo> & ';
$result = h($string, false);
$this->assertEqual('<foo> & ', $result);
$string = '<foo> & ';
$result = h($string, 'UTF-8');
$this->assertEqual('<foo> & &nbsp;', $result);
$arr = array('<foo>', ' ');
$result = h($arr);
$expected = array(
'<foo>',
'&nbsp;'
);
$this->assertEqual($expected, $result);
$arr = array('<foo>', ' ');
$result = h($arr, false);
$expected = array(
'<foo>',
' '
);
$this->assertEqual($expected, $result);
$arr = array('f' => '<foo>', 'n' => ' ');
$result = h($arr, false);
$expected = array(
'f' => '<foo>',
'n' => ' '
);
$this->assertEqual($expected, $result);
}
/**
* Test am()
*
* @return void
*/
public function testAm() {
$result = am(array('one', 'two'), 2, 3, 4);
$expected = array('one', 'two', 2, 3, 4);
$this->assertEqual($expected, $result);
$result = am(array('one' => array(2, 3), 'two' => array('foo')), array('one' => array(4, 5)));
$expected = array('one' => array(4, 5),'two' => array('foo'));
$this->assertEqual($expected, $result);
}
/**
* test cache()
*
* @return void
*/
public function testCache() {
$_cacheDisable = Configure::read('Cache.disable');
$this->skipIf($_cacheDisable, 'Cache is disabled, skipping cache() tests.');
Configure::write('Cache.disable', true);
$result = cache('basics_test', 'simple cache write');
$this->assertNull($result);
$result = cache('basics_test');
$this->assertNull($result);
Configure::write('Cache.disable', false);
$result = cache('basics_test', 'simple cache write');
$this->assertTrue((boolean)$result);
$this->assertTrue(file_exists(CACHE . 'basics_test'));
$result = cache('basics_test');
$this->assertEqual($result, 'simple cache write');
@unlink(CACHE . 'basics_test');
cache('basics_test', 'expired', '+1 second');
sleep(2);
$result = cache('basics_test', null, '+1 second');
$this->assertNull($result);
Configure::write('Cache.disable', $_cacheDisable);
}
/**
* test clearCache()
*
* @return void
*/
public function testClearCache() {
$cacheOff = Configure::read('Cache.disable');
$this->skipIf($cacheOff, 'Cache is disabled, skipping clearCache() tests.');
cache('views' . DS . 'basics_test.cache', 'simple cache write');
$this->assertTrue(file_exists(CACHE . 'views' . DS . 'basics_test.cache'));
cache('views' . DS . 'basics_test_2.cache', 'simple cache write 2');
$this->assertTrue(file_exists(CACHE . 'views' . DS . 'basics_test_2.cache'));
cache('views' . DS . 'basics_test_3.cache', 'simple cache write 3');
$this->assertTrue(file_exists(CACHE . 'views' . DS . 'basics_test_3.cache'));
$result = clearCache(array('basics_test', 'basics_test_2'), 'views', '.cache');
$this->assertTrue($result);
$this->assertFalse(file_exists(CACHE . 'views' . DS . 'basics_test.cache'));
$this->assertFalse(file_exists(CACHE . 'views' . DS . 'basics_test.cache'));
$this->assertTrue(file_exists(CACHE . 'views' . DS . 'basics_test_3.cache'));
$result = clearCache(null, 'views', '.cache');
$this->assertTrue($result);
$this->assertFalse(file_exists(CACHE . 'views' . DS . 'basics_test_3.cache'));
// Different path from views and with prefix
cache('models' . DS . 'basics_test.cache', 'simple cache write');
$this->assertTrue(file_exists(CACHE . 'models' . DS . 'basics_test.cache'));
cache('models' . DS . 'basics_test_2.cache', 'simple cache write 2');
$this->assertTrue(file_exists(CACHE . 'models' . DS . 'basics_test_2.cache'));
cache('models' . DS . 'basics_test_3.cache', 'simple cache write 3');
$this->assertTrue(file_exists(CACHE . 'models' . DS . 'basics_test_3.cache'));
$result = clearCache('basics', 'models', '.cache');
$this->assertTrue($result);
$this->assertFalse(file_exists(CACHE . 'models' . DS . 'basics_test.cache'));
$this->assertFalse(file_exists(CACHE . 'models' . DS . 'basics_test_2.cache'));
$this->assertFalse(file_exists(CACHE . 'models' . DS . 'basics_test_3.cache'));
// checking if empty files were not removed
$emptyExists = file_exists(CACHE . 'views' . DS . 'empty');
if (!$emptyExists) {
cache('views' . DS . 'empty', '');
}
cache('views' . DS . 'basics_test.php', 'simple cache write');
$this->assertTrue(file_exists(CACHE . 'views' . DS . 'basics_test.php'));
$this->assertTrue(file_exists(CACHE . 'views' . DS . 'empty'));
$result = clearCache();
$this->assertTrue($result);
$this->assertTrue(file_exists(CACHE . 'views' . DS . 'empty'));
$this->assertFalse(file_exists(CACHE . 'views' . DS . 'basics_test.php'));
if (!$emptyExists) {
unlink(CACHE . 'views' . DS . 'empty');
}
}
/**
* test __()
*
* @return void
*/
public function test__() {
Configure::write('Config.language', 'rule_1_po');
$result = __('Plural Rule 1');
$expected = 'Plural Rule 1 (translated)';
$this->assertEqual($expected, $result);
$result = __('Plural Rule 1 (from core)');
$expected = 'Plural Rule 1 (from core translated)';
$this->assertEqual($expected, $result);
$result = __('Some string with %s', 'arguments');
$expected = 'Some string with arguments';
$this->assertEqual($expected, $result);
$result = __('Some string with %s %s', 'multiple', 'arguments');
$expected = 'Some string with multiple arguments';
$this->assertEqual($expected, $result);
$result = __('Some string with %s %s', array('multiple', 'arguments'));
$expected = 'Some string with multiple arguments';
$this->assertEqual($expected, $result);
$result = __('Testing %2$s %1$s', 'order', 'different');
$expected = 'Testing different order';
$this->assertEqual($expected, $result);
$result = __('Testing %2$s %1$s', array('order', 'different'));
$expected = 'Testing different order';
$this->assertEqual($expected, $result);
$result = __('Testing %.2f number', 1.2345);
$expected = 'Testing 1.23 number';
$this->assertEqual($expected, $result);
}
/**
* test __n()
*
* @return void
*/
public function test__n() {
Configure::write('Config.language', 'rule_1_po');
$result = __n('%d = 1', '%d = 0 or > 1', 0);
$expected = '%d = 0 or > 1 (translated)';
$this->assertEqual($expected, $result);
$result = __n('%d = 1', '%d = 0 or > 1', 1);
$expected = '%d = 1 (translated)';
$this->assertEqual($expected, $result);
$result = __n('%d = 1 (from core)', '%d = 0 or > 1 (from core)', 2);
$expected = '%d = 0 or > 1 (from core translated)';
$this->assertEqual($expected, $result);
$result = __n('%d item.', '%d items.', 1, 1);
$expected = '1 item.';
$this->assertEqual($expected, $result);
$result = __n('%d item for id %s', '%d items for id %s', 2, 2, '1234');
$expected = '2 items for id 1234';
$this->assertEqual($expected, $result);
$result = __n('%d item for id %s', '%d items for id %s', 2, array(2, '1234'));
$expected = '2 items for id 1234';
$this->assertEqual($expected, $result);
}
/**
* test __d()
*
* @return void
*/
public function test__d() {
Configure::write('Config.language', 'rule_1_po');
$result = __d('default', 'Plural Rule 1');
$expected = 'Plural Rule 1 (translated)';
$this->assertEqual($expected, $result);
$result = __d('core', 'Plural Rule 1');
$expected = 'Plural Rule 1';
$this->assertEqual($expected, $result);
$result = __d('core', 'Plural Rule 1 (from core)');
$expected = 'Plural Rule 1 (from core translated)';
$this->assertEqual($expected, $result);
$result = __d('core', 'Some string with %s', 'arguments');
$expected = 'Some string with arguments';
$this->assertEqual($expected, $result);
$result = __d('core', 'Some string with %s %s', 'multiple', 'arguments');
$expected = 'Some string with multiple arguments';
$this->assertEqual($expected, $result);
$result = __d('core', 'Some string with %s %s', array('multiple', 'arguments'));
$expected = 'Some string with multiple arguments';
$this->assertEqual($expected, $result);
}
/**
* test __dn()
*
* @return void
*/
public function test__dn() {
Configure::write('Config.language', 'rule_1_po');
$result = __dn('default', '%d = 1', '%d = 0 or > 1', 0);
$expected = '%d = 0 or > 1 (translated)';
$this->assertEqual($expected, $result);
$result = __dn('core', '%d = 1', '%d = 0 or > 1', 0);
$expected = '%d = 0 or > 1';
$this->assertEqual($expected, $result);
$result = __dn('core', '%d = 1 (from core)', '%d = 0 or > 1 (from core)', 0);
$expected = '%d = 0 or > 1 (from core translated)';
$this->assertEqual($expected, $result);
$result = __dn('default', '%d = 1', '%d = 0 or > 1', 1);
$expected = '%d = 1 (translated)';
$this->assertEqual($expected, $result);
$result = __dn('core', '%d item.', '%d items.', 1, 1);
$expected = '1 item.';
$this->assertEqual($expected, $result);
$result = __dn('core', '%d item for id %s', '%d items for id %s', 2, 2, '1234');
$expected = '2 items for id 1234';
$this->assertEqual($expected, $result);
$result = __dn('core', '%d item for id %s', '%d items for id %s', 2, array(2, '1234'));
$expected = '2 items for id 1234';
$this->assertEqual($expected, $result);
}
/**
* test __c()
*
* @return void
*/
public function test__c() {
Configure::write('Config.language', 'rule_1_po');
$result = __c('Plural Rule 1', 6);
$expected = 'Plural Rule 1 (translated)';
$this->assertEqual($expected, $result);
$result = __c('Plural Rule 1 (from core)', 6);
$expected = 'Plural Rule 1 (from core translated)';
$this->assertEqual($expected, $result);
$result = __c('Some string with %s', 6, 'arguments');
$expected = 'Some string with arguments';
$this->assertEqual($expected, $result);
$result = __c('Some string with %s %s', 6, 'multiple', 'arguments');
$expected = 'Some string with multiple arguments';
$this->assertEqual($expected, $result);
$result = __c('Some string with %s %s', 6, array('multiple', 'arguments'));
$expected = 'Some string with multiple arguments';
$this->assertEqual($expected, $result);
}
/**
* test __dc()
*
* @return void
*/
public function test__dc() {
Configure::write('Config.language', 'rule_1_po');
$result = __dc('default', 'Plural Rule 1', 6);
$expected = 'Plural Rule 1 (translated)';
$this->assertEqual($expected, $result);
$result = __dc('default', 'Plural Rule 1 (from core)', 6);
$expected = 'Plural Rule 1 (from core translated)';
$this->assertEqual($expected, $result);
$result = __dc('core', 'Plural Rule 1', 6);
$expected = 'Plural Rule 1';
$this->assertEqual($expected, $result);
$result = __dc('core', 'Plural Rule 1 (from core)', 6);
$expected = 'Plural Rule 1 (from core translated)';
$this->assertEqual($expected, $result);
$result = __dc('core', 'Some string with %s', 6, 'arguments');
$expected = 'Some string with arguments';
$this->assertEqual($expected, $result);
$result = __dc('core', 'Some string with %s %s', 6, 'multiple', 'arguments');
$expected = 'Some string with multiple arguments';
$this->assertEqual($expected, $result);
$result = __dc('core', 'Some string with %s %s', 6, array('multiple', 'arguments'));
$expected = 'Some string with multiple arguments';
$this->assertEqual($expected, $result);
}
/**
* test __dcn()
*
* @return void
*/
public function test__dcn() {
Configure::write('Config.language', 'rule_1_po');
$result = __dcn('default', '%d = 1', '%d = 0 or > 1', 0, 6);
$expected = '%d = 0 or > 1 (translated)';
$this->assertEqual($expected, $result);
$result = __dcn('default', '%d = 1 (from core)', '%d = 0 or > 1 (from core)', 1, 6);
$expected = '%d = 1 (from core translated)';
$this->assertEqual($expected, $result);
$result = __dcn('core', '%d = 1', '%d = 0 or > 1', 0, 6);
$expected = '%d = 0 or > 1';
$this->assertEqual($expected, $result);
$result = __dcn('core', '%d item.', '%d items.', 1, 6, 1);
$expected = '1 item.';
$this->assertEqual($expected, $result);
$result = __dcn('core', '%d item for id %s', '%d items for id %s', 2, 6, 2, '1234');
$expected = '2 items for id 1234';
$this->assertEqual($expected, $result);
$result = __dcn('core', '%d item for id %s', '%d items for id %s', 2, 6, array(2, '1234'));
$expected = '2 items for id 1234';
$this->assertEqual($expected, $result);
}
/**
* test LogError()
*
* @return void
*/
public function testLogError() {
@unlink(LOGS . 'error.log');
LogError('Testing LogError() basic function');
LogError("Testing with\nmulti-line\nstring");
$result = file_get_contents(LOGS . 'error.log');
$this->assertPattern('/Error: Testing LogError\(\) basic function/', $result);
$this->assertNoPattern("/Error: Testing with\nmulti-line\nstring/", $result);
$this->assertPattern('/Error: Testing with multi-line string/', $result);
}
/**
* test fileExistsInPath()
*
* @return void
*/
public function testFileExistsInPath() {
$this->skipUnless(function_exists('ini_set'), '%s ini_set function not available');
$_includePath = ini_get('include_path');
$path = TMP . 'basics_test';
$folder1 = $path . DS . 'folder1';
$folder2 = $path . DS . 'folder2';
$file1 = $path . DS . 'file1.php';
$file2 = $folder1 . DS . 'file2.php';
$file3 = $folder1 . DS . 'file3.php';
$file4 = $folder2 . DS . 'file4.php';
new Folder($path, true);
new Folder($folder1, true);
new Folder($folder2, true);
touch($file1);
touch($file2);
touch($file3);
touch($file4);
ini_set('include_path', $path . PATH_SEPARATOR . $folder1);
$this->assertEqual(fileExistsInPath('file1.php'), $file1);
$this->assertEqual(fileExistsInPath('file2.php'), $file2);
$this->assertEqual(fileExistsInPath('folder1' . DS . 'file2.php'), $file2);
$this->assertEqual(fileExistsInPath($file2), $file2);
$this->assertEqual(fileExistsInPath('file3.php'), $file3);
$this->assertEqual(fileExistsInPath($file4), $file4);
$this->assertFalse(fileExistsInPath('file1'));
$this->assertFalse(fileExistsInPath('file4.php'));
$Folder = new Folder($path);
$Folder->delete();
ini_set('include_path', $_includePath);
}
/**
* test convertSlash()
*
* @return void
*/
public function testConvertSlash() {
$result = convertSlash('\path\to\location\\');
$expected = '\path\to\location\\';
$this->assertEqual($expected, $result);
$result = convertSlash('/path/to/location/');
$expected = 'path_to_location';
$this->assertEqual($expected, $result);
}
/**
* test debug()
*
* @return void
*/
public function testDebug() {
ob_start();
debug('this-is-a-test');
$result = ob_get_clean();
$pattern = '/(.+?Test(\/|\\\)Case(\/|\\\)BasicsTest\.php|';
$pattern .= preg_quote(substr(__FILE__, 1), '/') . ')';
$pattern .= '.*line.*' . (__LINE__ - 4) . '.*this-is-a-test.*/s';
$this->assertRegExp($pattern, $result);
ob_start();
debug('<div>this-is-a-test</div>', true);
$result = ob_get_clean();
$pattern = '/(.+?Test(\/|\\\)Case(\/|\\\)BasicsTest\.php|';
$pattern .= preg_quote(substr(__FILE__, 1), '/') . ')';
$pattern .= '.*line.*' . (__LINE__ -4) . '.*<div>this-is-a-test<\/div>.*/s';
$this->assertRegExp($pattern, $result);
ob_start();
debug('<div>this-is-a-test</div>', false);
$result = ob_get_clean();
$pattern = '/(.+?Test(\/|\\\)Case(\/|\\\)BasicsTest\.php|';
$pattern .= preg_quote(substr(__FILE__, 1), '/') . ')';
$pattern .= '.*line.*' . (__LINE__ - 4) . '.*\<div\>this-is-a-test\<\/div\>.*/s';
$this->assertRegExp($pattern, $result);
}
/**
* test pr()
*
* @return void
*/
public function testPr() {
ob_start();
pr('this is a test');
$result = ob_get_clean();
$expected = "<pre>this is a test</pre>";
$this->assertEqual($expected, $result);
ob_start();
pr(array('this' => 'is', 'a' => 'test'));
$result = ob_get_clean();
$expected = "<pre>Array\n(\n [this] => is\n [a] => test\n)\n</pre>";
$this->assertEqual($expected, $result);
}
/**
* test stripslashes_deep()
*
* @return void
*/
public function testStripslashesDeep() {
$this->skipIf(ini_get('magic_quotes_sybase') === '1', 'magic_quotes_sybase is on.');
$this->assertEqual(stripslashes_deep("tes\'t"), "tes't");
$this->assertEqual(stripslashes_deep('tes\\' . chr(0) .'t'), 'tes' . chr(0) .'t');
$this->assertEqual(stripslashes_deep('tes\"t'), 'tes"t');
$this->assertEqual(stripslashes_deep("tes\'t"), "tes't");
$this->assertEqual(stripslashes_deep('te\\st'), 'test');
$nested = array(
'a' => "tes\'t",
'b' => 'tes\\' . chr(0) .'t',
'c' => array(
'd' => 'tes\"t',
'e' => "te\'s\'t",
array('f' => "tes\'t")
),
'g' => 'te\\st'
);
$expected = array(
'a' => "tes't",
'b' => 'tes' . chr(0) .'t',
'c' => array(
'd' => 'tes"t',
'e' => "te's't",
array('f' => "tes't")
),
'g' => 'test'
);
$this->assertEqual(stripslashes_deep($nested), $expected);
}
/**
* test stripslashes_deep() with magic_quotes_sybase on
*
* @return void
*/
public function testStripslashesDeepSybase() {
$this->skipUnless(ini_get('magic_quotes_sybase') === '1', 'magic_quotes_sybase is off');
$this->assertEqual(stripslashes_deep("tes\'t"), "tes\'t");
$nested = array(
'a' => "tes't",
'b' => "tes''t",
'c' => array(
'd' => "tes'''t",
'e' => "tes''''t",
array('f' => "tes''t")
),
'g' => "te'''''st"
);
$expected = array(
'a' => "tes't",
'b' => "tes't",
'c' => array(
'd' => "tes''t",
'e' => "tes''t",
array('f' => "tes't")
),
'g' => "te'''st"
);
$this->assertEqual(stripslashes_deep($nested), $expected);
}
/**
* test pluginSplit
*
* @return void
*/
public function testPluginSplit() {
$result = pluginSplit('Something.else');
$this->assertEqual($result, array('Something', 'else'));
$result = pluginSplit('Something.else.more.dots');
$this->assertEqual($result, array('Something', 'else.more.dots'));
$result = pluginSplit('Somethingelse');
$this->assertEqual($result, array(null, 'Somethingelse'));
$result = pluginSplit('Something.else', true);
$this->assertEqual($result, array('Something.', 'else'));
$result = pluginSplit('Something.else.more.dots', true);
$this->assertEqual($result, array('Something.', 'else.more.dots'));
$result = pluginSplit('Post', false, 'Blog');
$this->assertEqual($result, array('Blog', 'Post'));
$result = pluginSplit('Blog.Post', false, 'Ultimate');
$this->assertEqual($result, array('Blog', 'Post'));
}
}
| 0001-bee | trunk/cakephp2/lib/Cake/Test/Case/BasicsTest.php | PHP | gpl3 | 24,109 |
<?php
/**
* AllViewTest file
*
* PHP 5
*
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
* Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://cakephp.org CakePHP(tm) Project
* @package Cake.Test.Case
* @since CakePHP(tm) v 2.0
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
/**
* AllViewTest class
*
* This test group will run view class tests (view, theme)
*
* @package Cake.Test.Case
*/
class AllViewTest extends PHPUnit_Framework_TestSuite {
/**
* suite method, defines tests for this suite.
*
* @return void
*/
public static function suite() {
$suite = new CakeTestSuite('All View class tests');
$suite->addTestDirectory(CORE_TEST_CASES . DS . 'View');
return $suite;
}
}
| 0001-bee | trunk/cakephp2/lib/Cake/Test/Case/AllViewTest.php | PHP | gpl3 | 1,042 |
<?php
/**
* MultibyteTest file
*
* PHP 5
*
* CakePHP(tm) Tests <http://book.cakephp.org/view/1196/Testing>
* Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice
*
* @copyright Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://book.cakephp.org/view/1196/Testing CakePHP(tm) Tests
* @package Cake.Test.Case.I18n
* @since CakePHP(tm) v 1.2.0.6833
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
App::uses('Multibyte', 'I18n');
/**
* MultibyteTest class
*
* @package Cake.Test.Case.I18n
*/
class MultibyteTest extends CakeTestCase {
/**
* testUtf8 method
*
* @return void
*/
public function testUtf8() {
$string = '!"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~';
$result = Multibyte::utf8($string);
$expected = array(33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57,
58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82,
83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105,
106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126);
$this->assertEqual($expected, $result);
$string = '¡¢£¤¥¦§¨©ª«¬®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈ';
$result = Multibyte::utf8($string);
$expected = array(161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181,
182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 200);
$this->assertEqual($expected, $result);
$string = 'ÉÊËÌÍÎÏÐÑÒÓÔÕÖרÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿĀāĂ㥹ĆćĈĉĊċČčĎďĐđĒēĔĕĖėĘęĚěĜĝĞğĠġĢģĤĥĦħĨĩĪīĬ';
$result = Multibyte::utf8($string);
$expected = array(201, 202, 203, 204, 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 220, 221,
222, 223, 224, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238, 239, 240, 241, 242,
243, 244, 245, 246, 247, 248, 249, 250, 251, 252, 253, 254, 255, 256, 257, 258, 259, 260, 261, 262, 263,
264, 265, 266, 267, 268, 269, 270, 271, 272, 273, 274, 275, 276, 277, 278, 279, 280, 281, 282, 283, 284,
285, 286, 287, 288, 289, 290, 291, 292, 293, 294, 295, 296, 297, 298, 299, 300);
$this->assertEqual($expected, $result);
$string = 'ĭĮįİıIJijĴĵĶķĸĹĺĻļĽľĿŀŁłŃńŅņŇňʼnŊŋŌōŎŏŐőŒœŔŕŖŗŘřŚśŜŝŞşŠšŢţŤťŦŧŨũŪūŬŭŮůŰűŲųŴŵŶŷŸŹźŻżŽžſƀƁƂƃƄƅƆƇƈƉƊƋƌƍƎƏƐ';
$result = Multibyte::utf8($string);
$expected = array(301, 302, 303, 304, 305, 306, 307, 308, 309, 310, 311, 312, 313, 314, 315, 316, 317, 318, 319, 320, 321,
322, 323, 324, 325, 326, 327, 328, 329, 330, 331, 332, 333, 334, 335, 336, 337, 338, 339, 340, 341, 342,
343, 344, 345, 346, 347, 348, 349, 350, 351, 352, 353, 354, 355, 356, 357, 358, 359, 360, 361, 362, 363,
364, 365, 366, 367, 368, 369, 370, 371, 372, 373, 374, 375, 376, 377, 378, 379, 380, 381, 382, 383, 384,
385, 386, 387, 388, 389, 390, 391, 392, 393, 394, 395, 396, 397, 398, 399, 400);
$this->assertEqual($expected, $result);
$string = 'ƑƒƓƔƕƖƗƘƙƚƛƜƝƞƟƠơƢƣƤƥƦƧƨƩƪƫƬƭƮƯưƱƲƳƴƵƶƷƸƹƺƻƼƽƾƿǀǁǂǃDŽDždžLJLjljNJNjnjǍǎǏǐǑǒǓǔǕǖǗǘǙǚǛǜǝǞǟǠǡǢǣǤǥǦǧǨǩǪǫǬǭǮǯǰDZDzdzǴ';
$result = Multibyte::utf8($string);
$expected = array(401, 402, 403, 404, 405, 406, 407, 408, 409, 410, 411, 412, 413, 414, 415, 416, 417, 418, 419, 420, 421,
422, 423, 424, 425, 426, 427, 428, 429, 430, 431, 432, 433, 434, 435, 436, 437, 438, 439, 440, 441, 442,
443, 444, 445, 446, 447, 448, 449, 450, 451, 452, 453, 454, 455, 456, 457, 458, 459, 460, 461, 462, 463,
464, 465, 466, 467, 468, 469, 470, 471, 472, 473, 474, 475, 476, 477, 478, 479, 480, 481, 482, 483, 484,
485, 486, 487, 488, 489, 490, 491, 492, 493, 494, 495, 496, 497, 498, 499, 500);
$this->assertEqual($expected, $result);
$string = 'əɚɛɜɝɞɟɠɡɢɣɤɥɦɧɨɩɪɫɬɭɮɯɰɱɲɳɴɵɶɷɸɹɺɻɼɽɾɿʀʁʂʃʄʅʆʇʈʉʊʋʌʍʎʏʐʑʒʓʔʕʖʗʘʙʚʛʜʝʞʟʠʡʢʣʤʥʦʧʨʩʪʫʬʭʮʯʰʱʲʳʴʵʶʷʸʹʺʻʼ';
$result = Multibyte::utf8($string);
$expected = array(601, 602, 603, 604, 605, 606, 607, 608, 609, 610, 611, 612, 613, 614, 615, 616, 617, 618, 619, 620, 621,
622, 623, 624, 625, 626, 627, 628, 629, 630, 631, 632, 633, 634, 635, 636, 637, 638, 639, 640, 641, 642,
643, 644, 645, 646, 647, 648, 649, 650, 651, 652, 653, 654, 655, 656, 657, 658, 659, 660, 661, 662, 663,
664, 665, 666, 667, 668, 669, 670, 671, 672, 673, 674, 675, 676, 677, 678, 679, 680, 681, 682, 683, 684,
685, 686, 687, 688, 689, 690, 691, 692, 693, 694, 695, 696, 697, 698, 699, 700);
$this->assertEqual($expected, $result);
$string = 'ЀЁЂЃЄЅІЇЈЉЊЋЌЍЎЏАБВГДЕЖЗИЙКЛ';
$result = Multibyte::utf8($string);
$expected = array(1024, 1025, 1026, 1027, 1028, 1029, 1030, 1031, 1032, 1033, 1034, 1035, 1036, 1037, 1038, 1039, 1040, 1041,
1042, 1043, 1044, 1045, 1046, 1047, 1048, 1049, 1050, 1051);
$this->assertEqual($expected, $result);
$string = 'МНОПРСТУФХЦЧШЩЪЫЬЭЮЯабвгдежзийклмнопрстуфхцчшщъыь';
$result = Multibyte::utf8($string);
$expected = array(1052, 1053, 1054, 1055, 1056, 1057, 1058, 1059, 1060, 1061, 1062, 1063, 1064, 1065, 1066, 1067, 1068, 1069,
1070, 1071, 1072, 1073, 1074, 1075, 1076, 1077, 1078, 1079, 1080, 1081, 1082, 1083, 1084, 1085, 1086, 1087,
1088, 1089, 1090, 1091, 1092, 1093, 1094, 1095, 1096, 1097, 1098, 1099, 1100);
$this->assertEqual($expected, $result);
$string = 'չպջռսվտ';
$result = Multibyte::utf8($string);
$expected = array(1401, 1402, 1403, 1404, 1405, 1406, 1407);
$this->assertEqual($expected, $result);
$string = 'فقكلمنهوىيًٌٍَُ';
$result = Multibyte::utf8($string);
$expected = array(1601, 1602, 1603, 1604, 1605, 1606, 1607, 1608, 1609, 1610, 1611, 1612, 1613, 1614, 1615);
$this->assertEqual($expected, $result);
$string = '✰✱✲✳✴✵✶✷✸✹✺✻✼✽✾✿❀❁❂❃❄❅❆❇❈❉❊❋❌❍❎❏❐❑❒❓❔❕❖❗❘❙❚❛❜❝❞';
$result = Multibyte::utf8($string);
$expected = array(10032, 10033, 10034, 10035, 10036, 10037, 10038, 10039, 10040, 10041, 10042, 10043, 10044,
10045, 10046, 10047, 10048, 10049, 10050, 10051, 10052, 10053, 10054, 10055, 10056, 10057,
10058, 10059, 10060, 10061, 10062, 10063, 10064, 10065, 10066, 10067, 10068, 10069, 10070,
10071, 10072, 10073, 10074, 10075, 10076, 10077, 10078);
$this->assertEqual($expected, $result);
$string = '⺀⺁⺂⺃⺄⺅⺆⺇⺈⺉⺊⺋⺌⺍⺎⺏⺐⺑⺒⺓⺔⺕⺖⺗⺘⺙⺛⺜⺝⺞⺟⺠⺡⺢⺣⺤⺥⺦⺧⺨⺩⺪⺫⺬⺭⺮⺯⺰⺱⺲⺳⺴⺵⺶⺷⺸⺹⺺⺻⺼⺽⺾⺿⻀⻁⻂⻃⻄⻅⻆⻇⻈⻉⻊⻋⻌⻍⻎⻏⻐⻑⻒⻓⻔⻕⻖⻗⻘⻙⻚⻛⻜⻝⻞⻟⻠';
$result = Multibyte::utf8($string);
$expected = array(11904, 11905, 11906, 11907, 11908, 11909, 11910, 11911, 11912, 11913, 11914, 11915, 11916, 11917, 11918, 11919,
11920, 11921, 11922, 11923, 11924, 11925, 11926, 11927, 11928, 11929, 11931, 11932, 11933, 11934, 11935, 11936,
11937, 11938, 11939, 11940, 11941, 11942, 11943, 11944, 11945, 11946, 11947, 11948, 11949, 11950, 11951, 11952,
11953, 11954, 11955, 11956, 11957, 11958, 11959, 11960, 11961, 11962, 11963, 11964, 11965, 11966, 11967, 11968,
11969, 11970, 11971, 11972, 11973, 11974, 11975, 11976, 11977, 11978, 11979, 11980, 11981, 11982, 11983, 11984,
11985, 11986, 11987, 11988, 11989, 11990, 11991, 11992, 11993, 11994, 11995, 11996, 11997, 11998, 11999, 12000);
$this->assertEqual($expected, $result);
$string = '⽅⽆⽇⽈⽉⽊⽋⽌⽍⽎⽏⽐⽑⽒⽓⽔⽕⽖⽗⽘⽙⽚⽛⽜⽝⽞⽟⽠⽡⽢⽣⽤⽥⽦⽧⽨⽩⽪⽫⽬⽭⽮⽯⽰⽱⽲⽳⽴⽵⽶⽷⽸⽹⽺⽻⽼⽽⽾⽿';
$result = Multibyte::utf8($string);
$expected = array(12101, 12102, 12103, 12104, 12105, 12106, 12107, 12108, 12109, 12110, 12111, 12112, 12113, 12114, 12115, 12116,
12117, 12118, 12119, 12120, 12121, 12122, 12123, 12124, 12125, 12126, 12127, 12128, 12129, 12130, 12131, 12132,
12133, 12134, 12135, 12136, 12137, 12138, 12139, 12140, 12141, 12142, 12143, 12144, 12145, 12146, 12147, 12148,
12149, 12150, 12151, 12152, 12153, 12154, 12155, 12156, 12157, 12158, 12159);
$this->assertEqual($expected, $result);
$string = '눡눢눣눤눥눦눧눨눩눪눫눬눭눮눯눰눱눲눳눴눵눶눷눸눹눺눻눼눽눾눿뉀뉁뉂뉃뉄뉅뉆뉇뉈뉉뉊뉋뉌뉍뉎뉏뉐뉑뉒뉓뉔뉕뉖뉗뉘뉙뉚뉛뉜뉝뉞뉟뉠뉡뉢뉣뉤뉥뉦뉧뉨뉩뉪뉫뉬뉭뉮뉯뉰뉱뉲뉳뉴뉵뉶뉷뉸뉹뉺뉻뉼뉽뉾뉿늀늁늂늃늄';
$result = Multibyte::utf8($string);
$expected = array(45601, 45602, 45603, 45604, 45605, 45606, 45607, 45608, 45609, 45610, 45611, 45612, 45613, 45614, 45615, 45616,
45617, 45618, 45619, 45620, 45621, 45622, 45623, 45624, 45625, 45626, 45627, 45628, 45629, 45630, 45631, 45632,
45633, 45634, 45635, 45636, 45637, 45638, 45639, 45640, 45641, 45642, 45643, 45644, 45645, 45646, 45647, 45648,
45649, 45650, 45651, 45652, 45653, 45654, 45655, 45656, 45657, 45658, 45659, 45660, 45661, 45662, 45663, 45664,
45665, 45666, 45667, 45668, 45669, 45670, 45671, 45672, 45673, 45674, 45675, 45676, 45677, 45678, 45679, 45680,
45681, 45682, 45683, 45684, 45685, 45686, 45687, 45688, 45689, 45690, 45691, 45692, 45693, 45694, 45695, 45696,
45697, 45698, 45699, 45700);
$this->assertEqual($expected, $result);
$string = 'ﹰﹱﹲﹳﹴﹶﹷﹸﹹﹺﹻﹼﹽﹾﹿﺀﺁﺂﺃﺄﺅﺆﺇﺈﺉﺊﺋﺌﺍﺎﺏﺐﺑﺒﺓﺔﺕﺖﺗﺘﺙﺚﺛﺜﺝﺞﺟﺠﺡﺢﺣﺤﺥﺦﺧﺨﺩﺪﺫﺬﺭﺮﺯﺰ';
$result = Multibyte::utf8($string);
$expected = array(65136, 65137, 65138, 65139, 65140, 65141, 65142, 65143, 65144, 65145, 65146, 65147, 65148, 65149, 65150, 65151,
65152, 65153, 65154, 65155, 65156, 65157, 65158, 65159, 65160, 65161, 65162, 65163, 65164, 65165, 65166, 65167,
65168, 65169, 65170, 65171, 65172, 65173, 65174, 65175, 65176, 65177, 65178, 65179, 65180, 65181, 65182, 65183,
65184, 65185, 65186, 65187, 65188, 65189, 65190, 65191, 65192, 65193, 65194, 65195, 65196, 65197, 65198, 65199,
65200);
$this->assertEqual($expected, $result);
$string = 'ﺱﺲﺳﺴﺵﺶﺷﺸﺹﺺﺻﺼﺽﺾﺿﻀﻁﻂﻃﻄﻅﻆﻇﻈﻉﻊﻋﻌﻍﻎﻏﻐﻑﻒﻓﻔﻕﻖﻗﻘﻙﻚﻛﻜﻝﻞﻟﻠﻡﻢﻣﻤﻥﻦﻧﻨﻩﻪﻫﻬﻭﻮﻯﻰﻱﻲﻳﻴﻵﻶﻷﻸﻹﻺﻻﻼ';
$result = Multibyte::utf8($string);
$expected = array(65201, 65202, 65203, 65204, 65205, 65206, 65207, 65208, 65209, 65210, 65211, 65212, 65213, 65214, 65215, 65216,
65217, 65218, 65219, 65220, 65221, 65222, 65223, 65224, 65225, 65226, 65227, 65228, 65229, 65230, 65231, 65232,
65233, 65234, 65235, 65236, 65237, 65238, 65239, 65240, 65241, 65242, 65243, 65244, 65245, 65246, 65247, 65248,
65249, 65250, 65251, 65252, 65253, 65254, 65255, 65256, 65257, 65258, 65259, 65260, 65261, 65262, 65263, 65264,
65265, 65266, 65267, 65268, 65269, 65270, 65271, 65272, 65273, 65274, 65275, 65276);
$this->assertEqual($expected, $result);
$string = 'abcdefghijklmnopqrstuvwxyz';
$result = Multibyte::utf8($string);
$expected = array(65345, 65346, 65347, 65348, 65349, 65350, 65351, 65352, 65353, 65354, 65355, 65356, 65357, 65358, 65359, 65360,
65361, 65362, 65363, 65364, 65365, 65366, 65367, 65368, 65369, 65370);
$this->assertEqual($expected, $result);
$string = '。「」、・ヲァィゥェォャュョッーアイウエオカキク';
$result = Multibyte::utf8($string);
$expected = array(65377, 65378, 65379, 65380, 65381, 65382, 65383, 65384, 65385, 65386, 65387, 65388, 65389, 65390, 65391, 65392,
65393, 65394, 65395, 65396, 65397, 65398, 65399, 65400);
$this->assertEqual($expected, $result);
$string = 'ケコサシスセソタチツテトナニヌネノハヒフヘホマミムメモヤユヨラリルレロワン゙';
$result = Multibyte::utf8($string);
$expected = array(65401, 65402, 65403, 65404, 65405, 65406, 65407, 65408, 65409, 65410, 65411, 65412, 65413, 65414, 65415, 65416,
65417, 65418, 65419, 65420, 65421, 65422, 65423, 65424, 65425, 65426, 65427, 65428, 65429, 65430, 65431, 65432,
65433, 65434, 65435, 65436, 65437, 65438);
$this->assertEqual($expected, $result);
$string = 'Ĥēĺļŏ, Ŵőřļď!';
$result = Multibyte::utf8($string);
$expected = array(292, 275, 314, 316, 335, 44, 32, 372, 337, 345, 316, 271, 33);
$this->assertEqual($expected, $result);
$string = 'Hello, World!';
$result = Multibyte::utf8($string);
$expected = array(72, 101, 108, 108, 111, 44, 32, 87, 111, 114, 108, 100, 33);
$this->assertEqual($expected, $result);
$string = '¨';
$result = Multibyte::utf8($string);
$expected = array(168);
$this->assertEqual($expected, $result);
$string = '¿';
$result = Multibyte::utf8($string);
$expected = array(191);
$this->assertEqual($expected, $result);
$string = 'čini';
$result = Multibyte::utf8($string);
$expected = array(269, 105, 110, 105);
$this->assertEqual($expected, $result);
$string = 'moći';
$result = Multibyte::utf8($string);
$expected = array(109, 111, 263, 105);
$this->assertEqual($expected, $result);
$string = 'državni';
$result = Multibyte::utf8($string);
$expected = array(100, 114, 382, 97, 118, 110, 105);
$this->assertEqual($expected, $result);
$string = '把百度设为首页';
$result = Multibyte::utf8($string);
$expected = array(25226, 30334, 24230, 35774, 20026, 39318, 39029);
$this->assertEqual($expected, $result);
$string = '一二三周永龍';
$result = Multibyte::utf8($string);
$expected = array(19968, 20108, 19977, 21608, 27704, 40845);
$this->assertEqual($expected, $result);
$string = 'ԀԂԄԆԈԊԌԎԐԒ';
$result = Multibyte::utf8($string);
$expected = array(1280, 1282, 1284, 1286, 1288, 1290, 1292, 1294, 1296, 1298);
$this->assertEqual($expected, $result);
$string = 'ԁԃԅԇԉԋԍԏԐԒ';
$result = Multibyte::utf8($string);
$expected = array(1281, 1283, 1285, 1287, 1289, 1291, 1293, 1295, 1296, 1298);
$this->assertEqual($expected, $result);
$string = 'ԱԲԳԴԵԶԷԸԹԺԻԼԽԾԿՀՁՂՃՄՅՆՇՈՉՊՋՌՍՎՏՐՑՒՓՔՕՖև';
$result = Multibyte::utf8($string);
$expected = array(1329, 1330, 1331, 1332, 1333, 1334, 1335, 1336, 1337, 1338, 1339, 1340, 1341, 1342, 1343, 1344, 1345, 1346,
1347, 1348, 1349, 1350, 1351, 1352, 1353, 1354, 1355, 1356, 1357, 1358, 1359, 1360, 1361, 1362, 1363, 1364,
1365, 1366, 1415);
$this->assertEqual($expected, $result);
$string = 'աբգդեզէըթժիլխծկհձղճմյնշոչպջռսվտրցւփքօֆև';
$result = Multibyte::utf8($string);
$expected = array(1377, 1378, 1379, 1380, 1381, 1382, 1383, 1384, 1385, 1386, 1387, 1388, 1389, 1390, 1391, 1392, 1393, 1394,
1395, 1396, 1397, 1398, 1399, 1400, 1401, 1402, 1403, 1404, 1405, 1406, 1407, 1408, 1409, 1410, 1411, 1412,
1413, 1414, 1415);
$this->assertEqual($expected, $result);
$string = 'ႠႡႢႣႤႥႦႧႨႩႪႫႬႭႮႯႰႱႲႳႴႵႶႷႸႹႺႻႼႽႾႿჀჁჂჃჄჅ';
$result = Multibyte::utf8($string);
$expected = array(4256, 4257, 4258, 4259, 4260, 4261, 4262, 4263, 4264, 4265, 4266, 4267, 4268, 4269, 4270, 4271, 4272, 4273,
4274, 4275, 4276, 4277, 4278, 4279, 4280, 4281, 4282, 4283, 4284, 4285, 4286, 4287, 4288, 4289, 4290, 4291,
4292, 4293);
$this->assertEqual($expected, $result);
$string = 'ḀḂḄḆḈḊḌḎḐḒḔḖḘḚḜḞḠḢḤḦḨḪḬḮḰḲḴḶḸḺḼḾṀṂṄṆṈṊṌṎṐṒṔṖṘṚṜṞṠṢṤṦṨṪṬṮṰṲṴṶṸṺṼṾẀẂẄẆẈẊẌẎẐẒẔẖẗẘẙẚẠẢẤẦẨẪẬẮẰẲẴẶẸẺẼẾỀỂỄỆỈỊỌỎỐỒỔỖỘỚỜỞỠỢỤỦỨỪỬỮỰỲỴỶỸ';
$result = Multibyte::utf8($string);
$expected = array(7680, 7682, 7684, 7686, 7688, 7690, 7692, 7694, 7696, 7698, 7700, 7702, 7704, 7706, 7708, 7710, 7712, 7714,
7716, 7718, 7720, 7722, 7724, 7726, 7728, 7730, 7732, 7734, 7736, 7738, 7740, 7742, 7744, 7746, 7748, 7750,
7752, 7754, 7756, 7758, 7760, 7762, 7764, 7766, 7768, 7770, 7772, 7774, 7776, 7778, 7780, 7782, 7784, 7786,
7788, 7790, 7792, 7794, 7796, 7798, 7800, 7802, 7804, 7806, 7808, 7810, 7812, 7814, 7816, 7818, 7820, 7822,
7824, 7826, 7828, 7830, 7831, 7832, 7833, 7834, 7840, 7842, 7844, 7846, 7848, 7850, 7852, 7854, 7856,
7858, 7860, 7862, 7864, 7866, 7868, 7870, 7872, 7874, 7876, 7878, 7880, 7882, 7884, 7886, 7888, 7890, 7892,
7894, 7896, 7898, 7900, 7902, 7904, 7906, 7908, 7910, 7912, 7914, 7916, 7918, 7920, 7922, 7924, 7926, 7928);
$this->assertEqual($expected, $result);
$string = 'ḁḃḅḇḉḋḍḏḑḓḕḗḙḛḝḟḡḣḥḧḩḫḭḯḱḳḵḷḹḻḽḿṁṃṅṇṉṋṍṏṑṓṕṗṙṛṝṟṡṣṥṧṩṫṭṯṱṳṵṷṹṻṽṿẁẃẅẇẉẋẍẏẑẓẕẖẗẘẙẚạảấầẩẫậắằẳẵặẹẻẽếềểễệỉịọỏốồổỗộớờởỡợụủứừửữựỳỵỷỹ';
$result = Multibyte::utf8($string);
$expected = array(7681, 7683, 7685, 7687, 7689, 7691, 7693, 7695, 7697, 7699, 7701, 7703, 7705, 7707, 7709, 7711, 7713, 7715,
7717, 7719, 7721, 7723, 7725, 7727, 7729, 7731, 7733, 7735, 7737, 7739, 7741, 7743, 7745, 7747, 7749, 7751,
7753, 7755, 7757, 7759, 7761, 7763, 7765, 7767, 7769, 7771, 7773, 7775, 7777, 7779, 7781, 7783, 7785, 7787,
7789, 7791, 7793, 7795, 7797, 7799, 7801, 7803, 7805, 7807, 7809, 7811, 7813, 7815, 7817, 7819, 7821, 7823,
7825, 7827, 7829, 7830, 7831, 7832, 7833, 7834, 7841, 7843, 7845, 7847, 7849, 7851, 7853, 7855, 7857, 7859,
7861, 7863, 7865, 7867, 7869, 7871, 7873, 7875, 7877, 7879, 7881, 7883, 7885, 7887, 7889, 7891, 7893, 7895,
7897, 7899, 7901, 7903, 7905, 7907, 7909, 7911, 7913, 7915, 7917, 7919, 7921, 7923, 7925, 7927, 7929);
$this->assertEqual($expected, $result);
$string = 'ΩKÅℲ';
$result = Multibyte::utf8($string);
$expected = array(8486, 8490, 8491, 8498);
$this->assertEqual($expected, $result);
$string = 'ωkåⅎ';
$result = Multibyte::utf8($string);
$expected = array(969, 107, 229, 8526);
$this->assertEqual($expected, $result);
$string = 'ⅠⅡⅢⅣⅤⅥⅦⅧⅨⅩⅪⅫⅬⅭⅮⅯↃ';
$result = Multibyte::utf8($string);
$expected = array(8544, 8545, 8546, 8547, 8548, 8549, 8550, 8551, 8552, 8553, 8554, 8555, 8556, 8557, 8558, 8559, 8579);
$this->assertEqual($expected, $result);
$string = 'ⅰⅱⅲⅳⅴⅵⅶⅷⅸⅹⅺⅻⅼⅽⅾⅿↄ';
$result = Multibyte::utf8($string);
$expected = array(8560, 8561, 8562, 8563, 8564, 8565, 8566, 8567, 8568, 8569, 8570, 8571, 8572, 8573, 8574, 8575, 8580);
$this->assertEqual($expected, $result);
$string = 'ⒶⒷⒸⒹⒺⒻⒼⒽⒾⒿⓀⓁⓂⓃⓄⓅⓆⓇⓈⓉⓊⓋⓌⓍⓎⓏ';
$result = Multibyte::utf8($string);
$expected = array(9398, 9399, 9400, 9401, 9402, 9403, 9404, 9405, 9406, 9407, 9408, 9409, 9410, 9411, 9412, 9413, 9414,
9415, 9416, 9417, 9418, 9419, 9420, 9421, 9422, 9423);
$this->assertEqual($expected, $result);
$string = 'ⓐⓑⓒⓓⓔⓕⓖⓗⓘⓙⓚⓛⓜⓝⓞⓟⓠⓡⓢⓣⓤⓥⓦⓧⓨⓩ';
$result = Multibyte::utf8($string);
$expected = array(9424, 9425, 9426, 9427, 9428, 9429, 9430, 9431, 9432, 9433, 9434, 9435, 9436, 9437, 9438, 9439, 9440, 9441,
9442, 9443, 9444, 9445, 9446, 9447, 9448, 9449);
$this->assertEqual($expected, $result);
$string = 'ⰀⰁⰂⰃⰄⰅⰆⰇⰈⰉⰊⰋⰌⰍⰎⰏⰐⰑⰒⰓⰔⰕⰖⰗⰘⰙⰚⰛⰜⰝⰞⰟⰠⰡⰢⰣⰤⰥⰦⰧⰨⰩⰪⰫⰬⰭⰮ';
$result = Multibyte::utf8($string);
$expected = array(11264, 11265, 11266, 11267, 11268, 11269, 11270, 11271, 11272, 11273, 11274, 11275, 11276, 11277, 11278,
11279, 11280, 11281, 11282, 11283, 11284, 11285, 11286, 11287, 11288, 11289, 11290, 11291, 11292, 11293,
11294, 11295, 11296, 11297, 11298, 11299, 11300, 11301, 11302, 11303, 11304, 11305, 11306, 11307, 11308,
11309, 11310);
$this->assertEqual($expected, $result);
$string = 'ⰰⰱⰲⰳⰴⰵⰶⰷⰸⰹⰺⰻⰼⰽⰾⰿⱀⱁⱂⱃⱄⱅⱆⱇⱈⱉⱊⱋⱌⱍⱎⱏⱐⱑⱒⱓⱔⱕⱖⱗⱘⱙⱚⱛⱜⱝⱞ';
$result = Multibyte::utf8($string);
$expected = array(11312, 11313, 11314, 11315, 11316, 11317, 11318, 11319, 11320, 11321, 11322, 11323, 11324, 11325, 11326, 11327,
11328, 11329, 11330, 11331, 11332, 11333, 11334, 11335, 11336, 11337, 11338, 11339, 11340, 11341, 11342, 11343,
11344, 11345, 11346, 11347, 11348, 11349, 11350, 11351, 11352, 11353, 11354, 11355, 11356, 11357, 11358);
$this->assertEqual($expected, $result);
$string = 'ⲀⲂⲄⲆⲈⲊⲌⲎⲐⲒⲔⲖⲘⲚⲜⲞⲠⲢⲤⲦⲨⲪⲬⲮⲰⲲⲴⲶⲸⲺⲼⲾⳀⳂⳄⳆⳈⳊⳌⳎⳐⳒⳔⳖⳘⳚⳜⳞⳠⳢ';
$result = Multibyte::utf8($string);
$expected = array(11392, 11394, 11396, 11398, 11400, 11402, 11404, 11406, 11408, 11410, 11412, 11414, 11416, 11418, 11420,
11422, 11424, 11426, 11428, 11430, 11432, 11434, 11436, 11438, 11440, 11442, 11444, 11446, 11448, 11450,
11452, 11454, 11456, 11458, 11460, 11462, 11464, 11466, 11468, 11470, 11472, 11474, 11476, 11478, 11480,
11482, 11484, 11486, 11488, 11490);
$this->assertEqual($expected, $result);
$string = 'ⲁⲃⲅⲇⲉⲋⲍⲏⲑⲓⲕⲗⲙⲛⲝⲟⲡⲣⲥⲧⲩⲫⲭⲯⲱⲳⲵⲷⲹⲻⲽⲿⳁⳃⳅⳇⳉⳋⳍⳏⳑⳓⳕⳗⳙⳛⳝⳟⳡⳣ';
$result = Multibyte::utf8($string);
$expected = array(11393, 11395, 11397, 11399, 11401, 11403, 11405, 11407, 11409, 11411, 11413, 11415, 11417, 11419, 11421, 11423,
11425, 11427, 11429, 11431, 11433, 11435, 11437, 11439, 11441, 11443, 11445, 11447, 11449, 11451, 11453, 11455,
11457, 11459, 11461, 11463, 11465, 11467, 11469, 11471, 11473, 11475, 11477, 11479, 11481, 11483, 11485, 11487,
11489, 11491);
$this->assertEqual($expected, $result);
$string = 'fffiflffifflſtstﬓﬔﬕﬖﬗ';
$result = Multibyte::utf8($string);
$expected = array(64256, 64257, 64258, 64259, 64260, 64261, 64262, 64275, 64276, 64277, 64278, 64279);
$this->assertEqual($expected, $result);
}
/**
* testAscii method
*
* @return void
*/
public function testAscii() {
$utf8 = array(33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57,
58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82,
83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105,
106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126);
$result = Multibyte::ascii($utf8);
$expected = '!"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~';
$this->assertEqual($expected, $result);
$utf8 = array(161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181,
182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 200);
$result = Multibyte::ascii($utf8);
$expected = '¡¢£¤¥¦§¨©ª«¬®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈ';
$this->assertEqual($expected, $result);
$utf8 = array(201, 202, 203, 204, 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 220, 221,
222, 223, 224, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238, 239, 240, 241, 242,
243, 244, 245, 246, 247, 248, 249, 250, 251, 252, 253, 254, 255, 256, 257, 258, 259, 260, 261, 262, 263,
264, 265, 266, 267, 268, 269, 270, 271, 272, 273, 274, 275, 276, 277, 278, 279, 280, 281, 282, 283, 284,
285, 286, 287, 288, 289, 290, 291, 292, 293, 294, 295, 296, 297, 298, 299, 300);
$result = Multibyte::ascii($utf8);
$expected = 'ÉÊËÌÍÎÏÐÑÒÓÔÕÖרÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿĀāĂ㥹ĆćĈĉĊċČčĎďĐđĒēĔĕĖėĘęĚěĜĝĞğĠġĢģĤĥĦħĨĩĪīĬ';
$this->assertEqual($expected, $result);
$utf8 = array(301, 302, 303, 304, 305, 306, 307, 308, 309, 310, 311, 312, 313, 314, 315, 316, 317, 318, 319, 320, 321,
322, 323, 324, 325, 326, 327, 328, 329, 330, 331, 332, 333, 334, 335, 336, 337, 338, 339, 340, 341, 342,
343, 344, 345, 346, 347, 348, 349, 350, 351, 352, 353, 354, 355, 356, 357, 358, 359, 360, 361, 362, 363,
364, 365, 366, 367, 368, 369, 370, 371, 372, 373, 374, 375, 376, 377, 378, 379, 380, 381, 382, 383, 384,
385, 386, 387, 388, 389, 390, 391, 392, 393, 394, 395, 396, 397, 398, 399, 400);
$expected = 'ĭĮįİıIJijĴĵĶķĸĹĺĻļĽľĿŀŁłŃńŅņŇňʼnŊŋŌōŎŏŐőŒœŔŕŖŗŘřŚśŜŝŞşŠšŢţŤťŦŧŨũŪūŬŭŮůŰűŲųŴŵŶŷŸŹźŻżŽžſƀƁƂƃƄƅƆƇƈƉƊƋƌƍƎƏƐ';
$result = Multibyte::ascii($utf8);
$this->assertEqual($expected, $result);
$utf8 = array(401, 402, 403, 404, 405, 406, 407, 408, 409, 410, 411, 412, 413, 414, 415, 416, 417, 418, 419, 420, 421,
422, 423, 424, 425, 426, 427, 428, 429, 430, 431, 432, 433, 434, 435, 436, 437, 438, 439, 440, 441, 442,
443, 444, 445, 446, 447, 448, 449, 450, 451, 452, 453, 454, 455, 456, 457, 458, 459, 460, 461, 462, 463,
464, 465, 466, 467, 468, 469, 470, 471, 472, 473, 474, 475, 476, 477, 478, 479, 480, 481, 482, 483, 484,
485, 486, 487, 488, 489, 490, 491, 492, 493, 494, 495, 496, 497, 498, 499, 500);
$expected = 'ƑƒƓƔƕƖƗƘƙƚƛƜƝƞƟƠơƢƣƤƥƦƧƨƩƪƫƬƭƮƯưƱƲƳƴƵƶƷƸƹƺƻƼƽƾƿǀǁǂǃDŽDždžLJLjljNJNjnjǍǎǏǐǑǒǓǔǕǖǗǘǙǚǛǜǝǞǟǠǡǢǣǤǥǦǧǨǩǪǫǬǭǮǯǰDZDzdzǴ';
$result = Multibyte::ascii($utf8);
$this->assertEqual($expected, $result);
$utf8 = array(601, 602, 603, 604, 605, 606, 607, 608, 609, 610, 611, 612, 613, 614, 615, 616, 617, 618, 619, 620, 621,
622, 623, 624, 625, 626, 627, 628, 629, 630, 631, 632, 633, 634, 635, 636, 637, 638, 639, 640, 641, 642,
643, 644, 645, 646, 647, 648, 649, 650, 651, 652, 653, 654, 655, 656, 657, 658, 659, 660, 661, 662, 663,
664, 665, 666, 667, 668, 669, 670, 671, 672, 673, 674, 675, 676, 677, 678, 679, 680, 681, 682, 683, 684,
685, 686, 687, 688, 689, 690, 691, 692, 693, 694, 695, 696, 697, 698, 699, 700);
$expected = 'əɚɛɜɝɞɟɠɡɢɣɤɥɦɧɨɩɪɫɬɭɮɯɰɱɲɳɴɵɶɷɸɹɺɻɼɽɾɿʀʁʂʃʄʅʆʇʈʉʊʋʌʍʎʏʐʑʒʓʔʕʖʗʘʙʚʛʜʝʞʟʠʡʢʣʤʥʦʧʨʩʪʫʬʭʮʯʰʱʲʳʴʵʶʷʸʹʺʻʼ';
$result = Multibyte::ascii($utf8);
$this->assertEqual($expected, $result);
$utf8 = array(1024, 1025, 1026, 1027, 1028, 1029, 1030, 1031, 1032, 1033, 1034, 1035, 1036, 1037, 1038, 1039, 1040, 1041,
1042, 1043, 1044, 1045, 1046, 1047, 1048, 1049, 1050, 1051);
$expected = 'ЀЁЂЃЄЅІЇЈЉЊЋЌЍЎЏАБВГДЕЖЗИЙКЛ';
$result = Multibyte::ascii($utf8);
$this->assertEqual($expected, $result);
$utf8 = array(1052, 1053, 1054, 1055, 1056, 1057, 1058, 1059, 1060, 1061, 1062, 1063, 1064, 1065, 1066, 1067, 1068, 1069,
1070, 1071, 1072, 1073, 1074, 1075, 1076, 1077, 1078, 1079, 1080, 1081, 1082, 1083, 1084, 1085, 1086, 1087,
1088, 1089, 1090, 1091, 1092, 1093, 1094, 1095, 1096, 1097, 1098, 1099, 1100);
$expected = 'МНОПРСТУФХЦЧШЩЪЫЬЭЮЯабвгдежзийклмнопрстуфхцчшщъыь';
$result = Multibyte::ascii($utf8);
$this->assertEqual($expected, $result);
$utf8 = array(1401, 1402, 1403, 1404, 1405, 1406, 1407);
$expected = 'չպջռսվտ';
$result = Multibyte::ascii($utf8);
$this->assertEqual($expected, $result);
$utf8 = array(1601, 1602, 1603, 1604, 1605, 1606, 1607, 1608, 1609, 1610, 1611, 1612, 1613, 1614, 1615);
$expected = 'فقكلمنهوىيًٌٍَُ';
$result = Multibyte::ascii($utf8);
$this->assertEqual($expected, $result);
$utf8 = array(10032, 10033, 10034, 10035, 10036, 10037, 10038, 10039, 10040, 10041, 10042, 10043, 10044,
10045, 10046, 10047, 10048, 10049, 10050, 10051, 10052, 10053, 10054, 10055, 10056, 10057,
10058, 10059, 10060, 10061, 10062, 10063, 10064, 10065, 10066, 10067, 10068, 10069, 10070,
10071, 10072, 10073, 10074, 10075, 10076, 10077, 10078);
$expected = '✰✱✲✳✴✵✶✷✸✹✺✻✼✽✾✿❀❁❂❃❄❅❆❇❈❉❊❋❌❍❎❏❐❑❒❓❔❕❖❗❘❙❚❛❜❝❞';
$result = Multibyte::ascii($utf8);
$this->assertEqual($expected, $result);
$utf8 = array(11904, 11905, 11906, 11907, 11908, 11909, 11910, 11911, 11912, 11913, 11914, 11915, 11916, 11917, 11918, 11919,
11920, 11921, 11922, 11923, 11924, 11925, 11926, 11927, 11928, 11929, 11931, 11932, 11933, 11934, 11935, 11936,
11937, 11938, 11939, 11940, 11941, 11942, 11943, 11944, 11945, 11946, 11947, 11948, 11949, 11950, 11951, 11952,
11953, 11954, 11955, 11956, 11957, 11958, 11959, 11960, 11961, 11962, 11963, 11964, 11965, 11966, 11967, 11968,
11969, 11970, 11971, 11972, 11973, 11974, 11975, 11976, 11977, 11978, 11979, 11980, 11981, 11982, 11983, 11984,
11985, 11986, 11987, 11988, 11989, 11990, 11991, 11992, 11993, 11994, 11995, 11996, 11997, 11998, 11999, 12000);
$expected = '⺀⺁⺂⺃⺄⺅⺆⺇⺈⺉⺊⺋⺌⺍⺎⺏⺐⺑⺒⺓⺔⺕⺖⺗⺘⺙⺛⺜⺝⺞⺟⺠⺡⺢⺣⺤⺥⺦⺧⺨⺩⺪⺫⺬⺭⺮⺯⺰⺱⺲⺳⺴⺵⺶⺷⺸⺹⺺⺻⺼⺽⺾⺿⻀⻁⻂⻃⻄⻅⻆⻇⻈⻉⻊⻋⻌⻍⻎⻏⻐⻑⻒⻓⻔⻕⻖⻗⻘⻙⻚⻛⻜⻝⻞⻟⻠';
$result = Multibyte::ascii($utf8);
$this->assertEqual($expected, $result);
$utf8 = array(12101, 12102, 12103, 12104, 12105, 12106, 12107, 12108, 12109, 12110, 12111, 12112, 12113, 12114, 12115, 12116,
12117, 12118, 12119, 12120, 12121, 12122, 12123, 12124, 12125, 12126, 12127, 12128, 12129, 12130, 12131, 12132,
12133, 12134, 12135, 12136, 12137, 12138, 12139, 12140, 12141, 12142, 12143, 12144, 12145, 12146, 12147, 12148,
12149, 12150, 12151, 12152, 12153, 12154, 12155, 12156, 12157, 12158, 12159);
$expected = '⽅⽆⽇⽈⽉⽊⽋⽌⽍⽎⽏⽐⽑⽒⽓⽔⽕⽖⽗⽘⽙⽚⽛⽜⽝⽞⽟⽠⽡⽢⽣⽤⽥⽦⽧⽨⽩⽪⽫⽬⽭⽮⽯⽰⽱⽲⽳⽴⽵⽶⽷⽸⽹⽺⽻⽼⽽⽾⽿';
$result = Multibyte::ascii($utf8);
$this->assertEqual($expected, $result);
$utf8 = array(45601, 45602, 45603, 45604, 45605, 45606, 45607, 45608, 45609, 45610, 45611, 45612, 45613, 45614, 45615, 45616,
45617, 45618, 45619, 45620, 45621, 45622, 45623, 45624, 45625, 45626, 45627, 45628, 45629, 45630, 45631, 45632,
45633, 45634, 45635, 45636, 45637, 45638, 45639, 45640, 45641, 45642, 45643, 45644, 45645, 45646, 45647, 45648,
45649, 45650, 45651, 45652, 45653, 45654, 45655, 45656, 45657, 45658, 45659, 45660, 45661, 45662, 45663, 45664,
45665, 45666, 45667, 45668, 45669, 45670, 45671, 45672, 45673, 45674, 45675, 45676, 45677, 45678, 45679, 45680,
45681, 45682, 45683, 45684, 45685, 45686, 45687, 45688, 45689, 45690, 45691, 45692, 45693, 45694, 45695, 45696,
45697, 45698, 45699, 45700);
$expected = '눡눢눣눤눥눦눧눨눩눪눫눬눭눮눯눰눱눲눳눴눵눶눷눸눹눺눻눼눽눾눿뉀뉁뉂뉃뉄뉅뉆뉇뉈뉉뉊뉋뉌뉍뉎뉏뉐뉑뉒뉓뉔뉕뉖뉗뉘뉙뉚뉛뉜뉝뉞뉟뉠뉡뉢뉣뉤뉥뉦뉧뉨뉩뉪뉫뉬뉭뉮뉯뉰뉱뉲뉳뉴뉵뉶뉷뉸뉹뉺뉻뉼뉽뉾뉿늀늁늂늃늄';
$result = Multibyte::ascii($utf8);
$this->assertEqual($expected, $result);
$utf8 = array(65136, 65137, 65138, 65139, 65140, 65141, 65142, 65143, 65144, 65145, 65146, 65147, 65148, 65149, 65150, 65151,
65152, 65153, 65154, 65155, 65156, 65157, 65158, 65159, 65160, 65161, 65162, 65163, 65164, 65165, 65166, 65167,
65168, 65169, 65170, 65171, 65172, 65173, 65174, 65175, 65176, 65177, 65178, 65179, 65180, 65181, 65182, 65183,
65184, 65185, 65186, 65187, 65188, 65189, 65190, 65191, 65192, 65193, 65194, 65195, 65196, 65197, 65198, 65199,
65200);
$expected = 'ﹰﹱﹲﹳﹴﹶﹷﹸﹹﹺﹻﹼﹽﹾﹿﺀﺁﺂﺃﺄﺅﺆﺇﺈﺉﺊﺋﺌﺍﺎﺏﺐﺑﺒﺓﺔﺕﺖﺗﺘﺙﺚﺛﺜﺝﺞﺟﺠﺡﺢﺣﺤﺥﺦﺧﺨﺩﺪﺫﺬﺭﺮﺯﺰ';
$result = Multibyte::ascii($utf8);
$this->assertEqual($expected, $result);
$utf8 = array(65201, 65202, 65203, 65204, 65205, 65206, 65207, 65208, 65209, 65210, 65211, 65212, 65213, 65214, 65215, 65216,
65217, 65218, 65219, 65220, 65221, 65222, 65223, 65224, 65225, 65226, 65227, 65228, 65229, 65230, 65231, 65232,
65233, 65234, 65235, 65236, 65237, 65238, 65239, 65240, 65241, 65242, 65243, 65244, 65245, 65246, 65247, 65248,
65249, 65250, 65251, 65252, 65253, 65254, 65255, 65256, 65257, 65258, 65259, 65260, 65261, 65262, 65263, 65264,
65265, 65266, 65267, 65268, 65269, 65270, 65271, 65272, 65273, 65274, 65275, 65276);
$expected = 'ﺱﺲﺳﺴﺵﺶﺷﺸﺹﺺﺻﺼﺽﺾﺿﻀﻁﻂﻃﻄﻅﻆﻇﻈﻉﻊﻋﻌﻍﻎﻏﻐﻑﻒﻓﻔﻕﻖﻗﻘﻙﻚﻛﻜﻝﻞﻟﻠﻡﻢﻣﻤﻥﻦﻧﻨﻩﻪﻫﻬﻭﻮﻯﻰﻱﻲﻳﻴﻵﻶﻷﻸﻹﻺﻻﻼ';
$result = Multibyte::ascii($utf8);
$this->assertEqual($expected, $result);
$utf8 = array(65345, 65346, 65347, 65348, 65349, 65350, 65351, 65352, 65353, 65354, 65355, 65356, 65357, 65358, 65359, 65360,
65361, 65362, 65363, 65364, 65365, 65366, 65367, 65368, 65369, 65370);
$expected = 'abcdefghijklmnopqrstuvwxyz';
$result = Multibyte::ascii($utf8);
$this->assertEqual($expected, $result);
$utf8 = array(65377, 65378, 65379, 65380, 65381, 65382, 65383, 65384, 65385, 65386, 65387, 65388, 65389, 65390, 65391, 65392,
65393, 65394, 65395, 65396, 65397, 65398, 65399, 65400);
$expected = '。「」、・ヲァィゥェォャュョッーアイウエオカキク';
$result = Multibyte::ascii($utf8);
$this->assertEqual($expected, $result);
$utf8 = array(65401, 65402, 65403, 65404, 65405, 65406, 65407, 65408, 65409, 65410, 65411, 65412, 65413, 65414, 65415, 65416,
65417, 65418, 65419, 65420, 65421, 65422, 65423, 65424, 65425, 65426, 65427, 65428, 65429, 65430, 65431, 65432,
65433, 65434, 65435, 65436, 65437, 65438);
$expected = 'ケコサシスセソタチツテトナニヌネノハヒフヘホマミムメモヤユヨラリルレロワン゙';
$result = Multibyte::ascii($utf8);
$this->assertEqual($expected, $result);
$utf8 = array(292, 275, 314, 316, 335, 44, 32, 372, 337, 345, 316, 271, 33);
$expected = 'Ĥēĺļŏ, Ŵőřļď!';
$result = Multibyte::ascii($utf8);
$this->assertEqual($expected, $result);
$utf8 = array(72, 101, 108, 108, 111, 44, 32, 87, 111, 114, 108, 100, 33);
$expected = 'Hello, World!';
$result = Multibyte::ascii($utf8);
$this->assertEqual($expected, $result);
$utf8 = array(168);
$expected = '¨';
$result = Multibyte::ascii($utf8);
$this->assertEqual($expected, $result);
$utf8 = array(191);
$expected = '¿';
$result = Multibyte::ascii($utf8);
$this->assertEqual($expected, $result);
$utf8 = array(269, 105, 110, 105);
$expected = 'čini';
$result = Multibyte::ascii($utf8);
$this->assertEqual($expected, $result);
$utf8 = array(109, 111, 263, 105);
$expected = 'moći';
$result = Multibyte::ascii($utf8);
$this->assertEqual($expected, $result);
$utf8 = array(100, 114, 382, 97, 118, 110, 105);
$expected = 'državni';
$result = Multibyte::ascii($utf8);
$this->assertEqual($expected, $result);
$utf8 = array(25226, 30334, 24230, 35774, 20026, 39318, 39029);
$expected = '把百度设为首页';
$result = Multibyte::ascii($utf8);
$this->assertEqual($expected, $result);
$utf8 = array(19968, 20108, 19977, 21608, 27704, 40845);
$expected = '一二三周永龍';
$result = Multibyte::ascii($utf8);
$this->assertEqual($expected, $result);
$utf8 = array(1280, 1282, 1284, 1286, 1288, 1290, 1292, 1294, 1296, 1298);
$expected = 'ԀԂԄԆԈԊԌԎԐԒ';
$result = Multibyte::ascii($utf8);
$this->assertEqual($expected, $result);
$utf8 = array(1281, 1283, 1285, 1287, 1289, 1291, 1293, 1295, 1296, 1298);
$expected = 'ԁԃԅԇԉԋԍԏԐԒ';
$result = Multibyte::ascii($utf8);
$this->assertEqual($expected, $result);
$utf8 = array(1329, 1330, 1331, 1332, 1333, 1334, 1335, 1336, 1337, 1338, 1339, 1340, 1341, 1342, 1343, 1344, 1345, 1346, 1347,
1348, 1349, 1350, 1351, 1352, 1353, 1354, 1355, 1356, 1357, 1358, 1359, 1360, 1361, 1362, 1363, 1364, 1365,
1366, 1415);
$result = Multibyte::ascii($utf8);
$expected = 'ԱԲԳԴԵԶԷԸԹԺԻԼԽԾԿՀՁՂՃՄՅՆՇՈՉՊՋՌՍՎՏՐՑՒՓՔՕՖև';
$this->assertEqual($expected, $result);
$utf8 = array(1377, 1378, 1379, 1380, 1381, 1382, 1383, 1384, 1385, 1386, 1387, 1388, 1389, 1390, 1391, 1392, 1393, 1394,
1395, 1396, 1397, 1398, 1399, 1400, 1401, 1402, 1403, 1404, 1405, 1406, 1407, 1408, 1409, 1410, 1411, 1412,
1413, 1414, 1415);
$result = Multibyte::ascii($utf8);
$expected = 'աբգդեզէըթժիլխծկհձղճմյնշոչպջռսվտրցւփքօֆև';
$this->assertEqual($expected, $result);
$utf8 = array(4256, 4257, 4258, 4259, 4260, 4261, 4262, 4263, 4264, 4265, 4266, 4267, 4268, 4269, 4270, 4271, 4272, 4273, 4274,
4275, 4276, 4277, 4278, 4279, 4280, 4281, 4282, 4283, 4284, 4285, 4286, 4287, 4288, 4289, 4290, 4291, 4292, 4293);
$result = Multibyte::ascii($utf8);
$expected = 'ႠႡႢႣႤႥႦႧႨႩႪႫႬႭႮႯႰႱႲႳႴႵႶႷႸႹႺႻႼႽႾႿჀჁჂჃჄჅ';
$this->assertEqual($expected, $result);
$utf8 = array(7680, 7682, 7684, 7686, 7688, 7690, 7692, 7694, 7696, 7698, 7700, 7702, 7704, 7706, 7708, 7710, 7712, 7714,
7716, 7718, 7720, 7722, 7724, 7726, 7728, 7730, 7732, 7734, 7736, 7738, 7740, 7742, 7744, 7746, 7748, 7750,
7752, 7754, 7756, 7758, 7760, 7762, 7764, 7766, 7768, 7770, 7772, 7774, 7776, 7778, 7780, 7782, 7784, 7786,
7788, 7790, 7792, 7794, 7796, 7798, 7800, 7802, 7804, 7806, 7808, 7810, 7812, 7814, 7816, 7818, 7820, 7822,
7824, 7826, 7828, 7830, 7831, 7832, 7833, 7834, 7840, 7842, 7844, 7846, 7848, 7850, 7852, 7854, 7856,
7858, 7860, 7862, 7864, 7866, 7868, 7870, 7872, 7874, 7876, 7878, 7880, 7882, 7884, 7886, 7888, 7890, 7892,
7894, 7896, 7898, 7900, 7902, 7904, 7906, 7908, 7910, 7912, 7914, 7916, 7918, 7920, 7922, 7924, 7926, 7928);
$result = Multibyte::ascii($utf8);
$expected = 'ḀḂḄḆḈḊḌḎḐḒḔḖḘḚḜḞḠḢḤḦḨḪḬḮḰḲḴḶḸḺḼḾṀṂṄṆṈṊṌṎṐṒṔṖṘṚṜṞṠṢṤṦṨṪṬṮṰṲṴṶṸṺṼṾẀẂẄẆẈẊẌẎẐẒẔẖẗẘẙẚẠẢẤẦẨẪẬẮẰẲẴẶẸẺẼẾỀỂỄỆỈỊỌỎỐỒỔỖỘỚỜỞỠỢỤỦỨỪỬỮỰỲỴỶỸ';
$this->assertEqual($expected, $result);
$utf8 = array(7681, 7683, 7685, 7687, 7689, 7691, 7693, 7695, 7697, 7699, 7701, 7703, 7705, 7707, 7709, 7711, 7713, 7715,
7717, 7719, 7721, 7723, 7725, 7727, 7729, 7731, 7733, 7735, 7737, 7739, 7741, 7743, 7745, 7747, 7749, 7751,
7753, 7755, 7757, 7759, 7761, 7763, 7765, 7767, 7769, 7771, 7773, 7775, 7777, 7779, 7781, 7783, 7785, 7787,
7789, 7791, 7793, 7795, 7797, 7799, 7801, 7803, 7805, 7807, 7809, 7811, 7813, 7815, 7817, 7819, 7821, 7823,
7825, 7827, 7829, 7830, 7831, 7832, 7833, 7834, 7841, 7843, 7845, 7847, 7849, 7851, 7853, 7855, 7857, 7859,
7861, 7863, 7865, 7867, 7869, 7871, 7873, 7875, 7877, 7879, 7881, 7883, 7885, 7887, 7889, 7891, 7893, 7895,
7897, 7899, 7901, 7903, 7905, 7907, 7909, 7911, 7913, 7915, 7917, 7919, 7921, 7923, 7925, 7927, 7929);
$result = Multibyte::ascii($utf8);
$expected = 'ḁḃḅḇḉḋḍḏḑḓḕḗḙḛḝḟḡḣḥḧḩḫḭḯḱḳḵḷḹḻḽḿṁṃṅṇṉṋṍṏṑṓṕṗṙṛṝṟṡṣṥṧṩṫṭṯṱṳṵṷṹṻṽṿẁẃẅẇẉẋẍẏẑẓẕẖẗẘẙẚạảấầẩẫậắằẳẵặẹẻẽếềểễệỉịọỏốồổỗộớờởỡợụủứừửữựỳỵỷỹ';
$this->assertEqual($expected, $result);
$utf8 = array(8486, 8490, 8491, 8498);
$result = Multibyte::ascii($utf8);
$expected = 'ΩKÅℲ';
$this->assertEqual($expected, $result);
$utf8 = array(969, 107, 229, 8526);
$result = Multibyte::ascii($utf8);
$expected = 'ωkåⅎ';
$this->assertEqual($expected, $result);
$utf8 = array(8544, 8545, 8546, 8547, 8548, 8549, 8550, 8551, 8552, 8553, 8554, 8555, 8556, 8557, 8558, 8559, 8579);
$result = Multibyte::ascii($utf8);
$expected = 'ⅠⅡⅢⅣⅤⅥⅦⅧⅨⅩⅪⅫⅬⅭⅮⅯↃ';
$this->assertEqual($expected, $result);
$utf8 = array(8560, 8561, 8562, 8563, 8564, 8565, 8566, 8567, 8568, 8569, 8570, 8571, 8572, 8573, 8574, 8575, 8580);
$result = Multibyte::ascii($utf8);
$expected = 'ⅰⅱⅲⅳⅴⅵⅶⅷⅸⅹⅺⅻⅼⅽⅾⅿↄ';
$this->assertEqual($expected, $result);
$utf8 = array(9398, 9399, 9400, 9401, 9402, 9403, 9404, 9405, 9406, 9407, 9408, 9409, 9410, 9411, 9412, 9413, 9414,
9415, 9416, 9417, 9418, 9419, 9420, 9421, 9422, 9423);
$result = Multibyte::ascii($utf8);
$expected = 'ⒶⒷⒸⒹⒺⒻⒼⒽⒾⒿⓀⓁⓂⓃⓄⓅⓆⓇⓈⓉⓊⓋⓌⓍⓎⓏ';
$this->assertEqual($expected, $result);
$utf8 = array(9424, 9425, 9426, 9427, 9428, 9429, 9430, 9431, 9432, 9433, 9434, 9435, 9436, 9437, 9438, 9439, 9440, 9441,
9442, 9443, 9444, 9445, 9446, 9447, 9448, 9449);
$result = Multibyte::ascii($utf8);
$expected = 'ⓐⓑⓒⓓⓔⓕⓖⓗⓘⓙⓚⓛⓜⓝⓞⓟⓠⓡⓢⓣⓤⓥⓦⓧⓨⓩ';
$this->assertEqual($expected, $result);
$utf8 = array(11264, 11265, 11266, 11267, 11268, 11269, 11270, 11271, 11272, 11273, 11274, 11275, 11276, 11277, 11278, 11279,
11280, 11281, 11282, 11283, 11284, 11285, 11286, 11287, 11288, 11289, 11290, 11291, 11292, 11293, 11294, 11295,
11296, 11297, 11298, 11299, 11300, 11301, 11302, 11303, 11304, 11305, 11306, 11307, 11308, 11309, 11310);
$result = Multibyte::ascii($utf8);
$expected = 'ⰀⰁⰂⰃⰄⰅⰆⰇⰈⰉⰊⰋⰌⰍⰎⰏⰐⰑⰒⰓⰔⰕⰖⰗⰘⰙⰚⰛⰜⰝⰞⰟⰠⰡⰢⰣⰤⰥⰦⰧⰨⰩⰪⰫⰬⰭⰮ';
$this->assertEqual($expected, $result);
$utf8 = array(11312, 11313, 11314, 11315, 11316, 11317, 11318, 11319, 11320, 11321, 11322, 11323, 11324, 11325, 11326, 11327,
11328, 11329, 11330, 11331, 11332, 11333, 11334, 11335, 11336, 11337, 11338, 11339, 11340, 11341, 11342, 11343,
11344, 11345, 11346, 11347, 11348, 11349, 11350, 11351, 11352, 11353, 11354, 11355, 11356, 11357, 11358);
$result = Multibyte::ascii($utf8);
$expected = 'ⰰⰱⰲⰳⰴⰵⰶⰷⰸⰹⰺⰻⰼⰽⰾⰿⱀⱁⱂⱃⱄⱅⱆⱇⱈⱉⱊⱋⱌⱍⱎⱏⱐⱑⱒⱓⱔⱕⱖⱗⱘⱙⱚⱛⱜⱝⱞ';
$this->assertEqual($expected, $result);
$utf8 = array(11392, 11394, 11396, 11398, 11400, 11402, 11404, 11406, 11408, 11410, 11412, 11414, 11416, 11418, 11420,
11422, 11424, 11426, 11428, 11430, 11432, 11434, 11436, 11438, 11440, 11442, 11444, 11446, 11448, 11450,
11452, 11454, 11456, 11458, 11460, 11462, 11464, 11466, 11468, 11470, 11472, 11474, 11476, 11478, 11480,
11482, 11484, 11486, 11488, 11490);
$result = Multibyte::ascii($utf8);
$expected = 'ⲀⲂⲄⲆⲈⲊⲌⲎⲐⲒⲔⲖⲘⲚⲜⲞⲠⲢⲤⲦⲨⲪⲬⲮⲰⲲⲴⲶⲸⲺⲼⲾⳀⳂⳄⳆⳈⳊⳌⳎⳐⳒⳔⳖⳘⳚⳜⳞⳠⳢ';
$this->assertEqual($expected, $result);
$utf8 = array(11393, 11395, 11397, 11399, 11401, 11403, 11405, 11407, 11409, 11411, 11413, 11415, 11417, 11419, 11421, 11423,
11425, 11427, 11429, 11431, 11433, 11435, 11437, 11439, 11441, 11443, 11445, 11447, 11449, 11451, 11453, 11455,
11457, 11459, 11461, 11463, 11465, 11467, 11469, 11471, 11473, 11475, 11477, 11479, 11481, 11483, 11485, 11487,
11489, 11491);
$result = Multibyte::ascii($utf8);
$expected = 'ⲁⲃⲅⲇⲉⲋⲍⲏⲑⲓⲕⲗⲙⲛⲝⲟⲡⲣⲥⲧⲩⲫⲭⲯⲱⲳⲵⲷⲹⲻⲽⲿⳁⳃⳅⳇⳉⳋⳍⳏⳑⳓⳕⳗⳙⳛⳝⳟⳡⳣ';
$this->assertEqual($expected, $result);
$utf8 = array(64256, 64257, 64258, 64259, 64260, 64261, 64262, 64275, 64276, 64277, 64278, 64279);
$result = Multibyte::ascii($utf8);
$expected = 'fffiflffifflſtstﬓﬔﬕﬖﬗ';
$this->assertEqual($expected, $result);
}
/**
* testUsingMbStripos method
*
* @return void
*/
public function testUsingMbStripos() {
$string = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
$find = 'f';
$result = mb_stripos($string, $find);
$expected = 5;
$this->assertEqual($expected, $result);
$string = 'ABCDEFGHIJKLMNOPQFRSTUVWXYZ0123456789';
$find = 'f';
$result = mb_stripos($string, $find, 6);
$expected = 17;
$this->assertEqual($expected, $result);
$string = 'ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞ';
$find = 'å';
$result = mb_stripos($string, $find);
$expected = 5;
$this->assertEqual($expected, $result);
$string = 'ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÅÙÚÛÜÝÞ';
$find = 'å';
$result = mb_stripos($string, $find, 6);
$expected = 24;
$this->assertEqual($expected, $result);
$string = 'ĀĂĄĆĈĊČĎĐĒĔĖĘĚĜĞĠĢĤĦĨĪĬĮIJĴĶĹĻĽĿŁŃŅŇŊŌŎŐŒŔŖŘŚŜŞŠŢŤŦŨŪŬŮŰŲŴŶŹŻŽ';
$find = 'ċ';
$result = mb_stripos($string, $find);
$expected = 5;
$this->assertEqual($expected, $result);
$string = 'ĀĂĄĆĈĊČĎĐĒĔĖĘĚĜĞĠĢĤĦĨĪĬĮIJĴĶĹĻĽĿŁĊŃŅŇŊŌŎŐŒŔŖŘŚŜŞŠŢŤŦŨŪŬŮŰŲŴŶŹŻŽ';
$find = 'ċ';
$result = mb_stripos($string, $find, 6);
$expected = 32;
$this->assertEqual($expected, $result);
$string = '!"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~';
$find = 'f';
$result = mb_stripos($string, $find);
$expected = 37;
$this->assertEqual($expected, $result);
$string = '¡¢£¤¥¦§¨©ª«¬®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈ';
$find = 'Μ';
$result = mb_stripos($string, $find);
$expected = 20;
$this->assertEqual($expected, $result);
$string = 'ÉÊËÌÍÎÏÐÑÒÓÔÕÖרÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿĀāĂ㥹ĆćĈĉĊċČčĎďĐđĒēĔĕĖėĘęĚěĜĝĞğĠġĢģĤĥĦħĨĩĪīĬ';
$find = 'É';
$result = mb_stripos($string, $find, 6);
$expected = 32;
$this->assertEqual($expected, $result);
$string = 'ĭĮįİıIJijĴĵĶķĸĹĺĻļĽľĿŀŁłŃńŅņŇňʼnŊŋŌōŎŏŐőŒœŔŕŖŗŘřŚśŜŝŞşŠšŢţŤťŦŧŨũŪūŬŭŮůŰűŲųŴŵŶŷŸŹźŻżŽžſƀƁƂƃƄƅƆƇƈƉƊƋƌƍƎƏƐ';
$find = 'Ņ';
$result = mb_stripos($string, $find);
$expected = 24;
$this->assertEqual($expected, $result);
$string = 'ƑƒƓƔƕƖƗƘƙƚƛƜƝƞƟƠơƢƣƤƥƦƧƨƩƪƫƬƭƮƯưƱƲƳƴƵƶƷƸƹƺƻƼƽƾƿǀǁǂǃDŽDždžLJLjljNJNjnjǍǎǏǐǑǒǓǔǕǖǗǘǙǚǛǜǝǞǟǠǡǢǣǤǥǦǧǨǩǪǫǬǭǮǯǰDZDzdzǴ';
$find = 'Ƹ';
$result = mb_stripos($string, $find);
$expected = 39;
$this->assertEqual($expected, $result);
$string = 'ƑƒƓƔƕƖƗƘƙƚƛƜƝƞƟƠơƢƣƤƥƦƧƨƩƪƫƬƭƮƯưƱƲƳƴƵƶƷƸƹƺƻƼƽƾƿǀǁǂǃDŽDždžLJLjljNJNjnjǍǎǏǐǑǒǓǔǕǖǗǘǙǚǛǜǝǞǟǠǡǢǣǤǥǦǧǨǩǪǫǬǭǮǯǰDZDzdzǴ';
$find = 'Ƹ';
$result = mb_stripos($string, $find, 40);
$expected = 40;
$this->assertEqual($expected, $result);
$string = 'əɚɛɜɝɞɟɠɡɢɣɤɥɦɧɨɩɪɫɬɭɮɯɰɱɲɳɴɵɶɷɸɹɺɻɼɽɾɿʀʁʂʃʄʅʆʇʈʉʊʋʌʍʎʏʐʑʒʓʔʕʖʗʘʙʚʛʜʝʞʟʠʡʢʣʤʥʦʧʨʩʪʫʬʭʮʯʰʱʲʳʴʵʶʷʸʹʺʻʼ';
$find = 'Ʀ';
$result = mb_stripos($string, $find);
$expected = 39;
$this->assertEqual($expected, $result);
$string = 'ЀЁЂЃЄЅІЇЈЉЊЋЌЍЎЏАБВГДЕЖЗИЙКЛ';
$find = 'ї';
$result = mb_stripos($string, $find);
$expected = 7;
$this->assertEqual($expected, $result);
$string = 'МНОПРСТУФХЦЧШЩЪЫЬЭЮЯабвгдежзийклмнопрстуфхцчшщъыь';
$find = 'Р';
$result = mb_stripos($string, $find);
$expected = 4;
$this->assertEqual($expected, $result);
$string = 'МНОПРСТУФХЦЧШЩЪЫЬЭЮЯабвгдежзийклмнопрстуфхцчшщъыь';
$find = 'Р';
$result = mb_stripos($string, $find, 5);
$expected = 36;
$this->assertEqual($expected, $result);
$string = 'فقكلمنهوىيًٌٍَُ';
$find = 'ن';
$result = mb_stripos($string, $find);
$expected = 5;
$this->assertEqual($expected, $result);
$string = '✰✱✲✳✴✵✶✷✸✹✺✻✼✽✾✿❀❁❂❃❄❅❆❇❈❉❊❋❌❍❎❏❐❑❒❓❔❕❖❗❘❙❚❛❜❝❞';
$find = '✿';
$result = mb_stripos($string, $find);
$expected = 15;
$this->assertEqual($expected, $result);
$string = '⺀⺁⺂⺃⺄⺅⺆⺇⺈⺉⺊⺋⺌⺍⺎⺏⺐⺑⺒⺓⺔⺕⺖⺗⺘⺙⺛⺜⺝⺞⺟⺠⺡⺢⺣⺤⺥⺦⺧⺨⺩⺪⺫⺬⺭⺮⺯⺰⺱⺲⺳⺴⺵⺶⺷⺸⺹⺺⺻⺼⺽⺾⺿⻀⻁⻂⻃⻄⻅⻆⻇⻈⻉⻊⻋⻌⻍⻎⻏⻐⻑⻒⻓⻔⻕⻖⻗⻘⻙⻚⻛⻜⻝⻞⻟⻠';
$find = '⺐';
$result = mb_stripos($string, $find);
$expected = 16;
$this->assertEqual($expected, $result);
$string = '⽅⽆⽇⽈⽉⽊⽋⽌⽍⽎⽏⽐⽑⽒⽓⽔⽕⽖⽗⽘⽙⽚⽛⽜⽝⽞⽟⽠⽡⽢⽣⽤⽥⽦⽧⽨⽩⽪⽫⽬⽭⽮⽯⽰⽱⽲⽳⽴⽵⽶⽷⽸⽹⽺⽻⽼⽽⽾⽿';
$find = '⽤';
$result = mb_stripos($string, $find);
$expected = 31;
$this->assertEqual($expected, $result);
$string = '눡눢눣눤눥눦눧눨눩눪눫눬눭눮눯눰눱눲눳눴눵눶눷눸눹눺눻눼눽눾눿뉀뉁뉂뉃뉄뉅뉆뉇뉈뉉뉊뉋뉌뉍뉎뉏뉐뉑뉒뉓뉔뉕뉖뉗뉘뉙뉚뉛뉜뉝뉞뉟뉠뉡뉢뉣뉤뉥뉦뉧뉨뉩뉪뉫뉬뉭뉮뉯뉰뉱뉲뉳뉴뉵뉶뉷뉸뉹뉺뉻뉼뉽뉾뉿늀늁늂늃늄';
$find = '눻';
$result = mb_stripos($string, $find);
$expected = 26;
$this->assertEqual($expected, $result);
$string = 'ﹰﹱﹲﹳﹴﹶﹷﹸﹹﹺﹻﹼﹽﹾﹿﺀﺁﺂﺃﺄﺅﺆﺇﺈﺉﺊﺋﺌﺍﺎﺏﺐﺑﺒﺓﺔﺕﺖﺗﺘﺙﺚﺛﺜﺝﺞﺟﺠﺡﺢﺣﺤﺥﺦﺧﺨﺩﺪﺫﺬﺭﺮﺯﺰ';
$find = 'ﺞ';
$result = mb_stripos($string, $find);
$expected = 46;
$this->assertEqual($expected, $result);
$string = 'ﺱﺲﺳﺴﺵﺶﺷﺸﺹﺺﺻﺼﺽﺾﺿﻀﻁﻂﻃﻄﻅﻆﻇﻈﻉﻊﻋﻌﻍﻎﻏﻐﻑﻒﻓﻔﻕﻖﻗﻘﻙﻚﻛﻜﻝﻞﻟﻠﻡﻢﻣﻤﻥﻦﻧﻨﻩﻪﻫﻬﻭﻮﻯﻰﻱﻲﻳﻴﻵﻶﻷﻸﻹﻺﻻﻼ';
$find = 'ﻞ';
$result = mb_stripos($string, $find);
$expected = 45;
$this->assertEqual($expected, $result);
$string = 'abcdefghijklmnopqrstuvwxyz';
$find = 'k';
$result = mb_stripos($string, $find);
$expected = 10;
$this->assertEqual($expected, $result);
$string = 'abcdefghijklmnopqrstuvwxyz';
$find = 'K';
$result = mb_stripos($string, $find);
$expected = 10;
$this->assertEqual($expected, $result);
$string = '。「」、・ヲァィゥェォャュョッーアイウエオカキク';
$find = 'ア';
$result = mb_stripos($string, $find);
$expected = 16;
$this->assertEqual($expected, $result);
$string = 'ケコサシスセソタチツテトナニヌネノハヒフヘホマミムメモヤユヨラリルレロワン゙';
$find = 'ハ';
$result = mb_stripos($string, $find);
$expected = 17;
$this->assertEqual($expected, $result);
$string = 'Ĥēĺļŏ, Ŵőřļď!';
$find = 'ő';
$result = mb_stripos($string, $find);
$expected = 8;
$this->assertEqual($expected, $result);
$string = 'Ĥēĺļŏ, Ŵőřļď!';
$find = 'Ő';
$result = mb_stripos($string, $find);
$expected = 8;
$this->assertEqual($expected, $result);
$string = 'Hello, World!';
$find = 'O';
$result = mb_stripos($string, $find);
$expected = 4;
$this->assertEqual($expected, $result);
$string = 'Hello, World!';
$find = 'o';
$result = mb_stripos($string, $find);
$expected = 4;
$this->assertEqual($expected, $result);
$string = 'čini';
$find = 'n';
$result = mb_stripos($string, $find);
$expected = 2;
$this->assertEqual($expected, $result);
$string = 'čini';
$find = 'N';
$result = mb_stripos($string, $find);
$expected = 2;
$this->assertEqual($expected, $result);
$string = 'moći';
$find = 'ć';
$result = mb_stripos($string, $find);
$expected = 2;
$this->assertEqual($expected, $result);
$string = 'moći';
$find = 'Ć';
$result = mb_stripos($string, $find);
$expected = 2;
$this->assertEqual($expected, $result);
$string = 'državni';
$find = 'ž';
$result = mb_stripos($string, $find);
$expected = 2;
$this->assertEqual($expected, $result);
$string = 'državni';
$find = 'Ž';
$result = mb_stripos($string, $find);
$expected = 2;
$this->assertEqual($expected, $result);
$string = '把百度设为首页';
$find = '设';
$result = mb_stripos($string, $find);
$expected = 3;
$this->assertEqual($expected, $result);
$string = '一二三周永龍';
$find = '周';
$result = mb_stripos($string, $find);
$expected = 3;
$this->assertEqual($expected, $result);
$string = 'državni';
$find = 'DŽ';
$result = mb_stripos($string, $find);
$expected = false;
$this->assertEqual($expected, $result);
}
/**
* testMultibyteStripos method
*
* @return void
*/
public function testMultibyteStripos() {
$string = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
$find = 'f';
$result = Multibyte::stripos($string, $find);
$expected = 5;
$this->assertEqual($expected, $result);
$string = 'ABCDEFGHIJKLMNOPQFRSTUVWXYZ0123456789';
$find = 'f';
$result = Multibyte::stripos($string, $find, 6);
$expected = 17;
$this->assertEqual($expected, $result);
$string = 'ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞ';
$find = 'å';
$result = Multibyte::stripos($string, $find);
$expected = 5;
$this->assertEqual($expected, $result);
$string = 'ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÅÙÚÛÜÝÞ';
$find = 'å';
$result = Multibyte::stripos($string, $find, 6);
$expected = 24;
$this->assertEqual($expected, $result);
$string = 'ĀĂĄĆĈĊČĎĐĒĔĖĘĚĜĞĠĢĤĦĨĪĬĮIJĴĶĹĻĽĿŁŃŅŇŊŌŎŐŒŔŖŘŚŜŞŠŢŤŦŨŪŬŮŰŲŴŶŹŻŽ';
$find = 'ċ';
$result = Multibyte::stripos($string, $find);
$expected = 5;
$this->assertEqual($expected, $result);
$string = 'ĀĂĄĆĈĊČĎĐĒĔĖĘĚĜĞĠĢĤĦĨĪĬĮIJĴĶĹĻĽĿŁĊŃŅŇŊŌŎŐŒŔŖŘŚŜŞŠŢŤŦŨŪŬŮŰŲŴŶŹŻŽ';
$find = 'ċ';
$result = Multibyte::stripos($string, $find, 6);
$expected = 32;
$this->assertEqual($expected, $result);
$string = '!"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~';
$find = 'f';
$result = Multibyte::stripos($string, $find);
$expected = 37;
$this->assertEqual($expected, $result);
$string = '¡¢£¤¥¦§¨©ª«¬®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈ';
$find = 'Μ';
$result = Multibyte::stripos($string, $find);
$expected = 20;
$this->assertEqual($expected, $result);
$string = 'ÉÊËÌÍÎÏÐÑÒÓÔÕÖרÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿĀāĂ㥹ĆćĈĉĊċČčĎďĐđĒēĔĕĖėĘęĚěĜĝĞğĠġĢģĤĥĦħĨĩĪīĬ';
$find = 'É';
$result = Multibyte::stripos($string, $find, 6);
$expected = 32;
$this->assertEqual($expected, $result);
$string = 'ĭĮįİıIJijĴĵĶķĸĹĺĻļĽľĿŀŁłŃńŅņŇňʼnŊŋŌōŎŏŐőŒœŔŕŖŗŘřŚśŜŝŞşŠšŢţŤťŦŧŨũŪūŬŭŮůŰűŲųŴŵŶŷŸŹźŻżŽžſƀƁƂƃƄƅƆƇƈƉƊƋƌƍƎƏƐ';
$find = 'Ņ';
$result = Multibyte::stripos($string, $find);
$expected = 24;
$this->assertEqual($expected, $result);
$string = 'ƑƒƓƔƕƖƗƘƙƚƛƜƝƞƟƠơƢƣƤƥƦƧƨƩƪƫƬƭƮƯưƱƲƳƴƵƶƷƸƹƺƻƼƽƾƿǀǁǂǃDŽDždžLJLjljNJNjnjǍǎǏǐǑǒǓǔǕǖǗǘǙǚǛǜǝǞǟǠǡǢǣǤǥǦǧǨǩǪǫǬǭǮǯǰDZDzdzǴ';
$find = 'Ƹ';
$result = Multibyte::stripos($string, $find);
$expected = 39;
$this->assertEqual($expected, $result);
$string = 'ƑƒƓƔƕƖƗƘƙƚƛƜƝƞƟƠơƢƣƤƥƦƧƨƩƪƫƬƭƮƯưƱƲƳƴƵƶƷƸƹƺƻƼƽƾƿǀǁǂǃDŽDždžLJLjljNJNjnjǍǎǏǐǑǒǓǔǕǖǗǘǙǚǛǜǝǞǟǠǡǢǣǤǥǦǧǨǩǪǫǬǭǮǯǰDZDzdzǴ';
$find = 'Ƹ';
$result = Multibyte::stripos($string, $find, 40);
$expected = 40;
$this->assertEqual($expected, $result);
$string = 'əɚɛɜɝɞɟɠɡɢɣɤɥɦɧɨɩɪɫɬɭɮɯɰɱɲɳɴɵɶɷɸɹɺɻɼɽɾɿʀʁʂʃʄʅʆʇʈʉʊʋʌʍʎʏʐʑʒʓʔʕʖʗʘʙʚʛʜʝʞʟʠʡʢʣʤʥʦʧʨʩʪʫʬʭʮʯʰʱʲʳʴʵʶʷʸʹʺʻʼ';
$find = 'Ʀ';
$result = Multibyte::stripos($string, $find);
$expected = 39;
$this->assertEqual($expected, $result);
$string = 'ЀЁЂЃЄЅІЇЈЉЊЋЌЍЎЏАБВГДЕЖЗИЙКЛ';
$find = 'ї';
$result = Multibyte::stripos($string, $find);
$expected = 7;
$this->assertEqual($expected, $result);
$string = 'МНОПРСТУФХЦЧШЩЪЫЬЭЮЯабвгдежзийклмнопрстуфхцчшщъыь';
$find = 'Р';
$result = Multibyte::stripos($string, $find);
$expected = 4;
$this->assertEqual($expected, $result);
$string = 'МНОПРСТУФХЦЧШЩЪЫЬЭЮЯабвгдежзийклмнопрстуфхцчшщъыь';
$find = 'Р';
$result = Multibyte::stripos($string, $find, 5);
$expected = 36;
$this->assertEqual($expected, $result);
$string = 'فقكلمنهوىيًٌٍَُ';
$find = 'ن';
$result = Multibyte::stripos($string, $find);
$expected = 5;
$this->assertEqual($expected, $result);
$string = '✰✱✲✳✴✵✶✷✸✹✺✻✼✽✾✿❀❁❂❃❄❅❆❇❈❉❊❋❌❍❎❏❐❑❒❓❔❕❖❗❘❙❚❛❜❝❞';
$find = '✿';
$result = Multibyte::stripos($string, $find);
$expected = 15;
$this->assertEqual($expected, $result);
$string = '⺀⺁⺂⺃⺄⺅⺆⺇⺈⺉⺊⺋⺌⺍⺎⺏⺐⺑⺒⺓⺔⺕⺖⺗⺘⺙⺛⺜⺝⺞⺟⺠⺡⺢⺣⺤⺥⺦⺧⺨⺩⺪⺫⺬⺭⺮⺯⺰⺱⺲⺳⺴⺵⺶⺷⺸⺹⺺⺻⺼⺽⺾⺿⻀⻁⻂⻃⻄⻅⻆⻇⻈⻉⻊⻋⻌⻍⻎⻏⻐⻑⻒⻓⻔⻕⻖⻗⻘⻙⻚⻛⻜⻝⻞⻟⻠';
$find = '⺐';
$result = Multibyte::stripos($string, $find);
$expected = 16;
$this->assertEqual($expected, $result);
$string = '⽅⽆⽇⽈⽉⽊⽋⽌⽍⽎⽏⽐⽑⽒⽓⽔⽕⽖⽗⽘⽙⽚⽛⽜⽝⽞⽟⽠⽡⽢⽣⽤⽥⽦⽧⽨⽩⽪⽫⽬⽭⽮⽯⽰⽱⽲⽳⽴⽵⽶⽷⽸⽹⽺⽻⽼⽽⽾⽿';
$find = '⽤';
$result = Multibyte::stripos($string, $find);
$expected = 31;
$this->assertEqual($expected, $result);
$string = '눡눢눣눤눥눦눧눨눩눪눫눬눭눮눯눰눱눲눳눴눵눶눷눸눹눺눻눼눽눾눿뉀뉁뉂뉃뉄뉅뉆뉇뉈뉉뉊뉋뉌뉍뉎뉏뉐뉑뉒뉓뉔뉕뉖뉗뉘뉙뉚뉛뉜뉝뉞뉟뉠뉡뉢뉣뉤뉥뉦뉧뉨뉩뉪뉫뉬뉭뉮뉯뉰뉱뉲뉳뉴뉵뉶뉷뉸뉹뉺뉻뉼뉽뉾뉿늀늁늂늃늄';
$find = '눻';
$result = Multibyte::stripos($string, $find);
$expected = 26;
$this->assertEqual($expected, $result);
$string = 'ﹰﹱﹲﹳﹴﹶﹷﹸﹹﹺﹻﹼﹽﹾﹿﺀﺁﺂﺃﺄﺅﺆﺇﺈﺉﺊﺋﺌﺍﺎﺏﺐﺑﺒﺓﺔﺕﺖﺗﺘﺙﺚﺛﺜﺝﺞﺟﺠﺡﺢﺣﺤﺥﺦﺧﺨﺩﺪﺫﺬﺭﺮﺯﺰ';
$find = 'ﺞ';
$result = Multibyte::stripos($string, $find);
$expected = 46;
$this->assertEqual($expected, $result);
$string = 'ﺱﺲﺳﺴﺵﺶﺷﺸﺹﺺﺻﺼﺽﺾﺿﻀﻁﻂﻃﻄﻅﻆﻇﻈﻉﻊﻋﻌﻍﻎﻏﻐﻑﻒﻓﻔﻕﻖﻗﻘﻙﻚﻛﻜﻝﻞﻟﻠﻡﻢﻣﻤﻥﻦﻧﻨﻩﻪﻫﻬﻭﻮﻯﻰﻱﻲﻳﻴﻵﻶﻷﻸﻹﻺﻻﻼ';
$find = 'ﻞ';
$result = Multibyte::stripos($string, $find);
$expected = 45;
$this->assertEqual($expected, $result);
$string = 'abcdefghijklmnopqrstuvwxyz';
$find = 'k';
$result = Multibyte::stripos($string, $find);
$expected = 10;
$this->assertEqual($expected, $result);
$string = 'abcdefghijklmnopqrstuvwxyz';
$find = 'K';
$result = Multibyte::stripos($string, $find);
$expected = 10;
$this->assertEqual($expected, $result);
$string = '。「」、・ヲァィゥェォャュョッーアイウエオカキク';
$find = 'ア';
$result = Multibyte::stripos($string, $find);
$expected = 16;
$this->assertEqual($expected, $result);
$string = 'ケコサシスセソタチツテトナニヌネノハヒフヘホマミムメモヤユヨラリルレロワン゙';
$find = 'ハ';
$result = Multibyte::stripos($string, $find);
$expected = 17;
$this->assertEqual($expected, $result);
$string = 'Ĥēĺļŏ, Ŵőřļď!';
$find = 'ő';
$result = Multibyte::stripos($string, $find);
$expected = 8;
$this->assertEqual($expected, $result);
$string = 'Ĥēĺļŏ, Ŵőřļď!';
$find = 'Ő';
$result = Multibyte::stripos($string, $find);
$expected = 8;
$this->assertEqual($expected, $result);
$string = 'Hello, World!';
$find = 'O';
$result = Multibyte::stripos($string, $find);
$expected = 4;
$this->assertEqual($expected, $result);
$string = 'Hello, World!';
$find = 'o';
$result = Multibyte::stripos($string, $find);
$expected = 4;
$this->assertEqual($expected, $result);
$string = 'čini';
$find = 'n';
$result = Multibyte::stripos($string, $find);
$expected = 2;
$this->assertEqual($expected, $result);
$string = 'čini';
$find = 'N';
$result = Multibyte::stripos($string, $find);
$expected = 2;
$this->assertEqual($expected, $result);
$string = 'moći';
$find = 'ć';
$result = Multibyte::stripos($string, $find);
$expected = 2;
$this->assertEqual($expected, $result);
$string = 'moći';
$find = 'Ć';
$result = Multibyte::stripos($string, $find);
$expected = 2;
$this->assertEqual($expected, $result);
$string = 'državni';
$find = 'ž';
$result = Multibyte::stripos($string, $find);
$expected = 2;
$this->assertEqual($expected, $result);
$string = 'državni';
$find = 'Ž';
$result = Multibyte::stripos($string, $find);
$expected = 2;
$this->assertEqual($expected, $result);
$string = '把百度设为首页';
$find = '设';
$result = Multibyte::stripos($string, $find);
$expected = 3;
$this->assertEqual($expected, $result);
$string = '一二三周永龍';
$find = '周';
$result = Multibyte::stripos($string, $find);
$expected = 3;
$this->assertEqual($expected, $result);
$string = 'državni';
$find = 'DŽ';
$result = Multibyte::stripos($string, $find);
$expected = false;
$this->assertEqual($expected, $result);
}
/**
* testUsingMbStristr method
*
* @return void
*/
public function testUsingMbStristr() {
$string = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
$find = 'f';
$result = mb_stristr($string, $find);
$expected = 'FGHIJKLMNOPQRSTUVWXYZ0123456789';
$this->assertEqual($expected, $result);
$string = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
$find = 'f';
$result = mb_stristr($string, $find, true);
$expected = 'ABCDE';
$this->assertEqual($expected, $result);
$string = 'ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞ';
$find = 'å';
$result = mb_stristr($string, $find);
$expected = 'ÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞ';
$this->assertEqual($expected, $result);
$string = 'ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞ';
$find = 'å';
$result = mb_stristr($string, $find, true);
$expected = 'ÀÁÂÃÄ';
$this->assertEqual($expected, $result);
$string = 'ĀĂĄĆĈĊČĎĐĒĔĖĘĚĜĞĠĢĤĦĨĪĬĮIJĴĶĹĻĽĿŁŃŅŇŊŌŎŐŒŔŖŘŚŜŞŠŢŤŦŨŪŬŮŰŲŴŶŹŻŽ';
$find = 'ċ';
$result = mb_stristr($string, $find);
$expected = 'ĊČĎĐĒĔĖĘĚĜĞĠĢĤĦĨĪĬĮIJĴĶĹĻĽĿŁŃŅŇŊŌŎŐŒŔŖŘŚŜŞŠŢŤŦŨŪŬŮŰŲŴŶŹŻŽ';
$this->assertEqual($expected, $result);
$string = 'ĀĂĄĆĈĊČĎĐĒĔĖĘĚĜĞĠĢĤĦĨĪĬĮIJĴĶĹĻĽĿŁŃŅŇŊŌŎŐŒŔŖŘŚŜŞŠŢŤŦŨŪŬŮŰŲŴŶŹŻŽ';
$find = 'ċ';
$result = mb_stristr($string, $find, true);
$expected = 'ĀĂĄĆĈ';
$this->assertEqual($expected, $result);
$string = '!"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~';
$find = 'f';
$result = mb_stristr($string, $find);
$expected = 'FGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~';
$this->assertEqual($expected, $result);
$string = '!"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~';
$find = 'f';
$result = mb_stristr($string, $find, true);
$expected = '!"#$%&\'()*+,-./0123456789:;<=>?@ABCDE';
$this->assertEqual($expected, $result);
$string = '¡¢£¤¥¦§¨©ª«¬®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈ';
$find = 'Μ';
$result = mb_stristr($string, $find);
$expected = 'µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈ';
$this->assertEqual($expected, $result);
$string = '¡¢£¤¥¦§¨©ª«¬®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈ';
$find = 'Μ';
$result = mb_stristr($string, $find, true);
$expected = '¡¢£¤¥¦§¨©ª«¬®¯°±²³´';
$this->assertEqual($expected, $result);
$string = 'ÉÊËÌÍÎÏÐÑÒÓÔÕÖרÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿĀāĂ㥹ĆćĈĉĊċČčĎďĐđĒēĔĕĖėĘęĚěĜĝĞğĠġĢģĤĥĦħĨĩĪīĬ';
$find = 'þ';
$result = mb_stristr($string, $find);
$expected = 'Þßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿĀāĂ㥹ĆćĈĉĊċČčĎďĐđĒēĔĕĖėĘęĚěĜĝĞğĠġĢģĤĥĦħĨĩĪīĬ';
$this->assertEqual($expected, $result);
$string = 'ÉÊËÌÍÎÏÐÑÒÓÔÕÖרÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿĀāĂ㥹ĆćĈĉĊċČčĎďĐđĒēĔĕĖėĘęĚěĜĝĞğĠġĢģĤĥĦħĨĩĪīĬ';
$find = 'þ';
$result = mb_stristr($string, $find, true);
$expected = 'ÉÊËÌÍÎÏÐÑÒÓÔÕÖרÙÚÛÜÝ';
$this->assertEqual($expected, $result);
$string = 'ĭĮįİıIJijĴĵĶķĸĹĺĻļĽľĿŀŁłŃńŅņŇňʼnŊŋŌōŎŏŐőŒœŔŕŖŗŘřŚśŜŝŞşŠšŢţŤťŦŧŨũŪūŬŭŮůŰűŲųŴŵŶŷŸŹźŻżŽžſƀƁƂƃƄƅƆƇƈƉƊƋƌƍƎƏƐ';
$find = 'Ņ';
$result = mb_stristr($string, $find);
$expected = 'ŅņŇňʼnŊŋŌōŎŏŐőŒœŔŕŖŗŘřŚśŜŝŞşŠšŢţŤťŦŧŨũŪūŬŭŮůŰűŲųŴŵŶŷŸŹźŻżŽžſƀƁƂƃƄƅƆƇƈƉƊƋƌƍƎƏƐ';
$this->assertEqual($expected, $result);
$string = 'ĭĮįİıIJijĴĵĶķĸĹĺĻļĽľĿŀŁłŃńŅņŇňʼnŊŋŌōŎŏŐőŒœŔŕŖŗŘřŚśŜŝŞşŠšŢţŤťŦŧŨũŪūŬŭŮůŰűŲųŴŵŶŷŸŹźŻżŽžſƀƁƂƃƄƅƆƇƈƉƊƋƌƍƎƏƐ';
$find = 'Ņ';
$result = mb_stristr($string, $find, true);
$expected = 'ĭĮįİıIJijĴĵĶķĸĹĺĻļĽľĿŀŁłŃń';
$this->assertEqual($expected, $result);
$string = 'ƑƒƓƔƕƖƗƘƙƚƛƜƝƞƟƠơƢƣƤƥƦƧƨƩƪƫƬƭƮƯưƱƲƳƴƵƶƷƸƹƺƻƼƽƾƿǀǁǂǃDŽDždžLJLjljNJNjnjǍǎǏǐǑǒǓǔǕǖǗǘǙǚǛǜǝǞǟǠǡǢǣǤǥǦǧǨǩǪǫǬǭǮǯǰDZDzdzǴ';
$find = 'Ƹ';
$result = mb_stristr($string, $find);
$expected = 'ƸƹƺƻƼƽƾƿǀǁǂǃDŽDždžLJLjljNJNjnjǍǎǏǐǑǒǓǔǕǖǗǘǙǚǛǜǝǞǟǠǡǢǣǤǥǦǧǨǩǪǫǬǭǮǯǰDZDzdzǴ';
$this->assertEqual($expected, $result);
$find = 'Ƹ';
$result = mb_stristr($string, $find, true);
$expected = 'ƑƒƓƔƕƖƗƘƙƚƛƜƝƞƟƠơƢƣƤƥƦƧƨƩƪƫƬƭƮƯưƱƲƳƴƵƶƷ';
$this->assertEqual($expected, $result);
$string = 'əɚɛɜɝɞɟɠɡɢɣɤɥɦɧɨɩɪɫɬɭɮɯɰɱɲɳɴɵɶɷɸɹɺɻɼɽɾɿʀʁʂʃʄʅʆʇʈʉʊʋʌʍʎʏʐʑʒʓʔʕʖʗʘʙʚʛʜʝʞʟʠʡʢʣʤʥʦʧʨʩʪʫʬʭʮʯʰʱʲʳʴʵʶʷʸʹʺʻʼ';
$find = 'Ʀ';
$result = mb_stristr($string, $find);
$expected = 'ʀʁʂʃʄʅʆʇʈʉʊʋʌʍʎʏʐʑʒʓʔʕʖʗʘʙʚʛʜʝʞʟʠʡʢʣʤʥʦʧʨʩʪʫʬʭʮʯʰʱʲʳʴʵʶʷʸʹʺʻʼ';
$this->assertEqual($expected, $result);
$string = 'əɚɛɜɝɞɟɠɡɢɣɤɥɦɧɨɩɪɫɬɭɮɯɰɱɲɳɴɵɶɷɸɹɺɻɼɽɾɿʀʁʂʃʄʅʆʇʈʉʊʋʌʍʎʏʐʑʒʓʔʕʖʗʘʙʚʛʜʝʞʟʠʡʢʣʤʥʦʧʨʩʪʫʬʭʮʯʰʱʲʳʴʵʶʷʸʹʺʻʼ';
$find = 'Ʀ';
$result = mb_stristr($string, $find, true);
$expected = 'əɚɛɜɝɞɟɠɡɢɣɤɥɦɧɨɩɪɫɬɭɮɯɰɱɲɳɴɵɶɷɸɹɺɻɼɽɾɿ';
$this->assertEqual($expected, $result);
$string = 'ЀЁЂЃЄЅІЇЈЉЊЋЌЍЎЏАБВГДЕЖЗИЙКЛ';
$find = 'ї';
$result = mb_stristr($string, $find);
$expected = 'ЇЈЉЊЋЌЍЎЏАБВГДЕЖЗИЙКЛ';
$this->assertEqual($expected, $result);
$string = 'ЀЁЂЃЄЅІЇЈЉЊЋЌЍЎЏАБВГДЕЖЗИЙКЛ';
$find = 'ї';
$result = mb_stristr($string, $find, true);
$expected = 'ЀЁЂЃЄЅІ';
$this->assertEqual($expected, $result);
$string = 'МНОПРСТУФХЦЧШЩЪЫЬЭЮЯабвгдежзийклмнопрстуфхцчшщъыь';
$find = 'Р';
$result = mb_stristr($string, $find);
$expected = 'РСТУФХЦЧШЩЪЫЬЭЮЯабвгдежзийклмнопрстуфхцчшщъыь';
$this->assertEqual($expected, $result);
$string = 'МНОПРСТУФХЦЧШЩЪЫЬЭЮЯабвгдежзийклмнопрстуфхцчшщъыь';
$find = 'Р';
$result = mb_stristr($string, $find, true);
$expected = 'МНОП';
$this->assertEqual($expected, $result);
$string = 'فقكلمنهوىيًٌٍَُ';
$find = 'ن';
$result = mb_stristr($string, $find);
$expected = 'نهوىيًٌٍَُ';
$this->assertEqual($expected, $result);
$string = 'فقكلمنهوىيًٌٍَُ';
$find = 'ن';
$result = mb_stristr($string, $find, true);
$expected = 'فقكلم';
$this->assertEqual($expected, $result);
$string = '✰✱✲✳✴✵✶✷✸✹✺✻✼✽✾✿❀❁❂❃❄❅❆❇❈❉❊❋❌❍❎❏❐❑❒❓❔❕❖❗❘❙❚❛❜❝❞';
$find = '✿';
$result = mb_stristr($string, $find);
$expected = '✿❀❁❂❃❄❅❆❇❈❉❊❋❌❍❎❏❐❑❒❓❔❕❖❗❘❙❚❛❜❝❞';
$this->assertEqual($expected, $result);
$string = '✰✱✲✳✴✵✶✷✸✹✺✻✼✽✾✿❀❁❂❃❄❅❆❇❈❉❊❋❌❍❎❏❐❑❒❓❔❕❖❗❘❙❚❛❜❝❞';
$find = '✿';
$result = mb_stristr($string, $find, true);
$expected = '✰✱✲✳✴✵✶✷✸✹✺✻✼✽✾';
$this->assertEqual($expected, $result);
$string = '⺀⺁⺂⺃⺄⺅⺆⺇⺈⺉⺊⺋⺌⺍⺎⺏⺐⺑⺒⺓⺔⺕⺖⺗⺘⺙⺛⺜⺝⺞⺟⺠⺡⺢⺣⺤⺥⺦⺧⺨⺩⺪⺫⺬⺭⺮⺯⺰⺱⺲⺳⺴⺵⺶⺷⺸⺹⺺⺻⺼⺽⺾⺿⻀⻁⻂⻃⻄⻅⻆⻇⻈⻉⻊⻋⻌⻍⻎⻏⻐⻑⻒⻓⻔⻕⻖⻗⻘⻙⻚⻛⻜⻝⻞⻟⻠';
$find = '⺐';
$result = mb_stristr($string, $find);
$expected = '⺐⺑⺒⺓⺔⺕⺖⺗⺘⺙⺛⺜⺝⺞⺟⺠⺡⺢⺣⺤⺥⺦⺧⺨⺩⺪⺫⺬⺭⺮⺯⺰⺱⺲⺳⺴⺵⺶⺷⺸⺹⺺⺻⺼⺽⺾⺿⻀⻁⻂⻃⻄⻅⻆⻇⻈⻉⻊⻋⻌⻍⻎⻏⻐⻑⻒⻓⻔⻕⻖⻗⻘⻙⻚⻛⻜⻝⻞⻟⻠';
$this->assertEqual($expected, $result);
$string = '⺀⺁⺂⺃⺄⺅⺆⺇⺈⺉⺊⺋⺌⺍⺎⺏⺐⺑⺒⺓⺔⺕⺖⺗⺘⺙⺛⺜⺝⺞⺟⺠⺡⺢⺣⺤⺥⺦⺧⺨⺩⺪⺫⺬⺭⺮⺯⺰⺱⺲⺳⺴⺵⺶⺷⺸⺹⺺⺻⺼⺽⺾⺿⻀⻁⻂⻃⻄⻅⻆⻇⻈⻉⻊⻋⻌⻍⻎⻏⻐⻑⻒⻓⻔⻕⻖⻗⻘⻙⻚⻛⻜⻝⻞⻟⻠';
$find = '⺐';
$result = mb_stristr($string, $find, true);
$expected = '⺀⺁⺂⺃⺄⺅⺆⺇⺈⺉⺊⺋⺌⺍⺎⺏';
$this->assertEqual($expected, $result);
$string = '⽅⽆⽇⽈⽉⽊⽋⽌⽍⽎⽏⽐⽑⽒⽓⽔⽕⽖⽗⽘⽙⽚⽛⽜⽝⽞⽟⽠⽡⽢⽣⽤⽥⽦⽧⽨⽩⽪⽫⽬⽭⽮⽯⽰⽱⽲⽳⽴⽵⽶⽷⽸⽹⽺⽻⽼⽽⽾⽿';
$find = '⽤';
$result = mb_stristr($string, $find);
$expected = '⽤⽥⽦⽧⽨⽩⽪⽫⽬⽭⽮⽯⽰⽱⽲⽳⽴⽵⽶⽷⽸⽹⽺⽻⽼⽽⽾⽿';
$this->assertEqual($expected, $result);
$string = '⽅⽆⽇⽈⽉⽊⽋⽌⽍⽎⽏⽐⽑⽒⽓⽔⽕⽖⽗⽘⽙⽚⽛⽜⽝⽞⽟⽠⽡⽢⽣⽤⽥⽦⽧⽨⽩⽪⽫⽬⽭⽮⽯⽰⽱⽲⽳⽴⽵⽶⽷⽸⽹⽺⽻⽼⽽⽾⽿';
$find = '⽤';
$result = mb_stristr($string, $find, true);
$expected = '⽅⽆⽇⽈⽉⽊⽋⽌⽍⽎⽏⽐⽑⽒⽓⽔⽕⽖⽗⽘⽙⽚⽛⽜⽝⽞⽟⽠⽡⽢⽣';
$this->assertEqual($expected, $result);
$string = '눡눢눣눤눥눦눧눨눩눪눫눬눭눮눯눰눱눲눳눴눵눶눷눸눹눺눻눼눽눾눿뉀뉁뉂뉃뉄뉅뉆뉇뉈뉉뉊뉋뉌뉍뉎뉏뉐뉑뉒뉓뉔뉕뉖뉗뉘뉙뉚뉛뉜뉝뉞뉟뉠뉡뉢뉣뉤뉥뉦뉧뉨뉩뉪뉫뉬뉭뉮뉯뉰뉱뉲뉳뉴뉵뉶뉷뉸뉹뉺뉻뉼뉽뉾뉿늀늁늂늃늄';
$find = '눻';
$result = mb_stristr($string, $find);
$expected = '눻눼눽눾눿뉀뉁뉂뉃뉄뉅뉆뉇뉈뉉뉊뉋뉌뉍뉎뉏뉐뉑뉒뉓뉔뉕뉖뉗뉘뉙뉚뉛뉜뉝뉞뉟뉠뉡뉢뉣뉤뉥뉦뉧뉨뉩뉪뉫뉬뉭뉮뉯뉰뉱뉲뉳뉴뉵뉶뉷뉸뉹뉺뉻뉼뉽뉾뉿늀늁늂늃늄';
$this->assertEqual($expected, $result);
$string = '눡눢눣눤눥눦눧눨눩눪눫눬눭눮눯눰눱눲눳눴눵눶눷눸눹눺눻눼눽눾눿뉀뉁뉂뉃뉄뉅뉆뉇뉈뉉뉊뉋뉌뉍뉎뉏뉐뉑뉒뉓뉔뉕뉖뉗뉘뉙뉚뉛뉜뉝뉞뉟뉠뉡뉢뉣뉤뉥뉦뉧뉨뉩뉪뉫뉬뉭뉮뉯뉰뉱뉲뉳뉴뉵뉶뉷뉸뉹뉺뉻뉼뉽뉾뉿늀늁늂늃늄';
$find = '눻';
$result = mb_stristr($string, $find, true);
$expected = '눡눢눣눤눥눦눧눨눩눪눫눬눭눮눯눰눱눲눳눴눵눶눷눸눹눺';
$this->assertEqual($expected, $result);
$string = 'ﹰﹱﹲﹳﹴﹶﹷﹸﹹﹺﹻﹼﹽﹾﹿﺀﺁﺂﺃﺄﺅﺆﺇﺈﺉﺊﺋﺌﺍﺎﺏﺐﺑﺒﺓﺔﺕﺖﺗﺘﺙﺚﺛﺜﺝﺞﺟﺠﺡﺢﺣﺤﺥﺦﺧﺨﺩﺪﺫﺬﺭﺮﺯﺰ';
$find = 'ﺞ';
$result = mb_stristr($string, $find);
$expected = 'ﺞﺟﺠﺡﺢﺣﺤﺥﺦﺧﺨﺩﺪﺫﺬﺭﺮﺯﺰ';
$this->assertEqual($expected, $result);
$string = 'ﹰﹱﹲﹳﹴﹶﹷﹸﹹﹺﹻﹼﹽﹾﹿﺀﺁﺂﺃﺄﺅﺆﺇﺈﺉﺊﺋﺌﺍﺎﺏﺐﺑﺒﺓﺔﺕﺖﺗﺘﺙﺚﺛﺜﺝﺞﺟﺠﺡﺢﺣﺤﺥﺦﺧﺨﺩﺪﺫﺬﺭﺮﺯﺰ';
$find = 'ﺞ';
$result = mb_stristr($string, $find, true);
$expected = 'ﹰﹱﹲﹳﹴﹶﹷﹸﹹﹺﹻﹼﹽﹾﹿﺀﺁﺂﺃﺄﺅﺆﺇﺈﺉﺊﺋﺌﺍﺎﺏﺐﺑﺒﺓﺔﺕﺖﺗﺘﺙﺚﺛﺜﺝ';
$this->assertEqual($expected, $result);
$string = 'ﺱﺲﺳﺴﺵﺶﺷﺸﺹﺺﺻﺼﺽﺾﺿﻀﻁﻂﻃﻄﻅﻆﻇﻈﻉﻊﻋﻌﻍﻎﻏﻐﻑﻒﻓﻔﻕﻖﻗﻘﻙﻚﻛﻜﻝﻞﻟﻠﻡﻢﻣﻤﻥﻦﻧﻨﻩﻪﻫﻬﻭﻮﻯﻰﻱﻲﻳﻴﻵﻶﻷﻸﻹﻺﻻﻼ';
$find = 'ﻞ';
$result = mb_stristr($string, $find);
$expected = 'ﻞﻟﻠﻡﻢﻣﻤﻥﻦﻧﻨﻩﻪﻫﻬﻭﻮﻯﻰﻱﻲﻳﻴﻵﻶﻷﻸﻹﻺﻻﻼ';
$this->assertEqual($expected, $result);
$string = 'ﺱﺲﺳﺴﺵﺶﺷﺸﺹﺺﺻﺼﺽﺾﺿﻀﻁﻂﻃﻄﻅﻆﻇﻈﻉﻊﻋﻌﻍﻎﻏﻐﻑﻒﻓﻔﻕﻖﻗﻘﻙﻚﻛﻜﻝﻞﻟﻠﻡﻢﻣﻤﻥﻦﻧﻨﻩﻪﻫﻬﻭﻮﻯﻰﻱﻲﻳﻴﻵﻶﻷﻸﻹﻺﻻﻼ';
$find = 'ﻞ';
$result = mb_stristr($string, $find, true);
$expected = 'ﺱﺲﺳﺴﺵﺶﺷﺸﺹﺺﺻﺼﺽﺾﺿﻀﻁﻂﻃﻄﻅﻆﻇﻈﻉﻊﻋﻌﻍﻎﻏﻐﻑﻒﻓﻔﻕﻖﻗﻘﻙﻚﻛﻜﻝ';
$this->assertEqual($expected, $result);
$string = 'abcdefghijklmnopqrstuvwxyz';
$find = 'K';
$result = mb_stristr($string, $find);
$expected = 'klmnopqrstuvwxyz';
$this->assertEqual($expected, $result);
$string = 'abcdefghijklmnopqrstuvwxyz';
$find = 'K';
$result = mb_stristr($string, $find, true);
$expected = 'abcdefghij';
$this->assertEqual($expected, $result);
$string = '。「」、・ヲァィゥェォャュョッーアイウエオカキク';
$find = 'ア';
$result = mb_stristr($string, $find);
$expected = 'アイウエオカキク';
$this->assertEqual($expected, $result);
$string = '。「」、・ヲァィゥェォャュョッーアイウエオカキク';
$find = 'ア';
$result = mb_stristr($string, $find, true);
$expected = '。「」、・ヲァィゥェォャュョッー';
$this->assertEqual($expected, $result);
$string = 'ケコサシスセソタチツテトナニヌネノハヒフヘホマミムメモヤユヨラリルレロワン゙';
$find = 'ハ';
$result = mb_stristr($string, $find);
$expected = 'ハヒフヘホマミムメモヤユヨラリルレロワン゙';
$this->assertEqual($expected, $result);
$string = 'ケコサシスセソタチツテトナニヌネノハヒフヘホマミムメモヤユヨラリルレロワン゙';
$find = 'ハ';
$result = mb_stristr($string, $find, true);
$expected = 'ケコサシスセソタチツテトナニヌネノ';
$this->assertEqual($expected, $result);
$string = 'Ĥēĺļŏ, Ŵőřļď!';
$find = 'Ő';
$result = mb_stristr($string, $find);
$expected = 'őřļď!';
$this->assertEqual($expected, $result);
$string = 'Ĥēĺļŏ, Ŵőřļď!';
$find = 'Ő';
$result = mb_stristr($string, $find, true);
$expected = 'Ĥēĺļŏ, Ŵ';
$this->assertEqual($expected, $result);
$string = 'Ĥēĺļŏ, Ŵőřļď!';
$find = 'ĺļ';
$result = mb_stristr($string, $find, true);
$expected = 'Ĥē';
$this->assertEqual($expected, $result);
$string = 'Hello, World!';
$find = 'O';
$result = mb_stristr($string, $find);
$expected = 'o, World!';
$this->assertEqual($expected, $result);
$string = 'Hello, World!';
$find = 'O';
$result = mb_stristr($string, $find, true);
$expected = 'Hell';
$this->assertEqual($expected, $result);
$string = 'Hello, World!';
$find = 'Wo';
$result = mb_stristr($string, $find);
$expected = 'World!';
$this->assertEqual($expected, $result);
$string = 'Hello, World!';
$find = 'Wo';
$result = mb_stristr($string, $find, true);
$expected = 'Hello, ';
$this->assertEqual($expected, $result);
$string = 'Hello, World!';
$find = 'll';
$result = mb_stristr($string, $find);
$expected = 'llo, World!';
$this->assertEqual($expected, $result);
$string = 'Hello, World!';
$find = 'll';
$result = mb_stristr($string, $find, true);
$expected = 'He';
$this->assertEqual($expected, $result);
$string = 'Hello, World!';
$find = 'rld';
$result = mb_stristr($string, $find);
$expected = 'rld!';
$this->assertEqual($expected, $result);
$string = 'Hello, World!';
$find = 'rld';
$result = mb_stristr($string, $find, true);
$expected = 'Hello, Wo';
$this->assertEqual($expected, $result);
$string = 'čini';
$find = 'N';
$result = mb_stristr($string, $find);
$expected = 'ni';
$this->assertEqual($expected, $result);
$string = 'čini';
$find = 'N';
$result = mb_stristr($string, $find, true);
$expected = 'či';
$this->assertEqual($expected, $result);
$string = 'moći';
$find = 'Ć';
$result = mb_stristr($string, $find);
$expected = 'ći';
$this->assertEqual($expected, $result);
$string = 'moći';
$find = 'Ć';
$result = mb_stristr($string, $find, true);
$expected = 'mo';
$this->assertEqual($expected, $result);
$string = 'državni';
$find = 'Ž';
$result = mb_stristr($string, $find);
$expected = 'žavni';
$this->assertEqual($expected, $result);
$string = 'državni';
$find = 'Ž';
$result = mb_stristr($string, $find, true);
$expected = 'dr';
$this->assertEqual($expected, $result);
$string = '把百度设为首页';
$find = '设';
$result = mb_stristr($string, $find);
$expected = '设为首页';
$this->assertEqual($expected, $result);
$string = '把百度设为首页';
$find = '设';
$result = mb_stristr($string, $find, true);
$expected = '把百度';
$this->assertEqual($expected, $result);
$string = '一二三周永龍';
$find = '周';
$result = mb_stristr($string, $find);
$expected = '周永龍';
$this->assertEqual($expected, $result);
$string = '一二三周永龍';
$find = '周';
$result = mb_stristr($string, $find, true);
$expected = '一二三';
$this->assertEqual($expected, $result);
$string = '一二三周永龍';
$find = '二周';
$result = mb_stristr($string, $find);
$expected = false;
$this->assertEqual($expected, $result);
}
/**
* testMultibyteStristr method
*
* @return void
*/
public function testMultibyteStristr() {
$string = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
$find = 'f';
$result = Multibyte::stristr($string, $find);
$expected = 'FGHIJKLMNOPQRSTUVWXYZ0123456789';
$this->assertEqual($expected, $result);
$string = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
$find = 'f';
$result = Multibyte::stristr($string, $find, true);
$expected = 'ABCDE';
$this->assertEqual($expected, $result);
$string = 'ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞ';
$find = 'å';
$result = Multibyte::stristr($string, $find);
$expected = 'ÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞ';
$this->assertEqual($expected, $result);
$string = 'ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞ';
$find = 'å';
$result = Multibyte::stristr($string, $find, true);
$expected = 'ÀÁÂÃÄ';
$this->assertEqual($expected, $result);
$string = 'ĀĂĄĆĈĊČĎĐĒĔĖĘĚĜĞĠĢĤĦĨĪĬĮIJĴĶĹĻĽĿŁŃŅŇŊŌŎŐŒŔŖŘŚŜŞŠŢŤŦŨŪŬŮŰŲŴŶŹŻŽ';
$find = 'ċ';
$result = Multibyte::stristr($string, $find);
$expected = 'ĊČĎĐĒĔĖĘĚĜĞĠĢĤĦĨĪĬĮIJĴĶĹĻĽĿŁŃŅŇŊŌŎŐŒŔŖŘŚŜŞŠŢŤŦŨŪŬŮŰŲŴŶŹŻŽ';
$this->assertEqual($expected, $result);
$string = 'ĀĂĄĆĈĊČĎĐĒĔĖĘĚĜĞĠĢĤĦĨĪĬĮIJĴĶĹĻĽĿŁŃŅŇŊŌŎŐŒŔŖŘŚŜŞŠŢŤŦŨŪŬŮŰŲŴŶŹŻŽ';
$find = 'ċ';
$result = Multibyte::stristr($string, $find, true);
$expected = 'ĀĂĄĆĈ';
$this->assertEqual($expected, $result);
$string = '!"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~';
$find = 'f';
$result = Multibyte::stristr($string, $find);
$expected = 'FGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~';
$this->assertEqual($expected, $result);
$string = '!"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~';
$find = 'f';
$result = Multibyte::stristr($string, $find, true);
$expected = '!"#$%&\'()*+,-./0123456789:;<=>?@ABCDE';
$this->assertEqual($expected, $result);
$string = '¡¢£¤¥¦§¨©ª«¬®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈ';
$find = 'Μ';
$result = Multibyte::stristr($string, $find);
$expected = 'µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈ';
$this->assertEqual($expected, $result);
$string = '¡¢£¤¥¦§¨©ª«¬®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈ';
$find = 'Μ';
$result = Multibyte::stristr($string, $find, true);
$expected = '¡¢£¤¥¦§¨©ª«¬®¯°±²³´';
$this->assertEqual($expected, $result);
$string = 'ÉÊËÌÍÎÏÐÑÒÓÔÕÖרÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿĀāĂ㥹ĆćĈĉĊċČčĎďĐđĒēĔĕĖėĘęĚěĜĝĞğĠġĢģĤĥĦħĨĩĪīĬ';
$find = 'þ';
$result = Multibyte::stristr($string, $find);
$expected = 'Þßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿĀāĂ㥹ĆćĈĉĊċČčĎďĐđĒēĔĕĖėĘęĚěĜĝĞğĠġĢģĤĥĦħĨĩĪīĬ';
$this->assertEqual($expected, $result);
$string = 'ÉÊËÌÍÎÏÐÑÒÓÔÕÖרÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿĀāĂ㥹ĆćĈĉĊċČčĎďĐđĒēĔĕĖėĘęĚěĜĝĞğĠġĢģĤĥĦħĨĩĪīĬ';
$find = 'þ';
$result = Multibyte::stristr($string, $find, true);
$expected = 'ÉÊËÌÍÎÏÐÑÒÓÔÕÖרÙÚÛÜÝ';
$this->assertEqual($expected, $result);
$string = 'ĭĮįİıIJijĴĵĶķĸĹĺĻļĽľĿŀŁłŃńŅņŇňʼnŊŋŌōŎŏŐőŒœŔŕŖŗŘřŚśŜŝŞşŠšŢţŤťŦŧŨũŪūŬŭŮůŰűŲųŴŵŶŷŸŹźŻżŽžſƀƁƂƃƄƅƆƇƈƉƊƋƌƍƎƏƐ';
$find = 'Ņ';
$result = Multibyte::stristr($string, $find);
$expected = 'ŅņŇňʼnŊŋŌōŎŏŐőŒœŔŕŖŗŘřŚśŜŝŞşŠšŢţŤťŦŧŨũŪūŬŭŮůŰűŲųŴŵŶŷŸŹźŻżŽžſƀƁƂƃƄƅƆƇƈƉƊƋƌƍƎƏƐ';
$this->assertEqual($expected, $result);
$string = 'ĭĮįİıIJijĴĵĶķĸĹĺĻļĽľĿŀŁłŃńŅņŇňʼnŊŋŌōŎŏŐőŒœŔŕŖŗŘřŚśŜŝŞşŠšŢţŤťŦŧŨũŪūŬŭŮůŰűŲųŴŵŶŷŸŹźŻżŽžſƀƁƂƃƄƅƆƇƈƉƊƋƌƍƎƏƐ';
$find = 'Ņ';
$result = Multibyte::stristr($string, $find, true);
$expected = 'ĭĮįİıIJijĴĵĶķĸĹĺĻļĽľĿŀŁłŃń';
$this->assertEqual($expected, $result);
$string = 'ƑƒƓƔƕƖƗƘƙƚƛƜƝƞƟƠơƢƣƤƥƦƧƨƩƪƫƬƭƮƯưƱƲƳƴƵƶƷƸƹƺƻƼƽƾƿǀǁǂǃDŽDždžLJLjljNJNjnjǍǎǏǐǑǒǓǔǕǖǗǘǙǚǛǜǝǞǟǠǡǢǣǤǥǦǧǨǩǪǫǬǭǮǯǰDZDzdzǴ';
$find = 'Ƹ';
$result = Multibyte::stristr($string, $find);
$expected = 'ƸƹƺƻƼƽƾƿǀǁǂǃDŽDždžLJLjljNJNjnjǍǎǏǐǑǒǓǔǕǖǗǘǙǚǛǜǝǞǟǠǡǢǣǤǥǦǧǨǩǪǫǬǭǮǯǰDZDzdzǴ';
$this->assertEqual($expected, $result);
$find = 'Ƹ';
$result = Multibyte::stristr($string, $find, true);
$expected = 'ƑƒƓƔƕƖƗƘƙƚƛƜƝƞƟƠơƢƣƤƥƦƧƨƩƪƫƬƭƮƯưƱƲƳƴƵƶƷ';
$this->assertEqual($expected, $result);
$string = 'əɚɛɜɝɞɟɠɡɢɣɤɥɦɧɨɩɪɫɬɭɮɯɰɱɲɳɴɵɶɷɸɹɺɻɼɽɾɿʀʁʂʃʄʅʆʇʈʉʊʋʌʍʎʏʐʑʒʓʔʕʖʗʘʙʚʛʜʝʞʟʠʡʢʣʤʥʦʧʨʩʪʫʬʭʮʯʰʱʲʳʴʵʶʷʸʹʺʻʼ';
$find = 'Ʀ';
$result = Multibyte::stristr($string, $find);
$expected = 'ʀʁʂʃʄʅʆʇʈʉʊʋʌʍʎʏʐʑʒʓʔʕʖʗʘʙʚʛʜʝʞʟʠʡʢʣʤʥʦʧʨʩʪʫʬʭʮʯʰʱʲʳʴʵʶʷʸʹʺʻʼ';
$this->assertEqual($expected, $result);
$string = 'əɚɛɜɝɞɟɠɡɢɣɤɥɦɧɨɩɪɫɬɭɮɯɰɱɲɳɴɵɶɷɸɹɺɻɼɽɾɿʀʁʂʃʄʅʆʇʈʉʊʋʌʍʎʏʐʑʒʓʔʕʖʗʘʙʚʛʜʝʞʟʠʡʢʣʤʥʦʧʨʩʪʫʬʭʮʯʰʱʲʳʴʵʶʷʸʹʺʻʼ';
$find = 'Ʀ';
$result = Multibyte::stristr($string, $find, true);
$expected = 'əɚɛɜɝɞɟɠɡɢɣɤɥɦɧɨɩɪɫɬɭɮɯɰɱɲɳɴɵɶɷɸɹɺɻɼɽɾɿ';
$this->assertEqual($expected, $result);
$string = 'ЀЁЂЃЄЅІЇЈЉЊЋЌЍЎЏАБВГДЕЖЗИЙКЛ';
$find = 'ї';
$result = Multibyte::stristr($string, $find);
$expected = 'ЇЈЉЊЋЌЍЎЏАБВГДЕЖЗИЙКЛ';
$this->assertEqual($expected, $result);
$string = 'ЀЁЂЃЄЅІЇЈЉЊЋЌЍЎЏАБВГДЕЖЗИЙКЛ';
$find = 'ї';
$result = Multibyte::stristr($string, $find, true);
$expected = 'ЀЁЂЃЄЅІ';
$this->assertEqual($expected, $result);
$string = 'МНОПРСТУФХЦЧШЩЪЫЬЭЮЯабвгдежзийклмнопрстуфхцчшщъыь';
$find = 'Р';
$result = Multibyte::stristr($string, $find);
$expected = 'РСТУФХЦЧШЩЪЫЬЭЮЯабвгдежзийклмнопрстуфхцчшщъыь';
$this->assertEqual($expected, $result);
$string = 'МНОПРСТУФХЦЧШЩЪЫЬЭЮЯабвгдежзийклмнопрстуфхцчшщъыь';
$find = 'Р';
$result = Multibyte::stristr($string, $find, true);
$expected = 'МНОП';
$this->assertEqual($expected, $result);
$string = 'فقكلمنهوىيًٌٍَُ';
$find = 'ن';
$result = Multibyte::stristr($string, $find);
$expected = 'نهوىيًٌٍَُ';
$this->assertEqual($expected, $result);
$string = 'فقكلمنهوىيًٌٍَُ';
$find = 'ن';
$result = Multibyte::stristr($string, $find, true);
$expected = 'فقكلم';
$this->assertEqual($expected, $result);
$string = '✰✱✲✳✴✵✶✷✸✹✺✻✼✽✾✿❀❁❂❃❄❅❆❇❈❉❊❋❌❍❎❏❐❑❒❓❔❕❖❗❘❙❚❛❜❝❞';
$find = '✿';
$result = Multibyte::stristr($string, $find);
$expected = '✿❀❁❂❃❄❅❆❇❈❉❊❋❌❍❎❏❐❑❒❓❔❕❖❗❘❙❚❛❜❝❞';
$this->assertEqual($expected, $result);
$string = '✰✱✲✳✴✵✶✷✸✹✺✻✼✽✾✿❀❁❂❃❄❅❆❇❈❉❊❋❌❍❎❏❐❑❒❓❔❕❖❗❘❙❚❛❜❝❞';
$find = '✿';
$result = Multibyte::stristr($string, $find, true);
$expected = '✰✱✲✳✴✵✶✷✸✹✺✻✼✽✾';
$this->assertEqual($expected, $result);
$string = '⺀⺁⺂⺃⺄⺅⺆⺇⺈⺉⺊⺋⺌⺍⺎⺏⺐⺑⺒⺓⺔⺕⺖⺗⺘⺙⺛⺜⺝⺞⺟⺠⺡⺢⺣⺤⺥⺦⺧⺨⺩⺪⺫⺬⺭⺮⺯⺰⺱⺲⺳⺴⺵⺶⺷⺸⺹⺺⺻⺼⺽⺾⺿⻀⻁⻂⻃⻄⻅⻆⻇⻈⻉⻊⻋⻌⻍⻎⻏⻐⻑⻒⻓⻔⻕⻖⻗⻘⻙⻚⻛⻜⻝⻞⻟⻠';
$find = '⺐';
$result = Multibyte::stristr($string, $find);
$expected = '⺐⺑⺒⺓⺔⺕⺖⺗⺘⺙⺛⺜⺝⺞⺟⺠⺡⺢⺣⺤⺥⺦⺧⺨⺩⺪⺫⺬⺭⺮⺯⺰⺱⺲⺳⺴⺵⺶⺷⺸⺹⺺⺻⺼⺽⺾⺿⻀⻁⻂⻃⻄⻅⻆⻇⻈⻉⻊⻋⻌⻍⻎⻏⻐⻑⻒⻓⻔⻕⻖⻗⻘⻙⻚⻛⻜⻝⻞⻟⻠';
$this->assertEqual($expected, $result);
$string = '⺀⺁⺂⺃⺄⺅⺆⺇⺈⺉⺊⺋⺌⺍⺎⺏⺐⺑⺒⺓⺔⺕⺖⺗⺘⺙⺛⺜⺝⺞⺟⺠⺡⺢⺣⺤⺥⺦⺧⺨⺩⺪⺫⺬⺭⺮⺯⺰⺱⺲⺳⺴⺵⺶⺷⺸⺹⺺⺻⺼⺽⺾⺿⻀⻁⻂⻃⻄⻅⻆⻇⻈⻉⻊⻋⻌⻍⻎⻏⻐⻑⻒⻓⻔⻕⻖⻗⻘⻙⻚⻛⻜⻝⻞⻟⻠';
$find = '⺐';
$result = Multibyte::stristr($string, $find, true);
$expected = '⺀⺁⺂⺃⺄⺅⺆⺇⺈⺉⺊⺋⺌⺍⺎⺏';
$this->assertEqual($expected, $result);
$string = '⽅⽆⽇⽈⽉⽊⽋⽌⽍⽎⽏⽐⽑⽒⽓⽔⽕⽖⽗⽘⽙⽚⽛⽜⽝⽞⽟⽠⽡⽢⽣⽤⽥⽦⽧⽨⽩⽪⽫⽬⽭⽮⽯⽰⽱⽲⽳⽴⽵⽶⽷⽸⽹⽺⽻⽼⽽⽾⽿';
$find = '⽤';
$result = Multibyte::stristr($string, $find);
$expected = '⽤⽥⽦⽧⽨⽩⽪⽫⽬⽭⽮⽯⽰⽱⽲⽳⽴⽵⽶⽷⽸⽹⽺⽻⽼⽽⽾⽿';
$this->assertEqual($expected, $result);
$string = '⽅⽆⽇⽈⽉⽊⽋⽌⽍⽎⽏⽐⽑⽒⽓⽔⽕⽖⽗⽘⽙⽚⽛⽜⽝⽞⽟⽠⽡⽢⽣⽤⽥⽦⽧⽨⽩⽪⽫⽬⽭⽮⽯⽰⽱⽲⽳⽴⽵⽶⽷⽸⽹⽺⽻⽼⽽⽾⽿';
$find = '⽤';
$result = Multibyte::stristr($string, $find, true);
$expected = '⽅⽆⽇⽈⽉⽊⽋⽌⽍⽎⽏⽐⽑⽒⽓⽔⽕⽖⽗⽘⽙⽚⽛⽜⽝⽞⽟⽠⽡⽢⽣';
$this->assertEqual($expected, $result);
$string = '눡눢눣눤눥눦눧눨눩눪눫눬눭눮눯눰눱눲눳눴눵눶눷눸눹눺눻눼눽눾눿뉀뉁뉂뉃뉄뉅뉆뉇뉈뉉뉊뉋뉌뉍뉎뉏뉐뉑뉒뉓뉔뉕뉖뉗뉘뉙뉚뉛뉜뉝뉞뉟뉠뉡뉢뉣뉤뉥뉦뉧뉨뉩뉪뉫뉬뉭뉮뉯뉰뉱뉲뉳뉴뉵뉶뉷뉸뉹뉺뉻뉼뉽뉾뉿늀늁늂늃늄';
$find = '눻';
$result = Multibyte::stristr($string, $find);
$expected = '눻눼눽눾눿뉀뉁뉂뉃뉄뉅뉆뉇뉈뉉뉊뉋뉌뉍뉎뉏뉐뉑뉒뉓뉔뉕뉖뉗뉘뉙뉚뉛뉜뉝뉞뉟뉠뉡뉢뉣뉤뉥뉦뉧뉨뉩뉪뉫뉬뉭뉮뉯뉰뉱뉲뉳뉴뉵뉶뉷뉸뉹뉺뉻뉼뉽뉾뉿늀늁늂늃늄';
$this->assertEqual($expected, $result);
$string = '눡눢눣눤눥눦눧눨눩눪눫눬눭눮눯눰눱눲눳눴눵눶눷눸눹눺눻눼눽눾눿뉀뉁뉂뉃뉄뉅뉆뉇뉈뉉뉊뉋뉌뉍뉎뉏뉐뉑뉒뉓뉔뉕뉖뉗뉘뉙뉚뉛뉜뉝뉞뉟뉠뉡뉢뉣뉤뉥뉦뉧뉨뉩뉪뉫뉬뉭뉮뉯뉰뉱뉲뉳뉴뉵뉶뉷뉸뉹뉺뉻뉼뉽뉾뉿늀늁늂늃늄';
$find = '눻';
$result = Multibyte::stristr($string, $find, true);
$expected = '눡눢눣눤눥눦눧눨눩눪눫눬눭눮눯눰눱눲눳눴눵눶눷눸눹눺';
$this->assertEqual($expected, $result);
$string = 'ﹰﹱﹲﹳﹴﹶﹷﹸﹹﹺﹻﹼﹽﹾﹿﺀﺁﺂﺃﺄﺅﺆﺇﺈﺉﺊﺋﺌﺍﺎﺏﺐﺑﺒﺓﺔﺕﺖﺗﺘﺙﺚﺛﺜﺝﺞﺟﺠﺡﺢﺣﺤﺥﺦﺧﺨﺩﺪﺫﺬﺭﺮﺯﺰ';
$find = 'ﺞ';
$result = Multibyte::stristr($string, $find);
$expected = 'ﺞﺟﺠﺡﺢﺣﺤﺥﺦﺧﺨﺩﺪﺫﺬﺭﺮﺯﺰ';
$this->assertEqual($expected, $result);
$string = 'ﹰﹱﹲﹳﹴﹶﹷﹸﹹﹺﹻﹼﹽﹾﹿﺀﺁﺂﺃﺄﺅﺆﺇﺈﺉﺊﺋﺌﺍﺎﺏﺐﺑﺒﺓﺔﺕﺖﺗﺘﺙﺚﺛﺜﺝﺞﺟﺠﺡﺢﺣﺤﺥﺦﺧﺨﺩﺪﺫﺬﺭﺮﺯﺰ';
$find = 'ﺞ';
$result = Multibyte::stristr($string, $find, true);
$expected = 'ﹰﹱﹲﹳﹴﹶﹷﹸﹹﹺﹻﹼﹽﹾﹿﺀﺁﺂﺃﺄﺅﺆﺇﺈﺉﺊﺋﺌﺍﺎﺏﺐﺑﺒﺓﺔﺕﺖﺗﺘﺙﺚﺛﺜﺝ';
$this->assertEqual($expected, $result);
$string = 'ﺱﺲﺳﺴﺵﺶﺷﺸﺹﺺﺻﺼﺽﺾﺿﻀﻁﻂﻃﻄﻅﻆﻇﻈﻉﻊﻋﻌﻍﻎﻏﻐﻑﻒﻓﻔﻕﻖﻗﻘﻙﻚﻛﻜﻝﻞﻟﻠﻡﻢﻣﻤﻥﻦﻧﻨﻩﻪﻫﻬﻭﻮﻯﻰﻱﻲﻳﻴﻵﻶﻷﻸﻹﻺﻻﻼ';
$find = 'ﻞ';
$result = Multibyte::stristr($string, $find);
$expected = 'ﻞﻟﻠﻡﻢﻣﻤﻥﻦﻧﻨﻩﻪﻫﻬﻭﻮﻯﻰﻱﻲﻳﻴﻵﻶﻷﻸﻹﻺﻻﻼ';
$this->assertEqual($expected, $result);
$string = 'ﺱﺲﺳﺴﺵﺶﺷﺸﺹﺺﺻﺼﺽﺾﺿﻀﻁﻂﻃﻄﻅﻆﻇﻈﻉﻊﻋﻌﻍﻎﻏﻐﻑﻒﻓﻔﻕﻖﻗﻘﻙﻚﻛﻜﻝﻞﻟﻠﻡﻢﻣﻤﻥﻦﻧﻨﻩﻪﻫﻬﻭﻮﻯﻰﻱﻲﻳﻴﻵﻶﻷﻸﻹﻺﻻﻼ';
$find = 'ﻞ';
$result = Multibyte::stristr($string, $find, true);
$expected = 'ﺱﺲﺳﺴﺵﺶﺷﺸﺹﺺﺻﺼﺽﺾﺿﻀﻁﻂﻃﻄﻅﻆﻇﻈﻉﻊﻋﻌﻍﻎﻏﻐﻑﻒﻓﻔﻕﻖﻗﻘﻙﻚﻛﻜﻝ';
$this->assertEqual($expected, $result);
$string = 'abcdefghijklmnopqrstuvwxyz';
$find = 'K';
$result = Multibyte::stristr($string, $find);
$expected = 'klmnopqrstuvwxyz';
$this->assertEqual($expected, $result);
$string = 'abcdefghijklmnopqrstuvwxyz';
$find = 'K';
$result = Multibyte::stristr($string, $find, true);
$expected = 'abcdefghij';
$this->assertEqual($expected, $result);
$string = '。「」、・ヲァィゥェォャュョッーアイウエオカキク';
$find = 'ア';
$result = Multibyte::stristr($string, $find);
$expected = 'アイウエオカキク';
$this->assertEqual($expected, $result);
$string = '。「」、・ヲァィゥェォャュョッーアイウエオカキク';
$find = 'ア';
$result = Multibyte::stristr($string, $find, true);
$expected = '。「」、・ヲァィゥェォャュョッー';
$this->assertEqual($expected, $result);
$string = 'ケコサシスセソタチツテトナニヌネノハヒフヘホマミムメモヤユヨラリルレロワン゙';
$find = 'ハ';
$result = Multibyte::stristr($string, $find);
$expected = 'ハヒフヘホマミムメモヤユヨラリルレロワン゙';
$this->assertEqual($expected, $result);
$string = 'ケコサシスセソタチツテトナニヌネノハヒフヘホマミムメモヤユヨラリルレロワン゙';
$find = 'ハ';
$result = Multibyte::stristr($string, $find, true);
$expected = 'ケコサシスセソタチツテトナニヌネノ';
$this->assertEqual($expected, $result);
$string = 'Ĥēĺļŏ, Ŵőřļď!';
$find = 'Ő';
$result = Multibyte::stristr($string, $find);
$expected = 'őřļď!';
$this->assertEqual($expected, $result);
$string = 'Ĥēĺļŏ, Ŵőřļď!';
$find = 'Ő';
$result = Multibyte::stristr($string, $find, true);
$expected = 'Ĥēĺļŏ, Ŵ';
$this->assertEqual($expected, $result);
$string = 'Ĥēĺļŏ, Ŵőřļď!';
$find = 'ĺļ';
$result = Multibyte::stristr($string, $find, true);
$expected = 'Ĥē';
$this->assertEqual($expected, $result);
$string = 'Hello, World!';
$find = 'O';
$result = Multibyte::stristr($string, $find);
$expected = 'o, World!';
$this->assertEqual($expected, $result);
$string = 'Hello, World!';
$find = 'O';
$result = Multibyte::stristr($string, $find, true);
$expected = 'Hell';
$this->assertEqual($expected, $result);
$string = 'Hello, World!';
$find = 'Wo';
$result = Multibyte::stristr($string, $find);
$expected = 'World!';
$this->assertEqual($expected, $result);
$string = 'Hello, World!';
$find = 'Wo';
$result = Multibyte::stristr($string, $find, true);
$expected = 'Hello, ';
$this->assertEqual($expected, $result);
$string = 'Hello, World!';
$find = 'll';
$result = Multibyte::stristr($string, $find);
$expected = 'llo, World!';
$this->assertEqual($expected, $result);
$string = 'Hello, World!';
$find = 'll';
$result = Multibyte::stristr($string, $find, true);
$expected = 'He';
$this->assertEqual($expected, $result);
$string = 'Hello, World!';
$find = 'rld';
$result = Multibyte::stristr($string, $find);
$expected = 'rld!';
$this->assertEqual($expected, $result);
$string = 'Hello, World!';
$find = 'rld';
$result = Multibyte::stristr($string, $find, true);
$expected = 'Hello, Wo';
$this->assertEqual($expected, $result);
$string = 'čini';
$find = 'N';
$result = Multibyte::stristr($string, $find);
$expected = 'ni';
$this->assertEqual($expected, $result);
$string = 'čini';
$find = 'N';
$result = Multibyte::stristr($string, $find, true);
$expected = 'či';
$this->assertEqual($expected, $result);
$string = 'moći';
$find = 'Ć';
$result = Multibyte::stristr($string, $find);
$expected = 'ći';
$this->assertEqual($expected, $result);
$string = 'moći';
$find = 'Ć';
$result = Multibyte::stristr($string, $find, true);
$expected = 'mo';
$this->assertEqual($expected, $result);
$string = 'državni';
$find = 'Ž';
$result = Multibyte::stristr($string, $find);
$expected = 'žavni';
$this->assertEqual($expected, $result);
$string = 'državni';
$find = 'Ž';
$result = Multibyte::stristr($string, $find, true);
$expected = 'dr';
$this->assertEqual($expected, $result);
$string = '把百度设为首页';
$find = '设';
$result = Multibyte::stristr($string, $find);
$expected = '设为首页';
$this->assertEqual($expected, $result);
$string = '把百度设为首页';
$find = '设';
$result = Multibyte::stristr($string, $find, true);
$expected = '把百度';
$this->assertEqual($expected, $result);
$string = '一二三周永龍';
$find = '周';
$result = Multibyte::stristr($string, $find);
$expected = '周永龍';
$this->assertEqual($expected, $result);
$string = '一二三周永龍';
$find = '周';
$result = Multibyte::stristr($string, $find, true);
$expected = '一二三';
$this->assertEqual($expected, $result);
$string = '一二三周永龍';
$find = '二周';
$result = Multibyte::stristr($string, $find);
$expected = false;
$this->assertEqual($expected, $result);
}
/**
* testUsingMbStrlen method
*
* @return void
*/
public function testUsingMbStrlen() {
$string = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
$result = mb_strlen($string);
$expected = 36;
$this->assertEqual($expected, $result);
$string = 'ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞ';
$result = mb_strlen($string);
$expected = 30;
$this->assertEqual($expected, $result);
$string = 'ĀĂĄĆĈĊČĎĐĒĔĖĘĚĜĞĠĢĤĦĨĪĬĮIJĴĶĹĻĽĿŁŃŅŇŊŌŎŐŒŔŖŘŚŜŞŠŢŤŦŨŪŬŮŰŲŴŶŹŻŽ';
$result = mb_strlen($string);
$expected = 61;
$this->assertEqual($expected, $result);
$string = '!"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~';
$result = mb_strlen($string);
$expected = 94;
$this->assertEqual($expected, $result);
$string = '¡¢£¤¥¦§¨©ª«¬®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈ';
$result = mb_strlen($string);
$expected = 40;
$this->assertEqual($expected, $result);
$string = 'ÉÊËÌÍÎÏÐÑÒÓÔÕÖרÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿĀāĂ㥹ĆćĈĉĊċČčĎďĐđĒēĔĕĖėĘęĚěĜĝĞğĠġĢģĤĥĦħĨĩĪīĬ';
$result = mb_strlen($string);
$expected = 100;
$this->assertEqual($expected, $result);
$string = 'ĭĮįİıIJijĴĵĶķĸĹĺĻļĽľĿŀŁłŃńŅņŇňʼnŊŋŌōŎŏŐőŒœŔŕŖŗŘřŚśŜŝŞşŠšŢţŤťŦŧŨũŪūŬŭŮůŰűŲųŴŵŶŷŸŹźŻżŽžſƀƁƂƃƄƅƆƇƈƉƊƋƌƍƎƏƐ';
$result = mb_strlen($string);
$expected = 100;
$this->assertEqual($expected, $result);
$string = 'ƑƒƓƔƕƖƗƘƙƚƛƜƝƞƟƠơƢƣƤƥƦƧƨƩƪƫƬƭƮƯưƱƲƳƴƵƶƷƸƹƺƻƼƽƾƿǀǁǂǃDŽDždžLJLjljNJNjnjǍǎǏǐǑǒǓǔǕǖǗǘǙǚǛǜǝǞǟǠǡǢǣǤǥǦǧǨǩǪǫǬǭǮǯǰDZDzdzǴ';
$result = mb_strlen($string);
$expected = 100;
$this->assertEqual($expected, $result);
$string = 'əɚɛɜɝɞɟɠɡɢɣɤɥɦɧɨɩɪɫɬɭɮɯɰɱɲɳɴɵɶɷɸɹɺɻɼɽɾɿʀʁʂʃʄʅʆʇʈʉʊʋʌʍʎʏʐʑʒʓʔʕʖʗʘʙʚʛʜʝʞʟʠʡʢʣʤʥʦʧʨʩʪʫʬʭʮʯʰʱʲʳʴʵʶʷʸʹʺʻʼ';
$result = mb_strlen($string);
$expected = 100;
$this->assertEqual($expected, $result);
$string = 'ЀЁЂЃЄЅІЇЈЉЊЋЌЍЎЏАБВГДЕЖЗИЙКЛ';
$result = mb_strlen($string);
$expected = 28;
$this->assertEqual($expected, $result);
$string = 'МНОПРСТУФХЦЧШЩЪЫЬЭЮЯабвгдежзийклмнопрстуфхцчшщъыь';
$result = mb_strlen($string);
$expected = 49;
$this->assertEqual($expected, $result);
$string = 'فقكلمنهوىيًٌٍَُ';
$result = mb_strlen($string);
$expected = 15;
$this->assertEqual($expected, $result);
$string = '✰✱✲✳✴✵✶✷✸✹✺✻✼✽✾✿❀❁❂❃❄❅❆❇❈❉❊❋❌❍❎❏❐❑❒❓❔❕❖❗❘❙❚❛❜❝❞';
$result = mb_strlen($string);
$expected = 47;
$this->assertEqual($expected, $result);
$string = '⺀⺁⺂⺃⺄⺅⺆⺇⺈⺉⺊⺋⺌⺍⺎⺏⺐⺑⺒⺓⺔⺕⺖⺗⺘⺙⺛⺜⺝⺞⺟⺠⺡⺢⺣⺤⺥⺦⺧⺨⺩⺪⺫⺬⺭⺮⺯⺰⺱⺲⺳⺴⺵⺶⺷⺸⺹⺺⺻⺼⺽⺾⺿⻀⻁⻂⻃⻄⻅⻆⻇⻈⻉⻊⻋⻌⻍⻎⻏⻐⻑⻒⻓⻔⻕⻖⻗⻘⻙⻚⻛⻜⻝⻞⻟⻠';
$result = mb_strlen($string);
$expected = 96;
$this->assertEqual($expected, $result);
$string = '⽅⽆⽇⽈⽉⽊⽋⽌⽍⽎⽏⽐⽑⽒⽓⽔⽕⽖⽗⽘⽙⽚⽛⽜⽝⽞⽟⽠⽡⽢⽣⽤⽥⽦⽧⽨⽩⽪⽫⽬⽭⽮⽯⽰⽱⽲⽳⽴⽵⽶⽷⽸⽹⽺⽻⽼⽽⽾⽿';
$result = mb_strlen($string);
$expected = 59;
$this->assertEqual($expected, $result);
$string = '눡눢눣눤눥눦눧눨눩눪눫눬눭눮눯눰눱눲눳눴눵눶눷눸눹눺눻눼눽눾눿뉀뉁뉂뉃뉄뉅뉆뉇뉈뉉뉊뉋뉌뉍뉎뉏뉐뉑뉒뉓뉔뉕뉖뉗뉘뉙뉚뉛뉜뉝뉞뉟뉠뉡뉢뉣뉤뉥뉦뉧뉨뉩뉪뉫뉬뉭뉮뉯뉰뉱뉲뉳뉴뉵뉶뉷뉸뉹뉺뉻뉼뉽뉾뉿늀늁늂늃늄';
$result = mb_strlen($string);
$expected = 100;
$this->assertEqual($expected, $result);
$string = 'ﹰﹱﹲﹳﹴﹶﹷﹸﹹﹺﹻﹼﹽﹾﹿﺀﺁﺂﺃﺄﺅﺆﺇﺈﺉﺊﺋﺌﺍﺎﺏﺐﺑﺒﺓﺔﺕﺖﺗﺘﺙﺚﺛﺜﺝﺞﺟﺠﺡﺢﺣﺤﺥﺦﺧﺨﺩﺪﺫﺬﺭﺮﺯﺰ';
$result = mb_strlen($string);
$expected = 65;
$this->assertEqual($expected, $result);
$string = 'ﺱﺲﺳﺴﺵﺶﺷﺸﺹﺺﺻﺼﺽﺾﺿﻀﻁﻂﻃﻄﻅﻆﻇﻈﻉﻊﻋﻌﻍﻎﻏﻐﻑﻒﻓﻔﻕﻖﻗﻘﻙﻚﻛﻜﻝﻞﻟﻠﻡﻢﻣﻤﻥﻦﻧﻨﻩﻪﻫﻬﻭﻮﻯﻰﻱﻲﻳﻴﻵﻶﻷﻸﻹﻺﻻﻼ';
$result = mb_strlen($string);
$expected = 76;
$this->assertEqual($expected, $result);
$string = 'abcdefghijklmnopqrstuvwxyz';
$result = mb_strlen($string);
$expected = 26;
$this->assertEqual($expected, $result);
$string = '。「」、・ヲァィゥェォャュョッーアイウエオカキク';
$result = mb_strlen($string);
$expected = 24;
$this->assertEqual($expected, $result);
$string = 'ケコサシスセソタチツテトナニヌネノハヒフヘホマミムメモヤユヨラリルレロワン゙';
$result = mb_strlen($string);
$expected = 38;
$this->assertEqual($expected, $result);
$string = 'Ĥēĺļŏ, Ŵőřļď!';
$result = mb_strlen($string);
$expected = 13;
$this->assertEqual($expected, $result);
$string = 'Hello, World!';
$result = mb_strlen($string);
$expected = 13;
$this->assertEqual($expected, $result);
$string = 'čini';
$result = mb_strlen($string);
$expected = 4;
$this->assertEqual($expected, $result);
$string = 'moći';
$result = mb_strlen($string);
$expected = 4;
$this->assertEqual($expected, $result);
$string = 'državni';
$result = mb_strlen($string);
$expected = 7;
$this->assertEqual($expected, $result);
$string = '把百度设为首页';
$result = mb_strlen($string);
$expected = 7;
$this->assertEqual($expected, $result);
$string = '一二三周永龍';
$result = mb_strlen($string);
$expected = 6;
$this->assertEqual($expected, $result);
}
/**
* testMultibyteStrlen method
*
* @return void
*/
public function testMultibyteStrlen() {
$string = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
$result = Multibyte::strlen($string);
$expected = 36;
$this->assertEqual($expected, $result);
$string = 'ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞ';
$result = Multibyte::strlen($string);
$expected = 30;
$this->assertEqual($expected, $result);
$string = 'ĀĂĄĆĈĊČĎĐĒĔĖĘĚĜĞĠĢĤĦĨĪĬĮIJĴĶĹĻĽĿŁŃŅŇŊŌŎŐŒŔŖŘŚŜŞŠŢŤŦŨŪŬŮŰŲŴŶŹŻŽ';
$result = Multibyte::strlen($string);
$expected = 61;
$this->assertEqual($expected, $result);
$string = '!"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~';
$result = Multibyte::strlen($string);
$expected = 94;
$this->assertEqual($expected, $result);
$string = '¡¢£¤¥¦§¨©ª«¬®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈ';
$result = Multibyte::strlen($string);
$expected = 40;
$this->assertEqual($expected, $result);
$string = 'ÉÊËÌÍÎÏÐÑÒÓÔÕÖרÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿĀāĂ㥹ĆćĈĉĊċČčĎďĐđĒēĔĕĖėĘęĚěĜĝĞğĠġĢģĤĥĦħĨĩĪīĬ';
$result = Multibyte::strlen($string);
$expected = 100;
$this->assertEqual($expected, $result);
$string = 'ĭĮįİıIJijĴĵĶķĸĹĺĻļĽľĿŀŁłŃńŅņŇňʼnŊŋŌōŎŏŐőŒœŔŕŖŗŘřŚśŜŝŞşŠšŢţŤťŦŧŨũŪūŬŭŮůŰűŲųŴŵŶŷŸŹźŻżŽžſƀƁƂƃƄƅƆƇƈƉƊƋƌƍƎƏƐ';
$result = Multibyte::strlen($string);
$expected = 100;
$this->assertEqual($expected, $result);
$string = 'ƑƒƓƔƕƖƗƘƙƚƛƜƝƞƟƠơƢƣƤƥƦƧƨƩƪƫƬƭƮƯưƱƲƳƴƵƶƷƸƹƺƻƼƽƾƿǀǁǂǃDŽDždžLJLjljNJNjnjǍǎǏǐǑǒǓǔǕǖǗǘǙǚǛǜǝǞǟǠǡǢǣǤǥǦǧǨǩǪǫǬǭǮǯǰDZDzdzǴ';
$result = Multibyte::strlen($string);
$expected = 100;
$this->assertEqual($expected, $result);
$string = 'əɚɛɜɝɞɟɠɡɢɣɤɥɦɧɨɩɪɫɬɭɮɯɰɱɲɳɴɵɶɷɸɹɺɻɼɽɾɿʀʁʂʃʄʅʆʇʈʉʊʋʌʍʎʏʐʑʒʓʔʕʖʗʘʙʚʛʜʝʞʟʠʡʢʣʤʥʦʧʨʩʪʫʬʭʮʯʰʱʲʳʴʵʶʷʸʹʺʻʼ';
$result = Multibyte::strlen($string);
$expected = 100;
$this->assertEqual($expected, $result);
$string = 'ЀЁЂЃЄЅІЇЈЉЊЋЌЍЎЏАБВГДЕЖЗИЙКЛ';
$result = Multibyte::strlen($string);
$expected = 28;
$this->assertEqual($expected, $result);
$string = 'МНОПРСТУФХЦЧШЩЪЫЬЭЮЯабвгдежзийклмнопрстуфхцчшщъыь';
$result = Multibyte::strlen($string);
$expected = 49;
$this->assertEqual($expected, $result);
$string = 'فقكلمنهوىيًٌٍَُ';
$result = Multibyte::strlen($string);
$expected = 15;
$this->assertEqual($expected, $result);
$string = '✰✱✲✳✴✵✶✷✸✹✺✻✼✽✾✿❀❁❂❃❄❅❆❇❈❉❊❋❌❍❎❏❐❑❒❓❔❕❖❗❘❙❚❛❜❝❞';
$result = Multibyte::strlen($string);
$expected = 47;
$this->assertEqual($expected, $result);
$string = '⺀⺁⺂⺃⺄⺅⺆⺇⺈⺉⺊⺋⺌⺍⺎⺏⺐⺑⺒⺓⺔⺕⺖⺗⺘⺙⺛⺜⺝⺞⺟⺠⺡⺢⺣⺤⺥⺦⺧⺨⺩⺪⺫⺬⺭⺮⺯⺰⺱⺲⺳⺴⺵⺶⺷⺸⺹⺺⺻⺼⺽⺾⺿⻀⻁⻂⻃⻄⻅⻆⻇⻈⻉⻊⻋⻌⻍⻎⻏⻐⻑⻒⻓⻔⻕⻖⻗⻘⻙⻚⻛⻜⻝⻞⻟⻠';
$result = Multibyte::strlen($string);
$expected = 96;
$this->assertEqual($expected, $result);
$string = '⽅⽆⽇⽈⽉⽊⽋⽌⽍⽎⽏⽐⽑⽒⽓⽔⽕⽖⽗⽘⽙⽚⽛⽜⽝⽞⽟⽠⽡⽢⽣⽤⽥⽦⽧⽨⽩⽪⽫⽬⽭⽮⽯⽰⽱⽲⽳⽴⽵⽶⽷⽸⽹⽺⽻⽼⽽⽾⽿';
$result = Multibyte::strlen($string);
$expected = 59;
$this->assertEqual($expected, $result);
$string = '눡눢눣눤눥눦눧눨눩눪눫눬눭눮눯눰눱눲눳눴눵눶눷눸눹눺눻눼눽눾눿뉀뉁뉂뉃뉄뉅뉆뉇뉈뉉뉊뉋뉌뉍뉎뉏뉐뉑뉒뉓뉔뉕뉖뉗뉘뉙뉚뉛뉜뉝뉞뉟뉠뉡뉢뉣뉤뉥뉦뉧뉨뉩뉪뉫뉬뉭뉮뉯뉰뉱뉲뉳뉴뉵뉶뉷뉸뉹뉺뉻뉼뉽뉾뉿늀늁늂늃늄';
$result = Multibyte::strlen($string);
$expected = 100;
$this->assertEqual($expected, $result);
$string = 'ﹰﹱﹲﹳﹴﹶﹷﹸﹹﹺﹻﹼﹽﹾﹿﺀﺁﺂﺃﺄﺅﺆﺇﺈﺉﺊﺋﺌﺍﺎﺏﺐﺑﺒﺓﺔﺕﺖﺗﺘﺙﺚﺛﺜﺝﺞﺟﺠﺡﺢﺣﺤﺥﺦﺧﺨﺩﺪﺫﺬﺭﺮﺯﺰ';
$result = Multibyte::strlen($string);
$expected = 65;
$this->assertEqual($expected, $result);
$string = 'ﺱﺲﺳﺴﺵﺶﺷﺸﺹﺺﺻﺼﺽﺾﺿﻀﻁﻂﻃﻄﻅﻆﻇﻈﻉﻊﻋﻌﻍﻎﻏﻐﻑﻒﻓﻔﻕﻖﻗﻘﻙﻚﻛﻜﻝﻞﻟﻠﻡﻢﻣﻤﻥﻦﻧﻨﻩﻪﻫﻬﻭﻮﻯﻰﻱﻲﻳﻴﻵﻶﻷﻸﻹﻺﻻﻼ';
$result = Multibyte::strlen($string);
$expected = 76;
$this->assertEqual($expected, $result);
$string = 'abcdefghijklmnopqrstuvwxyz';
$result = Multibyte::strlen($string);
$expected = 26;
$this->assertEqual($expected, $result);
$string = '。「」、・ヲァィゥェォャュョッーアイウエオカキク';
$result = Multibyte::strlen($string);
$expected = 24;
$this->assertEqual($expected, $result);
$string = 'ケコサシスセソタチツテトナニヌネノハヒフヘホマミムメモヤユヨラリルレロワン゙';
$result = Multibyte::strlen($string);
$expected = 38;
$this->assertEqual($expected, $result);
$string = 'Ĥēĺļŏ, Ŵőřļď!';
$result = Multibyte::strlen($string);
$expected = 13;
$this->assertEqual($expected, $result);
$string = 'Hello, World!';
$result = Multibyte::strlen($string);
$expected = 13;
$this->assertEqual($expected, $result);
$string = 'čini';
$result = Multibyte::strlen($string);
$expected = 4;
$this->assertEqual($expected, $result);
$string = 'moći';
$result = Multibyte::strlen($string);
$expected = 4;
$this->assertEqual($expected, $result);
$string = 'državni';
$result = Multibyte::strlen($string);
$expected = 7;
$this->assertEqual($expected, $result);
$string = '把百度设为首页';
$result = Multibyte::strlen($string);
$expected = 7;
$this->assertEqual($expected, $result);
$string = '一二三周永龍';
$result = Multibyte::strlen($string);
$expected = 6;
$this->assertEqual($expected, $result);
}
/**
* testUsingMbStrpos method
*
* @return void
*/
public function testUsingMbStrpos() {
$string = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
$find = 'F';
$result = mb_strpos($string, $find);
$expected = 5;
$this->assertEqual($expected, $result);
$string = 'ABCDEFGHIJKLMNOPQFRSTUVWXYZ0123456789';
$find = 'F';
$result = mb_strpos($string, $find, 6);
$expected = 17;
$this->assertEqual($expected, $result);
$string = 'ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞ';
$find = 'Å';
$result = mb_strpos($string, $find);
$expected = 5;
$this->assertEqual($expected, $result);
$string = 'ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÅÙÚÛÜÝÞ';
$find = 'Å';
$result = mb_strpos($string, $find, 6);
$expected = 24;
$this->assertEqual($expected, $result);
$string = 'ĀĂĄĆĈĊČĎĐĒĔĖĘĚĜĞĠĢĤĦĨĪĬĮIJĴĶĹĻĽĿŁŃŅŇŊŌŎŐŒŔŖŘŚŜŞŠŢŤŦŨŪŬŮŰŲŴŶŹŻŽ';
$find = 'Ċ';
$result = mb_strpos($string, $find);
$expected = 5;
$this->assertEqual($expected, $result);
$string = 'ĀĂĄĆĈĊČĎĐĒĔĖĘĚĜĞĠĢĤĦĨĪĬĮIJĴĶĹĻĽĿŁĊŃŅŇŊŌŎŐŒŔŖŘŚŜŞŠŢŤŦŨŪŬŮŰŲŴŶŹŻŽ';
$find = 'Ċ';
$result = mb_strpos($string, $find, 6);
$expected = 32;
$this->assertEqual($expected, $result);
$string = '!"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~';
$find = 'F';
$result = mb_strpos($string, $find);
$expected = 37;
$this->assertEqual($expected, $result);
$string = '¡¢£¤¥¦§¨©ª«¬®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈ';
$find = 'µ';
$result = mb_strpos($string, $find);
$expected = 20;
$this->assertEqual($expected, $result);
$string = 'ÉÊËÌÍÎÏÐÑÒÓÔÕÖרÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿĀāĂ㥹ĆćĈĉĊċČčĎďĐđĒēĔĕĖėĘęĚěĜĝĞğĠġĢģĤĥĦħĨĩĪīĬ';
$find = 'é';
$result = mb_strpos($string, $find);
$expected = 32;
$this->assertEqual($expected, $result);
$string = 'ĭĮįİıIJijĴĵĶķĸĹĺĻļĽľĿŀŁłŃńŅņŇňʼnŊŋŌōŎŏŐőŒœŔŕŖŗŘřŚśŜŝŞşŠšŢţŤťŦŧŨũŪūŬŭŮůŰűŲųŴŵŶŷŸŹźŻżŽžſƀƁƂƃƄƅƆƇƈƉƊƋƌƍƎƏƐ';
$find = 'Ņ';
$result = mb_strpos($string, $find);
$expected = 24;
$this->assertEqual($expected, $result);
$string = 'ƑƒƓƔƕƖƗƘƙƚƛƜƝƞƟƠơƢƣƤƥƦƧƨƩƪƫƬƭƮƯưƱƲƳƴƵƶƷƸƹƺƻƼƽƾƿǀǁǂǃDŽDždžLJLjljNJNjnjǍǎǏǐǑǒǓǔǕǖǗǘǙǚǛǜǝǞǟǠǡǢǣǤǥǦǧǨǩǪǫǬǭǮǯǰDZDzdzǴ';
$find = 'Ƹ';
$result = mb_strpos($string, $find);
$expected = 39;
$this->assertEqual($expected, $result);
$string = 'ƑƒƓƔƕƖƗƘƙƚƛƜƝƞƟƠơƢƣƤƥƦƧƨƩƪƫƬƭƮƯưƱƲƳƴƵƶƷƸƹƺƻƼƽƾƿǀǁǂǃDŽDždžLJLjljNJNjnjǍǎǏǐǑǒǓǔǕǖǗǘǙǚǛǜǝǞǟǠǡǢǣǤǥǦǧǨǩǪǫǬǭǮǯǰDZDzdzǴ';
$find = 'ƹ';
$result = mb_strpos($string, $find);
$expected = 40;
$this->assertEqual($expected, $result);
$string = 'əɚɛɜɝɞɟɠɡɢɣɤɥɦɧɨɩɪɫɬɭɮɯɰɱɲɳɴɵɶɷɸɹɺɻɼɽɾɿʀʁʂʃʄʅʆʇʈʉʊʋʌʍʎʏʐʑʒʓʔʕʖʗʘʙʚʛʜʝʞʟʠʡʢʣʤʥʦʧʨʩʪʫʬʭʮʯʰʱʲʳʴʵʶʷʸʹʺʻʼ';
$find = 'ʀ';
$result = mb_strpos($string, $find);
$expected = 39;
$this->assertEqual($expected, $result);
$string = 'ЀЁЂЃЄЅІЇЈЉЊЋЌЍЎЏАБВГДЕЖЗИЙКЛ';
$find = 'Ї';
$result = mb_strpos($string, $find);
$expected = 7;
$this->assertEqual($expected, $result);
$string = 'МНОПРСТУФХЦЧШЩЪЫЬЭЮЯабвгдежзийклмнопрстуфхцчшщъыь';
$find = 'Р';
$result = mb_strpos($string, $find);
$expected = 4;
$this->assertEqual($expected, $result);
$string = 'МНОПРСТУФХЦЧШЩЪЫЬЭЮЯабвгдежзийклмнопрстуфхцчшщъыь';
$find = 'р';
$result = mb_strpos($string, $find, 5);
$expected = 36;
$this->assertEqual($expected, $result);
$string = 'فقكلمنهوىيًٌٍَُ';
$find = 'ن';
$result = mb_strpos($string, $find);
$expected = 5;
$this->assertEqual($expected, $result);
$string = '✰✱✲✳✴✵✶✷✸✹✺✻✼✽✾✿❀❁❂❃❄❅❆❇❈❉❊❋❌❍❎❏❐❑❒❓❔❕❖❗❘❙❚❛❜❝❞';
$find = '✿';
$result = mb_strpos($string, $find);
$expected = 15;
$this->assertEqual($expected, $result);
$string = '⺀⺁⺂⺃⺄⺅⺆⺇⺈⺉⺊⺋⺌⺍⺎⺏⺐⺑⺒⺓⺔⺕⺖⺗⺘⺙⺛⺜⺝⺞⺟⺠⺡⺢⺣⺤⺥⺦⺧⺨⺩⺪⺫⺬⺭⺮⺯⺰⺱⺲⺳⺴⺵⺶⺷⺸⺹⺺⺻⺼⺽⺾⺿⻀⻁⻂⻃⻄⻅⻆⻇⻈⻉⻊⻋⻌⻍⻎⻏⻐⻑⻒⻓⻔⻕⻖⻗⻘⻙⻚⻛⻜⻝⻞⻟⻠';
$find = '⺐';
$result = mb_strpos($string, $find);
$expected = 16;
$this->assertEqual($expected, $result);
$string = '⽅⽆⽇⽈⽉⽊⽋⽌⽍⽎⽏⽐⽑⽒⽓⽔⽕⽖⽗⽘⽙⽚⽛⽜⽝⽞⽟⽠⽡⽢⽣⽤⽥⽦⽧⽨⽩⽪⽫⽬⽭⽮⽯⽰⽱⽲⽳⽴⽵⽶⽷⽸⽹⽺⽻⽼⽽⽾⽿';
$find = '⽤';
$result = mb_strpos($string, $find);
$expected = 31;
$this->assertEqual($expected, $result);
$string = '눡눢눣눤눥눦눧눨눩눪눫눬눭눮눯눰눱눲눳눴눵눶눷눸눹눺눻눼눽눾눿뉀뉁뉂뉃뉄뉅뉆뉇뉈뉉뉊뉋뉌뉍뉎뉏뉐뉑뉒뉓뉔뉕뉖뉗뉘뉙뉚뉛뉜뉝뉞뉟뉠뉡뉢뉣뉤뉥뉦뉧뉨뉩뉪뉫뉬뉭뉮뉯뉰뉱뉲뉳뉴뉵뉶뉷뉸뉹뉺뉻뉼뉽뉾뉿늀늁늂늃늄';
$find = '눻';
$result = mb_strpos($string, $find);
$expected = 26;
$this->assertEqual($expected, $result);
$string = 'ﹰﹱﹲﹳﹴﹶﹷﹸﹹﹺﹻﹼﹽﹾﹿﺀﺁﺂﺃﺄﺅﺆﺇﺈﺉﺊﺋﺌﺍﺎﺏﺐﺑﺒﺓﺔﺕﺖﺗﺘﺙﺚﺛﺜﺝﺞﺟﺠﺡﺢﺣﺤﺥﺦﺧﺨﺩﺪﺫﺬﺭﺮﺯﺰ';
$find = 'ﺞ';
$result = mb_strpos($string, $find);
$expected = 46;
$this->assertEqual($expected, $result);
$string = 'ﺱﺲﺳﺴﺵﺶﺷﺸﺹﺺﺻﺼﺽﺾﺿﻀﻁﻂﻃﻄﻅﻆﻇﻈﻉﻊﻋﻌﻍﻎﻏﻐﻑﻒﻓﻔﻕﻖﻗﻘﻙﻚﻛﻜﻝﻞﻟﻠﻡﻢﻣﻤﻥﻦﻧﻨﻩﻪﻫﻬﻭﻮﻯﻰﻱﻲﻳﻴﻵﻶﻷﻸﻹﻺﻻﻼ';
$find = 'ﻞ';
$result = mb_strpos($string, $find);
$expected = 45;
$this->assertEqual($expected, $result);
$string = 'abcdefghijklmnopqrstuvwxyz';
$find = 'k';
$result = mb_strpos($string, $find);
$expected = 10;
$this->assertEqual($expected, $result);
$string = 'abcdefghijklmnopqrstuvwxyz';
$find = 'k';
$result = mb_strpos($string, $find);
$expected = 10;
$this->assertEqual($expected, $result);
$string = '。「」、・ヲァィゥェォャュョッーアイウエオカキク';
$find = 'ア';
$result = mb_strpos($string, $find);
$expected = 16;
$this->assertEqual($expected, $result);
$string = 'ケコサシスセソタチツテトナニヌネノハヒフヘホマミムメモヤユヨラリルレロワン゙';
$find = 'ハ';
$result = mb_strpos($string, $find);
$expected = 17;
$this->assertEqual($expected, $result);
$string = 'Ĥēĺļŏ, Ŵőřļď!';
$find = 'ő';
$result = mb_strpos($string, $find);
$expected = 8;
$this->assertEqual($expected, $result);
$string = 'Ĥēĺļŏ, Ŵőřļď!';
$find = 'ő';
$result = mb_strpos($string, $find);
$expected = 8;
$this->assertEqual($expected, $result);
$string = 'Ĥēĺļŏ, Ŵőřļď!';
$find = 'őř';
$result = mb_strpos($string, $find);
$expected = 8;
$this->assertEqual($expected, $result);
$string = 'Hello, World!';
$find = 'o';
$result = mb_strpos($string, $find);
$expected = 4;
$this->assertEqual($expected, $result);
$string = 'Hello, World!';
$find = 'o';
$result = mb_strpos($string, $find, 5);
$expected = 8;
$this->assertEqual($expected, $result);
$string = 'čini';
$find = 'n';
$result = mb_strpos($string, $find);
$expected = 2;
$this->assertEqual($expected, $result);
$string = 'čini';
$find = 'n';
$result = mb_strpos($string, $find);
$expected = 2;
$this->assertEqual($expected, $result);
$string = 'moći';
$find = 'ć';
$result = mb_strpos($string, $find);
$expected = 2;
$this->assertEqual($expected, $result);
$string = 'moći';
$find = 'ć';
$result = mb_strpos($string, $find);
$expected = 2;
$this->assertEqual($expected, $result);
$string = 'državni';
$find = 'ž';
$result = mb_strpos($string, $find);
$expected = 2;
$this->assertEqual($expected, $result);
$string = '把百度设为首页';
$find = '设';
$result = mb_strpos($string, $find);
$expected = 3;
$this->assertEqual($expected, $result);
$string = '一二三周永龍';
$find = '周';
$result = mb_strpos($string, $find);
$expected = 3;
$this->assertEqual($expected, $result);
$string = '一二三周永龍';
$find = '一周';
$result = mb_strpos($string, $find);
$expected = false;
$this->assertEqual($expected, $result);
}
/**
* testMultibyteStrpos method
*
* @return void
*/
public function testMultibyteStrpos() {
$string = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
$find = 'F';
$result = Multibyte::strpos($string, $find);
$expected = 5;
$this->assertEqual($expected, $result);
$string = 'ABCDEFGHIJKLMNOPQFRSTUVWXYZ0123456789';
$find = 'F';
$result = Multibyte::strpos($string, $find, 6);
$expected = 17;
$this->assertEqual($expected, $result);
$string = 'ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞ';
$find = 'Å';
$result = Multibyte::strpos($string, $find);
$expected = 5;
$this->assertEqual($expected, $result);
$string = 'ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÅÙÚÛÜÝÞ';
$find = 'Å';
$result = Multibyte::strpos($string, $find, 6);
$expected = 24;
$this->assertEqual($expected, $result);
$string = 'ĀĂĄĆĈĊČĎĐĒĔĖĘĚĜĞĠĢĤĦĨĪĬĮIJĴĶĹĻĽĿŁŃŅŇŊŌŎŐŒŔŖŘŚŜŞŠŢŤŦŨŪŬŮŰŲŴŶŹŻŽ';
$find = 'Ċ';
$result = Multibyte::strpos($string, $find);
$expected = 5;
$this->assertEqual($expected, $result);
$string = 'ĀĂĄĆĈĊČĎĐĒĔĖĘĚĜĞĠĢĤĦĨĪĬĮIJĴĶĹĻĽĿŁĊŃŅŇŊŌŎŐŒŔŖŘŚŜŞŠŢŤŦŨŪŬŮŰŲŴŶŹŻŽ';
$find = 'Ċ';
$result = Multibyte::strpos($string, $find, 6);
$expected = 32;
$this->assertEqual($expected, $result);
$string = '!"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~';
$find = 'F';
$result = Multibyte::strpos($string, $find);
$expected = 37;
$this->assertEqual($expected, $result);
$string = '¡¢£¤¥¦§¨©ª«¬®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈ';
$find = 'µ';
$result = Multibyte::strpos($string, $find);
$expected = 20;
$this->assertEqual($expected, $result);
$string = 'ÉÊËÌÍÎÏÐÑÒÓÔÕÖרÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿĀāĂ㥹ĆćĈĉĊċČčĎďĐđĒēĔĕĖėĘęĚěĜĝĞğĠġĢģĤĥĦħĨĩĪīĬ';
$find = 'é';
$result = Multibyte::strpos($string, $find);
$expected = 32;
$this->assertEqual($expected, $result);
$string = 'ĭĮįİıIJijĴĵĶķĸĹĺĻļĽľĿŀŁłŃńŅņŇňʼnŊŋŌōŎŏŐőŒœŔŕŖŗŘřŚśŜŝŞşŠšŢţŤťŦŧŨũŪūŬŭŮůŰűŲųŴŵŶŷŸŹźŻżŽžſƀƁƂƃƄƅƆƇƈƉƊƋƌƍƎƏƐ';
$find = 'Ņ';
$result = Multibyte::strpos($string, $find);
$expected = 24;
$this->assertEqual($expected, $result);
$string = 'ƑƒƓƔƕƖƗƘƙƚƛƜƝƞƟƠơƢƣƤƥƦƧƨƩƪƫƬƭƮƯưƱƲƳƴƵƶƷƸƹƺƻƼƽƾƿǀǁǂǃDŽDždžLJLjljNJNjnjǍǎǏǐǑǒǓǔǕǖǗǘǙǚǛǜǝǞǟǠǡǢǣǤǥǦǧǨǩǪǫǬǭǮǯǰDZDzdzǴ';
$find = 'Ƹ';
$result = Multibyte::strpos($string, $find);
$expected = 39;
$this->assertEqual($expected, $result);
$string = 'ƑƒƓƔƕƖƗƘƙƚƛƜƝƞƟƠơƢƣƤƥƦƧƨƩƪƫƬƭƮƯưƱƲƳƴƵƶƷƸƹƺƻƼƽƾƿǀǁǂǃDŽDždžLJLjljNJNjnjǍǎǏǐǑǒǓǔǕǖǗǘǙǚǛǜǝǞǟǠǡǢǣǤǥǦǧǨǩǪǫǬǭǮǯǰDZDzdzǴ';
$find = 'ƹ';
$result = Multibyte::strpos($string, $find);
$expected = 40;
$this->assertEqual($expected, $result);
$string = 'əɚɛɜɝɞɟɠɡɢɣɤɥɦɧɨɩɪɫɬɭɮɯɰɱɲɳɴɵɶɷɸɹɺɻɼɽɾɿʀʁʂʃʄʅʆʇʈʉʊʋʌʍʎʏʐʑʒʓʔʕʖʗʘʙʚʛʜʝʞʟʠʡʢʣʤʥʦʧʨʩʪʫʬʭʮʯʰʱʲʳʴʵʶʷʸʹʺʻʼ';
$find = 'ʀ';
$result = Multibyte::strpos($string, $find);
$expected = 39;
$this->assertEqual($expected, $result);
$string = 'ЀЁЂЃЄЅІЇЈЉЊЋЌЍЎЏАБВГДЕЖЗИЙКЛ';
$find = 'Ї';
$result = Multibyte::strpos($string, $find);
$expected = 7;
$this->assertEqual($expected, $result);
$string = 'МНОПРСТУФХЦЧШЩЪЫЬЭЮЯабвгдежзийклмнопрстуфхцчшщъыь';
$find = 'Р';
$result = Multibyte::strpos($string, $find);
$expected = 4;
$this->assertEqual($expected, $result);
$string = 'МНОПРСТУФХЦЧШЩЪЫЬЭЮЯабвгдежзийклмнопрстуфхцчшщъыь';
$find = 'р';
$result = Multibyte::strpos($string, $find, 5);
$expected = 36;
$this->assertEqual($expected, $result);
$string = 'فقكلمنهوىيًٌٍَُ';
$find = 'ن';
$result = Multibyte::strpos($string, $find);
$expected = 5;
$this->assertEqual($expected, $result);
$string = '✰✱✲✳✴✵✶✷✸✹✺✻✼✽✾✿❀❁❂❃❄❅❆❇❈❉❊❋❌❍❎❏❐❑❒❓❔❕❖❗❘❙❚❛❜❝❞';
$find = '✿';
$result = Multibyte::strpos($string, $find);
$expected = 15;
$this->assertEqual($expected, $result);
$string = '⺀⺁⺂⺃⺄⺅⺆⺇⺈⺉⺊⺋⺌⺍⺎⺏⺐⺑⺒⺓⺔⺕⺖⺗⺘⺙⺛⺜⺝⺞⺟⺠⺡⺢⺣⺤⺥⺦⺧⺨⺩⺪⺫⺬⺭⺮⺯⺰⺱⺲⺳⺴⺵⺶⺷⺸⺹⺺⺻⺼⺽⺾⺿⻀⻁⻂⻃⻄⻅⻆⻇⻈⻉⻊⻋⻌⻍⻎⻏⻐⻑⻒⻓⻔⻕⻖⻗⻘⻙⻚⻛⻜⻝⻞⻟⻠';
$find = '⺐';
$result = Multibyte::strpos($string, $find);
$expected = 16;
$this->assertEqual($expected, $result);
$string = '⽅⽆⽇⽈⽉⽊⽋⽌⽍⽎⽏⽐⽑⽒⽓⽔⽕⽖⽗⽘⽙⽚⽛⽜⽝⽞⽟⽠⽡⽢⽣⽤⽥⽦⽧⽨⽩⽪⽫⽬⽭⽮⽯⽰⽱⽲⽳⽴⽵⽶⽷⽸⽹⽺⽻⽼⽽⽾⽿';
$find = '⽤';
$result = Multibyte::strpos($string, $find);
$expected = 31;
$this->assertEqual($expected, $result);
$string = '눡눢눣눤눥눦눧눨눩눪눫눬눭눮눯눰눱눲눳눴눵눶눷눸눹눺눻눼눽눾눿뉀뉁뉂뉃뉄뉅뉆뉇뉈뉉뉊뉋뉌뉍뉎뉏뉐뉑뉒뉓뉔뉕뉖뉗뉘뉙뉚뉛뉜뉝뉞뉟뉠뉡뉢뉣뉤뉥뉦뉧뉨뉩뉪뉫뉬뉭뉮뉯뉰뉱뉲뉳뉴뉵뉶뉷뉸뉹뉺뉻뉼뉽뉾뉿늀늁늂늃늄';
$find = '눻';
$result = Multibyte::strpos($string, $find);
$expected = 26;
$this->assertEqual($expected, $result);
$string = 'ﹰﹱﹲﹳﹴﹶﹷﹸﹹﹺﹻﹼﹽﹾﹿﺀﺁﺂﺃﺄﺅﺆﺇﺈﺉﺊﺋﺌﺍﺎﺏﺐﺑﺒﺓﺔﺕﺖﺗﺘﺙﺚﺛﺜﺝﺞﺟﺠﺡﺢﺣﺤﺥﺦﺧﺨﺩﺪﺫﺬﺭﺮﺯﺰ';
$find = 'ﺞ';
$result = Multibyte::strpos($string, $find);
$expected = 46;
$this->assertEqual($expected, $result);
$string = 'ﺱﺲﺳﺴﺵﺶﺷﺸﺹﺺﺻﺼﺽﺾﺿﻀﻁﻂﻃﻄﻅﻆﻇﻈﻉﻊﻋﻌﻍﻎﻏﻐﻑﻒﻓﻔﻕﻖﻗﻘﻙﻚﻛﻜﻝﻞﻟﻠﻡﻢﻣﻤﻥﻦﻧﻨﻩﻪﻫﻬﻭﻮﻯﻰﻱﻲﻳﻴﻵﻶﻷﻸﻹﻺﻻﻼ';
$find = 'ﻞ';
$result = Multibyte::strpos($string, $find);
$expected = 45;
$this->assertEqual($expected, $result);
$string = 'abcdefghijklmnopqrstuvwxyz';
$find = 'k';
$result = Multibyte::strpos($string, $find);
$expected = 10;
$this->assertEqual($expected, $result);
$string = 'abcdefghijklmnopqrstuvwxyz';
$find = 'k';
$result = Multibyte::strpos($string, $find);
$expected = 10;
$this->assertEqual($expected, $result);
$string = '。「」、・ヲァィゥェォャュョッーアイウエオカキク';
$find = 'ア';
$result = Multibyte::strpos($string, $find);
$expected = 16;
$this->assertEqual($expected, $result);
$string = 'ケコサシスセソタチツテトナニヌネノハヒフヘホマミムメモヤユヨラリルレロワン゙';
$find = 'ハ';
$result = Multibyte::strpos($string, $find);
$expected = 17;
$this->assertEqual($expected, $result);
$string = 'Ĥēĺļŏ, Ŵőřļď!';
$find = 'ő';
$result = Multibyte::strpos($string, $find);
$expected = 8;
$this->assertEqual($expected, $result);
$string = 'Ĥēĺļŏ, Ŵőřļď!';
$find = 'ő';
$result = Multibyte::strpos($string, $find);
$expected = 8;
$this->assertEqual($expected, $result);
$string = 'Ĥēĺļŏ, Ŵőřļď!';
$find = 'őř';
$result = Multibyte::strpos($string, $find);
$expected = 8;
$this->assertEqual($expected, $result);
$string = 'Hello, World!';
$find = 'o';
$result = Multibyte::strpos($string, $find);
$expected = 4;
$this->assertEqual($expected, $result);
$string = 'Hello, World!';
$find = 'o';
$result = Multibyte::strpos($string, $find, 5);
$expected = 8;
$this->assertEqual($expected, $result);
$string = 'čini';
$find = 'n';
$result = Multibyte::strpos($string, $find);
$expected = 2;
$this->assertEqual($expected, $result);
$string = 'čini';
$find = 'n';
$result = Multibyte::strpos($string, $find);
$expected = 2;
$this->assertEqual($expected, $result);
$string = 'moći';
$find = 'ć';
$result = Multibyte::strpos($string, $find);
$expected = 2;
$this->assertEqual($expected, $result);
$string = 'moći';
$find = 'ć';
$result = Multibyte::strpos($string, $find);
$expected = 2;
$this->assertEqual($expected, $result);
$string = 'državni';
$find = 'ž';
$result = Multibyte::strpos($string, $find);
$expected = 2;
$this->assertEqual($expected, $result);
$string = '把百度设为首页';
$find = '设';
$result = Multibyte::strpos($string, $find);
$expected = 3;
$this->assertEqual($expected, $result);
$string = '一二三周永龍';
$find = '周';
$result = Multibyte::strpos($string, $find);
$expected = 3;
$this->assertEqual($expected, $result);
$string = '一二三周永龍';
$find = '一周';
$result = Multibyte::strpos($string, $find);
$expected = false;
$this->assertEqual($expected, $result);
}
/**
* testUsingMbStrrchr method
*
* @return void
*/
public function testUsingMbStrrchr() {
$string = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
$find = 'F';
$result = mb_strrchr($string, $find);
$expected = 'FGHIJKLMNOPQRSTUVWXYZ0123456789';
$this->assertEqual($expected, $result);
$string = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
$find = 'F';
$result = mb_strrchr($string, $find, true);
$expected = 'ABCDE';
$this->assertEqual($expected, $result);
$string = 'ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞ';
$find = 'Å';
$result = mb_strrchr($string, $find);
$expected = 'ÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞ';
$this->assertEqual($expected, $result);
$string = 'ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞ';
$find = 'Å';
$result = mb_strrchr($string, $find, true);
$expected = 'ÀÁÂÃÄ';
$this->assertEqual($expected, $result);
$string = 'ĀĂĄĆĈĊČĎĐĒĔĖĘĚĜĞĠĢĤĦĨĪĬĮIJĴĶĹĻĽĿŁŃŅŇŊŌŎŐŒŔŖŘŚŜŞŠŢŤŦŨŪŬŮŰŲŴŶŹŻŽ';
$find = 'Ċ';
$result = mb_strrchr($string, $find);
$expected = 'ĊČĎĐĒĔĖĘĚĜĞĠĢĤĦĨĪĬĮIJĴĶĹĻĽĿŁŃŅŇŊŌŎŐŒŔŖŘŚŜŞŠŢŤŦŨŪŬŮŰŲŴŶŹŻŽ';
$this->assertEqual($expected, $result);
$string = 'ĀĂĄĆĈĊČĎĐĒĔĖĘĚĜĞĠĢĤĦĨĪĬĮIJĴĶĹĻĽĿŁŃŅŇŊŌŎŐŒŔŖŘŚŜŞŠŢŤŦŨŪŬŮŰŲŴŶŹŻŽ';
$find = 'Ċ';
$result = mb_strrchr($string, $find, true);
$expected = 'ĀĂĄĆĈ';
$this->assertEqual($expected, $result);
$string = '!"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~';
$find = 'F';
$result = mb_strrchr($string, $find);
$expected = 'FGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~';
$this->assertEqual($expected, $result);
$string = '!"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~';
$find = 'F';
$result = mb_strrchr($string, $find, true);
$expected = '!"#$%&\'()*+,-./0123456789:;<=>?@ABCDE';
$this->assertEqual($expected, $result);
$string = '¡¢£¤¥¦§¨©ª«¬®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈ';
$find = 'µ';
$result = mb_strrchr($string, $find);
$expected = 'µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈ';
$this->assertEqual($expected, $result);
$string = '¡¢£¤¥¦§¨©ª«¬®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈ';
$find = 'µ';
$result = mb_strrchr($string, $find, true);
$expected = '¡¢£¤¥¦§¨©ª«¬®¯°±²³´';
$this->assertEqual($expected, $result);
$string = 'ÉÊËÌÍÎÏÐÑÒÓÔÕÖרÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿĀāĂ㥹ĆćĈĉĊċČčĎďĐđĒēĔĕĖėĘęĚěĜĝĞğĠġĢģĤĥĦħĨĩĪīĬ';
$find = 'Þ';
$result = mb_strrchr($string, $find);
$expected = 'Þßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿĀāĂ㥹ĆćĈĉĊċČčĎďĐđĒēĔĕĖėĘęĚěĜĝĞğĠġĢģĤĥĦħĨĩĪīĬ';
$this->assertEqual($expected, $result);
$string = 'ÉÊËÌÍÎÏÐÑÒÓÔÕÖרÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿĀāĂ㥹ĆćĈĉĊċČčĎďĐđĒēĔĕĖėĘęĚěĜĝĞğĠġĢģĤĥĦħĨĩĪīĬ';
$find = 'Þ';
$result = mb_strrchr($string, $find, true);
$expected = 'ÉÊËÌÍÎÏÐÑÒÓÔÕÖרÙÚÛÜÝ';
$this->assertEqual($expected, $result);
$string = 'ĭĮįİıIJijĴĵĶķĸĹĺĻļĽľĿŀŁłŃńŅņŇňʼnŊŋŌōŎŏŐőŒœŔŕŖŗŘřŚśŜŝŞşŠšŢţŤťŦŧŨũŪūŬŭŮůŰűŲųŴŵŶŷŸŹźŻżŽžſƀƁƂƃƄƅƆƇƈƉƊƋƌƍƎƏƐ';
$find = 'Ņ';
$result = mb_strrchr($string, $find);
$expected = 'ŅņŇňʼnŊŋŌōŎŏŐőŒœŔŕŖŗŘřŚśŜŝŞşŠšŢţŤťŦŧŨũŪūŬŭŮůŰűŲųŴŵŶŷŸŹźŻżŽžſƀƁƂƃƄƅƆƇƈƉƊƋƌƍƎƏƐ';
$this->assertEqual($expected, $result);
$string = 'ĭĮįİıIJijĴĵĶķĸĹĺĻļĽľĿŀŁłŃńŅņŇňʼnŊŋŌōŎŏŐőŒœŔŕŖŗŘřŚśŜŝŞşŠšŢţŤťŦŧŨũŪūŬŭŮůŰűŲųŴŵŶŷŸŹźŻżŽžſƀƁƂƃƄƅƆƇƈƉƊƋƌƍƎƏƐ';
$find = 'Ņ';
$result = mb_strrchr($string, $find, true);
$expected = 'ĭĮįİıIJijĴĵĶķĸĹĺĻļĽľĿŀŁłŃń';
$this->assertEqual($expected, $result);
$string = 'ƑƒƓƔƕƖƗƘƙƚƛƜƝƞƟƠơƢƣƤƥƦƧƨƩƪƫƬƭƮƯưƱƲƳƴƵƶƷƸƹƺƻƼƽƾƿǀǁǂǃDŽDždžLJLjljNJNjnjǍǎǏǐǑǒǓǔǕǖǗǘǙǚǛǜǝǞǟǠǡǢǣǤǥǦǧǨǩǪǫǬǭǮǯǰDZDzdzǴ';
$find = 'Ƹ';
$result = mb_strrchr($string, $find);
$expected = 'ƸƹƺƻƼƽƾƿǀǁǂǃDŽDždžLJLjljNJNjnjǍǎǏǐǑǒǓǔǕǖǗǘǙǚǛǜǝǞǟǠǡǢǣǤǥǦǧǨǩǪǫǬǭǮǯǰDZDzdzǴ';
$this->assertEqual($expected, $result);
$find = 'Ƹ';
$result = mb_strrchr($string, $find, true);
$expected = 'ƑƒƓƔƕƖƗƘƙƚƛƜƝƞƟƠơƢƣƤƥƦƧƨƩƪƫƬƭƮƯưƱƲƳƴƵƶƷ';
$this->assertEqual($expected, $result);
$string = 'əɚɛɜɝɞɟɠɡɢɣɤɥɦɧɨɩɪɫɬɭɮɯɰɱɲɳɴɵɶɷɸɹɺɻɼɽɾɿʀʁʂʃʄʅʆʇʈʉʊʋʌʍʎʏʐʑʒʓʔʕʖʗʘʙʚʛʜʝʞʟʠʡʢʣʤʥʦʧʨʩʪʫʬʭʮʯʰʱʲʳʴʵʶʷʸʹʺʻʼ';
$find = 'ʀ';
$result = mb_strrchr($string, $find);
$expected = 'ʀʁʂʃʄʅʆʇʈʉʊʋʌʍʎʏʐʑʒʓʔʕʖʗʘʙʚʛʜʝʞʟʠʡʢʣʤʥʦʧʨʩʪʫʬʭʮʯʰʱʲʳʴʵʶʷʸʹʺʻʼ';
$this->assertEqual($expected, $result);
$string = 'əɚɛɜɝɞɟɠɡɢɣɤɥɦɧɨɩɪɫɬɭɮɯɰɱɲɳɴɵɶɷɸɹɺɻɼɽɾɿʀʁʂʃʄʅʆʇʈʉʊʋʌʍʎʏʐʑʒʓʔʕʖʗʘʙʚʛʜʝʞʟʠʡʢʣʤʥʦʧʨʩʪʫʬʭʮʯʰʱʲʳʴʵʶʷʸʹʺʻʼ';
$find = 'ʀ';
$result = mb_strrchr($string, $find, true);
$expected = 'əɚɛɜɝɞɟɠɡɢɣɤɥɦɧɨɩɪɫɬɭɮɯɰɱɲɳɴɵɶɷɸɹɺɻɼɽɾɿ';
$this->assertEqual($expected, $result);
$string = 'ЀЁЂЃЄЅІЇЈЉЊЋЌЍЎЏАБВГДЕЖЗИЙКЛ';
$find = 'Ї';
$result = mb_strrchr($string, $find);
$expected = 'ЇЈЉЊЋЌЍЎЏАБВГДЕЖЗИЙКЛ';
$this->assertEqual($expected, $result);
$string = 'ЀЁЂЃЄЅІЇЈЉЊЋЌЍЎЏАБВГДЕЖЗИЙКЛ';
$find = 'Ї';
$result = mb_strrchr($string, $find, true);
$expected = 'ЀЁЂЃЄЅІ';
$this->assertEqual($expected, $result);
$string = 'МНОПРСТУФХЦЧШЩЪЫЬЭЮЯабвгдежзийклмнопрстуфхцчшщъыь';
$find = 'Р';
$result = mb_strrchr($string, $find);
$expected = 'РСТУФХЦЧШЩЪЫЬЭЮЯабвгдежзийклмнопрстуфхцчшщъыь';
$this->assertEqual($expected, $result);
$string = 'МНОПРСТУФХЦЧШЩЪЫЬЭЮЯабвгдежзийклмнопрстуфхцчшщъыь';
$find = 'Р';
$result = mb_strrchr($string, $find, true);
$expected = 'МНОП';
$this->assertEqual($expected, $result);
$string = 'فقكلمنهوىيًٌٍَُ';
$find = 'ن';
$result = mb_strrchr($string, $find);
$expected = 'نهوىيًٌٍَُ';
$this->assertEqual($expected, $result);
$string = 'فقكلمنهوىيًٌٍَُ';
$find = 'ن';
$result = mb_strrchr($string, $find, true);
$expected = 'فقكلم';
$this->assertEqual($expected, $result);
$string = '✰✱✲✳✴✵✶✷✸✹✺✻✼✽✾✿❀❁❂❃❄❅❆❇❈❉❊❋❌❍❎❏❐❑❒❓❔❕❖❗❘❙❚❛❜❝❞';
$find = '✿';
$result = mb_strrchr($string, $find);
$expected = '✿❀❁❂❃❄❅❆❇❈❉❊❋❌❍❎❏❐❑❒❓❔❕❖❗❘❙❚❛❜❝❞';
$this->assertEqual($expected, $result);
$string = '✰✱✲✳✴✵✶✷✸✹✺✻✼✽✾✿❀❁❂❃❄❅❆❇❈❉❊❋❌❍❎❏❐❑❒❓❔❕❖❗❘❙❚❛❜❝❞';
$find = '✿';
$result = mb_strrchr($string, $find, true);
$expected = '✰✱✲✳✴✵✶✷✸✹✺✻✼✽✾';
$this->assertEqual($expected, $result);
$string = '⺀⺁⺂⺃⺄⺅⺆⺇⺈⺉⺊⺋⺌⺍⺎⺏⺐⺑⺒⺓⺔⺕⺖⺗⺘⺙⺛⺜⺝⺞⺟⺠⺡⺢⺣⺤⺥⺦⺧⺨⺩⺪⺫⺬⺭⺮⺯⺰⺱⺲⺳⺴⺵⺶⺷⺸⺹⺺⺻⺼⺽⺾⺿⻀⻁⻂⻃⻄⻅⻆⻇⻈⻉⻊⻋⻌⻍⻎⻏⻐⻑⻒⻓⻔⻕⻖⻗⻘⻙⻚⻛⻜⻝⻞⻟⻠';
$find = '⺐';
$result = mb_strrchr($string, $find);
$expected = '⺐⺑⺒⺓⺔⺕⺖⺗⺘⺙⺛⺜⺝⺞⺟⺠⺡⺢⺣⺤⺥⺦⺧⺨⺩⺪⺫⺬⺭⺮⺯⺰⺱⺲⺳⺴⺵⺶⺷⺸⺹⺺⺻⺼⺽⺾⺿⻀⻁⻂⻃⻄⻅⻆⻇⻈⻉⻊⻋⻌⻍⻎⻏⻐⻑⻒⻓⻔⻕⻖⻗⻘⻙⻚⻛⻜⻝⻞⻟⻠';
$this->assertEqual($expected, $result);
$string = '⺀⺁⺂⺃⺄⺅⺆⺇⺈⺉⺊⺋⺌⺍⺎⺏⺐⺑⺒⺓⺔⺕⺖⺗⺘⺙⺛⺜⺝⺞⺟⺠⺡⺢⺣⺤⺥⺦⺧⺨⺩⺪⺫⺬⺭⺮⺯⺰⺱⺲⺳⺴⺵⺶⺷⺸⺹⺺⺻⺼⺽⺾⺿⻀⻁⻂⻃⻄⻅⻆⻇⻈⻉⻊⻋⻌⻍⻎⻏⻐⻑⻒⻓⻔⻕⻖⻗⻘⻙⻚⻛⻜⻝⻞⻟⻠';
$find = '⺐';
$result = mb_strrchr($string, $find, true);
$expected = '⺀⺁⺂⺃⺄⺅⺆⺇⺈⺉⺊⺋⺌⺍⺎⺏';
$this->assertEqual($expected, $result);
$string = '⽅⽆⽇⽈⽉⽊⽋⽌⽍⽎⽏⽐⽑⽒⽓⽔⽕⽖⽗⽘⽙⽚⽛⽜⽝⽞⽟⽠⽡⽢⽣⽤⽥⽦⽧⽨⽩⽪⽫⽬⽭⽮⽯⽰⽱⽲⽳⽴⽵⽶⽷⽸⽹⽺⽻⽼⽽⽾⽿';
$find = '⽤';
$result = mb_strrchr($string, $find);
$expected = '⽤⽥⽦⽧⽨⽩⽪⽫⽬⽭⽮⽯⽰⽱⽲⽳⽴⽵⽶⽷⽸⽹⽺⽻⽼⽽⽾⽿';
$this->assertEqual($expected, $result);
$string = '⽅⽆⽇⽈⽉⽊⽋⽌⽍⽎⽏⽐⽑⽒⽓⽔⽕⽖⽗⽘⽙⽚⽛⽜⽝⽞⽟⽠⽡⽢⽣⽤⽥⽦⽧⽨⽩⽪⽫⽬⽭⽮⽯⽰⽱⽲⽳⽴⽵⽶⽷⽸⽹⽺⽻⽼⽽⽾⽿';
$find = '⽤';
$result = mb_strrchr($string, $find, true);
$expected = '⽅⽆⽇⽈⽉⽊⽋⽌⽍⽎⽏⽐⽑⽒⽓⽔⽕⽖⽗⽘⽙⽚⽛⽜⽝⽞⽟⽠⽡⽢⽣';
$this->assertEqual($expected, $result);
$string = '눡눢눣눤눥눦눧눨눩눪눫눬눭눮눯눰눱눲눳눴눵눶눷눸눹눺눻눼눽눾눿뉀뉁뉂뉃뉄뉅뉆뉇뉈뉉뉊뉋뉌뉍뉎뉏뉐뉑뉒뉓뉔뉕뉖뉗뉘뉙뉚뉛뉜뉝뉞뉟뉠뉡뉢뉣뉤뉥뉦뉧뉨뉩뉪뉫뉬뉭뉮뉯뉰뉱뉲뉳뉴뉵뉶뉷뉸뉹뉺뉻뉼뉽뉾뉿늀늁늂늃늄';
$find = '눻';
$result = mb_strrchr($string, $find);
$expected = '눻눼눽눾눿뉀뉁뉂뉃뉄뉅뉆뉇뉈뉉뉊뉋뉌뉍뉎뉏뉐뉑뉒뉓뉔뉕뉖뉗뉘뉙뉚뉛뉜뉝뉞뉟뉠뉡뉢뉣뉤뉥뉦뉧뉨뉩뉪뉫뉬뉭뉮뉯뉰뉱뉲뉳뉴뉵뉶뉷뉸뉹뉺뉻뉼뉽뉾뉿늀늁늂늃늄';
$this->assertEqual($expected, $result);
$string = '눡눢눣눤눥눦눧눨눩눪눫눬눭눮눯눰눱눲눳눴눵눶눷눸눹눺눻눼눽눾눿뉀뉁뉂뉃뉄뉅뉆뉇뉈뉉뉊뉋뉌뉍뉎뉏뉐뉑뉒뉓뉔뉕뉖뉗뉘뉙뉚뉛뉜뉝뉞뉟뉠뉡뉢뉣뉤뉥뉦뉧뉨뉩뉪뉫뉬뉭뉮뉯뉰뉱뉲뉳뉴뉵뉶뉷뉸뉹뉺뉻뉼뉽뉾뉿늀늁늂늃늄';
$find = '눻';
$result = mb_strrchr($string, $find, true);
$expected = '눡눢눣눤눥눦눧눨눩눪눫눬눭눮눯눰눱눲눳눴눵눶눷눸눹눺';
$this->assertEqual($expected, $result);
$string = 'ﹰﹱﹲﹳﹴﹶﹷﹸﹹﹺﹻﹼﹽﹾﹿﺀﺁﺂﺃﺄﺅﺆﺇﺈﺉﺊﺋﺌﺍﺎﺏﺐﺑﺒﺓﺔﺕﺖﺗﺘﺙﺚﺛﺜﺝﺞﺟﺠﺡﺢﺣﺤﺥﺦﺧﺨﺩﺪﺫﺬﺭﺮﺯﺰ';
$find = 'ﺞ';
$result = mb_strrchr($string, $find);
$expected = 'ﺞﺟﺠﺡﺢﺣﺤﺥﺦﺧﺨﺩﺪﺫﺬﺭﺮﺯﺰ';
$this->assertEqual($expected, $result);
$string = 'ﹰﹱﹲﹳﹴﹶﹷﹸﹹﹺﹻﹼﹽﹾﹿﺀﺁﺂﺃﺄﺅﺆﺇﺈﺉﺊﺋﺌﺍﺎﺏﺐﺑﺒﺓﺔﺕﺖﺗﺘﺙﺚﺛﺜﺝﺞﺟﺠﺡﺢﺣﺤﺥﺦﺧﺨﺩﺪﺫﺬﺭﺮﺯﺰ';
$find = 'ﺞ';
$result = mb_strrchr($string, $find, true);
$expected = 'ﹰﹱﹲﹳﹴﹶﹷﹸﹹﹺﹻﹼﹽﹾﹿﺀﺁﺂﺃﺄﺅﺆﺇﺈﺉﺊﺋﺌﺍﺎﺏﺐﺑﺒﺓﺔﺕﺖﺗﺘﺙﺚﺛﺜﺝ';
$this->assertEqual($expected, $result);
$string = 'ﺱﺲﺳﺴﺵﺶﺷﺸﺹﺺﺻﺼﺽﺾﺿﻀﻁﻂﻃﻄﻅﻆﻇﻈﻉﻊﻋﻌﻍﻎﻏﻐﻑﻒﻓﻔﻕﻖﻗﻘﻙﻚﻛﻜﻝﻞﻟﻠﻡﻢﻣﻤﻥﻦﻧﻨﻩﻪﻫﻬﻭﻮﻯﻰﻱﻲﻳﻴﻵﻶﻷﻸﻹﻺﻻﻼ';
$find = 'ﻞ';
$result = mb_strrchr($string, $find);
$expected = 'ﻞﻟﻠﻡﻢﻣﻤﻥﻦﻧﻨﻩﻪﻫﻬﻭﻮﻯﻰﻱﻲﻳﻴﻵﻶﻷﻸﻹﻺﻻﻼ';
$this->assertEqual($expected, $result);
$string = 'ﺱﺲﺳﺴﺵﺶﺷﺸﺹﺺﺻﺼﺽﺾﺿﻀﻁﻂﻃﻄﻅﻆﻇﻈﻉﻊﻋﻌﻍﻎﻏﻐﻑﻒﻓﻔﻕﻖﻗﻘﻙﻚﻛﻜﻝﻞﻟﻠﻡﻢﻣﻤﻥﻦﻧﻨﻩﻪﻫﻬﻭﻮﻯﻰﻱﻲﻳﻴﻵﻶﻷﻸﻹﻺﻻﻼ';
$find = 'ﻞ';
$result = mb_strrchr($string, $find, true);
$expected = 'ﺱﺲﺳﺴﺵﺶﺷﺸﺹﺺﺻﺼﺽﺾﺿﻀﻁﻂﻃﻄﻅﻆﻇﻈﻉﻊﻋﻌﻍﻎﻏﻐﻑﻒﻓﻔﻕﻖﻗﻘﻙﻚﻛﻜﻝ';
$this->assertEqual($expected, $result);
$string = 'abcdefghijklmnopqrstuvwxyz';
$find = 'k';
$result = mb_strrchr($string, $find);
$expected = 'klmnopqrstuvwxyz';
$this->assertEqual($expected, $result);
$string = 'abcdefghijklmnopqrstuvwxyz';
$find = 'k';
$result = mb_strrchr($string, $find, true);
$expected = 'abcdefghij';
$this->assertEqual($expected, $result);
$string = '。「」、・ヲァィゥェォャュョッーアイウエオカキク';
$find = 'ア';
$result = mb_strrchr($string, $find);
$expected = 'アイウエオカキク';
$this->assertEqual($expected, $result);
$string = '。「」、・ヲァィゥェォャュョッーアイウエオカキク';
$find = 'ア';
$result = mb_strrchr($string, $find, true);
$expected = '。「」、・ヲァィゥェォャュョッー';
$this->assertEqual($expected, $result);
$string = 'ケコサシスセソタチツテトナニヌネノハヒフヘホマミムメモヤユヨラリルレロワン゙';
$find = 'ハ';
$result = mb_strrchr($string, $find);
$expected = 'ハヒフヘホマミムメモヤユヨラリルレロワン゙';
$this->assertEqual($expected, $result);
$string = 'ケコサシスセソタチツテトナニヌネノハヒフヘホマミムメモヤユヨラリルレロワン゙';
$find = 'ハ';
$result = mb_strrchr($string, $find, true);
$expected = 'ケコサシスセソタチツテトナニヌネノ';
$this->assertEqual($expected, $result);
$string = 'Ĥēĺļŏ, Ŵőřļď!';
$find = 'ő';
$result = mb_strrchr($string, $find);
$expected = 'őřļď!';
$this->assertEqual($expected, $result);
$string = 'Ĥēĺļŏ, Ŵőřļď!';
$find = 'ő';
$result = mb_strrchr($string, $find, true);
$expected = 'Ĥēĺļŏ, Ŵ';
$this->assertEqual($expected, $result);
$string = 'Hello, World!';
$find = 'o';
$result = mb_strrchr($string, $find);
$expected = 'orld!';
$this->assertEqual($expected, $result);
$string = 'Hello, World!';
$find = 'o';
$result = mb_strrchr($string, $find, true);
$expected = 'Hello, W';
$this->assertEqual($expected, $result);
$string = 'Hello, World!';
$find = 'Wo';
$result = mb_strrchr($string, $find);
$expected = 'World!';
$this->assertEqual($expected, $result);
$string = 'Hello, World!';
$find = 'Wo';
$result = mb_strrchr($string, $find, true);
$expected = 'Hello, ';
$this->assertEqual($expected, $result);
$string = 'Hello, World!';
$find = 'll';
$result = mb_strrchr($string, $find);
$expected = 'llo, World!';
$this->assertEqual($expected, $result);
$string = 'Hello, World!';
$find = 'll';
$result = mb_strrchr($string, $find, true);
$expected = 'He';
$this->assertEqual($expected, $result);
$string = 'Hello, World!';
$find = 'rld';
$result = mb_strrchr($string, $find);
$expected = 'rld!';
$this->assertEqual($expected, $result);
$string = 'Hello, World!';
$find = 'rld';
$result = mb_strrchr($string, $find, true);
$expected = 'Hello, Wo';
$this->assertEqual($expected, $result);
$string = 'čini';
$find = 'n';
$result = mb_strrchr($string, $find);
$expected = 'ni';
$this->assertEqual($expected, $result);
$string = 'čini';
$find = 'n';
$result = mb_strrchr($string, $find, true);
$expected = 'či';
$this->assertEqual($expected, $result);
$string = 'moći';
$find = 'ć';
$result = mb_strrchr($string, $find);
$expected = 'ći';
$this->assertEqual($expected, $result);
$string = 'moći';
$find = 'ć';
$result = mb_strrchr($string, $find, true);
$expected = 'mo';
$this->assertEqual($expected, $result);
$string = 'državni';
$find = 'ž';
$result = mb_strrchr($string, $find);
$expected = 'žavni';
$this->assertEqual($expected, $result);
$string = 'državni';
$find = 'ž';
$result = mb_strrchr($string, $find, true);
$expected = 'dr';
$this->assertEqual($expected, $result);
$string = '把百度设为首页';
$find = '设';
$result = mb_strrchr($string, $find);
$expected = '设为首页';
$this->assertEqual($expected, $result);
$string = '把百度设为首页';
$find = '设';
$result = mb_strrchr($string, $find, true);
$expected = '把百度';
$this->assertEqual($expected, $result);
$string = '一二三周永龍';
$find = '周';
$result = mb_strrchr($string, $find);
$expected = '周永龍';
$this->assertEqual($expected, $result);
$string = '一二三周永龍';
$find = '周';
$result = mb_strrchr($string, $find, true);
$expected = '一二三';
$this->assertEqual($expected, $result);
$string = '一二三周永龍';
$find = '周龍';
$result = mb_strrchr($string, $find, true);
$expected = false;
$this->assertEqual($expected, $result);
}
/**
* testMultibyteStrrchr method
*
* @return void
*/
public function testMultibyteStrrchr() {
$string = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
$find = 'F';
$result = Multibyte::strrchr($string, $find);
$expected = 'FGHIJKLMNOPQRSTUVWXYZ0123456789';
$this->assertEqual($expected, $result);
$string = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
$find = 'F';
$result = Multibyte::strrchr($string, $find, true);
$expected = 'ABCDE';
$this->assertEqual($expected, $result);
$string = 'ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞ';
$find = 'Å';
$result = Multibyte::strrchr($string, $find);
$expected = 'ÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞ';
$this->assertEqual($expected, $result);
$string = 'ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞ';
$find = 'Å';
$result = Multibyte::strrchr($string, $find, true);
$expected = 'ÀÁÂÃÄ';
$this->assertEqual($expected, $result);
$string = 'ĀĂĄĆĈĊČĎĐĒĔĖĘĚĜĞĠĢĤĦĨĪĬĮIJĴĶĹĻĽĿŁŃŅŇŊŌŎŐŒŔŖŘŚŜŞŠŢŤŦŨŪŬŮŰŲŴŶŹŻŽ';
$find = 'Ċ';
$result = Multibyte::strrchr($string, $find);
$expected = 'ĊČĎĐĒĔĖĘĚĜĞĠĢĤĦĨĪĬĮIJĴĶĹĻĽĿŁŃŅŇŊŌŎŐŒŔŖŘŚŜŞŠŢŤŦŨŪŬŮŰŲŴŶŹŻŽ';
$this->assertEqual($expected, $result);
$string = 'ĀĂĄĆĈĊČĎĐĒĔĖĘĚĜĞĠĢĤĦĨĪĬĮIJĴĶĹĻĽĿŁŃŅŇŊŌŎŐŒŔŖŘŚŜŞŠŢŤŦŨŪŬŮŰŲŴŶŹŻŽ';
$find = 'Ċ';
$result = Multibyte::strrchr($string, $find, true);
$expected = 'ĀĂĄĆĈ';
$this->assertEqual($expected, $result);
$string = '!"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~';
$find = 'F';
$result = Multibyte::strrchr($string, $find);
$expected = 'FGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~';
$this->assertEqual($expected, $result);
$string = '!"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~';
$find = 'F';
$result = Multibyte::strrchr($string, $find, true);
$expected = '!"#$%&\'()*+,-./0123456789:;<=>?@ABCDE';
$this->assertEqual($expected, $result);
$string = '¡¢£¤¥¦§¨©ª«¬®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈ';
$find = 'µ';
$result = Multibyte::strrchr($string, $find);
$expected = 'µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈ';
$this->assertEqual($expected, $result);
$string = '¡¢£¤¥¦§¨©ª«¬®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈ';
$find = 'µ';
$result = Multibyte::strrchr($string, $find, true);
$expected = '¡¢£¤¥¦§¨©ª«¬®¯°±²³´';
$this->assertEqual($expected, $result);
$string = 'ÉÊËÌÍÎÏÐÑÒÓÔÕÖרÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿĀāĂ㥹ĆćĈĉĊċČčĎďĐđĒēĔĕĖėĘęĚěĜĝĞğĠġĢģĤĥĦħĨĩĪīĬ';
$find = 'Þ';
$result = Multibyte::strrchr($string, $find);
$expected = 'Þßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿĀāĂ㥹ĆćĈĉĊċČčĎďĐđĒēĔĕĖėĘęĚěĜĝĞğĠġĢģĤĥĦħĨĩĪīĬ';
$this->assertEqual($expected, $result);
$string = 'ÉÊËÌÍÎÏÐÑÒÓÔÕÖרÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿĀāĂ㥹ĆćĈĉĊċČčĎďĐđĒēĔĕĖėĘęĚěĜĝĞğĠġĢģĤĥĦħĨĩĪīĬ';
$find = 'Þ';
$result = Multibyte::strrchr($string, $find, true);
$expected = 'ÉÊËÌÍÎÏÐÑÒÓÔÕÖרÙÚÛÜÝ';
$this->assertEqual($expected, $result);
$string = 'ĭĮįİıIJijĴĵĶķĸĹĺĻļĽľĿŀŁłŃńŅņŇňʼnŊŋŌōŎŏŐőŒœŔŕŖŗŘřŚśŜŝŞşŠšŢţŤťŦŧŨũŪūŬŭŮůŰűŲųŴŵŶŷŸŹźŻżŽžſƀƁƂƃƄƅƆƇƈƉƊƋƌƍƎƏƐ';
$find = 'Ņ';
$result = Multibyte::strrchr($string, $find);
$expected = 'ŅņŇňʼnŊŋŌōŎŏŐőŒœŔŕŖŗŘřŚśŜŝŞşŠšŢţŤťŦŧŨũŪūŬŭŮůŰűŲųŴŵŶŷŸŹźŻżŽžſƀƁƂƃƄƅƆƇƈƉƊƋƌƍƎƏƐ';
$this->assertEqual($expected, $result);
$string = 'ĭĮįİıIJijĴĵĶķĸĹĺĻļĽľĿŀŁłŃńŅņŇňʼnŊŋŌōŎŏŐőŒœŔŕŖŗŘřŚśŜŝŞşŠšŢţŤťŦŧŨũŪūŬŭŮůŰűŲųŴŵŶŷŸŹźŻżŽžſƀƁƂƃƄƅƆƇƈƉƊƋƌƍƎƏƐ';
$find = 'Ņ';
$result = Multibyte::strrchr($string, $find, true);
$expected = 'ĭĮįİıIJijĴĵĶķĸĹĺĻļĽľĿŀŁłŃń';
$this->assertEqual($expected, $result);
$string = 'ƑƒƓƔƕƖƗƘƙƚƛƜƝƞƟƠơƢƣƤƥƦƧƨƩƪƫƬƭƮƯưƱƲƳƴƵƶƷƸƹƺƻƼƽƾƿǀǁǂǃDŽDždžLJLjljNJNjnjǍǎǏǐǑǒǓǔǕǖǗǘǙǚǛǜǝǞǟǠǡǢǣǤǥǦǧǨǩǪǫǬǭǮǯǰDZDzdzǴ';
$find = 'Ƹ';
$result = Multibyte::strrchr($string, $find);
$expected = 'ƸƹƺƻƼƽƾƿǀǁǂǃDŽDždžLJLjljNJNjnjǍǎǏǐǑǒǓǔǕǖǗǘǙǚǛǜǝǞǟǠǡǢǣǤǥǦǧǨǩǪǫǬǭǮǯǰDZDzdzǴ';
$this->assertEqual($expected, $result);
$find = 'Ƹ';
$result = Multibyte::strrchr($string, $find, true);
$expected = 'ƑƒƓƔƕƖƗƘƙƚƛƜƝƞƟƠơƢƣƤƥƦƧƨƩƪƫƬƭƮƯưƱƲƳƴƵƶƷ';
$this->assertEqual($expected, $result);
$string = 'əɚɛɜɝɞɟɠɡɢɣɤɥɦɧɨɩɪɫɬɭɮɯɰɱɲɳɴɵɶɷɸɹɺɻɼɽɾɿʀʁʂʃʄʅʆʇʈʉʊʋʌʍʎʏʐʑʒʓʔʕʖʗʘʙʚʛʜʝʞʟʠʡʢʣʤʥʦʧʨʩʪʫʬʭʮʯʰʱʲʳʴʵʶʷʸʹʺʻʼ';
$find = 'ʀ';
$result = Multibyte::strrchr($string, $find);
$expected = 'ʀʁʂʃʄʅʆʇʈʉʊʋʌʍʎʏʐʑʒʓʔʕʖʗʘʙʚʛʜʝʞʟʠʡʢʣʤʥʦʧʨʩʪʫʬʭʮʯʰʱʲʳʴʵʶʷʸʹʺʻʼ';
$this->assertEqual($expected, $result);
$string = 'əɚɛɜɝɞɟɠɡɢɣɤɥɦɧɨɩɪɫɬɭɮɯɰɱɲɳɴɵɶɷɸɹɺɻɼɽɾɿʀʁʂʃʄʅʆʇʈʉʊʋʌʍʎʏʐʑʒʓʔʕʖʗʘʙʚʛʜʝʞʟʠʡʢʣʤʥʦʧʨʩʪʫʬʭʮʯʰʱʲʳʴʵʶʷʸʹʺʻʼ';
$find = 'ʀ';
$result = Multibyte::strrchr($string, $find, true);
$expected = 'əɚɛɜɝɞɟɠɡɢɣɤɥɦɧɨɩɪɫɬɭɮɯɰɱɲɳɴɵɶɷɸɹɺɻɼɽɾɿ';
$this->assertEqual($expected, $result);
$string = 'ЀЁЂЃЄЅІЇЈЉЊЋЌЍЎЏАБВГДЕЖЗИЙКЛ';
$find = 'Ї';
$result = Multibyte::strrchr($string, $find);
$expected = 'ЇЈЉЊЋЌЍЎЏАБВГДЕЖЗИЙКЛ';
$this->assertEqual($expected, $result);
$string = 'ЀЁЂЃЄЅІЇЈЉЊЋЌЍЎЏАБВГДЕЖЗИЙКЛ';
$find = 'Ї';
$result = Multibyte::strrchr($string, $find, true);
$expected = 'ЀЁЂЃЄЅІ';
$this->assertEqual($expected, $result);
$string = 'МНОПРСТУФХЦЧШЩЪЫЬЭЮЯабвгдежзийклмнопрстуфхцчшщъыь';
$find = 'Р';
$result = Multibyte::strrchr($string, $find);
$expected = 'РСТУФХЦЧШЩЪЫЬЭЮЯабвгдежзийклмнопрстуфхцчшщъыь';
$this->assertEqual($expected, $result);
$string = 'МНОПРСТУФХЦЧШЩЪЫЬЭЮЯабвгдежзийклмнопрстуфхцчшщъыь';
$find = 'Р';
$result = Multibyte::strrchr($string, $find, true);
$expected = 'МНОП';
$this->assertEqual($expected, $result);
$string = 'فقكلمنهوىيًٌٍَُ';
$find = 'ن';
$result = Multibyte::strrchr($string, $find);
$expected = 'نهوىيًٌٍَُ';
$this->assertEqual($expected, $result);
$string = 'فقكلمنهوىيًٌٍَُ';
$find = 'ن';
$result = Multibyte::strrchr($string, $find, true);
$expected = 'فقكلم';
$this->assertEqual($expected, $result);
$string = '✰✱✲✳✴✵✶✷✸✹✺✻✼✽✾✿❀❁❂❃❄❅❆❇❈❉❊❋❌❍❎❏❐❑❒❓❔❕❖❗❘❙❚❛❜❝❞';
$find = '✿';
$result = Multibyte::strrchr($string, $find);
$expected = '✿❀❁❂❃❄❅❆❇❈❉❊❋❌❍❎❏❐❑❒❓❔❕❖❗❘❙❚❛❜❝❞';
$this->assertEqual($expected, $result);
$string = '✰✱✲✳✴✵✶✷✸✹✺✻✼✽✾✿❀❁❂❃❄❅❆❇❈❉❊❋❌❍❎❏❐❑❒❓❔❕❖❗❘❙❚❛❜❝❞';
$find = '✿';
$result = Multibyte::strrchr($string, $find, true);
$expected = '✰✱✲✳✴✵✶✷✸✹✺✻✼✽✾';
$this->assertEqual($expected, $result);
$string = '⺀⺁⺂⺃⺄⺅⺆⺇⺈⺉⺊⺋⺌⺍⺎⺏⺐⺑⺒⺓⺔⺕⺖⺗⺘⺙⺛⺜⺝⺞⺟⺠⺡⺢⺣⺤⺥⺦⺧⺨⺩⺪⺫⺬⺭⺮⺯⺰⺱⺲⺳⺴⺵⺶⺷⺸⺹⺺⺻⺼⺽⺾⺿⻀⻁⻂⻃⻄⻅⻆⻇⻈⻉⻊⻋⻌⻍⻎⻏⻐⻑⻒⻓⻔⻕⻖⻗⻘⻙⻚⻛⻜⻝⻞⻟⻠';
$find = '⺐';
$result = Multibyte::strrchr($string, $find);
$expected = '⺐⺑⺒⺓⺔⺕⺖⺗⺘⺙⺛⺜⺝⺞⺟⺠⺡⺢⺣⺤⺥⺦⺧⺨⺩⺪⺫⺬⺭⺮⺯⺰⺱⺲⺳⺴⺵⺶⺷⺸⺹⺺⺻⺼⺽⺾⺿⻀⻁⻂⻃⻄⻅⻆⻇⻈⻉⻊⻋⻌⻍⻎⻏⻐⻑⻒⻓⻔⻕⻖⻗⻘⻙⻚⻛⻜⻝⻞⻟⻠';
$this->assertEqual($expected, $result);
$string = '⺀⺁⺂⺃⺄⺅⺆⺇⺈⺉⺊⺋⺌⺍⺎⺏⺐⺑⺒⺓⺔⺕⺖⺗⺘⺙⺛⺜⺝⺞⺟⺠⺡⺢⺣⺤⺥⺦⺧⺨⺩⺪⺫⺬⺭⺮⺯⺰⺱⺲⺳⺴⺵⺶⺷⺸⺹⺺⺻⺼⺽⺾⺿⻀⻁⻂⻃⻄⻅⻆⻇⻈⻉⻊⻋⻌⻍⻎⻏⻐⻑⻒⻓⻔⻕⻖⻗⻘⻙⻚⻛⻜⻝⻞⻟⻠';
$find = '⺐';
$result = Multibyte::strrchr($string, $find, true);
$expected = '⺀⺁⺂⺃⺄⺅⺆⺇⺈⺉⺊⺋⺌⺍⺎⺏';
$this->assertEqual($expected, $result);
$string = '⽅⽆⽇⽈⽉⽊⽋⽌⽍⽎⽏⽐⽑⽒⽓⽔⽕⽖⽗⽘⽙⽚⽛⽜⽝⽞⽟⽠⽡⽢⽣⽤⽥⽦⽧⽨⽩⽪⽫⽬⽭⽮⽯⽰⽱⽲⽳⽴⽵⽶⽷⽸⽹⽺⽻⽼⽽⽾⽿';
$find = '⽤';
$result = Multibyte::strrchr($string, $find);
$expected = '⽤⽥⽦⽧⽨⽩⽪⽫⽬⽭⽮⽯⽰⽱⽲⽳⽴⽵⽶⽷⽸⽹⽺⽻⽼⽽⽾⽿';
$this->assertEqual($expected, $result);
$string = '⽅⽆⽇⽈⽉⽊⽋⽌⽍⽎⽏⽐⽑⽒⽓⽔⽕⽖⽗⽘⽙⽚⽛⽜⽝⽞⽟⽠⽡⽢⽣⽤⽥⽦⽧⽨⽩⽪⽫⽬⽭⽮⽯⽰⽱⽲⽳⽴⽵⽶⽷⽸⽹⽺⽻⽼⽽⽾⽿';
$find = '⽤';
$result = Multibyte::strrchr($string, $find, true);
$expected = '⽅⽆⽇⽈⽉⽊⽋⽌⽍⽎⽏⽐⽑⽒⽓⽔⽕⽖⽗⽘⽙⽚⽛⽜⽝⽞⽟⽠⽡⽢⽣';
$this->assertEqual($expected, $result);
$string = '눡눢눣눤눥눦눧눨눩눪눫눬눭눮눯눰눱눲눳눴눵눶눷눸눹눺눻눼눽눾눿뉀뉁뉂뉃뉄뉅뉆뉇뉈뉉뉊뉋뉌뉍뉎뉏뉐뉑뉒뉓뉔뉕뉖뉗뉘뉙뉚뉛뉜뉝뉞뉟뉠뉡뉢뉣뉤뉥뉦뉧뉨뉩뉪뉫뉬뉭뉮뉯뉰뉱뉲뉳뉴뉵뉶뉷뉸뉹뉺뉻뉼뉽뉾뉿늀늁늂늃늄';
$find = '눻';
$result = Multibyte::strrchr($string, $find);
$expected = '눻눼눽눾눿뉀뉁뉂뉃뉄뉅뉆뉇뉈뉉뉊뉋뉌뉍뉎뉏뉐뉑뉒뉓뉔뉕뉖뉗뉘뉙뉚뉛뉜뉝뉞뉟뉠뉡뉢뉣뉤뉥뉦뉧뉨뉩뉪뉫뉬뉭뉮뉯뉰뉱뉲뉳뉴뉵뉶뉷뉸뉹뉺뉻뉼뉽뉾뉿늀늁늂늃늄';
$this->assertEqual($expected, $result);
$string = '눡눢눣눤눥눦눧눨눩눪눫눬눭눮눯눰눱눲눳눴눵눶눷눸눹눺눻눼눽눾눿뉀뉁뉂뉃뉄뉅뉆뉇뉈뉉뉊뉋뉌뉍뉎뉏뉐뉑뉒뉓뉔뉕뉖뉗뉘뉙뉚뉛뉜뉝뉞뉟뉠뉡뉢뉣뉤뉥뉦뉧뉨뉩뉪뉫뉬뉭뉮뉯뉰뉱뉲뉳뉴뉵뉶뉷뉸뉹뉺뉻뉼뉽뉾뉿늀늁늂늃늄';
$find = '눻';
$result = Multibyte::strrchr($string, $find, true);
$expected = '눡눢눣눤눥눦눧눨눩눪눫눬눭눮눯눰눱눲눳눴눵눶눷눸눹눺';
$this->assertEqual($expected, $result);
$string = 'ﹰﹱﹲﹳﹴﹶﹷﹸﹹﹺﹻﹼﹽﹾﹿﺀﺁﺂﺃﺄﺅﺆﺇﺈﺉﺊﺋﺌﺍﺎﺏﺐﺑﺒﺓﺔﺕﺖﺗﺘﺙﺚﺛﺜﺝﺞﺟﺠﺡﺢﺣﺤﺥﺦﺧﺨﺩﺪﺫﺬﺭﺮﺯﺰ';
$find = 'ﺞ';
$result = Multibyte::strrchr($string, $find);
$expected = 'ﺞﺟﺠﺡﺢﺣﺤﺥﺦﺧﺨﺩﺪﺫﺬﺭﺮﺯﺰ';
$this->assertEqual($expected, $result);
$string = 'ﹰﹱﹲﹳﹴﹶﹷﹸﹹﹺﹻﹼﹽﹾﹿﺀﺁﺂﺃﺄﺅﺆﺇﺈﺉﺊﺋﺌﺍﺎﺏﺐﺑﺒﺓﺔﺕﺖﺗﺘﺙﺚﺛﺜﺝﺞﺟﺠﺡﺢﺣﺤﺥﺦﺧﺨﺩﺪﺫﺬﺭﺮﺯﺰ';
$find = 'ﺞ';
$result = Multibyte::strrchr($string, $find, true);
$expected = 'ﹰﹱﹲﹳﹴﹶﹷﹸﹹﹺﹻﹼﹽﹾﹿﺀﺁﺂﺃﺄﺅﺆﺇﺈﺉﺊﺋﺌﺍﺎﺏﺐﺑﺒﺓﺔﺕﺖﺗﺘﺙﺚﺛﺜﺝ';
$this->assertEqual($expected, $result);
$string = 'ﺱﺲﺳﺴﺵﺶﺷﺸﺹﺺﺻﺼﺽﺾﺿﻀﻁﻂﻃﻄﻅﻆﻇﻈﻉﻊﻋﻌﻍﻎﻏﻐﻑﻒﻓﻔﻕﻖﻗﻘﻙﻚﻛﻜﻝﻞﻟﻠﻡﻢﻣﻤﻥﻦﻧﻨﻩﻪﻫﻬﻭﻮﻯﻰﻱﻲﻳﻴﻵﻶﻷﻸﻹﻺﻻﻼ';
$find = 'ﻞ';
$result = Multibyte::strrchr($string, $find);
$expected = 'ﻞﻟﻠﻡﻢﻣﻤﻥﻦﻧﻨﻩﻪﻫﻬﻭﻮﻯﻰﻱﻲﻳﻴﻵﻶﻷﻸﻹﻺﻻﻼ';
$this->assertEqual($expected, $result);
$string = 'ﺱﺲﺳﺴﺵﺶﺷﺸﺹﺺﺻﺼﺽﺾﺿﻀﻁﻂﻃﻄﻅﻆﻇﻈﻉﻊﻋﻌﻍﻎﻏﻐﻑﻒﻓﻔﻕﻖﻗﻘﻙﻚﻛﻜﻝﻞﻟﻠﻡﻢﻣﻤﻥﻦﻧﻨﻩﻪﻫﻬﻭﻮﻯﻰﻱﻲﻳﻴﻵﻶﻷﻸﻹﻺﻻﻼ';
$find = 'ﻞ';
$result = Multibyte::strrchr($string, $find, true);
$expected = 'ﺱﺲﺳﺴﺵﺶﺷﺸﺹﺺﺻﺼﺽﺾﺿﻀﻁﻂﻃﻄﻅﻆﻇﻈﻉﻊﻋﻌﻍﻎﻏﻐﻑﻒﻓﻔﻕﻖﻗﻘﻙﻚﻛﻜﻝ';
$this->assertEqual($expected, $result);
$string = 'abcdefghijklmnopqrstuvwxyz';
$find = 'k';
$result = Multibyte::strrchr($string, $find);
$expected = 'klmnopqrstuvwxyz';
$this->assertEqual($expected, $result);
$string = 'abcdefghijklmnopqrstuvwxyz';
$find = 'k';
$result = Multibyte::strrchr($string, $find, true);
$expected = 'abcdefghij';
$this->assertEqual($expected, $result);
$string = '。「」、・ヲァィゥェォャュョッーアイウエオカキク';
$find = 'ア';
$result = Multibyte::strrchr($string, $find);
$expected = 'アイウエオカキク';
$this->assertEqual($expected, $result);
$string = '。「」、・ヲァィゥェォャュョッーアイウエオカキク';
$find = 'ア';
$result = Multibyte::strrchr($string, $find, true);
$expected = '。「」、・ヲァィゥェォャュョッー';
$this->assertEqual($expected, $result);
$string = 'ケコサシスセソタチツテトナニヌネノハヒフヘホマミムメモヤユヨラリルレロワン゙';
$find = 'ハ';
$result = Multibyte::strrchr($string, $find);
$expected = 'ハヒフヘホマミムメモヤユヨラリルレロワン゙';
$this->assertEqual($expected, $result);
$string = 'ケコサシスセソタチツテトナニヌネノハヒフヘホマミムメモヤユヨラリルレロワン゙';
$find = 'ハ';
$result = Multibyte::strrchr($string, $find, true);
$expected = 'ケコサシスセソタチツテトナニヌネノ';
$this->assertEqual($expected, $result);
$string = 'Ĥēĺļŏ, Ŵőřļď!';
$find = 'ő';
$result = Multibyte::strrchr($string, $find);
$expected = 'őřļď!';
$this->assertEqual($expected, $result);
$string = 'Ĥēĺļŏ, Ŵőřļď!';
$find = 'ő';
$result = Multibyte::strrchr($string, $find, true);
$expected = 'Ĥēĺļŏ, Ŵ';
$this->assertEqual($expected, $result);
$string = 'Hello, World!';
$find = 'o';
$result = Multibyte::strrchr($string, $find);
$expected = 'orld!';
$this->assertEqual($expected, $result);
$string = 'Hello, World!';
$find = 'o';
$result = Multibyte::strrchr($string, $find, true);
$expected = 'Hello, W';
$this->assertEqual($expected, $result);
$string = 'Hello, World!';
$find = 'Wo';
$result = Multibyte::strrchr($string, $find);
$expected = 'World!';
$this->assertEqual($expected, $result);
$string = 'Hello, World!';
$find = 'Wo';
$result = Multibyte::strrchr($string, $find, true);
$expected = 'Hello, ';
$this->assertEqual($expected, $result);
$string = 'Hello, World!';
$find = 'll';
$result = Multibyte::strrchr($string, $find);
$expected = 'llo, World!';
$this->assertEqual($expected, $result);
$string = 'Hello, World!';
$find = 'll';
$result = Multibyte::strrchr($string, $find, true);
$expected = 'He';
$this->assertEqual($expected, $result);
$string = 'Hello, World!';
$find = 'rld';
$result = Multibyte::strrchr($string, $find);
$expected = 'rld!';
$this->assertEqual($expected, $result);
$string = 'Hello, World!';
$find = 'rld';
$result = Multibyte::strrchr($string, $find, true);
$expected = 'Hello, Wo';
$this->assertEqual($expected, $result);
$string = 'čini';
$find = 'n';
$result = Multibyte::strrchr($string, $find);
$expected = 'ni';
$this->assertEqual($expected, $result);
$string = 'čini';
$find = 'n';
$result = Multibyte::strrchr($string, $find, true);
$expected = 'či';
$this->assertEqual($expected, $result);
$string = 'moći';
$find = 'ć';
$result = Multibyte::strrchr($string, $find);
$expected = 'ći';
$this->assertEqual($expected, $result);
$string = 'moći';
$find = 'ć';
$result = Multibyte::strrchr($string, $find, true);
$expected = 'mo';
$this->assertEqual($expected, $result);
$string = 'državni';
$find = 'ž';
$result = Multibyte::strrchr($string, $find);
$expected = 'žavni';
$this->assertEqual($expected, $result);
$string = 'državni';
$find = 'ž';
$result = Multibyte::strrchr($string, $find, true);
$expected = 'dr';
$this->assertEqual($expected, $result);
$string = '把百度设为首页';
$find = '设';
$result = Multibyte::strrchr($string, $find);
$expected = '设为首页';
$this->assertEqual($expected, $result);
$string = '把百度设为首页';
$find = '设';
$result = Multibyte::strrchr($string, $find, true);
$expected = '把百度';
$this->assertEqual($expected, $result);
$string = '一二三周永龍';
$find = '周';
$result = Multibyte::strrchr($string, $find);
$expected = '周永龍';
$this->assertEqual($expected, $result);
$string = '一二三周永龍';
$find = '周';
$result = Multibyte::strrchr($string, $find, true);
$expected = '一二三';
$this->assertEqual($expected, $result);
$string = '一二三周永龍';
$find = '周龍';
$result = Multibyte::strrchr($string, $find, true);
$expected = false;
$this->assertEqual($expected, $result);
}
/**
* testUsingMbStrrichr method
*
* @return void
*/
public function testUsingMbStrrichr() {
$string = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
$find = 'F';
$result = mb_strrichr($string, $find);
$expected = 'FGHIJKLMNOPQRSTUVWXYZ0123456789';
$this->assertEqual($expected, $result);
$string = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
$find = 'F';
$result = mb_strrichr($string, $find, true);
$expected = 'ABCDE';
$this->assertEqual($expected, $result);
$string = 'ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞ';
$find = 'Å';
$result = mb_strrichr($string, $find);
$expected = 'ÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞ';
$this->assertEqual($expected, $result);
$string = 'ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞ';
$find = 'Å';
$result = mb_strrichr($string, $find, true);
$expected = 'ÀÁÂÃÄ';
$this->assertEqual($expected, $result);
$string = 'ĀĂĄĆĈĊČĎĐĒĔĖĘĚĜĞĠĢĤĦĨĪĬĮIJĴĶĹĻĽĿŁŃŅŇŊŌŎŐŒŔŖŘŚŜŞŠŢŤŦŨŪŬŮŰŲŴŶŹŻŽ';
$find = 'Ċ';
$result = mb_strrichr($string, $find);
$expected = 'ĊČĎĐĒĔĖĘĚĜĞĠĢĤĦĨĪĬĮIJĴĶĹĻĽĿŁŃŅŇŊŌŎŐŒŔŖŘŚŜŞŠŢŤŦŨŪŬŮŰŲŴŶŹŻŽ';
$this->assertEqual($expected, $result);
$string = 'ĀĂĄĆĈĊČĎĐĒĔĖĘĚĜĞĠĢĤĦĨĪĬĮIJĴĶĹĻĽĿŁŃŅŇŊŌŎŐŒŔŖŘŚŜŞŠŢŤŦŨŪŬŮŰŲŴŶŹŻŽ';
$find = 'Ċ';
$result = mb_strrichr($string, $find, true);
$expected = 'ĀĂĄĆĈ';
$this->assertEqual($expected, $result);
$string = '!"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~';
$find = 'F';
$result = mb_strrichr($string, $find);
$expected = 'fghijklmnopqrstuvwxyz{|}~';
$this->assertEqual($expected, $result);
$string = '!"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~';
$find = 'F';
$result = mb_strrichr($string, $find, true);
$expected = '!"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcde';
$this->assertEqual($expected, $result);
$string = '¡¢£¤¥¦§¨©ª«¬®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈ';
$find = 'µ';
$result = mb_strrichr($string, $find);
$expected = 'µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈ';
$this->assertEqual($expected, $result);
$string = '¡¢£¤¥¦§¨©ª«¬®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈ';
$find = 'µ';
$result = mb_strrichr($string, $find, true);
$expected = '¡¢£¤¥¦§¨©ª«¬®¯°±²³´';
$this->assertEqual($expected, $result);
$string = 'ÉÊËÌÍÎÏÐÑÒÓÔÕÖרÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿĀāĂ㥹ĆćĈĉĊċČčĎďĐđĒēĔĕĖėĘęĚěĜĝĞğĠġĢģĤĥĦħĨĩĪīĬ';
$find = 'Þ';
$result = mb_strrichr($string, $find);
$expected = 'þÿĀāĂ㥹ĆćĈĉĊċČčĎďĐđĒēĔĕĖėĘęĚěĜĝĞğĠġĢģĤĥĦħĨĩĪīĬ';
$this->assertEqual($expected, $result);
$string = 'ÉÊËÌÍÎÏÐÑÒÓÔÕÖרÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿĀāĂ㥹ĆćĈĉĊċČčĎďĐđĒēĔĕĖėĘęĚěĜĝĞğĠġĢģĤĥĦħĨĩĪīĬ';
$find = 'Þ';
$result = mb_strrichr($string, $find, true);
$expected = 'ÉÊËÌÍÎÏÐÑÒÓÔÕÖרÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüý';
$this->assertEqual($expected, $result);
$string = 'ĭĮįİıIJijĴĵĶķĸĹĺĻļĽľĿŀŁłŃńŅņŇňʼnŊŋŌōŎŏŐőŒœŔŕŖŗŘřŚśŜŝŞşŠšŢţŤťŦŧŨũŪūŬŭŮůŰűŲųŴŵŶŷŸŹźŻżŽžſƀƁƂƃƄƅƆƇƈƉƊƋƌƍƎƏƐ';
$find = 'Ņ';
$result = mb_strrichr($string, $find);
$expected = 'ņŇňʼnŊŋŌōŎŏŐőŒœŔŕŖŗŘřŚśŜŝŞşŠšŢţŤťŦŧŨũŪūŬŭŮůŰűŲųŴŵŶŷŸŹźŻżŽžſƀƁƂƃƄƅƆƇƈƉƊƋƌƍƎƏƐ';
$this->assertEqual($expected, $result);
$string = 'ĭĮįİıIJijĴĵĶķĸĹĺĻļĽľĿŀŁłŃńŅņŇňʼnŊŋŌōŎŏŐőŒœŔŕŖŗŘřŚśŜŝŞşŠšŢţŤťŦŧŨũŪūŬŭŮůŰűŲųŴŵŶŷŸŹźŻżŽžſƀƁƂƃƄƅƆƇƈƉƊƋƌƍƎƏƐ';
$find = 'Ņ';
$result = mb_strrichr($string, $find, true);
$expected = 'ĭĮįİıIJijĴĵĶķĸĹĺĻļĽľĿŀŁłŃńŅ';
$this->assertEqual($expected, $result);
$string = 'ƑƒƓƔƕƖƗƘƙƚƛƜƝƞƟƠơƢƣƤƥƦƧƨƩƪƫƬƭƮƯưƱƲƳƴƵƶƷƸƹƺƻƼƽƾƿǀǁǂǃDŽDždžLJLjljNJNjnjǍǎǏǐǑǒǓǔǕǖǗǘǙǚǛǜǝǞǟǠǡǢǣǤǥǦǧǨǩǪǫǬǭǮǯǰDZDzdzǴ';
$find = 'Ƹ';
$result = mb_strrichr($string, $find);
$expected = 'ƹƺƻƼƽƾƿǀǁǂǃDŽDždžLJLjljNJNjnjǍǎǏǐǑǒǓǔǕǖǗǘǙǚǛǜǝǞǟǠǡǢǣǤǥǦǧǨǩǪǫǬǭǮǯǰDZDzdzǴ';
$this->assertEqual($expected, $result);
$find = 'Ƹ';
$result = mb_strrichr($string, $find, true);
$expected = 'ƑƒƓƔƕƖƗƘƙƚƛƜƝƞƟƠơƢƣƤƥƦƧƨƩƪƫƬƭƮƯưƱƲƳƴƵƶƷƸ';
$this->assertEqual($expected, $result);
$string = 'əɚɛɜɝɞɟɠɡɢɣɤɥɦɧɨɩɪɫɬɭɮɯɰɱɲɳɴɵɶɷɸɹɺɻɼɽɾɿʀʁʂʃʄʅʆʇʈʉʊʋʌʍʎʏʐʑʒʓʔʕʖʗʘʙʚʛʜʝʞʟʠʡʢʣʤʥʦʧʨʩʪʫʬʭʮʯʰʱʲʳʴʵʶʷʸʹʺʻʼ';
$find = 'ʀ';
$result = mb_strrichr($string, $find);
$expected = 'ʀʁʂʃʄʅʆʇʈʉʊʋʌʍʎʏʐʑʒʓʔʕʖʗʘʙʚʛʜʝʞʟʠʡʢʣʤʥʦʧʨʩʪʫʬʭʮʯʰʱʲʳʴʵʶʷʸʹʺʻʼ';
$this->assertEqual($expected, $result);
$string = 'əɚɛɜɝɞɟɠɡɢɣɤɥɦɧɨɩɪɫɬɭɮɯɰɱɲɳɴɵɶɷɸɹɺɻɼɽɾɿʀʁʂʃʄʅʆʇʈʉʊʋʌʍʎʏʐʑʒʓʔʕʖʗʘʙʚʛʜʝʞʟʠʡʢʣʤʥʦʧʨʩʪʫʬʭʮʯʰʱʲʳʴʵʶʷʸʹʺʻʼ';
$find = 'ʀ';
$result = mb_strrichr($string, $find, true);
$expected = 'əɚɛɜɝɞɟɠɡɢɣɤɥɦɧɨɩɪɫɬɭɮɯɰɱɲɳɴɵɶɷɸɹɺɻɼɽɾɿ';
$this->assertEqual($expected, $result);
$string = 'ЀЁЂЃЄЅІЇЈЉЊЋЌЍЎЏАБВГДЕЖЗИЙКЛ';
$find = 'Ї';
$result = mb_strrichr($string, $find);
$expected = 'ЇЈЉЊЋЌЍЎЏАБВГДЕЖЗИЙКЛ';
$this->assertEqual($expected, $result);
$string = 'ЀЁЂЃЄЅІЇЈЉЊЋЌЍЎЏАБВГДЕЖЗИЙКЛ';
$find = 'Ї';
$result = mb_strrichr($string, $find, true);
$expected = 'ЀЁЂЃЄЅІ';
$this->assertEqual($expected, $result);
$string = 'МНОПРСТУФХЦЧШЩЪЫЬЭЮЯабвгдежзийклмнопрстуфхцчшщъыь';
$find = 'Р';
$result = mb_strrichr($string, $find);
$expected = 'рстуфхцчшщъыь';
$this->assertEqual($expected, $result);
$string = 'МНОПРСТУФХЦЧШЩЪЫЬЭЮЯабвгдежзийклмноп';
$find = 'Р';
$result = mb_strrichr($string, $find, true);
$expected = 'МНОП';
$this->assertEqual($expected, $result);
$string = 'فقكلمنهوىيًٌٍَُ';
$find = 'ن';
$result = mb_strrichr($string, $find);
$expected = 'نهوىيًٌٍَُ';
$this->assertEqual($expected, $result);
$string = 'فقكلمنهوىيًٌٍَُ';
$find = 'ن';
$result = mb_strrichr($string, $find, true);
$expected = 'فقكلم';
$this->assertEqual($expected, $result);
$string = '✰✱✲✳✴✵✶✷✸✹✺✻✼✽✾✿❀❁❂❃❄❅❆❇❈❉❊❋❌❍❎❏❐❑❒❓❔❕❖❗❘❙❚❛❜❝❞';
$find = '✿';
$result = mb_strrichr($string, $find);
$expected = '✿❀❁❂❃❄❅❆❇❈❉❊❋❌❍❎❏❐❑❒❓❔❕❖❗❘❙❚❛❜❝❞';
$this->assertEqual($expected, $result);
$string = '✰✱✲✳✴✵✶✷✸✹✺✻✼✽✾✿❀❁❂❃❄❅❆❇❈❉❊❋❌❍❎❏❐❑❒❓❔❕❖❗❘❙❚❛❜❝❞';
$find = '✿';
$result = mb_strrichr($string, $find, true);
$expected = '✰✱✲✳✴✵✶✷✸✹✺✻✼✽✾';
$this->assertEqual($expected, $result);
$string = '⺀⺁⺂⺃⺄⺅⺆⺇⺈⺉⺊⺋⺌⺍⺎⺏⺐⺑⺒⺓⺔⺕⺖⺗⺘⺙⺛⺜⺝⺞⺟⺠⺡⺢⺣⺤⺥⺦⺧⺨⺩⺪⺫⺬⺭⺮⺯⺰⺱⺲⺳⺴⺵⺶⺷⺸⺹⺺⺻⺼⺽⺾⺿⻀⻁⻂⻃⻄⻅⻆⻇⻈⻉⻊⻋⻌⻍⻎⻏⻐⻑⻒⻓⻔⻕⻖⻗⻘⻙⻚⻛⻜⻝⻞⻟⻠';
$find = '⺐';
$result = mb_strrichr($string, $find);
$expected = '⺐⺑⺒⺓⺔⺕⺖⺗⺘⺙⺛⺜⺝⺞⺟⺠⺡⺢⺣⺤⺥⺦⺧⺨⺩⺪⺫⺬⺭⺮⺯⺰⺱⺲⺳⺴⺵⺶⺷⺸⺹⺺⺻⺼⺽⺾⺿⻀⻁⻂⻃⻄⻅⻆⻇⻈⻉⻊⻋⻌⻍⻎⻏⻐⻑⻒⻓⻔⻕⻖⻗⻘⻙⻚⻛⻜⻝⻞⻟⻠';
$this->assertEqual($expected, $result);
$string = '⺀⺁⺂⺃⺄⺅⺆⺇⺈⺉⺊⺋⺌⺍⺎⺏⺐⺑⺒⺓⺔⺕⺖⺗⺘⺙⺛⺜⺝⺞⺟⺠⺡⺢⺣⺤⺥⺦⺧⺨⺩⺪⺫⺬⺭⺮⺯⺰⺱⺲⺳⺴⺵⺶⺷⺸⺹⺺⺻⺼⺽⺾⺿⻀⻁⻂⻃⻄⻅⻆⻇⻈⻉⻊⻋⻌⻍⻎⻏⻐⻑⻒⻓⻔⻕⻖⻗⻘⻙⻚⻛⻜⻝⻞⻟⻠';
$find = '⺐';
$result = mb_strrichr($string, $find, true);
$expected = '⺀⺁⺂⺃⺄⺅⺆⺇⺈⺉⺊⺋⺌⺍⺎⺏';
$this->assertEqual($expected, $result);
$string = '⽅⽆⽇⽈⽉⽊⽋⽌⽍⽎⽏⽐⽑⽒⽓⽔⽕⽖⽗⽘⽙⽚⽛⽜⽝⽞⽟⽠⽡⽢⽣⽤⽥⽦⽧⽨⽩⽪⽫⽬⽭⽮⽯⽰⽱⽲⽳⽴⽵⽶⽷⽸⽹⽺⽻⽼⽽⽾⽿';
$find = '⽤';
$result = mb_strrichr($string, $find);
$expected = '⽤⽥⽦⽧⽨⽩⽪⽫⽬⽭⽮⽯⽰⽱⽲⽳⽴⽵⽶⽷⽸⽹⽺⽻⽼⽽⽾⽿';
$this->assertEqual($expected, $result);
$string = '⽅⽆⽇⽈⽉⽊⽋⽌⽍⽎⽏⽐⽑⽒⽓⽔⽕⽖⽗⽘⽙⽚⽛⽜⽝⽞⽟⽠⽡⽢⽣⽤⽥⽦⽧⽨⽩⽪⽫⽬⽭⽮⽯⽰⽱⽲⽳⽴⽵⽶⽷⽸⽹⽺⽻⽼⽽⽾⽿';
$find = '⽤';
$result = mb_strrichr($string, $find, true);
$expected = '⽅⽆⽇⽈⽉⽊⽋⽌⽍⽎⽏⽐⽑⽒⽓⽔⽕⽖⽗⽘⽙⽚⽛⽜⽝⽞⽟⽠⽡⽢⽣';
$this->assertEqual($expected, $result);
$string = '눡눢눣눤눥눦눧눨눩눪눫눬눭눮눯눰눱눲눳눴눵눶눷눸눹눺눻눼눽눾눿뉀뉁뉂뉃뉄뉅뉆뉇뉈뉉뉊뉋뉌뉍뉎뉏뉐뉑뉒뉓뉔뉕뉖뉗뉘뉙뉚뉛뉜뉝뉞뉟뉠뉡뉢뉣뉤뉥뉦뉧뉨뉩뉪뉫뉬뉭뉮뉯뉰뉱뉲뉳뉴뉵뉶뉷뉸뉹뉺뉻뉼뉽뉾뉿늀늁늂늃늄';
$find = '눻';
$result = mb_strrichr($string, $find);
$expected = '눻눼눽눾눿뉀뉁뉂뉃뉄뉅뉆뉇뉈뉉뉊뉋뉌뉍뉎뉏뉐뉑뉒뉓뉔뉕뉖뉗뉘뉙뉚뉛뉜뉝뉞뉟뉠뉡뉢뉣뉤뉥뉦뉧뉨뉩뉪뉫뉬뉭뉮뉯뉰뉱뉲뉳뉴뉵뉶뉷뉸뉹뉺뉻뉼뉽뉾뉿늀늁늂늃늄';
$this->assertEqual($expected, $result);
$string = '눡눢눣눤눥눦눧눨눩눪눫눬눭눮눯눰눱눲눳눴눵눶눷눸눹눺눻눼눽눾눿뉀뉁뉂뉃뉄뉅뉆뉇뉈뉉뉊뉋뉌뉍뉎뉏뉐뉑뉒뉓뉔뉕뉖뉗뉘뉙뉚뉛뉜뉝뉞뉟뉠뉡뉢뉣뉤뉥뉦뉧뉨뉩뉪뉫뉬뉭뉮뉯뉰뉱뉲뉳뉴뉵뉶뉷뉸뉹뉺뉻뉼뉽뉾뉿늀늁늂늃늄';
$find = '눻';
$result = mb_strrichr($string, $find, true);
$expected = '눡눢눣눤눥눦눧눨눩눪눫눬눭눮눯눰눱눲눳눴눵눶눷눸눹눺';
$this->assertEqual($expected, $result);
$string = 'ﹰﹱﹲﹳﹴﹶﹷﹸﹹﹺﹻﹼﹽﹾﹿﺀﺁﺂﺃﺄﺅﺆﺇﺈﺉﺊﺋﺌﺍﺎﺏﺐﺑﺒﺓﺔﺕﺖﺗﺘﺙﺚﺛﺜﺝﺞﺟﺠﺡﺢﺣﺤﺥﺦﺧﺨﺩﺪﺫﺬﺭﺮﺯﺰ';
$find = 'ﺞ';
$result = mb_strrichr($string, $find);
$expected = 'ﺞﺟﺠﺡﺢﺣﺤﺥﺦﺧﺨﺩﺪﺫﺬﺭﺮﺯﺰ';
$this->assertEqual($expected, $result);
$string = 'ﹰﹱﹲﹳﹴﹶﹷﹸﹹﹺﹻﹼﹽﹾﹿﺀﺁﺂﺃﺄﺅﺆﺇﺈﺉﺊﺋﺌﺍﺎﺏﺐﺑﺒﺓﺔﺕﺖﺗﺘﺙﺚﺛﺜﺝﺞﺟﺠﺡﺢﺣﺤﺥﺦﺧﺨﺩﺪﺫﺬﺭﺮﺯﺰ';
$find = 'ﺞ';
$result = mb_strrichr($string, $find, true);
$expected = 'ﹰﹱﹲﹳﹴﹶﹷﹸﹹﹺﹻﹼﹽﹾﹿﺀﺁﺂﺃﺄﺅﺆﺇﺈﺉﺊﺋﺌﺍﺎﺏﺐﺑﺒﺓﺔﺕﺖﺗﺘﺙﺚﺛﺜﺝ';
$this->assertEqual($expected, $result);
$string = 'ﺱﺲﺳﺴﺵﺶﺷﺸﺹﺺﺻﺼﺽﺾﺿﻀﻁﻂﻃﻄﻅﻆﻇﻈﻉﻊﻋﻌﻍﻎﻏﻐﻑﻒﻓﻔﻕﻖﻗﻘﻙﻚﻛﻜﻝﻞﻟﻠﻡﻢﻣﻤﻥﻦﻧﻨﻩﻪﻫﻬﻭﻮﻯﻰﻱﻲﻳﻴﻵﻶﻷﻸﻹﻺﻻﻼ';
$find = 'ﻞ';
$result = mb_strrichr($string, $find);
$expected = 'ﻞﻟﻠﻡﻢﻣﻤﻥﻦﻧﻨﻩﻪﻫﻬﻭﻮﻯﻰﻱﻲﻳﻴﻵﻶﻷﻸﻹﻺﻻﻼ';
$this->assertEqual($expected, $result);
$string = 'ﺱﺲﺳﺴﺵﺶﺷﺸﺹﺺﺻﺼﺽﺾﺿﻀﻁﻂﻃﻄﻅﻆﻇﻈﻉﻊﻋﻌﻍﻎﻏﻐﻑﻒﻓﻔﻕﻖﻗﻘﻙﻚﻛﻜﻝﻞﻟﻠﻡﻢﻣﻤﻥﻦﻧﻨﻩﻪﻫﻬﻭﻮﻯﻰﻱﻲﻳﻴﻵﻶﻷﻸﻹﻺﻻﻼ';
$find = 'ﻞ';
$result = mb_strrichr($string, $find, true);
$expected = 'ﺱﺲﺳﺴﺵﺶﺷﺸﺹﺺﺻﺼﺽﺾﺿﻀﻁﻂﻃﻄﻅﻆﻇﻈﻉﻊﻋﻌﻍﻎﻏﻐﻑﻒﻓﻔﻕﻖﻗﻘﻙﻚﻛﻜﻝ';
$this->assertEqual($expected, $result);
$string = 'abcdefghijklmnopqrstuvwxyz';
$find = 'k';
$result = mb_strrichr($string, $find);
$expected = 'klmnopqrstuvwxyz';
$this->assertEqual($expected, $result);
$string = 'abcdefghijklmnopqrstuvwxyz';
$find = 'k';
$result = mb_strrichr($string, $find, true);
$expected = 'abcdefghij';
$this->assertEqual($expected, $result);
$string = '。「」、・ヲァィゥェォャュョッーアイウエオカキク';
$find = 'ア';
$result = mb_strrichr($string, $find);
$expected = 'アイウエオカキク';
$this->assertEqual($expected, $result);
$string = '。「」、・ヲァィゥェォャュョッーアイウエオカキク';
$find = 'ア';
$result = mb_strrichr($string, $find, true);
$expected = '。「」、・ヲァィゥェォャュョッー';
$this->assertEqual($expected, $result);
$string = 'ケコサシスセソタチツテトナニヌネノハヒフヘホマミムメモヤユヨラリルレロワン゙';
$find = 'ハ';
$result = mb_strrichr($string, $find);
$expected = 'ハヒフヘホマミムメモヤユヨラリルレロワン゙';
$this->assertEqual($expected, $result);
$string = 'ケコサシスセソタチツテトナニヌネノハヒフヘホマミムメモヤユヨラリルレロワン゙';
$find = 'ハ';
$result = mb_strrichr($string, $find, true);
$expected = 'ケコサシスセソタチツテトナニヌネノ';
$this->assertEqual($expected, $result);
$string = 'Ĥēĺļŏ, Ŵőřļď!';
$find = 'ő';
$result = mb_strrichr($string, $find);
$expected = 'őřļď!';
$this->assertEqual($expected, $result);
$string = 'Ĥēĺļŏ, Ŵőřļď!';
$find = 'ő';
$result = mb_strrichr($string, $find, true);
$expected = 'Ĥēĺļŏ, Ŵ';
$this->assertEqual($expected, $result);
$string = 'Hello, World!';
$find = 'o';
$result = mb_strrichr($string, $find);
$expected = 'orld!';
$this->assertEqual($expected, $result);
$string = 'Hello, World!';
$find = 'o';
$result = mb_strrichr($string, $find, true);
$expected = 'Hello, W';
$this->assertEqual($expected, $result);
$string = 'Hello, World!';
$find = 'Wo';
$result = mb_strrichr($string, $find);
$expected = 'World!';
$this->assertEqual($expected, $result);
$string = 'Hello, World!';
$find = 'Wo';
$result = mb_strrichr($string, $find, true);
$expected = 'Hello, ';
$this->assertEqual($expected, $result);
$string = 'Hello, World!';
$find = 'll';
$result = mb_strrichr($string, $find);
$expected = 'llo, World!';
$this->assertEqual($expected, $result);
$string = 'Hello, World!';
$find = 'll';
$result = mb_strrichr($string, $find, true);
$expected = 'He';
$this->assertEqual($expected, $result);
$string = 'Hello, World!';
$find = 'rld';
$result = mb_strrichr($string, $find);
$expected = 'rld!';
$this->assertEqual($expected, $result);
$string = 'Hello, World!';
$find = 'rld';
$result = mb_strrichr($string, $find, true);
$expected = 'Hello, Wo';
$this->assertEqual($expected, $result);
$string = 'čini';
$find = 'n';
$result = mb_strrichr($string, $find);
$expected = 'ni';
$this->assertEqual($expected, $result);
$string = 'čini';
$find = 'n';
$result = mb_strrichr($string, $find, true);
$expected = 'či';
$this->assertEqual($expected, $result);
$string = 'moći';
$find = 'ć';
$result = mb_strrichr($string, $find);
$expected = 'ći';
$this->assertEqual($expected, $result);
$string = 'moći';
$find = 'ć';
$result = mb_strrichr($string, $find, true);
$expected = 'mo';
$this->assertEqual($expected, $result);
$string = 'državni';
$find = 'ž';
$result = mb_strrichr($string, $find);
$expected = 'žavni';
$this->assertEqual($expected, $result);
$string = 'državni';
$find = 'ž';
$result = mb_strrichr($string, $find, true);
$expected = 'dr';
$this->assertEqual($expected, $result);
$string = '把百度设为首页';
$find = '设';
$result = mb_strrichr($string, $find);
$expected = '设为首页';
$this->assertEqual($expected, $result);
$string = '把百度设为首页';
$find = '设';
$result = mb_strrichr($string, $find, true);
$expected = '把百度';
$this->assertEqual($expected, $result);
$string = '一二三周永龍';
$find = '周';
$result = mb_strrichr($string, $find);
$expected = '周永龍';
$this->assertEqual($expected, $result);
$string = '一二三周永龍';
$find = '周';
$result = mb_strrichr($string, $find, true);
$expected = '一二三';
$this->assertEqual($expected, $result);
$string = '把百度设为首页';
$find = '百设';
$result = mb_strrichr($string, $find, true);
$expected = false;
$this->assertEqual($expected, $result);
}
/**
* testMultibyteStrrichr method
*
* @return void
*/
public function testMultibyteStrrichr() {
$string = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
$find = 'F';
$result = Multibyte::strrichr($string, $find);
$expected = 'FGHIJKLMNOPQRSTUVWXYZ0123456789';
$this->assertEqual($expected, $result);
$string = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
$find = 'F';
$result = Multibyte::strrichr($string, $find, true);
$expected = 'ABCDE';
$this->assertEqual($expected, $result);
$string = 'ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞ';
$find = 'Å';
$result = Multibyte::strrichr($string, $find);
$expected = 'ÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞ';
$this->assertEqual($expected, $result);
$string = 'ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞ';
$find = 'Å';
$result = Multibyte::strrichr($string, $find, true);
$expected = 'ÀÁÂÃÄ';
$this->assertEqual($expected, $result);
$string = 'ĀĂĄĆĈĊČĎĐĒĔĖĘĚĜĞĠĢĤĦĨĪĬĮIJĴĶĹĻĽĿŁŃŅŇŊŌŎŐŒŔŖŘŚŜŞŠŢŤŦŨŪŬŮŰŲŴŶŹŻŽ';
$find = 'Ċ';
$result = Multibyte::strrichr($string, $find);
$expected = 'ĊČĎĐĒĔĖĘĚĜĞĠĢĤĦĨĪĬĮIJĴĶĹĻĽĿŁŃŅŇŊŌŎŐŒŔŖŘŚŜŞŠŢŤŦŨŪŬŮŰŲŴŶŹŻŽ';
$this->assertEqual($expected, $result);
$string = 'ĀĂĄĆĈĊČĎĐĒĔĖĘĚĜĞĠĢĤĦĨĪĬĮIJĴĶĹĻĽĿŁŃŅŇŊŌŎŐŒŔŖŘŚŜŞŠŢŤŦŨŪŬŮŰŲŴŶŹŻŽ';
$find = 'Ċ';
$result = Multibyte::strrichr($string, $find, true);
$expected = 'ĀĂĄĆĈ';
$this->assertEqual($expected, $result);
$string = '!"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~';
$find = 'F';
$result = Multibyte::strrichr($string, $find);
$expected = 'fghijklmnopqrstuvwxyz{|}~';
$this->assertEqual($expected, $result);
$string = '!"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~';
$find = 'F';
$result = Multibyte::strrichr($string, $find, true);
$expected = '!"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcde';
$this->assertEqual($expected, $result);
$string = '¡¢£¤¥¦§¨©ª«¬®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈ';
$find = 'µ';
$result = Multibyte::strrichr($string, $find);
$expected = 'µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈ';
$this->assertEqual($expected, $result);
$string = '¡¢£¤¥¦§¨©ª«¬®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈ';
$find = 'µ';
$result = Multibyte::strrichr($string, $find, true);
$expected = '¡¢£¤¥¦§¨©ª«¬®¯°±²³´';
$this->assertEqual($expected, $result);
$string = 'ÉÊËÌÍÎÏÐÑÒÓÔÕÖרÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿĀāĂ㥹ĆćĈĉĊċČčĎďĐđĒēĔĕĖėĘęĚěĜĝĞğĠġĢģĤĥĦħĨĩĪīĬ';
$find = 'Þ';
$result = Multibyte::strrichr($string, $find);
$expected = 'þÿĀāĂ㥹ĆćĈĉĊċČčĎďĐđĒēĔĕĖėĘęĚěĜĝĞğĠġĢģĤĥĦħĨĩĪīĬ';
$this->assertEqual($expected, $result);
$string = 'ÉÊËÌÍÎÏÐÑÒÓÔÕÖרÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿĀāĂ㥹ĆćĈĉĊċČčĎďĐđĒēĔĕĖėĘęĚěĜĝĞğĠġĢģĤĥĦħĨĩĪīĬ';
$find = 'Þ';
$result = Multibyte::strrichr($string, $find, true);
$expected = 'ÉÊËÌÍÎÏÐÑÒÓÔÕÖרÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüý';
$this->assertEqual($expected, $result);
$string = 'ĭĮįİıIJijĴĵĶķĸĹĺĻļĽľĿŀŁłŃńŅņŇňʼnŊŋŌōŎŏŐőŒœŔŕŖŗŘřŚśŜŝŞşŠšŢţŤťŦŧŨũŪūŬŭŮůŰűŲųŴŵŶŷŸŹźŻżŽžſƀƁƂƃƄƅƆƇƈƉƊƋƌƍƎƏƐ';
$find = 'Ņ';
$result = Multibyte::strrichr($string, $find);
$expected = 'ņŇňʼnŊŋŌōŎŏŐőŒœŔŕŖŗŘřŚśŜŝŞşŠšŢţŤťŦŧŨũŪūŬŭŮůŰűŲųŴŵŶŷŸŹźŻżŽžſƀƁƂƃƄƅƆƇƈƉƊƋƌƍƎƏƐ';
$this->assertEqual($expected, $result);
$string = 'ĭĮįİıIJijĴĵĶķĸĹĺĻļĽľĿŀŁłŃńŅņŇňʼnŊŋŌōŎŏŐőŒœŔŕŖŗŘřŚśŜŝŞşŠšŢţŤťŦŧŨũŪūŬŭŮůŰűŲųŴŵŶŷŸŹźŻżŽžſƀƁƂƃƄƅƆƇƈƉƊƋƌƍƎƏƐ';
$find = 'Ņ';
$result = Multibyte::strrichr($string, $find, true);
$expected = 'ĭĮįİıIJijĴĵĶķĸĹĺĻļĽľĿŀŁłŃńŅ';
$this->assertEqual($expected, $result);
$string = 'ƑƒƓƔƕƖƗƘƙƚƛƜƝƞƟƠơƢƣƤƥƦƧƨƩƪƫƬƭƮƯưƱƲƳƴƵƶƷƸƹƺƻƼƽƾƿǀǁǂǃDŽDždžLJLjljNJNjnjǍǎǏǐǑǒǓǔǕǖǗǘǙǚǛǜǝǞǟǠǡǢǣǤǥǦǧǨǩǪǫǬǭǮǯǰDZDzdzǴ';
$find = 'Ƹ';
$result = Multibyte::strrichr($string, $find);
$expected = 'ƹƺƻƼƽƾƿǀǁǂǃDŽDždžLJLjljNJNjnjǍǎǏǐǑǒǓǔǕǖǗǘǙǚǛǜǝǞǟǠǡǢǣǤǥǦǧǨǩǪǫǬǭǮǯǰDZDzdzǴ';
$this->assertEqual($expected, $result);
$find = 'Ƹ';
$result = Multibyte::strrichr($string, $find, true);
$expected = 'ƑƒƓƔƕƖƗƘƙƚƛƜƝƞƟƠơƢƣƤƥƦƧƨƩƪƫƬƭƮƯưƱƲƳƴƵƶƷƸ';
$this->assertEqual($expected, $result);
$string = 'əɚɛɜɝɞɟɠɡɢɣɤɥɦɧɨɩɪɫɬɭɮɯɰɱɲɳɴɵɶɷɸɹɺɻɼɽɾɿʀʁʂʃʄʅʆʇʈʉʊʋʌʍʎʏʐʑʒʓʔʕʖʗʘʙʚʛʜʝʞʟʠʡʢʣʤʥʦʧʨʩʪʫʬʭʮʯʰʱʲʳʴʵʶʷʸʹʺʻʼ';
$find = 'ʀ';
$result = Multibyte::strrichr($string, $find);
$expected = 'ʀʁʂʃʄʅʆʇʈʉʊʋʌʍʎʏʐʑʒʓʔʕʖʗʘʙʚʛʜʝʞʟʠʡʢʣʤʥʦʧʨʩʪʫʬʭʮʯʰʱʲʳʴʵʶʷʸʹʺʻʼ';
$this->assertEqual($expected, $result);
$string = 'əɚɛɜɝɞɟɠɡɢɣɤɥɦɧɨɩɪɫɬɭɮɯɰɱɲɳɴɵɶɷɸɹɺɻɼɽɾɿʀʁʂʃʄʅʆʇʈʉʊʋʌʍʎʏʐʑʒʓʔʕʖʗʘʙʚʛʜʝʞʟʠʡʢʣʤʥʦʧʨʩʪʫʬʭʮʯʰʱʲʳʴʵʶʷʸʹʺʻʼ';
$find = 'ʀ';
$result = Multibyte::strrichr($string, $find, true);
$expected = 'əɚɛɜɝɞɟɠɡɢɣɤɥɦɧɨɩɪɫɬɭɮɯɰɱɲɳɴɵɶɷɸɹɺɻɼɽɾɿ';
$this->assertEqual($expected, $result);
$string = 'ЀЁЂЃЄЅІЇЈЉЊЋЌЍЎЏАБВГДЕЖЗИЙКЛ';
$find = 'Ї';
$result = Multibyte::strrichr($string, $find);
$expected = 'ЇЈЉЊЋЌЍЎЏАБВГДЕЖЗИЙКЛ';
$this->assertEqual($expected, $result);
$string = 'ЀЁЂЃЄЅІЇЈЉЊЋЌЍЎЏАБВГДЕЖЗИЙКЛ';
$find = 'Ї';
$result = Multibyte::strrichr($string, $find, true);
$expected = 'ЀЁЂЃЄЅІ';
$this->assertEqual($expected, $result);
$string = 'МНОПРСТУФХЦЧШЩЪЫЬЭЮЯабвгдежзийклмнопрстуфхцчшщъыь';
$find = 'Р';
$result = Multibyte::strrichr($string, $find);
$expected = 'рстуфхцчшщъыь';
$this->assertEqual($expected, $result);
$string = 'МНОПРСТУФХЦЧШЩЪЫЬЭЮЯабвгдежзийклмноп';
$find = 'Р';
$result = Multibyte::strrichr($string, $find, true);
$expected = 'МНОП';
$this->assertEqual($expected, $result);
$string = 'فقكلمنهوىيًٌٍَُ';
$find = 'ن';
$result = Multibyte::strrichr($string, $find);
$expected = 'نهوىيًٌٍَُ';
$this->assertEqual($expected, $result);
$string = 'فقكلمنهوىيًٌٍَُ';
$find = 'ن';
$result = Multibyte::strrichr($string, $find, true);
$expected = 'فقكلم';
$this->assertEqual($expected, $result);
$string = '✰✱✲✳✴✵✶✷✸✹✺✻✼✽✾✿❀❁❂❃❄❅❆❇❈❉❊❋❌❍❎❏❐❑❒❓❔❕❖❗❘❙❚❛❜❝❞';
$find = '✿';
$result = Multibyte::strrichr($string, $find);
$expected = '✿❀❁❂❃❄❅❆❇❈❉❊❋❌❍❎❏❐❑❒❓❔❕❖❗❘❙❚❛❜❝❞';
$this->assertEqual($expected, $result);
$string = '✰✱✲✳✴✵✶✷✸✹✺✻✼✽✾✿❀❁❂❃❄❅❆❇❈❉❊❋❌❍❎❏❐❑❒❓❔❕❖❗❘❙❚❛❜❝❞';
$find = '✿';
$result = Multibyte::strrichr($string, $find, true);
$expected = '✰✱✲✳✴✵✶✷✸✹✺✻✼✽✾';
$this->assertEqual($expected, $result);
$string = '⺀⺁⺂⺃⺄⺅⺆⺇⺈⺉⺊⺋⺌⺍⺎⺏⺐⺑⺒⺓⺔⺕⺖⺗⺘⺙⺛⺜⺝⺞⺟⺠⺡⺢⺣⺤⺥⺦⺧⺨⺩⺪⺫⺬⺭⺮⺯⺰⺱⺲⺳⺴⺵⺶⺷⺸⺹⺺⺻⺼⺽⺾⺿⻀⻁⻂⻃⻄⻅⻆⻇⻈⻉⻊⻋⻌⻍⻎⻏⻐⻑⻒⻓⻔⻕⻖⻗⻘⻙⻚⻛⻜⻝⻞⻟⻠';
$find = '⺐';
$result = Multibyte::strrichr($string, $find);
$expected = '⺐⺑⺒⺓⺔⺕⺖⺗⺘⺙⺛⺜⺝⺞⺟⺠⺡⺢⺣⺤⺥⺦⺧⺨⺩⺪⺫⺬⺭⺮⺯⺰⺱⺲⺳⺴⺵⺶⺷⺸⺹⺺⺻⺼⺽⺾⺿⻀⻁⻂⻃⻄⻅⻆⻇⻈⻉⻊⻋⻌⻍⻎⻏⻐⻑⻒⻓⻔⻕⻖⻗⻘⻙⻚⻛⻜⻝⻞⻟⻠';
$this->assertEqual($expected, $result);
$string = '⺀⺁⺂⺃⺄⺅⺆⺇⺈⺉⺊⺋⺌⺍⺎⺏⺐⺑⺒⺓⺔⺕⺖⺗⺘⺙⺛⺜⺝⺞⺟⺠⺡⺢⺣⺤⺥⺦⺧⺨⺩⺪⺫⺬⺭⺮⺯⺰⺱⺲⺳⺴⺵⺶⺷⺸⺹⺺⺻⺼⺽⺾⺿⻀⻁⻂⻃⻄⻅⻆⻇⻈⻉⻊⻋⻌⻍⻎⻏⻐⻑⻒⻓⻔⻕⻖⻗⻘⻙⻚⻛⻜⻝⻞⻟⻠';
$find = '⺐';
$result = Multibyte::strrichr($string, $find, true);
$expected = '⺀⺁⺂⺃⺄⺅⺆⺇⺈⺉⺊⺋⺌⺍⺎⺏';
$this->assertEqual($expected, $result);
$string = '⽅⽆⽇⽈⽉⽊⽋⽌⽍⽎⽏⽐⽑⽒⽓⽔⽕⽖⽗⽘⽙⽚⽛⽜⽝⽞⽟⽠⽡⽢⽣⽤⽥⽦⽧⽨⽩⽪⽫⽬⽭⽮⽯⽰⽱⽲⽳⽴⽵⽶⽷⽸⽹⽺⽻⽼⽽⽾⽿';
$find = '⽤';
$result = Multibyte::strrichr($string, $find);
$expected = '⽤⽥⽦⽧⽨⽩⽪⽫⽬⽭⽮⽯⽰⽱⽲⽳⽴⽵⽶⽷⽸⽹⽺⽻⽼⽽⽾⽿';
$this->assertEqual($expected, $result);
$string = '⽅⽆⽇⽈⽉⽊⽋⽌⽍⽎⽏⽐⽑⽒⽓⽔⽕⽖⽗⽘⽙⽚⽛⽜⽝⽞⽟⽠⽡⽢⽣⽤⽥⽦⽧⽨⽩⽪⽫⽬⽭⽮⽯⽰⽱⽲⽳⽴⽵⽶⽷⽸⽹⽺⽻⽼⽽⽾⽿';
$find = '⽤';
$result = Multibyte::strrichr($string, $find, true);
$expected = '⽅⽆⽇⽈⽉⽊⽋⽌⽍⽎⽏⽐⽑⽒⽓⽔⽕⽖⽗⽘⽙⽚⽛⽜⽝⽞⽟⽠⽡⽢⽣';
$this->assertEqual($expected, $result);
$string = '눡눢눣눤눥눦눧눨눩눪눫눬눭눮눯눰눱눲눳눴눵눶눷눸눹눺눻눼눽눾눿뉀뉁뉂뉃뉄뉅뉆뉇뉈뉉뉊뉋뉌뉍뉎뉏뉐뉑뉒뉓뉔뉕뉖뉗뉘뉙뉚뉛뉜뉝뉞뉟뉠뉡뉢뉣뉤뉥뉦뉧뉨뉩뉪뉫뉬뉭뉮뉯뉰뉱뉲뉳뉴뉵뉶뉷뉸뉹뉺뉻뉼뉽뉾뉿늀늁늂늃늄';
$find = '눻';
$result = Multibyte::strrichr($string, $find);
$expected = '눻눼눽눾눿뉀뉁뉂뉃뉄뉅뉆뉇뉈뉉뉊뉋뉌뉍뉎뉏뉐뉑뉒뉓뉔뉕뉖뉗뉘뉙뉚뉛뉜뉝뉞뉟뉠뉡뉢뉣뉤뉥뉦뉧뉨뉩뉪뉫뉬뉭뉮뉯뉰뉱뉲뉳뉴뉵뉶뉷뉸뉹뉺뉻뉼뉽뉾뉿늀늁늂늃늄';
$this->assertEqual($expected, $result);
$string = '눡눢눣눤눥눦눧눨눩눪눫눬눭눮눯눰눱눲눳눴눵눶눷눸눹눺눻눼눽눾눿뉀뉁뉂뉃뉄뉅뉆뉇뉈뉉뉊뉋뉌뉍뉎뉏뉐뉑뉒뉓뉔뉕뉖뉗뉘뉙뉚뉛뉜뉝뉞뉟뉠뉡뉢뉣뉤뉥뉦뉧뉨뉩뉪뉫뉬뉭뉮뉯뉰뉱뉲뉳뉴뉵뉶뉷뉸뉹뉺뉻뉼뉽뉾뉿늀늁늂늃늄';
$find = '눻';
$result = Multibyte::strrichr($string, $find, true);
$expected = '눡눢눣눤눥눦눧눨눩눪눫눬눭눮눯눰눱눲눳눴눵눶눷눸눹눺';
$this->assertEqual($expected, $result);
$string = 'ﹰﹱﹲﹳﹴﹶﹷﹸﹹﹺﹻﹼﹽﹾﹿﺀﺁﺂﺃﺄﺅﺆﺇﺈﺉﺊﺋﺌﺍﺎﺏﺐﺑﺒﺓﺔﺕﺖﺗﺘﺙﺚﺛﺜﺝﺞﺟﺠﺡﺢﺣﺤﺥﺦﺧﺨﺩﺪﺫﺬﺭﺮﺯﺰ';
$find = 'ﺞ';
$result = Multibyte::strrichr($string, $find);
$expected = 'ﺞﺟﺠﺡﺢﺣﺤﺥﺦﺧﺨﺩﺪﺫﺬﺭﺮﺯﺰ';
$this->assertEqual($expected, $result);
$string = 'ﹰﹱﹲﹳﹴﹶﹷﹸﹹﹺﹻﹼﹽﹾﹿﺀﺁﺂﺃﺄﺅﺆﺇﺈﺉﺊﺋﺌﺍﺎﺏﺐﺑﺒﺓﺔﺕﺖﺗﺘﺙﺚﺛﺜﺝﺞﺟﺠﺡﺢﺣﺤﺥﺦﺧﺨﺩﺪﺫﺬﺭﺮﺯﺰ';
$find = 'ﺞ';
$result = Multibyte::strrichr($string, $find, true);
$expected = 'ﹰﹱﹲﹳﹴﹶﹷﹸﹹﹺﹻﹼﹽﹾﹿﺀﺁﺂﺃﺄﺅﺆﺇﺈﺉﺊﺋﺌﺍﺎﺏﺐﺑﺒﺓﺔﺕﺖﺗﺘﺙﺚﺛﺜﺝ';
$this->assertEqual($expected, $result);
$string = 'ﺱﺲﺳﺴﺵﺶﺷﺸﺹﺺﺻﺼﺽﺾﺿﻀﻁﻂﻃﻄﻅﻆﻇﻈﻉﻊﻋﻌﻍﻎﻏﻐﻑﻒﻓﻔﻕﻖﻗﻘﻙﻚﻛﻜﻝﻞﻟﻠﻡﻢﻣﻤﻥﻦﻧﻨﻩﻪﻫﻬﻭﻮﻯﻰﻱﻲﻳﻴﻵﻶﻷﻸﻹﻺﻻﻼ';
$find = 'ﻞ';
$result = Multibyte::strrichr($string, $find);
$expected = 'ﻞﻟﻠﻡﻢﻣﻤﻥﻦﻧﻨﻩﻪﻫﻬﻭﻮﻯﻰﻱﻲﻳﻴﻵﻶﻷﻸﻹﻺﻻﻼ';
$this->assertEqual($expected, $result);
$string = 'ﺱﺲﺳﺴﺵﺶﺷﺸﺹﺺﺻﺼﺽﺾﺿﻀﻁﻂﻃﻄﻅﻆﻇﻈﻉﻊﻋﻌﻍﻎﻏﻐﻑﻒﻓﻔﻕﻖﻗﻘﻙﻚﻛﻜﻝﻞﻟﻠﻡﻢﻣﻤﻥﻦﻧﻨﻩﻪﻫﻬﻭﻮﻯﻰﻱﻲﻳﻴﻵﻶﻷﻸﻹﻺﻻﻼ';
$find = 'ﻞ';
$result = Multibyte::strrichr($string, $find, true);
$expected = 'ﺱﺲﺳﺴﺵﺶﺷﺸﺹﺺﺻﺼﺽﺾﺿﻀﻁﻂﻃﻄﻅﻆﻇﻈﻉﻊﻋﻌﻍﻎﻏﻐﻑﻒﻓﻔﻕﻖﻗﻘﻙﻚﻛﻜﻝ';
$this->assertEqual($expected, $result);
$string = 'abcdefghijklmnopqrstuvwxyz';
$find = 'k';
$result = Multibyte::strrichr($string, $find);
$expected = 'klmnopqrstuvwxyz';
$this->assertEqual($expected, $result);
$string = 'abcdefghijklmnopqrstuvwxyz';
$find = 'k';
$result = Multibyte::strrichr($string, $find, true);
$expected = 'abcdefghij';
$this->assertEqual($expected, $result);
$string = '。「」、・ヲァィゥェォャュョッーアイウエオカキク';
$find = 'ア';
$result = Multibyte::strrichr($string, $find);
$expected = 'アイウエオカキク';
$this->assertEqual($expected, $result);
$string = '。「」、・ヲァィゥェォャュョッーアイウエオカキク';
$find = 'ア';
$result = Multibyte::strrichr($string, $find, true);
$expected = '。「」、・ヲァィゥェォャュョッー';
$this->assertEqual($expected, $result);
$string = 'ケコサシスセソタチツテトナニヌネノハヒフヘホマミムメモヤユヨラリルレロワン゙';
$find = 'ハ';
$result = Multibyte::strrichr($string, $find);
$expected = 'ハヒフヘホマミムメモヤユヨラリルレロワン゙';
$this->assertEqual($expected, $result);
$string = 'ケコサシスセソタチツテトナニヌネノハヒフヘホマミムメモヤユヨラリルレロワン゙';
$find = 'ハ';
$result = Multibyte::strrichr($string, $find, true);
$expected = 'ケコサシスセソタチツテトナニヌネノ';
$this->assertEqual($expected, $result);
$string = 'Ĥēĺļŏ, Ŵőřļď!';
$find = 'ő';
$result = Multibyte::strrichr($string, $find);
$expected = 'őřļď!';
$this->assertEqual($expected, $result);
$string = 'Ĥēĺļŏ, Ŵőřļď!';
$find = 'ő';
$result = Multibyte::strrichr($string, $find, true);
$expected = 'Ĥēĺļŏ, Ŵ';
$this->assertEqual($expected, $result);
$string = 'Hello, World!';
$find = 'o';
$result = Multibyte::strrichr($string, $find);
$expected = 'orld!';
$this->assertEqual($expected, $result);
$string = 'Hello, World!';
$find = 'o';
$result = Multibyte::strrichr($string, $find, true);
$expected = 'Hello, W';
$this->assertEqual($expected, $result);
$string = 'Hello, World!';
$find = 'Wo';
$result = Multibyte::strrichr($string, $find);
$expected = 'World!';
$this->assertEqual($expected, $result);
$string = 'Hello, World!';
$find = 'Wo';
$result = Multibyte::strrichr($string, $find, true);
$expected = 'Hello, ';
$this->assertEqual($expected, $result);
$string = 'Hello, World!';
$find = 'll';
$result = Multibyte::strrichr($string, $find);
$expected = 'llo, World!';
$this->assertEqual($expected, $result);
$string = 'Hello, World!';
$find = 'll';
$result = Multibyte::strrichr($string, $find, true);
$expected = 'He';
$this->assertEqual($expected, $result);
$string = 'Hello, World!';
$find = 'rld';
$result = Multibyte::strrichr($string, $find);
$expected = 'rld!';
$this->assertEqual($expected, $result);
$string = 'Hello, World!';
$find = 'rld';
$result = Multibyte::strrichr($string, $find, true);
$expected = 'Hello, Wo';
$this->assertEqual($expected, $result);
$string = 'čini';
$find = 'n';
$result = Multibyte::strrichr($string, $find);
$expected = 'ni';
$this->assertEqual($expected, $result);
$string = 'čini';
$find = 'n';
$result = Multibyte::strrichr($string, $find, true);
$expected = 'či';
$this->assertEqual($expected, $result);
$string = 'moći';
$find = 'ć';
$result = Multibyte::strrichr($string, $find);
$expected = 'ći';
$this->assertEqual($expected, $result);
$string = 'moći';
$find = 'ć';
$result = Multibyte::strrichr($string, $find, true);
$expected = 'mo';
$this->assertEqual($expected, $result);
$string = 'državni';
$find = 'ž';
$result = Multibyte::strrichr($string, $find);
$expected = 'žavni';
$this->assertEqual($expected, $result);
$string = 'državni';
$find = 'ž';
$result = Multibyte::strrichr($string, $find, true);
$expected = 'dr';
$this->assertEqual($expected, $result);
$string = '把百度设为首页';
$find = '设';
$result = Multibyte::strrichr($string, $find);
$expected = '设为首页';
$this->assertEqual($expected, $result);
$string = '把百度设为首页';
$find = '设';
$result = Multibyte::strrichr($string, $find, true);
$expected = '把百度';
$this->assertEqual($expected, $result);
$string = '一二三周永龍';
$find = '周';
$result = Multibyte::strrichr($string, $find);
$expected = '周永龍';
$this->assertEqual($expected, $result);
$string = '一二三周永龍';
$find = '周';
$result = Multibyte::strrichr($string, $find, true);
$expected = '一二三';
$this->assertEqual($expected, $result);
$string = '把百度设为首页';
$find = '百设';
$result = Multibyte::strrichr($string, $find, true);
$expected = false;
$this->assertEqual($expected, $result);
}
/**
* testUsingMbStrripos method
*
* @return void
*/
public function testUsingMbStrripos() {
$string = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
$find = 'F';
$result = mb_strripos($string, $find);
$expected = 5;
$this->assertEqual($expected, $result);
$string = 'ABCDEFGHIJKLMNOPQFRSTUVWXYZ0123456789';
$find = 'F';
$result = mb_strripos($string, $find, 6);
$expected = 17;
$this->assertEqual($expected, $result);
$string = 'ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞ';
$find = 'Å';
$result = mb_strripos($string, $find);
$expected = 5;
$this->assertEqual($expected, $result);
$string = 'ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÅÙÚÛÜÝÞ';
$find = 'Å';
$result = mb_strripos($string, $find, 6);
$expected = 24;
$this->assertEqual($expected, $result);
$string = 'ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÅÙÚÛÜÝÞ';
$find = 'ÓÔ';
$result = mb_strripos($string, $find);
$expected = 19;
$this->assertEqual($expected, $result);
$string = 'ĀĂĄĆĈĊČĎĐĒĔĖĘĚĜĞĠĢĤĦĨĪĬĮIJĴĶĹĻĽĿŁŃŅŇŊŌŎŐŒŔŖŘŚŜŞŠŢŤŦŨŪŬŮŰŲŴŶŹŻŽ';
$find = 'Ċ';
$result = mb_strripos($string, $find);
$expected = 5;
$this->assertEqual($expected, $result);
$string = 'ĀĂĄĆĈĊČĎĐĒĔĖĘĚĜĞĠĢĤĦĨĪĬĮIJĴĶĹĻĽĿŁĊŃŅŇŊŌŎŐŒŔŖŘŚŜŞŠŢŤŦŨŪŬŮŰŲŴŶŹŻŽ';
$find = 'Ċ';
$result = mb_strripos($string, $find, 6);
$expected = 32;
$this->assertEqual($expected, $result);
$string = '!"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~';
$find = 'F';
$result = mb_strripos($string, $find);
$expected = 69;
$this->assertEqual($expected, $result);
$string = '¡¢£¤¥¦§¨©ª«¬®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈ';
$find = 'µ';
$result = mb_strripos($string, $find);
$expected = 20;
$this->assertEqual($expected, $result);
$string = 'ÉÊËÌÍÎÏÐÑÒÓÔÕÖרÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿĀāĂ㥹ĆćĈĉĊċČčĎďĐđĒēĔĕĖėĘęĚěĜĝĞğĠġĢģĤĥĦħĨĩĪīĬ';
$find = 'é';
$result = mb_strripos($string, $find);
$expected = 32;
$this->assertEqual($expected, $result);
$string = 'ĭĮįİıIJijĴĵĶķĸĹĺĻļĽľĿŀŁłŃńŅņŇňʼnŊŋŌōŎŏŐőŒœŔŕŖŗŘřŚśŜŝŞşŠšŢţŤťŦŧŨũŪūŬŭŮůŰűŲųŴŵŶŷŸŹźŻżŽžſƀƁƂƃƄƅƆƇƈƉƊƋƌƍƎƏƐ';
$find = 'Ņ';
$result = mb_strripos($string, $find);
$expected = 25;
$this->assertEqual($expected, $result);
$string = 'ƑƒƓƔƕƖƗƘƙƚƛƜƝƞƟƠơƢƣƤƥƦƧƨƩƪƫƬƭƮƯưƱƲƳƴƵƶƷƸƹƺƻƼƽƾƿǀǁǂǃDŽDždžLJLjljNJNjnjǍǎǏǐǑǒǓǔǕǖǗǘǙǚǛǜǝǞǟǠǡǢǣǤǥǦǧǨǩǪǫǬǭǮǯǰDZDzdzǴ';
$find = 'Ƹ';
$result = mb_strripos($string, $find);
$expected = 40;
$this->assertEqual($expected, $result);
$string = 'ƑƒƓƔƕƖƗƘƙƚƛƜƝƞƟƠơƢƣƤƥƦƧƨƩƪƫƬƭƮƯưƱƲƳƴƵƶƷƸƹƺƻƼƽƾƿǀǁǂǃDŽDždžLJLjljNJNjnjǍǎǏǐǑǒǓǔǕǖǗǘǙǚǛǜǝǞǟǠǡǢǣǤǥǦǧǨǩǪǫǬǭǮǯǰDZDzdzǴ';
$find = 'ƹ';
$result = mb_strripos($string, $find);
$expected = 40;
$this->assertEqual($expected, $result);
$string = 'əɚɛɜɝɞɟɠɡɢɣɤɥɦɧɨɩɪɫɬɭɮɯɰɱɲɳɴɵɶɷɸɹɺɻɼɽɾɿʀʁʂʃʄʅʆʇʈʉʊʋʌʍʎʏʐʑʒʓʔʕʖʗʘʙʚʛʜʝʞʟʠʡʢʣʤʥʦʧʨʩʪʫʬʭʮʯʰʱʲʳʴʵʶʷʸʹʺʻʼ';
$find = 'ʀ';
$result = mb_strripos($string, $find);
$expected = 39;
$this->assertEqual($expected, $result);
$string = 'ЀЁЂЃЄЅІЇЈЉЊЋЌЍЎЏАБВГДЕЖЗИЙКЛ';
$find = 'Ї';
$result = mb_strripos($string, $find);
$expected = 7;
$this->assertEqual($expected, $result);
$string = 'МНОПРСТУФХЦЧШЩЪЫЬЭЮЯабвгдежзийклмнопрстуфхцчшщъыь';
$find = 'Р';
$result = mb_strripos($string, $find);
$expected = 36;
$this->assertEqual($expected, $result);
$string = 'МНОПРСТУФХЦЧШЩЪЫЬЭЮЯабвгдежзийклмнопрстуфхцчшщъыь';
$find = 'р';
$result = mb_strripos($string, $find, 5);
$expected = 36;
$this->assertEqual($expected, $result);
$string = 'فقكلمنهوىيًٌٍَُ';
$find = 'ن';
$result = mb_strripos($string, $find);
$expected = 5;
$this->assertEqual($expected, $result);
$string = '✰✱✲✳✴✵✶✷✸✹✺✻✼✽✾✿❀❁❂❃❄❅❆❇❈❉❊❋❌❍❎❏❐❑❒❓❔❕❖❗❘❙❚❛❜❝❞';
$find = '✿';
$result = mb_strripos($string, $find);
$expected = 15;
$this->assertEqual($expected, $result);
$string = '⺀⺁⺂⺃⺄⺅⺆⺇⺈⺉⺊⺋⺌⺍⺎⺏⺐⺑⺒⺓⺔⺕⺖⺗⺘⺙⺛⺜⺝⺞⺟⺠⺡⺢⺣⺤⺥⺦⺧⺨⺩⺪⺫⺬⺭⺮⺯⺰⺱⺲⺳⺴⺵⺶⺷⺸⺹⺺⺻⺼⺽⺾⺿⻀⻁⻂⻃⻄⻅⻆⻇⻈⻉⻊⻋⻌⻍⻎⻏⻐⻑⻒⻓⻔⻕⻖⻗⻘⻙⻚⻛⻜⻝⻞⻟⻠';
$find = '⺐';
$result = mb_strripos($string, $find);
$expected = 16;
$this->assertEqual($expected, $result);
$string = '⽅⽆⽇⽈⽉⽊⽋⽌⽍⽎⽏⽐⽑⽒⽓⽔⽕⽖⽗⽘⽙⽚⽛⽜⽝⽞⽟⽠⽡⽢⽣⽤⽥⽦⽧⽨⽩⽪⽫⽬⽭⽮⽯⽰⽱⽲⽳⽴⽵⽶⽷⽸⽹⽺⽻⽼⽽⽾⽿';
$find = '⽤';
$result = mb_strripos($string, $find);
$expected = 31;
$this->assertEqual($expected, $result);
$string = '눡눢눣눤눥눦눧눨눩눪눫눬눭눮눯눰눱눲눳눴눵눶눷눸눹눺눻눼눽눾눿뉀뉁뉂뉃뉄뉅뉆뉇뉈뉉뉊뉋뉌뉍뉎뉏뉐뉑뉒뉓뉔뉕뉖뉗뉘뉙뉚뉛뉜뉝뉞뉟뉠뉡뉢뉣뉤뉥뉦뉧뉨뉩뉪뉫뉬뉭뉮뉯뉰뉱뉲뉳뉴뉵뉶뉷뉸뉹뉺뉻뉼뉽뉾뉿늀늁늂늃늄';
$find = '눻';
$result = mb_strripos($string, $find);
$expected = 26;
$this->assertEqual($expected, $result);
$string = 'ﹰﹱﹲﹳﹴﹶﹷﹸﹹﹺﹻﹼﹽﹾﹿﺀﺁﺂﺃﺄﺅﺆﺇﺈﺉﺊﺋﺌﺍﺎﺏﺐﺑﺒﺓﺔﺕﺖﺗﺘﺙﺚﺛﺜﺝﺞﺟﺠﺡﺢﺣﺤﺥﺦﺧﺨﺩﺪﺫﺬﺭﺮﺯﺰ';
$find = 'ﺞ';
$result = mb_strripos($string, $find);
$expected = 46;
$this->assertEqual($expected, $result);
$string = 'ﺱﺲﺳﺴﺵﺶﺷﺸﺹﺺﺻﺼﺽﺾﺿﻀﻁﻂﻃﻄﻅﻆﻇﻈﻉﻊﻋﻌﻍﻎﻏﻐﻑﻒﻓﻔﻕﻖﻗﻘﻙﻚﻛﻜﻝﻞﻟﻠﻡﻢﻣﻤﻥﻦﻧﻨﻩﻪﻫﻬﻭﻮﻯﻰﻱﻲﻳﻴﻵﻶﻷﻸﻹﻺﻻﻼ';
$find = 'ﻞ';
$result = mb_strripos($string, $find);
$expected = 45;
$this->assertEqual($expected, $result);
$string = 'abcdefghijklmnopqrstuvwxyz';
$find = 'k';
$result = mb_strripos($string, $find);
$expected = 10;
$this->assertEqual($expected, $result);
$string = 'abcdefghijklmnopqrstuvwxyz';
$find = 'k';
$result = mb_strripos($string, $find);
$expected = 10;
$this->assertEqual($expected, $result);
$string = 'abcdefghijklmnoppqrstuvwxyz';
$find = 'pp';
$result = mb_strripos($string, $find);
$expected = 15;
$this->assertEqual($expected, $result);
$string = '。「」、・ヲァィゥェォャュョッーアイウエオカキク';
$find = 'ア';
$result = mb_strripos($string, $find);
$expected = 16;
$this->assertEqual($expected, $result);
$string = 'ケコサシスセソタチツテトナニヌネノハヒフヘホマミムメモヤユヨラリルレロワン゙';
$find = 'ハ';
$result = mb_strripos($string, $find);
$expected = 17;
$this->assertEqual($expected, $result);
$string = 'Ĥēĺļŏ, Ŵőřļď!';
$find = 'ő';
$result = mb_strripos($string, $find);
$expected = 8;
$this->assertEqual($expected, $result);
$string = 'Ĥēĺļŏ, Ŵőřļď!';
$find = 'ő';
$result = mb_strripos($string, $find);
$expected = 8;
$this->assertEqual($expected, $result);
$string = 'Hello, World!';
$find = 'o';
$result = mb_strripos($string, $find);
$expected = 8;
$this->assertEqual($expected, $result);
$string = 'Hello, World!';
$find = 'o';
$result = mb_strripos($string, $find, 5);
$expected = 8;
$this->assertEqual($expected, $result);
$string = 'čini';
$find = 'n';
$result = mb_strripos($string, $find);
$expected = 2;
$this->assertEqual($expected, $result);
$string = 'čini';
$find = 'n';
$result = mb_strripos($string, $find);
$expected = 2;
$this->assertEqual($expected, $result);
$string = 'moći';
$find = 'ć';
$result = mb_strripos($string, $find);
$expected = 2;
$this->assertEqual($expected, $result);
$string = 'moći';
$find = 'ć';
$result = mb_strripos($string, $find);
$expected = 2;
$this->assertEqual($expected, $result);
$string = 'državni';
$find = 'ž';
$result = mb_strripos($string, $find);
$expected = 2;
$this->assertEqual($expected, $result);
$string = '把百度设为首页';
$find = '设';
$result = mb_strripos($string, $find);
$expected = 3;
$this->assertEqual($expected, $result);
$string = '一二三周永龍';
$find = '周';
$result = mb_strripos($string, $find);
$expected = 3;
$this->assertEqual($expected, $result);
$string = 'državni';
$find = 'dž';
$result = mb_strripos($string, $find);
$this->assertFalse($result);
}
/**
* testMultibyteStrripos method
*
* @return void
*/
public function testMultibyteStrripos() {
$string = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
$find = 'F';
$result = Multibyte::strripos($string, $find);
$expected = 5;
$this->assertEqual($expected, $result);
$string = 'ABCDEFGHIJKLMNOPQFRSTUVWXYZ0123456789';
$find = 'F';
$result = Multibyte::strripos($string, $find, 6);
$expected = 17;
$this->assertEqual($expected, $result);
$string = 'ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞ';
$find = 'Å';
$result = Multibyte::strripos($string, $find);
$expected = 5;
$this->assertEqual($expected, $result);
$string = 'ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÅÙÚÛÜÝÞ';
$find = 'Å';
$result = Multibyte::strripos($string, $find, 6);
$expected = 24;
$this->assertEqual($expected, $result);
$string = 'ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÅÙÚÛÜÝÞ';
$find = 'ÓÔ';
$result = Multibyte::strripos($string, $find);
$expected = 19;
$this->assertEqual($expected, $result);
$string = 'ĀĂĄĆĈĊČĎĐĒĔĖĘĚĜĞĠĢĤĦĨĪĬĮIJĴĶĹĻĽĿŁŃŅŇŊŌŎŐŒŔŖŘŚŜŞŠŢŤŦŨŪŬŮŰŲŴŶŹŻŽ';
$find = 'Ċ';
$result = Multibyte::strripos($string, $find);
$expected = 5;
$this->assertEqual($expected, $result);
$string = 'ĀĂĄĆĈĊČĎĐĒĔĖĘĚĜĞĠĢĤĦĨĪĬĮIJĴĶĹĻĽĿŁĊŃŅŇŊŌŎŐŒŔŖŘŚŜŞŠŢŤŦŨŪŬŮŰŲŴŶŹŻŽ';
$find = 'Ċ';
$result = Multibyte::strripos($string, $find, 6);
$expected = 32;
$this->assertEqual($expected, $result);
$string = '!"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~';
$find = 'F';
$result = Multibyte::strripos($string, $find);
$expected = 69;
$this->assertEqual($expected, $result);
$string = '¡¢£¤¥¦§¨©ª«¬®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈ';
$find = 'µ';
$result = Multibyte::strripos($string, $find);
$expected = 20;
$this->assertEqual($expected, $result);
$string = 'ÉÊËÌÍÎÏÐÑÒÓÔÕÖרÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿĀāĂ㥹ĆćĈĉĊċČčĎďĐđĒēĔĕĖėĘęĚěĜĝĞğĠġĢģĤĥĦħĨĩĪīĬ';
$find = 'é';
$result = Multibyte::strripos($string, $find);
$expected = 32;
$this->assertEqual($expected, $result);
$string = 'ĭĮįİıIJijĴĵĶķĸĹĺĻļĽľĿŀŁłŃńŅņŇňʼnŊŋŌōŎŏŐőŒœŔŕŖŗŘřŚśŜŝŞşŠšŢţŤťŦŧŨũŪūŬŭŮůŰűŲųŴŵŶŷŸŹźŻżŽžſƀƁƂƃƄƅƆƇƈƉƊƋƌƍƎƏƐ';
$find = 'Ņ';
$result = Multibyte::strripos($string, $find);
$expected = 25;
$this->assertEqual($expected, $result);
$string = 'ƑƒƓƔƕƖƗƘƙƚƛƜƝƞƟƠơƢƣƤƥƦƧƨƩƪƫƬƭƮƯưƱƲƳƴƵƶƷƸƹƺƻƼƽƾƿǀǁǂǃDŽDždžLJLjljNJNjnjǍǎǏǐǑǒǓǔǕǖǗǘǙǚǛǜǝǞǟǠǡǢǣǤǥǦǧǨǩǪǫǬǭǮǯǰDZDzdzǴ';
$find = 'Ƹ';
$result = Multibyte::strripos($string, $find);
$expected = 40;
$this->assertEqual($expected, $result);
$string = 'ƑƒƓƔƕƖƗƘƙƚƛƜƝƞƟƠơƢƣƤƥƦƧƨƩƪƫƬƭƮƯưƱƲƳƴƵƶƷƸƹƺƻƼƽƾƿǀǁǂǃDŽDždžLJLjljNJNjnjǍǎǏǐǑǒǓǔǕǖǗǘǙǚǛǜǝǞǟǠǡǢǣǤǥǦǧǨǩǪǫǬǭǮǯǰDZDzdzǴ';
$find = 'ƹ';
$result = Multibyte::strripos($string, $find);
$expected = 40;
$this->assertEqual($expected, $result);
$string = 'əɚɛɜɝɞɟɠɡɢɣɤɥɦɧɨɩɪɫɬɭɮɯɰɱɲɳɴɵɶɷɸɹɺɻɼɽɾɿʀʁʂʃʄʅʆʇʈʉʊʋʌʍʎʏʐʑʒʓʔʕʖʗʘʙʚʛʜʝʞʟʠʡʢʣʤʥʦʧʨʩʪʫʬʭʮʯʰʱʲʳʴʵʶʷʸʹʺʻʼ';
$find = 'ʀ';
$result = Multibyte::strripos($string, $find);
$expected = 39;
$this->assertEqual($expected, $result);
$string = 'ЀЁЂЃЄЅІЇЈЉЊЋЌЍЎЏАБВГДЕЖЗИЙКЛ';
$find = 'Ї';
$result = Multibyte::strripos($string, $find);
$expected = 7;
$this->assertEqual($expected, $result);
$string = 'МНОПРСТУФХЦЧШЩЪЫЬЭЮЯабвгдежзийклмнопрстуфхцчшщъыь';
$find = 'Р';
$result = Multibyte::strripos($string, $find);
$expected = 36;
$this->assertEqual($expected, $result);
$string = 'МНОПРСТУФХЦЧШЩЪЫЬЭЮЯабвгдежзийклмнопрстуфхцчшщъыь';
$find = 'р';
$result = Multibyte::strripos($string, $find, 5);
$expected = 36;
$this->assertEqual($expected, $result);
$string = 'فقكلمنهوىيًٌٍَُ';
$find = 'ن';
$result = Multibyte::strripos($string, $find);
$expected = 5;
$this->assertEqual($expected, $result);
$string = '✰✱✲✳✴✵✶✷✸✹✺✻✼✽✾✿❀❁❂❃❄❅❆❇❈❉❊❋❌❍❎❏❐❑❒❓❔❕❖❗❘❙❚❛❜❝❞';
$find = '✿';
$result = Multibyte::strripos($string, $find);
$expected = 15;
$this->assertEqual($expected, $result);
$string = '⺀⺁⺂⺃⺄⺅⺆⺇⺈⺉⺊⺋⺌⺍⺎⺏⺐⺑⺒⺓⺔⺕⺖⺗⺘⺙⺛⺜⺝⺞⺟⺠⺡⺢⺣⺤⺥⺦⺧⺨⺩⺪⺫⺬⺭⺮⺯⺰⺱⺲⺳⺴⺵⺶⺷⺸⺹⺺⺻⺼⺽⺾⺿⻀⻁⻂⻃⻄⻅⻆⻇⻈⻉⻊⻋⻌⻍⻎⻏⻐⻑⻒⻓⻔⻕⻖⻗⻘⻙⻚⻛⻜⻝⻞⻟⻠';
$find = '⺐';
$result = Multibyte::strripos($string, $find);
$expected = 16;
$this->assertEqual($expected, $result);
$string = '⽅⽆⽇⽈⽉⽊⽋⽌⽍⽎⽏⽐⽑⽒⽓⽔⽕⽖⽗⽘⽙⽚⽛⽜⽝⽞⽟⽠⽡⽢⽣⽤⽥⽦⽧⽨⽩⽪⽫⽬⽭⽮⽯⽰⽱⽲⽳⽴⽵⽶⽷⽸⽹⽺⽻⽼⽽⽾⽿';
$find = '⽤';
$result = Multibyte::strripos($string, $find);
$expected = 31;
$this->assertEqual($expected, $result);
$string = '눡눢눣눤눥눦눧눨눩눪눫눬눭눮눯눰눱눲눳눴눵눶눷눸눹눺눻눼눽눾눿뉀뉁뉂뉃뉄뉅뉆뉇뉈뉉뉊뉋뉌뉍뉎뉏뉐뉑뉒뉓뉔뉕뉖뉗뉘뉙뉚뉛뉜뉝뉞뉟뉠뉡뉢뉣뉤뉥뉦뉧뉨뉩뉪뉫뉬뉭뉮뉯뉰뉱뉲뉳뉴뉵뉶뉷뉸뉹뉺뉻뉼뉽뉾뉿늀늁늂늃늄';
$find = '눻';
$result = Multibyte::strripos($string, $find);
$expected = 26;
$this->assertEqual($expected, $result);
$string = 'ﹰﹱﹲﹳﹴﹶﹷﹸﹹﹺﹻﹼﹽﹾﹿﺀﺁﺂﺃﺄﺅﺆﺇﺈﺉﺊﺋﺌﺍﺎﺏﺐﺑﺒﺓﺔﺕﺖﺗﺘﺙﺚﺛﺜﺝﺞﺟﺠﺡﺢﺣﺤﺥﺦﺧﺨﺩﺪﺫﺬﺭﺮﺯﺰ';
$find = 'ﺞ';
$result = Multibyte::strripos($string, $find);
$expected = 46;
$this->assertEqual($expected, $result);
$string = 'ﺱﺲﺳﺴﺵﺶﺷﺸﺹﺺﺻﺼﺽﺾﺿﻀﻁﻂﻃﻄﻅﻆﻇﻈﻉﻊﻋﻌﻍﻎﻏﻐﻑﻒﻓﻔﻕﻖﻗﻘﻙﻚﻛﻜﻝﻞﻟﻠﻡﻢﻣﻤﻥﻦﻧﻨﻩﻪﻫﻬﻭﻮﻯﻰﻱﻲﻳﻴﻵﻶﻷﻸﻹﻺﻻﻼ';
$find = 'ﻞ';
$result = Multibyte::strripos($string, $find);
$expected = 45;
$this->assertEqual($expected, $result);
$string = 'abcdefghijklmnopqrstuvwxyz';
$find = 'k';
$result = Multibyte::strripos($string, $find);
$expected = 10;
$this->assertEqual($expected, $result);
$string = 'abcdefghijklmnopqrstuvwxyz';
$find = 'k';
$result = Multibyte::strripos($string, $find);
$expected = 10;
$this->assertEqual($expected, $result);
$string = 'abcdefghijklmnoppqrstuvwxyz';
$find = 'pp';
$result = Multibyte::strripos($string, $find);
$expected = 15;
$this->assertEqual($expected, $result);
$string = '。「」、・ヲァィゥェォャュョッーアイウエオカキク';
$find = 'ア';
$result = Multibyte::strripos($string, $find);
$expected = 16;
$this->assertEqual($expected, $result);
$string = 'ケコサシスセソタチツテトナニヌネノハヒフヘホマミムメモヤユヨラリルレロワン゙';
$find = 'ハ';
$result = Multibyte::strripos($string, $find);
$expected = 17;
$this->assertEqual($expected, $result);
$string = 'Ĥēĺļŏ, Ŵőřļď!';
$find = 'ő';
$result = Multibyte::strripos($string, $find);
$expected = 8;
$this->assertEqual($expected, $result);
$string = 'Ĥēĺļŏ, Ŵőřļď!';
$find = 'ő';
$result = Multibyte::strripos($string, $find);
$expected = 8;
$this->assertEqual($expected, $result);
$string = 'Hello, World!';
$find = 'o';
$result = Multibyte::strripos($string, $find);
$expected = 8;
$this->assertEqual($expected, $result);
$string = 'Hello, World!';
$find = 'o';
$result = Multibyte::strripos($string, $find, 5);
$expected = 8;
$this->assertEqual($expected, $result);
$string = 'čini';
$find = 'n';
$result = Multibyte::strripos($string, $find);
$expected = 2;
$this->assertEqual($expected, $result);
$string = 'čini';
$find = 'n';
$result = Multibyte::strripos($string, $find);
$expected = 2;
$this->assertEqual($expected, $result);
$string = 'moći';
$find = 'ć';
$result = Multibyte::strripos($string, $find);
$expected = 2;
$this->assertEqual($expected, $result);
$string = 'moći';
$find = 'ć';
$result = Multibyte::strripos($string, $find);
$expected = 2;
$this->assertEqual($expected, $result);
$string = 'državni';
$find = 'ž';
$result = Multibyte::strripos($string, $find);
$expected = 2;
$this->assertEqual($expected, $result);
$string = '把百度设为首页';
$find = '设';
$result = Multibyte::strripos($string, $find);
$expected = 3;
$this->assertEqual($expected, $result);
$string = '一二三周永龍';
$find = '周';
$result = Multibyte::strripos($string, $find);
$expected = 3;
$this->assertEqual($expected, $result);
$string = 'državni';
$find = 'dž';
$result = Multibyte::strripos($string, $find);
$expected = 0;
$this->assertEqual($expected, $result);
}
/**
* testUsingMbStrrpos method
*
* @return void
*/
public function testUsingMbStrrpos() {
$this->skipIf(extension_loaded('mbstring') && version_compare(PHP_VERSION, '5.2.0', '<'), 'PHP version does not support $offset parameter in mb_strrpos().');
$string = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
$find = 'F';
$result = mb_strrpos($string, $find);
$expected = 5;
$this->assertEqual($expected, $result);
$string = 'ABCDEFGHIJKLMNOPQFRSTUVWXYZ0123456789';
$find = 'F';
$result = mb_strrpos($string, $find, 6);
$expected = 17;
$this->assertEqual($expected, $result);
$string = 'ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞ';
$find = 'Å';
$result = mb_strrpos($string, $find);
$expected = 5;
$this->assertEqual($expected, $result);
$string = 'ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÅÙÚÛÜÝÞ';
$find = 'ÙÚ';
$result = mb_strrpos($string, $find);
$expected = 25;
$this->assertEqual($expected, $result);
$string = 'ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÅÙÚÛÜÝÞ';
$find = 'Å';
$result = mb_strrpos($string, $find, 6);
$expected = 24;
$this->assertEqual($expected, $result);
$string = 'ĀĂĄĆĈĊČĎĐĒĔĖĘĚĜĞĠĢĤĦĨĪĬĮIJĴĶĹĻĽĿŁŃŅŇŊŌŎŐŒŔŖŘŚŜŞŠŢŤŦŨŪŬŮŰŲŴŶŹŻŽ';
$find = 'Ċ';
$result = mb_strrpos($string, $find);
$expected = 5;
$this->assertEqual($expected, $result);
$string = 'ĀĂĄĆĈĊČĎĐĒĔĖĘĚĜĞĠĢĤĦĨĪĬĮIJĴĶĹĻĽĿŁĊŃŅŇŊŌŎŐŒŔŖŘŚŜŞŠŢŤŦŨŪŬŮŰŲŴŶŹŻŽ';
$find = 'Ċ';
$result = mb_strrpos($string, $find, 6);
$expected = 32;
$this->assertEqual($expected, $result);
$string = '!"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~';
$find = 'F';
$result = mb_strrpos($string, $find);
$expected = 37;
$this->assertEqual($expected, $result);
$string = '¡¢£¤¥¦§¨©ª«¬®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈ';
$find = 'µ';
$result = mb_strrpos($string, $find);
$expected = 20;
$this->assertEqual($expected, $result);
$string = 'ÉÊËÌÍÎÏÐÑÒÓÔÕÖרÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿĀāĂ㥹ĆćĈĉĊċČčĎďĐđĒēĔĕĖėĘęĚěĜĝĞğĠġĢģĤĥĦħĨĩĪīĬ';
$find = 'é';
$result = mb_strrpos($string, $find);
$expected = 32;
$this->assertEqual($expected, $result);
$string = 'ĭĮįİıIJijĴĵĶķĸĹĺĻļĽľĿŀŁłŃńŅņŇňʼnŊŋŌōŎŏŐőŒœŔŕŖŗŘřŚśŜŝŞşŠšŢţŤťŦŧŨũŪūŬŭŮůŰűŲųŴŵŶŷŸŹźŻżŽžſƀƁƂƃƄƅƆƇƈƉƊƋƌƍƎƏƐ';
$find = 'Ņ';
$result = mb_strrpos($string, $find);
$expected = 24;
$this->assertEqual($expected, $result);
$string = 'ƑƒƓƔƕƖƗƘƙƚƛƜƝƞƟƠơƢƣƤƥƦƧƨƩƪƫƬƭƮƯưƱƲƳƴƵƶƷƸƹƺƻƼƽƾƿǀǁǂǃDŽDždžLJLjljNJNjnjǍǎǏǐǑǒǓǔǕǖǗǘǙǚǛǜǝǞǟǠǡǢǣǤǥǦǧǨǩǪǫǬǭǮǯǰDZDzdzǴ';
$find = 'Ƹ';
$result = mb_strrpos($string, $find);
$expected = 39;
$this->assertEqual($expected, $result);
$string = 'ƑƒƓƔƕƖƗƘƙƚƛƜƝƞƟƠơƢƣƤƥƦƧƨƩƪƫƬƭƮƯưƱƲƳƴƵƶƷƸƹƺƻƼƽƾƿǀǁǂǃDŽDždžLJLjljNJNjnjǍǎǏǐǑǒǓǔǕǖǗǘǙǚǛǜǝǞǟǠǡǢǣǤǥǦǧǨǩǪǫǬǭǮǯǰDZDzdzǴ';
$find = 'ƹ';
$result = mb_strrpos($string, $find);
$expected = 40;
$this->assertEqual($expected, $result);
$string = 'əɚɛɜɝɞɟɠɡɢɣɤɥɦɧɨɩɪɫɬɭɮɯɰɱɲɳɴɵɶɷɸɹɺɻɼɽɾɿʀʁʂʃʄʅʆʇʈʉʊʋʌʍʎʏʐʑʒʓʔʕʖʗʘʙʚʛʜʝʞʟʠʡʢʣʤʥʦʧʨʩʪʫʬʭʮʯʰʱʲʳʴʵʶʷʸʹʺʻʼ';
$find = 'ʀ';
$result = mb_strrpos($string, $find);
$expected = 39;
$this->assertEqual($expected, $result);
$string = 'ЀЁЂЃЄЅІЇЈЉЊЋЌЍЎЏАБВГДЕЖЗИЙКЛ';
$find = 'Ї';
$result = mb_strrpos($string, $find);
$expected = 7;
$this->assertEqual($expected, $result);
$string = 'МНОПРСТУФХЦЧШЩЪЫЬЭЮЯабвгдежзийклмнопрстуфхцчшщъыь';
$find = 'Р';
$result = mb_strrpos($string, $find);
$expected = 4;
$this->assertEqual($expected, $result);
$string = 'МНОПРСТУФХЦЧШЩЪЫЬЭЮЯабвгдежзийклмнопрстуфхцчшщъыь';
$find = 'р';
$result = mb_strrpos($string, $find, 5);
$expected = 36;
$this->assertEqual($expected, $result);
$string = 'فقكلمنهوىيًٌٍَُ';
$find = 'ن';
$result = mb_strrpos($string, $find);
$expected = 5;
$this->assertEqual($expected, $result);
$string = '✰✱✲✳✴✵✶✷✸✹✺✻✼✽✾✿❀❁❂❃❄❅❆❇❈❉❊❋❌❍❎❏❐❑❒❓❔❕❖❗❘❙❚❛❜❝❞';
$find = '✿';
$result = mb_strrpos($string, $find);
$expected = 15;
$this->assertEqual($expected, $result);
$string = '⺀⺁⺂⺃⺄⺅⺆⺇⺈⺉⺊⺋⺌⺍⺎⺏⺐⺑⺒⺓⺔⺕⺖⺗⺘⺙⺛⺜⺝⺞⺟⺠⺡⺢⺣⺤⺥⺦⺧⺨⺩⺪⺫⺬⺭⺮⺯⺰⺱⺲⺳⺴⺵⺶⺷⺸⺹⺺⺻⺼⺽⺾⺿⻀⻁⻂⻃⻄⻅⻆⻇⻈⻉⻊⻋⻌⻍⻎⻏⻐⻑⻒⻓⻔⻕⻖⻗⻘⻙⻚⻛⻜⻝⻞⻟⻠';
$find = '⺐';
$result = mb_strrpos($string, $find);
$expected = 16;
$this->assertEqual($expected, $result);
$string = '⽅⽆⽇⽈⽉⽊⽋⽌⽍⽎⽏⽐⽑⽒⽓⽔⽕⽖⽗⽘⽙⽚⽛⽜⽝⽞⽟⽠⽡⽢⽣⽤⽥⽦⽧⽨⽩⽪⽫⽬⽭⽮⽯⽰⽱⽲⽳⽴⽵⽶⽷⽸⽹⽺⽻⽼⽽⽾⽿';
$find = '⽤';
$result = mb_strrpos($string, $find);
$expected = 31;
$this->assertEqual($expected, $result);
$string = '눡눢눣눤눥눦눧눨눩눪눫눬눭눮눯눰눱눲눳눴눵눶눷눸눹눺눻눼눽눾눿뉀뉁뉂뉃뉄뉅뉆뉇뉈뉉뉊뉋뉌뉍뉎뉏뉐뉑뉒뉓뉔뉕뉖뉗뉘뉙뉚뉛뉜뉝뉞뉟뉠뉡뉢뉣뉤뉥뉦뉧뉨뉩뉪뉫뉬뉭뉮뉯뉰뉱뉲뉳뉴뉵뉶뉷뉸뉹뉺뉻뉼뉽뉾뉿늀늁늂늃늄';
$find = '눻';
$result = mb_strrpos($string, $find);
$expected = 26;
$this->assertEqual($expected, $result);
$string = 'ﹰﹱﹲﹳﹴﹶﹷﹸﹹﹺﹻﹼﹽﹾﹿﺀﺁﺂﺃﺄﺅﺆﺇﺈﺉﺊﺋﺌﺍﺎﺏﺐﺑﺒﺓﺔﺕﺖﺗﺘﺙﺚﺛﺜﺝﺞﺟﺠﺡﺢﺣﺤﺥﺦﺧﺨﺩﺪﺫﺬﺭﺮﺯﺰ';
$find = 'ﺞ';
$result = mb_strrpos($string, $find);
$expected = 46;
$this->assertEqual($expected, $result);
$string = 'ﺱﺲﺳﺴﺵﺶﺷﺸﺹﺺﺻﺼﺽﺾﺿﻀﻁﻂﻃﻄﻅﻆﻇﻈﻉﻊﻋﻌﻍﻎﻏﻐﻑﻒﻓﻔﻕﻖﻗﻘﻙﻚﻛﻜﻝﻞﻟﻠﻡﻢﻣﻤﻥﻦﻧﻨﻩﻪﻫﻬﻭﻮﻯﻰﻱﻲﻳﻴﻵﻶﻷﻸﻹﻺﻻﻼ';
$find = 'ﻞ';
$result = mb_strrpos($string, $find);
$expected = 45;
$this->assertEqual($expected, $result);
$string = 'abcdefghijklmnopqrstuvwxyz';
$find = 'k';
$result = mb_strrpos($string, $find);
$expected = 10;
$this->assertEqual($expected, $result);
$string = 'abcdefghijklmnopqrstuvwxyz';
$find = 'k';
$result = mb_strrpos($string, $find);
$expected = 10;
$this->assertEqual($expected, $result);
$string = 'abcdefghijklmnoppqrstuvwxyz';
$find = 'pp';
$result = mb_strrpos($string, $find);
$expected = 15;
$this->assertEqual($expected, $result);
$string = '。「」、・ヲァィゥェォャュョッーアイウエオカキク';
$find = 'ア';
$result = mb_strrpos($string, $find);
$expected = 16;
$this->assertEqual($expected, $result);
$string = 'ケコサシスセソタチツテトナニヌネノハヒフヘホマミムメモヤユヨラリルレロワン゙';
$find = 'ハ';
$result = mb_strrpos($string, $find);
$expected = 17;
$this->assertEqual($expected, $result);
$string = 'Ĥēĺļŏ, Ŵőřļď!';
$find = 'ő';
$result = mb_strrpos($string, $find);
$expected = 8;
$this->assertEqual($expected, $result);
$string = 'Ĥēĺļŏ, Ŵőřļď!';
$find = 'ő';
$result = mb_strrpos($string, $find);
$expected = 8;
$this->assertEqual($expected, $result);
$string = 'Hello, World!';
$find = 'o';
$result = mb_strrpos($string, $find);
$expected = 8;
$this->assertEqual($expected, $result);
$string = 'Hello, World!';
$find = 'o';
$result = mb_strrpos($string, $find, 5);
$expected = 8;
$this->assertEqual($expected, $result);
$string = 'čini';
$find = 'n';
$result = mb_strrpos($string, $find);
$expected = 2;
$this->assertEqual($expected, $result);
$string = 'čini';
$find = 'n';
$result = mb_strrpos($string, $find);
$expected = 2;
$this->assertEqual($expected, $result);
$string = 'moći';
$find = 'ć';
$result = mb_strrpos($string, $find);
$expected = 2;
$this->assertEqual($expected, $result);
$string = 'moći';
$find = 'ć';
$result = mb_strrpos($string, $find);
$expected = 2;
$this->assertEqual($expected, $result);
$string = 'državni';
$find = 'ž';
$result = mb_strrpos($string, $find);
$expected = 2;
$this->assertEqual($expected, $result);
$string = '把百度设为首页';
$find = '设';
$result = mb_strrpos($string, $find);
$expected = 3;
$this->assertEqual($expected, $result);
$string = '一二三周永龍';
$find = '周';
$result = mb_strrpos($string, $find);
$expected = 3;
$this->assertEqual($expected, $result);
$string = 'Ĥēĺļŏ, Ŵőřļď!';
$find = 'H';
$result = mb_strrpos($string, $find);
$expected = false;
$this->assertEqual($expected, $result);
}
/**
* testMultibyteStrrpos method
*
* @return void
*/
public function testMultibyteStrrpos() {
$string = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
$find = 'F';
$result = Multibyte::strrpos($string, $find);
$expected = 5;
$this->assertEqual($expected, $result);
$string = 'ABCDEFGHIJKLMNOPQFRSTUVWXYZ0123456789';
$find = 'F';
$result = Multibyte::strrpos($string, $find, 6);
$expected = 17;
$this->assertEqual($expected, $result);
$string = 'ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞ';
$find = 'Å';
$result = Multibyte::strrpos($string, $find);
$expected = 5;
$this->assertEqual($expected, $result);
$string = 'ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÅÙÚÛÜÝÞ';
$find = 'Å';
$result = Multibyte::strrpos($string, $find, 6);
$expected = 24;
$this->assertEqual($expected, $result);
$string = 'ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÅÙÚÛÜÝÞ';
$find = 'ÙÚ';
$result = Multibyte::strrpos($string, $find);
$expected = 25;
$this->assertEqual($expected, $result);
$string = 'ĀĂĄĆĈĊČĎĐĒĔĖĘĚĜĞĠĢĤĦĨĪĬĮIJĴĶĹĻĽĿŁŃŅŇŊŌŎŐŒŔŖŘŚŜŞŠŢŤŦŨŪŬŮŰŲŴŶŹŻŽ';
$find = 'Ċ';
$result = Multibyte::strrpos($string, $find);
$expected = 5;
$this->assertEqual($expected, $result);
$string = 'ĀĂĄĆĈĊČĎĐĒĔĖĘĚĜĞĠĢĤĦĨĪĬĮIJĴĶĹĻĽĿŁĊŃŅŇŊŌŎŐŒŔŖŘŚŜŞŠŢŤŦŨŪŬŮŰŲŴŶŹŻŽ';
$find = 'Ċ';
$result = Multibyte::strrpos($string, $find, 6);
$expected = 32;
$this->assertEqual($expected, $result);
$string = '!"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~';
$find = 'F';
$result = Multibyte::strrpos($string, $find);
$expected = 37;
$this->assertEqual($expected, $result);
$string = '¡¢£¤¥¦§¨©ª«¬®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈ';
$find = 'µ';
$result = Multibyte::strrpos($string, $find);
$expected = 20;
$this->assertEqual($expected, $result);
$string = 'ÉÊËÌÍÎÏÐÑÒÓÔÕÖרÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿĀāĂ㥹ĆćĈĉĊċČčĎďĐđĒēĔĕĖėĘęĚěĜĝĞğĠġĢģĤĥĦħĨĩĪīĬ';
$find = 'é';
$result = Multibyte::strrpos($string, $find);
$expected = 32;
$this->assertEqual($expected, $result);
$string = 'ĭĮįİıIJijĴĵĶķĸĹĺĻļĽľĿŀŁłŃńŅņŇňʼnŊŋŌōŎŏŐőŒœŔŕŖŗŘřŚśŜŝŞşŠšŢţŤťŦŧŨũŪūŬŭŮůŰűŲųŴŵŶŷŸŹźŻżŽžſƀƁƂƃƄƅƆƇƈƉƊƋƌƍƎƏƐ';
$find = 'Ņ';
$result = Multibyte::strrpos($string, $find);
$expected = 24;
$this->assertEqual($expected, $result);
$string = 'ƑƒƓƔƕƖƗƘƙƚƛƜƝƞƟƠơƢƣƤƥƦƧƨƩƪƫƬƭƮƯưƱƲƳƴƵƶƷƸƹƺƻƼƽƾƿǀǁǂǃDŽDždžLJLjljNJNjnjǍǎǏǐǑǒǓǔǕǖǗǘǙǚǛǜǝǞǟǠǡǢǣǤǥǦǧǨǩǪǫǬǭǮǯǰDZDzdzǴ';
$find = 'Ƹ';
$result = Multibyte::strrpos($string, $find);
$expected = 39;
$this->assertEqual($expected, $result);
$string = 'ƑƒƓƔƕƖƗƘƙƚƛƜƝƞƟƠơƢƣƤƥƦƧƨƩƪƫƬƭƮƯưƱƲƳƴƵƶƷƸƹƺƻƼƽƾƿǀǁǂǃDŽDždžLJLjljNJNjnjǍǎǏǐǑǒǓǔǕǖǗǘǙǚǛǜǝǞǟǠǡǢǣǤǥǦǧǨǩǪǫǬǭǮǯǰDZDzdzǴ';
$find = 'ƹ';
$result = Multibyte::strrpos($string, $find);
$expected = 40;
$this->assertEqual($expected, $result);
$string = 'əɚɛɜɝɞɟɠɡɢɣɤɥɦɧɨɩɪɫɬɭɮɯɰɱɲɳɴɵɶɷɸɹɺɻɼɽɾɿʀʁʂʃʄʅʆʇʈʉʊʋʌʍʎʏʐʑʒʓʔʕʖʗʘʙʚʛʜʝʞʟʠʡʢʣʤʥʦʧʨʩʪʫʬʭʮʯʰʱʲʳʴʵʶʷʸʹʺʻʼ';
$find = 'ʀ';
$result = Multibyte::strrpos($string, $find);
$expected = 39;
$this->assertEqual($expected, $result);
$string = 'ЀЁЂЃЄЅІЇЈЉЊЋЌЍЎЏАБВГДЕЖЗИЙКЛ';
$find = 'Ї';
$result = Multibyte::strrpos($string, $find);
$expected = 7;
$this->assertEqual($expected, $result);
$string = 'МНОПРСТУФХЦЧШЩЪЫЬЭЮЯабвгдежзийклмнопрстуфхцчшщъыь';
$find = 'Р';
$result = Multibyte::strrpos($string, $find);
$expected = 4;
$this->assertEqual($expected, $result);
$string = 'МНОПРСТУФХЦЧШЩЪЫЬЭЮЯабвгдежзийклмнопрстуфхцчшщъыь';
$find = 'р';
$result = Multibyte::strrpos($string, $find, 5);
$expected = 36;
$this->assertEqual($expected, $result);
$string = 'فقكلمنهوىيًٌٍَُ';
$find = 'ن';
$result = Multibyte::strrpos($string, $find);
$expected = 5;
$this->assertEqual($expected, $result);
$string = '✰✱✲✳✴✵✶✷✸✹✺✻✼✽✾✿❀❁❂❃❄❅❆❇❈❉❊❋❌❍❎❏❐❑❒❓❔❕❖❗❘❙❚❛❜❝❞';
$find = '✿';
$result = Multibyte::strrpos($string, $find);
$expected = 15;
$this->assertEqual($expected, $result);
$string = '⺀⺁⺂⺃⺄⺅⺆⺇⺈⺉⺊⺋⺌⺍⺎⺏⺐⺑⺒⺓⺔⺕⺖⺗⺘⺙⺛⺜⺝⺞⺟⺠⺡⺢⺣⺤⺥⺦⺧⺨⺩⺪⺫⺬⺭⺮⺯⺰⺱⺲⺳⺴⺵⺶⺷⺸⺹⺺⺻⺼⺽⺾⺿⻀⻁⻂⻃⻄⻅⻆⻇⻈⻉⻊⻋⻌⻍⻎⻏⻐⻑⻒⻓⻔⻕⻖⻗⻘⻙⻚⻛⻜⻝⻞⻟⻠';
$find = '⺐';
$result = Multibyte::strrpos($string, $find);
$expected = 16;
$this->assertEqual($expected, $result);
$string = '⽅⽆⽇⽈⽉⽊⽋⽌⽍⽎⽏⽐⽑⽒⽓⽔⽕⽖⽗⽘⽙⽚⽛⽜⽝⽞⽟⽠⽡⽢⽣⽤⽥⽦⽧⽨⽩⽪⽫⽬⽭⽮⽯⽰⽱⽲⽳⽴⽵⽶⽷⽸⽹⽺⽻⽼⽽⽾⽿';
$find = '⽤';
$result = Multibyte::strrpos($string, $find);
$expected = 31;
$this->assertEqual($expected, $result);
$string = '눡눢눣눤눥눦눧눨눩눪눫눬눭눮눯눰눱눲눳눴눵눶눷눸눹눺눻눼눽눾눿뉀뉁뉂뉃뉄뉅뉆뉇뉈뉉뉊뉋뉌뉍뉎뉏뉐뉑뉒뉓뉔뉕뉖뉗뉘뉙뉚뉛뉜뉝뉞뉟뉠뉡뉢뉣뉤뉥뉦뉧뉨뉩뉪뉫뉬뉭뉮뉯뉰뉱뉲뉳뉴뉵뉶뉷뉸뉹뉺뉻뉼뉽뉾뉿늀늁늂늃늄';
$find = '눻';
$result = Multibyte::strrpos($string, $find);
$expected = 26;
$this->assertEqual($expected, $result);
$string = 'ﹰﹱﹲﹳﹴﹶﹷﹸﹹﹺﹻﹼﹽﹾﹿﺀﺁﺂﺃﺄﺅﺆﺇﺈﺉﺊﺋﺌﺍﺎﺏﺐﺑﺒﺓﺔﺕﺖﺗﺘﺙﺚﺛﺜﺝﺞﺟﺠﺡﺢﺣﺤﺥﺦﺧﺨﺩﺪﺫﺬﺭﺮﺯﺰ';
$find = 'ﺞ';
$result = Multibyte::strrpos($string, $find);
$expected = 46;
$this->assertEqual($expected, $result);
$string = 'ﺱﺲﺳﺴﺵﺶﺷﺸﺹﺺﺻﺼﺽﺾﺿﻀﻁﻂﻃﻄﻅﻆﻇﻈﻉﻊﻋﻌﻍﻎﻏﻐﻑﻒﻓﻔﻕﻖﻗﻘﻙﻚﻛﻜﻝﻞﻟﻠﻡﻢﻣﻤﻥﻦﻧﻨﻩﻪﻫﻬﻭﻮﻯﻰﻱﻲﻳﻴﻵﻶﻷﻸﻹﻺﻻﻼ';
$find = 'ﻞ';
$result = Multibyte::strrpos($string, $find);
$expected = 45;
$this->assertEqual($expected, $result);
$string = 'abcdefghijklmnopqrstuvwxyz';
$find = 'k';
$result = Multibyte::strrpos($string, $find);
$expected = 10;
$this->assertEqual($expected, $result);
$string = 'abcdefghijklmnopqrstuvwxyz';
$find = 'k';
$result = Multibyte::strrpos($string, $find);
$expected = 10;
$this->assertEqual($expected, $result);
$string = 'abcdefghijklmnoppqrstuvwxyz';
$find = 'pp';
$result = Multibyte::strrpos($string, $find);
$expected = 15;
$this->assertEqual($expected, $result);
$string = '。「」、・ヲァィゥェォャュョッーアイウエオカキク';
$find = 'ア';
$result = Multibyte::strrpos($string, $find);
$expected = 16;
$this->assertEqual($expected, $result);
$string = 'ケコサシスセソタチツテトナニヌネノハヒフヘホマミムメモヤユヨラリルレロワン゙';
$find = 'ハ';
$result = Multibyte::strrpos($string, $find);
$expected = 17;
$this->assertEqual($expected, $result);
$string = 'Ĥēĺļŏ, Ŵőřļď!';
$find = 'ő';
$result = Multibyte::strrpos($string, $find);
$expected = 8;
$this->assertEqual($expected, $result);
$string = 'Ĥēĺļŏ, Ŵőřļď!';
$find = 'ő';
$result = Multibyte::strrpos($string, $find);
$expected = 8;
$this->assertEqual($expected, $result);
$string = 'Hello, World!';
$find = 'o';
$result = Multibyte::strrpos($string, $find);
$expected = 8;
$this->assertEqual($expected, $result);
$string = 'Hello, World!';
$find = 'o';
$result = Multibyte::strrpos($string, $find, 5);
$expected = 8;
$this->assertEqual($expected, $result);
$string = 'čini';
$find = 'n';
$result = Multibyte::strrpos($string, $find);
$expected = 2;
$this->assertEqual($expected, $result);
$string = 'čini';
$find = 'n';
$result = Multibyte::strrpos($string, $find);
$expected = 2;
$this->assertEqual($expected, $result);
$string = 'moći';
$find = 'ć';
$result = Multibyte::strrpos($string, $find);
$expected = 2;
$this->assertEqual($expected, $result);
$string = 'moći';
$find = 'ć';
$result = Multibyte::strrpos($string, $find);
$expected = 2;
$this->assertEqual($expected, $result);
$string = 'državni';
$find = 'ž';
$result = Multibyte::strrpos($string, $find);
$expected = 2;
$this->assertEqual($expected, $result);
$string = '把百度设为首页';
$find = '设';
$result = Multibyte::strrpos($string, $find);
$expected = 3;
$this->assertEqual($expected, $result);
$string = '一二三周永龍';
$find = '周';
$result = Multibyte::strrpos($string, $find);
$expected = 3;
$this->assertEqual($expected, $result);
$string = 'Ĥēĺļŏ, Ŵőřļď!';
$find = 'H';
$result = Multibyte::strrpos($string, $find);
$expected = false;
$this->assertEqual($expected, $result);
}
/**
* testUsingMbStrstr method
*
* @return void
*/
public function testUsingMbStrstr() {
$string = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
$find = 'F';
$result = mb_strstr($string, $find);
$expected = 'FGHIJKLMNOPQRSTUVWXYZ0123456789';
$this->assertEqual($expected, $result);
$string = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
$find = 'F';
$result = mb_strstr($string, $find, true);
$expected = 'ABCDE';
$this->assertEqual($expected, $result);
$string = 'ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞ';
$find = 'Å';
$result = mb_strstr($string, $find);
$expected = 'ÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞ';
$this->assertEqual($expected, $result);
$string = 'ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞ';
$find = 'Å';
$result = mb_strstr($string, $find, true);
$expected = 'ÀÁÂÃÄ';
$this->assertEqual($expected, $result);
$string = 'ĀĂĄĆĈĊČĎĐĒĔĖĘĚĜĞĠĢĤĦĨĪĬĮIJĴĶĹĻĽĿŁŃŅŇŊŌŎŐŒŔŖŘŚŜŞŠŢŤŦŨŪŬŮŰŲŴŶŹŻŽ';
$find = 'Ċ';
$result = mb_strstr($string, $find);
$expected = 'ĊČĎĐĒĔĖĘĚĜĞĠĢĤĦĨĪĬĮIJĴĶĹĻĽĿŁŃŅŇŊŌŎŐŒŔŖŘŚŜŞŠŢŤŦŨŪŬŮŰŲŴŶŹŻŽ';
$this->assertEqual($expected, $result);
$string = 'ĀĂĄĆĈĊČĎĐĒĔĖĘĚĜĞĠĢĤĦĨĪĬĮIJĴĶĹĻĽĿŁŃŅŇŊŌŎŐŒŔŖŘŚŜŞŠŢŤŦŨŪŬŮŰŲŴŶŹŻŽ';
$find = 'Ċ';
$result = mb_strstr($string, $find, true);
$expected = 'ĀĂĄĆĈ';
$this->assertEqual($expected, $result);
$string = '!"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~';
$find = 'F';
$result = mb_strstr($string, $find);
$expected = 'FGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~';
$this->assertEqual($expected, $result);
$string = '!"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~';
$find = 'F';
$result = mb_strstr($string, $find, true);
$expected = '!"#$%&\'()*+,-./0123456789:;<=>?@ABCDE';
$this->assertEqual($expected, $result);
$string = '¡¢£¤¥¦§¨©ª«¬®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈ';
$find = 'µ';
$result = mb_strstr($string, $find);
$expected = 'µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈ';
$this->assertEqual($expected, $result);
$string = '¡¢£¤¥¦§¨©ª«¬®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈ';
$find = 'µ';
$result = mb_strstr($string, $find, true);
$expected = '¡¢£¤¥¦§¨©ª«¬®¯°±²³´';
$this->assertEqual($expected, $result);
$string = 'ÉÊËÌÍÎÏÐÑÒÓÔÕÖרÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿĀāĂ㥹ĆćĈĉĊċČčĎďĐđĒēĔĕĖėĘęĚěĜĝĞğĠġĢģĤĥĦħĨĩĪīĬ';
$find = 'Þ';
$result = mb_strstr($string, $find);
$expected = 'Þßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿĀāĂ㥹ĆćĈĉĊċČčĎďĐđĒēĔĕĖėĘęĚěĜĝĞğĠġĢģĤĥĦħĨĩĪīĬ';
$this->assertEqual($expected, $result);
$string = 'ÉÊËÌÍÎÏÐÑÒÓÔÕÖרÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿĀāĂ㥹ĆćĈĉĊċČčĎďĐđĒēĔĕĖėĘęĚěĜĝĞğĠġĢģĤĥĦħĨĩĪīĬ';
$find = 'Þ';
$result = mb_strstr($string, $find, true);
$expected = 'ÉÊËÌÍÎÏÐÑÒÓÔÕÖרÙÚÛÜÝ';
$this->assertEqual($expected, $result);
$string = 'ĭĮįİıIJijĴĵĶķĸĹĺĻļĽľĿŀŁłŃńŅņŇňʼnŊŋŌōŎŏŐőŒœŔŕŖŗŘřŚśŜŝŞşŠšŢţŤťŦŧŨũŪūŬŭŮůŰűŲųŴŵŶŷŸŹźŻżŽžſƀƁƂƃƄƅƆƇƈƉƊƋƌƍƎƏƐ';
$find = 'Ņ';
$result = mb_strstr($string, $find);
$expected = 'ŅņŇňʼnŊŋŌōŎŏŐőŒœŔŕŖŗŘřŚśŜŝŞşŠšŢţŤťŦŧŨũŪūŬŭŮůŰűŲųŴŵŶŷŸŹźŻżŽžſƀƁƂƃƄƅƆƇƈƉƊƋƌƍƎƏƐ';
$this->assertEqual($expected, $result);
$string = 'ĭĮįİıIJijĴĵĶķĸĹĺĻļĽľĿŀŁłŃńŅņŇňʼnŊŋŌōŎŏŐőŒœŔŕŖŗŘřŚśŜŝŞşŠšŢţŤťŦŧŨũŪūŬŭŮůŰűŲųŴŵŶŷŸŹźŻżŽžſƀƁƂƃƄƅƆƇƈƉƊƋƌƍƎƏƐ';
$find = 'Ņ';
$result = mb_strstr($string, $find, true);
$expected = 'ĭĮįİıIJijĴĵĶķĸĹĺĻļĽľĿŀŁłŃń';
$this->assertEqual($expected, $result);
$string = 'ƑƒƓƔƕƖƗƘƙƚƛƜƝƞƟƠơƢƣƤƥƦƧƨƩƪƫƬƭƮƯưƱƲƳƴƵƶƷƸƹƺƻƼƽƾƿǀǁǂǃDŽDždžLJLjljNJNjnjǍǎǏǐǑǒǓǔǕǖǗǘǙǚǛǜǝǞǟǠǡǢǣǤǥǦǧǨǩǪǫǬǭǮǯǰDZDzdzǴ';
$find = 'Ƹ';
$result = mb_strstr($string, $find);
$expected = 'ƸƹƺƻƼƽƾƿǀǁǂǃDŽDždžLJLjljNJNjnjǍǎǏǐǑǒǓǔǕǖǗǘǙǚǛǜǝǞǟǠǡǢǣǤǥǦǧǨǩǪǫǬǭǮǯǰDZDzdzǴ';
$this->assertEqual($expected, $result);
$find = 'Ƹ';
$result = mb_strstr($string, $find, true);
$expected = 'ƑƒƓƔƕƖƗƘƙƚƛƜƝƞƟƠơƢƣƤƥƦƧƨƩƪƫƬƭƮƯưƱƲƳƴƵƶƷ';
$this->assertEqual($expected, $result);
$string = 'əɚɛɜɝɞɟɠɡɢɣɤɥɦɧɨɩɪɫɬɭɮɯɰɱɲɳɴɵɶɷɸɹɺɻɼɽɾɿʀʁʂʃʄʅʆʇʈʉʊʋʌʍʎʏʐʑʒʓʔʕʖʗʘʙʚʛʜʝʞʟʠʡʢʣʤʥʦʧʨʩʪʫʬʭʮʯʰʱʲʳʴʵʶʷʸʹʺʻʼ';
$find = 'ʀ';
$result = mb_strstr($string, $find);
$expected = 'ʀʁʂʃʄʅʆʇʈʉʊʋʌʍʎʏʐʑʒʓʔʕʖʗʘʙʚʛʜʝʞʟʠʡʢʣʤʥʦʧʨʩʪʫʬʭʮʯʰʱʲʳʴʵʶʷʸʹʺʻʼ';
$this->assertEqual($expected, $result);
$string = 'əɚɛɜɝɞɟɠɡɢɣɤɥɦɧɨɩɪɫɬɭɮɯɰɱɲɳɴɵɶɷɸɹɺɻɼɽɾɿʀʁʂʃʄʅʆʇʈʉʊʋʌʍʎʏʐʑʒʓʔʕʖʗʘʙʚʛʜʝʞʟʠʡʢʣʤʥʦʧʨʩʪʫʬʭʮʯʰʱʲʳʴʵʶʷʸʹʺʻʼ';
$find = 'ʀ';
$result = mb_strstr($string, $find, true);
$expected = 'əɚɛɜɝɞɟɠɡɢɣɤɥɦɧɨɩɪɫɬɭɮɯɰɱɲɳɴɵɶɷɸɹɺɻɼɽɾɿ';
$this->assertEqual($expected, $result);
$string = 'ЀЁЂЃЄЅІЇЈЉЊЋЌЍЎЏАБВГДЕЖЗИЙКЛ';
$find = 'Ї';
$result = mb_strstr($string, $find);
$expected = 'ЇЈЉЊЋЌЍЎЏАБВГДЕЖЗИЙКЛ';
$this->assertEqual($expected, $result);
$string = 'ЀЁЂЃЄЅІЇЈЉЊЋЌЍЎЏАБВГДЕЖЗИЙКЛ';
$find = 'Ї';
$result = mb_strstr($string, $find, true);
$expected = 'ЀЁЂЃЄЅІ';
$this->assertEqual($expected, $result);
$string = 'МНОПРСТУФХЦЧШЩЪЫЬЭЮЯабвгдежзийклмнопрстуфхцчшщъыь';
$find = 'Р';
$result = mb_strstr($string, $find);
$expected = 'РСТУФХЦЧШЩЪЫЬЭЮЯабвгдежзийклмнопрстуфхцчшщъыь';
$this->assertEqual($expected, $result);
$string = 'МНОПРСТУФХЦЧШЩЪЫЬЭЮЯабвгдежзийклмнопрстуфхцчшщъыь';
$find = 'Р';
$result = mb_strstr($string, $find, true);
$expected = 'МНОП';
$this->assertEqual($expected, $result);
$string = 'فقكلمنهوىيًٌٍَُ';
$find = 'ن';
$result = mb_strstr($string, $find);
$expected = 'نهوىيًٌٍَُ';
$this->assertEqual($expected, $result);
$string = 'فقكلمنهوىيًٌٍَُ';
$find = 'ن';
$result = mb_strstr($string, $find, true);
$expected = 'فقكلم';
$this->assertEqual($expected, $result);
$string = '✰✱✲✳✴✵✶✷✸✹✺✻✼✽✾✿❀❁❂❃❄❅❆❇❈❉❊❋❌❍❎❏❐❑❒❓❔❕❖❗❘❙❚❛❜❝❞';
$find = '✿';
$result = mb_strstr($string, $find);
$expected = '✿❀❁❂❃❄❅❆❇❈❉❊❋❌❍❎❏❐❑❒❓❔❕❖❗❘❙❚❛❜❝❞';
$this->assertEqual($expected, $result);
$string = '✰✱✲✳✴✵✶✷✸✹✺✻✼✽✾✿❀❁❂❃❄❅❆❇❈❉❊❋❌❍❎❏❐❑❒❓❔❕❖❗❘❙❚❛❜❝❞';
$find = '✿';
$result = mb_strstr($string, $find, true);
$expected = '✰✱✲✳✴✵✶✷✸✹✺✻✼✽✾';
$this->assertEqual($expected, $result);
$string = '⺀⺁⺂⺃⺄⺅⺆⺇⺈⺉⺊⺋⺌⺍⺎⺏⺐⺑⺒⺓⺔⺕⺖⺗⺘⺙⺛⺜⺝⺞⺟⺠⺡⺢⺣⺤⺥⺦⺧⺨⺩⺪⺫⺬⺭⺮⺯⺰⺱⺲⺳⺴⺵⺶⺷⺸⺹⺺⺻⺼⺽⺾⺿⻀⻁⻂⻃⻄⻅⻆⻇⻈⻉⻊⻋⻌⻍⻎⻏⻐⻑⻒⻓⻔⻕⻖⻗⻘⻙⻚⻛⻜⻝⻞⻟⻠';
$find = '⺐';
$result = mb_strstr($string, $find);
$expected = '⺐⺑⺒⺓⺔⺕⺖⺗⺘⺙⺛⺜⺝⺞⺟⺠⺡⺢⺣⺤⺥⺦⺧⺨⺩⺪⺫⺬⺭⺮⺯⺰⺱⺲⺳⺴⺵⺶⺷⺸⺹⺺⺻⺼⺽⺾⺿⻀⻁⻂⻃⻄⻅⻆⻇⻈⻉⻊⻋⻌⻍⻎⻏⻐⻑⻒⻓⻔⻕⻖⻗⻘⻙⻚⻛⻜⻝⻞⻟⻠';
$this->assertEqual($expected, $result);
$string = '⺀⺁⺂⺃⺄⺅⺆⺇⺈⺉⺊⺋⺌⺍⺎⺏⺐⺑⺒⺓⺔⺕⺖⺗⺘⺙⺛⺜⺝⺞⺟⺠⺡⺢⺣⺤⺥⺦⺧⺨⺩⺪⺫⺬⺭⺮⺯⺰⺱⺲⺳⺴⺵⺶⺷⺸⺹⺺⺻⺼⺽⺾⺿⻀⻁⻂⻃⻄⻅⻆⻇⻈⻉⻊⻋⻌⻍⻎⻏⻐⻑⻒⻓⻔⻕⻖⻗⻘⻙⻚⻛⻜⻝⻞⻟⻠';
$find = '⺐';
$result = mb_strstr($string, $find, true);
$expected = '⺀⺁⺂⺃⺄⺅⺆⺇⺈⺉⺊⺋⺌⺍⺎⺏';
$this->assertEqual($expected, $result);
$string = '⽅⽆⽇⽈⽉⽊⽋⽌⽍⽎⽏⽐⽑⽒⽓⽔⽕⽖⽗⽘⽙⽚⽛⽜⽝⽞⽟⽠⽡⽢⽣⽤⽥⽦⽧⽨⽩⽪⽫⽬⽭⽮⽯⽰⽱⽲⽳⽴⽵⽶⽷⽸⽹⽺⽻⽼⽽⽾⽿';
$find = '⽤';
$result = mb_strstr($string, $find);
$expected = '⽤⽥⽦⽧⽨⽩⽪⽫⽬⽭⽮⽯⽰⽱⽲⽳⽴⽵⽶⽷⽸⽹⽺⽻⽼⽽⽾⽿';
$this->assertEqual($expected, $result);
$string = '⽅⽆⽇⽈⽉⽊⽋⽌⽍⽎⽏⽐⽑⽒⽓⽔⽕⽖⽗⽘⽙⽚⽛⽜⽝⽞⽟⽠⽡⽢⽣⽤⽥⽦⽧⽨⽩⽪⽫⽬⽭⽮⽯⽰⽱⽲⽳⽴⽵⽶⽷⽸⽹⽺⽻⽼⽽⽾⽿';
$find = '⽤';
$result = mb_strstr($string, $find, true);
$expected = '⽅⽆⽇⽈⽉⽊⽋⽌⽍⽎⽏⽐⽑⽒⽓⽔⽕⽖⽗⽘⽙⽚⽛⽜⽝⽞⽟⽠⽡⽢⽣';
$this->assertEqual($expected, $result);
$string = '눡눢눣눤눥눦눧눨눩눪눫눬눭눮눯눰눱눲눳눴눵눶눷눸눹눺눻눼눽눾눿뉀뉁뉂뉃뉄뉅뉆뉇뉈뉉뉊뉋뉌뉍뉎뉏뉐뉑뉒뉓뉔뉕뉖뉗뉘뉙뉚뉛뉜뉝뉞뉟뉠뉡뉢뉣뉤뉥뉦뉧뉨뉩뉪뉫뉬뉭뉮뉯뉰뉱뉲뉳뉴뉵뉶뉷뉸뉹뉺뉻뉼뉽뉾뉿늀늁늂늃늄';
$find = '눻';
$result = mb_strstr($string, $find);
$expected = '눻눼눽눾눿뉀뉁뉂뉃뉄뉅뉆뉇뉈뉉뉊뉋뉌뉍뉎뉏뉐뉑뉒뉓뉔뉕뉖뉗뉘뉙뉚뉛뉜뉝뉞뉟뉠뉡뉢뉣뉤뉥뉦뉧뉨뉩뉪뉫뉬뉭뉮뉯뉰뉱뉲뉳뉴뉵뉶뉷뉸뉹뉺뉻뉼뉽뉾뉿늀늁늂늃늄';
$this->assertEqual($expected, $result);
$string = '눡눢눣눤눥눦눧눨눩눪눫눬눭눮눯눰눱눲눳눴눵눶눷눸눹눺눻눼눽눾눿뉀뉁뉂뉃뉄뉅뉆뉇뉈뉉뉊뉋뉌뉍뉎뉏뉐뉑뉒뉓뉔뉕뉖뉗뉘뉙뉚뉛뉜뉝뉞뉟뉠뉡뉢뉣뉤뉥뉦뉧뉨뉩뉪뉫뉬뉭뉮뉯뉰뉱뉲뉳뉴뉵뉶뉷뉸뉹뉺뉻뉼뉽뉾뉿늀늁늂늃늄';
$find = '눻';
$result = mb_strstr($string, $find, true);
$expected = '눡눢눣눤눥눦눧눨눩눪눫눬눭눮눯눰눱눲눳눴눵눶눷눸눹눺';
$this->assertEqual($expected, $result);
$string = 'ﹰﹱﹲﹳﹴﹶﹷﹸﹹﹺﹻﹼﹽﹾﹿﺀﺁﺂﺃﺄﺅﺆﺇﺈﺉﺊﺋﺌﺍﺎﺏﺐﺑﺒﺓﺔﺕﺖﺗﺘﺙﺚﺛﺜﺝﺞﺟﺠﺡﺢﺣﺤﺥﺦﺧﺨﺩﺪﺫﺬﺭﺮﺯﺰ';
$find = 'ﺞ';
$result = mb_strstr($string, $find);
$expected = 'ﺞﺟﺠﺡﺢﺣﺤﺥﺦﺧﺨﺩﺪﺫﺬﺭﺮﺯﺰ';
$this->assertEqual($expected, $result);
$string = 'ﹰﹱﹲﹳﹴﹶﹷﹸﹹﹺﹻﹼﹽﹾﹿﺀﺁﺂﺃﺄﺅﺆﺇﺈﺉﺊﺋﺌﺍﺎﺏﺐﺑﺒﺓﺔﺕﺖﺗﺘﺙﺚﺛﺜﺝﺞﺟﺠﺡﺢﺣﺤﺥﺦﺧﺨﺩﺪﺫﺬﺭﺮﺯﺰ';
$find = 'ﺞ';
$result = mb_strstr($string, $find, true);
$expected = 'ﹰﹱﹲﹳﹴﹶﹷﹸﹹﹺﹻﹼﹽﹾﹿﺀﺁﺂﺃﺄﺅﺆﺇﺈﺉﺊﺋﺌﺍﺎﺏﺐﺑﺒﺓﺔﺕﺖﺗﺘﺙﺚﺛﺜﺝ';
$this->assertEqual($expected, $result);
$string = 'ﺱﺲﺳﺴﺵﺶﺷﺸﺹﺺﺻﺼﺽﺾﺿﻀﻁﻂﻃﻄﻅﻆﻇﻈﻉﻊﻋﻌﻍﻎﻏﻐﻑﻒﻓﻔﻕﻖﻗﻘﻙﻚﻛﻜﻝﻞﻟﻠﻡﻢﻣﻤﻥﻦﻧﻨﻩﻪﻫﻬﻭﻮﻯﻰﻱﻲﻳﻴﻵﻶﻷﻸﻹﻺﻻﻼ';
$find = 'ﻞ';
$result = mb_strstr($string, $find);
$expected = 'ﻞﻟﻠﻡﻢﻣﻤﻥﻦﻧﻨﻩﻪﻫﻬﻭﻮﻯﻰﻱﻲﻳﻴﻵﻶﻷﻸﻹﻺﻻﻼ';
$this->assertEqual($expected, $result);
$string = 'ﺱﺲﺳﺴﺵﺶﺷﺸﺹﺺﺻﺼﺽﺾﺿﻀﻁﻂﻃﻄﻅﻆﻇﻈﻉﻊﻋﻌﻍﻎﻏﻐﻑﻒﻓﻔﻕﻖﻗﻘﻙﻚﻛﻜﻝﻞﻟﻠﻡﻢﻣﻤﻥﻦﻧﻨﻩﻪﻫﻬﻭﻮﻯﻰﻱﻲﻳﻴﻵﻶﻷﻸﻹﻺﻻﻼ';
$find = 'ﻞ';
$result = mb_strstr($string, $find, true);
$expected = 'ﺱﺲﺳﺴﺵﺶﺷﺸﺹﺺﺻﺼﺽﺾﺿﻀﻁﻂﻃﻄﻅﻆﻇﻈﻉﻊﻋﻌﻍﻎﻏﻐﻑﻒﻓﻔﻕﻖﻗﻘﻙﻚﻛﻜﻝ';
$this->assertEqual($expected, $result);
$string = 'abcdefghijklmnopqrstuvwxyz';
$find = 'k';
$result = mb_strstr($string, $find);
$expected = 'klmnopqrstuvwxyz';
$this->assertEqual($expected, $result);
$string = 'abcdefghijklmnopqrstuvwxyz';
$find = 'k';
$result = mb_strstr($string, $find, true);
$expected = 'abcdefghij';
$this->assertEqual($expected, $result);
$string = 'abcdefghijklmnopqrstuvwxyz';
$find = 'K';
$result = mb_strstr($string, $find);
$expected = false;
$this->assertEqual($expected, $result);
$string = '。「」、・ヲァィゥェォャュョッーアイウエオカキク';
$find = 'ア';
$result = mb_strstr($string, $find);
$expected = 'アイウエオカキク';
$this->assertEqual($expected, $result);
$string = '。「」、・ヲァィゥェォャュョッーアイウエオカキク';
$find = 'ア';
$result = mb_strstr($string, $find, true);
$expected = '。「」、・ヲァィゥェォャュョッー';
$this->assertEqual($expected, $result);
$string = 'ケコサシスセソタチツテトナニヌネノハヒフヘホマミムメモヤユヨラリルレロワン゙';
$find = 'ハ';
$result = mb_strstr($string, $find);
$expected = 'ハヒフヘホマミムメモヤユヨラリルレロワン゙';
$this->assertEqual($expected, $result);
$string = 'ケコサシスセソタチツテトナニヌネノハヒフヘホマミムメモヤユヨラリルレロワン゙';
$find = 'ハ';
$result = mb_strstr($string, $find, true);
$expected = 'ケコサシスセソタチツテトナニヌネノ';
$this->assertEqual($expected, $result);
$string = 'Ĥēĺļŏ, Ŵőřļď!';
$find = 'ő';
$result = mb_strstr($string, $find);
$expected = 'őřļď!';
$this->assertEqual($expected, $result);
$string = 'Ĥēĺļŏ, Ŵőřļď!';
$find = 'ő';
$result = mb_strstr($string, $find, true);
$expected = 'Ĥēĺļŏ, Ŵ';
$this->assertEqual($expected, $result);
$string = 'Ĥēĺļŏ, Ŵőřļď!';
$find = 'ĺļ';
$result = mb_strstr($string, $find, true);
$expected = 'Ĥē';
$this->assertEqual($expected, $result);
$string = 'Hello, World!';
$find = 'o';
$result = mb_strstr($string, $find);
$expected = 'o, World!';
$this->assertEqual($expected, $result);
$string = 'Hello, World!';
$find = 'o';
$result = mb_strstr($string, $find, true);
$expected = 'Hell';
$this->assertEqual($expected, $result);
$string = 'Hello, World!';
$find = 'Wo';
$result = mb_strstr($string, $find);
$expected = 'World!';
$this->assertEqual($expected, $result);
$string = 'Hello, World!';
$find = 'Wo';
$result = mb_strstr($string, $find, true);
$expected = 'Hello, ';
$this->assertEqual($expected, $result);
$string = 'Hello, World!';
$find = 'll';
$result = mb_strstr($string, $find);
$expected = 'llo, World!';
$this->assertEqual($expected, $result);
$string = 'Hello, World!';
$find = 'll';
$result = mb_strstr($string, $find, true);
$expected = 'He';
$this->assertEqual($expected, $result);
$string = 'Hello, World!';
$find = 'rld';
$result = mb_strstr($string, $find);
$expected = 'rld!';
$this->assertEqual($expected, $result);
$string = 'Hello, World!';
$find = 'rld';
$result = mb_strstr($string, $find, true);
$expected = 'Hello, Wo';
$this->assertEqual($expected, $result);
$string = 'čini';
$find = 'n';
$result = mb_strstr($string, $find);
$expected = 'ni';
$this->assertEqual($expected, $result);
$string = 'čini';
$find = 'n';
$result = mb_strstr($string, $find, true);
$expected = 'či';
$this->assertEqual($expected, $result);
$string = 'moći';
$find = 'ć';
$result = mb_strstr($string, $find);
$expected = 'ći';
$this->assertEqual($expected, $result);
$string = 'moći';
$find = 'ć';
$result = mb_strstr($string, $find, true);
$expected = 'mo';
$this->assertEqual($expected, $result);
$string = 'državni';
$find = 'ž';
$result = mb_strstr($string, $find);
$expected = 'žavni';
$this->assertEqual($expected, $result);
$string = 'državni';
$find = 'ž';
$result = mb_strstr($string, $find, true);
$expected = 'dr';
$this->assertEqual($expected, $result);
$string = '把百度设为首页';
$find = '设';
$result = mb_strstr($string, $find);
$expected = '设为首页';
$this->assertEqual($expected, $result);
$string = '把百度设为首页';
$find = '设';
$result = mb_strstr($string, $find, true);
$expected = '把百度';
$this->assertEqual($expected, $result);
$string = '一二三周永龍';
$find = '周';
$result = mb_strstr($string, $find);
$expected = '周永龍';
$this->assertEqual($expected, $result);
$string = '一二三周永龍';
$find = '周';
$result = mb_strstr($string, $find, true);
$expected = '一二三';
$this->assertEqual($expected, $result);
$string = '一二三周永龍';
$find = '二周';
$result = mb_strstr($string, $find);
$expected = false;
$this->assertEqual($expected, $result);
}
/**
* testMultibyteStrstr method
*
* @return void
*/
public function testMultibyteStrstr() {
$string = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
$find = 'F';
$result = Multibyte::strstr($string, $find);
$expected = 'FGHIJKLMNOPQRSTUVWXYZ0123456789';
$this->assertEqual($expected, $result);
$string = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
$find = 'F';
$result = Multibyte::strstr($string, $find, true);
$expected = 'ABCDE';
$this->assertEqual($expected, $result);
$string = 'ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞ';
$find = 'Å';
$result = Multibyte::strstr($string, $find);
$expected = 'ÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞ';
$this->assertEqual($expected, $result);
$string = 'ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞ';
$find = 'Å';
$result = Multibyte::strstr($string, $find, true);
$expected = 'ÀÁÂÃÄ';
$this->assertEqual($expected, $result);
$string = 'ĀĂĄĆĈĊČĎĐĒĔĖĘĚĜĞĠĢĤĦĨĪĬĮIJĴĶĹĻĽĿŁŃŅŇŊŌŎŐŒŔŖŘŚŜŞŠŢŤŦŨŪŬŮŰŲŴŶŹŻŽ';
$find = 'Ċ';
$result = Multibyte::strstr($string, $find);
$expected = 'ĊČĎĐĒĔĖĘĚĜĞĠĢĤĦĨĪĬĮIJĴĶĹĻĽĿŁŃŅŇŊŌŎŐŒŔŖŘŚŜŞŠŢŤŦŨŪŬŮŰŲŴŶŹŻŽ';
$this->assertEqual($expected, $result);
$string = 'ĀĂĄĆĈĊČĎĐĒĔĖĘĚĜĞĠĢĤĦĨĪĬĮIJĴĶĹĻĽĿŁŃŅŇŊŌŎŐŒŔŖŘŚŜŞŠŢŤŦŨŪŬŮŰŲŴŶŹŻŽ';
$find = 'Ċ';
$result = Multibyte::strstr($string, $find, true);
$expected = 'ĀĂĄĆĈ';
$this->assertEqual($expected, $result);
$string = '!"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~';
$find = 'F';
$result = Multibyte::strstr($string, $find);
$expected = 'FGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~';
$this->assertEqual($expected, $result);
$string = '!"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~';
$find = 'F';
$result = Multibyte::strstr($string, $find, true);
$expected = '!"#$%&\'()*+,-./0123456789:;<=>?@ABCDE';
$this->assertEqual($expected, $result);
$string = '¡¢£¤¥¦§¨©ª«¬®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈ';
$find = 'µ';
$result = Multibyte::strstr($string, $find);
$expected = 'µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈ';
$this->assertEqual($expected, $result);
$string = '¡¢£¤¥¦§¨©ª«¬®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈ';
$find = 'µ';
$result = Multibyte::strstr($string, $find, true);
$expected = '¡¢£¤¥¦§¨©ª«¬®¯°±²³´';
$this->assertEqual($expected, $result);
$string = 'ÉÊËÌÍÎÏÐÑÒÓÔÕÖרÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿĀāĂ㥹ĆćĈĉĊċČčĎďĐđĒēĔĕĖėĘęĚěĜĝĞğĠġĢģĤĥĦħĨĩĪīĬ';
$find = 'Þ';
$result = Multibyte::strstr($string, $find);
$expected = 'Þßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿĀāĂ㥹ĆćĈĉĊċČčĎďĐđĒēĔĕĖėĘęĚěĜĝĞğĠġĢģĤĥĦħĨĩĪīĬ';
$this->assertEqual($expected, $result);
$string = 'ÉÊËÌÍÎÏÐÑÒÓÔÕÖרÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿĀāĂ㥹ĆćĈĉĊċČčĎďĐđĒēĔĕĖėĘęĚěĜĝĞğĠġĢģĤĥĦħĨĩĪīĬ';
$find = 'Þ';
$result = Multibyte::strstr($string, $find, true);
$expected = 'ÉÊËÌÍÎÏÐÑÒÓÔÕÖרÙÚÛÜÝ';
$this->assertEqual($expected, $result);
$string = 'ĭĮįİıIJijĴĵĶķĸĹĺĻļĽľĿŀŁłŃńŅņŇňʼnŊŋŌōŎŏŐőŒœŔŕŖŗŘřŚśŜŝŞşŠšŢţŤťŦŧŨũŪūŬŭŮůŰűŲųŴŵŶŷŸŹźŻżŽžſƀƁƂƃƄƅƆƇƈƉƊƋƌƍƎƏƐ';
$find = 'Ņ';
$result = Multibyte::strstr($string, $find);
$expected = 'ŅņŇňʼnŊŋŌōŎŏŐőŒœŔŕŖŗŘřŚśŜŝŞşŠšŢţŤťŦŧŨũŪūŬŭŮůŰűŲųŴŵŶŷŸŹźŻżŽžſƀƁƂƃƄƅƆƇƈƉƊƋƌƍƎƏƐ';
$this->assertEqual($expected, $result);
$string = 'ĭĮįİıIJijĴĵĶķĸĹĺĻļĽľĿŀŁłŃńŅņŇňʼnŊŋŌōŎŏŐőŒœŔŕŖŗŘřŚśŜŝŞşŠšŢţŤťŦŧŨũŪūŬŭŮůŰűŲųŴŵŶŷŸŹźŻżŽžſƀƁƂƃƄƅƆƇƈƉƊƋƌƍƎƏƐ';
$find = 'Ņ';
$result = Multibyte::strstr($string, $find, true);
$expected = 'ĭĮįİıIJijĴĵĶķĸĹĺĻļĽľĿŀŁłŃń';
$this->assertEqual($expected, $result);
$string = 'ƑƒƓƔƕƖƗƘƙƚƛƜƝƞƟƠơƢƣƤƥƦƧƨƩƪƫƬƭƮƯưƱƲƳƴƵƶƷƸƹƺƻƼƽƾƿǀǁǂǃDŽDždžLJLjljNJNjnjǍǎǏǐǑǒǓǔǕǖǗǘǙǚǛǜǝǞǟǠǡǢǣǤǥǦǧǨǩǪǫǬǭǮǯǰDZDzdzǴ';
$find = 'Ƹ';
$result = Multibyte::strstr($string, $find);
$expected = 'ƸƹƺƻƼƽƾƿǀǁǂǃDŽDždžLJLjljNJNjnjǍǎǏǐǑǒǓǔǕǖǗǘǙǚǛǜǝǞǟǠǡǢǣǤǥǦǧǨǩǪǫǬǭǮǯǰDZDzdzǴ';
$this->assertEqual($expected, $result);
$find = 'Ƹ';
$result = Multibyte::strstr($string, $find, true);
$expected = 'ƑƒƓƔƕƖƗƘƙƚƛƜƝƞƟƠơƢƣƤƥƦƧƨƩƪƫƬƭƮƯưƱƲƳƴƵƶƷ';
$this->assertEqual($expected, $result);
$string = 'əɚɛɜɝɞɟɠɡɢɣɤɥɦɧɨɩɪɫɬɭɮɯɰɱɲɳɴɵɶɷɸɹɺɻɼɽɾɿʀʁʂʃʄʅʆʇʈʉʊʋʌʍʎʏʐʑʒʓʔʕʖʗʘʙʚʛʜʝʞʟʠʡʢʣʤʥʦʧʨʩʪʫʬʭʮʯʰʱʲʳʴʵʶʷʸʹʺʻʼ';
$find = 'ʀ';
$result = Multibyte::strstr($string, $find);
$expected = 'ʀʁʂʃʄʅʆʇʈʉʊʋʌʍʎʏʐʑʒʓʔʕʖʗʘʙʚʛʜʝʞʟʠʡʢʣʤʥʦʧʨʩʪʫʬʭʮʯʰʱʲʳʴʵʶʷʸʹʺʻʼ';
$this->assertEqual($expected, $result);
$string = 'əɚɛɜɝɞɟɠɡɢɣɤɥɦɧɨɩɪɫɬɭɮɯɰɱɲɳɴɵɶɷɸɹɺɻɼɽɾɿʀʁʂʃʄʅʆʇʈʉʊʋʌʍʎʏʐʑʒʓʔʕʖʗʘʙʚʛʜʝʞʟʠʡʢʣʤʥʦʧʨʩʪʫʬʭʮʯʰʱʲʳʴʵʶʷʸʹʺʻʼ';
$find = 'ʀ';
$result = Multibyte::strstr($string, $find, true);
$expected = 'əɚɛɜɝɞɟɠɡɢɣɤɥɦɧɨɩɪɫɬɭɮɯɰɱɲɳɴɵɶɷɸɹɺɻɼɽɾɿ';
$this->assertEqual($expected, $result);
$string = 'ЀЁЂЃЄЅІЇЈЉЊЋЌЍЎЏАБВГДЕЖЗИЙКЛ';
$find = 'Ї';
$result = Multibyte::strstr($string, $find);
$expected = 'ЇЈЉЊЋЌЍЎЏАБВГДЕЖЗИЙКЛ';
$this->assertEqual($expected, $result);
$string = 'ЀЁЂЃЄЅІЇЈЉЊЋЌЍЎЏАБВГДЕЖЗИЙКЛ';
$find = 'Ї';
$result = Multibyte::strstr($string, $find, true);
$expected = 'ЀЁЂЃЄЅІ';
$this->assertEqual($expected, $result);
$string = 'МНОПРСТУФХЦЧШЩЪЫЬЭЮЯабвгдежзийклмнопрстуфхцчшщъыь';
$find = 'Р';
$result = Multibyte::strstr($string, $find);
$expected = 'РСТУФХЦЧШЩЪЫЬЭЮЯабвгдежзийклмнопрстуфхцчшщъыь';
$this->assertEqual($expected, $result);
$string = 'МНОПРСТУФХЦЧШЩЪЫЬЭЮЯабвгдежзийклмнопрстуфхцчшщъыь';
$find = 'Р';
$result = Multibyte::strstr($string, $find, true);
$expected = 'МНОП';
$this->assertEqual($expected, $result);
$string = 'فقكلمنهوىيًٌٍَُ';
$find = 'ن';
$result = Multibyte::strstr($string, $find);
$expected = 'نهوىيًٌٍَُ';
$this->assertEqual($expected, $result);
$string = 'فقكلمنهوىيًٌٍَُ';
$find = 'ن';
$result = Multibyte::strstr($string, $find, true);
$expected = 'فقكلم';
$this->assertEqual($expected, $result);
$string = '✰✱✲✳✴✵✶✷✸✹✺✻✼✽✾✿❀❁❂❃❄❅❆❇❈❉❊❋❌❍❎❏❐❑❒❓❔❕❖❗❘❙❚❛❜❝❞';
$find = '✿';
$result = Multibyte::strstr($string, $find);
$expected = '✿❀❁❂❃❄❅❆❇❈❉❊❋❌❍❎❏❐❑❒❓❔❕❖❗❘❙❚❛❜❝❞';
$this->assertEqual($expected, $result);
$string = '✰✱✲✳✴✵✶✷✸✹✺✻✼✽✾✿❀❁❂❃❄❅❆❇❈❉❊❋❌❍❎❏❐❑❒❓❔❕❖❗❘❙❚❛❜❝❞';
$find = '✿';
$result = Multibyte::strstr($string, $find, true);
$expected = '✰✱✲✳✴✵✶✷✸✹✺✻✼✽✾';
$this->assertEqual($expected, $result);
$string = '⺀⺁⺂⺃⺄⺅⺆⺇⺈⺉⺊⺋⺌⺍⺎⺏⺐⺑⺒⺓⺔⺕⺖⺗⺘⺙⺛⺜⺝⺞⺟⺠⺡⺢⺣⺤⺥⺦⺧⺨⺩⺪⺫⺬⺭⺮⺯⺰⺱⺲⺳⺴⺵⺶⺷⺸⺹⺺⺻⺼⺽⺾⺿⻀⻁⻂⻃⻄⻅⻆⻇⻈⻉⻊⻋⻌⻍⻎⻏⻐⻑⻒⻓⻔⻕⻖⻗⻘⻙⻚⻛⻜⻝⻞⻟⻠';
$find = '⺐';
$result = Multibyte::strstr($string, $find);
$expected = '⺐⺑⺒⺓⺔⺕⺖⺗⺘⺙⺛⺜⺝⺞⺟⺠⺡⺢⺣⺤⺥⺦⺧⺨⺩⺪⺫⺬⺭⺮⺯⺰⺱⺲⺳⺴⺵⺶⺷⺸⺹⺺⺻⺼⺽⺾⺿⻀⻁⻂⻃⻄⻅⻆⻇⻈⻉⻊⻋⻌⻍⻎⻏⻐⻑⻒⻓⻔⻕⻖⻗⻘⻙⻚⻛⻜⻝⻞⻟⻠';
$this->assertEqual($expected, $result);
$string = '⺀⺁⺂⺃⺄⺅⺆⺇⺈⺉⺊⺋⺌⺍⺎⺏⺐⺑⺒⺓⺔⺕⺖⺗⺘⺙⺛⺜⺝⺞⺟⺠⺡⺢⺣⺤⺥⺦⺧⺨⺩⺪⺫⺬⺭⺮⺯⺰⺱⺲⺳⺴⺵⺶⺷⺸⺹⺺⺻⺼⺽⺾⺿⻀⻁⻂⻃⻄⻅⻆⻇⻈⻉⻊⻋⻌⻍⻎⻏⻐⻑⻒⻓⻔⻕⻖⻗⻘⻙⻚⻛⻜⻝⻞⻟⻠';
$find = '⺐';
$result = Multibyte::strstr($string, $find, true);
$expected = '⺀⺁⺂⺃⺄⺅⺆⺇⺈⺉⺊⺋⺌⺍⺎⺏';
$this->assertEqual($expected, $result);
$string = '⽅⽆⽇⽈⽉⽊⽋⽌⽍⽎⽏⽐⽑⽒⽓⽔⽕⽖⽗⽘⽙⽚⽛⽜⽝⽞⽟⽠⽡⽢⽣⽤⽥⽦⽧⽨⽩⽪⽫⽬⽭⽮⽯⽰⽱⽲⽳⽴⽵⽶⽷⽸⽹⽺⽻⽼⽽⽾⽿';
$find = '⽤';
$result = Multibyte::strstr($string, $find);
$expected = '⽤⽥⽦⽧⽨⽩⽪⽫⽬⽭⽮⽯⽰⽱⽲⽳⽴⽵⽶⽷⽸⽹⽺⽻⽼⽽⽾⽿';
$this->assertEqual($expected, $result);
$string = '⽅⽆⽇⽈⽉⽊⽋⽌⽍⽎⽏⽐⽑⽒⽓⽔⽕⽖⽗⽘⽙⽚⽛⽜⽝⽞⽟⽠⽡⽢⽣⽤⽥⽦⽧⽨⽩⽪⽫⽬⽭⽮⽯⽰⽱⽲⽳⽴⽵⽶⽷⽸⽹⽺⽻⽼⽽⽾⽿';
$find = '⽤';
$result = Multibyte::strstr($string, $find, true);
$expected = '⽅⽆⽇⽈⽉⽊⽋⽌⽍⽎⽏⽐⽑⽒⽓⽔⽕⽖⽗⽘⽙⽚⽛⽜⽝⽞⽟⽠⽡⽢⽣';
$this->assertEqual($expected, $result);
$string = '눡눢눣눤눥눦눧눨눩눪눫눬눭눮눯눰눱눲눳눴눵눶눷눸눹눺눻눼눽눾눿뉀뉁뉂뉃뉄뉅뉆뉇뉈뉉뉊뉋뉌뉍뉎뉏뉐뉑뉒뉓뉔뉕뉖뉗뉘뉙뉚뉛뉜뉝뉞뉟뉠뉡뉢뉣뉤뉥뉦뉧뉨뉩뉪뉫뉬뉭뉮뉯뉰뉱뉲뉳뉴뉵뉶뉷뉸뉹뉺뉻뉼뉽뉾뉿늀늁늂늃늄';
$find = '눻';
$result = Multibyte::strstr($string, $find);
$expected = '눻눼눽눾눿뉀뉁뉂뉃뉄뉅뉆뉇뉈뉉뉊뉋뉌뉍뉎뉏뉐뉑뉒뉓뉔뉕뉖뉗뉘뉙뉚뉛뉜뉝뉞뉟뉠뉡뉢뉣뉤뉥뉦뉧뉨뉩뉪뉫뉬뉭뉮뉯뉰뉱뉲뉳뉴뉵뉶뉷뉸뉹뉺뉻뉼뉽뉾뉿늀늁늂늃늄';
$this->assertEqual($expected, $result);
$string = '눡눢눣눤눥눦눧눨눩눪눫눬눭눮눯눰눱눲눳눴눵눶눷눸눹눺눻눼눽눾눿뉀뉁뉂뉃뉄뉅뉆뉇뉈뉉뉊뉋뉌뉍뉎뉏뉐뉑뉒뉓뉔뉕뉖뉗뉘뉙뉚뉛뉜뉝뉞뉟뉠뉡뉢뉣뉤뉥뉦뉧뉨뉩뉪뉫뉬뉭뉮뉯뉰뉱뉲뉳뉴뉵뉶뉷뉸뉹뉺뉻뉼뉽뉾뉿늀늁늂늃늄';
$find = '눻';
$result = Multibyte::strstr($string, $find, true);
$expected = '눡눢눣눤눥눦눧눨눩눪눫눬눭눮눯눰눱눲눳눴눵눶눷눸눹눺';
$this->assertEqual($expected, $result);
$string = 'ﹰﹱﹲﹳﹴﹶﹷﹸﹹﹺﹻﹼﹽﹾﹿﺀﺁﺂﺃﺄﺅﺆﺇﺈﺉﺊﺋﺌﺍﺎﺏﺐﺑﺒﺓﺔﺕﺖﺗﺘﺙﺚﺛﺜﺝﺞﺟﺠﺡﺢﺣﺤﺥﺦﺧﺨﺩﺪﺫﺬﺭﺮﺯﺰ';
$find = 'ﺞ';
$result = Multibyte::strstr($string, $find);
$expected = 'ﺞﺟﺠﺡﺢﺣﺤﺥﺦﺧﺨﺩﺪﺫﺬﺭﺮﺯﺰ';
$this->assertEqual($expected, $result);
$string = 'ﹰﹱﹲﹳﹴﹶﹷﹸﹹﹺﹻﹼﹽﹾﹿﺀﺁﺂﺃﺄﺅﺆﺇﺈﺉﺊﺋﺌﺍﺎﺏﺐﺑﺒﺓﺔﺕﺖﺗﺘﺙﺚﺛﺜﺝﺞﺟﺠﺡﺢﺣﺤﺥﺦﺧﺨﺩﺪﺫﺬﺭﺮﺯﺰ';
$find = 'ﺞ';
$result = Multibyte::strstr($string, $find, true);
$expected = 'ﹰﹱﹲﹳﹴﹶﹷﹸﹹﹺﹻﹼﹽﹾﹿﺀﺁﺂﺃﺄﺅﺆﺇﺈﺉﺊﺋﺌﺍﺎﺏﺐﺑﺒﺓﺔﺕﺖﺗﺘﺙﺚﺛﺜﺝ';
$this->assertEqual($expected, $result);
$string = 'ﺱﺲﺳﺴﺵﺶﺷﺸﺹﺺﺻﺼﺽﺾﺿﻀﻁﻂﻃﻄﻅﻆﻇﻈﻉﻊﻋﻌﻍﻎﻏﻐﻑﻒﻓﻔﻕﻖﻗﻘﻙﻚﻛﻜﻝﻞﻟﻠﻡﻢﻣﻤﻥﻦﻧﻨﻩﻪﻫﻬﻭﻮﻯﻰﻱﻲﻳﻴﻵﻶﻷﻸﻹﻺﻻﻼ';
$find = 'ﻞ';
$result = Multibyte::strstr($string, $find);
$expected = 'ﻞﻟﻠﻡﻢﻣﻤﻥﻦﻧﻨﻩﻪﻫﻬﻭﻮﻯﻰﻱﻲﻳﻴﻵﻶﻷﻸﻹﻺﻻﻼ';
$this->assertEqual($expected, $result);
$string = 'ﺱﺲﺳﺴﺵﺶﺷﺸﺹﺺﺻﺼﺽﺾﺿﻀﻁﻂﻃﻄﻅﻆﻇﻈﻉﻊﻋﻌﻍﻎﻏﻐﻑﻒﻓﻔﻕﻖﻗﻘﻙﻚﻛﻜﻝﻞﻟﻠﻡﻢﻣﻤﻥﻦﻧﻨﻩﻪﻫﻬﻭﻮﻯﻰﻱﻲﻳﻴﻵﻶﻷﻸﻹﻺﻻﻼ';
$find = 'ﻞ';
$result = Multibyte::strstr($string, $find, true);
$expected = 'ﺱﺲﺳﺴﺵﺶﺷﺸﺹﺺﺻﺼﺽﺾﺿﻀﻁﻂﻃﻄﻅﻆﻇﻈﻉﻊﻋﻌﻍﻎﻏﻐﻑﻒﻓﻔﻕﻖﻗﻘﻙﻚﻛﻜﻝ';
$this->assertEqual($expected, $result);
$string = 'abcdefghijklmnopqrstuvwxyz';
$find = 'k';
$result = Multibyte::strstr($string, $find);
$expected = 'klmnopqrstuvwxyz';
$this->assertEqual($expected, $result);
$string = 'abcdefghijklmnopqrstuvwxyz';
$find = 'k';
$result = Multibyte::strstr($string, $find, true);
$expected = 'abcdefghij';
$this->assertEqual($expected, $result);
$string = 'abcdefghijklmnopqrstuvwxyz';
$find = 'K';
$result = Multibyte::strstr($string, $find);
$expected = false;
$this->assertEqual($expected, $result);
$string = '。「」、・ヲァィゥェォャュョッーアイウエオカキク';
$find = 'ア';
$result = Multibyte::strstr($string, $find);
$expected = 'アイウエオカキク';
$this->assertEqual($expected, $result);
$string = '。「」、・ヲァィゥェォャュョッーアイウエオカキク';
$find = 'ア';
$result = Multibyte::strstr($string, $find, true);
$expected = '。「」、・ヲァィゥェォャュョッー';
$this->assertEqual($expected, $result);
$string = 'ケコサシスセソタチツテトナニヌネノハヒフヘホマミムメモヤユヨラリルレロワン゙';
$find = 'ハ';
$result = Multibyte::strstr($string, $find);
$expected = 'ハヒフヘホマミムメモヤユヨラリルレロワン゙';
$this->assertEqual($expected, $result);
$string = 'ケコサシスセソタチツテトナニヌネノハヒフヘホマミムメモヤユヨラリルレロワン゙';
$find = 'ハ';
$result = Multibyte::strstr($string, $find, true);
$expected = 'ケコサシスセソタチツテトナニヌネノ';
$this->assertEqual($expected, $result);
$string = 'Ĥēĺļŏ, Ŵőřļď!';
$find = 'ő';
$result = Multibyte::strstr($string, $find);
$expected = 'őřļď!';
$this->assertEqual($expected, $result);
$string = 'Ĥēĺļŏ, Ŵőřļď!';
$find = 'ő';
$result = Multibyte::strstr($string, $find, true);
$expected = 'Ĥēĺļŏ, Ŵ';
$this->assertEqual($expected, $result);
$string = 'Ĥēĺļŏ, Ŵőřļď!';
$find = 'ĺļ';
$result = Multibyte::strstr($string, $find, true);
$expected = 'Ĥē';
$this->assertEqual($expected, $result);
$string = 'Hello, World!';
$find = 'o';
$result = Multibyte::strstr($string, $find);
$expected = 'o, World!';
$this->assertEqual($expected, $result);
$string = 'Hello, World!';
$find = 'o';
$result = Multibyte::strstr($string, $find, true);
$expected = 'Hell';
$this->assertEqual($expected, $result);
$string = 'Hello, World!';
$find = 'Wo';
$result = Multibyte::strstr($string, $find);
$expected = 'World!';
$this->assertEqual($expected, $result);
$string = 'Hello, World!';
$find = 'Wo';
$result = Multibyte::strstr($string, $find, true);
$expected = 'Hello, ';
$this->assertEqual($expected, $result);
$string = 'Hello, World!';
$find = 'll';
$result = Multibyte::strstr($string, $find);
$expected = 'llo, World!';
$this->assertEqual($expected, $result);
$string = 'Hello, World!';
$find = 'll';
$result = Multibyte::strstr($string, $find, true);
$expected = 'He';
$this->assertEqual($expected, $result);
$string = 'Hello, World!';
$find = 'rld';
$result = Multibyte::strstr($string, $find);
$expected = 'rld!';
$this->assertEqual($expected, $result);
$string = 'Hello, World!';
$find = 'rld';
$result = Multibyte::strstr($string, $find, true);
$expected = 'Hello, Wo';
$this->assertEqual($expected, $result);
$string = 'čini';
$find = 'n';
$result = Multibyte::strstr($string, $find);
$expected = 'ni';
$this->assertEqual($expected, $result);
$string = 'čini';
$find = 'n';
$result = Multibyte::strstr($string, $find, true);
$expected = 'či';
$this->assertEqual($expected, $result);
$string = 'moći';
$find = 'ć';
$result = Multibyte::strstr($string, $find);
$expected = 'ći';
$this->assertEqual($expected, $result);
$string = 'moći';
$find = 'ć';
$result = Multibyte::strstr($string, $find, true);
$expected = 'mo';
$this->assertEqual($expected, $result);
$string = 'državni';
$find = 'ž';
$result = Multibyte::strstr($string, $find);
$expected = 'žavni';
$this->assertEqual($expected, $result);
$string = 'državni';
$find = 'ž';
$result = Multibyte::strstr($string, $find, true);
$expected = 'dr';
$this->assertEqual($expected, $result);
$string = '把百度设为首页';
$find = '设';
$result = Multibyte::strstr($string, $find);
$expected = '设为首页';
$this->assertEqual($expected, $result);
$string = '把百度设为首页';
$find = '设';
$result = Multibyte::strstr($string, $find, true);
$expected = '把百度';
$this->assertEqual($expected, $result);
$string = '一二三周永龍';
$find = '周';
$result = Multibyte::strstr($string, $find);
$expected = '周永龍';
$this->assertEqual($expected, $result);
$string = '一二三周永龍';
$find = '周';
$result = Multibyte::strstr($string, $find, true);
$expected = '一二三';
$this->assertEqual($expected, $result);
$string = '一二三周永龍';
$find = '二周';
$result = Multibyte::strstr($string, $find);
$expected = false;
$this->assertEqual($expected, $result);
}
/**
* testUsingMbStrtolower method
*
* @return void
*/
public function testUsingMbStrtolower() {
$string = '!"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`ABCDEFGHIJKLMNOPQRSTUVWXYZ{|}~';
$result = mb_strtolower($string);
$expected = '!"#$%&\'()*+,-./0123456789:;<=>?@abcdefghijklmnopqrstuvwxyz[\]^_`abcdefghijklmnopqrstuvwxyz{|}~';
$this->assertEqual($expected, $result);
$string = '!"#$%&\'()*+,-./0123456789:;<=>?@';
$result = mb_strtolower($string);
$expected = '!"#$%&\'()*+,-./0123456789:;<=>?@';
$this->assertEqual($expected, $result);
$string = 'À';
$result = mb_strtolower($string);
$expected = 'à';
$this->assertEqual($expected, $result);
$string = 'Á';
$result = mb_strtolower($string);
$expected = 'á';
$this->assertEqual($expected, $result);
$string = 'Â';
$result = mb_strtolower($string);
$expected = 'â';
$this->assertEqual($expected, $result);
$string = 'Ã';
$result = mb_strtolower($string);
$expected = 'ã';
$this->assertEqual($expected, $result);
$string = 'Ä';
$result = mb_strtolower($string);
$expected = 'ä';
$this->assertEqual($expected, $result);
$string = 'Å';
$result = mb_strtolower($string);
$expected = 'å';
$this->assertEqual($expected, $result);
$string = 'Æ';
$result = mb_strtolower($string);
$expected = 'æ';
$this->assertEqual($expected, $result);
$string = 'Ç';
$result = mb_strtolower($string);
$expected = 'ç';
$this->assertEqual($expected, $result);
$string = 'È';
$result = mb_strtolower($string);
$expected = 'è';
$this->assertEqual($expected, $result);
$string = 'É';
$result = mb_strtolower($string);
$expected = 'é';
$this->assertEqual($expected, $result);
$string = 'Ê';
$result = mb_strtolower($string);
$expected = 'ê';
$this->assertEqual($expected, $result);
$string = 'Ë';
$result = mb_strtolower($string);
$expected = 'ë';
$this->assertEqual($expected, $result);
$string = 'Ì';
$result = mb_strtolower($string);
$expected = 'ì';
$this->assertEqual($expected, $result);
$string = 'Í';
$result = mb_strtolower($string);
$expected = 'í';
$this->assertEqual($expected, $result);
$string = 'Î';
$result = mb_strtolower($string);
$expected = 'î';
$this->assertEqual($expected, $result);
$string = 'Ï';
$result = mb_strtolower($string);
$expected = 'ï';
$this->assertEqual($expected, $result);
$string = 'Ð';
$result = mb_strtolower($string);
$expected = 'ð';
$this->assertEqual($expected, $result);
$string = 'Ñ';
$result = mb_strtolower($string);
$expected = 'ñ';
$this->assertEqual($expected, $result);
$string = 'Ò';
$result = mb_strtolower($string);
$expected = 'ò';
$this->assertEqual($expected, $result);
$string = 'Ó';
$result = mb_strtolower($string);
$expected = 'ó';
$this->assertEqual($expected, $result);
$string = 'Ô';
$result = mb_strtolower($string);
$expected = 'ô';
$this->assertEqual($expected, $result);
$string = 'Õ';
$result = mb_strtolower($string);
$expected = 'õ';
$this->assertEqual($expected, $result);
$string = 'Ö';
$result = mb_strtolower($string);
$expected = 'ö';
$this->assertEqual($expected, $result);
$string = 'Ø';
$result = mb_strtolower($string);
$expected = 'ø';
$this->assertEqual($expected, $result);
$string = 'Ù';
$result = mb_strtolower($string);
$expected = 'ù';
$this->assertEqual($expected, $result);
$string = 'Ú';
$result = mb_strtolower($string);
$expected = 'ú';
$this->assertEqual($expected, $result);
$string = 'Û';
$result = mb_strtolower($string);
$expected = 'û';
$this->assertEqual($expected, $result);
$string = 'Ü';
$result = mb_strtolower($string);
$expected = 'ü';
$this->assertEqual($expected, $result);
$string = 'Ý';
$result = mb_strtolower($string);
$expected = 'ý';
$this->assertEqual($expected, $result);
$string = 'Þ';
$result = mb_strtolower($string);
$expected = 'þ';
$this->assertEqual($expected, $result);
$string = 'ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞ';
$result = mb_strtolower($string);
$expected = 'àáâãäåæçèéêëìíîïðñòóôõöøùúûüýþ';
$this->assertEqual($expected, $result);
$string = 'Ā';
$result = mb_strtolower($string);
$expected = 'ā';
$this->assertEqual($expected, $result);
$string = 'Ă';
$result = mb_strtolower($string);
$expected = 'ă';
$this->assertEqual($expected, $result);
$string = 'Ą';
$result = mb_strtolower($string);
$expected = 'ą';
$this->assertEqual($expected, $result);
$string = 'Ć';
$result = mb_strtolower($string);
$expected = 'ć';
$this->assertEqual($expected, $result);
$string = 'Ĉ';
$result = mb_strtolower($string);
$expected = 'ĉ';
$this->assertEqual($expected, $result);
$string = 'Ċ';
$result = mb_strtolower($string);
$expected = 'ċ';
$this->assertEqual($expected, $result);
$string = 'Č';
$result = mb_strtolower($string);
$expected = 'č';
$this->assertEqual($expected, $result);
$string = 'Ď';
$result = mb_strtolower($string);
$expected = 'ď';
$this->assertEqual($expected, $result);
$string = 'Đ';
$result = mb_strtolower($string);
$expected = 'đ';
$this->assertEqual($expected, $result);
$string = 'Ē';
$result = mb_strtolower($string);
$expected = 'ē';
$this->assertEqual($expected, $result);
$string = 'Ĕ';
$result = mb_strtolower($string);
$expected = 'ĕ';
$this->assertEqual($expected, $result);
$string = 'Ė';
$result = mb_strtolower($string);
$expected = 'ė';
$this->assertEqual($expected, $result);
$string = 'Ę';
$result = mb_strtolower($string);
$expected = 'ę';
$this->assertEqual($expected, $result);
$string = 'Ě';
$result = mb_strtolower($string);
$expected = 'ě';
$this->assertEqual($expected, $result);
$string = 'Ĝ';
$result = mb_strtolower($string);
$expected = 'ĝ';
$this->assertEqual($expected, $result);
$string = 'Ğ';
$result = mb_strtolower($string);
$expected = 'ğ';
$this->assertEqual($expected, $result);
$string = 'Ġ';
$result = mb_strtolower($string);
$expected = 'ġ';
$this->assertEqual($expected, $result);
$string = 'Ģ';
$result = mb_strtolower($string);
$expected = 'ģ';
$this->assertEqual($expected, $result);
$string = 'Ĥ';
$result = mb_strtolower($string);
$expected = 'ĥ';
$this->assertEqual($expected, $result);
$string = 'Ħ';
$result = mb_strtolower($string);
$expected = 'ħ';
$this->assertEqual($expected, $result);
$string = 'Ĩ';
$result = mb_strtolower($string);
$expected = 'ĩ';
$this->assertEqual($expected, $result);
$string = 'Ī';
$result = mb_strtolower($string);
$expected = 'ī';
$this->assertEqual($expected, $result);
$string = 'Ĭ';
$result = mb_strtolower($string);
$expected = 'ĭ';
$this->assertEqual($expected, $result);
$string = 'Į';
$result = mb_strtolower($string);
$expected = 'į';
$this->assertEqual($expected, $result);
$string = 'IJ';
$result = mb_strtolower($string);
$expected = 'ij';
$this->assertEqual($expected, $result);
$string = 'Ĵ';
$result = mb_strtolower($string);
$expected = 'ĵ';
$this->assertEqual($expected, $result);
$string = 'Ķ';
$result = mb_strtolower($string);
$expected = 'ķ';
$this->assertEqual($expected, $result);
$string = 'Ĺ';
$result = mb_strtolower($string);
$expected = 'ĺ';
$this->assertEqual($expected, $result);
$string = 'Ļ';
$result = mb_strtolower($string);
$expected = 'ļ';
$this->assertEqual($expected, $result);
$string = 'Ľ';
$result = mb_strtolower($string);
$expected = 'ľ';
$this->assertEqual($expected, $result);
$string = 'Ŀ';
$result = mb_strtolower($string);
$expected = 'ŀ';
$this->assertEqual($expected, $result);
$string = 'Ł';
$result = mb_strtolower($string);
$expected = 'ł';
$this->assertEqual($expected, $result);
$string = 'Ń';
$result = mb_strtolower($string);
$expected = 'ń';
$this->assertEqual($expected, $result);
$string = 'Ņ';
$result = mb_strtolower($string);
$expected = 'ņ';
$this->assertEqual($expected, $result);
$string = 'Ň';
$result = mb_strtolower($string);
$expected = 'ň';
$this->assertEqual($expected, $result);
$string = 'Ŋ';
$result = mb_strtolower($string);
$expected = 'ŋ';
$this->assertEqual($expected, $result);
$string = 'Ō';
$result = mb_strtolower($string);
$expected = 'ō';
$this->assertEqual($expected, $result);
$string = 'Ŏ';
$result = mb_strtolower($string);
$expected = 'ŏ';
$this->assertEqual($expected, $result);
$string = 'Ő';
$result = mb_strtolower($string);
$expected = 'ő';
$this->assertEqual($expected, $result);
$string = 'Œ';
$result = mb_strtolower($string);
$expected = 'œ';
$this->assertEqual($expected, $result);
$string = 'Ŕ';
$result = mb_strtolower($string);
$expected = 'ŕ';
$this->assertEqual($expected, $result);
$string = 'Ŗ';
$result = mb_strtolower($string);
$expected = 'ŗ';
$this->assertEqual($expected, $result);
$string = 'Ř';
$result = mb_strtolower($string);
$expected = 'ř';
$this->assertEqual($expected, $result);
$string = 'Ś';
$result = mb_strtolower($string);
$expected = 'ś';
$this->assertEqual($expected, $result);
$string = 'Ŝ';
$result = mb_strtolower($string);
$expected = 'ŝ';
$this->assertEqual($expected, $result);
$string = 'Ş';
$result = mb_strtolower($string);
$expected = 'ş';
$this->assertEqual($expected, $result);
$string = 'Š';
$result = mb_strtolower($string);
$expected = 'š';
$this->assertEqual($expected, $result);
$string = 'Ţ';
$result = mb_strtolower($string);
$expected = 'ţ';
$this->assertEqual($expected, $result);
$string = 'Ť';
$result = mb_strtolower($string);
$expected = 'ť';
$this->assertEqual($expected, $result);
$string = 'Ŧ';
$result = mb_strtolower($string);
$expected = 'ŧ';
$this->assertEqual($expected, $result);
$string = 'Ũ';
$result = mb_strtolower($string);
$expected = 'ũ';
$this->assertEqual($expected, $result);
$string = 'Ū';
$result = mb_strtolower($string);
$expected = 'ū';
$this->assertEqual($expected, $result);
$string = 'Ŭ';
$result = mb_strtolower($string);
$expected = 'ŭ';
$this->assertEqual($expected, $result);
$string = 'Ů';
$result = mb_strtolower($string);
$expected = 'ů';
$this->assertEqual($expected, $result);
$string = 'Ű';
$result = mb_strtolower($string);
$expected = 'ű';
$this->assertEqual($expected, $result);
$string = 'Ų';
$result = mb_strtolower($string);
$expected = 'ų';
$this->assertEqual($expected, $result);
$string = 'Ŵ';
$result = mb_strtolower($string);
$expected = 'ŵ';
$this->assertEqual($expected, $result);
$string = 'Ŷ';
$result = mb_strtolower($string);
$expected = 'ŷ';
$this->assertEqual($expected, $result);
$string = 'Ź';
$result = mb_strtolower($string);
$expected = 'ź';
$this->assertEqual($expected, $result);
$string = 'Ż';
$result = mb_strtolower($string);
$expected = 'ż';
$this->assertEqual($expected, $result);
$string = 'Ž';
$result = mb_strtolower($string);
$expected = 'ž';
$this->assertEqual($expected, $result);
$string = 'ĀĂĄĆĈĊČĎĐĒĔĖĘĚĜĞĠĢĤĦĨĪĬĮIJĴĶĹĻĽĿŁŃŅŇŊŌŎŐŒŔŖŘŚŜŞŠŢŤŦŨŪŬŮŰŲŴŶŹŻŽ';
$result = mb_strtolower($string);
$expected = 'āăąćĉċčďđēĕėęěĝğġģĥħĩīĭįijĵķĺļľŀłńņňŋōŏőœŕŗřśŝşšţťŧũūŭůűųŵŷźżž';
$this->assertEqual($expected, $result);
$string = 'ĤĒĹĻŎ, ŴŐŘĻĎ!';
$result = mb_strtolower($string);
$expected = 'ĥēĺļŏ, ŵőřļď!';
$this->assertEqual($expected, $result);
$string = 'ĥēĺļŏ, ŵőřļď!';
$result = mb_strtolower($string);
$expected = 'ĥēĺļŏ, ŵőřļď!';
$this->assertEqual($expected, $result);
$string = 'ἈΙ';
$result = mb_strtolower($string);
$expected = 'ἀι';
$this->assertEqual($expected, $result);
/*
The tests below are flaky across different platforms.
$string = 'ԀԂԄԆԈԊԌԎԐԒ';
$result = mb_strtolower($string);
$expected = 'ԁԃԅԇԉԋԍԏԑԓ';
$this->assertEqual($expected, $result);
$string = 'ԱԲԳԴԵԶԷԸԹԺԻԼԽԾԿՀՁՂՃՄՅՆՇՈՉՊՋՌՍՎՏՐՑՒՓՔՕՖև';
$result = mb_strtolower($string);
$expected = 'աբգդեզէըթժիլխծկհձղճմյնշոչպջռսվտրցւփքօֆև';
$this->assertEqual($expected, $result);
$string = 'ḀḂḄḆḈḊḌḎḐḒḔḖḘḚḜḞḠḢḤḦḨḪḬḮḰḲḴḶḸḺḼḾṀṂṄṆṈṊṌṎṐṒṔṖṘṚṜṞṠṢṤṦṨṪṬṮṰṲṴṶṸṺṼṾẀẂẄẆẈẊẌẎẐẒẔẖẗẘẙẚẠẢẤẦẨẪẬẮẰẲẴẶẸẺẼẾỀỂỄỆỈỊỌỎỐỒỔỖỘỚỜỞỠỢỤỦỨỪỬỮỰỲỴỶỸ';
$result = mb_strtolower($string);
$expected = 'ḁḃḅḇḉḋḍḏḑḓḕḗḙḛḝḟḡḣḥḧḩḫḭḯḱḳḵḷḹḻḽḿṁṃṅṇṉṋṍṏṑṓṕṗṙṛṝṟṡṣṥṧṩṫṭṯṱṳṵṷṹṻṽṿẁẃẅẇẉẋẍẏẑẓẕẖẗẘẙẚạảấầẩẫậắằẳẵặẹẻẽếềểễệỉịọỏốồổỗộớờởỡợụủứừửữựỳỵỷỹ';
$this->assertEqual($expected, $result);
$string = 'ΩKÅ';
$result = mb_strtolower($string);
$expected = 'ωkå';
$this->assertEqual($expected, $result);
$string = 'ΩKÅ';
$result = mb_strtolower($string);
$expected = 'ωkå';
$this->assertEqual($expected, $result);
/*
mb_strtolower does not work for these strings.
$string = 'ⅠⅡⅢⅣⅤⅥⅦⅧⅨⅩⅪⅫⅬⅭⅮⅯↃ';
$result = mb_strtolower($string);
$expected = 'ⅰⅱⅲⅳⅴⅵⅶⅷⅸⅹⅺⅻⅼⅽⅾⅿↄ';
$this->assertEqual($expected, $result);
$string = 'ⒶⒷⒸⒹⒺⒻⒼⒽⒾⒿⓀⓁⓂⓃⓄⓅⓆⓇⓈⓉⓊⓋⓌⓍⓎⓏ';
$result = mb_strtolower($string);
$expected = 'ⓐⓑⓒⓓⓔⓕⓖⓗⓘⓙⓚⓛⓜⓝⓞⓟⓠⓡⓢⓣⓤⓥⓦⓧⓨⓩ';
$this->assertEqual($expected, $result);
$string = 'ⰀⰁⰂⰃⰄⰅⰆⰇⰈⰉⰊⰋⰌⰍⰎⰏⰐⰑⰒⰓⰔⰕⰖⰗⰘⰙⰚⰛⰜⰝⰞⰟⰠⰡⰢⰣⰤⰥⰦⰧⰨⰩⰪⰫⰬⰭⰮ';
$result = mb_strtolower($string);
$expected = 'ⰰⰱⰲⰳⰴⰵⰶⰷⰸⰹⰺⰻⰼⰽⰾⰿⱀⱁⱂⱃⱄⱅⱆⱇⱈⱉⱊⱋⱌⱍⱎⱏⱐⱑⱒⱓⱔⱕⱖⱗⱘⱙⱚⱛⱜⱝⱞ';
$this->assertEqual($expected, $result);
$string = 'ⲀⲂⲄⲆⲈⲊⲌⲎⲐⲒⲔⲖⲘⲚⲜⲞⲠⲢⲤⲦⲨⲪⲬⲮⲰⲲⲴⲶⲸⲺⲼⲾⳀⳂⳄⳆⳈⳊⳌⳎⳐⳒⳔⳖⳘⳚⳜⳞⳠⳢ';
$result = mb_strtolower($string);
$expected = 'ⲁⲃⲅⲇⲉⲋⲍⲏⲑⲓⲕⲗⲙⲛⲝⲟⲡⲣⲥⲧⲩⲫⲭⲯⲱⲳⲵⲷⲹⲻⲽⲿⳁⳃⳅⳇⳉⳋⳍⳏⳑⳓⳕⳗⳙⳛⳝⳟⳡⳣ';
$this->assertEqual($expected, $result);
*/
$string = 'fffiflffifflſtstﬓﬔﬕﬖﬗ';
$result = mb_strtolower($string);
$expected = 'fffiflffifflſtstﬓﬔﬕﬖﬗ';
$this->assertEqual($expected, $result);
}
/**
* testMultibyteStrtolower method
*
* @return void
*/
public function testMultibyteStrtolower() {
$string = '!"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`ABCDEFGHIJKLMNOPQRSTUVWXYZ{|}~';
$result = Multibyte::strtolower($string);
$expected = '!"#$%&\'()*+,-./0123456789:;<=>?@abcdefghijklmnopqrstuvwxyz[\]^_`abcdefghijklmnopqrstuvwxyz{|}~';
$this->assertEqual($expected, $result);
$string = '!"#$%&\'()*+,-./0123456789:;<=>?@';
$result = Multibyte::strtolower($string);
$expected = '!"#$%&\'()*+,-./0123456789:;<=>?@';
$this->assertEqual($expected, $result);
$string = 'À';
$result = Multibyte::strtolower($string);
$expected = 'à';
$this->assertEqual($expected, $result);
$string = 'Á';
$result = Multibyte::strtolower($string);
$expected = 'á';
$this->assertEqual($expected, $result);
$string = 'Â';
$result = Multibyte::strtolower($string);
$expected = 'â';
$this->assertEqual($expected, $result);
$string = 'Ã';
$result = Multibyte::strtolower($string);
$expected = 'ã';
$this->assertEqual($expected, $result);
$string = 'Ä';
$result = Multibyte::strtolower($string);
$expected = 'ä';
$this->assertEqual($expected, $result);
$string = 'Å';
$result = Multibyte::strtolower($string);
$expected = 'å';
$this->assertEqual($expected, $result);
$string = 'Æ';
$result = Multibyte::strtolower($string);
$expected = 'æ';
$this->assertEqual($expected, $result);
$string = 'Ç';
$result = Multibyte::strtolower($string);
$expected = 'ç';
$this->assertEqual($expected, $result);
$string = 'È';
$result = Multibyte::strtolower($string);
$expected = 'è';
$this->assertEqual($expected, $result);
$string = 'É';
$result = Multibyte::strtolower($string);
$expected = 'é';
$this->assertEqual($expected, $result);
$string = 'Ê';
$result = Multibyte::strtolower($string);
$expected = 'ê';
$this->assertEqual($expected, $result);
$string = 'Ë';
$result = Multibyte::strtolower($string);
$expected = 'ë';
$this->assertEqual($expected, $result);
$string = 'Ì';
$result = Multibyte::strtolower($string);
$expected = 'ì';
$this->assertEqual($expected, $result);
$string = 'Í';
$result = Multibyte::strtolower($string);
$expected = 'í';
$this->assertEqual($expected, $result);
$string = 'Î';
$result = Multibyte::strtolower($string);
$expected = 'î';
$this->assertEqual($expected, $result);
$string = 'Ï';
$result = Multibyte::strtolower($string);
$expected = 'ï';
$this->assertEqual($expected, $result);
$string = 'Ð';
$result = Multibyte::strtolower($string);
$expected = 'ð';
$this->assertEqual($expected, $result);
$string = 'Ñ';
$result = Multibyte::strtolower($string);
$expected = 'ñ';
$this->assertEqual($expected, $result);
$string = 'Ò';
$result = Multibyte::strtolower($string);
$expected = 'ò';
$this->assertEqual($expected, $result);
$string = 'Ó';
$result = Multibyte::strtolower($string);
$expected = 'ó';
$this->assertEqual($expected, $result);
$string = 'Ô';
$result = Multibyte::strtolower($string);
$expected = 'ô';
$this->assertEqual($expected, $result);
$string = 'Õ';
$result = Multibyte::strtolower($string);
$expected = 'õ';
$this->assertEqual($expected, $result);
$string = 'Ö';
$result = Multibyte::strtolower($string);
$expected = 'ö';
$this->assertEqual($expected, $result);
$string = 'Ø';
$result = Multibyte::strtolower($string);
$expected = 'ø';
$this->assertEqual($expected, $result);
$string = 'Ù';
$result = Multibyte::strtolower($string);
$expected = 'ù';
$this->assertEqual($expected, $result);
$string = 'Ú';
$result = Multibyte::strtolower($string);
$expected = 'ú';
$this->assertEqual($expected, $result);
$string = 'Û';
$result = Multibyte::strtolower($string);
$expected = 'û';
$this->assertEqual($expected, $result);
$string = 'Ü';
$result = Multibyte::strtolower($string);
$expected = 'ü';
$this->assertEqual($expected, $result);
$string = 'Ý';
$result = Multibyte::strtolower($string);
$expected = 'ý';
$this->assertEqual($expected, $result);
$string = 'Þ';
$result = Multibyte::strtolower($string);
$expected = 'þ';
$this->assertEqual($expected, $result);
$string = 'ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞ';
$result = Multibyte::strtolower($string);
$expected = 'àáâãäåæçèéêëìíîïðñòóôõöøùúûüýþ';
$this->assertEqual($expected, $result);
$string = 'Ā';
$result = Multibyte::strtolower($string);
$expected = 'ā';
$this->assertEqual($expected, $result);
$string = 'Ă';
$result = Multibyte::strtolower($string);
$expected = 'ă';
$this->assertEqual($expected, $result);
$string = 'Ą';
$result = Multibyte::strtolower($string);
$expected = 'ą';
$this->assertEqual($expected, $result);
$string = 'Ć';
$result = Multibyte::strtolower($string);
$expected = 'ć';
$this->assertEqual($expected, $result);
$string = 'Ĉ';
$result = Multibyte::strtolower($string);
$expected = 'ĉ';
$this->assertEqual($expected, $result);
$string = 'Ċ';
$result = Multibyte::strtolower($string);
$expected = 'ċ';
$this->assertEqual($expected, $result);
$string = 'Č';
$result = Multibyte::strtolower($string);
$expected = 'č';
$this->assertEqual($expected, $result);
$string = 'Ď';
$result = Multibyte::strtolower($string);
$expected = 'ď';
$this->assertEqual($expected, $result);
$string = 'Đ';
$result = Multibyte::strtolower($string);
$expected = 'đ';
$this->assertEqual($expected, $result);
$string = 'Ē';
$result = Multibyte::strtolower($string);
$expected = 'ē';
$this->assertEqual($expected, $result);
$string = 'Ĕ';
$result = Multibyte::strtolower($string);
$expected = 'ĕ';
$this->assertEqual($expected, $result);
$string = 'Ė';
$result = Multibyte::strtolower($string);
$expected = 'ė';
$this->assertEqual($expected, $result);
$string = 'Ę';
$result = Multibyte::strtolower($string);
$expected = 'ę';
$this->assertEqual($expected, $result);
$string = 'Ě';
$result = Multibyte::strtolower($string);
$expected = 'ě';
$this->assertEqual($expected, $result);
$string = 'Ĝ';
$result = Multibyte::strtolower($string);
$expected = 'ĝ';
$this->assertEqual($expected, $result);
$string = 'Ğ';
$result = Multibyte::strtolower($string);
$expected = 'ğ';
$this->assertEqual($expected, $result);
$string = 'Ġ';
$result = Multibyte::strtolower($string);
$expected = 'ġ';
$this->assertEqual($expected, $result);
$string = 'Ģ';
$result = Multibyte::strtolower($string);
$expected = 'ģ';
$this->assertEqual($expected, $result);
$string = 'Ĥ';
$result = Multibyte::strtolower($string);
$expected = 'ĥ';
$this->assertEqual($expected, $result);
$string = 'Ħ';
$result = Multibyte::strtolower($string);
$expected = 'ħ';
$this->assertEqual($expected, $result);
$string = 'Ĩ';
$result = Multibyte::strtolower($string);
$expected = 'ĩ';
$this->assertEqual($expected, $result);
$string = 'Ī';
$result = Multibyte::strtolower($string);
$expected = 'ī';
$this->assertEqual($expected, $result);
$string = 'Ĭ';
$result = Multibyte::strtolower($string);
$expected = 'ĭ';
$this->assertEqual($expected, $result);
$string = 'Į';
$result = Multibyte::strtolower($string);
$expected = 'į';
$this->assertEqual($expected, $result);
$string = 'IJ';
$result = Multibyte::strtolower($string);
$expected = 'ij';
$this->assertEqual($expected, $result);
$string = 'Ĵ';
$result = Multibyte::strtolower($string);
$expected = 'ĵ';
$this->assertEqual($expected, $result);
$string = 'Ķ';
$result = Multibyte::strtolower($string);
$expected = 'ķ';
$this->assertEqual($expected, $result);
$string = 'Ĺ';
$result = Multibyte::strtolower($string);
$expected = 'ĺ';
$this->assertEqual($expected, $result);
$string = 'Ļ';
$result = Multibyte::strtolower($string);
$expected = 'ļ';
$this->assertEqual($expected, $result);
$string = 'Ľ';
$result = Multibyte::strtolower($string);
$expected = 'ľ';
$this->assertEqual($expected, $result);
$string = 'Ŀ';
$result = Multibyte::strtolower($string);
$expected = 'ŀ';
$this->assertEqual($expected, $result);
$string = 'Ł';
$result = Multibyte::strtolower($string);
$expected = 'ł';
$this->assertEqual($expected, $result);
$string = 'Ń';
$result = Multibyte::strtolower($string);
$expected = 'ń';
$this->assertEqual($expected, $result);
$string = 'Ņ';
$result = Multibyte::strtolower($string);
$expected = 'ņ';
$this->assertEqual($expected, $result);
$string = 'Ň';
$result = Multibyte::strtolower($string);
$expected = 'ň';
$this->assertEqual($expected, $result);
$string = 'Ŋ';
$result = Multibyte::strtolower($string);
$expected = 'ŋ';
$this->assertEqual($expected, $result);
$string = 'Ō';
$result = Multibyte::strtolower($string);
$expected = 'ō';
$this->assertEqual($expected, $result);
$string = 'Ŏ';
$result = Multibyte::strtolower($string);
$expected = 'ŏ';
$this->assertEqual($expected, $result);
$string = 'Ő';
$result = Multibyte::strtolower($string);
$expected = 'ő';
$this->assertEqual($expected, $result);
$string = 'Œ';
$result = Multibyte::strtolower($string);
$expected = 'œ';
$this->assertEqual($expected, $result);
$string = 'Ŕ';
$result = Multibyte::strtolower($string);
$expected = 'ŕ';
$this->assertEqual($expected, $result);
$string = 'Ŗ';
$result = Multibyte::strtolower($string);
$expected = 'ŗ';
$this->assertEqual($expected, $result);
$string = 'Ř';
$result = Multibyte::strtolower($string);
$expected = 'ř';
$this->assertEqual($expected, $result);
$string = 'Ś';
$result = Multibyte::strtolower($string);
$expected = 'ś';
$this->assertEqual($expected, $result);
$string = 'Ŝ';
$result = Multibyte::strtolower($string);
$expected = 'ŝ';
$this->assertEqual($expected, $result);
$string = 'Ş';
$result = Multibyte::strtolower($string);
$expected = 'ş';
$this->assertEqual($expected, $result);
$string = 'Š';
$result = Multibyte::strtolower($string);
$expected = 'š';
$this->assertEqual($expected, $result);
$string = 'Ţ';
$result = Multibyte::strtolower($string);
$expected = 'ţ';
$this->assertEqual($expected, $result);
$string = 'Ť';
$result = Multibyte::strtolower($string);
$expected = 'ť';
$this->assertEqual($expected, $result);
$string = 'Ŧ';
$result = Multibyte::strtolower($string);
$expected = 'ŧ';
$this->assertEqual($expected, $result);
$string = 'Ũ';
$result = Multibyte::strtolower($string);
$expected = 'ũ';
$this->assertEqual($expected, $result);
$string = 'Ū';
$result = Multibyte::strtolower($string);
$expected = 'ū';
$this->assertEqual($expected, $result);
$string = 'Ŭ';
$result = Multibyte::strtolower($string);
$expected = 'ŭ';
$this->assertEqual($expected, $result);
$string = 'Ů';
$result = Multibyte::strtolower($string);
$expected = 'ů';
$this->assertEqual($expected, $result);
$string = 'Ű';
$result = Multibyte::strtolower($string);
$expected = 'ű';
$this->assertEqual($expected, $result);
$string = 'Ų';
$result = Multibyte::strtolower($string);
$expected = 'ų';
$this->assertEqual($expected, $result);
$string = 'Ŵ';
$result = Multibyte::strtolower($string);
$expected = 'ŵ';
$this->assertEqual($expected, $result);
$string = 'Ŷ';
$result = Multibyte::strtolower($string);
$expected = 'ŷ';
$this->assertEqual($expected, $result);
$string = 'Ź';
$result = Multibyte::strtolower($string);
$expected = 'ź';
$this->assertEqual($expected, $result);
$string = 'Ż';
$result = Multibyte::strtolower($string);
$expected = 'ż';
$this->assertEqual($expected, $result);
$string = 'Ž';
$result = Multibyte::strtolower($string);
$expected = 'ž';
$this->assertEqual($expected, $result);
$string = 'ĀĂĄĆĈĊČĎĐĒĔĖĘĚĜĞĠĢĤĦĨĪĬĮIJĴĶĹĻĽĿŁŃŅŇŊŌŎŐŒŔŖŘŚŜŞŠŢŤŦŨŪŬŮŰŲŴŶŹŻŽ';
$result = Multibyte::strtolower($string);
$expected = 'āăąćĉċčďđēĕėęěĝğġģĥħĩīĭįijĵķĺļľŀłńņňŋōŏőœŕŗřśŝşšţťŧũūŭůűųŵŷźżž';
$this->assertEqual($expected, $result);
$string = 'ĤĒĹĻŎ, ŴŐŘĻĎ!';
$result = Multibyte::strtolower($string);
$expected = 'ĥēĺļŏ, ŵőřļď!';
$this->assertEqual($expected, $result);
$string = 'ĥēĺļŏ, ŵőřļď!';
$result = Multibyte::strtolower($string);
$expected = 'ĥēĺļŏ, ŵőřļď!';
$this->assertEqual($expected, $result);
$string = 'ἈΙ';
$result = Multibyte::strtolower($string);
$expected = 'ἀι';
$this->assertEqual($expected, $result);
$string = 'ԀԂԄԆԈԊԌԎԐԒ';
$result = Multibyte::strtolower($string);
$expected = 'ԁԃԅԇԉԋԍԏԑԓ';
$this->assertEqual($expected, $result);
$string = 'ԱԲԳԴԵԶԷԸԹԺԻԼԽԾԿՀՁՂՃՄՅՆՇՈՉՊՋՌՍՎՏՐՑՒՓՔՕՖև';
$result = Multibyte::strtolower($string);
$expected = 'աբգդեզէըթժիլխծկհձղճմյնշոչպջռսվտրցւփքօֆև';
$this->assertEqual($expected, $result);
$string = 'ႠႡႢႣႤႥႦႧႨႩႪႫႬႭႮႯႰႱႲႳႴႵႶႷႸႹႺႻႼႽႾႿჀჁჂჃჄჅ';
$result = Multibyte::strtolower($string);
$expected = 'ႠႡႢႣႤႥႦႧႨႩႪႫႬႭႮႯႰႱႲႳႴႵႶႷႸႹႺႻႼႽႾႿჀჁჂჃჄჅ';
$this->assertEqual($expected, $result);
$string = 'ḀḂḄḆḈḊḌḎḐḒḔḖḘḚḜḞḠḢḤḦḨḪḬḮḰḲḴḶḸḺḼḾṀṂṄṆṈṊṌṎṐṒṔṖṘṚṜṞṠṢṤṦṨṪṬṮṰṲṴṶṸṺṼṾẀẂẄẆẈẊẌẎẐẒẔẖẗẘẙẚẠẢẤẦẨẪẬẮẰẲẴẶẸẺẼẾỀỂỄỆỈỊỌỎỐỒỔỖỘỚỜỞỠỢỤỦỨỪỬỮỰỲỴỶỸ';
$result = Multibyte::strtolower($string);
$expected = 'ḁḃḅḇḉḋḍḏḑḓḕḗḙḛḝḟḡḣḥḧḩḫḭḯḱḳḵḷḹḻḽḿṁṃṅṇṉṋṍṏṑṓṕṗṙṛṝṟṡṣṥṧṩṫṭṯṱṳṵṷṹṻṽṿẁẃẅẇẉẋẍẏẑẓẕẖẗẘẙẚạảấầẩẫậắằẳẵặẹẻẽếềểễệỉịọỏốồổỗộớờởỡợụủứừửữựỳỵỷỹ';
$this->assertEqual($expected, $result);
$string = 'ΩKÅℲ';
$result = Multibyte::strtolower($string);
$expected = 'ωkåⅎ';
$this->assertEqual($expected, $result);
$string = 'ΩKÅ';
$result = Multibyte::strtolower($string);
$expected = 'ωkå';
$this->assertEqual($expected, $result);
$string = 'ΩKÅ';
$result = Multibyte::strtolower($string);
$expected = 'ωkå';
$this->assertEqual($expected, $result);
$string = 'ⅠⅡⅢⅣⅤⅥⅦⅧⅨⅩⅪⅫⅬⅭⅮⅯↃ';
$result = Multibyte::strtolower($string);
$expected = 'ⅰⅱⅲⅳⅴⅵⅶⅷⅸⅹⅺⅻⅼⅽⅾⅿↄ';
$this->assertEqual($expected, $result);
$string = 'ⒶⒷⒸⒹⒺⒻⒼⒽⒾⒿⓀⓁⓂⓃⓄⓅⓆⓇⓈⓉⓊⓋⓌⓍⓎⓏ';
$result = Multibyte::strtolower($string);
$expected = 'ⓐⓑⓒⓓⓔⓕⓖⓗⓘⓙⓚⓛⓜⓝⓞⓟⓠⓡⓢⓣⓤⓥⓦⓧⓨⓩ';
$this->assertEqual($expected, $result);
$string = 'ⰀⰁⰂⰃⰄⰅⰆⰇⰈⰉⰊⰋⰌⰍⰎⰏⰐⰑⰒⰓⰔⰕⰖⰗⰘⰙⰚⰛⰜⰝⰞⰟⰠⰡⰢⰣⰤⰥⰦⰧⰨⰩⰪⰫⰬⰭⰮ';
$result = Multibyte::strtolower($string);
$expected = 'ⰰⰱⰲⰳⰴⰵⰶⰷⰸⰹⰺⰻⰼⰽⰾⰿⱀⱁⱂⱃⱄⱅⱆⱇⱈⱉⱊⱋⱌⱍⱎⱏⱐⱑⱒⱓⱔⱕⱖⱗⱘⱙⱚⱛⱜⱝⱞ';
$this->assertEqual($expected, $result);
$string = 'ⲀⲂⲄⲆⲈⲊⲌⲎⲐⲒⲔⲖⲘⲚⲜⲞⲠⲢⲤⲦⲨⲪⲬⲮⲰⲲⲴⲶⲸⲺⲼⲾⳀⳂⳄⳆⳈⳊⳌⳎⳐⳒⳔⳖⳘⳚⳜⳞⳠⳢ';
$result = Multibyte::strtolower($string);
$expected = 'ⲁⲃⲅⲇⲉⲋⲍⲏⲑⲓⲕⲗⲙⲛⲝⲟⲡⲣⲥⲧⲩⲫⲭⲯⲱⲳⲵⲷⲹⲻⲽⲿⳁⳃⳅⳇⳉⳋⳍⳏⳑⳓⳕⳗⳙⳛⳝⳟⳡⳣ';
$this->assertEqual($expected, $result);
$string = 'fffiflffifflſtstﬓﬔﬕﬖﬗ';
$result = Multibyte::strtolower($string);
$expected = 'fffiflffifflſtstﬓﬔﬕﬖﬗ';
$this->assertEqual($expected, $result);
}
/**
* testUsingMbStrtoupper method
*
* @return void
*/
public function testUsingMbStrtoupper() {
$string = '!"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~';
$result = mb_strtoupper($string);
$expected = '!"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`ABCDEFGHIJKLMNOPQRSTUVWXYZ{|}~';
$this->assertEqual($expected, $result);
$string = '!"#$%&\'()*+,-./0123456789:;<=>?@';
$result = mb_strtoupper($string);
$expected = '!"#$%&\'()*+,-./0123456789:;<=>?@';
$this->assertEqual($expected, $result);
$string = 'à';
$result = mb_strtoupper($string);
$expected = 'À';
$this->assertEqual($expected, $result);
$string = 'á';
$result = mb_strtoupper($string);
$expected = 'Á';
$this->assertEqual($expected, $result);
$string = 'â';
$result = mb_strtoupper($string);
$expected = 'Â';
$this->assertEqual($expected, $result);
$string = 'ã';
$result = mb_strtoupper($string);
$expected = 'Ã';
$this->assertEqual($expected, $result);
$string = 'ä';
$result = mb_strtoupper($string);
$expected = 'Ä';
$this->assertEqual($expected, $result);
$string = 'å';
$result = mb_strtoupper($string);
$expected = 'Å';
$this->assertEqual($expected, $result);
$string = 'æ';
$result = mb_strtoupper($string);
$expected = 'Æ';
$this->assertEqual($expected, $result);
$string = 'ç';
$result = mb_strtoupper($string);
$expected = 'Ç';
$this->assertEqual($expected, $result);
$string = 'è';
$result = mb_strtoupper($string);
$expected = 'È';
$this->assertEqual($expected, $result);
$string = 'é';
$result = mb_strtoupper($string);
$expected = 'É';
$this->assertEqual($expected, $result);
$string = 'ê';
$result = mb_strtoupper($string);
$expected = 'Ê';
$this->assertEqual($expected, $result);
$string = 'ë';
$result = mb_strtoupper($string);
$expected = 'Ë';
$this->assertEqual($expected, $result);
$string = 'ì';
$result = mb_strtoupper($string);
$expected = 'Ì';
$this->assertEqual($expected, $result);
$string = 'í';
$result = mb_strtoupper($string);
$expected = 'Í';
$this->assertEqual($expected, $result);
$string = 'î';
$result = mb_strtoupper($string);
$expected = 'Î';
$this->assertEqual($expected, $result);
$string = 'ï';
$result = mb_strtoupper($string);
$expected = 'Ï';
$this->assertEqual($expected, $result);
$string = 'ð';
$result = mb_strtoupper($string);
$expected = 'Ð';
$this->assertEqual($expected, $result);
$string = 'ñ';
$result = mb_strtoupper($string);
$expected = 'Ñ';
$this->assertEqual($expected, $result);
$string = 'ò';
$result = mb_strtoupper($string);
$expected = 'Ò';
$this->assertEqual($expected, $result);
$string = 'ó';
$result = mb_strtoupper($string);
$expected = 'Ó';
$this->assertEqual($expected, $result);
$string = 'ô';
$result = mb_strtoupper($string);
$expected = 'Ô';
$this->assertEqual($expected, $result);
$string = 'õ';
$result = mb_strtoupper($string);
$expected = 'Õ';
$this->assertEqual($expected, $result);
$string = 'ö';
$result = mb_strtoupper($string);
$expected = 'Ö';
$this->assertEqual($expected, $result);
$string = 'ø';
$result = mb_strtoupper($string);
$expected = 'Ø';
$this->assertEqual($expected, $result);
$string = 'ù';
$result = mb_strtoupper($string);
$expected = 'Ù';
$this->assertEqual($expected, $result);
$string = 'ú';
$result = mb_strtoupper($string);
$expected = 'Ú';
$this->assertEqual($expected, $result);
$string = 'û';
$result = mb_strtoupper($string);
$expected = 'Û';
$this->assertEqual($expected, $result);
$string = 'ü';
$result = mb_strtoupper($string);
$expected = 'Ü';
$this->assertEqual($expected, $result);
$string = 'ý';
$result = mb_strtoupper($string);
$expected = 'Ý';
$this->assertEqual($expected, $result);
$string = 'þ';
$result = mb_strtoupper($string);
$expected = 'Þ';
$this->assertEqual($expected, $result);
$string = 'àáâãäåæçèéêëìíîïðñòóôõöøùúûüýþ';
$result = mb_strtoupper($string);
$expected = 'ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞ';
$this->assertEqual($expected, $result);
$string = 'ā';
$result = mb_strtoupper($string);
$expected = 'Ā';
$this->assertEqual($expected, $result);
$string = 'ă';
$result = mb_strtoupper($string);
$expected = 'Ă';
$this->assertEqual($expected, $result);
$string = 'ą';
$result = mb_strtoupper($string);
$expected = 'Ą';
$this->assertEqual($expected, $result);
$string = 'ć';
$result = mb_strtoupper($string);
$expected = 'Ć';
$this->assertEqual($expected, $result);
$string = 'ĉ';
$result = mb_strtoupper($string);
$expected = 'Ĉ';
$this->assertEqual($expected, $result);
$string = 'ċ';
$result = mb_strtoupper($string);
$expected = 'Ċ';
$this->assertEqual($expected, $result);
$string = 'č';
$result = mb_strtoupper($string);
$expected = 'Č';
$this->assertEqual($expected, $result);
$string = 'ď';
$result = mb_strtoupper($string);
$expected = 'Ď';
$this->assertEqual($expected, $result);
$string = 'đ';
$result = mb_strtoupper($string);
$expected = 'Đ';
$this->assertEqual($expected, $result);
$string = 'ē';
$result = mb_strtoupper($string);
$expected = 'Ē';
$this->assertEqual($expected, $result);
$string = 'ĕ';
$result = mb_strtoupper($string);
$expected = 'Ĕ';
$this->assertEqual($expected, $result);
$string = 'ė';
$result = mb_strtoupper($string);
$expected = 'Ė';
$this->assertEqual($expected, $result);
$string = 'ę';
$result = mb_strtoupper($string);
$expected = 'Ę';
$this->assertEqual($expected, $result);
$string = 'ě';
$result = mb_strtoupper($string);
$expected = 'Ě';
$this->assertEqual($expected, $result);
$string = 'ĝ';
$result = mb_strtoupper($string);
$expected = 'Ĝ';
$this->assertEqual($expected, $result);
$string = 'ğ';
$result = mb_strtoupper($string);
$expected = 'Ğ';
$this->assertEqual($expected, $result);
$string = 'ġ';
$result = mb_strtoupper($string);
$expected = 'Ġ';
$this->assertEqual($expected, $result);
$string = 'ģ';
$result = mb_strtoupper($string);
$expected = 'Ģ';
$this->assertEqual($expected, $result);
$string = 'ĥ';
$result = mb_strtoupper($string);
$expected = 'Ĥ';
$this->assertEqual($expected, $result);
$string = 'ħ';
$result = mb_strtoupper($string);
$expected = 'Ħ';
$this->assertEqual($expected, $result);
$string = 'ĩ';
$result = mb_strtoupper($string);
$expected = 'Ĩ';
$this->assertEqual($expected, $result);
$string = 'ī';
$result = mb_strtoupper($string);
$expected = 'Ī';
$this->assertEqual($expected, $result);
$string = 'ĭ';
$result = mb_strtoupper($string);
$expected = 'Ĭ';
$this->assertEqual($expected, $result);
$string = 'į';
$result = mb_strtoupper($string);
$expected = 'Į';
$this->assertEqual($expected, $result);
$string = 'ij';
$result = mb_strtoupper($string);
$expected = 'IJ';
$this->assertEqual($expected, $result);
$string = 'ĵ';
$result = mb_strtoupper($string);
$expected = 'Ĵ';
$this->assertEqual($expected, $result);
$string = 'ķ';
$result = mb_strtoupper($string);
$expected = 'Ķ';
$this->assertEqual($expected, $result);
$string = 'ĺ';
$result = mb_strtoupper($string);
$expected = 'Ĺ';
$this->assertEqual($expected, $result);
$string = 'ļ';
$result = mb_strtoupper($string);
$expected = 'Ļ';
$this->assertEqual($expected, $result);
$string = 'ľ';
$result = mb_strtoupper($string);
$expected = 'Ľ';
$this->assertEqual($expected, $result);
$string = 'ŀ';
$result = mb_strtoupper($string);
$expected = 'Ŀ';
$this->assertEqual($expected, $result);
$string = 'ł';
$result = mb_strtoupper($string);
$expected = 'Ł';
$this->assertEqual($expected, $result);
$string = 'ń';
$result = mb_strtoupper($string);
$expected = 'Ń';
$this->assertEqual($expected, $result);
$string = 'ņ';
$result = mb_strtoupper($string);
$expected = 'Ņ';
$this->assertEqual($expected, $result);
$string = 'ň';
$result = mb_strtoupper($string);
$expected = 'Ň';
$this->assertEqual($expected, $result);
$string = 'ŋ';
$result = mb_strtoupper($string);
$expected = 'Ŋ';
$this->assertEqual($expected, $result);
$string = 'ō';
$result = mb_strtoupper($string);
$expected = 'Ō';
$this->assertEqual($expected, $result);
$string = 'ŏ';
$result = mb_strtoupper($string);
$expected = 'Ŏ';
$this->assertEqual($expected, $result);
$string = 'ő';
$result = mb_strtoupper($string);
$expected = 'Ő';
$this->assertEqual($expected, $result);
$string = 'œ';
$result = mb_strtoupper($string);
$expected = 'Œ';
$this->assertEqual($expected, $result);
$string = 'ŕ';
$result = mb_strtoupper($string);
$expected = 'Ŕ';
$this->assertEqual($expected, $result);
$string = 'ŗ';
$result = mb_strtoupper($string);
$expected = 'Ŗ';
$this->assertEqual($expected, $result);
$string = 'ř';
$result = mb_strtoupper($string);
$expected = 'Ř';
$this->assertEqual($expected, $result);
$string = 'ś';
$result = mb_strtoupper($string);
$expected = 'Ś';
$this->assertEqual($expected, $result);
$string = 'ŝ';
$result = mb_strtoupper($string);
$expected = 'Ŝ';
$this->assertEqual($expected, $result);
$string = 'ş';
$result = mb_strtoupper($string);
$expected = 'Ş';
$this->assertEqual($expected, $result);
$string = 'š';
$result = mb_strtoupper($string);
$expected = 'Š';
$this->assertEqual($expected, $result);
$string = 'ţ';
$result = mb_strtoupper($string);
$expected = 'Ţ';
$this->assertEqual($expected, $result);
$string = 'ť';
$result = mb_strtoupper($string);
$expected = 'Ť';
$this->assertEqual($expected, $result);
$string = 'ŧ';
$result = mb_strtoupper($string);
$expected = 'Ŧ';
$this->assertEqual($expected, $result);
$string = 'ũ';
$result = mb_strtoupper($string);
$expected = 'Ũ';
$this->assertEqual($expected, $result);
$string = 'ū';
$result = mb_strtoupper($string);
$expected = 'Ū';
$this->assertEqual($expected, $result);
$string = 'ŭ';
$result = mb_strtoupper($string);
$expected = 'Ŭ';
$this->assertEqual($expected, $result);
$string = 'ů';
$result = mb_strtoupper($string);
$expected = 'Ů';
$this->assertEqual($expected, $result);
$string = 'ű';
$result = mb_strtoupper($string);
$expected = 'Ű';
$this->assertEqual($expected, $result);
$string = 'ų';
$result = mb_strtoupper($string);
$expected = 'Ų';
$this->assertEqual($expected, $result);
$string = 'ŵ';
$result = mb_strtoupper($string);
$expected = 'Ŵ';
$this->assertEqual($expected, $result);
$string = 'ŷ';
$result = mb_strtoupper($string);
$expected = 'Ŷ';
$this->assertEqual($expected, $result);
$string = 'ź';
$result = mb_strtoupper($string);
$expected = 'Ź';
$this->assertEqual($expected, $result);
$string = 'ż';
$result = mb_strtoupper($string);
$expected = 'Ż';
$this->assertEqual($expected, $result);
$string = 'ž';
$result = mb_strtoupper($string);
$expected = 'Ž';
$this->assertEqual($expected, $result);
$string = 'āăąćĉċčďđēĕėęěĝğġģĥħĩīĭįijĵķĺļľŀłńņňŋōŏőœŕŗřśŝşšţťŧũūŭůűųŵŷźżž';
$result = mb_strtoupper($string);
$expected = 'ĀĂĄĆĈĊČĎĐĒĔĖĘĚĜĞĠĢĤĦĨĪĬĮIJĴĶĹĻĽĿŁŃŅŇŊŌŎŐŒŔŖŘŚŜŞŠŢŤŦŨŪŬŮŰŲŴŶŹŻŽ';
$this->assertEqual($expected, $result);
$string = 'Ĥēĺļŏ, Ŵőřļď!';
$result = mb_strtoupper($string);
$expected = 'ĤĒĹĻŎ, ŴŐŘĻĎ!';
$this->assertEqual($expected, $result);
$string = 'ἀι';
$result = mb_strtoupper($string);
$expected = 'ἈΙ';
$this->assertEqual($expected, $result);
$string = 'ԁԃԅԇԉԋԍԏԐԒ';
$result = mb_strtoupper($string);
$expected = 'ԀԂԄԆԈԊԌԎԐԒ';
$this->assertEqual($expected, $result);
$string = 'աբգդեզէըթժիլխծկհձղճմյնշոչպջռսվտրցւփքօֆև';
$result = mb_strtoupper($string);
$expected = 'ԱԲԳԴԵԶԷԸԹԺԻԼԽԾԿՀՁՂՃՄՅՆՇՈՉՊՋՌՍՎՏՐՑՒՓՔՕՖև';
$this->assertEqual($expected, $result);
$string = 'ႠႡႢႣႤႥႦႧႨႩႪႫႬႭႮႯႰႱႲႳႴႵႶႷႸႹႺႻႼႽႾႿჀჁჂჃჄჅ';
$result = mb_strtoupper($string);
$expected = 'ႠႡႢႣႤႥႦႧႨႩႪႫႬႭႮႯႰႱႲႳႴႵႶႷႸႹႺႻႼႽႾႿჀჁჂჃჄჅ';
$this->assertEqual($expected, $result);
$string = 'ḁḃḅḇḉḋḍḏḑḓḕḗḙḛḝḟḡḣḥḧḩḫḭḯḱḳḵḷḹḻḽḿṁṃṅṇṉṋṍṏṑṓṕṗṙṛṝṟṡṣṥṧṩṫṭṯṱṳṵṷṹṻṽṿẁẃẅẇẉẋẍẏẑẓẕẖẗẘẙẚạảấầẩẫậắằẳẵặẹẻẽếềểễệỉịọỏốồổỗộớờởỡợụủứừửữựỳỵỷỹ';
$result = mb_strtoupper($string);
$expected = 'ḀḂḄḆḈḊḌḎḐḒḔḖḘḚḜḞḠḢḤḦḨḪḬḮḰḲḴḶḸḺḼḾṀṂṄṆṈṊṌṎṐṒṔṖṘṚṜṞṠṢṤṦṨṪṬṮṰṲṴṶṸṺṼṾẀẂẄẆẈẊẌẎẐẒẔẖẗẘẙẚẠẢẤẦẨẪẬẮẰẲẴẶẸẺẼẾỀỂỄỆỈỊỌỎỐỒỔỖỘỚỜỞỠỢỤỦỨỪỬỮỰỲỴỶỸ';
$this->assertEqual($expected, $result);
$string = 'ωkå';
$result = mb_strtoupper($string);
$expected = 'ΩKÅ';
$this->assertEqual($expected, $result);
/*
mb_strtoupper does not work for these strings.
$string = 'ⅰⅱⅲⅳⅴⅵⅶⅷⅸⅹⅺⅻⅼⅽⅾⅿↄ';
$result = mb_strtoupper($string);
$expected = 'ⅠⅡⅢⅣⅤⅥⅦⅧⅨⅩⅪⅫⅬⅭⅮⅯↃ';
$this->assertEqual($expected, $result);
$string = 'ⓐⓑⓒⓓⓔⓕⓖⓗⓘⓙⓚⓛⓜⓝⓞⓟⓠⓡⓢⓣⓤⓥⓦⓧⓨⓩ';
$result = mb_strtoupper($string);
$expected = 'ⒶⒷⒸⒹⒺⒻⒼⒽⒾⒿⓀⓁⓂⓃⓄⓅⓆⓇⓈⓉⓊⓋⓌⓍⓎⓏ';
$this->assertEqual($expected, $result);
$string = 'ⰰⰱⰲⰳⰴⰵⰶⰷⰸⰹⰺⰻⰼⰽⰾⰿⱀⱁⱂⱃⱄⱅⱆⱇⱈⱉⱊⱋⱌⱍⱎⱏⱐⱑⱒⱓⱔⱕⱖⱗⱘⱙⱚⱛⱜⱝⱞ';
$result = mb_strtoupper($string);
$expected = 'ⰀⰁⰂⰃⰄⰅⰆⰇⰈⰉⰊⰋⰌⰍⰎⰏⰐⰑⰒⰓⰔⰕⰖⰗⰘⰙⰚⰛⰜⰝⰞⰟⰠⰡⰢⰣⰤⰥⰦⰧⰨⰩⰪⰫⰬⰭⰮ';
$this->assertEqual($expected, $result);
$string = 'ⲁⲃⲅⲇⲉⲋⲍⲏⲑⲓⲕⲗⲙⲛⲝⲟⲡⲣⲥⲧⲩⲫⲭⲯⲱⲳⲵⲷⲹⲻⲽⲿⳁⳃⳅⳇⳉⳋⳍⳏⳑⳓⳕⳗⳙⳛⳝⳟⳡⳣ';
$result = mb_strtoupper($string);
$expected = 'ⲀⲂⲄⲆⲈⲊⲌⲎⲐⲒⲔⲖⲘⲚⲜⲞⲠⲢⲤⲦⲨⲪⲬⲮⲰⲲⲴⲶⲸⲺⲼⲾⳀⳂⳄⳆⳈⳊⳌⳎⳐⳒⳔⳖⳘⳚⳜⳞⳠⳢ';
$this->assertEqual($expected, $result);
*/
$string = 'fffiflffifflſtstﬓﬔﬕﬖﬗ';
$result = mb_strtoupper($string);
$expected = 'fffiflffifflſtstﬓﬔﬕﬖﬗ';
$this->assertEqual($expected, $result);
}
/**
* testMultibyteStrtoupper method
*
* @return void
*/
public function testMultibyteStrtoupper() {
$string = '!"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~';
$result = Multibyte::strtoupper($string);
$expected = '!"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`ABCDEFGHIJKLMNOPQRSTUVWXYZ{|}~';
$this->assertEqual($expected, $result);
$string = '!"#$%&\'()*+,-./0123456789:;<=>?@';
$result = Multibyte::strtoupper($string);
$expected = '!"#$%&\'()*+,-./0123456789:;<=>?@';
$this->assertEqual($expected, $result);
$string = 'à';
$result = Multibyte::strtoupper($string);
$expected = 'À';
$this->assertEqual($expected, $result);
$string = 'á';
$result = Multibyte::strtoupper($string);
$expected = 'Á';
$this->assertEqual($expected, $result);
$string = 'â';
$result = Multibyte::strtoupper($string);
$expected = 'Â';
$this->assertEqual($expected, $result);
$string = 'ã';
$result = Multibyte::strtoupper($string);
$expected = 'Ã';
$this->assertEqual($expected, $result);
$string = 'ä';
$result = Multibyte::strtoupper($string);
$expected = 'Ä';
$this->assertEqual($expected, $result);
$string = 'å';
$result = Multibyte::strtoupper($string);
$expected = 'Å';
$this->assertEqual($expected, $result);
$string = 'æ';
$result = Multibyte::strtoupper($string);
$expected = 'Æ';
$this->assertEqual($expected, $result);
$string = 'ç';
$result = Multibyte::strtoupper($string);
$expected = 'Ç';
$this->assertEqual($expected, $result);
$string = 'è';
$result = Multibyte::strtoupper($string);
$expected = 'È';
$this->assertEqual($expected, $result);
$string = 'é';
$result = Multibyte::strtoupper($string);
$expected = 'É';
$this->assertEqual($expected, $result);
$string = 'ê';
$result = Multibyte::strtoupper($string);
$expected = 'Ê';
$this->assertEqual($expected, $result);
$string = 'ë';
$result = Multibyte::strtoupper($string);
$expected = 'Ë';
$this->assertEqual($expected, $result);
$string = 'ì';
$result = Multibyte::strtoupper($string);
$expected = 'Ì';
$this->assertEqual($expected, $result);
$string = 'í';
$result = Multibyte::strtoupper($string);
$expected = 'Í';
$this->assertEqual($expected, $result);
$string = 'î';
$result = Multibyte::strtoupper($string);
$expected = 'Î';
$this->assertEqual($expected, $result);
$string = 'ï';
$result = Multibyte::strtoupper($string);
$expected = 'Ï';
$this->assertEqual($expected, $result);
$string = 'ð';
$result = Multibyte::strtoupper($string);
$expected = 'Ð';
$this->assertEqual($expected, $result);
$string = 'ñ';
$result = Multibyte::strtoupper($string);
$expected = 'Ñ';
$this->assertEqual($expected, $result);
$string = 'ò';
$result = Multibyte::strtoupper($string);
$expected = 'Ò';
$this->assertEqual($expected, $result);
$string = 'ó';
$result = Multibyte::strtoupper($string);
$expected = 'Ó';
$this->assertEqual($expected, $result);
$string = 'ô';
$result = Multibyte::strtoupper($string);
$expected = 'Ô';
$this->assertEqual($expected, $result);
$string = 'õ';
$result = Multibyte::strtoupper($string);
$expected = 'Õ';
$this->assertEqual($expected, $result);
$string = 'ö';
$result = Multibyte::strtoupper($string);
$expected = 'Ö';
$this->assertEqual($expected, $result);
$string = 'ø';
$result = Multibyte::strtoupper($string);
$expected = 'Ø';
$this->assertEqual($expected, $result);
$string = 'ù';
$result = Multibyte::strtoupper($string);
$expected = 'Ù';
$this->assertEqual($expected, $result);
$string = 'ú';
$result = Multibyte::strtoupper($string);
$expected = 'Ú';
$this->assertEqual($expected, $result);
$string = 'û';
$result = Multibyte::strtoupper($string);
$expected = 'Û';
$this->assertEqual($expected, $result);
$string = 'ü';
$result = Multibyte::strtoupper($string);
$expected = 'Ü';
$this->assertEqual($expected, $result);
$string = 'ý';
$result = Multibyte::strtoupper($string);
$expected = 'Ý';
$this->assertEqual($expected, $result);
$string = 'þ';
$result = Multibyte::strtoupper($string);
$expected = 'Þ';
$this->assertEqual($expected, $result);
$string = 'àáâãäåæçèéêëìíîïðñòóôõöøùúûüýþ';
$result = Multibyte::strtoupper($string);
$expected = 'ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞ';
$this->assertEqual($expected, $result);
$string = 'ā';
$result = Multibyte::strtoupper($string);
$expected = 'Ā';
$this->assertEqual($expected, $result);
$string = 'ă';
$result = Multibyte::strtoupper($string);
$expected = 'Ă';
$this->assertEqual($expected, $result);
$string = 'ą';
$result = Multibyte::strtoupper($string);
$expected = 'Ą';
$this->assertEqual($expected, $result);
$string = 'ć';
$result = Multibyte::strtoupper($string);
$expected = 'Ć';
$this->assertEqual($expected, $result);
$string = 'ĉ';
$result = Multibyte::strtoupper($string);
$expected = 'Ĉ';
$this->assertEqual($expected, $result);
$string = 'ċ';
$result = Multibyte::strtoupper($string);
$expected = 'Ċ';
$this->assertEqual($expected, $result);
$string = 'č';
$result = Multibyte::strtoupper($string);
$expected = 'Č';
$this->assertEqual($expected, $result);
$string = 'ď';
$result = Multibyte::strtoupper($string);
$expected = 'Ď';
$this->assertEqual($expected, $result);
$string = 'đ';
$result = Multibyte::strtoupper($string);
$expected = 'Đ';
$this->assertEqual($expected, $result);
$string = 'ē';
$result = Multibyte::strtoupper($string);
$expected = 'Ē';
$this->assertEqual($expected, $result);
$string = 'ĕ';
$result = Multibyte::strtoupper($string);
$expected = 'Ĕ';
$this->assertEqual($expected, $result);
$string = 'ė';
$result = Multibyte::strtoupper($string);
$expected = 'Ė';
$this->assertEqual($expected, $result);
$string = 'ę';
$result = Multibyte::strtoupper($string);
$expected = 'Ę';
$this->assertEqual($expected, $result);
$string = 'ě';
$result = Multibyte::strtoupper($string);
$expected = 'Ě';
$this->assertEqual($expected, $result);
$string = 'ĝ';
$result = Multibyte::strtoupper($string);
$expected = 'Ĝ';
$this->assertEqual($expected, $result);
$string = 'ğ';
$result = Multibyte::strtoupper($string);
$expected = 'Ğ';
$this->assertEqual($expected, $result);
$string = 'ġ';
$result = Multibyte::strtoupper($string);
$expected = 'Ġ';
$this->assertEqual($expected, $result);
$string = 'ģ';
$result = Multibyte::strtoupper($string);
$expected = 'Ģ';
$this->assertEqual($expected, $result);
$string = 'ĥ';
$result = Multibyte::strtoupper($string);
$expected = 'Ĥ';
$this->assertEqual($expected, $result);
$string = 'ħ';
$result = Multibyte::strtoupper($string);
$expected = 'Ħ';
$this->assertEqual($expected, $result);
$string = 'ĩ';
$result = Multibyte::strtoupper($string);
$expected = 'Ĩ';
$this->assertEqual($expected, $result);
$string = 'ī';
$result = Multibyte::strtoupper($string);
$expected = 'Ī';
$this->assertEqual($expected, $result);
$string = 'ĭ';
$result = Multibyte::strtoupper($string);
$expected = 'Ĭ';
$this->assertEqual($expected, $result);
$string = 'į';
$result = Multibyte::strtoupper($string);
$expected = 'Į';
$this->assertEqual($expected, $result);
$string = 'ij';
$result = Multibyte::strtoupper($string);
$expected = 'IJ';
$this->assertEqual($expected, $result);
$string = 'ĵ';
$result = Multibyte::strtoupper($string);
$expected = 'Ĵ';
$this->assertEqual($expected, $result);
$string = 'ķ';
$result = Multibyte::strtoupper($string);
$expected = 'Ķ';
$this->assertEqual($expected, $result);
$string = 'ĺ';
$result = Multibyte::strtoupper($string);
$expected = 'Ĺ';
$this->assertEqual($expected, $result);
$string = 'ļ';
$result = Multibyte::strtoupper($string);
$expected = 'Ļ';
$this->assertEqual($expected, $result);
$string = 'ľ';
$result = Multibyte::strtoupper($string);
$expected = 'Ľ';
$this->assertEqual($expected, $result);
$string = 'ŀ';
$result = Multibyte::strtoupper($string);
$expected = 'Ŀ';
$this->assertEqual($expected, $result);
$string = 'ł';
$result = Multibyte::strtoupper($string);
$expected = 'Ł';
$this->assertEqual($expected, $result);
$string = 'ń';
$result = Multibyte::strtoupper($string);
$expected = 'Ń';
$this->assertEqual($expected, $result);
$string = 'ņ';
$result = Multibyte::strtoupper($string);
$expected = 'Ņ';
$this->assertEqual($expected, $result);
$string = 'ň';
$result = Multibyte::strtoupper($string);
$expected = 'Ň';
$this->assertEqual($expected, $result);
$string = 'ŋ';
$result = Multibyte::strtoupper($string);
$expected = 'Ŋ';
$this->assertEqual($expected, $result);
$string = 'ō';
$result = Multibyte::strtoupper($string);
$expected = 'Ō';
$this->assertEqual($expected, $result);
$string = 'ŏ';
$result = Multibyte::strtoupper($string);
$expected = 'Ŏ';
$this->assertEqual($expected, $result);
$string = 'ő';
$result = Multibyte::strtoupper($string);
$expected = 'Ő';
$this->assertEqual($expected, $result);
$string = 'œ';
$result = Multibyte::strtoupper($string);
$expected = 'Œ';
$this->assertEqual($expected, $result);
$string = 'ŕ';
$result = Multibyte::strtoupper($string);
$expected = 'Ŕ';
$this->assertEqual($expected, $result);
$string = 'ŗ';
$result = Multibyte::strtoupper($string);
$expected = 'Ŗ';
$this->assertEqual($expected, $result);
$string = 'ř';
$result = Multibyte::strtoupper($string);
$expected = 'Ř';
$this->assertEqual($expected, $result);
$string = 'ś';
$result = Multibyte::strtoupper($string);
$expected = 'Ś';
$this->assertEqual($expected, $result);
$string = 'ŝ';
$result = Multibyte::strtoupper($string);
$expected = 'Ŝ';
$this->assertEqual($expected, $result);
$string = 'ş';
$result = Multibyte::strtoupper($string);
$expected = 'Ş';
$this->assertEqual($expected, $result);
$string = 'š';
$result = Multibyte::strtoupper($string);
$expected = 'Š';
$this->assertEqual($expected, $result);
$string = 'ţ';
$result = Multibyte::strtoupper($string);
$expected = 'Ţ';
$this->assertEqual($expected, $result);
$string = 'ť';
$result = Multibyte::strtoupper($string);
$expected = 'Ť';
$this->assertEqual($expected, $result);
$string = 'ŧ';
$result = Multibyte::strtoupper($string);
$expected = 'Ŧ';
$this->assertEqual($expected, $result);
$string = 'ũ';
$result = Multibyte::strtoupper($string);
$expected = 'Ũ';
$this->assertEqual($expected, $result);
$string = 'ū';
$result = Multibyte::strtoupper($string);
$expected = 'Ū';
$this->assertEqual($expected, $result);
$string = 'ŭ';
$result = Multibyte::strtoupper($string);
$expected = 'Ŭ';
$this->assertEqual($expected, $result);
$string = 'ů';
$result = Multibyte::strtoupper($string);
$expected = 'Ů';
$this->assertEqual($expected, $result);
$string = 'ű';
$result = Multibyte::strtoupper($string);
$expected = 'Ű';
$this->assertEqual($expected, $result);
$string = 'ų';
$result = Multibyte::strtoupper($string);
$expected = 'Ų';
$this->assertEqual($expected, $result);
$string = 'ŵ';
$result = Multibyte::strtoupper($string);
$expected = 'Ŵ';
$this->assertEqual($expected, $result);
$string = 'ŷ';
$result = Multibyte::strtoupper($string);
$expected = 'Ŷ';
$this->assertEqual($expected, $result);
$string = 'ź';
$result = Multibyte::strtoupper($string);
$expected = 'Ź';
$this->assertEqual($expected, $result);
$string = 'ż';
$result = Multibyte::strtoupper($string);
$expected = 'Ż';
$this->assertEqual($expected, $result);
$string = 'ž';
$result = Multibyte::strtoupper($string);
$expected = 'Ž';
$this->assertEqual($expected, $result);
$string = 'āăąćĉċčďđēĕėęěĝğġģĥħĩīĭįijĵķĺļľŀłńņňŋōŏőœŕŗřśŝşšţťŧũūŭůűųŵŷźżž';
$result = Multibyte::strtoupper($string);
$expected = 'ĀĂĄĆĈĊČĎĐĒĔĖĘĚĜĞĠĢĤĦĨĪĬĮIJĴĶĹĻĽĿŁŃŅŇŊŌŎŐŒŔŖŘŚŜŞŠŢŤŦŨŪŬŮŰŲŴŶŹŻŽ';
$this->assertEqual($expected, $result);
$string = 'Ĥēĺļŏ, Ŵőřļď!';
$result = Multibyte::strtoupper($string);
$expected = 'ĤĒĹĻŎ, ŴŐŘĻĎ!';
$this->assertEqual($expected, $result);
$string = 'ἀι';
$result = mb_strtoupper($string);
$expected = 'ἈΙ';
$this->assertEqual($expected, $result);
$string = 'ἀι';
$result = Multibyte::strtoupper($string);
$expected = 'ἈΙ';
$this->assertEqual($expected, $result);
$string = 'ԁԃԅԇԉԋԍԏԐԒ';
$result = Multibyte::strtoupper($string);
$expected = 'ԀԂԄԆԈԊԌԎԐԒ';
$this->assertEqual($expected, $result);
$string = 'աբգդեզէըթժիլխծկհձղճմյնշոչպջռսվտրցւփքօֆև';
$result = Multibyte::strtoupper($string);
$expected = 'ԱԲԳԴԵԶԷԸԹԺԻԼԽԾԿՀՁՂՃՄՅՆՇՈՉՊՋՌՍՎՏՐՑՒՓՔՕՖև';
$this->assertEqual($expected, $result);
$string = 'ႠႡႢႣႤႥႦႧႨႩႪႫႬႭႮႯႰႱႲႳႴႵႶႷႸႹႺႻႼႽႾႿჀჁჂჃჄჅ';
$result = Multibyte::strtoupper($string);
$expected = 'ႠႡႢႣႤႥႦႧႨႩႪႫႬႭႮႯႰႱႲႳႴႵႶႷႸႹႺႻႼႽႾႿჀჁჂჃჄჅ';
$this->assertEqual($expected, $result);
$string = 'ḁḃḅḇḉḋḍḏḑḓḕḗḙḛḝḟḡḣḥḧḩḫḭḯḱḳḵḷḹḻḽḿṁṃṅṇṉṋṍṏṑṓṕṗṙṛṝṟṡṣṥṧṩṫṭṯṱṳṵṷṹṻṽṿẁẃẅẇẉẋẍẏẑẓẕẖẗẘẙẚạảấầẩẫậắằẳẵặẹẻẽếềểễệỉịọỏốồổỗộớờởỡợụủứừửữựỳỵỷỹ';
$result = Multibyte::strtoupper($string);
$expected = 'ḀḂḄḆḈḊḌḎḐḒḔḖḘḚḜḞḠḢḤḦḨḪḬḮḰḲḴḶḸḺḼḾṀṂṄṆṈṊṌṎṐṒṔṖṘṚṜṞṠṢṤṦṨṪṬṮṰṲṴṶṸṺṼṾẀẂẄẆẈẊẌẎẐẒẔẖẗẘẙẚẠẢẤẦẨẪẬẮẰẲẴẶẸẺẼẾỀỂỄỆỈỊỌỎỐỒỔỖỘỚỜỞỠỢỤỦỨỪỬỮỰỲỴỶỸ';
$this->assertEqual($expected, $result);
$string = 'ωkåⅎ';
$result = Multibyte::strtoupper($string);
$expected = 'ΩKÅℲ';
$this->assertEqual($expected, $result);
$string = 'ωkå';
$result = Multibyte::strtoupper($string);
$expected = 'ΩKÅ';
$this->assertEqual($expected, $result);
$string = 'ⅰⅱⅲⅳⅴⅵⅶⅷⅸⅹⅺⅻⅼⅽⅾⅿↄ';
$result = Multibyte::strtoupper($string);
$expected = 'ⅠⅡⅢⅣⅤⅥⅦⅧⅨⅩⅪⅫⅬⅭⅮⅯↃ';
$this->assertEqual($expected, $result);
$string = 'ⓐⓑⓒⓓⓔⓕⓖⓗⓘⓙⓚⓛⓜⓝⓞⓟⓠⓡⓢⓣⓤⓥⓦⓧⓨⓩ';
$result = Multibyte::strtoupper($string);
$expected = 'ⒶⒷⒸⒹⒺⒻⒼⒽⒾⒿⓀⓁⓂⓃⓄⓅⓆⓇⓈⓉⓊⓋⓌⓍⓎⓏ';
$this->assertEqual($expected, $result);
$string = 'ⰰⰱⰲⰳⰴⰵⰶⰷⰸⰹⰺⰻⰼⰽⰾⰿⱀⱁⱂⱃⱄⱅⱆⱇⱈⱉⱊⱋⱌⱍⱎⱏⱐⱑⱒⱓⱔⱕⱖⱗⱘⱙⱚⱛⱜⱝⱞ';
$result = Multibyte::strtoupper($string);
$expected = 'ⰀⰁⰂⰃⰄⰅⰆⰇⰈⰉⰊⰋⰌⰍⰎⰏⰐⰑⰒⰓⰔⰕⰖⰗⰘⰙⰚⰛⰜⰝⰞⰟⰠⰡⰢⰣⰤⰥⰦⰧⰨⰩⰪⰫⰬⰭⰮ';
$this->assertEqual($expected, $result);
$string = 'ⲁⲃⲅⲇⲉⲋⲍⲏⲑⲓⲕⲗⲙⲛⲝⲟⲡⲣⲥⲧⲩⲫⲭⲯⲱⲳⲵⲷⲹⲻⲽⲿⳁⳃⳅⳇⳉⳋⳍⳏⳑⳓⳕⳗⳙⳛⳝⳟⳡⳣ';
$result = Multibyte::strtoupper($string);
$expected = 'ⲀⲂⲄⲆⲈⲊⲌⲎⲐⲒⲔⲖⲘⲚⲜⲞⲠⲢⲤⲦⲨⲪⲬⲮⲰⲲⲴⲶⲸⲺⲼⲾⳀⳂⳄⳆⳈⳊⳌⳎⳐⳒⳔⳖⳘⳚⳜⳞⳠⳢ';
$this->assertEqual($expected, $result);
$string = 'fffiflffifflſtstﬓﬔﬕﬖﬗ';
$result = Multibyte::strtoupper($string);
$expected = 'fffiflffifflſtstﬓﬔﬕﬖﬗ';
$this->assertEqual($expected, $result);
}
/**
* testUsingMbSubstrCount method
*
* @return void
*/
public function testUsingMbSubstrCount() {
$string = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
$find = 'F';
$result = mb_substr_count($string, $find);
$expected = 1;
$this->assertEqual($expected, $result);
$string = 'ABCDEFGHIJKLMNOPQFRSFTUVWXYZ0F12345F6789';
$find = 'F';
$result = mb_substr_count($string, $find);
$expected = 5;
$this->assertEqual($expected, $result);
$string = 'ÀÁÂÃÄÅÆÇÈÉÅÊËÌÍÎÏÐÑÒÓÔÅÕÖØÅÙÚÛÅÜÝÞ';
$find = 'Å';
$result = mb_substr_count($string, $find);
$expected = 5;
$this->assertEqual($expected, $result);
$string = 'ÀÁÙÚÂÃÄÅÆÇÈÙÚÉÊËÌÍÎÏÐÑÒÓÔÕÖØÅÙÚÛÜÝÞÙÚ';
$find = 'ÙÚ';
$result = mb_substr_count($string, $find);
$expected = 4;
$this->assertEqual($expected, $result);
$string = 'ÀÁÂÃÄÅÆÇÈÉÊÅËÌÍÎÏÐÑÒÓÔÕÅÖØÅÙÚÅÛÜÅÝÞÅ';
$find = 'Å';
$result = mb_substr_count($string, $find);
$expected = 7;
$this->assertEqual($expected, $result);
$string = 'ĊĀĂĄĆĈĊČĎĐĒĔĖĊĘĚĜĞĠĢĤĦĨĪĬĮĊIJĴĶĹĻĽĿŁŃŅŇŊŌĊŎŐŒŔŖŘŚŜŞŠŢĊŤŦŨŪŬŮŰĊŲŴŶŹŻŽ';
$find = 'Ċ';
$result = mb_substr_count($string, $find);
$expected = 7;
$this->assertEqual($expected, $result);
$string = 'ĀĂĄĆĈĊČĎĐĒĔĖĘĚĜĊĞĠĢĤĦĨĪĬĮIJĴĶĹĻĽĿŁĊŃŅĊŇŊŌŎŐŒŔŖĊŘŚŜŞŠŢŤŦŨŪŬŮŰŲŴŶŹŻŽ';
$find = 'Ċ';
$result = mb_substr_count($string, $find);
$expected = 5;
$this->assertEqual($expected, $result);
$string = '!"#$%&\'()*+,-./012F34567F89:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghiFjklmnopqFrstuvwFxyz{|}~';
$find = 'F';
$result = mb_substr_count($string, $find);
$expected = 6;
$this->assertEqual($expected, $result);
$string = '¡¢£¤¥µ¦§¨©ª«¬®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁµÂõÄÅÆÇµÈ';
$find = 'µ';
$result = mb_substr_count($string, $find);
$expected = 5;
$this->assertEqual($expected, $result);
$string = 'ÉÊËÌÍÎÏÐÑÒÓÔÕÖרÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôÕÖõö÷øùúûüýþÿĀāĂ㥹ĆćĈĉÕÖĊċČčĎďĐđĒēĔĕĖėĘęĚěĜĝÕÖĞğĠġĢģĤĥĦÕÖħĨĩĪīĬ';
$find = 'ÕÖ';
$result = mb_substr_count($string, $find);
$expected = 5;
$this->assertEqual($expected, $result);
$string = 'ĭĮįİıIJijĴĵĶķĸĹĺĻļĽľĿŀŁłŃńŅņŇňʼnŊŋŌōĵĶķĸĹŎŏŐőŒœŔŕŖŗŘřŚśŜŝŞşŠšĵĶķĸĹŢţŤťŦŧŨũŪūŬŭŮůŰűŲųĵĶķĸĹŴŵŶŷŸŹźŻżŽžſƀƁƂƃƄƅƆƇƈƉƊƋƌƍƎƏƐ';
$find = 'ĵĶķĸĹ';
$result = mb_substr_count($string, $find);
$expected = 4;
$this->assertEqual($expected, $result);
$string = 'ƑƒƓƔƕƖƸƗƘƙƚƛƜƝƞƟƠơƢƣƤƥƦƧƨƩƪƫƬƭƮƯưƱƲƳƴƵƶƷƸƹƺƻƼƽƾƿǀǁǂǃDŽDždžLJLjljNJƸNjnjǍǎǏǐǑǒǓƸǔǕǖǗǘǙǚƸǛǜǝǞǟǠǡǢǣǤǥǦǧǨǩǪǫǬǭǮǯǰDZDzdzǴ';
$find = 'Ƹ';
$result = mb_substr_count($string, $find);
$expected = 5;
$this->assertEqual($expected, $result);
$string = 'ƑƒƓƔƕƖƗƘƙƚƛƜƝƞƟƹƠơƢƣƤƥƦƧƨƩƹƪƫƬƭƮƯưƱƲƳƴƹƵƶƷƸƹƺƻƼƽƾƿǀǁǂƹǃDŽDždžLJLjljNJNjnjǍǎǏǐǑǒǓǔǕǖǗǘǙǚǛǜǝǞǟǠǡǢǣǤǥǦǧǨǩǪǫǬǭǮǯǰDZDzdzǴ';
$find = 'ƹ';
$result = mb_substr_count($string, $find);
$expected = 5;
$this->assertEqual($expected, $result);
$string = 'əɚɛɜɝɞʀɟɠɡɢɣɤɥɦɧɨɩɪɫɬɭɮɯɰɱɲɳɴɵɶɷɸɹɺɻɼɽɾɿʀʁʂʃʄʅʆʀʇʈʉʊʋʌʍʎʏʐʑʒʓʔʕʖʗʘʙʚʛʜʝʞʟʠʡʢʣʤʥʦʧʀʨʩʪʫʬʭʮʯʰʱʲʳʴʵʶʷʸʹʺʀʻʼ';
$find = 'ʀ';
$result = mb_substr_count($string, $find);
$expected = 5;
$this->assertEqual($expected, $result);
$string = 'ЀЁЂЃЄЅІЇЈЉЊЋЌЍЇЎЏАБВГДЕЖЗИЙКЛ';
$find = 'Ї';
$result = mb_substr_count($string, $find);
$expected = 2;
$this->assertEqual($expected, $result);
$string = 'МНОПРСРТУФХЦЧШЩЪЫЬРЭЮЯабРвгдежзийклРмнопрстуфхцчшщъыь';
$find = 'Р';
$result = mb_substr_count($string, $find);
$expected = 5;
$this->assertEqual($expected, $result);
$string = 'МНОПРСрТУФХЦЧШЩЪЫрЬЭЮЯабвгдежзийклмнопррстуфхцчшщъыь';
$find = 'р';
$result = mb_substr_count($string, $find);
$expected = 4;
$this->assertEqual($expected, $result);
$string = 'فنقكلنمنهونىينًٌٍَُ';
$find = 'ن';
$result = mb_substr_count($string, $find);
$expected = 5;
$this->assertEqual($expected, $result);
$string = '✰✱✲✳✿✴✵✶✷✸✿✹✺✻✼✽✾✿❀❁❂❃❄❅❆✿❇❈❉❊❋❌❍❎❏❐❑❒❓❔❕❖❗❘❙❚❛❜❝❞';
$find = '✿';
$result = mb_substr_count($string, $find);
$expected = 4;
$this->assertEqual($expected, $result);
$string = '⺀⺁⺂⺃⺄⺅⺆⺇⺈⺉⺐⺊⺋⺌⺍⺎⺏⺐⺑⺒⺓⺔⺕⺖⺗⺘⺙⺛⺜⺝⺞⺟⺠⺡⺢⺣⺤⺥⺦⺧⺨⺐⺩⺪⺫⺬⺭⺮⺯⺰⺱⺲⺳⺴⺵⺶⺷⺸⺹⺺⺻⺼⺽⺾⺿⻀⻁⻂⻃⻄⻅⻆⻇⻈⻉⺐⻊⻋⻌⻍⻎⻏⻐⻑⻒⻓⻔⻕⻖⻗⻘⻙⻚⻛⻜⻝⻞⻟⻠';
$find = '⺐';
$result = mb_substr_count($string, $find);
$expected = 4;
$this->assertEqual($expected, $result);
$string = '⽅⽆⽇⽈⽉⽊⽋⽌⽍⽎⽏⽐⽑⽒⽓⽔⽕⽖⽤⽗⽘⽙⽚⽛⽜⽝⽞⽟⽠⽡⽢⽣⽤⽥⽦⽧⽨⽩⽪⽫⽬⽭⽮⽯⽰⽱⽲⽳⽴⽵⽤⽶⽷⽸⽹⽺⽻⽼⽽⽾⽿';
$find = '⽤';
$result = mb_substr_count($string, $find);
$expected = 3;
$this->assertEqual($expected, $result);
$string = '눡눢눣눤눥눦눺눻눼눧눨눩눪눫눬눭눮눯눰눱눲눳눴눵눶눷눸눹눺눻눼눽눾눿뉀뉁뉂뉃뉄뉅뉆뉇뉈뉉뉊뉋뉌뉍뉎뉏뉐뉑뉒뉓뉔뉕눺눻눼뉖뉗뉘뉙뉚뉛뉜뉝눺눻눼뉞뉟뉠뉡뉢뉣뉤뉥뉦뉧뉨뉩뉪뉫뉬뉭뉮뉯뉰뉱뉲뉳뉴뉵뉶뉷뉸뉹뉺뉻뉼뉽뉾뉿늀늁늂늃늄';
$find = '눺눻눼';
$result = mb_substr_count($string, $find);
$expected = 4;
$this->assertEqual($expected, $result);
$string = 'ﺞﺟﺠﺡﹰﹱﹲﹳﹴﹶﹷﹸﹹﹺﹻﹼﹽﹾﹿﺀﺁﺂﺃﺄﺅﺞﺟﺠﺡﺆﺇﺞﺟﺠﺡﺈﺉﺊﺋﺌﺍﺎﺏﺐﺑﺒﺓﺔﺕﺖﺗﺘﺙﺚﺛﺜﺝﺞﺟﺠﺡﺢﺣﺤﺥﺦﺧﺨﺩﺪﺫﺬﺭﺮﺯﺰ';
$find = 'ﺞﺟﺠﺡ';
$result = mb_substr_count($string, $find);
$expected = 4;
$this->assertEqual($expected, $result);
$string = 'ﺱﺲﺳﺴﺵﺶﺷﺸﺹﺺﺻﺼﻞﺽﺾﺿﻀﻁﻂﻃﻄﻅﻆﻇﻈﻉﻊﻋﻌﻍﻎﻏﻐﻑﻒﻓﻔﻞﻕﻖﻗﻘﻙﻚﻛﻜﻝﻞﻟﻠﻡﻢﻣﻤﻥﻦﻧﻨﻩﻪﻫﻬﻭﻮﻯﻰﻱﻲﻳﻴﻵﻶﻷﻞﻸﻹﻺﻞﻻﻼ';
$find = 'ﻞ';
$result = mb_substr_count($string, $find);
$expected = 5;
$this->assertEqual($expected, $result);
$string = 'abcdkefghijklmnopqrstuvwxkyz';
$find = 'k';
$result = mb_substr_count($string, $find);
$expected = 3;
$this->assertEqual($expected, $result);
$string = 'abklmcdefghijklmnopqrstuvklmwxyz';
$find = 'klm';
$result = mb_substr_count($string, $find);
$expected = 3;
$this->assertEqual($expected, $result);
$string = 'abcdppefghijklmnoppqrstuvwxyz';
$find = 'ppe';
$result = mb_substr_count($string, $find);
$expected = 1;
$this->assertEqual($expected, $result);
$string = '。「」、・ヲァィゥェォャュョッーアイウエオカキク';
$find = 'ア';
$result = mb_substr_count($string, $find);
$expected = 1;
$this->assertEqual($expected, $result);
$string = 'ケコサシスセソタチツテトナニヌネノハヒフヘホマミムメモヤユヨラリルレロワン゙';
$find = 'ハ';
$result = mb_substr_count($string, $find);
$expected = 1;
$this->assertEqual($expected, $result);
$string = 'Ĥēĺļŏ, Ŵőřļď!';
$find = 'ő';
$result = mb_substr_count($string, $find);
$expected = 1;
$this->assertEqual($expected, $result);
$string = 'Ĥēĺļŏ, Ŵőřļď!';
$find = 'ĺļ';
$result = mb_substr_count($string, $find);
$expected = 1;
$this->assertEqual($expected, $result);
$string = 'Hello, World!';
$find = 'o';
$result = mb_substr_count($string, $find);
$expected = 2;
$this->assertEqual($expected, $result);
$string = 'Hello, World!';
$find = 'rl';
$result = mb_substr_count($string, $find);
$expected = 1;
$this->assertEqual($expected, $result);
$string = 'čini';
$find = 'n';
$result = mb_substr_count($string, $find);
$expected = 1;
$this->assertEqual($expected, $result);
$string = 'ničiničiini';
$find = 'n';
$result = mb_substr_count($string, $find);
$expected = 3;
$this->assertEqual($expected, $result);
$string = 'moći';
$find = 'ć';
$result = mb_substr_count($string, $find);
$expected = 1;
$this->assertEqual($expected, $result);
$string = 'moćimoćimoćmćioći';
$find = 'ći';
$result = mb_substr_count($string, $find);
$expected = 4;
$this->assertEqual($expected, $result);
$string = 'državni';
$find = 'ž';
$result = mb_substr_count($string, $find);
$expected = 1;
$this->assertEqual($expected, $result);
$string = '把百度设为首页';
$find = '设';
$result = mb_substr_count($string, $find);
$expected = 1;
$this->assertEqual($expected, $result);
$string = '一二三周永龍';
$find = '周';
$result = mb_substr_count($string, $find);
$expected = 1;
$this->assertEqual($expected, $result);
$string = 'Ĥēĺļŏ, Ŵőřļď!';
$find = 'H';
$result = mb_substr_count($string, $find);
$expected = 0;
$this->assertEqual($expected, $result);
}
/**
* testMultibyteSubstrCount method
*
* @return void
*/
public function testMultibyteSubstrCount() {
$string = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
$find = 'F';
$result = Multibyte::substrCount($string, $find);
$expected = 1;
$this->assertEqual($expected, $result);
$string = 'ABCDEFGHIJKLMNOPQFRSFTUVWXYZ0F12345F6789';
$find = 'F';
$result = Multibyte::substrCount($string, $find);
$expected = 5;
$this->assertEqual($expected, $result);
$string = 'ÀÁÂÃÄÅÆÇÈÉÅÊËÌÍÎÏÐÑÒÓÔÅÕÖØÅÙÚÛÅÜÝÞ';
$find = 'Å';
$result = Multibyte::substrCount($string, $find);
$expected = 5;
$this->assertEqual($expected, $result);
$string = 'ÀÁÙÚÂÃÄÅÆÇÈÙÚÉÊËÌÍÎÏÐÑÒÓÔÕÖØÅÙÚÛÜÝÞÙÚ';
$find = 'ÙÚ';
$result = Multibyte::substrCount($string, $find);
$expected = 4;
$this->assertEqual($expected, $result);
$string = 'ÀÁÂÃÄÅÆÇÈÉÊÅËÌÍÎÏÐÑÒÓÔÕÅÖØÅÙÚÅÛÜÅÝÞÅ';
$find = 'Å';
$result = Multibyte::substrCount($string, $find);
$expected = 7;
$this->assertEqual($expected, $result);
$string = 'ĊĀĂĄĆĈĊČĎĐĒĔĖĊĘĚĜĞĠĢĤĦĨĪĬĮĊIJĴĶĹĻĽĿŁŃŅŇŊŌĊŎŐŒŔŖŘŚŜŞŠŢĊŤŦŨŪŬŮŰĊŲŴŶŹŻŽ';
$find = 'Ċ';
$result = Multibyte::substrCount($string, $find);
$expected = 7;
$this->assertEqual($expected, $result);
$string = 'ĀĂĄĆĈĊČĎĐĒĔĖĘĚĜĊĞĠĢĤĦĨĪĬĮIJĴĶĹĻĽĿŁĊŃŅĊŇŊŌŎŐŒŔŖĊŘŚŜŞŠŢŤŦŨŪŬŮŰŲŴŶŹŻŽ';
$find = 'Ċ';
$result = Multibyte::substrCount($string, $find);
$expected = 5;
$this->assertEqual($expected, $result);
$string = '!"#$%&\'()*+,-./012F34567F89:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghiFjklmnopqFrstuvwFxyz{|}~';
$find = 'F';
$result = Multibyte::substrCount($string, $find);
$expected = 6;
$this->assertEqual($expected, $result);
$string = '¡¢£¤¥µ¦§¨©ª«¬®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁµÂõÄÅÆÇµÈ';
$find = 'µ';
$result = Multibyte::substrCount($string, $find);
$expected = 5;
$this->assertEqual($expected, $result);
$string = 'ÉÊËÌÍÎÏÐÑÒÓÔÕÖרÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôÕÖõö÷øùúûüýþÿĀāĂ㥹ĆćĈĉÕÖĊċČčĎďĐđĒēĔĕĖėĘęĚěĜĝÕÖĞğĠġĢģĤĥĦÕÖħĨĩĪīĬ';
$find = 'ÕÖ';
$result = Multibyte::substrCount($string, $find);
$expected = 5;
$this->assertEqual($expected, $result);
$string = 'ĭĮįİıIJijĴĵĶķĸĹĺĻļĽľĿŀŁłŃńŅņŇňʼnŊŋŌōĵĶķĸĹŎŏŐőŒœŔŕŖŗŘřŚśŜŝŞşŠšĵĶķĸĹŢţŤťŦŧŨũŪūŬŭŮůŰűŲųĵĶķĸĹŴŵŶŷŸŹźŻżŽžſƀƁƂƃƄƅƆƇƈƉƊƋƌƍƎƏƐ';
$find = 'ĵĶķĸĹ';
$result = Multibyte::substrCount($string, $find);
$expected = 4;
$this->assertEqual($expected, $result);
$string = 'ƑƒƓƔƕƖƸƗƘƙƚƛƜƝƞƟƠơƢƣƤƥƦƧƨƩƪƫƬƭƮƯưƱƲƳƴƵƶƷƸƹƺƻƼƽƾƿǀǁǂǃDŽDždžLJLjljNJƸNjnjǍǎǏǐǑǒǓƸǔǕǖǗǘǙǚƸǛǜǝǞǟǠǡǢǣǤǥǦǧǨǩǪǫǬǭǮǯǰDZDzdzǴ';
$find = 'Ƹ';
$result = Multibyte::substrCount($string, $find);
$expected = 5;
$this->assertEqual($expected, $result);
$string = 'ƑƒƓƔƕƖƗƘƙƚƛƜƝƞƟƹƠơƢƣƤƥƦƧƨƩƹƪƫƬƭƮƯưƱƲƳƴƹƵƶƷƸƹƺƻƼƽƾƿǀǁǂƹǃDŽDždžLJLjljNJNjnjǍǎǏǐǑǒǓǔǕǖǗǘǙǚǛǜǝǞǟǠǡǢǣǤǥǦǧǨǩǪǫǬǭǮǯǰDZDzdzǴ';
$find = 'ƹ';
$result = Multibyte::substrCount($string, $find);
$expected = 5;
$this->assertEqual($expected, $result);
$string = 'əɚɛɜɝɞʀɟɠɡɢɣɤɥɦɧɨɩɪɫɬɭɮɯɰɱɲɳɴɵɶɷɸɹɺɻɼɽɾɿʀʁʂʃʄʅʆʀʇʈʉʊʋʌʍʎʏʐʑʒʓʔʕʖʗʘʙʚʛʜʝʞʟʠʡʢʣʤʥʦʧʀʨʩʪʫʬʭʮʯʰʱʲʳʴʵʶʷʸʹʺʀʻʼ';
$find = 'ʀ';
$result = Multibyte::substrCount($string, $find);
$expected = 5;
$this->assertEqual($expected, $result);
$string = 'ЀЁЂЃЄЅІЇЈЉЊЋЌЍЇЎЏАБВГДЕЖЗИЙКЛ';
$find = 'Ї';
$result = Multibyte::substrCount($string, $find);
$expected = 2;
$this->assertEqual($expected, $result);
$string = 'МНОПРСРТУФХЦЧШЩЪЫЬРЭЮЯабРвгдежзийклРмнопрстуфхцчшщъыь';
$find = 'Р';
$result = Multibyte::substrCount($string, $find);
$expected = 5;
$this->assertEqual($expected, $result);
$string = 'МНОПРСрТУФХЦЧШЩЪЫрЬЭЮЯабвгдежзийклмнопррстуфхцчшщъыь';
$find = 'р';
$result = Multibyte::substrCount($string, $find);
$expected = 4;
$this->assertEqual($expected, $result);
$string = 'فنقكلنمنهونىينًٌٍَُ';
$find = 'ن';
$result = Multibyte::substrCount($string, $find);
$expected = 5;
$this->assertEqual($expected, $result);
$string = '✰✱✲✳✿✴✵✶✷✸✿✹✺✻✼✽✾✿❀❁❂❃❄❅❆✿❇❈❉❊❋❌❍❎❏❐❑❒❓❔❕❖❗❘❙❚❛❜❝❞';
$find = '✿';
$result = Multibyte::substrCount($string, $find);
$expected = 4;
$this->assertEqual($expected, $result);
$string = '⺀⺁⺂⺃⺄⺅⺆⺇⺈⺉⺐⺊⺋⺌⺍⺎⺏⺐⺑⺒⺓⺔⺕⺖⺗⺘⺙⺛⺜⺝⺞⺟⺠⺡⺢⺣⺤⺥⺦⺧⺨⺐⺩⺪⺫⺬⺭⺮⺯⺰⺱⺲⺳⺴⺵⺶⺷⺸⺹⺺⺻⺼⺽⺾⺿⻀⻁⻂⻃⻄⻅⻆⻇⻈⻉⺐⻊⻋⻌⻍⻎⻏⻐⻑⻒⻓⻔⻕⻖⻗⻘⻙⻚⻛⻜⻝⻞⻟⻠';
$find = '⺐';
$result = Multibyte::substrCount($string, $find);
$expected = 4;
$this->assertEqual($expected, $result);
$string = '⽅⽆⽇⽈⽉⽊⽋⽌⽍⽎⽏⽐⽑⽒⽓⽔⽕⽖⽤⽗⽘⽙⽚⽛⽜⽝⽞⽟⽠⽡⽢⽣⽤⽥⽦⽧⽨⽩⽪⽫⽬⽭⽮⽯⽰⽱⽲⽳⽴⽵⽤⽶⽷⽸⽹⽺⽻⽼⽽⽾⽿';
$find = '⽤';
$result = Multibyte::substrCount($string, $find);
$expected = 3;
$this->assertEqual($expected, $result);
$string = '눡눢눣눤눥눦눺눻눼눧눨눩눪눫눬눭눮눯눰눱눲눳눴눵눶눷눸눹눺눻눼눽눾눿뉀뉁뉂뉃뉄뉅뉆뉇뉈뉉뉊뉋뉌뉍뉎뉏뉐뉑뉒뉓뉔뉕눺눻눼뉖뉗뉘뉙뉚뉛뉜뉝눺눻눼뉞뉟뉠뉡뉢뉣뉤뉥뉦뉧뉨뉩뉪뉫뉬뉭뉮뉯뉰뉱뉲뉳뉴뉵뉶뉷뉸뉹뉺뉻뉼뉽뉾뉿늀늁늂늃늄';
$find = '눺눻눼';
$result = Multibyte::substrCount($string, $find);
$expected = 4;
$this->assertEqual($expected, $result);
$string = 'ﺞﺟﺠﺡﹰﹱﹲﹳﹴﹶﹷﹸﹹﹺﹻﹼﹽﹾﹿﺀﺁﺂﺃﺄﺅﺞﺟﺠﺡﺆﺇﺞﺟﺠﺡﺈﺉﺊﺋﺌﺍﺎﺏﺐﺑﺒﺓﺔﺕﺖﺗﺘﺙﺚﺛﺜﺝﺞﺟﺠﺡﺢﺣﺤﺥﺦﺧﺨﺩﺪﺫﺬﺭﺮﺯﺰ';
$find = 'ﺞﺟﺠﺡ';
$result = Multibyte::substrCount($string, $find);
$expected = 4;
$this->assertEqual($expected, $result);
$string = 'ﺱﺲﺳﺴﺵﺶﺷﺸﺹﺺﺻﺼﻞﺽﺾﺿﻀﻁﻂﻃﻄﻅﻆﻇﻈﻉﻊﻋﻌﻍﻎﻏﻐﻑﻒﻓﻔﻞﻕﻖﻗﻘﻙﻚﻛﻜﻝﻞﻟﻠﻡﻢﻣﻤﻥﻦﻧﻨﻩﻪﻫﻬﻭﻮﻯﻰﻱﻲﻳﻴﻵﻶﻷﻞﻸﻹﻺﻞﻻﻼ';
$find = 'ﻞ';
$result = Multibyte::substrCount($string, $find);
$expected = 5;
$this->assertEqual($expected, $result);
$string = 'abcdkefghijklmnopqrstuvwxkyz';
$find = 'k';
$result = Multibyte::substrCount($string, $find);
$expected = 3;
$this->assertEqual($expected, $result);
$string = 'abklmcdefghijklmnopqrstuvklmwxyz';
$find = 'klm';
$result = Multibyte::substrCount($string, $find);
$expected = 3;
$this->assertEqual($expected, $result);
$string = 'abcdppefghijklmnoppqrstuvwxyz';
$find = 'ppe';
$result = Multibyte::substrCount($string, $find);
$expected = 1;
$this->assertEqual($expected, $result);
$string = '。「」、・ヲァィゥェォャュョッーアイウエオカキク';
$find = 'ア';
$result = Multibyte::substrCount($string, $find);
$expected = 1;
$this->assertEqual($expected, $result);
$string = 'ケコサシスセソタチツテトナニヌネノハヒフヘホマミムメモヤユヨラリルレロワン゙';
$find = 'ハ';
$result = Multibyte::substrCount($string, $find);
$expected = 1;
$this->assertEqual($expected, $result);
$string = 'Ĥēĺļŏ, Ŵőřļď!';
$find = 'ő';
$result = Multibyte::substrCount($string, $find);
$expected = 1;
$this->assertEqual($expected, $result);
$string = 'Ĥēĺļŏ, Ŵőřļď!';
$find = 'ĺļ';
$result = Multibyte::substrCount($string, $find);
$expected = 1;
$this->assertEqual($expected, $result);
$string = 'Hello, World!';
$find = 'o';
$result = Multibyte::substrCount($string, $find);
$expected = 2;
$this->assertEqual($expected, $result);
$string = 'Hello, World!';
$find = 'rl';
$result = Multibyte::substrCount($string, $find);
$expected = 1;
$this->assertEqual($expected, $result);
$string = 'čini';
$find = 'n';
$result = Multibyte::substrCount($string, $find);
$expected = 1;
$this->assertEqual($expected, $result);
$string = 'ničiničiini';
$find = 'n';
$result = Multibyte::substrCount($string, $find);
$expected = 3;
$this->assertEqual($expected, $result);
$string = 'moći';
$find = 'ć';
$result = Multibyte::substrCount($string, $find);
$expected = 1;
$this->assertEqual($expected, $result);
$string = 'moćimoćimoćmćioći';
$find = 'ći';
$result = Multibyte::substrCount($string, $find);
$expected = 4;
$this->assertEqual($expected, $result);
$string = 'državni';
$find = 'ž';
$result = Multibyte::substrCount($string, $find);
$expected = 1;
$this->assertEqual($expected, $result);
$string = '把百度设为首页';
$find = '设';
$result = Multibyte::substrCount($string, $find);
$expected = 1;
$this->assertEqual($expected, $result);
$string = '一二三周永龍';
$find = '周';
$result = Multibyte::substrCount($string, $find);
$expected = 1;
$this->assertEqual($expected, $result);
$string = 'Ĥēĺļŏ, Ŵőřļď!';
$find = 'H';
$result = Multibyte::substrCount($string, $find);
$expected = 0;
$this->assertEqual($expected, $result);
}
/**
* testUsingMbSubstr method
*
* @return void
*/
public function testUsingMbSubstr() {
$string = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
$result = mb_substr($string, 4, 7);
$expected = 'EFGHIJK';
$this->assertEqual($expected, $result);
$string = 'ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞ';
$result = mb_substr($string, 4, 7);
$expected = 'ÄÅÆÇÈÉÊ';
$this->assertEqual($expected, $result);
$string = 'ĀĂĄĆĈĊČĎĐĒĔĖĘĚĜĞĠĢĤĦĨĪĬĮIJĴĶĹĻĽĿŁŃŅŇŊŌŎŐŒŔŖŘŚŜŞŠŢŤŦŨŪŬŮŰŲŴŶŹŻŽ';
$find = 'Ċ';
$result = mb_substr($string, 4, 7);
$expected = 'ĈĊČĎĐĒĔ';
$this->assertEqual($expected, $result);
$string = '!"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~';
$result = mb_substr($string, 4, 7);
$expected = '%&\'()*+';
$this->assertEqual($expected, $result);
$string = '¡¢£¤¥¦§¨©ª«¬®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈ';
$result = mb_substr($string, 4);
$expected = '¥¦§¨©ª«¬®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈ';
$this->assertEqual($expected, $result);
$string = 'ÉÊËÌÍÎÏÐÑÒÓÔÕÖרÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿĀāĂ㥹ĆćĈĉĊċČčĎďĐđĒēĔĕĖėĘęĚěĜĝĞğĠġĢģĤĥĦħĨĩĪīĬ';
$result = mb_substr($string, 4, 7);
$expected = 'ÍÎÏÐÑÒÓ';
$this->assertEqual($expected, $result);
$string = 'ĭĮįİıIJijĴĵĶķĸĹĺĻļĽľĿŀŁłŃńŅņŇňʼnŊŋŌōŎŏŐőŒœŔŕŖŗŘřŚśŜŝŞşŠšŢţŤťŦŧŨũŪūŬŭŮůŰűŲųŴŵŶŷŸŹźŻżŽžſƀƁƂƃƄƅƆƇƈƉƊƋƌƍƎƏƐ';
$result = mb_substr($string, 4, 7);
$expected = 'ıIJijĴĵĶķ';
$this->assertEqual($expected, $result);
$string = 'ƑƒƓƔƕƖƗƘƙƚƛƜƝƞƟƠơƢƣƤƥƦƧƨƩƪƫƬƭƮƯưƱƲƳƴƵƶƷƸƹƺƻƼƽƾƿǀǁǂǃDŽDždžLJLjljNJNjnjǍǎǏǐǑǒǓǔǕǖǗǘǙǚǛǜǝǞǟǠǡǢǣǤǥǦǧǨǩǪǫǬǭǮǯǰDZDzdzǴ';
$result = mb_substr($string, 25);
$expected = 'ƪƫƬƭƮƯưƱƲƳƴƵƶƷƸƹƺƻƼƽƾƿǀǁǂǃDŽDždžLJLjljNJNjnjǍǎǏǐǑǒǓǔǕǖǗǘǙǚǛǜǝǞǟǠǡǢǣǤǥǦǧǨǩǪǫǬǭǮǯǰDZDzdzǴ';
$this->assertEqual($expected, $result);
$string = 'əɚɛɜɝɞɟɠɡɢɣɤɥɦɧɨɩɪɫɬɭɮɯɰɱɲɳɴɵɶɷɸɹɺɻɼɽɾɿʀʁʂʃʄʅʆʇʈʉʊʋʌʍʎʏʐʑʒʓʔʕʖʗʘʙʚʛʜʝʞʟʠʡʢʣʤʥʦʧʨʩʪʫʬʭʮʯʰʱʲʳʴʵʶʷʸʹʺʻʼ';
$result = mb_substr($string, 3);
$expected = 'ɜɝɞɟɠɡɢɣɤɥɦɧɨɩɪɫɬɭɮɯɰɱɲɳɴɵɶɷɸɹɺɻɼɽɾɿʀʁʂʃʄʅʆʇʈʉʊʋʌʍʎʏʐʑʒʓʔʕʖʗʘʙʚʛʜʝʞʟʠʡʢʣʤʥʦʧʨʩʪʫʬʭʮʯʰʱʲʳʴʵʶʷʸʹʺʻʼ';
$this->assertEqual($expected, $result);
$string = 'ЀЁЂЃЄЅІЇЈЉЊЋЌЍЎЏАБВГДЕЖЗИЙКЛ';
$result = mb_substr($string, 3);
$expected = 'ЃЄЅІЇЈЉЊЋЌЍЎЏАБВГДЕЖЗИЙКЛ';
$this->assertEqual($expected, $result);
$string = 'МНОПРСТУФХЦЧШЩЪЫЬЭЮЯабвгдежзийклмнопрстуфхцчшщъыь';
$result = mb_substr($string, 3, 16);
$expected = 'ПРСТУФХЦЧШЩЪЫЬЭЮ';
$this->assertEqual($expected, $result);
$string = 'فقكلمنهوىيًٌٍَُ';
$result = mb_substr($string, 3, 6);
$expected = 'لمنهوى';
$this->assertEqual($expected, $result);
$string = '✰✱✲✳✴✵✶✷✸✹✺✻✼✽✾✿❀❁❂❃❄❅❆❇❈❉❊❋❌❍❎❏❐❑❒❓❔❕❖❗❘❙❚❛❜❝❞';
$result = mb_substr($string, 6, 14);
$expected = '✶✷✸✹✺✻✼✽✾✿❀❁❂❃';
$this->assertEqual($expected, $result);
$string = '⺀⺁⺂⺃⺄⺅⺆⺇⺈⺉⺊⺋⺌⺍⺎⺏⺐⺑⺒⺓⺔⺕⺖⺗⺘⺙⺛⺜⺝⺞⺟⺠⺡⺢⺣⺤⺥⺦⺧⺨⺩⺪⺫⺬⺭⺮⺯⺰⺱⺲⺳⺴⺵⺶⺷⺸⺹⺺⺻⺼⺽⺾⺿⻀⻁⻂⻃⻄⻅⻆⻇⻈⻉⻊⻋⻌⻍⻎⻏⻐⻑⻒⻓⻔⻕⻖⻗⻘⻙⻚⻛⻜⻝⻞⻟⻠';
$result = mb_substr($string, 8, 13);
$expected = '⺈⺉⺊⺋⺌⺍⺎⺏⺐⺑⺒⺓⺔';
$this->assertEqual($expected, $result);
$string = '⽅⽆⽇⽈⽉⽊⽋⽌⽍⽎⽏⽐⽑⽒⽓⽔⽕⽖⽗⽘⽙⽚⽛⽜⽝⽞⽟⽠⽡⽢⽣⽤⽥⽦⽧⽨⽩⽪⽫⽬⽭⽮⽯⽰⽱⽲⽳⽴⽵⽶⽷⽸⽹⽺⽻⽼⽽⽾⽿';
$result = mb_substr($string, 12, 24);
$expected = '⽑⽒⽓⽔⽕⽖⽗⽘⽙⽚⽛⽜⽝⽞⽟⽠⽡⽢⽣⽤⽥⽦⽧⽨';
$this->assertEqual($expected, $result);
$string = '눡눢눣눤눥눦눧눨눩눪눫눬눭눮눯눰눱눲눳눴눵눶눷눸눹눺눻눼눽눾눿뉀뉁뉂뉃뉄뉅뉆뉇뉈뉉뉊뉋뉌뉍뉎뉏뉐뉑뉒뉓뉔뉕뉖뉗뉘뉙뉚뉛뉜뉝뉞뉟뉠뉡뉢뉣뉤뉥뉦뉧뉨뉩뉪뉫뉬뉭뉮뉯뉰뉱뉲뉳뉴뉵뉶뉷뉸뉹뉺뉻뉼뉽뉾뉿늀늁늂늃늄';
$result = mb_substr($string, 12, 24);
$expected = '눭눮눯눰눱눲눳눴눵눶눷눸눹눺눻눼눽눾눿뉀뉁뉂뉃뉄';
$this->assertEqual($expected, $result);
$string = 'ﹰﹱﹲﹳﹴﹶﹷﹸﹹﹺﹻﹼﹽﹾﹿﺀﺁﺂﺃﺄﺅﺆﺇﺈﺉﺊﺋﺌﺍﺎﺏﺐﺑﺒﺓﺔﺕﺖﺗﺘﺙﺚﺛﺜﺝﺞﺟﺠﺡﺢﺣﺤﺥﺦﺧﺨﺩﺪﺫﺬﺭﺮﺯﺰ';
$result = mb_substr($string, 12);
$expected = 'ﹼﹽﹾﹿﺀﺁﺂﺃﺄﺅﺆﺇﺈﺉﺊﺋﺌﺍﺎﺏﺐﺑﺒﺓﺔﺕﺖﺗﺘﺙﺚﺛﺜﺝﺞﺟﺠﺡﺢﺣﺤﺥﺦﺧﺨﺩﺪﺫﺬﺭﺮﺯﺰ';
$this->assertEqual($expected, $result);
$string = 'ﺱﺲﺳﺴﺵﺶﺷﺸﺹﺺﺻﺼﺽﺾﺿﻀﻁﻂﻃﻄﻅﻆﻇﻈﻉﻊﻋﻌﻍﻎﻏﻐﻑﻒﻓﻔﻕﻖﻗﻘﻙﻚﻛﻜﻝﻞﻟﻠﻡﻢﻣﻤﻥﻦﻧﻨﻩﻪﻫﻬﻭﻮﻯﻰﻱﻲﻳﻴﻵﻶﻷﻸﻹﻺﻻﻼ';
$result = mb_substr($string, 24, 12);
$expected = 'ﻉﻊﻋﻌﻍﻎﻏﻐﻑﻒﻓﻔ';
$this->assertEqual($expected, $result);
$string = 'abcdefghijklmnopqrstuvwxyz';
$result = mb_substr($string, 11, 2);
$expected = 'lm';
$this->assertEqual($expected, $result);
$string = '。「」、・ヲァィゥェォャュョッーアイウエオカキク';
$result = mb_substr($string, 7, 11);
$expected = 'ィゥェォャュョッーアイ';
$this->assertEqual($expected, $result);
$string = 'ケコサシスセソタチツテトナニヌネノハヒフヘホマミムメモヤユヨラリルレロワン゙';
$result = mb_substr($string, 13, 13);
$expected = 'ニヌネノハヒフヘホマミムメ';
$this->assertEqual($expected, $result);
$string = 'Ĥēĺļŏ, Ŵőřļď!';
$result = mb_substr($string, 3, 4);
$expected = 'ļŏ, ';
$this->assertEqual($expected, $result);
$string = 'Hello, World!';
$result = mb_substr($string, 3, 4);
$expected = 'lo, ';
$this->assertEqual($expected, $result);
$string = 'čini';
$result = mb_substr($string, 3);
$expected = 'i';
$this->assertEqual($expected, $result);
$string = 'moći';
$result = mb_substr($string, 1);
$expected = 'oći';
$this->assertEqual($expected, $result);
$string = 'državni';
$result = mb_substr($string, 0, 2);
$expected = 'dr';
$this->assertEqual($expected, $result);
$string = '把百度设为首页';
$result = mb_substr($string, 3, 3);
$expected = '设为首';
$this->assertEqual($expected, $result);
$string = '一二三周永龍';
$result = mb_substr($string, 0, 1);
$expected = '一';
$this->assertEqual($expected, $result);
$string = '一二三周永龍';
$result = mb_substr($string, 6);
$expected = false;
$this->assertEqual($expected, $result);
$string = '一二三周永龍';
$result = mb_substr($string, 0);
$expected = '一二三周永龍';
$this->assertEqual($expected, $result);
}
/**
* testMultibyteSubstr method
*
* @return void
*/
public function testMultibyteSubstr() {
$string = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
$result = Multibyte::substr($string, 4, 7);
$expected = 'EFGHIJK';
$this->assertEqual($expected, $result);
$string = 'ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞ';
$result = Multibyte::substr($string, 4, 7);
$expected = 'ÄÅÆÇÈÉÊ';
$this->assertEqual($expected, $result);
$string = 'ĀĂĄĆĈĊČĎĐĒĔĖĘĚĜĞĠĢĤĦĨĪĬĮIJĴĶĹĻĽĿŁŃŅŇŊŌŎŐŒŔŖŘŚŜŞŠŢŤŦŨŪŬŮŰŲŴŶŹŻŽ';
$find = 'Ċ';
$result = Multibyte::substr($string, 4, 7);
$expected = 'ĈĊČĎĐĒĔ';
$this->assertEqual($expected, $result);
$string = '!"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~';
$result = Multibyte::substr($string, 4, 7);
$expected = '%&\'()*+';
$this->assertEqual($expected, $result);
$string = '¡¢£¤¥¦§¨©ª«¬®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈ';
$result = Multibyte::substr($string, 4);
$expected = '¥¦§¨©ª«¬®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈ';
$this->assertEqual($expected, $result);
$string = 'ÉÊËÌÍÎÏÐÑÒÓÔÕÖרÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿĀāĂ㥹ĆćĈĉĊċČčĎďĐđĒēĔĕĖėĘęĚěĜĝĞğĠġĢģĤĥĦħĨĩĪīĬ';
$result = Multibyte::substr($string, 4, 7);
$expected = 'ÍÎÏÐÑÒÓ';
$this->assertEqual($expected, $result);
$string = 'ĭĮįİıIJijĴĵĶķĸĹĺĻļĽľĿŀŁłŃńŅņŇňʼnŊŋŌōŎŏŐőŒœŔŕŖŗŘřŚśŜŝŞşŠšŢţŤťŦŧŨũŪūŬŭŮůŰűŲųŴŵŶŷŸŹźŻżŽžſƀƁƂƃƄƅƆƇƈƉƊƋƌƍƎƏƐ';
$result = Multibyte::substr($string, 4, 7);
$expected = 'ıIJijĴĵĶķ';
$this->assertEqual($expected, $result);
$string = 'ƑƒƓƔƕƖƗƘƙƚƛƜƝƞƟƠơƢƣƤƥƦƧƨƩƪƫƬƭƮƯưƱƲƳƴƵƶƷƸƹƺƻƼƽƾƿǀǁǂǃDŽDždžLJLjljNJNjnjǍǎǏǐǑǒǓǔǕǖǗǘǙǚǛǜǝǞǟǠǡǢǣǤǥǦǧǨǩǪǫǬǭǮǯǰDZDzdzǴ';
$result = Multibyte::substr($string, 25);
$expected = 'ƪƫƬƭƮƯưƱƲƳƴƵƶƷƸƹƺƻƼƽƾƿǀǁǂǃDŽDždžLJLjljNJNjnjǍǎǏǐǑǒǓǔǕǖǗǘǙǚǛǜǝǞǟǠǡǢǣǤǥǦǧǨǩǪǫǬǭǮǯǰDZDzdzǴ';
$this->assertEqual($expected, $result);
$string = 'əɚɛɜɝɞɟɠɡɢɣɤɥɦɧɨɩɪɫɬɭɮɯɰɱɲɳɴɵɶɷɸɹɺɻɼɽɾɿʀʁʂʃʄʅʆʇʈʉʊʋʌʍʎʏʐʑʒʓʔʕʖʗʘʙʚʛʜʝʞʟʠʡʢʣʤʥʦʧʨʩʪʫʬʭʮʯʰʱʲʳʴʵʶʷʸʹʺʻʼ';
$result = Multibyte::substr($string, 3);
$expected = 'ɜɝɞɟɠɡɢɣɤɥɦɧɨɩɪɫɬɭɮɯɰɱɲɳɴɵɶɷɸɹɺɻɼɽɾɿʀʁʂʃʄʅʆʇʈʉʊʋʌʍʎʏʐʑʒʓʔʕʖʗʘʙʚʛʜʝʞʟʠʡʢʣʤʥʦʧʨʩʪʫʬʭʮʯʰʱʲʳʴʵʶʷʸʹʺʻʼ';
$this->assertEqual($expected, $result);
$string = 'ЀЁЂЃЄЅІЇЈЉЊЋЌЍЎЏАБВГДЕЖЗИЙКЛ';
$result = Multibyte::substr($string, 3);
$expected = 'ЃЄЅІЇЈЉЊЋЌЍЎЏАБВГДЕЖЗИЙКЛ';
$this->assertEqual($expected, $result);
$string = 'МНОПРСТУФХЦЧШЩЪЫЬЭЮЯабвгдежзийклмнопрстуфхцчшщъыь';
$result = Multibyte::substr($string, 3, 16);
$expected = 'ПРСТУФХЦЧШЩЪЫЬЭЮ';
$this->assertEqual($expected, $result);
$string = 'فقكلمنهوىيًٌٍَُ';
$result = Multibyte::substr($string, 3, 6);
$expected = 'لمنهوى';
$this->assertEqual($expected, $result);
$string = '✰✱✲✳✴✵✶✷✸✹✺✻✼✽✾✿❀❁❂❃❄❅❆❇❈❉❊❋❌❍❎❏❐❑❒❓❔❕❖❗❘❙❚❛❜❝❞';
$result = Multibyte::substr($string, 6, 14);
$expected = '✶✷✸✹✺✻✼✽✾✿❀❁❂❃';
$this->assertEqual($expected, $result);
$string = '⺀⺁⺂⺃⺄⺅⺆⺇⺈⺉⺊⺋⺌⺍⺎⺏⺐⺑⺒⺓⺔⺕⺖⺗⺘⺙⺛⺜⺝⺞⺟⺠⺡⺢⺣⺤⺥⺦⺧⺨⺩⺪⺫⺬⺭⺮⺯⺰⺱⺲⺳⺴⺵⺶⺷⺸⺹⺺⺻⺼⺽⺾⺿⻀⻁⻂⻃⻄⻅⻆⻇⻈⻉⻊⻋⻌⻍⻎⻏⻐⻑⻒⻓⻔⻕⻖⻗⻘⻙⻚⻛⻜⻝⻞⻟⻠';
$result = Multibyte::substr($string, 8, 13);
$expected = '⺈⺉⺊⺋⺌⺍⺎⺏⺐⺑⺒⺓⺔';
$this->assertEqual($expected, $result);
$string = '⽅⽆⽇⽈⽉⽊⽋⽌⽍⽎⽏⽐⽑⽒⽓⽔⽕⽖⽗⽘⽙⽚⽛⽜⽝⽞⽟⽠⽡⽢⽣⽤⽥⽦⽧⽨⽩⽪⽫⽬⽭⽮⽯⽰⽱⽲⽳⽴⽵⽶⽷⽸⽹⽺⽻⽼⽽⽾⽿';
$result = Multibyte::substr($string, 12, 24);
$expected = '⽑⽒⽓⽔⽕⽖⽗⽘⽙⽚⽛⽜⽝⽞⽟⽠⽡⽢⽣⽤⽥⽦⽧⽨';
$this->assertEqual($expected, $result);
$string = '눡눢눣눤눥눦눧눨눩눪눫눬눭눮눯눰눱눲눳눴눵눶눷눸눹눺눻눼눽눾눿뉀뉁뉂뉃뉄뉅뉆뉇뉈뉉뉊뉋뉌뉍뉎뉏뉐뉑뉒뉓뉔뉕뉖뉗뉘뉙뉚뉛뉜뉝뉞뉟뉠뉡뉢뉣뉤뉥뉦뉧뉨뉩뉪뉫뉬뉭뉮뉯뉰뉱뉲뉳뉴뉵뉶뉷뉸뉹뉺뉻뉼뉽뉾뉿늀늁늂늃늄';
$result = Multibyte::substr($string, 12, 24);
$expected = '눭눮눯눰눱눲눳눴눵눶눷눸눹눺눻눼눽눾눿뉀뉁뉂뉃뉄';
$this->assertEqual($expected, $result);
$string = 'ﹰﹱﹲﹳﹴﹶﹷﹸﹹﹺﹻﹼﹽﹾﹿﺀﺁﺂﺃﺄﺅﺆﺇﺈﺉﺊﺋﺌﺍﺎﺏﺐﺑﺒﺓﺔﺕﺖﺗﺘﺙﺚﺛﺜﺝﺞﺟﺠﺡﺢﺣﺤﺥﺦﺧﺨﺩﺪﺫﺬﺭﺮﺯﺰ';
$result = Multibyte::substr($string, 12);
$expected = 'ﹼﹽﹾﹿﺀﺁﺂﺃﺄﺅﺆﺇﺈﺉﺊﺋﺌﺍﺎﺏﺐﺑﺒﺓﺔﺕﺖﺗﺘﺙﺚﺛﺜﺝﺞﺟﺠﺡﺢﺣﺤﺥﺦﺧﺨﺩﺪﺫﺬﺭﺮﺯﺰ';
$this->assertEqual($expected, $result);
$string = 'ﺱﺲﺳﺴﺵﺶﺷﺸﺹﺺﺻﺼﺽﺾﺿﻀﻁﻂﻃﻄﻅﻆﻇﻈﻉﻊﻋﻌﻍﻎﻏﻐﻑﻒﻓﻔﻕﻖﻗﻘﻙﻚﻛﻜﻝﻞﻟﻠﻡﻢﻣﻤﻥﻦﻧﻨﻩﻪﻫﻬﻭﻮﻯﻰﻱﻲﻳﻴﻵﻶﻷﻸﻹﻺﻻﻼ';
$result = Multibyte::substr($string, 24, 12);
$expected = 'ﻉﻊﻋﻌﻍﻎﻏﻐﻑﻒﻓﻔ';
$this->assertEqual($expected, $result);
$string = 'abcdefghijklmnopqrstuvwxyz';
$result = Multibyte::substr($string, 11, 2);
$expected = 'lm';
$this->assertEqual($expected, $result);
$string = '。「」、・ヲァィゥェォャュョッーアイウエオカキク';
$result = Multibyte::substr($string, 7, 11);
$expected = 'ィゥェォャュョッーアイ';
$this->assertEqual($expected, $result);
$string = 'ケコサシスセソタチツテトナニヌネノハヒフヘホマミムメモヤユヨラリルレロワン゙';
$result = Multibyte::substr($string, 13, 13);
$expected = 'ニヌネノハヒフヘホマミムメ';
$this->assertEqual($expected, $result);
$string = 'Ĥēĺļŏ, Ŵőřļď!';
$result = Multibyte::substr($string, 3, 4);
$expected = 'ļŏ, ';
$this->assertEqual($expected, $result);
$string = 'Hello, World!';
$result = Multibyte::substr($string, 3, 4);
$expected = 'lo, ';
$this->assertEqual($expected, $result);
$string = 'čini';
$result = Multibyte::substr($string, 3);
$expected = 'i';
$this->assertEqual($expected, $result);
$string = 'moći';
$result = Multibyte::substr($string, 1);
$expected = 'oći';
$this->assertEqual($expected, $result);
$string = 'državni';
$result = Multibyte::substr($string, 0, 2);
$expected = 'dr';
$this->assertEqual($expected, $result);
$string = '把百度设为首页';
$result = Multibyte::substr($string, 3, 3);
$expected = '设为首';
$this->assertEqual($expected, $result);
$string = '一二三周永龍';
$result = Multibyte::substr($string, 0, 1);
$expected = '一';
$this->assertEqual($expected, $result);
$string = '一二三周永龍';
$result = Multibyte::substr($string, 6);
$expected = false;
$this->assertEqual($expected, $result);
$string = '一二三周永龍';
$result = Multibyte::substr($string, 0);
$expected = '一二三周永龍';
$this->assertEqual($expected, $result);
}
/**
* testMultibyteSubstr method
*
* @return void
*/
public function testMultibyteMimeEncode() {
$string = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
$result = Multibyte::mimeEncode($string);
$this->assertEqual($result, $string);
$string = 'ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞ';
$result = Multibyte::mimeEncode($string);
$expected = '=?UTF-8?B?w4DDgcOCw4PDhMOFw4bDh8OIw4nDisOLw4zDjcOOw4/DkMORw5LDk8OUw5U=?=' . "\r\n" .
' =?UTF-8?B?w5bDmMOZw5rDm8Ocw53Dng==?=';
$this->assertEqual($expected, $result);
$result = Multibyte::mimeEncode($string, null, "\n");
$expected = '=?UTF-8?B?w4DDgcOCw4PDhMOFw4bDh8OIw4nDisOLw4zDjcOOw4/DkMORw5LDk8OUw5U=?=' . "\n" .
' =?UTF-8?B?w5bDmMOZw5rDm8Ocw53Dng==?=';
$this->assertEqual($expected, $result);
$string = 'ĀĂĄĆĈĊČĎĐĒĔĖĘĚĜĞĠĢĤĦĨĪĬĮIJĴĶĹĻĽĿŁŃŅŇŊŌŎŐŒŔŖŘŚŜŞŠŢŤŦŨŪŬŮŰŲŴŶŹŻŽ';
$result = Multibyte::mimeEncode($string);
$expected = '=?UTF-8?B?xIDEgsSExIbEiMSKxIzEjsSQxJLElMSWxJjEmsScxJ7EoMSixKTEpsSoxKo=?=' . "\r\n" .
' =?UTF-8?B?xKzErsSyxLTEtsS5xLvEvcS/xYHFg8WFxYfFisWMxY7FkMWSxZTFlsWYxZo=?=' . "\r\n" .
' =?UTF-8?B?xZzFnsWgxaLFpMWmxajFqsWsxa7FsMWyxbTFtsW5xbvFvQ==?=';
$this->assertEqual($expected, $result);
$string = '!"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~';
$result = Multibyte::mimeEncode($string);
$expected = '=?UTF-8?B?ISIjJCUmJygpKissLS4vMDEyMzQ1Njc4OTo7PD0+P0BBQkNERUZHSElKS0xN?=' . "\r\n" .
' =?UTF-8?B?Tk9QUVJTVFVWV1hZWltcXV5fYGFiY2RlZmdoaWprbG1ub3BxcnN0dXZ3eHl6?=' . "\r\n" .
' =?UTF-8?B?e3x9fg==?=';
$this->assertEqual($expected, $result);
$string = '¡¢£¤¥¦§¨©ª«¬®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈ';
$result = Multibyte::mimeEncode($string);
$expected = '=?UTF-8?B?wqHCosKjwqTCpcKmwqfCqMKpwqrCq8Kswq3CrsKvwrDCscKywrPCtMK1wrY=?=' . "\r\n" .
' =?UTF-8?B?wrfCuMK5wrrCu8K8wr3CvsK/w4DDgcOCw4PDhMOFw4bDh8OI?=';
$this->assertEqual($expected, $result);
$string = 'ÉÊËÌÍÎÏÐÑÒÓÔÕÖרÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿĀāĂ㥹ĆćĈĉĊċČčĎďĐđĒēĔĕĖėĘęĚěĜĝĞğĠġĢģĤĥĦħĨĩĪīĬ';
$result = Multibyte::mimeEncode($string);
$expected = '=?UTF-8?B?w4nDisOLw4zDjcOOw4/DkMORw5LDk8OUw5XDlsOXw5jDmcOaw5vDnMOdw54=?=' . "\r\n" .
' =?UTF-8?B?w5/DoMOhw6LDo8Okw6XDpsOnw6jDqcOqw6vDrMOtw67Dr8Oww7HDssOzw7Q=?=' . "\r\n" .
' =?UTF-8?B?w7XDtsO3w7jDucO6w7vDvMO9w77Dv8SAxIHEgsSDxITEhcSGxIfEiMSJxIo=?=' . "\r\n" .
' =?UTF-8?B?xIvEjMSNxI7Ej8SQxJHEksSTxJTElcSWxJfEmMSZxJrEm8ScxJ3EnsSfxKA=?=' . "\r\n" .
' =?UTF-8?B?xKHEosSjxKTEpcSmxKfEqMSpxKrEq8Ss?=';
$this->assertEqual($expected, $result);
$string = 'ĭĮįİıIJijĴĵĶķĸĹĺĻļĽľĿŀŁłŃńŅņŇňʼnŊŋŌōŎŏŐőŒœŔŕŖŗŘřŚśŜŝŞşŠšŢţŤťŦŧŨũŪūŬŭŮůŰűŲųŴŵŶŷŸŹźŻżŽžſƀƁƂƃƄƅƆƇƈƉƊƋƌƍƎƏƐ';
$result = Multibyte::mimeEncode($string);
$expected = '=?UTF-8?B?xK3ErsSvxLDEscSyxLPEtMS1xLbEt8S4xLnEusS7xLzEvcS+xL/FgMWBxYI=?=' . "\r\n" .
' =?UTF-8?B?xYPFhMWFxYbFh8WIxYnFisWLxYzFjcWOxY/FkMWRxZLFk8WUxZXFlsWXxZg=?=' . "\r\n" .
' =?UTF-8?B?xZnFmsWbxZzFncWexZ/FoMWhxaLFo8WkxaXFpsWnxajFqcWqxavFrMWtxa4=?=' . "\r\n" .
' =?UTF-8?B?xa/FsMWxxbLFs8W0xbXFtsW3xbjFucW6xbvFvMW9xb7Fv8aAxoHGgsaDxoQ=?=' . "\r\n" .
' =?UTF-8?B?xoXGhsaHxojGicaKxovGjMaNxo7Gj8aQ?=';
$this->assertEqual($expected, $result);
$string = 'ƑƒƓƔƕƖƗƘƙƚƛƜƝƞƟƠơƢƣƤƥƦƧƨƩƪƫƬƭƮƯưƱƲƳƴƵƶƷƸƹƺƻƼƽƾƿǀǁǂǃDŽDždžLJLjljNJNjnjǍǎǏǐǑǒǓǔǕǖǗǘǙǚǛǜǝǞǟǠǡǢǣǤǥǦǧǨǩǪǫǬǭǮǯǰDZDzdzǴ';
$result = Multibyte::mimeEncode($string);
$expected = '=?UTF-8?B?xpHGksaTxpTGlcaWxpfGmMaZxprGm8acxp3GnsafxqDGocaixqPGpMalxqY=?=' . "\r\n" .
' =?UTF-8?B?xqfGqMapxqrGq8asxq3GrsavxrDGscayxrPGtMa1xrbGt8a4xrnGusa7xrw=?=' . "\r\n" .
' =?UTF-8?B?xr3Gvsa/x4DHgceCx4PHhMeFx4bHh8eIx4nHiseLx4zHjceOx4/HkMeRx5I=?=' . "\r\n" .
' =?UTF-8?B?x5PHlMeVx5bHl8eYx5nHmsebx5zHnceex5/HoMehx6LHo8ekx6XHpsenx6g=?=' . "\r\n" .
' =?UTF-8?B?x6nHqserx6zHrceux6/HsMexx7LHs8e0?=';
$this->assertEqual($expected, $result);
$string = 'əɚɛɜɝɞɟɠɡɢɣɤɥɦɧɨɩɪɫɬɭɮɯɰɱɲɳɴɵɶɷɸɹɺɻɼɽɾɿʀʁʂʃʄʅʆʇʈʉʊʋʌʍʎʏʐʑʒʓʔʕʖʗʘʙʚʛʜʝʞʟʠʡʢʣʤʥʦʧʨʩʪʫʬʭʮʯʰʱʲʳʴʵʶʷʸʹʺʻʼ';
$result = Multibyte::mimeEncode($string);
$expected = '=?UTF-8?B?yZnJmsmbyZzJncmeyZ/JoMmhyaLJo8mkyaXJpsmnyajJqcmqyavJrMmtya4=?=' . "\r\n" .
' =?UTF-8?B?ya/JsMmxybLJs8m0ybXJtsm3ybjJucm6ybvJvMm9yb7Jv8qAyoHKgsqDyoQ=?=' . "\r\n" .
' =?UTF-8?B?yoXKhsqHyojKicqKyovKjMqNyo7Kj8qQypHKksqTypTKlcqWypfKmMqZypo=?=' . "\r\n" .
' =?UTF-8?B?ypvKnMqdyp7Kn8qgyqHKosqjyqTKpcqmyqfKqMqpyqrKq8qsyq3KrsqvyrA=?=' . "\r\n" .
' =?UTF-8?B?yrHKssqzyrTKtcq2yrfKuMq5yrrKu8q8?=';
$this->assertEqual($expected, $result);
$string = 'ЀЁЂЃЄЅІЇЈЉЊЋЌЍЎЏАБВГДЕЖЗИЙКЛ';
$result = Multibyte::mimeEncode($string);
$expected = '=?UTF-8?B?0IDQgdCC0IPQhNCF0IbQh9CI0InQitCL0IzQjdCO0I/QkNCR0JLQk9CU0JU=?=' . "\r\n" .
' =?UTF-8?B?0JbQl9CY0JnQmtCb?=';
$this->assertEqual($expected, $result);
$string = 'МНОПРСТУФХЦЧШЩЪЫЬЭЮЯабвгдежзийклмнопрстуфхцчшщъыь';
$result = Multibyte::mimeEncode($string);
$expected = '=?UTF-8?B?0JzQndCe0J/QoNCh0KLQo9Ck0KXQptCn0KjQqdCq0KvQrNCt0K7Qr9Cw0LE=?=' . "\r\n" .
' =?UTF-8?B?0LLQs9C00LXQttC30LjQudC60LvQvNC90L7Qv9GA0YHRgtGD0YTRhdGG0Yc=?=' . "\r\n" .
' =?UTF-8?B?0YjRidGK0YvRjA==?=';
$this->assertEqual($expected, $result);
$string = 'فقكلمنهوىيًٌٍَُ';
$result = Multibyte::mimeEncode($string);
$expected = '=?UTF-8?B?2YHZgtmD2YTZhdmG2YfZiNmJ2YrZi9mM2Y3ZjtmP?=';
$this->assertEqual($expected, $result);
$string = '✰✱✲✳✴✵✶✷✸✹✺✻✼✽✾✿❀❁❂❃❄❅❆❇❈❉❊❋❌❍❎❏❐❑❒❓❔❕❖❗❘❙❚❛❜❝❞';
$result = Multibyte::mimeEncode($string);
$expected = '=?UTF-8?B?4pyw4pyx4pyy4pyz4py04py14py24py34py44py54py64py74py84py94py+?=' . "\r\n" .
' =?UTF-8?B?4py/4p2A4p2B4p2C4p2D4p2E4p2F4p2G4p2H4p2I4p2J4p2K4p2L4p2M4p2N?=' . "\r\n" .
' =?UTF-8?B?4p2O4p2P4p2Q4p2R4p2S4p2T4p2U4p2V4p2W4p2X4p2Y4p2Z4p2a4p2b4p2c?=' . "\r\n" .
' =?UTF-8?B?4p2d4p2e?=';
$this->assertEqual($expected, $result);
$string = '⺀⺁⺂⺃⺄⺅⺆⺇⺈⺉⺊⺋⺌⺍⺎⺏⺐⺑⺒⺓⺔⺕⺖⺗⺘⺙⺛⺜⺝⺞⺟⺠⺡⺢⺣⺤⺥⺦⺧⺨⺩⺪⺫⺬⺭⺮⺯⺰⺱⺲⺳⺴⺵⺶⺷⺸⺹⺺⺻⺼⺽⺾⺿⻀⻁⻂⻃⻄⻅⻆⻇⻈⻉⻊⻋⻌⻍⻎⻏⻐⻑⻒⻓⻔⻕⻖⻗⻘⻙⻚⻛⻜⻝⻞⻟⻠';
$result = Multibyte::mimeEncode($string);
$expected = '=?UTF-8?B?4rqA4rqB4rqC4rqD4rqE4rqF4rqG4rqH4rqI4rqJ4rqK4rqL4rqM4rqN4rqO?=' . "\r\n" .
' =?UTF-8?B?4rqP4rqQ4rqR4rqS4rqT4rqU4rqV4rqW4rqX4rqY4rqZ4rqb4rqc4rqd4rqe?=' . "\r\n" .
' =?UTF-8?B?4rqf4rqg4rqh4rqi4rqj4rqk4rql4rqm4rqn4rqo4rqp4rqq4rqr4rqs4rqt?=' . "\r\n" .
' =?UTF-8?B?4rqu4rqv4rqw4rqx4rqy4rqz4rq04rq14rq24rq34rq44rq54rq64rq74rq8?=' . "\r\n" .
' =?UTF-8?B?4rq94rq+4rq/4ruA4ruB4ruC4ruD4ruE4ruF4ruG4ruH4ruI4ruJ4ruK4ruL?=' . "\r\n" .
' =?UTF-8?B?4ruM4ruN4ruO4ruP4ruQ4ruR4ruS4ruT4ruU4ruV4ruW4ruX4ruY4ruZ4rua?=' . "\r\n" .
' =?UTF-8?B?4rub4ruc4rud4rue4ruf4rug?=';
$this->assertEqual($expected, $result);
$string = '⽅⽆⽇⽈⽉⽊⽋⽌⽍⽎⽏⽐⽑⽒⽓⽔⽕⽖⽗⽘⽙⽚⽛⽜⽝⽞⽟⽠⽡⽢⽣⽤⽥⽦⽧⽨⽩⽪⽫⽬⽭⽮⽯⽰⽱⽲⽳⽴⽵⽶⽷⽸⽹⽺⽻⽼⽽⽾⽿';
$result = Multibyte::mimeEncode($string);
$expected = '=?UTF-8?B?4r2F4r2G4r2H4r2I4r2J4r2K4r2L4r2M4r2N4r2O4r2P4r2Q4r2R4r2S4r2T?=' . "\r\n" .
' =?UTF-8?B?4r2U4r2V4r2W4r2X4r2Y4r2Z4r2a4r2b4r2c4r2d4r2e4r2f4r2g4r2h4r2i?=' . "\r\n" .
' =?UTF-8?B?4r2j4r2k4r2l4r2m4r2n4r2o4r2p4r2q4r2r4r2s4r2t4r2u4r2v4r2w4r2x?=' . "\r\n" .
' =?UTF-8?B?4r2y4r2z4r204r214r224r234r244r254r264r274r284r294r2+4r2/?=';
$this->assertEqual($expected, $result);
$string = '눡눢눣눤눥눦눧눨눩눪눫눬눭눮눯눰눱눲눳눴눵눶눷눸눹눺눻눼눽눾눿뉀뉁뉂뉃뉄뉅뉆뉇뉈뉉뉊뉋뉌뉍뉎뉏뉐뉑뉒뉓뉔뉕뉖뉗뉘뉙뉚뉛뉜뉝뉞뉟뉠뉡뉢뉣뉤뉥뉦뉧뉨뉩뉪뉫뉬뉭뉮뉯뉰뉱뉲뉳뉴뉵뉶뉷뉸뉹뉺뉻뉼뉽뉾뉿늀늁늂늃늄';
$result = Multibyte::mimeEncode($string);
$expected = '=?UTF-8?B?64ih64ii64ij64ik64il64im64in64io64ip64iq64ir64is64it64iu64iv?=' . "\r\n" .
' =?UTF-8?B?64iw64ix64iy64iz64i064i164i264i364i464i564i664i764i864i964i+?=' . "\r\n" .
' =?UTF-8?B?64i/64mA64mB64mC64mD64mE64mF64mG64mH64mI64mJ64mK64mL64mM64mN?=' . "\r\n" .
' =?UTF-8?B?64mO64mP64mQ64mR64mS64mT64mU64mV64mW64mX64mY64mZ64ma64mb64mc?=' . "\r\n" .
' =?UTF-8?B?64md64me64mf64mg64mh64mi64mj64mk64ml64mm64mn64mo64mp64mq64mr?=' . "\r\n" .
' =?UTF-8?B?64ms64mt64mu64mv64mw64mx64my64mz64m064m164m264m364m464m564m6?=' . "\r\n" .
' =?UTF-8?B?64m764m864m964m+64m/64qA64qB64qC64qD64qE?=';
$this->assertEqual($expected, $result);
$string = 'ﹰﹱﹲﹳﹴﹶﹷﹸﹹﹺﹻﹼﹽﹾﹿﺀﺁﺂﺃﺄﺅﺆﺇﺈﺉﺊﺋﺌﺍﺎﺏﺐﺑﺒﺓﺔﺕﺖﺗﺘﺙﺚﺛﺜﺝﺞﺟﺠﺡﺢﺣﺤﺥﺦﺧﺨﺩﺪﺫﺬﺭﺮﺯﺰ';
$result = Multibyte::mimeEncode($string);
$expected = '=?UTF-8?B?77mw77mx77my77mz77m077m177m277m377m477m577m677m777m877m977m+?=' . "\r\n" .
' =?UTF-8?B?77m/77qA77qB77qC77qD77qE77qF77qG77qH77qI77qJ77qK77qL77qM77qN?=' . "\r\n" .
' =?UTF-8?B?77qO77qP77qQ77qR77qS77qT77qU77qV77qW77qX77qY77qZ77qa77qb77qc?=' . "\r\n" .
' =?UTF-8?B?77qd77qe77qf77qg77qh77qi77qj77qk77ql77qm77qn77qo77qp77qq77qr?=' . "\r\n" .
' =?UTF-8?B?77qs77qt77qu77qv77qw?=';
$this->assertEqual($expected, $result);
$string = 'ﺱﺲﺳﺴﺵﺶﺷﺸﺹﺺﺻﺼﺽﺾﺿﻀﻁﻂﻃﻄﻅﻆﻇﻈﻉﻊﻋﻌﻍﻎﻏﻐﻑﻒﻓﻔﻕﻖﻗﻘﻙﻚﻛﻜﻝﻞﻟﻠﻡﻢﻣﻤﻥﻦﻧﻨﻩﻪﻫﻬﻭﻮﻯﻰﻱﻲﻳﻴﻵﻶﻷﻸﻹﻺﻻﻼ';
$result = Multibyte::mimeEncode($string);
$expected = '=?UTF-8?B?77qx77qy77qz77q077q177q277q377q477q577q677q777q877q977q+77q/?=' . "\r\n" .
' =?UTF-8?B?77uA77uB77uC77uD77uE77uF77uG77uH77uI77uJ77uK77uL77uM77uN77uO?=' . "\r\n" .
' =?UTF-8?B?77uP77uQ77uR77uS77uT77uU77uV77uW77uX77uY77uZ77ua77ub77uc77ud?=' . "\r\n" .
' =?UTF-8?B?77ue77uf77ug77uh77ui77uj77uk77ul77um77un77uo77up77uq77ur77us?=' . "\r\n" .
' =?UTF-8?B?77ut77uu77uv77uw77ux77uy77uz77u077u177u277u377u477u577u677u7?=' . "\r\n" .
' =?UTF-8?B?77u8?=';
$this->assertEqual($expected, $result);
$string = 'abcdefghijklmnopqrstuvwxyz';
$result = Multibyte::mimeEncode($string);
$expected = '=?UTF-8?B?772B772C772D772E772F772G772H772I772J772K772L772M772N772O772P?=' . "\r\n" .
' =?UTF-8?B?772Q772R772S772T772U772V772W772X772Y772Z772a?=';
$this->assertEqual($expected, $result);
$string = '。「」、・ヲァィゥェォャュョッーアイウエオカキク';
$result = Multibyte::mimeEncode($string);
$expected = '=?UTF-8?B?772h772i772j772k772l772m772n772o772p772q772r772s772t772u772v?=' . "\r\n" .
' =?UTF-8?B?772w772x772y772z77207721772277237724?=';
$this->assertEqual($expected, $result);
$string = 'ケコサシスセソタチツテトナニヌネノハヒフヘホマミムメモヤユヨラリルレロワン゙';
$result = Multibyte::mimeEncode($string);
$expected = '=?UTF-8?B?77257726772777287729772+772/776A776B776C776D776E776F776G776H?=' . "\r\n" .
' =?UTF-8?B?776I776J776K776L776M776N776O776P776Q776R776S776T776U776V776W?=' . "\r\n" .
' =?UTF-8?B?776X776Y776Z776a776b776c776d776e?=';
$this->assertEqual($expected, $result);
$string = 'Ĥēĺļŏ, Ŵőřļď!';
$result = Multibyte::mimeEncode($string);
$expected = '=?UTF-8?B?xKTEk8S6xLzFjywgxbTFkcWZxLzEjyE=?=';
$this->assertEqual($expected, $result);
$string = 'Hello, World!';
$result = Multibyte::mimeEncode($string);
$this->assertEqual($result, $string);
$string = 'čini';
$result = Multibyte::mimeEncode($string);
$expected = '=?UTF-8?B?xI1pbmk=?=';
$this->assertEqual($expected, $result);
$string = 'moći';
$result = Multibyte::mimeEncode($string);
$expected = '=?UTF-8?B?bW/Eh2k=?=';
$this->assertEqual($expected, $result);
$string = 'državni';
$result = Multibyte::mimeEncode($string);
$expected = '=?UTF-8?B?ZHLFvmF2bmk=?=';
$this->assertEqual($expected, $result);
$string = '把百度设为首页';
$result = Multibyte::mimeEncode($string);
$expected = '=?UTF-8?B?5oqK55m+5bqm6K6+5Li66aaW6aG1?=';
$this->assertEqual($expected, $result);
$string = '一二三周永龍';
$result = Multibyte::mimeEncode($string);
$expected = '=?UTF-8?B?5LiA5LqM5LiJ5ZGo5rC46b6N?=';
$this->assertEqual($expected, $result);
}
}
| 0001-bee | trunk/cakephp2/lib/Cake/Test/Case/I18n/MultibyteTest.php | PHP | gpl3 | 392,332 |
<?php
/**
* L10nTest file
*
* PHP 5
*
* CakePHP(tm) Tests <http://book.cakephp.org/view/1196/Testing>
* Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice
*
* @copyright Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://book.cakephp.org/view/1196/Testing CakePHP(tm) Tests
* @package Cake.Test.Case.I18n
* @since CakePHP(tm) v 1.2.0.5432
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
App::uses('L10n', 'I18n');
/**
* L10nTest class
*
* @package Cake.Test.Case.I18n
*/
class L10nTest extends CakeTestCase {
/**
* testGet method
*
* @return void
*/
public function testGet() {
$l10n = new L10n();
// Catalog Entry
$l10n->get('en');
$this->assertEqual($l10n->language, 'English');
$this->assertEqual($l10n->languagePath, array('eng', 'eng'));
$this->assertEqual($l10n->locale, 'eng');
// Map Entry
$l10n->get('eng');
$this->assertEqual($l10n->language, 'English');
$this->assertEqual($l10n->languagePath, array('eng', 'eng'));
$this->assertEqual($l10n->locale, 'eng');
// Catalog Entry
$l10n->get('en-ca');
$this->assertEqual($l10n->language, 'English (Canadian)');
$this->assertEqual($l10n->languagePath, array('en_ca', 'eng'));
$this->assertEqual($l10n->locale, 'en_ca');
// Default Entry
define('DEFAULT_LANGUAGE', 'en-us');
$l10n->get('use_default');
$this->assertEqual($l10n->language, 'English (United States)');
$this->assertEqual($l10n->languagePath, array('en_us', 'eng'));
$this->assertEqual($l10n->locale, 'en_us');
$l10n->get('es');
$l10n->get('');
$this->assertEqual($l10n->lang, 'en-us');
// Using $this->default
$l10n = new L10n();
$l10n->get('use_default');
$this->assertEqual($l10n->language, 'English (United States)');
$this->assertEqual($l10n->languagePath, array('en_us', 'eng', 'eng'));
$this->assertEqual($l10n->locale, 'en_us');
}
/**
* testGetAutoLanguage method
*
* @return void
*/
public function testGetAutoLanguage() {
$__SERVER = $_SERVER;
$_SERVER['HTTP_ACCEPT_LANGUAGE'] = 'inexistent,en-ca';
$l10n = new L10n();
$l10n->get();
$this->assertEqual($l10n->language, 'English (Canadian)');
$this->assertEqual($l10n->languagePath, array('en_ca', 'eng', 'eng'));
$this->assertEqual($l10n->locale, 'en_ca');
$_SERVER['HTTP_ACCEPT_LANGUAGE'] = 'es_mx';
$l10n->get();
$this->assertEqual($l10n->language, 'Spanish (Mexican)');
$this->assertEqual($l10n->languagePath, array('es_mx', 'spa', 'eng'));
$this->assertEqual($l10n->locale, 'es_mx');
$_SERVER['HTTP_ACCEPT_LANGUAGE'] = 'en_xy,en_ca';
$l10n->get();
$this->assertEqual($l10n->language, 'English');
$this->assertEqual($l10n->languagePath, array('eng', 'eng', 'eng'));
$this->assertEqual($l10n->locale, 'eng');
$_SERVER = $__SERVER;
}
/**
* testMap method
*
* @return void
*/
public function testMap() {
$l10n = new L10n();
$result = $l10n->map(array('afr', 'af'));
$expected = array('afr' => 'af', 'af' => 'afr');
$this->assertEqual($expected, $result);
$result = $l10n->map(array('alb', 'sq'));
$expected = array('alb' => 'sq', 'sq' => 'alb');
$this->assertEqual($expected, $result);
$result = $l10n->map(array('ara', 'ar'));
$expected = array('ara' => 'ar', 'ar' => 'ara');
$this->assertEqual($expected, $result);
$result = $l10n->map(array('hye', 'hy'));
$expected = array('hye' => 'hy', 'hy' => 'hye');
$this->assertEqual($expected, $result);
$result = $l10n->map(array('baq', 'eu'));
$expected = array('baq' => 'eu', 'eu' => 'baq');
$this->assertEqual($expected, $result);
$result = $l10n->map(array('baq', 'eu'));
$expected = array('baq' => 'eu', 'eu' => 'baq');
$this->assertEqual($expected, $result);
$result = $l10n->map(array('bos', 'bs'));
$expected = array('bos' => 'bs', 'bs' => 'bos');
$this->assertEqual($expected, $result);
$result = $l10n->map(array('bul', 'bg'));
$expected = array('bul' => 'bg', 'bg' => 'bul');
$this->assertEqual($expected, $result);
$result = $l10n->map(array('bel', 'be'));
$expected = array('bel' => 'be', 'be' => 'bel');
$this->assertEqual($expected, $result);
$result = $l10n->map(array('cat', 'ca'));
$expected = array('cat' => 'ca', 'ca' => 'cat');
$this->assertEqual($expected, $result);
$result = $l10n->map(array('chi', 'zh'));
$expected = array('chi' => 'zh', 'zh' => 'chi');
$this->assertEqual($expected, $result);
$result = $l10n->map(array('zho', 'zh'));
$expected = array('zho' => 'zh', 'zh' => 'chi');
$this->assertEqual($expected, $result);
$result = $l10n->map(array('hrv', 'hr'));
$expected = array('hrv' => 'hr', 'hr' => 'hrv');
$this->assertEqual($expected, $result);
$result = $l10n->map(array('ces', 'cs'));
$expected = array('ces' => 'cs', 'cs' => 'cze');
$this->assertEqual($expected, $result);
$result = $l10n->map(array('cze', 'cs'));
$expected = array('cze' => 'cs', 'cs' => 'cze');
$this->assertEqual($expected, $result);
$result = $l10n->map(array('dan', 'da'));
$expected = array('dan' => 'da', 'da' => 'dan');
$this->assertEqual($expected, $result);
$result = $l10n->map(array('dut', 'nl'));
$expected = array('dut' => 'nl', 'nl' => 'dut');
$this->assertEqual($expected, $result);
$result = $l10n->map(array('nld', 'nl'));
$expected = array('nld' => 'nl', 'nl' => 'dut');
$this->assertEqual($expected, $result);
$result = $l10n->map(array('nld'));
$expected = array('nld' => 'nl');
$this->assertEqual($expected, $result);
$result = $l10n->map(array('eng', 'en'));
$expected = array('eng' => 'en', 'en' => 'eng');
$this->assertEqual($expected, $result);
$result = $l10n->map(array('est', 'et'));
$expected = array('est' => 'et', 'et' => 'est');
$this->assertEqual($expected, $result);
$result = $l10n->map(array('fao', 'fo'));
$expected = array('fao' => 'fo', 'fo' => 'fao');
$this->assertEqual($expected, $result);
$result = $l10n->map(array('fas', 'fa'));
$expected = array('fas' => 'fa', 'fa' => 'fas');
$this->assertEqual($expected, $result);
$result = $l10n->map(array('per', 'fa'));
$expected = array('per' => 'fa', 'fa' => 'fas');
$this->assertEqual($expected, $result);
$result = $l10n->map(array('fin', 'fi'));
$expected = array('fin' => 'fi', 'fi' => 'fin');
$this->assertEqual($expected, $result);
$result = $l10n->map(array('fra', 'fr'));
$expected = array('fra' => 'fr', 'fr' => 'fre');
$this->assertEqual($expected, $result);
$result = $l10n->map(array('fre', 'fr'));
$expected = array('fre' => 'fr', 'fr' => 'fre');
$this->assertEqual($expected, $result);
$result = $l10n->map(array('gla', 'gd'));
$expected = array('gla' => 'gd', 'gd' => 'gla');
$this->assertEqual($expected, $result);
$result = $l10n->map(array('glg', 'gl'));
$expected = array('glg' => 'gl', 'gl' => 'glg');
$this->assertEqual($expected, $result);
$result = $l10n->map(array('deu', 'de'));
$expected = array('deu' => 'de', 'de' => 'deu');
$this->assertEqual($expected, $result);
$result = $l10n->map(array('ger', 'de'));
$expected = array('ger' => 'de', 'de' => 'deu');
$this->assertEqual($expected, $result);
$result = $l10n->map(array('ell', 'el'));
$expected = array('ell' => 'el', 'el' => 'gre');
$this->assertEqual($expected, $result);
$result = $l10n->map(array('gre', 'el'));
$expected = array('gre' => 'el', 'el' => 'gre');
$this->assertEqual($expected, $result);
$result = $l10n->map(array('heb', 'he'));
$expected = array('heb' => 'he', 'he' => 'heb');
$this->assertEqual($expected, $result);
$result = $l10n->map(array('hin', 'hi'));
$expected = array('hin' => 'hi', 'hi' => 'hin');
$this->assertEqual($expected, $result);
$result = $l10n->map(array('hun', 'hu'));
$expected = array('hun' => 'hu', 'hu' => 'hun');
$this->assertEqual($expected, $result);
$result = $l10n->map(array('ice', 'is'));
$expected = array('ice' => 'is', 'is' => 'ice');
$this->assertEqual($expected, $result);
$result = $l10n->map(array('isl', 'is'));
$expected = array('isl' => 'is', 'is' => 'ice');
$this->assertEqual($expected, $result);
$result = $l10n->map(array('ind', 'id'));
$expected = array('ind' => 'id', 'id' => 'ind');
$this->assertEqual($expected, $result);
$result = $l10n->map(array('gle', 'ga'));
$expected = array('gle' => 'ga', 'ga' => 'gle');
$this->assertEqual($expected, $result);
$result = $l10n->map(array('ita', 'it'));
$expected = array('ita' => 'it', 'it' => 'ita');
$this->assertEqual($expected, $result);
$result = $l10n->map(array('jpn', 'ja'));
$expected = array('jpn' => 'ja', 'ja' => 'jpn');
$this->assertEqual($expected, $result);
$result = $l10n->map(array('kor', 'ko'));
$expected = array('kor' => 'ko', 'ko' => 'kor');
$this->assertEqual($expected, $result);
$result = $l10n->map(array('lav', 'lv'));
$expected = array('lav' => 'lv', 'lv' => 'lav');
$this->assertEqual($expected, $result);
$result = $l10n->map(array('lit', 'lt'));
$expected = array('lit' => 'lt', 'lt' => 'lit');
$this->assertEqual($expected, $result);
$result = $l10n->map(array('mac', 'mk'));
$expected = array('mac' => 'mk', 'mk' => 'mac');
$this->assertEqual($expected, $result);
$result = $l10n->map(array('mkd', 'mk'));
$expected = array('mkd' => 'mk', 'mk' => 'mac');
$this->assertEqual($expected, $result);
$result = $l10n->map(array('may', 'ms'));
$expected = array('may' => 'ms', 'ms' => 'may');
$this->assertEqual($expected, $result);
$result = $l10n->map(array('msa', 'ms'));
$expected = array('msa' => 'ms', 'ms' => 'may');
$this->assertEqual($expected, $result);
$result = $l10n->map(array('mlt', 'mt'));
$expected = array('mlt' => 'mt', 'mt' => 'mlt');
$this->assertEqual($expected, $result);
$result = $l10n->map(array('nor', 'no'));
$expected = array('nor' => 'no', 'no' => 'nor');
$this->assertEqual($expected, $result);
$result = $l10n->map(array('nob', 'nb'));
$expected = array('nob' => 'nb', 'nb' => 'nob');
$this->assertEqual($expected, $result);
$result = $l10n->map(array('nno', 'nn'));
$expected = array('nno' => 'nn', 'nn' => 'nno');
$this->assertEqual($expected, $result);
$result = $l10n->map(array('pol', 'pl'));
$expected = array('pol' => 'pl', 'pl' => 'pol');
$this->assertEqual($expected, $result);
$result = $l10n->map(array('por', 'pt'));
$expected = array('por' => 'pt', 'pt' => 'por');
$this->assertEqual($expected, $result);
$result = $l10n->map(array('roh', 'rm'));
$expected = array('roh' => 'rm', 'rm' => 'roh');
$this->assertEqual($expected, $result);
$result = $l10n->map(array('ron', 'ro'));
$expected = array('ron' => 'ro', 'ro' => 'rum');
$this->assertEqual($expected, $result);
$result = $l10n->map(array('rum', 'ro'));
$expected = array('rum' => 'ro', 'ro' => 'rum');
$this->assertEqual($expected, $result);
$result = $l10n->map(array('rus', 'ru'));
$expected = array('rus' => 'ru', 'ru' => 'rus');
$this->assertEqual($expected, $result);
$result = $l10n->map(array('smi', 'sz'));
$expected = array('smi' => 'sz', 'sz' => 'smi');
$this->assertEqual($expected, $result);
$result = $l10n->map(array('scc', 'sr'));
$expected = array('scc' => 'sr', 'sr' => 'scc');
$this->assertEqual($expected, $result);
$result = $l10n->map(array('srp', 'sr'));
$expected = array('srp' => 'sr', 'sr' => 'scc');
$this->assertEqual($expected, $result);
$result = $l10n->map(array('slk', 'sk'));
$expected = array('slk' => 'sk', 'sk' => 'slo');
$this->assertEqual($expected, $result);
$result = $l10n->map(array('slo', 'sk'));
$expected = array('slo' => 'sk', 'sk' => 'slo');
$this->assertEqual($expected, $result);
$result = $l10n->map(array('slv', 'sl'));
$expected = array('slv' => 'sl', 'sl' => 'slv');
$this->assertEqual($expected, $result);
$result = $l10n->map(array('wen', 'sb'));
$expected = array('wen' => 'sb', 'sb' => 'wen');
$this->assertEqual($expected, $result);
$result = $l10n->map(array('spa', 'es'));
$expected = array('spa' => 'es', 'es' => 'spa');
$this->assertEqual($expected, $result);
$result = $l10n->map(array('swe', 'sv'));
$expected = array('swe' => 'sv', 'sv' => 'swe');
$this->assertEqual($expected, $result);
$result = $l10n->map(array('tha', 'th'));
$expected = array('tha' => 'th', 'th' => 'tha');
$this->assertEqual($expected, $result);
$result = $l10n->map(array('tso', 'ts'));
$expected = array('tso' => 'ts', 'ts' => 'tso');
$this->assertEqual($expected, $result);
$result = $l10n->map(array('tsn', 'tn'));
$expected = array('tsn' => 'tn', 'tn' => 'tsn');
$this->assertEqual($expected, $result);
$result = $l10n->map(array('tur', 'tr'));
$expected = array('tur' => 'tr', 'tr' => 'tur');
$this->assertEqual($expected, $result);
$result = $l10n->map(array('ukr', 'uk'));
$expected = array('ukr' => 'uk', 'uk' => 'ukr');
$this->assertEqual($expected, $result);
$result = $l10n->map(array('urd', 'ur'));
$expected = array('urd' => 'ur', 'ur' => 'urd');
$this->assertEqual($expected, $result);
$result = $l10n->map(array('ven', 've'));
$expected = array('ven' => 've', 've' => 'ven');
$this->assertEqual($expected, $result);
$result = $l10n->map(array('vie', 'vi'));
$expected = array('vie' => 'vi', 'vi' => 'vie');
$this->assertEqual($expected, $result);
$result = $l10n->map(array('xho', 'xh'));
$expected = array('xho' => 'xh', 'xh' => 'xho');
$this->assertEqual($expected, $result);
$result = $l10n->map(array('cy', 'cym'));
$expected = array('cym' => 'cy', 'cy' => 'cym');
$this->assertEqual($expected, $result);
$result = $l10n->map(array('yid', 'yi'));
$expected = array('yid' => 'yi', 'yi' => 'yid');
$this->assertEqual($expected, $result);
$result = $l10n->map(array('zul', 'zu'));
$expected = array('zul' => 'zu', 'zu' => 'zul');
$this->assertEqual($expected, $result);
}
/**
* testCatalog method
*
* @return void
*/
public function testCatalog() {
$l10n = new L10n();
$result = $l10n->catalog(array('af'));
$expected = array(
'af' => array('language' => 'Afrikaans', 'locale' => 'afr', 'localeFallback' => 'afr', 'charset' => 'utf-8', 'direction' => 'ltr')
);
$this->assertEqual($expected, $result);
$result = $l10n->catalog(array('ar', 'ar-ae', 'ar-bh', 'ar-dz', 'ar-eg', 'ar-iq', 'ar-jo', 'ar-kw', 'ar-lb', 'ar-ly', 'ar-ma',
'ar-om', 'ar-qa', 'ar-sa', 'ar-sy', 'ar-tn', 'ar-ye'));
$expected = array(
'ar' => array('language' => 'Arabic', 'locale' => 'ara', 'localeFallback' => 'ara', 'charset' => 'utf-8', 'direction' => 'rtl'),
'ar-ae' => array('language' => 'Arabic (U.A.E.)', 'locale' => 'ar_ae', 'localeFallback' => 'ara', 'charset' => 'utf-8', 'direction' => 'rtl'),
'ar-bh' => array('language' => 'Arabic (Bahrain)', 'locale' => 'ar_bh', 'localeFallback' => 'ara', 'charset' => 'utf-8', 'direction' => 'rtl'),
'ar-dz' => array('language' => 'Arabic (Algeria)', 'locale' => 'ar_dz', 'localeFallback' => 'ara', 'charset' => 'utf-8', 'direction' => 'rtl'),
'ar-eg' => array('language' => 'Arabic (Egypt)', 'locale' => 'ar_eg', 'localeFallback' => 'ara', 'charset' => 'utf-8', 'direction' => 'rtl'),
'ar-iq' => array('language' => 'Arabic (Iraq)', 'locale' => 'ar_iq', 'localeFallback' => 'ara', 'charset' => 'utf-8', 'direction' => 'rtl'),
'ar-jo' => array('language' => 'Arabic (Jordan)', 'locale' => 'ar_jo', 'localeFallback' => 'ara', 'charset' => 'utf-8', 'direction' => 'rtl'),
'ar-kw' => array('language' => 'Arabic (Kuwait)', 'locale' => 'ar_kw', 'localeFallback' => 'ara', 'charset' => 'utf-8', 'direction' => 'rtl'),
'ar-lb' => array('language' => 'Arabic (Lebanon)', 'locale' => 'ar_lb', 'localeFallback' => 'ara', 'charset' => 'utf-8', 'direction' => 'rtl'),
'ar-ly' => array('language' => 'Arabic (Libya)', 'locale' => 'ar_ly', 'localeFallback' => 'ara', 'charset' => 'utf-8', 'direction' => 'rtl'),
'ar-ma' => array('language' => 'Arabic (Morocco)', 'locale' => 'ar_ma', 'localeFallback' => 'ara', 'charset' => 'utf-8', 'direction' => 'rtl'),
'ar-om' => array('language' => 'Arabic (Oman)', 'locale' => 'ar_om', 'localeFallback' => 'ara', 'charset' => 'utf-8', 'direction' => 'rtl'),
'ar-qa' => array('language' => 'Arabic (Qatar)', 'locale' => 'ar_qa', 'localeFallback' => 'ara', 'charset' => 'utf-8', 'direction' => 'rtl'),
'ar-sa' => array('language' => 'Arabic (Saudi Arabia)', 'locale' => 'ar_sa', 'localeFallback' => 'ara', 'charset' => 'utf-8', 'direction' => 'rtl'),
'ar-sy' => array('language' => 'Arabic (Syria)', 'locale' => 'ar_sy', 'localeFallback' => 'ara', 'charset' => 'utf-8', 'direction' => 'rtl'),
'ar-tn' => array('language' => 'Arabic (Tunisia)', 'locale' => 'ar_tn', 'localeFallback' => 'ara', 'charset' => 'utf-8', 'direction' => 'rtl'),
'ar-ye' => array('language' => 'Arabic (Yemen)', 'locale' => 'ar_ye', 'localeFallback' => 'ara', 'charset' => 'utf-8', 'direction' => 'rtl')
);
$this->assertEqual($expected, $result);
$result = $l10n->catalog(array('be'));
$expected = array(
'be' => array('language' => 'Byelorussian', 'locale' => 'bel', 'localeFallback' => 'bel', 'charset' => 'utf-8', 'direction' => 'ltr')
);
$this->assertEqual($expected, $result);
$result = $l10n->catalog(array('bg'));
$expected = array(
'bg' => array('language' => 'Bulgarian', 'locale' => 'bul', 'localeFallback' => 'bul', 'charset' => 'utf-8', 'direction' => 'ltr')
);
$this->assertEqual($expected, $result);
$result = $l10n->catalog(array('bs'));
$expected = array(
'bs' => array('language' => 'Bosnian', 'locale' => 'bos', 'localeFallback' => 'bos', 'charset' => 'utf-8', 'direction' => 'ltr')
);
$this->assertEqual($expected, $result);
$result = $l10n->catalog(array('ca'));
$expected = array(
'ca' => array('language' => 'Catalan', 'locale' => 'cat', 'localeFallback' => 'cat', 'charset' => 'utf-8', 'direction' => 'ltr')
);
$this->assertEqual($expected, $result);
$result = $l10n->catalog(array('cs'));
$expected = array(
'cs' => array('language' => 'Czech', 'locale' => 'cze', 'localeFallback' => 'cze', 'charset' => 'utf-8', 'direction' => 'ltr')
);
$this->assertEqual($expected, $result);
$result = $l10n->catalog(array('da'));
$expected = array(
'da' => array('language' => 'Danish', 'locale' => 'dan', 'localeFallback' => 'dan', 'charset' => 'utf-8', 'direction' => 'ltr')
);
$this->assertEqual($expected, $result);
$result = $l10n->catalog(array('de', 'de-at', 'de-ch', 'de-de', 'de-li', 'de-lu'));
$expected = array(
'de' => array('language' => 'German (Standard)', 'locale' => 'deu', 'localeFallback' => 'deu', 'charset' => 'utf-8', 'direction' => 'ltr'),
'de-at' => array('language' => 'German (Austria)', 'locale' => 'de_at', 'localeFallback' => 'deu', 'charset' => 'utf-8', 'direction' => 'ltr'),
'de-ch' => array('language' => 'German (Swiss)', 'locale' => 'de_ch', 'localeFallback' => 'deu', 'charset' => 'utf-8', 'direction' => 'ltr'),
'de-de' => array('language' => 'German (Germany)', 'locale' => 'de_de', 'localeFallback' => 'deu', 'charset' => 'utf-8', 'direction' => 'ltr'),
'de-li' => array('language' => 'German (Liechtenstein)', 'locale' => 'de_li', 'localeFallback' => 'deu', 'charset' => 'utf-8', 'direction' => 'ltr'),
'de-lu' => array('language' => 'German (Luxembourg)', 'locale' => 'de_lu', 'localeFallback' => 'deu', 'charset' => 'utf-8', 'direction' => 'ltr')
);
$this->assertEqual($expected, $result);
$result = $l10n->catalog(array('e', 'el'));
$expected = array(
'e' => array('language' => 'Greek', 'locale' => 'gre', 'localeFallback' => 'gre', 'charset' => 'utf-8', 'direction' => 'ltr'),
'el' => array('language' => 'Greek', 'locale' => 'gre', 'localeFallback' => 'gre', 'charset' => 'utf-8', 'direction' => 'ltr')
);
$this->assertEqual($expected, $result);
$result = $l10n->catalog(array('en', 'en-au', 'en-bz', 'en-ca', 'en-gb', 'en-ie', 'en-jm', 'en-nz', 'en-tt', 'en-us', 'en-za'));
$expected = array(
'en' => array('language' => 'English', 'locale' => 'eng', 'localeFallback' => 'eng', 'charset' => 'utf-8', 'direction' => 'ltr'),
'en-au' => array('language' => 'English (Australian)', 'locale' => 'en_au', 'localeFallback' => 'eng', 'charset' => 'utf-8', 'direction' => 'ltr'),
'en-bz' => array('language' => 'English (Belize)', 'locale' => 'en_bz', 'localeFallback' => 'eng', 'charset' => 'utf-8', 'direction' => 'ltr'),
'en-ca' => array('language' => 'English (Canadian)', 'locale' => 'en_ca', 'localeFallback' => 'eng', 'charset' => 'utf-8', 'direction' => 'ltr'),
'en-gb' => array('language' => 'English (British)', 'locale' => 'en_gb', 'localeFallback' => 'eng', 'charset' => 'utf-8', 'direction' => 'ltr'),
'en-ie' => array('language' => 'English (Ireland)', 'locale' => 'en_ie', 'localeFallback' => 'eng', 'charset' => 'utf-8', 'direction' => 'ltr'),
'en-jm' => array('language' => 'English (Jamaica)', 'locale' => 'en_jm', 'localeFallback' => 'eng', 'charset' => 'utf-8', 'direction' => 'ltr'),
'en-nz' => array('language' => 'English (New Zealand)', 'locale' => 'en_nz', 'localeFallback' => 'eng', 'charset' => 'utf-8', 'direction' => 'ltr'),
'en-tt' => array('language' => 'English (Trinidad)', 'locale' => 'en_tt', 'localeFallback' => 'eng', 'charset' => 'utf-8', 'direction' => 'ltr'),
'en-us' => array('language' => 'English (United States)', 'locale' => 'en_us', 'localeFallback' => 'eng', 'charset' => 'utf-8', 'direction' => 'ltr'),
'en-za' => array('language' => 'English (South Africa)', 'locale' => 'en_za', 'localeFallback' => 'eng', 'charset' => 'utf-8', 'direction' => 'ltr')
);
$this->assertEqual($expected, $result);
$result = $l10n->catalog(array('es', 'es-ar', 'es-bo', 'es-cl', 'es-co', 'es-cr', 'es-do', 'es-ec', 'es-es', 'es-gt', 'es-hn',
'es-mx', 'es-ni', 'es-pa', 'es-pe', 'es-pr', 'es-py', 'es-sv', 'es-uy', 'es-ve'));
$expected = array(
'es' => array('language' => 'Spanish (Spain - Traditional)', 'locale' => 'spa', 'localeFallback' => 'spa', 'charset' => 'utf-8', 'direction' => 'ltr'),
'es-ar' => array('language' => 'Spanish (Argentina)', 'locale' => 'es_ar', 'localeFallback' => 'spa', 'charset' => 'utf-8', 'direction' => 'ltr'),
'es-bo' => array('language' => 'Spanish (Bolivia)', 'locale' => 'es_bo', 'localeFallback' => 'spa', 'charset' => 'utf-8', 'direction' => 'ltr'),
'es-cl' => array('language' => 'Spanish (Chile)', 'locale' => 'es_cl', 'localeFallback' => 'spa', 'charset' => 'utf-8', 'direction' => 'ltr'),
'es-co' => array('language' => 'Spanish (Colombia)', 'locale' => 'es_co', 'localeFallback' => 'spa', 'charset' => 'utf-8', 'direction' => 'ltr'),
'es-cr' => array('language' => 'Spanish (Costa Rica)', 'locale' => 'es_cr', 'localeFallback' => 'spa', 'charset' => 'utf-8', 'direction' => 'ltr'),
'es-do' => array('language' => 'Spanish (Dominican Republic)', 'locale' => 'es_do', 'localeFallback' => 'spa', 'charset' => 'utf-8', 'direction' => 'ltr'),
'es-ec' => array('language' => 'Spanish (Ecuador)', 'locale' => 'es_ec', 'localeFallback' => 'spa', 'charset' => 'utf-8', 'direction' => 'ltr'),
'es-es' => array('language' => 'Spanish (Spain)', 'locale' => 'es_es', 'localeFallback' => 'spa', 'charset' => 'utf-8', 'direction' => 'ltr'),
'es-gt' => array('language' => 'Spanish (Guatemala)', 'locale' => 'es_gt', 'localeFallback' => 'spa', 'charset' => 'utf-8', 'direction' => 'ltr'),
'es-hn' => array('language' => 'Spanish (Honduras)', 'locale' => 'es_hn', 'localeFallback' => 'spa', 'charset' => 'utf-8', 'direction' => 'ltr'),
'es-mx' => array('language' => 'Spanish (Mexican)', 'locale' => 'es_mx', 'localeFallback' => 'spa', 'charset' => 'utf-8', 'direction' => 'ltr'),
'es-ni' => array('language' => 'Spanish (Nicaragua)', 'locale' => 'es_ni', 'localeFallback' => 'spa', 'charset' => 'utf-8', 'direction' => 'ltr'),
'es-pa' => array('language' => 'Spanish (Panama)', 'locale' => 'es_pa', 'localeFallback' => 'spa', 'charset' => 'utf-8', 'direction' => 'ltr'),
'es-pe' => array('language' => 'Spanish (Peru)', 'locale' => 'es_pe', 'localeFallback' => 'spa', 'charset' => 'utf-8', 'direction' => 'ltr'),
'es-pr' => array('language' => 'Spanish (Puerto Rico)', 'locale' => 'es_pr', 'localeFallback' => 'spa', 'charset' => 'utf-8', 'direction' => 'ltr'),
'es-py' => array('language' => 'Spanish (Paraguay)', 'locale' => 'es_py', 'localeFallback' => 'spa', 'charset' => 'utf-8', 'direction' => 'ltr'),
'es-sv' => array('language' => 'Spanish (El Salvador)', 'locale' => 'es_sv', 'localeFallback' => 'spa', 'charset' => 'utf-8', 'direction' => 'ltr'),
'es-uy' => array('language' => 'Spanish (Uruguay)', 'locale' => 'es_uy', 'localeFallback' => 'spa', 'charset' => 'utf-8', 'direction' => 'ltr'),
'es-ve' => array('language' => 'Spanish (Venezuela)', 'locale' => 'es_ve', 'localeFallback' => 'spa', 'charset' => 'utf-8', 'direction' => 'ltr')
);
$this->assertEqual($expected, $result);
$result = $l10n->catalog(array('et'));
$expected = array(
'et' => array('language' => 'Estonian', 'locale' => 'est', 'localeFallback' => 'est', 'charset' => 'utf-8', 'direction' => 'ltr')
);
$this->assertEqual($expected, $result);
$result = $l10n->catalog(array('eu'));
$expected = array(
'eu' => array('language' => 'Basque', 'locale' => 'baq', 'localeFallback' => 'baq', 'charset' => 'utf-8', 'direction' => 'ltr')
);
$this->assertEqual($expected, $result);
$result = $l10n->catalog(array('fa'));
$expected = array(
'fa' => array('language' => 'Farsi', 'locale' => 'per', 'localeFallback' => 'per', 'charset' => 'utf-8', 'direction' => 'rtl')
);
$this->assertEqual($expected, $result);
$result = $l10n->catalog(array('fi'));
$expected = array(
'fi' => array('language' => 'Finnish', 'locale' => 'fin', 'localeFallback' => 'fin', 'charset' => 'utf-8', 'direction' => 'ltr')
);
$this->assertEqual($expected, $result);
$result = $l10n->catalog(array('fo'));
$expected = array(
'fo' => array('language' => 'Faeroese', 'locale' => 'fao', 'localeFallback' => 'fao', 'charset' => 'utf-8', 'direction' => 'ltr')
);
$this->assertEqual($expected, $result);
$result = $l10n->catalog(array('fr', 'fr-be', 'fr-ca', 'fr-ch', 'fr-fr', 'fr-lu'));
$expected = array(
'fr' => array('language' => 'French (Standard)', 'locale' => 'fre', 'localeFallback' => 'fre', 'charset' => 'utf-8', 'direction' => 'ltr'),
'fr-be' => array('language' => 'French (Belgium)', 'locale' => 'fr_be', 'localeFallback' => 'fre', 'charset' => 'utf-8', 'direction' => 'ltr'),
'fr-ca' => array('language' => 'French (Canadian)', 'locale' => 'fr_ca', 'localeFallback' => 'fre', 'charset' => 'utf-8', 'direction' => 'ltr'),
'fr-ch' => array('language' => 'French (Swiss)', 'locale' => 'fr_ch', 'localeFallback' => 'fre', 'charset' => 'utf-8', 'direction' => 'ltr'),
'fr-fr' => array('language' => 'French (France)', 'locale' => 'fr_fr', 'localeFallback' => 'fre', 'charset' => 'utf-8', 'direction' => 'ltr'),
'fr-lu' => array('language' => 'French (Luxembourg)', 'locale' => 'fr_lu', 'localeFallback' => 'fre', 'charset' => 'utf-8', 'direction' => 'ltr')
);
$this->assertEqual($expected, $result);
$result = $l10n->catalog(array('ga'));
$expected = array(
'ga' => array('language' => 'Irish', 'locale' => 'gle', 'localeFallback' => 'gle', 'charset' => 'utf-8', 'direction' => 'ltr')
);
$this->assertEqual($expected, $result);
$result = $l10n->catalog(array('gd', 'gd-ie'));
$expected = array(
'gd' => array('language' => 'Gaelic (Scots)', 'locale' => 'gla', 'localeFallback' => 'gla', 'charset' => 'utf-8', 'direction' => 'ltr'),
'gd-ie' => array('language' => 'Gaelic (Irish)', 'locale' => 'gd_ie', 'localeFallback' => 'gla', 'charset' => 'utf-8', 'direction' => 'ltr')
);
$this->assertEqual($expected, $result);
$result = $l10n->catalog(array('gl'));
$expected = array(
'gl' => array('language' => 'Galician', 'locale' => 'glg', 'localeFallback' => 'glg', 'charset' => 'utf-8', 'direction' => 'ltr')
);
$this->assertEqual($expected, $result);
$result = $l10n->catalog(array('he'));
$expected = array(
'he' => array('language' => 'Hebrew', 'locale' => 'heb', 'localeFallback' => 'heb', 'charset' => 'utf-8', 'direction' => 'rtl')
);
$this->assertEqual($expected, $result);
$result = $l10n->catalog(array('hi'));
$expected = array(
'hi' => array('language' => 'Hindi', 'locale' => 'hin', 'localeFallback' => 'hin', 'charset' => 'utf-8', 'direction' => 'ltr')
);
$this->assertEqual($expected, $result);
$result = $l10n->catalog(array('hr'));
$expected = array(
'hr' => array('language' => 'Croatian', 'locale' => 'hrv', 'localeFallback' => 'hrv', 'charset' => 'utf-8', 'direction' => 'ltr')
);
$this->assertEqual($expected, $result);
$result = $l10n->catalog(array('hu'));
$expected = array(
'hu' => array('language' => 'Hungarian', 'locale' => 'hun', 'localeFallback' => 'hun', 'charset' => 'utf-8', 'direction' => 'ltr')
);
$this->assertEqual($expected, $result);
$result = $l10n->catalog(array('hy'));
$expected = array(
'hy' => array('language' => 'Armenian - Armenia', 'locale' => 'hye', 'localeFallback' => 'hye', 'charset' => 'utf-8', 'direction' => 'ltr')
);
$this->assertEqual($expected, $result);
$result = $l10n->catalog(array('id', 'in'));
$expected = array(
'id' => array('language' => 'Indonesian', 'locale' => 'ind', 'localeFallback' => 'ind', 'charset' => 'utf-8', 'direction' => 'ltr'),
'in' => array('language' => 'Indonesian', 'locale' => 'ind', 'localeFallback' => 'ind', 'charset' => 'utf-8', 'direction' => 'ltr')
);
$this->assertEqual($expected, $result);
$result = $l10n->catalog(array('is'));
$expected = array(
'is' => array('language' => 'Icelandic', 'locale' => 'ice', 'localeFallback' => 'ice', 'charset' => 'utf-8', 'direction' => 'ltr')
);
$this->assertEqual($expected, $result);
$result = $l10n->catalog(array('it', 'it-ch'));
$expected = array(
'it' => array('language' => 'Italian', 'locale' => 'ita', 'localeFallback' => 'ita', 'charset' => 'utf-8', 'direction' => 'ltr'),
'it-ch' => array('language' => 'Italian (Swiss) ', 'locale' => 'it_ch', 'localeFallback' => 'ita', 'charset' => 'utf-8', 'direction' => 'ltr')
);
$this->assertEqual($expected, $result);
$result = $l10n->catalog(array('ja'));
$expected = array(
'ja' => array('language' => 'Japanese', 'locale' => 'jpn', 'localeFallback' => 'jpn', 'charset' => 'utf-8', 'direction' => 'ltr')
);
$this->assertEqual($expected, $result);
$result = $l10n->catalog(array('ko', 'ko-kp', 'ko-kr'));
$expected = array(
'ko' => array('language' => 'Korean', 'locale' => 'kor', 'localeFallback' => 'kor', 'charset' => 'kr', 'direction' => 'ltr'),
'ko-kp' => array('language' => 'Korea (North)', 'locale' => 'ko_kp', 'localeFallback' => 'kor', 'charset' => 'kr', 'direction' => 'ltr'),
'ko-kr' => array('language' => 'Korea (South)', 'locale' => 'ko_kr', 'localeFallback' => 'kor', 'charset' => 'kr', 'direction' => 'ltr')
);
$this->assertEqual($expected, $result);
$result = $l10n->catalog(array('koi8-r', 'ru', 'ru-mo'));
$expected = array(
'koi8-r' => array('language' => 'Russian', 'locale' => 'koi8_r', 'localeFallback' => 'rus', 'charset' => 'koi8-r', 'direction' => 'ltr'),
'ru' => array('language' => 'Russian', 'locale' => 'rus', 'localeFallback' => 'rus', 'charset' => 'utf-8', 'direction' => 'ltr'),
'ru-mo' => array('language' => 'Russian (Moldavia)', 'locale' => 'ru_mo', 'localeFallback' => 'rus', 'charset' => 'utf-8', 'direction' => 'ltr')
);
$this->assertEqual($expected, $result);
$result = $l10n->catalog(array('lt'));
$expected = array(
'lt' => array('language' => 'Lithuanian', 'locale' => 'lit', 'localeFallback' => 'lit', 'charset' => 'utf-8', 'direction' => 'ltr')
);
$this->assertEqual($expected, $result);
$result = $l10n->catalog(array('lv'));
$expected = array(
'lv' => array('language' => 'Latvian', 'locale' => 'lav', 'localeFallback' => 'lav', 'charset' => 'utf-8', 'direction' => 'ltr')
);
$this->assertEqual($expected, $result);
$result = $l10n->catalog(array('mk', 'mk-mk'));
$expected = array(
'mk' => array('language' => 'FYRO Macedonian', 'locale' => 'mk', 'localeFallback' => 'mac', 'charset' => 'utf-8', 'direction' => 'ltr'),
'mk-mk' => array('language' => 'Macedonian', 'locale' => 'mk_mk', 'localeFallback' => 'mac', 'charset' => 'utf-8', 'direction' => 'ltr')
);
$this->assertEqual($expected, $result);
$result = $l10n->catalog(array('ms'));
$expected = array(
'ms' => array('language' => 'Malaysian', 'locale' => 'may', 'localeFallback' => 'may', 'charset' => 'utf-8', 'direction' => 'ltr')
);
$this->assertEqual($expected, $result);
$result = $l10n->catalog(array('mt'));
$expected = array(
'mt' => array('language' => 'Maltese', 'locale' => 'mlt', 'localeFallback' => 'mlt', 'charset' => 'utf-8', 'direction' => 'ltr')
);
$this->assertEqual($expected, $result);
$result = $l10n->catalog(array('n', 'nl', 'nl-be'));
$expected = array(
'n' => array('language' => 'Dutch (Standard)', 'locale' => 'dut', 'localeFallback' => 'dut', 'charset' => 'utf-8', 'direction' => 'ltr'),
'nl' => array('language' => 'Dutch (Standard)', 'locale' => 'dut', 'localeFallback' => 'dut', 'charset' => 'utf-8', 'direction' => 'ltr'),
'nl-be' => array('language' => 'Dutch (Belgium)', 'locale' => 'nl_be', 'localeFallback' => 'dut', 'charset' => 'utf-8', 'direction' => 'ltr')
);
$this->assertEqual($expected, $result);
$result = $l10n->catalog('nl');
$expected = array('language' => 'Dutch (Standard)', 'locale' => 'dut', 'localeFallback' => 'dut', 'charset' => 'utf-8', 'direction' => 'ltr');
$this->assertEqual($expected, $result);
$result = $l10n->catalog('nld');
$expected = array('language' => 'Dutch (Standard)', 'locale' => 'dut', 'localeFallback' => 'dut', 'charset' => 'utf-8', 'direction' => 'ltr');
$this->assertEqual($expected, $result);
$result = $l10n->catalog('dut');
$expected = array('language' => 'Dutch (Standard)', 'locale' => 'dut', 'localeFallback' => 'dut', 'charset' => 'utf-8', 'direction' => 'ltr');
$this->assertEqual($expected, $result);
$result = $l10n->catalog(array('nb'));
$expected = array(
'nb' => array('language' => 'Norwegian Bokmal', 'locale' => 'nob', 'localeFallback' => 'nor', 'charset' => 'utf-8', 'direction' => 'ltr')
);
$this->assertEqual($expected, $result);
$result = $l10n->catalog(array('nn', 'no'));
$expected = array(
'nn' => array('language' => 'Norwegian Nynorsk', 'locale' => 'nno', 'localeFallback' => 'nor', 'charset' => 'utf-8', 'direction' => 'ltr'),
'no' => array('language' => 'Norwegian', 'locale' => 'nor', 'localeFallback' => 'nor', 'charset' => 'utf-8', 'direction' => 'ltr')
);
$this->assertEqual($expected, $result);
$result = $l10n->catalog(array('p', 'pl'));
$expected = array(
'p' => array('language' => 'Polish', 'locale' => 'pol', 'localeFallback' => 'pol', 'charset' => 'utf-8', 'direction' => 'ltr'),
'pl' => array('language' => 'Polish', 'locale' => 'pol', 'localeFallback' => 'pol', 'charset' => 'utf-8', 'direction' => 'ltr')
);
$this->assertEqual($expected, $result);
$result = $l10n->catalog(array('pt', 'pt-br'));
$expected = array(
'pt' => array('language' => 'Portuguese (Portugal)', 'locale' => 'por', 'localeFallback' => 'por', 'charset' => 'utf-8', 'direction' => 'ltr'),
'pt-br' => array('language' => 'Portuguese (Brazil)', 'locale' => 'pt_br', 'localeFallback' => 'por', 'charset' => 'utf-8', 'direction' => 'ltr')
);
$this->assertEqual($expected, $result);
$result = $l10n->catalog(array('rm'));
$expected = array(
'rm' => array('language' => 'Rhaeto-Romanic', 'locale' => 'roh', 'localeFallback' => 'roh', 'charset' => 'utf-8', 'direction' => 'ltr')
);
$this->assertEqual($expected, $result);
$result = $l10n->catalog(array('ro', 'ro-mo'));
$expected = array(
'ro' => array('language' => 'Romanian', 'locale' => 'rum', 'localeFallback' => 'rum', 'charset' => 'utf-8', 'direction' => 'ltr'),
'ro-mo' => array('language' => 'Romanian (Moldavia)', 'locale' => 'ro_mo', 'localeFallback' => 'rum', 'charset' => 'utf-8', 'direction' => 'ltr')
);
$this->assertEqual($expected, $result);
$result = $l10n->catalog(array('sb'));
$expected = array(
'sb' => array('language' => 'Sorbian', 'locale' => 'wen', 'localeFallback' => 'wen', 'charset' => 'utf-8', 'direction' => 'ltr')
);
$this->assertEqual($expected, $result);
$result = $l10n->catalog(array('sk'));
$expected = array(
'sk' => array('language' => 'Slovak', 'locale' => 'slo', 'localeFallback' => 'slo', 'charset' => 'utf-8', 'direction' => 'ltr')
);
$this->assertEqual($expected, $result);
$result = $l10n->catalog(array('sl'));
$expected = array(
'sl' => array('language' => 'Slovenian', 'locale' => 'slv', 'localeFallback' => 'slv', 'charset' => 'utf-8', 'direction' => 'ltr')
);
$this->assertEqual($expected, $result);
$result = $l10n->catalog(array('sq'));
$expected = array(
'sq' => array('language' => 'Albanian', 'locale' => 'alb', 'localeFallback' => 'alb', 'charset' => 'utf-8', 'direction' => 'ltr')
);
$this->assertEqual($expected, $result);
$result = $l10n->catalog(array('sr'));
$expected = array(
'sr' => array('language' => 'Serbian', 'locale' => 'scc', 'localeFallback' => 'scc', 'charset' => 'utf-8', 'direction' => 'ltr')
);
$this->assertEqual($expected, $result);
$result = $l10n->catalog(array('sv', 'sv-fi'));
$expected = array(
'sv' => array('language' => 'Swedish', 'locale' => 'swe', 'localeFallback' => 'swe', 'charset' => 'utf-8', 'direction' => 'ltr'),
'sv-fi' => array('language' => 'Swedish (Finland)', 'locale' => 'sv_fi', 'localeFallback' => 'swe', 'charset' => 'utf-8', 'direction' => 'ltr')
);
$this->assertEqual($expected, $result);
$result = $l10n->catalog(array('sx'));
$expected = array(
'sx' => array('language' => 'Sutu', 'locale' => 'sx', 'localeFallback' => 'sx', 'charset' => 'utf-8', 'direction' => 'ltr')
);
$this->assertEqual($expected, $result);
$result = $l10n->catalog(array('sz'));
$expected = array(
'sz' => array('language' => 'Sami (Lappish)', 'locale' => 'smi', 'localeFallback' => 'smi', 'charset' => 'utf-8', 'direction' => 'ltr')
);
$this->assertEqual($expected, $result);
$result = $l10n->catalog(array('th'));
$expected = array(
'th' => array('language' => 'Thai', 'locale' => 'tha', 'localeFallback' => 'tha', 'charset' => 'utf-8', 'direction' => 'ltr')
);
$this->assertEqual($expected, $result);
$result = $l10n->catalog(array('tn'));
$expected = array(
'tn' => array('language' => 'Tswana', 'locale' => 'tsn', 'localeFallback' => 'tsn', 'charset' => 'utf-8', 'direction' => 'ltr')
);
$this->assertEqual($expected, $result);
$result = $l10n->catalog(array('tr'));
$expected = array(
'tr' => array('language' => 'Turkish', 'locale' => 'tur', 'localeFallback' => 'tur', 'charset' => 'utf-8', 'direction' => 'ltr')
);
$this->assertEqual($expected, $result);
$result = $l10n->catalog(array('ts'));
$expected = array(
'ts' => array('language' => 'Tsonga', 'locale' => 'tso', 'localeFallback' => 'tso', 'charset' => 'utf-8', 'direction' => 'ltr')
);
$this->assertEqual($expected, $result);
$result = $l10n->catalog(array('uk'));
$expected = array(
'uk' => array('language' => 'Ukrainian', 'locale' => 'ukr', 'localeFallback' => 'ukr', 'charset' => 'utf-8', 'direction' => 'ltr')
);
$this->assertEqual($expected, $result);
$result = $l10n->catalog(array('ur'));
$expected = array(
'ur' => array('language' => 'Urdu', 'locale' => 'urd', 'localeFallback' => 'urd', 'charset' => 'utf-8', 'direction' => 'rtl')
);
$this->assertEqual($expected, $result);
$result = $l10n->catalog(array('ve'));
$expected = array(
've' => array('language' => 'Venda', 'locale' => 'ven', 'localeFallback' => 'ven', 'charset' => 'utf-8', 'direction' => 'ltr')
);
$this->assertEqual($expected, $result);
$result = $l10n->catalog(array('vi'));
$expected = array(
'vi' => array('language' => 'Vietnamese', 'locale' => 'vie', 'localeFallback' => 'vie', 'charset' => 'utf-8', 'direction' => 'ltr')
);
$this->assertEqual($expected, $result);
$result = $l10n->catalog(array('cy'));
$expected = array(
'cy' => array('language' => 'Welsh', 'locale' => 'cym', 'localeFallback' => 'cym', 'charset' => 'utf-8',
'direction' => 'ltr')
);
$this->assertEqual($expected, $result);
$result = $l10n->catalog(array('xh'));
$expected = array(
'xh' => array('language' => 'Xhosa', 'locale' => 'xho', 'localeFallback' => 'xho', 'charset' => 'utf-8', 'direction' => 'ltr')
);
$this->assertEqual($expected, $result);
$result = $l10n->catalog(array('yi'));
$expected = array(
'yi' => array('language' => 'Yiddish', 'locale' => 'yid', 'localeFallback' => 'yid', 'charset' => 'utf-8', 'direction' => 'ltr')
);
$this->assertEqual($expected, $result);
$result = $l10n->catalog(array('zh', 'zh-cn', 'zh-hk', 'zh-sg', 'zh-tw'));
$expected = array(
'zh' => array('language' => 'Chinese', 'locale' => 'chi', 'localeFallback' => 'chi', 'charset' => 'utf-8', 'direction' => 'ltr'),
'zh-cn' => array('language' => 'Chinese (PRC)', 'locale' => 'zh_cn', 'localeFallback' => 'chi', 'charset' => 'GB2312', 'direction' => 'ltr'),
'zh-hk' => array('language' => 'Chinese (Hong Kong)', 'locale' => 'zh_hk', 'localeFallback' => 'chi', 'charset' => 'utf-8', 'direction' => 'ltr'),
'zh-sg' => array('language' => 'Chinese (Singapore)', 'locale' => 'zh_sg', 'localeFallback' => 'chi', 'charset' => 'utf-8', 'direction' => 'ltr'),
'zh-tw' => array('language' => 'Chinese (Taiwan)', 'locale' => 'zh_tw', 'localeFallback' => 'chi', 'charset' => 'utf-8', 'direction' => 'ltr')
);
$this->assertEqual($expected, $result);
$result = $l10n->catalog(array('zu'));
$expected = array(
'zu' => array('language' => 'Zulu', 'locale' => 'zul', 'localeFallback' => 'zul', 'charset' => 'utf-8', 'direction' => 'ltr')
);
$this->assertEqual($expected, $result);
$result = $l10n->catalog(array('en-nz', 'es-do', 'sz', 'ar-lb', 'zh-hk', 'pt-br'));
$expected = array(
'en-nz' => array('language' => 'English (New Zealand)', 'locale' => 'en_nz', 'localeFallback' => 'eng', 'charset' => 'utf-8', 'direction' => 'ltr'),
'es-do' => array('language' => 'Spanish (Dominican Republic)', 'locale' => 'es_do', 'localeFallback' => 'spa', 'charset' => 'utf-8', 'direction' => 'ltr'),
'sz' => array('language' => 'Sami (Lappish)', 'locale' => 'smi', 'localeFallback' => 'smi', 'charset' => 'utf-8', 'direction' => 'ltr'),
'ar-lb' => array('language' => 'Arabic (Lebanon)', 'locale' => 'ar_lb', 'localeFallback' => 'ara', 'charset' => 'utf-8', 'direction' => 'rtl'),
'zh-hk' => array('language' => 'Chinese (Hong Kong)', 'locale' => 'zh_hk', 'localeFallback' => 'chi', 'charset' => 'utf-8', 'direction' => 'ltr'),
'pt-br' => array('language' => 'Portuguese (Brazil)', 'locale' => 'pt_br', 'localeFallback' => 'por', 'charset' => 'utf-8', 'direction' => 'ltr')
);
$this->assertEqual($expected, $result);
$result = $l10n->catalog(array('eng', 'deu', 'zho', 'rum', 'zul', 'yid'));
$expected = array(
'eng' => array('language' => 'English', 'locale' => 'eng', 'localeFallback' => 'eng', 'charset' => 'utf-8', 'direction' => 'ltr'),
'deu' => array('language' => 'German (Standard)', 'locale' => 'deu', 'localeFallback' => 'deu', 'charset' => 'utf-8', 'direction' => 'ltr'),
'zho' => array('language' => 'Chinese', 'locale' => 'chi', 'localeFallback' => 'chi', 'charset' => 'utf-8', 'direction' => 'ltr'),
'rum' => array('language' => 'Romanian', 'locale' => 'rum', 'localeFallback' => 'rum', 'charset' => 'utf-8', 'direction' => 'ltr'),
'zul' => array('language' => 'Zulu', 'locale' => 'zul', 'localeFallback' => 'zul', 'charset' => 'utf-8', 'direction' => 'ltr'),
'yid' => array('language' => 'Yiddish', 'locale' => 'yid', 'localeFallback' => 'yid', 'charset' => 'utf-8', 'direction' => 'ltr')
);
$this->assertEqual($expected, $result);
}
}
| 0001-bee | trunk/cakephp2/lib/Cake/Test/Case/I18n/L10nTest.php | PHP | gpl3 | 44,440 |
<?php
/**
* I18nTest file
*
* PHP 5
*
* CakePHP(tm) Tests <http://book.cakephp.org/view/1196/Testing>
* Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice
*
* @copyright Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://book.cakephp.org/view/1196/Testing CakePHP(tm) Tests
* @package Cake.Test.Case.I18n
* @since CakePHP(tm) v 1.2.0.5432
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
App::uses('I18n', 'I18n');
/**
* I18nTest class
*
* @package Cake.Test.Case.I18n
*/
class I18nTest extends CakeTestCase {
/**
* setUp method
*
* @return void
*/
public function setUp() {
Cache::delete('object_map', '_cake_core_');
App::build(array(
'locales' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Locale' . DS),
'plugins' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS)
), true);
CakePlugin::loadAll();
}
/**
* tearDown method
*
* @return void
*/
public function tearDown() {
Cache::delete('object_map', '_cake_core_');
App::build();
CakePlugin::unload();
}
public function testTranslationCaching() {
Configure::write('Config.language', 'cache_test_po');
$i18n = i18n::getInstance();
// reset internally stored entries
I18n::clear();
Cache::clear(false, '_cake_core_');
$lang = Configure::read('Config.language');#$i18n->l10n->locale;
Cache::config('_cake_core_', Cache::config('default'));
// make some calls to translate using different domains
$this->assertEqual('Dom 1 Foo', I18n::translate('dom1.foo', false, 'dom1'));
$this->assertEqual('Dom 1 Bar', I18n::translate('dom1.bar', false, 'dom1'));
$domains = I18n::domains();
$this->assertEqual('Dom 1 Foo', $domains['dom1']['cache_test_po']['LC_MESSAGES']['dom1.foo']);
// reset internally stored entries
I18n::clear();
// now only dom1 should be in cache
$cachedDom1 = Cache::read('dom1_' . $lang, '_cake_core_');
$this->assertEqual('Dom 1 Foo', $cachedDom1['LC_MESSAGES']['dom1.foo']);
$this->assertEqual('Dom 1 Bar', $cachedDom1['LC_MESSAGES']['dom1.bar']);
// dom2 not in cache
$this->assertFalse(Cache::read('dom2_' . $lang, '_cake_core_'));
// translate a item of dom2 (adds dom2 to cache)
$this->assertEqual('Dom 2 Foo', I18n::translate('dom2.foo', false, 'dom2'));
// verify dom2 was cached through manual read from cache
$cachedDom2 = Cache::read('dom2_' . $lang, '_cake_core_');
$this->assertEqual('Dom 2 Foo', $cachedDom2['LC_MESSAGES']['dom2.foo']);
$this->assertEqual('Dom 2 Bar', $cachedDom2['LC_MESSAGES']['dom2.bar']);
// modify cache entry manually to verify that dom1 entries now will be read from cache
$cachedDom1['LC_MESSAGES']['dom1.foo'] = 'FOO';
Cache::write('dom1_' . $lang, $cachedDom1, '_cake_core_');
$this->assertEqual('FOO', I18n::translate('dom1.foo', false, 'dom1'));
}
/**
* testDefaultStrings method
*
* @return void
*/
public function testDefaultStrings() {
$singular = $this->__singular();
$this->assertEqual('Plural Rule 1', $singular);
$plurals = $this->__plural();
$this->assertTrue(in_array('0 = 0 or > 1', $plurals));
$this->assertTrue(in_array('1 = 1', $plurals));
$this->assertTrue(in_array('2 = 0 or > 1', $plurals));
$this->assertTrue(in_array('3 = 0 or > 1', $plurals));
$this->assertTrue(in_array('4 = 0 or > 1', $plurals));
$this->assertTrue(in_array('5 = 0 or > 1', $plurals));
$this->assertTrue(in_array('6 = 0 or > 1', $plurals));
$this->assertTrue(in_array('7 = 0 or > 1', $plurals));
$this->assertTrue(in_array('8 = 0 or > 1', $plurals));
$this->assertTrue(in_array('9 = 0 or > 1', $plurals));
$this->assertTrue(in_array('10 = 0 or > 1', $plurals));
$this->assertTrue(in_array('11 = 0 or > 1', $plurals));
$this->assertTrue(in_array('12 = 0 or > 1', $plurals));
$this->assertTrue(in_array('13 = 0 or > 1', $plurals));
$this->assertTrue(in_array('14 = 0 or > 1', $plurals));
$this->assertTrue(in_array('15 = 0 or > 1', $plurals));
$this->assertTrue(in_array('16 = 0 or > 1', $plurals));
$this->assertTrue(in_array('17 = 0 or > 1', $plurals));
$this->assertTrue(in_array('18 = 0 or > 1', $plurals));
$this->assertTrue(in_array('19 = 0 or > 1', $plurals));
$this->assertTrue(in_array('20 = 0 or > 1', $plurals));
$this->assertTrue(in_array('21 = 0 or > 1', $plurals));
$this->assertTrue(in_array('22 = 0 or > 1', $plurals));
$this->assertTrue(in_array('23 = 0 or > 1', $plurals));
$this->assertTrue(in_array('24 = 0 or > 1', $plurals));
$this->assertTrue(in_array('25 = 0 or > 1', $plurals));
$coreSingular = $this->__singularFromCore();
$this->assertEqual('Plural Rule 1 (from core)', $coreSingular);
$corePlurals = $this->__pluralFromCore();
$this->assertTrue(in_array('0 = 0 or > 1 (from core)', $corePlurals));
$this->assertTrue(in_array('1 = 1 (from core)', $corePlurals));
$this->assertTrue(in_array('2 = 0 or > 1 (from core)', $corePlurals));
$this->assertTrue(in_array('3 = 0 or > 1 (from core)', $corePlurals));
$this->assertTrue(in_array('4 = 0 or > 1 (from core)', $corePlurals));
$this->assertTrue(in_array('5 = 0 or > 1 (from core)', $corePlurals));
$this->assertTrue(in_array('6 = 0 or > 1 (from core)', $corePlurals));
$this->assertTrue(in_array('7 = 0 or > 1 (from core)', $corePlurals));
$this->assertTrue(in_array('8 = 0 or > 1 (from core)', $corePlurals));
$this->assertTrue(in_array('9 = 0 or > 1 (from core)', $corePlurals));
$this->assertTrue(in_array('10 = 0 or > 1 (from core)', $corePlurals));
$this->assertTrue(in_array('11 = 0 or > 1 (from core)', $corePlurals));
$this->assertTrue(in_array('12 = 0 or > 1 (from core)', $corePlurals));
$this->assertTrue(in_array('13 = 0 or > 1 (from core)', $corePlurals));
$this->assertTrue(in_array('14 = 0 or > 1 (from core)', $corePlurals));
$this->assertTrue(in_array('15 = 0 or > 1 (from core)', $corePlurals));
$this->assertTrue(in_array('16 = 0 or > 1 (from core)', $corePlurals));
$this->assertTrue(in_array('17 = 0 or > 1 (from core)', $corePlurals));
$this->assertTrue(in_array('18 = 0 or > 1 (from core)', $corePlurals));
$this->assertTrue(in_array('19 = 0 or > 1 (from core)', $corePlurals));
$this->assertTrue(in_array('20 = 0 or > 1 (from core)', $corePlurals));
$this->assertTrue(in_array('21 = 0 or > 1 (from core)', $corePlurals));
$this->assertTrue(in_array('22 = 0 or > 1 (from core)', $corePlurals));
$this->assertTrue(in_array('23 = 0 or > 1 (from core)', $corePlurals));
$this->assertTrue(in_array('24 = 0 or > 1 (from core)', $corePlurals));
$this->assertTrue(in_array('25 = 0 or > 1 (from core)', $corePlurals));
}
/**
* testPoRulesZero method
*
* @return void
*/
public function testPoRulesZero() {
Configure::write('Config.language', 'rule_0_po');
$singular = $this->__singular();
$this->assertEqual('Plural Rule 0 (translated)', $singular);
$plurals = $this->__plural();
$this->assertTrue(in_array('0 ends with any # (translated)', $plurals));
$this->assertTrue(in_array('1 ends with any # (translated)', $plurals));
$this->assertTrue(in_array('2 ends with any # (translated)', $plurals));
$this->assertTrue(in_array('3 ends with any # (translated)', $plurals));
$this->assertTrue(in_array('4 ends with any # (translated)', $plurals));
$this->assertTrue(in_array('5 ends with any # (translated)', $plurals));
$this->assertTrue(in_array('6 ends with any # (translated)', $plurals));
$this->assertTrue(in_array('7 ends with any # (translated)', $plurals));
$this->assertTrue(in_array('8 ends with any # (translated)', $plurals));
$this->assertTrue(in_array('9 ends with any # (translated)', $plurals));
$this->assertTrue(in_array('10 ends with any # (translated)', $plurals));
$this->assertTrue(in_array('11 ends with any # (translated)', $plurals));
$this->assertTrue(in_array('12 ends with any # (translated)', $plurals));
$this->assertTrue(in_array('13 ends with any # (translated)', $plurals));
$this->assertTrue(in_array('14 ends with any # (translated)', $plurals));
$this->assertTrue(in_array('15 ends with any # (translated)', $plurals));
$this->assertTrue(in_array('16 ends with any # (translated)', $plurals));
$this->assertTrue(in_array('17 ends with any # (translated)', $plurals));
$this->assertTrue(in_array('18 ends with any # (translated)', $plurals));
$this->assertTrue(in_array('19 ends with any # (translated)', $plurals));
$this->assertTrue(in_array('20 ends with any # (translated)', $plurals));
$this->assertTrue(in_array('21 ends with any # (translated)', $plurals));
$this->assertTrue(in_array('22 ends with any # (translated)', $plurals));
$this->assertTrue(in_array('23 ends with any # (translated)', $plurals));
$this->assertTrue(in_array('24 ends with any # (translated)', $plurals));
$this->assertTrue(in_array('25 ends with any # (translated)', $plurals));
$coreSingular = $this->__singularFromCore();
$this->assertEqual('Plural Rule 0 (from core translated)', $coreSingular);
$corePlurals = $this->__pluralFromCore();
$this->assertTrue(in_array('0 ends with any # (from core translated)', $corePlurals));
$this->assertTrue(in_array('1 ends with any # (from core translated)', $corePlurals));
$this->assertTrue(in_array('2 ends with any # (from core translated)', $corePlurals));
$this->assertTrue(in_array('3 ends with any # (from core translated)', $corePlurals));
$this->assertTrue(in_array('4 ends with any # (from core translated)', $corePlurals));
$this->assertTrue(in_array('5 ends with any # (from core translated)', $corePlurals));
$this->assertTrue(in_array('6 ends with any # (from core translated)', $corePlurals));
$this->assertTrue(in_array('7 ends with any # (from core translated)', $corePlurals));
$this->assertTrue(in_array('8 ends with any # (from core translated)', $corePlurals));
$this->assertTrue(in_array('9 ends with any # (from core translated)', $corePlurals));
$this->assertTrue(in_array('10 ends with any # (from core translated)', $corePlurals));
$this->assertTrue(in_array('11 ends with any # (from core translated)', $corePlurals));
$this->assertTrue(in_array('12 ends with any # (from core translated)', $corePlurals));
$this->assertTrue(in_array('13 ends with any # (from core translated)', $corePlurals));
$this->assertTrue(in_array('14 ends with any # (from core translated)', $corePlurals));
$this->assertTrue(in_array('15 ends with any # (from core translated)', $corePlurals));
$this->assertTrue(in_array('16 ends with any # (from core translated)', $corePlurals));
$this->assertTrue(in_array('17 ends with any # (from core translated)', $corePlurals));
$this->assertTrue(in_array('18 ends with any # (from core translated)', $corePlurals));
$this->assertTrue(in_array('19 ends with any # (from core translated)', $corePlurals));
$this->assertTrue(in_array('20 ends with any # (from core translated)', $corePlurals));
$this->assertTrue(in_array('21 ends with any # (from core translated)', $corePlurals));
$this->assertTrue(in_array('22 ends with any # (from core translated)', $corePlurals));
$this->assertTrue(in_array('23 ends with any # (from core translated)', $corePlurals));
$this->assertTrue(in_array('24 ends with any # (from core translated)', $corePlurals));
$this->assertTrue(in_array('25 ends with any # (from core translated)', $corePlurals));
}
/**
* testMoRulesZero method
*
* @return void
*/
public function testMoRulesZero() {
Configure::write('Config.language', 'rule_0_mo');
$singular = $this->__singular();
$this->assertEqual('Plural Rule 0 (translated)', $singular);
$plurals = $this->__plural();
$this->assertTrue(in_array('0 ends with any # (translated)', $plurals));
$this->assertTrue(in_array('1 ends with any # (translated)', $plurals));
$this->assertTrue(in_array('2 ends with any # (translated)', $plurals));
$this->assertTrue(in_array('3 ends with any # (translated)', $plurals));
$this->assertTrue(in_array('4 ends with any # (translated)', $plurals));
$this->assertTrue(in_array('5 ends with any # (translated)', $plurals));
$this->assertTrue(in_array('6 ends with any # (translated)', $plurals));
$this->assertTrue(in_array('7 ends with any # (translated)', $plurals));
$this->assertTrue(in_array('8 ends with any # (translated)', $plurals));
$this->assertTrue(in_array('9 ends with any # (translated)', $plurals));
$this->assertTrue(in_array('10 ends with any # (translated)', $plurals));
$this->assertTrue(in_array('11 ends with any # (translated)', $plurals));
$this->assertTrue(in_array('12 ends with any # (translated)', $plurals));
$this->assertTrue(in_array('13 ends with any # (translated)', $plurals));
$this->assertTrue(in_array('14 ends with any # (translated)', $plurals));
$this->assertTrue(in_array('15 ends with any # (translated)', $plurals));
$this->assertTrue(in_array('16 ends with any # (translated)', $plurals));
$this->assertTrue(in_array('17 ends with any # (translated)', $plurals));
$this->assertTrue(in_array('18 ends with any # (translated)', $plurals));
$this->assertTrue(in_array('19 ends with any # (translated)', $plurals));
$this->assertTrue(in_array('20 ends with any # (translated)', $plurals));
$this->assertTrue(in_array('21 ends with any # (translated)', $plurals));
$this->assertTrue(in_array('22 ends with any # (translated)', $plurals));
$this->assertTrue(in_array('23 ends with any # (translated)', $plurals));
$this->assertTrue(in_array('24 ends with any # (translated)', $plurals));
$this->assertTrue(in_array('25 ends with any # (translated)', $plurals));
$coreSingular = $this->__singularFromCore();
$this->assertEqual('Plural Rule 0 (from core translated)', $coreSingular);
$corePlurals = $this->__pluralFromCore();
$this->assertTrue(in_array('0 ends with any # (from core translated)', $corePlurals));
$this->assertTrue(in_array('1 ends with any # (from core translated)', $corePlurals));
$this->assertTrue(in_array('2 ends with any # (from core translated)', $corePlurals));
$this->assertTrue(in_array('3 ends with any # (from core translated)', $corePlurals));
$this->assertTrue(in_array('4 ends with any # (from core translated)', $corePlurals));
$this->assertTrue(in_array('5 ends with any # (from core translated)', $corePlurals));
$this->assertTrue(in_array('6 ends with any # (from core translated)', $corePlurals));
$this->assertTrue(in_array('7 ends with any # (from core translated)', $corePlurals));
$this->assertTrue(in_array('8 ends with any # (from core translated)', $corePlurals));
$this->assertTrue(in_array('9 ends with any # (from core translated)', $corePlurals));
$this->assertTrue(in_array('10 ends with any # (from core translated)', $corePlurals));
$this->assertTrue(in_array('11 ends with any # (from core translated)', $corePlurals));
$this->assertTrue(in_array('12 ends with any # (from core translated)', $corePlurals));
$this->assertTrue(in_array('13 ends with any # (from core translated)', $corePlurals));
$this->assertTrue(in_array('14 ends with any # (from core translated)', $corePlurals));
$this->assertTrue(in_array('15 ends with any # (from core translated)', $corePlurals));
$this->assertTrue(in_array('16 ends with any # (from core translated)', $corePlurals));
$this->assertTrue(in_array('17 ends with any # (from core translated)', $corePlurals));
$this->assertTrue(in_array('18 ends with any # (from core translated)', $corePlurals));
$this->assertTrue(in_array('19 ends with any # (from core translated)', $corePlurals));
$this->assertTrue(in_array('20 ends with any # (from core translated)', $corePlurals));
$this->assertTrue(in_array('21 ends with any # (from core translated)', $corePlurals));
$this->assertTrue(in_array('22 ends with any # (from core translated)', $corePlurals));
$this->assertTrue(in_array('23 ends with any # (from core translated)', $corePlurals));
$this->assertTrue(in_array('24 ends with any # (from core translated)', $corePlurals));
$this->assertTrue(in_array('25 ends with any # (from core translated)', $corePlurals));
}
/**
* testPoRulesOne method
*
* @return void
*/
public function testPoRulesOne() {
Configure::write('Config.language', 'rule_1_po');
$singular = $this->__singular();
$this->assertEqual('Plural Rule 1 (translated)', $singular);
$plurals = $this->__plural();
$this->assertTrue(in_array('0 = 0 or > 1 (translated)', $plurals));
$this->assertTrue(in_array('1 = 1 (translated)', $plurals));
$this->assertTrue(in_array('2 = 0 or > 1 (translated)', $plurals));
$this->assertTrue(in_array('3 = 0 or > 1 (translated)', $plurals));
$this->assertTrue(in_array('4 = 0 or > 1 (translated)', $plurals));
$this->assertTrue(in_array('5 = 0 or > 1 (translated)', $plurals));
$this->assertTrue(in_array('6 = 0 or > 1 (translated)', $plurals));
$this->assertTrue(in_array('7 = 0 or > 1 (translated)', $plurals));
$this->assertTrue(in_array('8 = 0 or > 1 (translated)', $plurals));
$this->assertTrue(in_array('9 = 0 or > 1 (translated)', $plurals));
$this->assertTrue(in_array('10 = 0 or > 1 (translated)', $plurals));
$this->assertTrue(in_array('11 = 0 or > 1 (translated)', $plurals));
$this->assertTrue(in_array('12 = 0 or > 1 (translated)', $plurals));
$this->assertTrue(in_array('13 = 0 or > 1 (translated)', $plurals));
$this->assertTrue(in_array('14 = 0 or > 1 (translated)', $plurals));
$this->assertTrue(in_array('15 = 0 or > 1 (translated)', $plurals));
$this->assertTrue(in_array('16 = 0 or > 1 (translated)', $plurals));
$this->assertTrue(in_array('17 = 0 or > 1 (translated)', $plurals));
$this->assertTrue(in_array('18 = 0 or > 1 (translated)', $plurals));
$this->assertTrue(in_array('19 = 0 or > 1 (translated)', $plurals));
$this->assertTrue(in_array('20 = 0 or > 1 (translated)', $plurals));
$this->assertTrue(in_array('21 = 0 or > 1 (translated)', $plurals));
$this->assertTrue(in_array('22 = 0 or > 1 (translated)', $plurals));
$this->assertTrue(in_array('23 = 0 or > 1 (translated)', $plurals));
$this->assertTrue(in_array('24 = 0 or > 1 (translated)', $plurals));
$this->assertTrue(in_array('25 = 0 or > 1 (translated)', $plurals));
$coreSingular = $this->__singularFromCore();
$this->assertEqual('Plural Rule 1 (from core translated)', $coreSingular);
$corePlurals = $this->__pluralFromCore();
$this->assertTrue(in_array('0 = 0 or > 1 (from core translated)', $corePlurals));
$this->assertTrue(in_array('1 = 1 (from core translated)', $corePlurals));
$this->assertTrue(in_array('2 = 0 or > 1 (from core translated)', $corePlurals));
$this->assertTrue(in_array('3 = 0 or > 1 (from core translated)', $corePlurals));
$this->assertTrue(in_array('4 = 0 or > 1 (from core translated)', $corePlurals));
$this->assertTrue(in_array('5 = 0 or > 1 (from core translated)', $corePlurals));
$this->assertTrue(in_array('6 = 0 or > 1 (from core translated)', $corePlurals));
$this->assertTrue(in_array('7 = 0 or > 1 (from core translated)', $corePlurals));
$this->assertTrue(in_array('8 = 0 or > 1 (from core translated)', $corePlurals));
$this->assertTrue(in_array('9 = 0 or > 1 (from core translated)', $corePlurals));
$this->assertTrue(in_array('10 = 0 or > 1 (from core translated)', $corePlurals));
$this->assertTrue(in_array('11 = 0 or > 1 (from core translated)', $corePlurals));
$this->assertTrue(in_array('12 = 0 or > 1 (from core translated)', $corePlurals));
$this->assertTrue(in_array('13 = 0 or > 1 (from core translated)', $corePlurals));
$this->assertTrue(in_array('14 = 0 or > 1 (from core translated)', $corePlurals));
$this->assertTrue(in_array('15 = 0 or > 1 (from core translated)', $corePlurals));
$this->assertTrue(in_array('16 = 0 or > 1 (from core translated)', $corePlurals));
$this->assertTrue(in_array('17 = 0 or > 1 (from core translated)', $corePlurals));
$this->assertTrue(in_array('18 = 0 or > 1 (from core translated)', $corePlurals));
$this->assertTrue(in_array('19 = 0 or > 1 (from core translated)', $corePlurals));
$this->assertTrue(in_array('20 = 0 or > 1 (from core translated)', $corePlurals));
$this->assertTrue(in_array('21 = 0 or > 1 (from core translated)', $corePlurals));
$this->assertTrue(in_array('22 = 0 or > 1 (from core translated)', $corePlurals));
$this->assertTrue(in_array('23 = 0 or > 1 (from core translated)', $corePlurals));
$this->assertTrue(in_array('24 = 0 or > 1 (from core translated)', $corePlurals));
$this->assertTrue(in_array('25 = 0 or > 1 (from core translated)', $corePlurals));
}
/**
* testMoRulesOne method
*
* @return void
*/
public function testMoRulesOne() {
Configure::write('Config.language', 'rule_1_mo');
$singular = $this->__singular();
$this->assertEqual('Plural Rule 1 (translated)', $singular);
$plurals = $this->__plural();
$this->assertTrue(in_array('0 = 0 or > 1 (translated)', $plurals));
$this->assertTrue(in_array('1 = 1 (translated)', $plurals));
$this->assertTrue(in_array('2 = 0 or > 1 (translated)', $plurals));
$this->assertTrue(in_array('3 = 0 or > 1 (translated)', $plurals));
$this->assertTrue(in_array('4 = 0 or > 1 (translated)', $plurals));
$this->assertTrue(in_array('5 = 0 or > 1 (translated)', $plurals));
$this->assertTrue(in_array('6 = 0 or > 1 (translated)', $plurals));
$this->assertTrue(in_array('7 = 0 or > 1 (translated)', $plurals));
$this->assertTrue(in_array('8 = 0 or > 1 (translated)', $plurals));
$this->assertTrue(in_array('9 = 0 or > 1 (translated)', $plurals));
$this->assertTrue(in_array('10 = 0 or > 1 (translated)', $plurals));
$this->assertTrue(in_array('11 = 0 or > 1 (translated)', $plurals));
$this->assertTrue(in_array('12 = 0 or > 1 (translated)', $plurals));
$this->assertTrue(in_array('13 = 0 or > 1 (translated)', $plurals));
$this->assertTrue(in_array('14 = 0 or > 1 (translated)', $plurals));
$this->assertTrue(in_array('15 = 0 or > 1 (translated)', $plurals));
$this->assertTrue(in_array('16 = 0 or > 1 (translated)', $plurals));
$this->assertTrue(in_array('17 = 0 or > 1 (translated)', $plurals));
$this->assertTrue(in_array('18 = 0 or > 1 (translated)', $plurals));
$this->assertTrue(in_array('19 = 0 or > 1 (translated)', $plurals));
$this->assertTrue(in_array('20 = 0 or > 1 (translated)', $plurals));
$this->assertTrue(in_array('21 = 0 or > 1 (translated)', $plurals));
$this->assertTrue(in_array('22 = 0 or > 1 (translated)', $plurals));
$this->assertTrue(in_array('23 = 0 or > 1 (translated)', $plurals));
$this->assertTrue(in_array('24 = 0 or > 1 (translated)', $plurals));
$this->assertTrue(in_array('25 = 0 or > 1 (translated)', $plurals));
$coreSingular = $this->__singularFromCore();
$this->assertEqual('Plural Rule 1 (from core translated)', $coreSingular);
$corePlurals = $this->__pluralFromCore();
$this->assertTrue(in_array('0 = 0 or > 1 (from core translated)', $corePlurals));
$this->assertTrue(in_array('1 = 1 (from core translated)', $corePlurals));
$this->assertTrue(in_array('2 = 0 or > 1 (from core translated)', $corePlurals));
$this->assertTrue(in_array('3 = 0 or > 1 (from core translated)', $corePlurals));
$this->assertTrue(in_array('4 = 0 or > 1 (from core translated)', $corePlurals));
$this->assertTrue(in_array('5 = 0 or > 1 (from core translated)', $corePlurals));
$this->assertTrue(in_array('6 = 0 or > 1 (from core translated)', $corePlurals));
$this->assertTrue(in_array('7 = 0 or > 1 (from core translated)', $corePlurals));
$this->assertTrue(in_array('8 = 0 or > 1 (from core translated)', $corePlurals));
$this->assertTrue(in_array('9 = 0 or > 1 (from core translated)', $corePlurals));
$this->assertTrue(in_array('10 = 0 or > 1 (from core translated)', $corePlurals));
$this->assertTrue(in_array('11 = 0 or > 1 (from core translated)', $corePlurals));
$this->assertTrue(in_array('12 = 0 or > 1 (from core translated)', $corePlurals));
$this->assertTrue(in_array('13 = 0 or > 1 (from core translated)', $corePlurals));
$this->assertTrue(in_array('14 = 0 or > 1 (from core translated)', $corePlurals));
$this->assertTrue(in_array('15 = 0 or > 1 (from core translated)', $corePlurals));
$this->assertTrue(in_array('16 = 0 or > 1 (from core translated)', $corePlurals));
$this->assertTrue(in_array('17 = 0 or > 1 (from core translated)', $corePlurals));
$this->assertTrue(in_array('18 = 0 or > 1 (from core translated)', $corePlurals));
$this->assertTrue(in_array('19 = 0 or > 1 (from core translated)', $corePlurals));
$this->assertTrue(in_array('20 = 0 or > 1 (from core translated)', $corePlurals));
$this->assertTrue(in_array('21 = 0 or > 1 (from core translated)', $corePlurals));
$this->assertTrue(in_array('22 = 0 or > 1 (from core translated)', $corePlurals));
$this->assertTrue(in_array('23 = 0 or > 1 (from core translated)', $corePlurals));
$this->assertTrue(in_array('24 = 0 or > 1 (from core translated)', $corePlurals));
$this->assertTrue(in_array('25 = 0 or > 1 (from core translated)', $corePlurals));
}
/**
* testPoRulesTwo method
*
* @return void
*/
public function testPoRulesTwo() {
Configure::write('Config.language', 'rule_2_po');
$singular = $this->__singular();
$this->assertEqual('Plural Rule 2 (translated)', $singular);
$plurals = $this->__plural();
$this->assertTrue(in_array('0 = 0 or 1 (translated)', $plurals));
$this->assertTrue(in_array('1 = 0 or 1 (translated)', $plurals));
$this->assertTrue(in_array('2 > 1 (translated)', $plurals));
$this->assertTrue(in_array('3 > 1 (translated)', $plurals));
$this->assertTrue(in_array('4 > 1 (translated)', $plurals));
$this->assertTrue(in_array('5 > 1 (translated)', $plurals));
$this->assertTrue(in_array('6 > 1 (translated)', $plurals));
$this->assertTrue(in_array('7 > 1 (translated)', $plurals));
$this->assertTrue(in_array('8 > 1 (translated)', $plurals));
$this->assertTrue(in_array('9 > 1 (translated)', $plurals));
$this->assertTrue(in_array('10 > 1 (translated)', $plurals));
$this->assertTrue(in_array('11 > 1 (translated)', $plurals));
$this->assertTrue(in_array('12 > 1 (translated)', $plurals));
$this->assertTrue(in_array('13 > 1 (translated)', $plurals));
$this->assertTrue(in_array('14 > 1 (translated)', $plurals));
$this->assertTrue(in_array('15 > 1 (translated)', $plurals));
$this->assertTrue(in_array('16 > 1 (translated)', $plurals));
$this->assertTrue(in_array('17 > 1 (translated)', $plurals));
$this->assertTrue(in_array('18 > 1 (translated)', $plurals));
$this->assertTrue(in_array('19 > 1 (translated)', $plurals));
$this->assertTrue(in_array('20 > 1 (translated)', $plurals));
$this->assertTrue(in_array('21 > 1 (translated)', $plurals));
$this->assertTrue(in_array('22 > 1 (translated)', $plurals));
$this->assertTrue(in_array('23 > 1 (translated)', $plurals));
$this->assertTrue(in_array('24 > 1 (translated)', $plurals));
$this->assertTrue(in_array('25 > 1 (translated)', $plurals));
$coreSingular = $this->__singularFromCore();
$this->assertEqual('Plural Rule 2 (from core translated)', $coreSingular);
$corePlurals = $this->__pluralFromCore();
$this->assertTrue(in_array('0 = 0 or 1 (from core translated)', $corePlurals));
$this->assertTrue(in_array('1 = 0 or 1 (from core translated)', $corePlurals));
$this->assertTrue(in_array('2 > 1 (from core translated)', $corePlurals));
$this->assertTrue(in_array('3 > 1 (from core translated)', $corePlurals));
$this->assertTrue(in_array('4 > 1 (from core translated)', $corePlurals));
$this->assertTrue(in_array('5 > 1 (from core translated)', $corePlurals));
$this->assertTrue(in_array('6 > 1 (from core translated)', $corePlurals));
$this->assertTrue(in_array('7 > 1 (from core translated)', $corePlurals));
$this->assertTrue(in_array('8 > 1 (from core translated)', $corePlurals));
$this->assertTrue(in_array('9 > 1 (from core translated)', $corePlurals));
$this->assertTrue(in_array('10 > 1 (from core translated)', $corePlurals));
$this->assertTrue(in_array('11 > 1 (from core translated)', $corePlurals));
$this->assertTrue(in_array('12 > 1 (from core translated)', $corePlurals));
$this->assertTrue(in_array('13 > 1 (from core translated)', $corePlurals));
$this->assertTrue(in_array('14 > 1 (from core translated)', $corePlurals));
$this->assertTrue(in_array('15 > 1 (from core translated)', $corePlurals));
$this->assertTrue(in_array('16 > 1 (from core translated)', $corePlurals));
$this->assertTrue(in_array('17 > 1 (from core translated)', $corePlurals));
$this->assertTrue(in_array('18 > 1 (from core translated)', $corePlurals));
$this->assertTrue(in_array('19 > 1 (from core translated)', $corePlurals));
$this->assertTrue(in_array('20 > 1 (from core translated)', $corePlurals));
$this->assertTrue(in_array('21 > 1 (from core translated)', $corePlurals));
$this->assertTrue(in_array('22 > 1 (from core translated)', $corePlurals));
$this->assertTrue(in_array('23 > 1 (from core translated)', $corePlurals));
$this->assertTrue(in_array('24 > 1 (from core translated)', $corePlurals));
$this->assertTrue(in_array('25 > 1 (from core translated)', $corePlurals));
}
/**
* testMoRulesTwo method
*
* @return void
*/
public function testMoRulesTwo() {
Configure::write('Config.language', 'rule_2_mo');
$singular = $this->__singular();
$this->assertEqual('Plural Rule 2 (translated)', $singular);
$plurals = $this->__plural();
$this->assertTrue(in_array('0 = 0 or 1 (translated)', $plurals));
$this->assertTrue(in_array('1 = 0 or 1 (translated)', $plurals));
$this->assertTrue(in_array('2 > 1 (translated)', $plurals));
$this->assertTrue(in_array('3 > 1 (translated)', $plurals));
$this->assertTrue(in_array('4 > 1 (translated)', $plurals));
$this->assertTrue(in_array('5 > 1 (translated)', $plurals));
$this->assertTrue(in_array('6 > 1 (translated)', $plurals));
$this->assertTrue(in_array('7 > 1 (translated)', $plurals));
$this->assertTrue(in_array('8 > 1 (translated)', $plurals));
$this->assertTrue(in_array('9 > 1 (translated)', $plurals));
$this->assertTrue(in_array('10 > 1 (translated)', $plurals));
$this->assertTrue(in_array('11 > 1 (translated)', $plurals));
$this->assertTrue(in_array('12 > 1 (translated)', $plurals));
$this->assertTrue(in_array('13 > 1 (translated)', $plurals));
$this->assertTrue(in_array('14 > 1 (translated)', $plurals));
$this->assertTrue(in_array('15 > 1 (translated)', $plurals));
$this->assertTrue(in_array('16 > 1 (translated)', $plurals));
$this->assertTrue(in_array('17 > 1 (translated)', $plurals));
$this->assertTrue(in_array('18 > 1 (translated)', $plurals));
$this->assertTrue(in_array('19 > 1 (translated)', $plurals));
$this->assertTrue(in_array('20 > 1 (translated)', $plurals));
$this->assertTrue(in_array('21 > 1 (translated)', $plurals));
$this->assertTrue(in_array('22 > 1 (translated)', $plurals));
$this->assertTrue(in_array('23 > 1 (translated)', $plurals));
$this->assertTrue(in_array('24 > 1 (translated)', $plurals));
$this->assertTrue(in_array('25 > 1 (translated)', $plurals));
$coreSingular = $this->__singularFromCore();
$this->assertEqual('Plural Rule 2 (from core translated)', $coreSingular);
$corePlurals = $this->__pluralFromCore();
$this->assertTrue(in_array('0 = 0 or 1 (from core translated)', $corePlurals));
$this->assertTrue(in_array('1 = 0 or 1 (from core translated)', $corePlurals));
$this->assertTrue(in_array('2 > 1 (from core translated)', $corePlurals));
$this->assertTrue(in_array('3 > 1 (from core translated)', $corePlurals));
$this->assertTrue(in_array('4 > 1 (from core translated)', $corePlurals));
$this->assertTrue(in_array('5 > 1 (from core translated)', $corePlurals));
$this->assertTrue(in_array('6 > 1 (from core translated)', $corePlurals));
$this->assertTrue(in_array('7 > 1 (from core translated)', $corePlurals));
$this->assertTrue(in_array('8 > 1 (from core translated)', $corePlurals));
$this->assertTrue(in_array('9 > 1 (from core translated)', $corePlurals));
$this->assertTrue(in_array('10 > 1 (from core translated)', $corePlurals));
$this->assertTrue(in_array('11 > 1 (from core translated)', $corePlurals));
$this->assertTrue(in_array('12 > 1 (from core translated)', $corePlurals));
$this->assertTrue(in_array('13 > 1 (from core translated)', $corePlurals));
$this->assertTrue(in_array('14 > 1 (from core translated)', $corePlurals));
$this->assertTrue(in_array('15 > 1 (from core translated)', $corePlurals));
$this->assertTrue(in_array('16 > 1 (from core translated)', $corePlurals));
$this->assertTrue(in_array('17 > 1 (from core translated)', $corePlurals));
$this->assertTrue(in_array('18 > 1 (from core translated)', $corePlurals));
$this->assertTrue(in_array('19 > 1 (from core translated)', $corePlurals));
$this->assertTrue(in_array('20 > 1 (from core translated)', $corePlurals));
$this->assertTrue(in_array('21 > 1 (from core translated)', $corePlurals));
$this->assertTrue(in_array('22 > 1 (from core translated)', $corePlurals));
$this->assertTrue(in_array('23 > 1 (from core translated)', $corePlurals));
$this->assertTrue(in_array('24 > 1 (from core translated)', $corePlurals));
$this->assertTrue(in_array('25 > 1 (from core translated)', $corePlurals));
}
/**
* testPoRulesThree method
*
* @return void
*/
public function testPoRulesThree() {
Configure::write('Config.language', 'rule_3_po');
$singular = $this->__singular();
$this->assertEqual('Plural Rule 3 (translated)', $singular);
$plurals = $this->__plural();
$this->assertTrue(in_array('0 = 0 (translated)', $plurals));
$this->assertTrue(in_array('1 ends 1 but not 11 (translated)', $plurals));
$this->assertTrue(in_array('2 everything else (translated)', $plurals));
$this->assertTrue(in_array('3 everything else (translated)', $plurals));
$this->assertTrue(in_array('4 everything else (translated)', $plurals));
$this->assertTrue(in_array('5 everything else (translated)', $plurals));
$this->assertTrue(in_array('6 everything else (translated)', $plurals));
$this->assertTrue(in_array('7 everything else (translated)', $plurals));
$this->assertTrue(in_array('8 everything else (translated)', $plurals));
$this->assertTrue(in_array('9 everything else (translated)', $plurals));
$this->assertTrue(in_array('10 everything else (translated)', $plurals));
$this->assertTrue(in_array('11 everything else (translated)', $plurals));
$this->assertTrue(in_array('12 everything else (translated)', $plurals));
$this->assertTrue(in_array('13 everything else (translated)', $plurals));
$this->assertTrue(in_array('14 everything else (translated)', $plurals));
$this->assertTrue(in_array('15 everything else (translated)', $plurals));
$this->assertTrue(in_array('16 everything else (translated)', $plurals));
$this->assertTrue(in_array('17 everything else (translated)', $plurals));
$this->assertTrue(in_array('18 everything else (translated)', $plurals));
$this->assertTrue(in_array('19 everything else (translated)', $plurals));
$this->assertTrue(in_array('20 everything else (translated)', $plurals));
$this->assertTrue(in_array('21 ends 1 but not 11 (translated)', $plurals));
$this->assertTrue(in_array('22 everything else (translated)', $plurals));
$this->assertTrue(in_array('23 everything else (translated)', $plurals));
$this->assertTrue(in_array('24 everything else (translated)', $plurals));
$this->assertTrue(in_array('25 everything else (translated)', $plurals));
$coreSingular = $this->__singularFromCore();
$this->assertEqual('Plural Rule 3 (from core translated)', $coreSingular);
$corePlurals = $this->__pluralFromCore();
$this->assertTrue(in_array('0 = 0 (from core translated)', $corePlurals));
$this->assertTrue(in_array('1 ends 1 but not 11 (from core translated)', $corePlurals));
$this->assertTrue(in_array('2 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('3 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('4 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('5 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('6 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('7 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('8 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('9 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('10 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('11 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('12 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('13 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('14 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('15 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('16 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('17 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('18 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('19 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('20 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('21 ends 1 but not 11 (from core translated)', $corePlurals));
$this->assertTrue(in_array('22 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('23 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('24 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('25 everything else (from core translated)', $corePlurals));
}
/**
* testMoRulesThree method
*
* @return void
*/
public function testMoRulesThree() {
Configure::write('Config.language', 'rule_3_mo');
$singular = $this->__singular();
$this->assertEqual('Plural Rule 3 (translated)', $singular);
$plurals = $this->__plural();
$this->assertTrue(in_array('0 = 0 (translated)', $plurals));
$this->assertTrue(in_array('1 ends 1 but not 11 (translated)', $plurals));
$this->assertTrue(in_array('2 everything else (translated)', $plurals));
$this->assertTrue(in_array('3 everything else (translated)', $plurals));
$this->assertTrue(in_array('4 everything else (translated)', $plurals));
$this->assertTrue(in_array('5 everything else (translated)', $plurals));
$this->assertTrue(in_array('6 everything else (translated)', $plurals));
$this->assertTrue(in_array('7 everything else (translated)', $plurals));
$this->assertTrue(in_array('8 everything else (translated)', $plurals));
$this->assertTrue(in_array('9 everything else (translated)', $plurals));
$this->assertTrue(in_array('10 everything else (translated)', $plurals));
$this->assertTrue(in_array('11 everything else (translated)', $plurals));
$this->assertTrue(in_array('12 everything else (translated)', $plurals));
$this->assertTrue(in_array('13 everything else (translated)', $plurals));
$this->assertTrue(in_array('14 everything else (translated)', $plurals));
$this->assertTrue(in_array('15 everything else (translated)', $plurals));
$this->assertTrue(in_array('16 everything else (translated)', $plurals));
$this->assertTrue(in_array('17 everything else (translated)', $plurals));
$this->assertTrue(in_array('18 everything else (translated)', $plurals));
$this->assertTrue(in_array('19 everything else (translated)', $plurals));
$this->assertTrue(in_array('20 everything else (translated)', $plurals));
$this->assertTrue(in_array('21 ends 1 but not 11 (translated)', $plurals));
$this->assertTrue(in_array('22 everything else (translated)', $plurals));
$this->assertTrue(in_array('23 everything else (translated)', $plurals));
$this->assertTrue(in_array('24 everything else (translated)', $plurals));
$this->assertTrue(in_array('25 everything else (translated)', $plurals));
$coreSingular = $this->__singularFromCore();
$this->assertEqual('Plural Rule 3 (from core translated)', $coreSingular);
$corePlurals = $this->__pluralFromCore();
$this->assertTrue(in_array('0 = 0 (from core translated)', $corePlurals));
$this->assertTrue(in_array('1 ends 1 but not 11 (from core translated)', $corePlurals));
$this->assertTrue(in_array('2 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('3 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('4 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('5 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('6 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('7 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('8 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('9 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('10 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('11 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('12 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('13 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('14 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('15 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('16 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('17 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('18 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('19 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('20 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('21 ends 1 but not 11 (from core translated)', $corePlurals));
$this->assertTrue(in_array('22 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('23 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('24 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('25 everything else (from core translated)', $corePlurals));
}
/**
* testPoRulesFour method
*
* @return void
*/
public function testPoRulesFour() {
Configure::write('Config.language', 'rule_4_po');
$singular = $this->__singular();
$this->assertEqual('Plural Rule 4 (translated)', $singular);
$plurals = $this->__plural();
$this->assertTrue(in_array('0 everything else (translated)', $plurals));
$this->assertTrue(in_array('1 = 1 (translated)', $plurals));
$this->assertTrue(in_array('2 = 2 (translated)', $plurals));
$this->assertTrue(in_array('3 everything else (translated)', $plurals));
$this->assertTrue(in_array('4 everything else (translated)', $plurals));
$this->assertTrue(in_array('5 everything else (translated)', $plurals));
$this->assertTrue(in_array('6 everything else (translated)', $plurals));
$this->assertTrue(in_array('7 everything else (translated)', $plurals));
$this->assertTrue(in_array('8 everything else (translated)', $plurals));
$this->assertTrue(in_array('9 everything else (translated)', $plurals));
$this->assertTrue(in_array('10 everything else (translated)', $plurals));
$this->assertTrue(in_array('11 everything else (translated)', $plurals));
$this->assertTrue(in_array('12 everything else (translated)', $plurals));
$this->assertTrue(in_array('13 everything else (translated)', $plurals));
$this->assertTrue(in_array('14 everything else (translated)', $plurals));
$this->assertTrue(in_array('15 everything else (translated)', $plurals));
$this->assertTrue(in_array('16 everything else (translated)', $plurals));
$this->assertTrue(in_array('17 everything else (translated)', $plurals));
$this->assertTrue(in_array('18 everything else (translated)', $plurals));
$this->assertTrue(in_array('19 everything else (translated)', $plurals));
$this->assertTrue(in_array('20 everything else (translated)', $plurals));
$this->assertTrue(in_array('21 everything else (translated)', $plurals));
$this->assertTrue(in_array('22 everything else (translated)', $plurals));
$this->assertTrue(in_array('23 everything else (translated)', $plurals));
$this->assertTrue(in_array('24 everything else (translated)', $plurals));
$this->assertTrue(in_array('25 everything else (translated)', $plurals));
$coreSingular = $this->__singularFromCore();
$this->assertEqual('Plural Rule 4 (from core translated)', $coreSingular);
$corePlurals = $this->__pluralFromCore();
$this->assertTrue(in_array('0 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('1 = 1 (from core translated)', $corePlurals));
$this->assertTrue(in_array('2 = 2 (from core translated)', $corePlurals));
$this->assertTrue(in_array('3 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('4 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('5 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('6 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('7 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('8 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('9 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('10 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('11 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('12 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('13 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('14 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('15 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('16 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('17 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('18 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('19 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('20 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('21 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('22 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('23 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('24 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('25 everything else (from core translated)', $corePlurals));
}
/**
* testMoRulesFour method
*
* @return void
*/
public function testMoRulesFour() {
Configure::write('Config.language', 'rule_4_mo');
$singular = $this->__singular();
$this->assertEqual('Plural Rule 4 (translated)', $singular);
$plurals = $this->__plural();
$this->assertTrue(in_array('0 everything else (translated)', $plurals));
$this->assertTrue(in_array('1 = 1 (translated)', $plurals));
$this->assertTrue(in_array('2 = 2 (translated)', $plurals));
$this->assertTrue(in_array('3 everything else (translated)', $plurals));
$this->assertTrue(in_array('4 everything else (translated)', $plurals));
$this->assertTrue(in_array('5 everything else (translated)', $plurals));
$this->assertTrue(in_array('6 everything else (translated)', $plurals));
$this->assertTrue(in_array('7 everything else (translated)', $plurals));
$this->assertTrue(in_array('8 everything else (translated)', $plurals));
$this->assertTrue(in_array('9 everything else (translated)', $plurals));
$this->assertTrue(in_array('10 everything else (translated)', $plurals));
$this->assertTrue(in_array('11 everything else (translated)', $plurals));
$this->assertTrue(in_array('12 everything else (translated)', $plurals));
$this->assertTrue(in_array('13 everything else (translated)', $plurals));
$this->assertTrue(in_array('14 everything else (translated)', $plurals));
$this->assertTrue(in_array('15 everything else (translated)', $plurals));
$this->assertTrue(in_array('16 everything else (translated)', $plurals));
$this->assertTrue(in_array('17 everything else (translated)', $plurals));
$this->assertTrue(in_array('18 everything else (translated)', $plurals));
$this->assertTrue(in_array('19 everything else (translated)', $plurals));
$this->assertTrue(in_array('20 everything else (translated)', $plurals));
$this->assertTrue(in_array('21 everything else (translated)', $plurals));
$this->assertTrue(in_array('22 everything else (translated)', $plurals));
$this->assertTrue(in_array('23 everything else (translated)', $plurals));
$this->assertTrue(in_array('24 everything else (translated)', $plurals));
$this->assertTrue(in_array('25 everything else (translated)', $plurals));
$coreSingular = $this->__singularFromCore();
$this->assertEqual('Plural Rule 4 (from core translated)', $coreSingular);
$corePlurals = $this->__pluralFromCore();
$this->assertTrue(in_array('0 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('1 = 1 (from core translated)', $corePlurals));
$this->assertTrue(in_array('2 = 2 (from core translated)', $corePlurals));
$this->assertTrue(in_array('3 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('4 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('5 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('6 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('7 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('8 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('9 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('10 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('11 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('12 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('13 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('14 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('15 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('16 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('17 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('18 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('19 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('20 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('21 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('22 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('23 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('24 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('25 everything else (from core translated)', $corePlurals));
}
/**
* testPoRulesFive method
*
* @return void
*/
public function testPoRulesFive() {
Configure::write('Config.language', 'rule_5_po');
$singular = $this->__singular();
$this->assertEqual('Plural Rule 5 (translated)', $singular);
$plurals = $this->__plural();
$this->assertTrue(in_array('0 = 0 or ends in 01-19 (translated)', $plurals));
$this->assertTrue(in_array('0 = 0 or ends in 01-19 (translated)', $plurals));
$this->assertTrue(in_array('1 = 1 (translated)', $plurals));
$this->assertTrue(in_array('2 = 0 or ends in 01-19 (translated)', $plurals));
$this->assertTrue(in_array('3 = 0 or ends in 01-19 (translated)', $plurals));
$this->assertTrue(in_array('4 = 0 or ends in 01-19 (translated)', $plurals));
$this->assertTrue(in_array('5 = 0 or ends in 01-19 (translated)', $plurals));
$this->assertTrue(in_array('6 = 0 or ends in 01-19 (translated)', $plurals));
$this->assertTrue(in_array('7 = 0 or ends in 01-19 (translated)', $plurals));
$this->assertTrue(in_array('8 = 0 or ends in 01-19 (translated)', $plurals));
$this->assertTrue(in_array('9 = 0 or ends in 01-19 (translated)', $plurals));
$this->assertTrue(in_array('10 = 0 or ends in 01-19 (translated)', $plurals));
$this->assertTrue(in_array('11 = 0 or ends in 01-19 (translated)', $plurals));
$this->assertTrue(in_array('12 = 0 or ends in 01-19 (translated)', $plurals));
$this->assertTrue(in_array('13 = 0 or ends in 01-19 (translated)', $plurals));
$this->assertTrue(in_array('14 = 0 or ends in 01-19 (translated)', $plurals));
$this->assertTrue(in_array('15 = 0 or ends in 01-19 (translated)', $plurals));
$this->assertTrue(in_array('16 = 0 or ends in 01-19 (translated)', $plurals));
$this->assertTrue(in_array('17 = 0 or ends in 01-19 (translated)', $plurals));
$this->assertTrue(in_array('18 = 0 or ends in 01-19 (translated)', $plurals));
$this->assertTrue(in_array('19 = 0 or ends in 01-19 (translated)', $plurals));
$this->assertTrue(in_array('20 everything else (translated)', $plurals));
$this->assertTrue(in_array('21 everything else (translated)', $plurals));
$this->assertTrue(in_array('22 everything else (translated)', $plurals));
$this->assertTrue(in_array('23 everything else (translated)', $plurals));
$this->assertTrue(in_array('24 everything else (translated)', $plurals));
$this->assertTrue(in_array('25 everything else (translated)', $plurals));
$coreSingular = $this->__singularFromCore();
$this->assertEqual('Plural Rule 5 (from core translated)', $coreSingular);
$corePlurals = $this->__pluralFromCore();
$this->assertTrue(in_array('0 = 0 or ends in 01-19 (from core translated)', $corePlurals));
$this->assertTrue(in_array('0 = 0 or ends in 01-19 (from core translated)', $corePlurals));
$this->assertTrue(in_array('1 = 1 (from core translated)', $corePlurals));
$this->assertTrue(in_array('2 = 0 or ends in 01-19 (from core translated)', $corePlurals));
$this->assertTrue(in_array('3 = 0 or ends in 01-19 (from core translated)', $corePlurals));
$this->assertTrue(in_array('4 = 0 or ends in 01-19 (from core translated)', $corePlurals));
$this->assertTrue(in_array('5 = 0 or ends in 01-19 (from core translated)', $corePlurals));
$this->assertTrue(in_array('6 = 0 or ends in 01-19 (from core translated)', $corePlurals));
$this->assertTrue(in_array('7 = 0 or ends in 01-19 (from core translated)', $corePlurals));
$this->assertTrue(in_array('8 = 0 or ends in 01-19 (from core translated)', $corePlurals));
$this->assertTrue(in_array('9 = 0 or ends in 01-19 (from core translated)', $corePlurals));
$this->assertTrue(in_array('10 = 0 or ends in 01-19 (from core translated)', $corePlurals));
$this->assertTrue(in_array('11 = 0 or ends in 01-19 (from core translated)', $corePlurals));
$this->assertTrue(in_array('12 = 0 or ends in 01-19 (from core translated)', $corePlurals));
$this->assertTrue(in_array('13 = 0 or ends in 01-19 (from core translated)', $corePlurals));
$this->assertTrue(in_array('14 = 0 or ends in 01-19 (from core translated)', $corePlurals));
$this->assertTrue(in_array('15 = 0 or ends in 01-19 (from core translated)', $corePlurals));
$this->assertTrue(in_array('16 = 0 or ends in 01-19 (from core translated)', $corePlurals));
$this->assertTrue(in_array('17 = 0 or ends in 01-19 (from core translated)', $corePlurals));
$this->assertTrue(in_array('18 = 0 or ends in 01-19 (from core translated)', $corePlurals));
$this->assertTrue(in_array('19 = 0 or ends in 01-19 (from core translated)', $corePlurals));
$this->assertTrue(in_array('20 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('21 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('22 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('23 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('24 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('25 everything else (from core translated)', $corePlurals));
}
/**
* testMoRulesFive method
*
* @return void
*/
public function testMoRulesFive() {
Configure::write('Config.language', 'rule_5_mo');
$singular = $this->__singular();
$this->assertEqual('Plural Rule 5 (translated)', $singular);
$plurals = $this->__plural();
$this->assertTrue(in_array('0 = 0 or ends in 01-19 (translated)', $plurals));
$this->assertTrue(in_array('0 = 0 or ends in 01-19 (translated)', $plurals));
$this->assertTrue(in_array('1 = 1 (translated)', $plurals));
$this->assertTrue(in_array('2 = 0 or ends in 01-19 (translated)', $plurals));
$this->assertTrue(in_array('3 = 0 or ends in 01-19 (translated)', $plurals));
$this->assertTrue(in_array('4 = 0 or ends in 01-19 (translated)', $plurals));
$this->assertTrue(in_array('5 = 0 or ends in 01-19 (translated)', $plurals));
$this->assertTrue(in_array('6 = 0 or ends in 01-19 (translated)', $plurals));
$this->assertTrue(in_array('7 = 0 or ends in 01-19 (translated)', $plurals));
$this->assertTrue(in_array('8 = 0 or ends in 01-19 (translated)', $plurals));
$this->assertTrue(in_array('9 = 0 or ends in 01-19 (translated)', $plurals));
$this->assertTrue(in_array('10 = 0 or ends in 01-19 (translated)', $plurals));
$this->assertTrue(in_array('11 = 0 or ends in 01-19 (translated)', $plurals));
$this->assertTrue(in_array('12 = 0 or ends in 01-19 (translated)', $plurals));
$this->assertTrue(in_array('13 = 0 or ends in 01-19 (translated)', $plurals));
$this->assertTrue(in_array('14 = 0 or ends in 01-19 (translated)', $plurals));
$this->assertTrue(in_array('15 = 0 or ends in 01-19 (translated)', $plurals));
$this->assertTrue(in_array('16 = 0 or ends in 01-19 (translated)', $plurals));
$this->assertTrue(in_array('17 = 0 or ends in 01-19 (translated)', $plurals));
$this->assertTrue(in_array('18 = 0 or ends in 01-19 (translated)', $plurals));
$this->assertTrue(in_array('19 = 0 or ends in 01-19 (translated)', $plurals));
$this->assertTrue(in_array('20 everything else (translated)', $plurals));
$this->assertTrue(in_array('21 everything else (translated)', $plurals));
$this->assertTrue(in_array('22 everything else (translated)', $plurals));
$this->assertTrue(in_array('23 everything else (translated)', $plurals));
$this->assertTrue(in_array('24 everything else (translated)', $plurals));
$this->assertTrue(in_array('25 everything else (translated)', $plurals));
$coreSingular = $this->__singularFromCore();
$this->assertEqual('Plural Rule 5 (from core translated)', $coreSingular);
$corePlurals = $this->__pluralFromCore();
$this->assertTrue(in_array('0 = 0 or ends in 01-19 (from core translated)', $corePlurals));
$this->assertTrue(in_array('0 = 0 or ends in 01-19 (from core translated)', $corePlurals));
$this->assertTrue(in_array('1 = 1 (from core translated)', $corePlurals));
$this->assertTrue(in_array('2 = 0 or ends in 01-19 (from core translated)', $corePlurals));
$this->assertTrue(in_array('3 = 0 or ends in 01-19 (from core translated)', $corePlurals));
$this->assertTrue(in_array('4 = 0 or ends in 01-19 (from core translated)', $corePlurals));
$this->assertTrue(in_array('5 = 0 or ends in 01-19 (from core translated)', $corePlurals));
$this->assertTrue(in_array('6 = 0 or ends in 01-19 (from core translated)', $corePlurals));
$this->assertTrue(in_array('7 = 0 or ends in 01-19 (from core translated)', $corePlurals));
$this->assertTrue(in_array('8 = 0 or ends in 01-19 (from core translated)', $corePlurals));
$this->assertTrue(in_array('9 = 0 or ends in 01-19 (from core translated)', $corePlurals));
$this->assertTrue(in_array('10 = 0 or ends in 01-19 (from core translated)', $corePlurals));
$this->assertTrue(in_array('11 = 0 or ends in 01-19 (from core translated)', $corePlurals));
$this->assertTrue(in_array('12 = 0 or ends in 01-19 (from core translated)', $corePlurals));
$this->assertTrue(in_array('13 = 0 or ends in 01-19 (from core translated)', $corePlurals));
$this->assertTrue(in_array('14 = 0 or ends in 01-19 (from core translated)', $corePlurals));
$this->assertTrue(in_array('15 = 0 or ends in 01-19 (from core translated)', $corePlurals));
$this->assertTrue(in_array('16 = 0 or ends in 01-19 (from core translated)', $corePlurals));
$this->assertTrue(in_array('17 = 0 or ends in 01-19 (from core translated)', $corePlurals));
$this->assertTrue(in_array('18 = 0 or ends in 01-19 (from core translated)', $corePlurals));
$this->assertTrue(in_array('19 = 0 or ends in 01-19 (from core translated)', $corePlurals));
$this->assertTrue(in_array('20 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('21 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('22 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('23 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('24 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('25 everything else (from core translated)', $corePlurals));
}
/**
* testPoRulesSix method
*
* @return void
*/
public function testPoRulesSix() {
Configure::write('Config.language', 'rule_6_po');
$singular = $this->__singular();
$this->assertEqual('Plural Rule 6 (translated)', $singular);
$plurals = $this->__plural();
$this->assertTrue(in_array('0 ends in 0 or ends in 10-20 (translated)', $plurals));
$this->assertTrue(in_array('1 ends in 1, not 11 (translated)', $plurals));
$this->assertTrue(in_array('2 everything else (translated)', $plurals));
$this->assertTrue(in_array('3 everything else (translated)', $plurals));
$this->assertTrue(in_array('4 everything else (translated)', $plurals));
$this->assertTrue(in_array('5 everything else (translated)', $plurals));
$this->assertTrue(in_array('6 everything else (translated)', $plurals));
$this->assertTrue(in_array('7 everything else (translated)', $plurals));
$this->assertTrue(in_array('8 everything else (translated)', $plurals));
$this->assertTrue(in_array('9 everything else (translated)', $plurals));
$this->assertTrue(in_array('10 ends in 0 or ends in 10-20 (translated)', $plurals));
$this->assertTrue(in_array('11 ends in 0 or ends in 10-20 (translated)', $plurals));
$this->assertTrue(in_array('12 ends in 0 or ends in 10-20 (translated)', $plurals));
$this->assertTrue(in_array('13 ends in 0 or ends in 10-20 (translated)', $plurals));
$this->assertTrue(in_array('14 ends in 0 or ends in 10-20 (translated)', $plurals));
$this->assertTrue(in_array('15 ends in 0 or ends in 10-20 (translated)', $plurals));
$this->assertTrue(in_array('16 ends in 0 or ends in 10-20 (translated)', $plurals));
$this->assertTrue(in_array('17 ends in 0 or ends in 10-20 (translated)', $plurals));
$this->assertTrue(in_array('18 ends in 0 or ends in 10-20 (translated)', $plurals));
$this->assertTrue(in_array('19 ends in 0 or ends in 10-20 (translated)', $plurals));
$this->assertTrue(in_array('20 ends in 0 or ends in 10-20 (translated)', $plurals));
$this->assertTrue(in_array('21 ends in 1, not 11 (translated)', $plurals));
$this->assertTrue(in_array('22 everything else (translated)', $plurals));
$this->assertTrue(in_array('23 everything else (translated)', $plurals));
$this->assertTrue(in_array('24 everything else (translated)', $plurals));
$this->assertTrue(in_array('25 everything else (translated)', $plurals));
$coreSingular = $this->__singularFromCore();
$this->assertEqual('Plural Rule 6 (from core translated)', $coreSingular);
$corePlurals = $this->__pluralFromCore();
$this->assertTrue(in_array('0 ends in 0 or ends in 10-20 (from core translated)', $corePlurals));
$this->assertTrue(in_array('1 ends in 1, not 11 (from core translated)', $corePlurals));
$this->assertTrue(in_array('2 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('3 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('4 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('5 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('6 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('7 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('8 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('9 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('10 ends in 0 or ends in 10-20 (from core translated)', $corePlurals));
$this->assertTrue(in_array('11 ends in 0 or ends in 10-20 (from core translated)', $corePlurals));
$this->assertTrue(in_array('12 ends in 0 or ends in 10-20 (from core translated)', $corePlurals));
$this->assertTrue(in_array('13 ends in 0 or ends in 10-20 (from core translated)', $corePlurals));
$this->assertTrue(in_array('14 ends in 0 or ends in 10-20 (from core translated)', $corePlurals));
$this->assertTrue(in_array('15 ends in 0 or ends in 10-20 (from core translated)', $corePlurals));
$this->assertTrue(in_array('16 ends in 0 or ends in 10-20 (from core translated)', $corePlurals));
$this->assertTrue(in_array('17 ends in 0 or ends in 10-20 (from core translated)', $corePlurals));
$this->assertTrue(in_array('18 ends in 0 or ends in 10-20 (from core translated)', $corePlurals));
$this->assertTrue(in_array('19 ends in 0 or ends in 10-20 (from core translated)', $corePlurals));
$this->assertTrue(in_array('20 ends in 0 or ends in 10-20 (from core translated)', $corePlurals));
$this->assertTrue(in_array('21 ends in 1, not 11 (from core translated)', $corePlurals));
$this->assertTrue(in_array('22 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('23 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('24 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('25 everything else (from core translated)', $corePlurals));
}
/**
* testMoRulesSix method
*
* @return void
*/
public function testMoRulesSix() {
Configure::write('Config.language', 'rule_6_mo');
$singular = $this->__singular();
$this->assertEqual('Plural Rule 6 (translated)', $singular);
$plurals = $this->__plural();
$this->assertTrue(in_array('0 ends in 0 or ends in 10-20 (translated)', $plurals));
$this->assertTrue(in_array('1 ends in 1, not 11 (translated)', $plurals));
$this->assertTrue(in_array('2 everything else (translated)', $plurals));
$this->assertTrue(in_array('3 everything else (translated)', $plurals));
$this->assertTrue(in_array('4 everything else (translated)', $plurals));
$this->assertTrue(in_array('5 everything else (translated)', $plurals));
$this->assertTrue(in_array('6 everything else (translated)', $plurals));
$this->assertTrue(in_array('7 everything else (translated)', $plurals));
$this->assertTrue(in_array('8 everything else (translated)', $plurals));
$this->assertTrue(in_array('9 everything else (translated)', $plurals));
$this->assertTrue(in_array('10 ends in 0 or ends in 10-20 (translated)', $plurals));
$this->assertTrue(in_array('11 ends in 0 or ends in 10-20 (translated)', $plurals));
$this->assertTrue(in_array('12 ends in 0 or ends in 10-20 (translated)', $plurals));
$this->assertTrue(in_array('13 ends in 0 or ends in 10-20 (translated)', $plurals));
$this->assertTrue(in_array('14 ends in 0 or ends in 10-20 (translated)', $plurals));
$this->assertTrue(in_array('15 ends in 0 or ends in 10-20 (translated)', $plurals));
$this->assertTrue(in_array('16 ends in 0 or ends in 10-20 (translated)', $plurals));
$this->assertTrue(in_array('17 ends in 0 or ends in 10-20 (translated)', $plurals));
$this->assertTrue(in_array('18 ends in 0 or ends in 10-20 (translated)', $plurals));
$this->assertTrue(in_array('19 ends in 0 or ends in 10-20 (translated)', $plurals));
$this->assertTrue(in_array('20 ends in 0 or ends in 10-20 (translated)', $plurals));
$this->assertTrue(in_array('21 ends in 1, not 11 (translated)', $plurals));
$this->assertTrue(in_array('22 everything else (translated)', $plurals));
$this->assertTrue(in_array('23 everything else (translated)', $plurals));
$this->assertTrue(in_array('24 everything else (translated)', $plurals));
$this->assertTrue(in_array('25 everything else (translated)', $plurals));
$coreSingular = $this->__singularFromCore();
$this->assertEqual('Plural Rule 6 (from core translated)', $coreSingular);
$corePlurals = $this->__pluralFromCore();
$this->assertTrue(in_array('0 ends in 0 or ends in 10-20 (from core translated)', $corePlurals));
$this->assertTrue(in_array('1 ends in 1, not 11 (from core translated)', $corePlurals));
$this->assertTrue(in_array('2 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('3 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('4 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('5 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('6 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('7 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('8 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('9 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('10 ends in 0 or ends in 10-20 (from core translated)', $corePlurals));
$this->assertTrue(in_array('11 ends in 0 or ends in 10-20 (from core translated)', $corePlurals));
$this->assertTrue(in_array('12 ends in 0 or ends in 10-20 (from core translated)', $corePlurals));
$this->assertTrue(in_array('13 ends in 0 or ends in 10-20 (from core translated)', $corePlurals));
$this->assertTrue(in_array('14 ends in 0 or ends in 10-20 (from core translated)', $corePlurals));
$this->assertTrue(in_array('15 ends in 0 or ends in 10-20 (from core translated)', $corePlurals));
$this->assertTrue(in_array('16 ends in 0 or ends in 10-20 (from core translated)', $corePlurals));
$this->assertTrue(in_array('17 ends in 0 or ends in 10-20 (from core translated)', $corePlurals));
$this->assertTrue(in_array('18 ends in 0 or ends in 10-20 (from core translated)', $corePlurals));
$this->assertTrue(in_array('19 ends in 0 or ends in 10-20 (from core translated)', $corePlurals));
$this->assertTrue(in_array('20 ends in 0 or ends in 10-20 (from core translated)', $corePlurals));
$this->assertTrue(in_array('21 ends in 1, not 11 (from core translated)', $corePlurals));
$this->assertTrue(in_array('22 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('23 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('24 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('25 everything else (from core translated)', $corePlurals));
}
/**
* testPoRulesSeven method
*
* @return void
*/
public function testPoRulesSeven() {
Configure::write('Config.language', 'rule_7_po');
$singular = $this->__singular();
$this->assertEqual('Plural Rule 7 (translated)', $singular);
$plurals = $this->__plural();
$this->assertTrue(in_array('0 everything else (translated)', $plurals));
$this->assertTrue(in_array('1 ends in 1, not 11 (translated)', $plurals));
$this->assertTrue(in_array('2 ends in 2-4, not 12-14 (translated)', $plurals));
$this->assertTrue(in_array('3 ends in 2-4, not 12-14 (translated)', $plurals));
$this->assertTrue(in_array('4 ends in 2-4, not 12-14 (translated)', $plurals));
$this->assertTrue(in_array('5 everything else (translated)', $plurals));
$this->assertTrue(in_array('6 everything else (translated)', $plurals));
$this->assertTrue(in_array('7 everything else (translated)', $plurals));
$this->assertTrue(in_array('8 everything else (translated)', $plurals));
$this->assertTrue(in_array('9 everything else (translated)', $plurals));
$this->assertTrue(in_array('10 everything else (translated)', $plurals));
$this->assertTrue(in_array('11 everything else (translated)', $plurals));
$this->assertTrue(in_array('12 everything else (translated)', $plurals));
$this->assertTrue(in_array('13 everything else (translated)', $plurals));
$this->assertTrue(in_array('14 everything else (translated)', $plurals));
$this->assertTrue(in_array('15 everything else (translated)', $plurals));
$this->assertTrue(in_array('16 everything else (translated)', $plurals));
$this->assertTrue(in_array('17 everything else (translated)', $plurals));
$this->assertTrue(in_array('18 everything else (translated)', $plurals));
$this->assertTrue(in_array('19 everything else (translated)', $plurals));
$this->assertTrue(in_array('20 everything else (translated)', $plurals));
$this->assertTrue(in_array('21 ends in 1, not 11 (translated)', $plurals));
$this->assertTrue(in_array('22 ends in 2-4, not 12-14 (translated)', $plurals));
$this->assertTrue(in_array('23 ends in 2-4, not 12-14 (translated)', $plurals));
$this->assertTrue(in_array('24 ends in 2-4, not 12-14 (translated)', $plurals));
$this->assertTrue(in_array('25 everything else (translated)', $plurals));
$coreSingular = $this->__singularFromCore();
$this->assertEqual('Plural Rule 7 (from core translated)', $coreSingular);
$corePlurals = $this->__pluralFromCore();
$this->assertTrue(in_array('0 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('1 ends in 1, not 11 (from core translated)', $corePlurals));
$this->assertTrue(in_array('2 ends in 2-4, not 12-14 (from core translated)', $corePlurals));
$this->assertTrue(in_array('3 ends in 2-4, not 12-14 (from core translated)', $corePlurals));
$this->assertTrue(in_array('4 ends in 2-4, not 12-14 (from core translated)', $corePlurals));
$this->assertTrue(in_array('5 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('6 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('7 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('8 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('9 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('10 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('11 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('12 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('13 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('14 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('15 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('16 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('17 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('18 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('19 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('20 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('21 ends in 1, not 11 (from core translated)', $corePlurals));
$this->assertTrue(in_array('22 ends in 2-4, not 12-14 (from core translated)', $corePlurals));
$this->assertTrue(in_array('23 ends in 2-4, not 12-14 (from core translated)', $corePlurals));
$this->assertTrue(in_array('24 ends in 2-4, not 12-14 (from core translated)', $corePlurals));
$this->assertTrue(in_array('25 everything else (from core translated)', $corePlurals));
}
/**
* testMoRulesSeven method
*
* @return void
*/
public function testMoRulesSeven() {
Configure::write('Config.language', 'rule_7_mo');
$singular = $this->__singular();
$this->assertEqual('Plural Rule 7 (translated)', $singular);
$plurals = $this->__plural();
$this->assertTrue(in_array('0 everything else (translated)', $plurals));
$this->assertTrue(in_array('1 ends in 1, not 11 (translated)', $plurals));
$this->assertTrue(in_array('2 ends in 2-4, not 12-14 (translated)', $plurals));
$this->assertTrue(in_array('3 ends in 2-4, not 12-14 (translated)', $plurals));
$this->assertTrue(in_array('4 ends in 2-4, not 12-14 (translated)', $plurals));
$this->assertTrue(in_array('5 everything else (translated)', $plurals));
$this->assertTrue(in_array('6 everything else (translated)', $plurals));
$this->assertTrue(in_array('7 everything else (translated)', $plurals));
$this->assertTrue(in_array('8 everything else (translated)', $plurals));
$this->assertTrue(in_array('9 everything else (translated)', $plurals));
$this->assertTrue(in_array('10 everything else (translated)', $plurals));
$this->assertTrue(in_array('11 everything else (translated)', $plurals));
$this->assertTrue(in_array('12 everything else (translated)', $plurals));
$this->assertTrue(in_array('13 everything else (translated)', $plurals));
$this->assertTrue(in_array('14 everything else (translated)', $plurals));
$this->assertTrue(in_array('15 everything else (translated)', $plurals));
$this->assertTrue(in_array('16 everything else (translated)', $plurals));
$this->assertTrue(in_array('17 everything else (translated)', $plurals));
$this->assertTrue(in_array('18 everything else (translated)', $plurals));
$this->assertTrue(in_array('19 everything else (translated)', $plurals));
$this->assertTrue(in_array('20 everything else (translated)', $plurals));
$this->assertTrue(in_array('21 ends in 1, not 11 (translated)', $plurals));
$this->assertTrue(in_array('22 ends in 2-4, not 12-14 (translated)', $plurals));
$this->assertTrue(in_array('23 ends in 2-4, not 12-14 (translated)', $plurals));
$this->assertTrue(in_array('24 ends in 2-4, not 12-14 (translated)', $plurals));
$this->assertTrue(in_array('25 everything else (translated)', $plurals));
$coreSingular = $this->__singularFromCore();
$this->assertEqual('Plural Rule 7 (from core translated)', $coreSingular);
$corePlurals = $this->__pluralFromCore();
$this->assertTrue(in_array('0 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('1 ends in 1, not 11 (from core translated)', $corePlurals));
$this->assertTrue(in_array('2 ends in 2-4, not 12-14 (from core translated)', $corePlurals));
$this->assertTrue(in_array('3 ends in 2-4, not 12-14 (from core translated)', $corePlurals));
$this->assertTrue(in_array('4 ends in 2-4, not 12-14 (from core translated)', $corePlurals));
$this->assertTrue(in_array('5 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('6 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('7 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('8 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('9 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('10 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('11 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('12 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('13 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('14 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('15 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('16 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('17 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('18 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('19 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('20 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('21 ends in 1, not 11 (from core translated)', $corePlurals));
$this->assertTrue(in_array('22 ends in 2-4, not 12-14 (from core translated)', $corePlurals));
$this->assertTrue(in_array('23 ends in 2-4, not 12-14 (from core translated)', $corePlurals));
$this->assertTrue(in_array('24 ends in 2-4, not 12-14 (from core translated)', $corePlurals));
$this->assertTrue(in_array('25 everything else (from core translated)', $corePlurals));
}
/**
* testPoRulesEight method
*
* @return void
*/
public function testPoRulesEight() {
Configure::write('Config.language', 'rule_8_po');
$singular = $this->__singular();
$this->assertEqual('Plural Rule 8 (translated)', $singular);
$plurals = $this->__plural();
$this->assertTrue(in_array('0 everything else (translated)', $plurals));
$this->assertTrue(in_array('1 is 1 (translated)', $plurals));
$this->assertTrue(in_array('2 is 2-4 (translated)', $plurals));
$this->assertTrue(in_array('3 is 2-4 (translated)', $plurals));
$this->assertTrue(in_array('4 is 2-4 (translated)', $plurals));
$this->assertTrue(in_array('5 everything else (translated)', $plurals));
$this->assertTrue(in_array('6 everything else (translated)', $plurals));
$this->assertTrue(in_array('7 everything else (translated)', $plurals));
$this->assertTrue(in_array('8 everything else (translated)', $plurals));
$this->assertTrue(in_array('9 everything else (translated)', $plurals));
$this->assertTrue(in_array('10 everything else (translated)', $plurals));
$this->assertTrue(in_array('11 everything else (translated)', $plurals));
$this->assertTrue(in_array('12 everything else (translated)', $plurals));
$this->assertTrue(in_array('13 everything else (translated)', $plurals));
$this->assertTrue(in_array('14 everything else (translated)', $plurals));
$this->assertTrue(in_array('15 everything else (translated)', $plurals));
$this->assertTrue(in_array('16 everything else (translated)', $plurals));
$this->assertTrue(in_array('17 everything else (translated)', $plurals));
$this->assertTrue(in_array('18 everything else (translated)', $plurals));
$this->assertTrue(in_array('19 everything else (translated)', $plurals));
$this->assertTrue(in_array('20 everything else (translated)', $plurals));
$this->assertTrue(in_array('21 everything else (translated)', $plurals));
$this->assertTrue(in_array('22 everything else (translated)', $plurals));
$this->assertTrue(in_array('23 everything else (translated)', $plurals));
$this->assertTrue(in_array('24 everything else (translated)', $plurals));
$this->assertTrue(in_array('25 everything else (translated)', $plurals));
$coreSingular = $this->__singularFromCore();
$this->assertEqual('Plural Rule 8 (from core translated)', $coreSingular);
$corePlurals = $this->__pluralFromCore();
$this->assertTrue(in_array('0 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('1 is 1 (from core translated)', $corePlurals));
$this->assertTrue(in_array('2 is 2-4 (from core translated)', $corePlurals));
$this->assertTrue(in_array('3 is 2-4 (from core translated)', $corePlurals));
$this->assertTrue(in_array('4 is 2-4 (from core translated)', $corePlurals));
$this->assertTrue(in_array('5 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('6 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('7 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('8 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('9 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('10 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('11 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('12 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('13 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('14 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('15 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('16 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('17 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('18 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('19 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('20 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('21 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('22 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('23 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('24 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('25 everything else (from core translated)', $corePlurals));
}
/**
* testMoRulesEight method
*
* @return void
*/
public function testMoRulesEight() {
Configure::write('Config.language', 'rule_8_mo');
$singular = $this->__singular();
$this->assertEqual('Plural Rule 8 (translated)', $singular);
$plurals = $this->__plural();
$this->assertTrue(in_array('0 everything else (translated)', $plurals));
$this->assertTrue(in_array('1 is 1 (translated)', $plurals));
$this->assertTrue(in_array('2 is 2-4 (translated)', $plurals));
$this->assertTrue(in_array('3 is 2-4 (translated)', $plurals));
$this->assertTrue(in_array('4 is 2-4 (translated)', $plurals));
$this->assertTrue(in_array('5 everything else (translated)', $plurals));
$this->assertTrue(in_array('6 everything else (translated)', $plurals));
$this->assertTrue(in_array('7 everything else (translated)', $plurals));
$this->assertTrue(in_array('8 everything else (translated)', $plurals));
$this->assertTrue(in_array('9 everything else (translated)', $plurals));
$this->assertTrue(in_array('10 everything else (translated)', $plurals));
$this->assertTrue(in_array('11 everything else (translated)', $plurals));
$this->assertTrue(in_array('12 everything else (translated)', $plurals));
$this->assertTrue(in_array('13 everything else (translated)', $plurals));
$this->assertTrue(in_array('14 everything else (translated)', $plurals));
$this->assertTrue(in_array('15 everything else (translated)', $plurals));
$this->assertTrue(in_array('16 everything else (translated)', $plurals));
$this->assertTrue(in_array('17 everything else (translated)', $plurals));
$this->assertTrue(in_array('18 everything else (translated)', $plurals));
$this->assertTrue(in_array('19 everything else (translated)', $plurals));
$this->assertTrue(in_array('20 everything else (translated)', $plurals));
$this->assertTrue(in_array('21 everything else (translated)', $plurals));
$this->assertTrue(in_array('22 everything else (translated)', $plurals));
$this->assertTrue(in_array('23 everything else (translated)', $plurals));
$this->assertTrue(in_array('24 everything else (translated)', $plurals));
$this->assertTrue(in_array('25 everything else (translated)', $plurals));
$coreSingular = $this->__singularFromCore();
$this->assertEqual('Plural Rule 8 (from core translated)', $coreSingular);
$corePlurals = $this->__pluralFromCore();
$this->assertTrue(in_array('0 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('1 is 1 (from core translated)', $corePlurals));
$this->assertTrue(in_array('2 is 2-4 (from core translated)', $corePlurals));
$this->assertTrue(in_array('3 is 2-4 (from core translated)', $corePlurals));
$this->assertTrue(in_array('4 is 2-4 (from core translated)', $corePlurals));
$this->assertTrue(in_array('5 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('6 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('7 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('8 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('9 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('10 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('11 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('12 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('13 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('14 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('15 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('16 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('17 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('18 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('19 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('20 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('21 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('22 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('23 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('24 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('25 everything else (from core translated)', $corePlurals));
}
/**
* testPoRulesNine method
*
* @return void
*/
public function testPoRulesNine() {
Configure::write('Config.language', 'rule_9_po');
$singular = $this->__singular();
$this->assertEqual('Plural Rule 9 (translated)', $singular);
$plurals = $this->__plural();
$this->assertTrue(in_array('0 everything else (translated)', $plurals));
$this->assertTrue(in_array('0 everything else (translated)', $plurals));
$this->assertTrue(in_array('1 is 1 (translated)', $plurals));
$this->assertTrue(in_array('2 ends in 2-4, not 12-14 (translated)', $plurals));
$this->assertTrue(in_array('3 ends in 2-4, not 12-14 (translated)', $plurals));
$this->assertTrue(in_array('4 ends in 2-4, not 12-14 (translated)', $plurals));
$this->assertTrue(in_array('5 everything else (translated)', $plurals));
$this->assertTrue(in_array('6 everything else (translated)', $plurals));
$this->assertTrue(in_array('7 everything else (translated)', $plurals));
$this->assertTrue(in_array('8 everything else (translated)', $plurals));
$this->assertTrue(in_array('9 everything else (translated)', $plurals));
$this->assertTrue(in_array('10 everything else (translated)', $plurals));
$this->assertTrue(in_array('11 everything else (translated)', $plurals));
$this->assertTrue(in_array('12 everything else (translated)', $plurals));
$this->assertTrue(in_array('13 everything else (translated)', $plurals));
$this->assertTrue(in_array('14 everything else (translated)', $plurals));
$this->assertTrue(in_array('15 everything else (translated)', $plurals));
$this->assertTrue(in_array('16 everything else (translated)', $plurals));
$this->assertTrue(in_array('17 everything else (translated)', $plurals));
$this->assertTrue(in_array('18 everything else (translated)', $plurals));
$this->assertTrue(in_array('19 everything else (translated)', $plurals));
$this->assertTrue(in_array('20 everything else (translated)', $plurals));
$this->assertTrue(in_array('21 everything else (translated)', $plurals));
$this->assertTrue(in_array('22 ends in 2-4, not 12-14 (translated)', $plurals));
$this->assertTrue(in_array('23 ends in 2-4, not 12-14 (translated)', $plurals));
$this->assertTrue(in_array('24 ends in 2-4, not 12-14 (translated)', $plurals));
$this->assertTrue(in_array('25 everything else (translated)', $plurals));
$coreSingular = $this->__singularFromCore();
$this->assertEqual('Plural Rule 9 (from core translated)', $coreSingular);
$corePlurals = $this->__pluralFromCore();
$this->assertTrue(in_array('0 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('0 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('0 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('1 is 1 (from core translated)', $corePlurals));
$this->assertTrue(in_array('2 ends in 2-4, not 12-14 (from core translated)', $corePlurals));
$this->assertTrue(in_array('3 ends in 2-4, not 12-14 (from core translated)', $corePlurals));
$this->assertTrue(in_array('4 ends in 2-4, not 12-14 (from core translated)', $corePlurals));
$this->assertTrue(in_array('5 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('6 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('7 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('8 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('9 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('10 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('11 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('12 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('13 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('14 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('15 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('16 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('17 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('18 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('19 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('20 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('21 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('22 ends in 2-4, not 12-14 (from core translated)', $corePlurals));
$this->assertTrue(in_array('23 ends in 2-4, not 12-14 (from core translated)', $corePlurals));
$this->assertTrue(in_array('24 ends in 2-4, not 12-14 (from core translated)', $corePlurals));
$this->assertTrue(in_array('25 everything else (from core translated)', $corePlurals));
}
/**
* testMoRulesNine method
*
* @return void
*/
public function testMoRulesNine() {
Configure::write('Config.language', 'rule_9_po');
$singular = $this->__singular();
$this->assertEqual('Plural Rule 9 (translated)', $singular);
$plurals = $this->__plural();
$this->assertTrue(in_array('0 everything else (translated)', $plurals));
$this->assertTrue(in_array('0 everything else (translated)', $plurals));
$this->assertTrue(in_array('1 is 1 (translated)', $plurals));
$this->assertTrue(in_array('2 ends in 2-4, not 12-14 (translated)', $plurals));
$this->assertTrue(in_array('3 ends in 2-4, not 12-14 (translated)', $plurals));
$this->assertTrue(in_array('4 ends in 2-4, not 12-14 (translated)', $plurals));
$this->assertTrue(in_array('5 everything else (translated)', $plurals));
$this->assertTrue(in_array('6 everything else (translated)', $plurals));
$this->assertTrue(in_array('7 everything else (translated)', $plurals));
$this->assertTrue(in_array('8 everything else (translated)', $plurals));
$this->assertTrue(in_array('9 everything else (translated)', $plurals));
$this->assertTrue(in_array('10 everything else (translated)', $plurals));
$this->assertTrue(in_array('11 everything else (translated)', $plurals));
$this->assertTrue(in_array('12 everything else (translated)', $plurals));
$this->assertTrue(in_array('13 everything else (translated)', $plurals));
$this->assertTrue(in_array('14 everything else (translated)', $plurals));
$this->assertTrue(in_array('15 everything else (translated)', $plurals));
$this->assertTrue(in_array('16 everything else (translated)', $plurals));
$this->assertTrue(in_array('17 everything else (translated)', $plurals));
$this->assertTrue(in_array('18 everything else (translated)', $plurals));
$this->assertTrue(in_array('19 everything else (translated)', $plurals));
$this->assertTrue(in_array('20 everything else (translated)', $plurals));
$this->assertTrue(in_array('21 everything else (translated)', $plurals));
$this->assertTrue(in_array('22 ends in 2-4, not 12-14 (translated)', $plurals));
$this->assertTrue(in_array('23 ends in 2-4, not 12-14 (translated)', $plurals));
$this->assertTrue(in_array('24 ends in 2-4, not 12-14 (translated)', $plurals));
$this->assertTrue(in_array('25 everything else (translated)', $plurals));
$coreSingular = $this->__singularFromCore();
$this->assertEqual('Plural Rule 9 (from core translated)', $coreSingular);
$corePlurals = $this->__pluralFromCore();
$this->assertTrue(in_array('0 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('0 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('0 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('1 is 1 (from core translated)', $corePlurals));
$this->assertTrue(in_array('2 ends in 2-4, not 12-14 (from core translated)', $corePlurals));
$this->assertTrue(in_array('3 ends in 2-4, not 12-14 (from core translated)', $corePlurals));
$this->assertTrue(in_array('4 ends in 2-4, not 12-14 (from core translated)', $corePlurals));
$this->assertTrue(in_array('5 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('6 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('7 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('8 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('9 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('10 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('11 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('12 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('13 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('14 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('15 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('16 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('17 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('18 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('19 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('20 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('21 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('22 ends in 2-4, not 12-14 (from core translated)', $corePlurals));
$this->assertTrue(in_array('23 ends in 2-4, not 12-14 (from core translated)', $corePlurals));
$this->assertTrue(in_array('24 ends in 2-4, not 12-14 (from core translated)', $corePlurals));
$this->assertTrue(in_array('25 everything else (from core translated)', $corePlurals));
}
/**
* testPoRulesTen method
*
* @return void
*/
public function testPoRulesTen() {
Configure::write('Config.language', 'rule_10_po');
$singular = $this->__singular();
$this->assertEqual('Plural Rule 10 (translated)', $singular);
$plurals = $this->__plural();
$this->assertTrue(in_array('0 everything else (translated)', $plurals));
$this->assertTrue(in_array('0 everything else (translated)', $plurals));
$this->assertTrue(in_array('1 ends in 1 (translated)', $plurals));
$this->assertTrue(in_array('2 ends in 2 (translated)', $plurals));
$this->assertTrue(in_array('3 ends in 03-04 (translated)', $plurals));
$this->assertTrue(in_array('4 ends in 03-04 (translated)', $plurals));
$this->assertTrue(in_array('5 everything else (translated)', $plurals));
$this->assertTrue(in_array('6 everything else (translated)', $plurals));
$this->assertTrue(in_array('7 everything else (translated)', $plurals));
$this->assertTrue(in_array('8 everything else (translated)', $plurals));
$this->assertTrue(in_array('9 everything else (translated)', $plurals));
$this->assertTrue(in_array('10 everything else (translated)', $plurals));
$this->assertTrue(in_array('11 everything else (translated)', $plurals));
$this->assertTrue(in_array('12 everything else (translated)', $plurals));
$this->assertTrue(in_array('13 everything else (translated)', $plurals));
$this->assertTrue(in_array('14 everything else (translated)', $plurals));
$this->assertTrue(in_array('15 everything else (translated)', $plurals));
$this->assertTrue(in_array('16 everything else (translated)', $plurals));
$this->assertTrue(in_array('17 everything else (translated)', $plurals));
$this->assertTrue(in_array('18 everything else (translated)', $plurals));
$this->assertTrue(in_array('19 everything else (translated)', $plurals));
$this->assertTrue(in_array('20 everything else (translated)', $plurals));
$this->assertTrue(in_array('21 everything else (translated)', $plurals));
$this->assertTrue(in_array('22 everything else (translated)', $plurals));
$this->assertTrue(in_array('23 everything else (translated)', $plurals));
$this->assertTrue(in_array('24 everything else (translated)', $plurals));
$this->assertTrue(in_array('25 everything else (translated)', $plurals));
$coreSingular = $this->__singularFromCore();
$this->assertEqual('Plural Rule 10 (from core translated)', $coreSingular);
$corePlurals = $this->__pluralFromCore();
$this->assertTrue(in_array('0 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('0 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('1 ends in 1 (from core translated)', $corePlurals));
$this->assertTrue(in_array('2 ends in 2 (from core translated)', $corePlurals));
$this->assertTrue(in_array('3 ends in 03-04 (from core translated)', $corePlurals));
$this->assertTrue(in_array('4 ends in 03-04 (from core translated)', $corePlurals));
$this->assertTrue(in_array('5 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('6 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('7 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('8 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('9 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('10 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('11 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('12 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('13 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('14 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('15 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('16 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('17 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('18 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('19 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('20 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('21 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('22 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('23 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('24 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('25 everything else (from core translated)', $corePlurals));
}
/**
* testMoRulesTen method
*
* @return void
*/
public function testMoRulesTen() {
Configure::write('Config.language', 'rule_10_mo');
$singular = $this->__singular();
$this->assertEqual('Plural Rule 10 (translated)', $singular);
$plurals = $this->__plural();
$this->assertTrue(in_array('0 everything else (translated)', $plurals));
$this->assertTrue(in_array('0 everything else (translated)', $plurals));
$this->assertTrue(in_array('1 ends in 1 (translated)', $plurals));
$this->assertTrue(in_array('2 ends in 2 (translated)', $plurals));
$this->assertTrue(in_array('3 ends in 03-04 (translated)', $plurals));
$this->assertTrue(in_array('4 ends in 03-04 (translated)', $plurals));
$this->assertTrue(in_array('5 everything else (translated)', $plurals));
$this->assertTrue(in_array('6 everything else (translated)', $plurals));
$this->assertTrue(in_array('7 everything else (translated)', $plurals));
$this->assertTrue(in_array('8 everything else (translated)', $plurals));
$this->assertTrue(in_array('9 everything else (translated)', $plurals));
$this->assertTrue(in_array('10 everything else (translated)', $plurals));
$this->assertTrue(in_array('11 everything else (translated)', $plurals));
$this->assertTrue(in_array('12 everything else (translated)', $plurals));
$this->assertTrue(in_array('13 everything else (translated)', $plurals));
$this->assertTrue(in_array('14 everything else (translated)', $plurals));
$this->assertTrue(in_array('15 everything else (translated)', $plurals));
$this->assertTrue(in_array('16 everything else (translated)', $plurals));
$this->assertTrue(in_array('17 everything else (translated)', $plurals));
$this->assertTrue(in_array('18 everything else (translated)', $plurals));
$this->assertTrue(in_array('19 everything else (translated)', $plurals));
$this->assertTrue(in_array('20 everything else (translated)', $plurals));
$this->assertTrue(in_array('21 everything else (translated)', $plurals));
$this->assertTrue(in_array('22 everything else (translated)', $plurals));
$this->assertTrue(in_array('23 everything else (translated)', $plurals));
$this->assertTrue(in_array('24 everything else (translated)', $plurals));
$this->assertTrue(in_array('25 everything else (translated)', $plurals));
$coreSingular = $this->__singularFromCore();
$this->assertEqual('Plural Rule 10 (from core translated)', $coreSingular);
$corePlurals = $this->__pluralFromCore();
$this->assertTrue(in_array('0 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('0 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('1 ends in 1 (from core translated)', $corePlurals));
$this->assertTrue(in_array('2 ends in 2 (from core translated)', $corePlurals));
$this->assertTrue(in_array('3 ends in 03-04 (from core translated)', $corePlurals));
$this->assertTrue(in_array('4 ends in 03-04 (from core translated)', $corePlurals));
$this->assertTrue(in_array('5 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('6 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('7 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('8 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('9 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('10 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('11 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('12 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('13 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('14 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('15 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('16 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('17 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('18 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('19 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('20 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('21 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('22 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('23 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('24 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('25 everything else (from core translated)', $corePlurals));
}
/**
* testPoRulesEleven method
*
* @return void
*/
public function testPoRulesEleven() {
Configure::write('Config.language', 'rule_11_po');
$singular = $this->__singular();
$this->assertEqual('Plural Rule 11 (translated)', $singular);
$plurals = $this->__plural();
$this->assertTrue(in_array('0 everything else (translated)', $plurals));
$this->assertTrue(in_array('1 is 1 (translated)', $plurals));
$this->assertTrue(in_array('2 is 2 (translated)', $plurals));
$this->assertTrue(in_array('3 is 3-6 (translated)', $plurals));
$this->assertTrue(in_array('4 is 3-6 (translated)', $plurals));
$this->assertTrue(in_array('5 is 3-6 (translated)', $plurals));
$this->assertTrue(in_array('6 is 3-6 (translated)', $plurals));
$this->assertTrue(in_array('7 is 7-10 (translated)', $plurals));
$this->assertTrue(in_array('8 is 7-10 (translated)', $plurals));
$this->assertTrue(in_array('9 is 7-10 (translated)', $plurals));
$this->assertTrue(in_array('10 is 7-10 (translated)', $plurals));
$this->assertTrue(in_array('11 everything else (translated)', $plurals));
$this->assertTrue(in_array('12 everything else (translated)', $plurals));
$this->assertTrue(in_array('13 everything else (translated)', $plurals));
$this->assertTrue(in_array('14 everything else (translated)', $plurals));
$this->assertTrue(in_array('15 everything else (translated)', $plurals));
$this->assertTrue(in_array('16 everything else (translated)', $plurals));
$this->assertTrue(in_array('17 everything else (translated)', $plurals));
$this->assertTrue(in_array('18 everything else (translated)', $plurals));
$this->assertTrue(in_array('19 everything else (translated)', $plurals));
$this->assertTrue(in_array('20 everything else (translated)', $plurals));
$this->assertTrue(in_array('21 everything else (translated)', $plurals));
$this->assertTrue(in_array('22 everything else (translated)', $plurals));
$this->assertTrue(in_array('23 everything else (translated)', $plurals));
$this->assertTrue(in_array('24 everything else (translated)', $plurals));
$this->assertTrue(in_array('25 everything else (translated)', $plurals));
$coreSingular = $this->__singularFromCore();
$this->assertEqual('Plural Rule 11 (from core translated)', $coreSingular);
$corePlurals = $this->__pluralFromCore();
$this->assertTrue(in_array('0 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('1 is 1 (from core translated)', $corePlurals));
$this->assertTrue(in_array('2 is 2 (from core translated)', $corePlurals));
$this->assertTrue(in_array('3 is 3-6 (from core translated)', $corePlurals));
$this->assertTrue(in_array('4 is 3-6 (from core translated)', $corePlurals));
$this->assertTrue(in_array('5 is 3-6 (from core translated)', $corePlurals));
$this->assertTrue(in_array('6 is 3-6 (from core translated)', $corePlurals));
$this->assertTrue(in_array('7 is 7-10 (from core translated)', $corePlurals));
$this->assertTrue(in_array('8 is 7-10 (from core translated)', $corePlurals));
$this->assertTrue(in_array('9 is 7-10 (from core translated)', $corePlurals));
$this->assertTrue(in_array('10 is 7-10 (from core translated)', $corePlurals));
$this->assertTrue(in_array('11 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('12 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('13 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('14 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('15 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('16 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('17 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('18 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('19 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('20 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('21 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('22 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('23 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('24 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('25 everything else (from core translated)', $corePlurals));
}
/**
* testMoRulesEleven method
*
* @return void
*/
public function testMoRulesEleven() {
Configure::write('Config.language', 'rule_11_mo');
$singular = $this->__singular();
$this->assertEqual('Plural Rule 11 (translated)', $singular);
$plurals = $this->__plural();
$this->assertTrue(in_array('0 everything else (translated)', $plurals));
$this->assertTrue(in_array('1 is 1 (translated)', $plurals));
$this->assertTrue(in_array('2 is 2 (translated)', $plurals));
$this->assertTrue(in_array('3 is 3-6 (translated)', $plurals));
$this->assertTrue(in_array('4 is 3-6 (translated)', $plurals));
$this->assertTrue(in_array('5 is 3-6 (translated)', $plurals));
$this->assertTrue(in_array('6 is 3-6 (translated)', $plurals));
$this->assertTrue(in_array('7 is 7-10 (translated)', $plurals));
$this->assertTrue(in_array('8 is 7-10 (translated)', $plurals));
$this->assertTrue(in_array('9 is 7-10 (translated)', $plurals));
$this->assertTrue(in_array('10 is 7-10 (translated)', $plurals));
$this->assertTrue(in_array('11 everything else (translated)', $plurals));
$this->assertTrue(in_array('12 everything else (translated)', $plurals));
$this->assertTrue(in_array('13 everything else (translated)', $plurals));
$this->assertTrue(in_array('14 everything else (translated)', $plurals));
$this->assertTrue(in_array('15 everything else (translated)', $plurals));
$this->assertTrue(in_array('16 everything else (translated)', $plurals));
$this->assertTrue(in_array('17 everything else (translated)', $plurals));
$this->assertTrue(in_array('18 everything else (translated)', $plurals));
$this->assertTrue(in_array('19 everything else (translated)', $plurals));
$this->assertTrue(in_array('20 everything else (translated)', $plurals));
$this->assertTrue(in_array('21 everything else (translated)', $plurals));
$this->assertTrue(in_array('22 everything else (translated)', $plurals));
$this->assertTrue(in_array('23 everything else (translated)', $plurals));
$this->assertTrue(in_array('24 everything else (translated)', $plurals));
$this->assertTrue(in_array('25 everything else (translated)', $plurals));
$coreSingular = $this->__singularFromCore();
$this->assertEqual('Plural Rule 11 (from core translated)', $coreSingular);
$corePlurals = $this->__pluralFromCore();
$this->assertTrue(in_array('0 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('1 is 1 (from core translated)', $corePlurals));
$this->assertTrue(in_array('2 is 2 (from core translated)', $corePlurals));
$this->assertTrue(in_array('3 is 3-6 (from core translated)', $corePlurals));
$this->assertTrue(in_array('4 is 3-6 (from core translated)', $corePlurals));
$this->assertTrue(in_array('5 is 3-6 (from core translated)', $corePlurals));
$this->assertTrue(in_array('6 is 3-6 (from core translated)', $corePlurals));
$this->assertTrue(in_array('7 is 7-10 (from core translated)', $corePlurals));
$this->assertTrue(in_array('8 is 7-10 (from core translated)', $corePlurals));
$this->assertTrue(in_array('9 is 7-10 (from core translated)', $corePlurals));
$this->assertTrue(in_array('10 is 7-10 (from core translated)', $corePlurals));
$this->assertTrue(in_array('11 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('12 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('13 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('14 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('15 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('16 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('17 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('18 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('19 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('20 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('21 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('22 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('23 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('24 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('25 everything else (from core translated)', $corePlurals));
}
/**
* testPoRulesTwelve method
*
* @return void
*/
public function testPoRulesTwelve() {
Configure::write('Config.language', 'rule_12_po');
$singular = $this->__singular();
$this->assertEqual('Plural Rule 12 (translated)', $singular);
$plurals = $this->__plural();
$this->assertTrue(in_array('0 is 0 or 3-10 (translated)', $plurals));
$this->assertTrue(in_array('1 is 1 (translated)', $plurals));
$this->assertTrue(in_array('2 is 2 (translated)', $plurals));
$this->assertTrue(in_array('3 is 0 or 3-10 (translated)', $plurals));
$this->assertTrue(in_array('4 is 0 or 3-10 (translated)', $plurals));
$this->assertTrue(in_array('5 is 0 or 3-10 (translated)', $plurals));
$this->assertTrue(in_array('6 is 0 or 3-10 (translated)', $plurals));
$this->assertTrue(in_array('7 is 0 or 3-10 (translated)', $plurals));
$this->assertTrue(in_array('8 is 0 or 3-10 (translated)', $plurals));
$this->assertTrue(in_array('9 is 0 or 3-10 (translated)', $plurals));
$this->assertTrue(in_array('10 is 0 or 3-10 (translated)', $plurals));
$this->assertTrue(in_array('11 everything else (translated)', $plurals));
$this->assertTrue(in_array('12 everything else (translated)', $plurals));
$this->assertTrue(in_array('13 everything else (translated)', $plurals));
$this->assertTrue(in_array('14 everything else (translated)', $plurals));
$this->assertTrue(in_array('15 everything else (translated)', $plurals));
$this->assertTrue(in_array('16 everything else (translated)', $plurals));
$this->assertTrue(in_array('17 everything else (translated)', $plurals));
$this->assertTrue(in_array('18 everything else (translated)', $plurals));
$this->assertTrue(in_array('19 everything else (translated)', $plurals));
$this->assertTrue(in_array('20 everything else (translated)', $plurals));
$this->assertTrue(in_array('21 everything else (translated)', $plurals));
$this->assertTrue(in_array('22 everything else (translated)', $plurals));
$this->assertTrue(in_array('23 everything else (translated)', $plurals));
$this->assertTrue(in_array('24 everything else (translated)', $plurals));
$this->assertTrue(in_array('25 everything else (translated)', $plurals));
$coreSingular = $this->__singularFromCore();
$this->assertEqual('Plural Rule 12 (from core translated)', $coreSingular);
$corePlurals = $this->__pluralFromCore();
$this->assertTrue(in_array('0 is 0 or 3-10 (from core translated)', $corePlurals));
$this->assertTrue(in_array('1 is 1 (from core translated)', $corePlurals));
$this->assertTrue(in_array('2 is 2 (from core translated)', $corePlurals));
$this->assertTrue(in_array('3 is 0 or 3-10 (from core translated)', $corePlurals));
$this->assertTrue(in_array('4 is 0 or 3-10 (from core translated)', $corePlurals));
$this->assertTrue(in_array('5 is 0 or 3-10 (from core translated)', $corePlurals));
$this->assertTrue(in_array('6 is 0 or 3-10 (from core translated)', $corePlurals));
$this->assertTrue(in_array('7 is 0 or 3-10 (from core translated)', $corePlurals));
$this->assertTrue(in_array('8 is 0 or 3-10 (from core translated)', $corePlurals));
$this->assertTrue(in_array('9 is 0 or 3-10 (from core translated)', $corePlurals));
$this->assertTrue(in_array('10 is 0 or 3-10 (from core translated)', $corePlurals));
$this->assertTrue(in_array('11 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('12 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('13 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('14 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('15 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('16 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('17 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('18 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('19 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('20 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('21 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('22 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('23 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('24 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('25 everything else (from core translated)', $corePlurals));
}
/**
* testMoRulesTwelve method
*
* @return void
*/
public function testMoRulesTwelve() {
Configure::write('Config.language', 'rule_12_mo');
$singular = $this->__singular();
$this->assertEqual('Plural Rule 12 (translated)', $singular);
$plurals = $this->__plural();
$this->assertTrue(in_array('0 is 0 or 3-10 (translated)', $plurals));
$this->assertTrue(in_array('1 is 1 (translated)', $plurals));
$this->assertTrue(in_array('2 is 2 (translated)', $plurals));
$this->assertTrue(in_array('3 is 0 or 3-10 (translated)', $plurals));
$this->assertTrue(in_array('4 is 0 or 3-10 (translated)', $plurals));
$this->assertTrue(in_array('5 is 0 or 3-10 (translated)', $plurals));
$this->assertTrue(in_array('6 is 0 or 3-10 (translated)', $plurals));
$this->assertTrue(in_array('7 is 0 or 3-10 (translated)', $plurals));
$this->assertTrue(in_array('8 is 0 or 3-10 (translated)', $plurals));
$this->assertTrue(in_array('9 is 0 or 3-10 (translated)', $plurals));
$this->assertTrue(in_array('10 is 0 or 3-10 (translated)', $plurals));
$this->assertTrue(in_array('11 everything else (translated)', $plurals));
$this->assertTrue(in_array('12 everything else (translated)', $plurals));
$this->assertTrue(in_array('13 everything else (translated)', $plurals));
$this->assertTrue(in_array('14 everything else (translated)', $plurals));
$this->assertTrue(in_array('15 everything else (translated)', $plurals));
$this->assertTrue(in_array('16 everything else (translated)', $plurals));
$this->assertTrue(in_array('17 everything else (translated)', $plurals));
$this->assertTrue(in_array('18 everything else (translated)', $plurals));
$this->assertTrue(in_array('19 everything else (translated)', $plurals));
$this->assertTrue(in_array('20 everything else (translated)', $plurals));
$this->assertTrue(in_array('21 everything else (translated)', $plurals));
$this->assertTrue(in_array('22 everything else (translated)', $plurals));
$this->assertTrue(in_array('23 everything else (translated)', $plurals));
$this->assertTrue(in_array('24 everything else (translated)', $plurals));
$this->assertTrue(in_array('25 everything else (translated)', $plurals));
$coreSingular = $this->__singularFromCore();
$this->assertEqual('Plural Rule 12 (from core translated)', $coreSingular);
$corePlurals = $this->__pluralFromCore();
$this->assertTrue(in_array('0 is 0 or 3-10 (from core translated)', $corePlurals));
$this->assertTrue(in_array('1 is 1 (from core translated)', $corePlurals));
$this->assertTrue(in_array('2 is 2 (from core translated)', $corePlurals));
$this->assertTrue(in_array('3 is 0 or 3-10 (from core translated)', $corePlurals));
$this->assertTrue(in_array('4 is 0 or 3-10 (from core translated)', $corePlurals));
$this->assertTrue(in_array('5 is 0 or 3-10 (from core translated)', $corePlurals));
$this->assertTrue(in_array('6 is 0 or 3-10 (from core translated)', $corePlurals));
$this->assertTrue(in_array('7 is 0 or 3-10 (from core translated)', $corePlurals));
$this->assertTrue(in_array('8 is 0 or 3-10 (from core translated)', $corePlurals));
$this->assertTrue(in_array('9 is 0 or 3-10 (from core translated)', $corePlurals));
$this->assertTrue(in_array('10 is 0 or 3-10 (from core translated)', $corePlurals));
$this->assertTrue(in_array('11 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('12 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('13 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('14 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('15 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('16 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('17 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('18 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('19 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('20 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('21 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('22 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('23 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('24 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('25 everything else (from core translated)', $corePlurals));
}
/**
* testPoRulesThirteen method
*
* @return void
*/
public function testPoRulesThirteen() {
Configure::write('Config.language', 'rule_13_po');
$singular = $this->__singular();
$this->assertEqual('Plural Rule 13 (translated)', $singular);
$plurals = $this->__plural();
$this->assertTrue(in_array('0 is 0 or ends in 01-10 (translated)', $plurals));
$this->assertTrue(in_array('1 is 1 (translated)', $plurals));
$this->assertTrue(in_array('2 is 0 or ends in 01-10 (translated)', $plurals));
$this->assertTrue(in_array('3 is 0 or ends in 01-10 (translated)', $plurals));
$this->assertTrue(in_array('4 is 0 or ends in 01-10 (translated)', $plurals));
$this->assertTrue(in_array('5 is 0 or ends in 01-10 (translated)', $plurals));
$this->assertTrue(in_array('6 is 0 or ends in 01-10 (translated)', $plurals));
$this->assertTrue(in_array('7 is 0 or ends in 01-10 (translated)', $plurals));
$this->assertTrue(in_array('8 is 0 or ends in 01-10 (translated)', $plurals));
$this->assertTrue(in_array('9 is 0 or ends in 01-10 (translated)', $plurals));
$this->assertTrue(in_array('10 is 0 or ends in 01-10 (translated)', $plurals));
$this->assertTrue(in_array('11 ends in 11-20 (translated)', $plurals));
$this->assertTrue(in_array('12 ends in 11-20 (translated)', $plurals));
$this->assertTrue(in_array('13 ends in 11-20 (translated)', $plurals));
$this->assertTrue(in_array('14 ends in 11-20 (translated)', $plurals));
$this->assertTrue(in_array('15 ends in 11-20 (translated)', $plurals));
$this->assertTrue(in_array('16 ends in 11-20 (translated)', $plurals));
$this->assertTrue(in_array('17 ends in 11-20 (translated)', $plurals));
$this->assertTrue(in_array('18 ends in 11-20 (translated)', $plurals));
$this->assertTrue(in_array('19 ends in 11-20 (translated)', $plurals));
$this->assertTrue(in_array('20 ends in 11-20 (translated)', $plurals));
$this->assertTrue(in_array('21 everything else (translated)', $plurals));
$this->assertTrue(in_array('22 everything else (translated)', $plurals));
$this->assertTrue(in_array('23 everything else (translated)', $plurals));
$this->assertTrue(in_array('24 everything else (translated)', $plurals));
$this->assertTrue(in_array('25 everything else (translated)', $plurals));
$coreSingular = $this->__singularFromCore();
$this->assertEqual('Plural Rule 13 (from core translated)', $coreSingular);
$corePlurals = $this->__pluralFromCore();
$this->assertTrue(in_array('0 is 0 or ends in 01-10 (from core translated)', $corePlurals));
$this->assertTrue(in_array('1 is 1 (from core translated)', $corePlurals));
$this->assertTrue(in_array('2 is 0 or ends in 01-10 (from core translated)', $corePlurals));
$this->assertTrue(in_array('3 is 0 or ends in 01-10 (from core translated)', $corePlurals));
$this->assertTrue(in_array('4 is 0 or ends in 01-10 (from core translated)', $corePlurals));
$this->assertTrue(in_array('5 is 0 or ends in 01-10 (from core translated)', $corePlurals));
$this->assertTrue(in_array('6 is 0 or ends in 01-10 (from core translated)', $corePlurals));
$this->assertTrue(in_array('7 is 0 or ends in 01-10 (from core translated)', $corePlurals));
$this->assertTrue(in_array('8 is 0 or ends in 01-10 (from core translated)', $corePlurals));
$this->assertTrue(in_array('9 is 0 or ends in 01-10 (from core translated)', $corePlurals));
$this->assertTrue(in_array('10 is 0 or ends in 01-10 (from core translated)', $corePlurals));
$this->assertTrue(in_array('11 ends in 11-20 (from core translated)', $corePlurals));
$this->assertTrue(in_array('12 ends in 11-20 (from core translated)', $corePlurals));
$this->assertTrue(in_array('13 ends in 11-20 (from core translated)', $corePlurals));
$this->assertTrue(in_array('14 ends in 11-20 (from core translated)', $corePlurals));
$this->assertTrue(in_array('15 ends in 11-20 (from core translated)', $corePlurals));
$this->assertTrue(in_array('16 ends in 11-20 (from core translated)', $corePlurals));
$this->assertTrue(in_array('17 ends in 11-20 (from core translated)', $corePlurals));
$this->assertTrue(in_array('18 ends in 11-20 (from core translated)', $corePlurals));
$this->assertTrue(in_array('19 ends in 11-20 (from core translated)', $corePlurals));
$this->assertTrue(in_array('20 ends in 11-20 (from core translated)', $corePlurals));
$this->assertTrue(in_array('21 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('22 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('23 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('24 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('25 everything else (from core translated)', $corePlurals));
}
/**
* testMoRulesThirteen method
*
* @return void
*/
public function testMoRulesThirteen() {
Configure::write('Config.language', 'rule_13_mo');
$singular = $this->__singular();
$this->assertEqual('Plural Rule 13 (translated)', $singular);
$plurals = $this->__plural();
$this->assertTrue(in_array('0 is 0 or ends in 01-10 (translated)', $plurals));
$this->assertTrue(in_array('1 is 1 (translated)', $plurals));
$this->assertTrue(in_array('2 is 0 or ends in 01-10 (translated)', $plurals));
$this->assertTrue(in_array('3 is 0 or ends in 01-10 (translated)', $plurals));
$this->assertTrue(in_array('4 is 0 or ends in 01-10 (translated)', $plurals));
$this->assertTrue(in_array('5 is 0 or ends in 01-10 (translated)', $plurals));
$this->assertTrue(in_array('6 is 0 or ends in 01-10 (translated)', $plurals));
$this->assertTrue(in_array('7 is 0 or ends in 01-10 (translated)', $plurals));
$this->assertTrue(in_array('8 is 0 or ends in 01-10 (translated)', $plurals));
$this->assertTrue(in_array('9 is 0 or ends in 01-10 (translated)', $plurals));
$this->assertTrue(in_array('10 is 0 or ends in 01-10 (translated)', $plurals));
$this->assertTrue(in_array('11 ends in 11-20 (translated)', $plurals));
$this->assertTrue(in_array('12 ends in 11-20 (translated)', $plurals));
$this->assertTrue(in_array('13 ends in 11-20 (translated)', $plurals));
$this->assertTrue(in_array('14 ends in 11-20 (translated)', $plurals));
$this->assertTrue(in_array('15 ends in 11-20 (translated)', $plurals));
$this->assertTrue(in_array('16 ends in 11-20 (translated)', $plurals));
$this->assertTrue(in_array('17 ends in 11-20 (translated)', $plurals));
$this->assertTrue(in_array('18 ends in 11-20 (translated)', $plurals));
$this->assertTrue(in_array('19 ends in 11-20 (translated)', $plurals));
$this->assertTrue(in_array('20 ends in 11-20 (translated)', $plurals));
$this->assertTrue(in_array('21 everything else (translated)', $plurals));
$this->assertTrue(in_array('22 everything else (translated)', $plurals));
$this->assertTrue(in_array('23 everything else (translated)', $plurals));
$this->assertTrue(in_array('24 everything else (translated)', $plurals));
$this->assertTrue(in_array('25 everything else (translated)', $plurals));
$coreSingular = $this->__singularFromCore();
$this->assertEqual('Plural Rule 13 (from core translated)', $coreSingular);
$corePlurals = $this->__pluralFromCore();
$this->assertTrue(in_array('0 is 0 or ends in 01-10 (from core translated)', $corePlurals));
$this->assertTrue(in_array('1 is 1 (from core translated)', $corePlurals));
$this->assertTrue(in_array('2 is 0 or ends in 01-10 (from core translated)', $corePlurals));
$this->assertTrue(in_array('3 is 0 or ends in 01-10 (from core translated)', $corePlurals));
$this->assertTrue(in_array('4 is 0 or ends in 01-10 (from core translated)', $corePlurals));
$this->assertTrue(in_array('5 is 0 or ends in 01-10 (from core translated)', $corePlurals));
$this->assertTrue(in_array('6 is 0 or ends in 01-10 (from core translated)', $corePlurals));
$this->assertTrue(in_array('7 is 0 or ends in 01-10 (from core translated)', $corePlurals));
$this->assertTrue(in_array('8 is 0 or ends in 01-10 (from core translated)', $corePlurals));
$this->assertTrue(in_array('9 is 0 or ends in 01-10 (from core translated)', $corePlurals));
$this->assertTrue(in_array('10 is 0 or ends in 01-10 (from core translated)', $corePlurals));
$this->assertTrue(in_array('11 ends in 11-20 (from core translated)', $corePlurals));
$this->assertTrue(in_array('12 ends in 11-20 (from core translated)', $corePlurals));
$this->assertTrue(in_array('13 ends in 11-20 (from core translated)', $corePlurals));
$this->assertTrue(in_array('14 ends in 11-20 (from core translated)', $corePlurals));
$this->assertTrue(in_array('15 ends in 11-20 (from core translated)', $corePlurals));
$this->assertTrue(in_array('16 ends in 11-20 (from core translated)', $corePlurals));
$this->assertTrue(in_array('17 ends in 11-20 (from core translated)', $corePlurals));
$this->assertTrue(in_array('18 ends in 11-20 (from core translated)', $corePlurals));
$this->assertTrue(in_array('19 ends in 11-20 (from core translated)', $corePlurals));
$this->assertTrue(in_array('20 ends in 11-20 (from core translated)', $corePlurals));
$this->assertTrue(in_array('21 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('22 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('23 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('24 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('25 everything else (from core translated)', $corePlurals));
}
/**
* testPoRulesFourteen method
*
* @return void
*/
public function testPoRulesFourteen() {
Configure::write('Config.language', 'rule_14_po');
$singular = $this->__singular();
$this->assertEqual('Plural Rule 14 (translated)', $singular);
$plurals = $this->__plural();
$this->assertTrue(in_array('0 everything else (translated)', $plurals));
$this->assertTrue(in_array('1 ends in 1 (translated)', $plurals));
$this->assertTrue(in_array('2 ends in 2 (translated)', $plurals));
$this->assertTrue(in_array('3 everything else (translated)', $plurals));
$this->assertTrue(in_array('4 everything else (translated)', $plurals));
$this->assertTrue(in_array('5 everything else (translated)', $plurals));
$this->assertTrue(in_array('6 everything else (translated)', $plurals));
$this->assertTrue(in_array('7 everything else (translated)', $plurals));
$this->assertTrue(in_array('8 everything else (translated)', $plurals));
$this->assertTrue(in_array('9 everything else (translated)', $plurals));
$this->assertTrue(in_array('10 everything else (translated)', $plurals));
$this->assertTrue(in_array('11 ends in 1 (translated)', $plurals));
$this->assertTrue(in_array('12 ends in 2 (translated)', $plurals));
$this->assertTrue(in_array('13 everything else (translated)', $plurals));
$this->assertTrue(in_array('14 everything else (translated)', $plurals));
$this->assertTrue(in_array('15 everything else (translated)', $plurals));
$this->assertTrue(in_array('16 everything else (translated)', $plurals));
$this->assertTrue(in_array('17 everything else (translated)', $plurals));
$this->assertTrue(in_array('18 everything else (translated)', $plurals));
$this->assertTrue(in_array('19 everything else (translated)', $plurals));
$this->assertTrue(in_array('20 everything else (translated)', $plurals));
$this->assertTrue(in_array('21 ends in 1 (translated)', $plurals));
$this->assertTrue(in_array('22 ends in 2 (translated)', $plurals));
$this->assertTrue(in_array('23 everything else (translated)', $plurals));
$this->assertTrue(in_array('24 everything else (translated)', $plurals));
$this->assertTrue(in_array('25 everything else (translated)', $plurals));
$coreSingular = $this->__singularFromCore();
$this->assertEqual('Plural Rule 14 (from core translated)', $coreSingular);
$corePlurals = $this->__pluralFromCore();
$this->assertTrue(in_array('0 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('1 ends in 1 (from core translated)', $corePlurals));
$this->assertTrue(in_array('2 ends in 2 (from core translated)', $corePlurals));
$this->assertTrue(in_array('3 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('4 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('5 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('6 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('7 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('8 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('9 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('10 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('11 ends in 1 (from core translated)', $corePlurals));
$this->assertTrue(in_array('12 ends in 2 (from core translated)', $corePlurals));
$this->assertTrue(in_array('13 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('14 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('15 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('16 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('17 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('18 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('19 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('20 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('21 ends in 1 (from core translated)', $corePlurals));
$this->assertTrue(in_array('22 ends in 2 (from core translated)', $corePlurals));
$this->assertTrue(in_array('23 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('24 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('25 everything else (from core translated)', $corePlurals));
}
/**
* testMoRulesFourteen method
*
* @return void
*/
public function testMoRulesFourteen() {
Configure::write('Config.language', 'rule_14_mo');
$singular = $this->__singular();
$this->assertEqual('Plural Rule 14 (translated)', $singular);
$plurals = $this->__plural();
$this->assertTrue(in_array('0 everything else (translated)', $plurals));
$this->assertTrue(in_array('1 ends in 1 (translated)', $plurals));
$this->assertTrue(in_array('2 ends in 2 (translated)', $plurals));
$this->assertTrue(in_array('3 everything else (translated)', $plurals));
$this->assertTrue(in_array('4 everything else (translated)', $plurals));
$this->assertTrue(in_array('5 everything else (translated)', $plurals));
$this->assertTrue(in_array('6 everything else (translated)', $plurals));
$this->assertTrue(in_array('7 everything else (translated)', $plurals));
$this->assertTrue(in_array('8 everything else (translated)', $plurals));
$this->assertTrue(in_array('9 everything else (translated)', $plurals));
$this->assertTrue(in_array('10 everything else (translated)', $plurals));
$this->assertTrue(in_array('11 ends in 1 (translated)', $plurals));
$this->assertTrue(in_array('12 ends in 2 (translated)', $plurals));
$this->assertTrue(in_array('13 everything else (translated)', $plurals));
$this->assertTrue(in_array('14 everything else (translated)', $plurals));
$this->assertTrue(in_array('15 everything else (translated)', $plurals));
$this->assertTrue(in_array('16 everything else (translated)', $plurals));
$this->assertTrue(in_array('17 everything else (translated)', $plurals));
$this->assertTrue(in_array('18 everything else (translated)', $plurals));
$this->assertTrue(in_array('19 everything else (translated)', $plurals));
$this->assertTrue(in_array('20 everything else (translated)', $plurals));
$this->assertTrue(in_array('21 ends in 1 (translated)', $plurals));
$this->assertTrue(in_array('22 ends in 2 (translated)', $plurals));
$this->assertTrue(in_array('23 everything else (translated)', $plurals));
$this->assertTrue(in_array('24 everything else (translated)', $plurals));
$this->assertTrue(in_array('25 everything else (translated)', $plurals));
$coreSingular = $this->__singularFromCore();
$this->assertEqual('Plural Rule 14 (from core translated)', $coreSingular);
$corePlurals = $this->__pluralFromCore();
$this->assertTrue(in_array('0 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('1 ends in 1 (from core translated)', $corePlurals));
$this->assertTrue(in_array('2 ends in 2 (from core translated)', $corePlurals));
$this->assertTrue(in_array('3 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('4 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('5 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('6 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('7 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('8 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('9 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('10 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('11 ends in 1 (from core translated)', $corePlurals));
$this->assertTrue(in_array('12 ends in 2 (from core translated)', $corePlurals));
$this->assertTrue(in_array('13 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('14 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('15 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('16 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('17 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('18 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('19 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('20 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('21 ends in 1 (from core translated)', $corePlurals));
$this->assertTrue(in_array('22 ends in 2 (from core translated)', $corePlurals));
$this->assertTrue(in_array('23 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('24 everything else (from core translated)', $corePlurals));
$this->assertTrue(in_array('25 everything else (from core translated)', $corePlurals));
}
/**
* testSetLanguageWithSession method
*
* @return void
*/
public function testSetLanguageWithSession () {
$_SESSION['Config']['language'] = 'po';
$singular = $this->__singular();
$this->assertEqual('Po (translated)', $singular);
$plurals = $this->__plural();
$this->assertTrue(in_array('0 everything else (po translated)', $plurals));
$this->assertTrue(in_array('1 is 1 (po translated)', $plurals));
$this->assertTrue(in_array('2 is 2-4 (po translated)', $plurals));
$this->assertTrue(in_array('3 is 2-4 (po translated)', $plurals));
$this->assertTrue(in_array('4 is 2-4 (po translated)', $plurals));
$this->assertTrue(in_array('5 everything else (po translated)', $plurals));
$this->assertTrue(in_array('6 everything else (po translated)', $plurals));
$this->assertTrue(in_array('7 everything else (po translated)', $plurals));
$this->assertTrue(in_array('8 everything else (po translated)', $plurals));
$this->assertTrue(in_array('9 everything else (po translated)', $plurals));
$this->assertTrue(in_array('10 everything else (po translated)', $plurals));
$this->assertTrue(in_array('11 everything else (po translated)', $plurals));
$this->assertTrue(in_array('12 everything else (po translated)', $plurals));
$this->assertTrue(in_array('13 everything else (po translated)', $plurals));
$this->assertTrue(in_array('14 everything else (po translated)', $plurals));
$this->assertTrue(in_array('15 everything else (po translated)', $plurals));
$this->assertTrue(in_array('16 everything else (po translated)', $plurals));
$this->assertTrue(in_array('17 everything else (po translated)', $plurals));
$this->assertTrue(in_array('18 everything else (po translated)', $plurals));
$this->assertTrue(in_array('19 everything else (po translated)', $plurals));
$this->assertTrue(in_array('20 everything else (po translated)', $plurals));
$this->assertTrue(in_array('21 everything else (po translated)', $plurals));
$this->assertTrue(in_array('22 everything else (po translated)', $plurals));
$this->assertTrue(in_array('23 everything else (po translated)', $plurals));
$this->assertTrue(in_array('24 everything else (po translated)', $plurals));
$this->assertTrue(in_array('25 everything else (po translated)', $plurals));
unset($_SESSION['Config']['language']);
}
/**
* testNoCoreTranslation method
*
* @return void
*/
public function testNoCoreTranslation () {
Configure::write('Config.language', 'po');
$singular = $this->__singular();
$this->assertEqual('Po (translated)', $singular);
$coreSingular = $this->__singularFromCore();
$this->assertNotEqual('Po (from core translated)', $coreSingular);
$corePlurals = $this->__pluralFromCore();
$this->assertFalse(in_array('0 everything else (from core translated)', $corePlurals));
$this->assertFalse(in_array('1 is 1 (from core translated)', $corePlurals));
$this->assertFalse(in_array('2 is 2-4 (from core translated)', $corePlurals));
$this->assertFalse(in_array('3 is 2-4 (from core translated)', $corePlurals));
$this->assertFalse(in_array('4 is 2-4 (from core translated)', $corePlurals));
$this->assertFalse(in_array('5 everything else (from core translated)', $corePlurals));
$this->assertFalse(in_array('6 everything else (from core translated)', $corePlurals));
$this->assertFalse(in_array('7 everything else (from core translated)', $corePlurals));
$this->assertFalse(in_array('8 everything else (from core translated)', $corePlurals));
$this->assertFalse(in_array('9 everything else (from core translated)', $corePlurals));
$this->assertFalse(in_array('10 everything else (from core translated)', $corePlurals));
$this->assertFalse(in_array('11 everything else (from core translated)', $corePlurals));
$this->assertFalse(in_array('12 everything else (from core translated)', $corePlurals));
$this->assertFalse(in_array('13 everything else (from core translated)', $corePlurals));
$this->assertFalse(in_array('14 everything else (from core translated)', $corePlurals));
$this->assertFalse(in_array('15 everything else (from core translated)', $corePlurals));
$this->assertFalse(in_array('16 everything else (from core translated)', $corePlurals));
$this->assertFalse(in_array('17 everything else (from core translated)', $corePlurals));
$this->assertFalse(in_array('18 everything else (from core translated)', $corePlurals));
$this->assertFalse(in_array('19 everything else (from core translated)', $corePlurals));
$this->assertFalse(in_array('20 everything else (from core translated)', $corePlurals));
$this->assertFalse(in_array('21 everything else (from core translated)', $corePlurals));
$this->assertFalse(in_array('22 everything else (from core translated)', $corePlurals));
$this->assertFalse(in_array('23 everything else (from core translated)', $corePlurals));
$this->assertFalse(in_array('24 everything else (from core translated)', $corePlurals));
$this->assertFalse(in_array('25 everything else (from core translated)', $corePlurals));
}
/**
* testPluginTranslation method
*
* @return void
*/
public function testPluginTranslation() {
App::build(array(
'plugins' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS)
));
Configure::write('Config.language', 'po');
$singular = $this->__domainSingular();
$this->assertEqual('Plural Rule 1 (from plugin)', $singular);
$plurals = $this->__domainPlural();
$this->assertTrue(in_array('0 = 0 or > 1 (from plugin)', $plurals));
$this->assertTrue(in_array('1 = 1 (from plugin)', $plurals));
$this->assertTrue(in_array('2 = 0 or > 1 (from plugin)', $plurals));
$this->assertTrue(in_array('3 = 0 or > 1 (from plugin)', $plurals));
$this->assertTrue(in_array('4 = 0 or > 1 (from plugin)', $plurals));
$this->assertTrue(in_array('5 = 0 or > 1 (from plugin)', $plurals));
$this->assertTrue(in_array('6 = 0 or > 1 (from plugin)', $plurals));
$this->assertTrue(in_array('7 = 0 or > 1 (from plugin)', $plurals));
$this->assertTrue(in_array('8 = 0 or > 1 (from plugin)', $plurals));
$this->assertTrue(in_array('9 = 0 or > 1 (from plugin)', $plurals));
$this->assertTrue(in_array('10 = 0 or > 1 (from plugin)', $plurals));
$this->assertTrue(in_array('11 = 0 or > 1 (from plugin)', $plurals));
$this->assertTrue(in_array('12 = 0 or > 1 (from plugin)', $plurals));
$this->assertTrue(in_array('13 = 0 or > 1 (from plugin)', $plurals));
$this->assertTrue(in_array('14 = 0 or > 1 (from plugin)', $plurals));
$this->assertTrue(in_array('15 = 0 or > 1 (from plugin)', $plurals));
$this->assertTrue(in_array('16 = 0 or > 1 (from plugin)', $plurals));
$this->assertTrue(in_array('17 = 0 or > 1 (from plugin)', $plurals));
$this->assertTrue(in_array('18 = 0 or > 1 (from plugin)', $plurals));
$this->assertTrue(in_array('19 = 0 or > 1 (from plugin)', $plurals));
$this->assertTrue(in_array('20 = 0 or > 1 (from plugin)', $plurals));
$this->assertTrue(in_array('21 = 0 or > 1 (from plugin)', $plurals));
$this->assertTrue(in_array('22 = 0 or > 1 (from plugin)', $plurals));
$this->assertTrue(in_array('23 = 0 or > 1 (from plugin)', $plurals));
$this->assertTrue(in_array('24 = 0 or > 1 (from plugin)', $plurals));
$this->assertTrue(in_array('25 = 0 or > 1 (from plugin)', $plurals));
}
/**
* testPoMultipleLineTranslation method
*
* @return void
*/
public function testPoMultipleLineTranslation () {
Configure::write('Config.language', 'po');
$string = "This is a multiline translation\n";
$string .= "broken up over multiple lines.\n";
$string .= "This is the third line.\n";
$string .= "This is the forth line.";
$result = __($string);
$expected = "This is a multiline translation\n";
$expected .= "broken up over multiple lines.\n";
$expected .= "This is the third line.\n";
$expected .= "This is the forth line. (translated)";
$this->assertEqual($expected, $result);
// Windows Newline is \r\n
$string = "This is a multiline translation\r\n";
$string .= "broken up over multiple lines.\r\n";
$string .= "This is the third line.\r\n";
$string .= "This is the forth line.";
$result = __($string);
$this->assertEqual($expected, $result);
$singular = "valid\nsecond line";
$plural = "valids\nsecond line";
$result = __n($singular, $plural, 1);
$expected = "v\nsecond line";
$this->assertEqual($expected, $result);
$result = __n($singular, $plural, 2);
$expected = "vs\nsecond line";
$this->assertEqual($expected, $result);
$string = "This is a multiline translation\n";
$string .= "broken up over multiple lines.\n";
$string .= "This is the third line.\n";
$string .= "This is the forth line.";
$singular = "%d = 1\n" . $string;
$plural = "%d = 0 or > 1\n" . $string;
$result = __n($singular, $plural, 1);
$expected = "%d is 1\n" . $string;
$this->assertEqual($expected, $result);
$result = __n($singular, $plural, 2);
$expected = "%d is 2-4\n" . $string;
$this->assertEqual($expected, $result);
// Windows Newline is \r\n
$string = "This is a multiline translation\r\n";
$string .= "broken up over multiple lines.\r\n";
$string .= "This is the third line.\r\n";
$string .= "This is the forth line.";
$singular = "%d = 1\r\n" . $string;
$plural = "%d = 0 or > 1\r\n" . $string;
$result = __n($singular, $plural, 1);
$expected = "%d is 1\n" . str_replace("\r\n", "\n", $string);
$this->assertEqual($expected, $result);
$result = __n($singular, $plural, 2);
$expected = "%d is 2-4\n" . str_replace("\r\n", "\n", $string);
$this->assertEqual($expected, $result);
}
/**
* testPoNoTranslationNeeded method
*
* @return void
*/
public function testPoNoTranslationNeeded () {
Configure::write('Config.language', 'po');
$result = __('No Translation needed');
$this->assertEqual('No Translation needed', $result);
}
/**
* testPoQuotedString method
*
* @return void
*/
public function testPoQuotedString () {
$expected = 'this is a "quoted string" (translated)';
$this->assertEqual($expected, __('this is a "quoted string"'));
}
/**
* testFloatValue method
*
* @return void
*/
public function testFloatValue() {
Configure::write('Config.language', 'rule_9_po');
$result = __n('%d = 1', '%d = 0 or > 1', (float)1);
$expected = '%d is 1 (translated)';
$this->assertEqual($expected, $result);
$result = __n('%d = 1', '%d = 0 or > 1', (float)2);
$expected = "%d ends in 2-4, not 12-14 (translated)";
$this->assertEqual($expected, $result);
$result = __n('%d = 1', '%d = 0 or > 1', (float)5);
$expected = "%d everything else (translated)";
$this->assertEqual($expected, $result);
}
/**
* testCategory method
*
* @return void
*/
public function testCategory() {
Configure::write('Config.language', 'po');
$category = $this->__category();
$this->assertEqual('Monetary Po (translated)', $category);
}
/**
* testPluginCategory method
*
* @return void
*/
public function testPluginCategory() {
Configure::write('Config.language', 'po');
$singular = $this->__domainCategorySingular();
$this->assertEqual('Monetary Plural Rule 1 (from plugin)', $singular);
$plurals = $this->__domainCategoryPlural();
$this->assertTrue(in_array('Monetary 0 = 0 or > 1 (from plugin)', $plurals));
$this->assertTrue(in_array('Monetary 1 = 1 (from plugin)', $plurals));
}
/**
* testCategoryThenSingular method
*
* @return void
*/
public function testCategoryThenSingular() {
Configure::write('Config.language', 'po');
$category = $this->__category();
$this->assertEqual('Monetary Po (translated)', $category);
$singular = $this->__singular();
$this->assertEqual('Po (translated)', $singular);
}
public function testTimeDefinition() {
Configure::write('Config.language', 'po');
$result = __c('d_fmt', 5);
$expected = '%m/%d/%Y';
$this->assertEqual($expected, $result);
$result = __c('am_pm', 5);
$expected = array('AM', 'PM');
$this->assertEqual($expected, $result);
$result = __c('abmon', 5);
$expected = array('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec');
$this->assertEqual($expected, $result);
}
public function testTimeDefinitionJapanese(){
Configure::write('Config.language', 'ja_jp');
$result = __c('d_fmt', 5);
$expected = "%Y年%m月%d日";
$this->assertEqual($expected, $result);
$result = __c('am_pm', 5);
$expected = array("午前", "午後");
$this->assertEqual($expected, $result);
$result = __c('abmon', 5);
$expected = array(" 1月", " 2月", " 3月", " 4月", " 5月", " 6月", " 7月", " 8月", " 9月", "10月", "11月", "12月");
$this->assertEqual($expected, $result);
}
/**
* Singular method
*
* @return void
*/
function __domainCategorySingular($domain = 'test_plugin', $category = 3) {
$singular = __dc($domain, 'Plural Rule 1', $category);
return $singular;
}
/**
* Plural method
*
* @return void
*/
function __domainCategoryPlural($domain = 'test_plugin', $category = 3) {
$plurals = array();
for ($number = 0; $number <= 25; $number++) {
$plurals[] = sprintf(__dcn($domain, '%d = 1', '%d = 0 or > 1', (float)$number, $category), (float)$number);
}
return $plurals;
}
/**
* Singular method
*
* @return void
*/
function __domainSingular($domain = 'test_plugin') {
$singular = __d($domain, 'Plural Rule 1');
return $singular;
}
/**
* Plural method
*
* @return void
*/
function __domainPlural($domain = 'test_plugin') {
$plurals = array();
for ($number = 0; $number <= 25; $number++) {
$plurals[] = sprintf(__dn($domain, '%d = 1', '%d = 0 or > 1', (float)$number), (float)$number );
}
return $plurals;
}
/**
* category method
*
* @return void
*/
function __category($category = 3) {
$singular = __c('Plural Rule 1', $category);
return $singular;
}
/**
* Singular method
*
* @return void
*/
function __singular() {
$singular = __('Plural Rule 1');
return $singular;
}
/**
* Plural method
*
* @return void
*/
function __plural() {
$plurals = array();
for ($number = 0; $number <= 25; $number++) {
$plurals[] = sprintf(__n('%d = 1', '%d = 0 or > 1', (float)$number), (float)$number);
}
return $plurals;
}
/**
* singularFromCore method
*
* @return void
*/
function __singularFromCore() {
$singular = __('Plural Rule 1 (from core)');
return $singular;
}
/**
* pluralFromCore method
*
* @return void
*/
function __pluralFromCore() {
$plurals = array();
for ($number = 0; $number <= 25; $number++) {
$plurals[] = sprintf(__n('%d = 1 (from core)', '%d = 0 or > 1 (from core)', (float)$number), (float)$number );
}
return $plurals;
}
}
| 0001-bee | trunk/cakephp2/lib/Cake/Test/Case/I18n/I18nTest.php | PHP | gpl3 | 163,563 |
<?php
/**
* IniReaderTest
*
* PHP 5
*
* CakePHP(tm) Tests <http://book.cakephp.org/view/1196/Testing>
* Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice
*
* @copyright Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://book.cakephp.org/view/1196/Testing CakePHP(tm) Tests
* @package Cake.Test.Case.Configure
* @since CakePHP(tm) v 2.0
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
App::uses('IniReader', 'Configure');
class IniReaderTest extends CakeTestCase {
/**
* The test file that will be read.
*
* @var string
*/
public $file;
/**
* setup
*
* @return void
*/
public function setup() {
parent::setup();
$this->path = CAKE . 'Test' . DS . 'test_app' . DS . 'Config'. DS;
}
/**
* test constrction
*
* @return void
*/
public function testConstruct() {
$reader = new IniReader($this->path);
$config = $reader->read('acl.ini.php');
$this->assertTrue(isset($config['admin']));
$this->assertTrue(isset($config['paul']['groups']));
$this->assertEquals('ads', $config['admin']['deny']);
}
/**
* no other sections should exist.
*
* @return void
*/
public function testReadingOnlyOneSection() {
$reader = new IniReader($this->path, 'admin');
$config = $reader->read('acl.ini.php');
$this->assertTrue(isset($config['groups']));
$this->assertEquals('administrators', $config['groups']);
}
/**
* test without section
*
* @return void
*/
public function testReadingWithoutSection() {
$reader = new IniReader($this->path);
$config = $reader->read('no_section.ini');
$expected = array(
'some_key' => 'some_value',
'bool_key' => true
);
$this->assertEquals($config, $expected);
}
/**
* test that names with .'s get exploded into arrays.
*
* @return void
*/
public function testReadingValuesWithDots() {
$reader = new IniReader($this->path);
$config = $reader->read('nested.ini');
$this->assertTrue(isset($config['database']['db']['username']));
$this->assertEquals('mark', $config['database']['db']['username']);
$this->assertEquals(3, $config['nesting']['one']['two']['three']);
}
/**
* test boolean reading
*
* @return void
*/
public function testBooleanReading() {
$reader = new IniReader($this->path);
$config = $reader->read('nested.ini');
$this->assertTrue($config['bools']['test_on']);
$this->assertFalse($config['bools']['test_off']);
$this->assertTrue($config['bools']['test_yes']);
$this->assertFalse($config['bools']['test_no']);
$this->assertTrue($config['bools']['test_true']);
$this->assertFalse($config['bools']['test_false']);
$this->assertFalse($config['bools']['test_null']);
}
/**
* test read file without extension
*
* @return void
*/
public function testReadingWithoutExtension() {
$reader = new IniReader($this->path);
$config = $reader->read('nested');
$this->assertTrue($config['bools']['test_on']);
}
}
| 0001-bee | trunk/cakephp2/lib/Cake/Test/Case/Configure/IniReaderTest.php | PHP | gpl3 | 3,109 |
<?php
/**
* PhpConfigReaderTest
*
* PHP 5
*
* CakePHP(tm) Tests <http://book.cakephp.org/view/1196/Testing>
* Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice
*
* @copyright Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://book.cakephp.org/view/1196/Testing CakePHP(tm) Tests
* @package Cake.Test.Case.Configure
* @since CakePHP(tm) v 2.0
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
App::uses('PhpReader', 'Configure');
class PhpReaderTest extends CakeTestCase {
/**
* setup
*
* @return void
*/
public function setUp() {
parent::setUp();
$this->path = CAKE . 'Test' . DS . 'test_app' . DS . 'Config'. DS;
}
/**
* test reading files
*
* @return void
*/
public function testRead() {
$reader = new PhpReader($this->path);
$values = $reader->read('var_test');
$this->assertEquals('value', $values['Read']);
$this->assertEquals('buried', $values['Deep']['Deeper']['Deepest']);
$values = $reader->read('var_test.php');
$this->assertEquals('value', $values['Read']);
}
/**
* Test an exception is thrown by reading files that don't exist.
*
* @expectedException ConfigureException
* @return void
*/
public function testReadWithNonExistantFile() {
$reader = new PhpReader($this->path);
$reader->read('fake_values');
}
/**
* test reading an empty file.
*
* @expectedException RuntimeException
* @return void
*/
public function testReadEmptyFile() {
$reader = new PhpReader($this->path);
$reader->read('empty');
}
/**
* test reading keys with ../ doesn't work
*
* @expectedException ConfigureException
* @return void
*/
public function testReadWithDots() {
$reader = new PhpReader($this->path);
$reader->read('../empty');
}
/**
* test reading from plugins
*
* @return void
*/
public function testReadPluginValue() {
App::build(array(
'plugins' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS)
), true);
CakePlugin::load('TestPlugin');
$reader = new PhpReader($this->path);
$result = $reader->read('TestPlugin.load');
$this->assertTrue(isset($result['plugin_load']));
$result = $reader->read('TestPlugin.load.php');
$this->assertTrue(isset($result['plugin_load']));
CakePlugin::unload();
}
}
| 0001-bee | trunk/cakephp2/lib/Cake/Test/Case/Configure/PhpReaderTest.php | PHP | gpl3 | 2,451 |
<?php
/**
* CakeTestFixture file
*
* PHP 5
*
* CakePHP(tm) Tests <http://book.cakephp.org/view/1196/Testing>
* Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice
*
* @copyright Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://book.cakephp.org/view/1196/Testing CakePHP(tm) Tests
* @package Cake.Test.Case.TestSuite
* @since CakePHP(tm) v 1.2.0.4667
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
App::uses('DboSource', 'Model/Datasource');
App::uses('Model', 'Model');
App::uses('CakeTestFixture', 'TestSuite/Fixture');
/**
* CakeTestFixtureTestFixture class
*
* @package Cake.Test.Case.TestSuite
*/
class CakeTestFixtureTestFixture extends CakeTestFixture {
/**
* Name property
*
* @var string
*/
public $name = 'FixtureTest';
/**
* Table property
*
* @var string
*/
public $table = 'fixture_tests';
/**
* Fields array
*
* @var array
*/
public $fields = array(
'id' => array('type' => 'integer', 'key' => 'primary'),
'name' => array('type' => 'string', 'length' => '255'),
'created' => array('type' => 'datetime')
);
/**
* Records property
*
* @var array
*/
public $records = array(
array('name' => 'Gandalf', 'created' => '2009-04-28 19:20:00'),
array('name' => 'Captain Picard', 'created' => '2009-04-28 19:20:00'),
array('name' => 'Chewbacca', 'created' => '2009-04-28 19:20:00')
);
}
/**
* StringFieldsTestFixture class
*
* @package Cake.Test.Case.TestSuite
* @subpackage cake.cake.tests.cases.libs
*/
class StringsTestFixture extends CakeTestFixture {
/**
* Name property
*
* @var string
*/
public $name = 'Strings';
/**
* Table property
*
* @var string
*/
public $table = 'strings';
/**
* Fields array
*
* @var array
*/
public $fields = array(
'id' => array('type' => 'integer', 'key' => 'primary'),
'name' => array('type' => 'string', 'length' => '255'),
'email' => array('type' => 'string', 'length' => '255'),
'age' => array('type' => 'integer', 'default' => 10)
);
/**
* Records property
*
* @var array
*/
public $records = array(
array('name' => 'Mark Doe', 'email' => 'mark.doe@email.com'),
array('name' => 'John Doe', 'email' => 'john.doe@email.com', 'age' => 20),
array('email' => 'jane.doe@email.com', 'name' => 'Jane Doe', 'age' => 30)
);
}
/**
* CakeTestFixtureImportFixture class
*
* @package Cake.Test.Case.TestSuite
*/
class CakeTestFixtureImportFixture extends CakeTestFixture {
/**
* Name property
*
* @var string
*/
public $name = 'ImportFixture';
/**
* Import property
*
* @var mixed
*/
public $import = array('table' => 'fixture_tests', 'connection' => 'fixture_test_suite');
}
/**
* CakeTestFixtureDefaultImportFixture class
*
* @package Cake.Test.Case.TestSuite
*/
class CakeTestFixtureDefaultImportFixture extends CakeTestFixture {
/**
* Name property
*
* @var string
*/
public $name = 'ImportFixture';
}
/**
* FixtureImportTestModel class
*
* @package Cake.Test.Case.TestSuite
* @package Cake.Test.Case.TestSuite
*/
class FixtureImportTestModel extends Model {
public $name = 'FixtureImport';
public $useTable = 'fixture_tests';
public $useDbConfig = 'test';
}
class FixturePrefixTest extends Model {
public $name = 'FixturePrefix';
public $useTable = '_tests';
public $tablePrefix = 'fixture';
public $useDbConfig = 'test';
}
/**
* Test case for CakeTestFixture
*
* @package Cake.Test.Case.TestSuite
*/
class CakeTestFixtureTest extends CakeTestCase {
/**
* setUp method
*
* @return void
*/
public function setUp() {
$methods = array_diff(get_class_methods('DboSource'), array('enabled'));
$methods[] = 'connect';
$this->criticDb = $this->getMock('DboSource', $methods);
$this->criticDb->fullDebug = true;
$this->db = ConnectionManager::getDataSource('test');
$this->_backupConfig = $this->db->config;
}
/**
* tearDown
*
* @return void
*/
public function tearDown() {
unset($this->criticDb);
$this->db->config = $this->_backupConfig;
}
/**
* testInit
*
* @return void
*/
public function testInit() {
$Fixture = new CakeTestFixtureTestFixture();
unset($Fixture->table);
$Fixture->init();
$this->assertEqual($Fixture->table, 'fixture_tests');
$this->assertEqual($Fixture->primaryKey, 'id');
$Fixture = new CakeTestFixtureTestFixture();
$Fixture->primaryKey = 'my_random_key';
$Fixture->init();
$this->assertEqual($Fixture->primaryKey, 'my_random_key');
}
/**
* test that init() correctly sets the fixture table when the connection or model have prefixes defined.
*
* @return void
*/
public function testInitDbPrefix() {
$this->skipIf($this->db instanceof Sqlite, 'Cannot open 2 connections to Sqlite');
$db = ConnectionManager::getDataSource('test');
$Source = new CakeTestFixtureTestFixture();
$Source->drop($db);
$Source->create($db);
$Source->insert($db);
$Fixture = new CakeTestFixtureTestFixture();
$expected = array('id', 'name', 'created');
$this->assertEqual(array_keys($Fixture->fields), $expected);
$config = $db->config;
$config['prefix'] = 'fixture_test_suite_';
ConnectionManager::create('fixture_test_suite', $config);
$Fixture->fields = $Fixture->records = null;
$Fixture->import = array('table' => 'fixture_tests', 'connection' => 'test', 'records' => true);
$Fixture->init();
$this->assertEqual(count($Fixture->records), count($Source->records));
$Fixture->create(ConnectionManager::getDataSource('fixture_test_suite'));
$Fixture = new CakeTestFixtureImportFixture();
$Fixture->fields = $Fixture->records = $Fixture->table = null;
$Fixture->import = array('model' => 'FixtureImportTestModel', 'connection' => 'test');
$Fixture->init();
$this->assertEqual(array_keys($Fixture->fields), array('id', 'name', 'created'));
$this->assertEqual($Fixture->table, 'fixture_tests');
$keys = array_flip(ClassRegistry::keys());
$this->assertFalse(array_key_exists('fixtureimporttestmodel', $keys));
$Fixture->drop(ConnectionManager::getDataSource('fixture_test_suite'));
$Source->drop($db);
}
/**
* test that fixtures don't duplicate the test db prefix.
*
* @return void
*/
public function testInitDbPrefixDuplication() {
$this->skipIf($this->db instanceof Sqlite, 'Cannot open 2 connections to Sqlite');
$db = ConnectionManager::getDataSource('test');
$backPrefix = $db->config['prefix'];
$db->config['prefix'] = 'cake_fixture_test_';
ConnectionManager::create('fixture_test_suite', $db->config);
$newDb = ConnectionManager::getDataSource('fixture_test_suite');
$newDb->config['prefix'] = 'cake_fixture_test_';
$Source = new CakeTestFixtureTestFixture();
$Source->create($db);
$Source->insert($db);
$Fixture = new CakeTestFixtureImportFixture();
$Fixture->fields = $Fixture->records = $Fixture->table = null;
$Fixture->import = array('model' => 'FixtureImportTestModel', 'connection' => 'test');
$Fixture->init();
$this->assertEqual(array_keys($Fixture->fields), array('id', 'name', 'created'));
$this->assertEqual($Fixture->table, 'fixture_tests');
$Source->drop($db);
$db->config['prefix'] = $backPrefix;
}
/**
* test init with a model that has a tablePrefix declared.
*
* @return void
*/
public function testInitModelTablePrefix() {
$this->skipIf($this->db instanceof Sqlite, 'Cannot open 2 connections to Sqlite');
$this->skipIf(!empty($this->db->config['prefix']), 'Cannot run this test, you have a database connection prefix.');
$Source = new CakeTestFixtureTestFixture();
$Source->create($this->db);
$Source->insert($this->db);
$Fixture = new CakeTestFixtureTestFixture();
unset($Fixture->table);
$Fixture->fields = $Fixture->records = null;
$Fixture->import = array('model' => 'FixturePrefixTest', 'connection' => 'test', 'records' => false);
$Fixture->init();
$this->assertEqual($Fixture->table, 'fixture_tests');
$keys = array_flip(ClassRegistry::keys());
$this->assertFalse(array_key_exists('fixtureimporttestmodel', $keys));
$Source->drop($this->db);
}
/**
* testImport
*
* @return void
*/
public function testImport() {
$testSuiteDb = ConnectionManager::getDataSource('test');
$testSuiteConfig = $testSuiteDb->config;
ConnectionManager::create('new_test_suite', array_merge($testSuiteConfig, array('prefix' => 'new_' . $testSuiteConfig['prefix'])));
$newTestSuiteDb = ConnectionManager::getDataSource('new_test_suite');
$Source = new CakeTestFixtureTestFixture();
$Source->create($newTestSuiteDb);
$Source->insert($newTestSuiteDb);
$Fixture = new CakeTestFixtureDefaultImportFixture();
$Fixture->fields = $Fixture->records = null;
$Fixture->import = array('model' => 'FixtureImportTestModel', 'connection' => 'new_test_suite');
$Fixture->init();
$this->assertEqual(array_keys($Fixture->fields), array('id', 'name', 'created'));
$keys = array_flip(ClassRegistry::keys());
$this->assertFalse(array_key_exists('fixtureimporttestmodel', $keys));
$Source->drop($newTestSuiteDb);
}
/**
* test that importing with records works. Make sure to try with postgres as its
* handling of aliases is a workaround at best.
*
* @return void
*/
public function testImportWithRecords() {
$testSuiteDb = ConnectionManager::getDataSource('test');
$testSuiteConfig = $testSuiteDb->config;
ConnectionManager::create('new_test_suite', array_merge($testSuiteConfig, array('prefix' => 'new_' . $testSuiteConfig['prefix'])));
$newTestSuiteDb = ConnectionManager::getDataSource('new_test_suite');
$Source = new CakeTestFixtureTestFixture();
$Source->create($newTestSuiteDb);
$Source->insert($newTestSuiteDb);
$Fixture = new CakeTestFixtureDefaultImportFixture();
$Fixture->fields = $Fixture->records = null;
$Fixture->import = array(
'model' => 'FixtureImportTestModel', 'connection' => 'new_test_suite', 'records' => true
);
$Fixture->init();
$this->assertEqual(array_keys($Fixture->fields), array('id', 'name', 'created'));
$this->assertFalse(empty($Fixture->records[0]), 'No records loaded on importing fixture.');
$this->assertTrue(isset($Fixture->records[0]['name']), 'No name loaded for first record');
$Source->drop($newTestSuiteDb);
}
/**
* test create method
*
* @return void
*/
public function testCreate() {
$Fixture = new CakeTestFixtureTestFixture();
$this->criticDb->expects($this->atLeastOnce())->method('execute');
$this->criticDb->expects($this->atLeastOnce())->method('createSchema');
$return = $Fixture->create($this->criticDb);
$this->assertTrue($this->criticDb->fullDebug);
$this->assertTrue($return);
unset($Fixture->fields);
$return = $Fixture->create($this->criticDb);
$this->assertFalse($return);
}
/**
* test the insert method
*
* @return void
*/
public function testInsert() {
$Fixture = new CakeTestFixtureTestFixture();
$this->criticDb->expects($this->atLeastOnce())
->method('insertMulti')
->will($this->returnCallback(array($this, '_insertCallback')));
$return = $Fixture->insert($this->criticDb);
$this->assertTrue(!empty($this->insertMulti));
$this->assertTrue($this->criticDb->fullDebug);
$this->assertTrue($return);
$this->assertEqual('fixture_tests', $this->insertMulti['table']);
$this->assertEqual(array('name', 'created'), $this->insertMulti['fields']);
$expected = array(
array('Gandalf', '2009-04-28 19:20:00'),
array('Captain Picard', '2009-04-28 19:20:00'),
array('Chewbacca', '2009-04-28 19:20:00')
);
$this->assertEqual($expected, $this->insertMulti['values']);
}
/**
* Helper function to be used as callback and store the parameters of an insertMulti call
*
* @param string $table
* @param string $fields
* @param string $values
* @return boolean true
*/
function _insertCallback($table, $fields, $values) {
$this->insertMulti['table'] = $table;
$this->insertMulti['fields'] = $fields;
$this->insertMulti['values'] = $values;
return true;
}
/**
* test the insert method
*
* @return void
*/
public function testInsertStrings() {
$Fixture = new StringsTestFixture();
$this->criticDb->expects($this->atLeastOnce())
->method('insertMulti')
->will($this->returnCallback(array($this, '_insertCallback')));
$return = $Fixture->insert($this->criticDb);
$this->assertTrue($this->criticDb->fullDebug);
$this->assertTrue($return);
$this->assertEqual('strings', $this->insertMulti['table']);
$this->assertEqual(array('email', 'name', 'age'), $this->insertMulti['fields']);
$expected = array(
array('Mark Doe', 'mark.doe@email.com', null),
array('John Doe', 'john.doe@email.com', 20),
array('Jane Doe', 'jane.doe@email.com', 30),
);
$this->assertEqual($expected, $this->insertMulti['values']);
}
/**
* Test the drop method
*
* @return void
*/
public function testDrop() {
$Fixture = new CakeTestFixtureTestFixture();
$this->criticDb->expects($this->at(1))->method('execute')->will($this->returnValue(true));
$this->criticDb->expects($this->at(3))->method('execute')->will($this->returnValue(false));
$this->criticDb->expects($this->exactly(2))->method('dropSchema');
$return = $Fixture->drop($this->criticDb);
$this->assertTrue($this->criticDb->fullDebug);
$this->assertTrue($return);
$return = $Fixture->drop($this->criticDb);
$this->assertTrue($return);
unset($Fixture->fields);
$return = $Fixture->drop($this->criticDb);
$this->assertFalse($return);
}
/**
* Test the truncate method.
*
* @return void
*/
public function testTruncate() {
$Fixture = new CakeTestFixtureTestFixture();
$this->criticDb->expects($this->atLeastOnce())->method('truncate');
$Fixture->truncate($this->criticDb);
$this->assertTrue($this->criticDb->fullDebug);
}
}
| 0001-bee | trunk/cakephp2/lib/Cake/Test/Case/TestSuite/CakeTestFixtureTest.php | PHP | gpl3 | 13,919 |
<?php
/**
* Test case for HtmlCoverageReport
*
* PHP5
*
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
* Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://cakephp.org CakePHP(tm) Project
* @package Cake.Test.Case.TestSuite
* @since CakePHP(tm) v 2.0
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
App::uses('HtmlCoverageReport', 'TestSuite/Coverage');
App::uses('CakeBaseReporter', 'TestSuite/Reporter');
class HtmlCoverageReportTest extends CakeTestCase {
/**
* setup
*
* @return void
*/
public function setUp() {
parent::setUp();
App::build(array(
'plugins' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS)
), App::RESET);
CakePlugin::loadAll();
$reporter = new CakeBaseReporter();
$reporter->params = array('app' => false, 'plugin' => false, 'group' => false);
$coverage = array();
$this->Coverage = new HtmlCoverageReport($coverage, $reporter);
}
/**
* test getting the path filters.
*
* @return void
*/
public function testGetPathFilter() {
$this->Coverage->appTest = false;
$result = $this->Coverage->getPathFilter();
$this->assertEquals(CAKE, $result);
$this->Coverage->appTest = true;
$result = $this->Coverage->getPathFilter();
$this->assertEquals(ROOT . DS . APP_DIR . DS, $result);
$this->Coverage->appTest = false;
$this->Coverage->pluginTest = 'TestPlugin';
$result = $this->Coverage->getPathFilter();
$this->assertEquals(CakePlugin::path('TestPlugin'), $result);
}
/**
* test filtering coverage data.
*
* @return void
*/
public function testFilterCoverageDataByPathRemovingElements() {
$data = array(
CAKE . 'dispatcher.php' => array(
10 => -1,
12 => 1
),
APP . 'app_model.php' => array(
50 => 1,
52 => -1
)
);
$this->Coverage->setCoverage($data);
$result = $this->Coverage->filterCoverageDataByPath(CAKE);
$this->assertTrue(isset($result[CAKE . 'dispatcher.php']));
$this->assertFalse(isset($result[APP . 'app_model.php']));
}
/**
* test generating HTML reports from file arrays.
*
* @return void
*/
public function testGenerateDiff() {
$file = array(
'line 1',
'line 2',
'line 3',
'line 4',
'line 5',
'line 6',
'line 7',
'line 8',
'line 9',
'line 10',
);
$coverage = array(
1 => array(array('id' => 'HtmlCoverageReportTest::testGenerateDiff')),
2 => -2,
3 => array(array('id' => 'HtmlCoverageReportTest::testGenerateDiff')),
4 => array(array('id' => 'HtmlCoverageReportTest::testGenerateDiff')),
5 => -1,
6 => array(array('id' => 'HtmlCoverageReportTest::testGenerateDiff')),
7 => array(array('id' => 'HtmlCoverageReportTest::testGenerateDiff')),
8 => array(array('id' => 'HtmlCoverageReportTest::testGenerateDiff')),
9 => -1,
10 => array(array('id' => 'HtmlCoverageReportTest::testGenerateDiff'))
);
$result = $this->Coverage->generateDiff('myfile.php', $file, $coverage);
$this->assertRegExp('/myfile\.php Code coverage\: \d+\.?\d*\%/', $result);
$this->assertRegExp('/<div class="code-coverage-results" id\="coverage\-myfile\.php"/', $result);
$this->assertRegExp('/<pre>/', $result);
foreach ($file as $i => $line) {
$this->assertTrue(strpos($line, $result) !== 0, 'Content is missing ' . $i);
$class = 'covered';
if (in_array($i + 1, array(5, 9, 2))) {
$class = 'uncovered';
}
if ($i + 1 == 2) {
$class .= ' dead';
}
$this->assertTrue(strpos($class, $result) !== 0, 'Class name is wrong ' . $i);
}
}
/**
* test that covering methods show up as title attributes for lines.
*
* @return void
*/
public function testCoveredLinesTitleAttributes() {
$file = array(
'line 1',
'line 2',
'line 3',
'line 4',
'line 5',
);
$coverage = array(
1 => array(array('id' => 'HtmlCoverageReportTest::testAwesomeness')),
2 => -2,
3 => array(array('id' => 'HtmlCoverageReportTest::testCakeIsSuperior')),
4 => array(array('id' => 'HtmlCoverageReportTest::testOther')),
5 => -1
);
$result = $this->Coverage->generateDiff('myfile.php', $file, $coverage);
$this->assertTrue(
strpos($result, "title=\"Covered by:\nHtmlCoverageReportTest::testAwesomeness\n\"><span class=\"line-num\">1") !== false,
'Missing method coverage for line 1'
);
$this->assertTrue(
strpos($result, "title=\"Covered by:\nHtmlCoverageReportTest::testCakeIsSuperior\n\"><span class=\"line-num\">3") !== false,
'Missing method coverage for line 3'
);
$this->assertTrue(
strpos($result, "title=\"Covered by:\nHtmlCoverageReportTest::testOther\n\"><span class=\"line-num\">4") !== false,
'Missing method coverage for line 4'
);
$this->assertTrue(
strpos($result, "title=\"\"><span class=\"line-num\">5") !== false,
'Coverage report is wrong for line 5'
);
}
/**
* teardown
*
* @return void
*/
public function tearDown() {
CakePlugin::unload();
unset($this->Coverage);
}
}
| 0001-bee | trunk/cakephp2/lib/Cake/Test/Case/TestSuite/HtmlCoverageReportTest.php | PHP | gpl3 | 5,212 |
<?php
/**
* CakeTestCaseTest file
*
* Test Case for CakeTestCase class
*
* PHP version 5
*
* CakePHP : Rapid Development Framework (http://cakephp.org)
* Copyright 2005-2011, Cake Software Foundation, Inc.
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright 2005-2011, Cake Software Foundation, Inc.
* @link http://cakephp.org CakePHP Project
* @package Cake.Test.Case.TestSuite
* @since CakePHP v 1.2.0.4487
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
App::uses('Controller', 'Controller');
App::uses('CakeHtmlReporter', 'TestSuite/Reporter');
if (!class_exists('AppController', false)) {
require_once CAKE . 'Controller' . DS . 'AppController.php';
} elseif (!defined('APP_CONTROLLER_EXISTS')) {
define('APP_CONTROLLER_EXISTS', true);
}
/**
* CakeTestCaseTest
*
* @package Cake.Test.Case.TestSuite
*/
class CakeTestCaseTest extends CakeTestCase {
public static function setUpBeforeClass() {
require_once CAKE . 'Test' . DS . 'Fixture' . DS . 'AssertTagsTestCase.php';
require_once CAKE . 'Test' . DS . 'Fixture' . DS . 'FixturizedTestCase.php';
}
/**
* setUp
*
* @return void
*/
public function setUp() {
parent::setUp();
$this->Reporter = $this->getMock('CakeHtmlReporter');
}
/**
* tearDown
*
* @return void
*/
public function tearDown() {
parent::tearDown();
unset($this->Result);
unset($this->Reporter);
}
/**
* testAssertGoodTags
*
* @return void
*/
public function testAssertTagsQuotes() {
$test = new AssertTagsTestCase('testAssertTagsQuotes');
$result = $test->run();
$this->assertEquals(0, $result->errorCount());
$this->assertTrue($result->wasSuccessful());
$this->assertEquals(0, $result->failureCount());
$input = '<a href="/test.html" class="active">My link</a>';
$pattern = array(
'a' => array('href' => '/test.html', 'class' => 'active'),
'My link',
'/a'
);
$this->assertTrue($test->assertTags($input, $pattern), 'Double quoted attributes %s');
$input = "<a href='/test.html' class='active'>My link</a>";
$pattern = array(
'a' => array('href' => '/test.html', 'class' => 'active'),
'My link',
'/a'
);
$this->assertTrue($test->assertTags($input, $pattern), 'Single quoted attributes %s');
$input = "<a href='/test.html' class='active'>My link</a>";
$pattern = array(
'a' => array('href' => 'preg:/.*\.html/', 'class' => 'active'),
'My link',
'/a'
);
$this->assertTrue($test->assertTags($input, $pattern), 'Single quoted attributes %s');
$input = "<span><strong>Text</strong></span>";
$pattern = array(
'<span',
'<strong',
'Text',
'/strong',
'/span'
);
$this->assertTrue($test->assertTags($input, $pattern), 'Tags with no attributes');
$input = "<span class='active'><strong>Text</strong></span>";
$pattern = array(
'span' => array('class'),
'<strong',
'Text',
'/strong',
'/span'
);
$this->assertTrue($test->assertTags($input, $pattern), 'Test attribute presence');
}
/**
* testNumericValuesInExpectationForAssertTags
*
* @return void
*/
public function testNumericValuesInExpectationForAssertTags() {
$test = new AssertTagsTestCase('testNumericValuesInExpectationForAssertTags');
$result = $test->run();
$this->assertEquals(0, $result->errorCount());
$this->assertTrue($result->wasSuccessful());
$this->assertEquals(0, $result->failureCount());
}
/**
* testBadAssertTags
*
* @return void
*/
public function testBadAssertTags() {
$test = new AssertTagsTestCase('testBadAssertTags');
$result = $test->run();
$this->assertEquals(0, $result->errorCount());
$this->assertFalse($result->wasSuccessful());
$this->assertEquals(1, $result->failureCount());
$test = new AssertTagsTestCase('testBadAssertTags2');
$result = $test->run();
$this->assertEquals(0, $result->errorCount());
$this->assertFalse($result->wasSuccessful());
$this->assertEquals(1, $result->failureCount());
}
/**
* testLoadFixtures
*
* @return void
*/
public function testLoadFixtures() {
$test = new FixturizedTestCase('testFixturePresent');
$manager = $this->getMock('CakeFixtureManager');
$manager->fixturize($test);
$test->fixtureManager = $manager;
$manager->expects($this->once())->method('load');
$manager->expects($this->once())->method('unload');
$result = $test->run();
$this->assertEquals(0, $result->errorCount());
$this->assertTrue($result->wasSuccessful());
$this->assertEquals(0, $result->failureCount());
}
/**
* testLoadFixturesOnDemand
*
* @return void
*/
public function testLoadFixturesOnDemand() {
$test = new FixturizedTestCase('testFixtureLoadOnDemand');
$test->autoFixtures = false;
$manager = $this->getMock('CakeFixtureManager');
$manager->fixturize($test);
$test->fixtureManager = $manager;
$manager->expects($this->once())->method('loadSingle');
$result = $test->run();
$this->assertEquals(0, $result->errorCount());
}
/**
* testLoadFixturesOnDemand
*
* @return void
*/
public function testUnoadFixturesAfterFailure() {
$test = new FixturizedTestCase('testFixtureLoadOnDemand');
$test->autoFixtures = false;
$manager = $this->getMock('CakeFixtureManager');
$manager->fixturize($test);
$test->fixtureManager = $manager;
$manager->expects($this->once())->method('loadSingle');
$result = $test->run();
$this->assertEquals(0, $result->errorCount());
}
/**
* testThrowException
*
* @return void
*/
public function testThrowException() {
$test = new FixturizedTestCase('testThrowException');
$test->autoFixtures = false;
$manager = $this->getMock('CakeFixtureManager');
$manager->fixturize($test);
$test->fixtureManager = $manager;
$manager->expects($this->once())->method('unload');
$result = $test->run();
$this->assertEquals(1, $result->errorCount());
}
/**
* testSkipIf
*
* @return void
*/
public function testSkipIf() {
$test = new FixturizedTestCase('testSkipIfTrue');
$result = $test->run();
$this->assertEquals(1, $result->skippedCount());
$test = new FixturizedTestCase('testSkipIfFalse');
$result = $test->run();
$this->assertEquals(0, $result->skippedCount());
}
/**
* Test that CakeTestCase::setUp() backs up values.
*
* @return void
*/
public function testSetupBackUpValues() {
$this->assertArrayHasKey('debug', $this->_configure);
$this->assertArrayHasKey('Plugin', $this->_pathRestore);
}
}
| 0001-bee | trunk/cakephp2/lib/Cake/Test/Case/TestSuite/CakeTestCaseTest.php | PHP | gpl3 | 6,503 |
<?php
/**
* ControllerTestCaseTest file
*
* Test Case for ControllerTestCase class
*
* PHP version 5
*
* CakePHP : Rapid Development Framework (http://cakephp.org)
* Copyright 2005-2011, Cake Software Foundation, Inc.
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright 2005-2011, Cake Software Foundation, Inc.
* @link http://cakephp.org CakePHP Project
* @package Cake.Test.Case.TestSuite
* @since CakePHP v 2.0
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
App::uses('Controller', 'Controller');
App::uses('Model', 'Model');
App::uses('AppModel', 'Model');
App::uses('CakeHtmlReporter', 'TestSuite/Reporter');
require_once dirname(dirname(__FILE__)) . DS . 'Model' . DS . 'models.php';
/**
* AppController class
*
* @package Cake.Test.Case.TestSuite
*/
if (!class_exists('AppController', false)) {
/**
* AppController class
*
* @package Cake.Test.Case.TestSuite
*/
class AppController extends Controller {
/**
* helpers property
*
* @var array
* @access public
*/
public $helpers = array('Html');
/**
* uses property
*
* @var array
* @access public
*/
public $uses = array('ControllerPost');
/**
* components property
*
* @var array
* @access public
*/
public $components = array('Cookie');
}
} elseif (!defined('APP_CONTROLLER_EXISTS')) {
define('APP_CONTROLLER_EXISTS', true);
}
/**
* PostsController class
*/
if (!class_exists('PostsController')) {
class PostsController extends AppController {
/**
* Components array
*
* @var array
*/
public $components = array(
'RequestHandler',
'Email',
'Auth'
);
}
}
/**
* ControllerTestCaseTest controller
*/
class ControllerTestCaseTestController extends AppController {
/**
* Uses array
*
* @param array
*/
public $uses = array('TestPlugin.TestPluginComment');
}
/**
* ControllerTestCaseTest
*
* @package Cake.Test.Case.TestSuite
*/
class ControllerTestCaseTest extends CakeTestCase {
/**
* fixtures property
*
* @var array
*/
public $fixtures = array('core.post', 'core.author', 'core.test_plugin_comment');
/**
* reset environment.
*
* @return void
*/
public function setUp() {
parent::setUp();
App::build(array(
'plugins' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS),
'Controller' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Controller' . DS),
'Model' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Model' . DS),
'View' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'View' . DS)
), App::RESET);
CakePlugin::loadAll();
$this->Case = $this->getMockForAbstractClass('ControllerTestCase');
Router::reload();
}
/**
* teardown
*
* @return void
*/
public function tearDown() {
parent::tearDown();
CakePlugin::unload();
$this->Case->controller = null;
}
/**
* Test that ControllerTestCase::generate() creates mock objects correctly
*/
public function testGenerate() {
if (defined('APP_CONTROLLER_EXISTS')) {
$this->markTestSkipped('AppController exists, cannot run.');
}
$Posts = $this->Case->generate('Posts');
$this->assertEquals($Posts->name, 'Posts');
$this->assertEquals($Posts->modelClass, 'Post');
$this->assertNull($Posts->response->send());
$Posts = $this->Case->generate('Posts', array(
'methods' => array(
'render'
)
));
$this->assertNull($Posts->render('index'));
$Posts = $this->Case->generate('Posts', array(
'models' => array('Post'),
'components' => array('RequestHandler')
));
$this->assertInstanceOf('Post', $Posts->Post);
$this->assertNull($Posts->Post->save(array()));
$this->assertNull($Posts->Post->find('all'));
$this->assertEquals($Posts->Post->useTable, 'posts');
$this->assertNull($Posts->RequestHandler->isAjax());
$Posts = $this->Case->generate('Posts', array(
'models' => array(
'Post' => true
)
));
$this->assertNull($Posts->Post->save(array()));
$this->assertNull($Posts->Post->find('all'));
$Posts = $this->Case->generate('Posts', array(
'models' => array(
'Post' => array('save'),
)
));
$this->assertNull($Posts->Post->save(array()));
$this->assertInternalType('array', $Posts->Post->find('all'));
$Posts = $this->Case->generate('Posts', array(
'models' => array('Post'),
'components' => array(
'RequestHandler' => array('isPut'),
'Email' => array('send'),
'Session'
)
));
$Posts->RequestHandler->expects($this->once())
->method('isPut')
->will($this->returnValue(true));
$this->assertTrue($Posts->RequestHandler->isPut());
$Posts->Auth->Session->expects($this->any())
->method('write')
->will($this->returnValue('written!'));
$this->assertEquals($Posts->Auth->Session->write('something'), 'written!');
}
/**
* Tests ControllerTestCase::generate() using classes from plugins
*/
public function testGenerateWithPlugin() {
$Tests = $this->Case->generate('TestPlugin.Tests', array(
'models' => array(
'TestPlugin.TestPluginComment'
),
'components' => array(
'TestPlugin.PluginsComponent'
)
));
$this->assertEquals($Tests->name, 'Tests');
$this->assertInstanceOf('PluginsComponentComponent', $Tests->PluginsComponent);
$result = ClassRegistry::init('TestPlugin.TestPluginComment');
$this->assertInstanceOf('TestPluginComment', $result);
$Tests = $this->Case->generate('ControllerTestCaseTest', array(
'models' => array(
'TestPlugin.TestPluginComment' => array('save')
)
));
$this->assertInstanceOf('TestPluginComment', $Tests->TestPluginComment);
$Tests->TestPluginComment->expects($this->at(0))
->method('save')
->will($this->returnValue(true));
$Tests->TestPluginComment->expects($this->at(1))
->method('save')
->will($this->returnValue(false));
$this->assertTrue($Tests->TestPluginComment->save(array()));
$this->assertFalse($Tests->TestPluginComment->save(array()));
}
/**
* Tests testAction
*/
public function testTestAction() {
$Controller = $this->Case->generate('TestsApps');
$this->Case->testAction('/tests_apps/index');
$this->assertInternalType('array', $this->Case->controller->viewVars);
$this->Case->testAction('/tests_apps/set_action');
$results = $this->Case->controller->viewVars;
$expected = array(
'var' => 'string'
);
$this->assertEquals($expected, $results);
$result = $this->Case->controller->response->body();
$this->assertPattern('/This is the TestsAppsController index view/', $result);
$this->Case->testAction('/tests_apps/redirect_to');
$results = $this->Case->headers;
$expected = array(
'Location' => 'http://cakephp.org'
);
$this->assertEquals($expected, $results);
}
/**
* Make sure testAction() can hit plugin controllers.
*
* @return void
*/
public function testTestActionWithPlugin() {
$Controller = $this->Case->generate('TestPlugin.Tests');
$this->Case->testAction('/test_plugin/tests/index');
$this->assertEquals('It is a variable', $this->Case->controller->viewVars['test_value']);
}
/**
* Tests using loaded routes during tests
*
* @return void
*/
public function testUseRoutes() {
Router::connect('/:controller/:action/*');
include CAKE . 'Test' . DS . 'test_app' . DS . 'Config' . DS . 'routes.php';
$controller = $this->Case->generate('TestsApps');
$controller->Components->load('RequestHandler');
$result = $this->Case->testAction('/tests_apps/index.json', array('return' => 'view'));
$result = json_decode($result, true);
$expected = array('cakephp' => 'cool');
$this->assertEquals($expected, $result);
include CAKE . 'Test' . DS . 'test_app' . DS . 'Config' . DS . 'routes.php';
$result = $this->Case->testAction('/some_alias');
$this->assertEquals($result, 5);
include CAKE . 'Test' . DS . 'test_app' . DS . 'Config' . DS . 'routes.php';
$this->Case->testAction('/redirect_me_now');
$result = $this->Case->headers['Location'];
$this->assertEquals($result, 'http://cakephp.org');
include CAKE . 'Test' . DS . 'test_app' . DS . 'Config' . DS . 'routes.php';
$this->Case->testAction('/redirect_me');
$result = $this->Case->headers['Location'];
$this->assertEquals($result, Router::url(array('controller' => 'tests_apps', 'action' => 'some_method'), true));
}
/**
* Tests not using loaded routes during tests
*
* @expectedException MissingActionException
*/
public function testSkipRoutes() {
Router::connect('/:controller/:action/*');
include CAKE . 'Test' . DS . 'test_app' . DS . 'Config' . DS . 'routes.php';
$this->Case->loadRoutes = false;
$result = $this->Case->testAction('/tests_apps/missing_action.json', array('return' => 'view'));
}
/**
* Tests backwards compatibility with setting the return type
*/
public function testBCSetReturn() {
$this->Case->autoMock = true;
$result = $this->Case->testAction('/tests_apps/some_method');
$this->assertEquals($result, 5);
$data = array('var' => 'set');
$result = $this->Case->testAction('/tests_apps_posts/post_var', array(
'data' => $data,
'return' => 'vars'
));
$this->assertEquals($result['data'], $data);
$result = $this->Case->testAction('/tests_apps/set_action', array(
'return' => 'view'
));
$this->assertEquals($result, 'This is the TestsAppsController index view');
$result = $this->Case->testAction('/tests_apps/set_action', array(
'return' => 'contents'
));
$this->assertPattern('/<html/', $result);
$this->assertPattern('/This is the TestsAppsController index view/', $result);
$this->assertPattern('/<\/html>/', $result);
}
/**
* Tests sending POST data to testAction
*/
public function testTestActionPostData() {
$this->Case->autoMock = true;
$data = array(
'Post' => array(
'name' => 'Some Post'
)
);
$this->Case->testAction('/tests_apps_posts/post_var', array(
'data' => $data
));
$this->assertEquals($this->Case->controller->viewVars['data'], $data);
$this->assertEquals($this->Case->controller->data, $data);
$this->Case->testAction('/tests_apps_posts/post_var/named:param', array(
'data' => $data
));
$expected = array(
'named' => 'param'
);
$this->assertEqual($this->Case->controller->request->named, $expected);
$this->assertEquals($this->Case->controller->data, $data);
$result = $this->Case->testAction('/tests_apps_posts/post_var', array(
'return' => 'vars',
'method' => 'post',
'data' => array(
'name' => 'is jonas',
'pork' => 'and beans',
)
));
$this->assertEqual(array_keys($result['data']), array('name', 'pork'));
$result = $this->Case->testAction('/tests_apps_posts/add', array('return' => 'vars'));
$this->assertTrue(array_key_exists('posts', $result));
$this->assertEqual(count($result['posts']), 4);
$this->assertTrue($this->Case->controller->request->is('post'));
}
/**
* Tests sending GET data to testAction
*/
public function testTestActionGetData() {
$this->Case->autoMock = true;
$result = $this->Case->testAction('/tests_apps_posts/url_var', array(
'method' => 'get',
'data' => array(
'some' => 'var',
'lackof' => 'creativity'
)
));
$this->assertEquals($this->Case->controller->request->query['some'], 'var');
$this->assertEquals($this->Case->controller->request->query['lackof'], 'creativity');
$result = $this->Case->testAction('/tests_apps_posts/url_var/var1:value1/var2:val2', array(
'return' => 'vars',
'method' => 'get',
));
$this->assertEqual(array_keys($result['params']['named']), array('var1', 'var2'));
$result = $this->Case->testAction('/tests_apps_posts/url_var/gogo/val2', array(
'return' => 'vars',
'method' => 'get',
));
$this->assertEqual($result['params']['pass'], array('gogo', 'val2'));
$result = $this->Case->testAction('/tests_apps_posts/url_var', array(
'return' => 'vars',
'method' => 'get',
'data' => array(
'red' => 'health',
'blue' => 'mana'
)
));
$query = $this->Case->controller->request->query;
$this->assertTrue(isset($query['red']));
$this->assertTrue(isset($query['blue']));
}
/**
* Tests autoMock ability
*/
public function testAutoMock() {
$this->Case->autoMock = true;
$this->Case->testAction('/tests_apps/set_action');
$results = $this->Case->controller->viewVars;
$expected = array(
'var' => 'string'
);
$this->assertEquals($expected, $results);
}
/**
* Test using testAction and not mocking
*/
public function testNoMocking() {
$result = $this->Case->testAction('/tests_apps/some_method');
$this->Case->assertEquals($result, 5);
$data = array('var' => 'set');
$result = $this->Case->testAction('/tests_apps_posts/post_var', array(
'data' => $data,
'return' => 'vars'
));
$this->assertEquals($result['data'], $data);
$result = $this->Case->testAction('/tests_apps/set_action', array(
'return' => 'view'
));
$this->assertEquals($result, 'This is the TestsAppsController index view');
$result = $this->Case->testAction('/tests_apps/set_action', array(
'return' => 'contents'
));
$this->assertPattern('/<html/', $result);
$this->assertPattern('/This is the TestsAppsController index view/', $result);
$this->assertPattern('/<\/html>/', $result);
}
}
| 0001-bee | trunk/cakephp2/lib/Cake/Test/Case/TestSuite/ControllerTestCaseTest.php | PHP | gpl3 | 13,286 |