本文整理匯總了PHP中CakeRequest::isExtension方法的典型用法代碼示例。如果您正苦於以下問題:PHP CakeRequest::isExtension方法的具體用法?PHP CakeRequest::isExtension怎麽用?PHP CakeRequest::isExtension使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類CakeRequest
的用法示例。
在下文中一共展示了CakeRequest::isExtension方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: testAddDetector
/**
* Test adding detectors and having them work.
*
* @return void
*/
public function testAddDetector()
{
$request = new CakeRequest('some/path');
$request->addDetector('compare', array('env' => 'TEST_VAR', 'value' => 'something'));
$_SERVER['TEST_VAR'] = 'something';
$this->assertTrue($request->is('compare'), 'Value match failed.');
$_SERVER['TEST_VAR'] = 'wrong';
$this->assertFalse($request->is('compare'), 'Value mis-match failed.');
$request->addDetector('compareCamelCase', array('env' => 'TEST_VAR', 'value' => 'foo'));
$_SERVER['TEST_VAR'] = 'foo';
$this->assertTrue($request->is('compareCamelCase'), 'Value match failed.');
$this->assertTrue($request->is('comparecamelcase'), 'detectors should be case insensitive');
$this->assertTrue($request->is('COMPARECAMELCASE'), 'detectors should be case insensitive');
$_SERVER['TEST_VAR'] = 'not foo';
$this->assertFalse($request->is('compareCamelCase'), 'Value match failed.');
$this->assertFalse($request->is('comparecamelcase'), 'detectors should be case insensitive');
$this->assertFalse($request->is('COMPARECAMELCASE'), 'detectors should be case insensitive');
$request->addDetector('banana', array('env' => 'TEST_VAR', 'pattern' => '/^ban.*$/'));
$_SERVER['TEST_VAR'] = 'banana';
$this->assertTrue($request->isBanana());
$_SERVER['TEST_VAR'] = 'wrong value';
$this->assertFalse($request->isBanana());
$request->addDetector('mobile', array('options' => array('Imagination')));
$_SERVER['HTTP_USER_AGENT'] = 'Imagination land';
$this->assertTrue($request->isMobile());
$_SERVER['HTTP_USER_AGENT'] = 'iPhone 3.0';
$this->assertTrue($request->isMobile());
$request->addDetector('callme', array('env' => 'TEST_VAR', 'callback' => array($this, 'detectCallback')));
$request->addDetector('index', array('param' => 'action', 'value' => 'index'));
$request->params['action'] = 'index';
$this->assertTrue($request->isIndex());
$request->params['action'] = 'add';
$this->assertFalse($request->isIndex());
$request->return = true;
$this->assertTrue($request->isCallMe());
$request->return = false;
$this->assertFalse($request->isCallMe());
$request->addDetector('extension', array('param' => 'ext', 'options' => array('pdf', 'png', 'txt')));
$request->params['ext'] = 'pdf';
$this->assertTrue($request->is('extension'));
$request->params['ext'] = 'exe';
$this->assertFalse($request->isExtension());
}