예제 #1
0
 * (c) 2004-2006 Fabien Potencier <*****@*****.**>
 * 
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */
$app = 'crud';
$fixtures = 'fixtures/fixtures.yml';
if (!(include dirname(__FILE__) . '/../bootstrap/functional.php')) {
    return;
}
$b = new sfTestBrowser();
$b->initialize();
// check symfony throws an exception if model class does not exist
$b->get('/error')->isRequestParameter('module', 'error')->isRequestParameter('action', 'index')->throwsException('sfInitializationException', '/Unable to scaffold unexistant model/');
// list page
$b->get('/simple')->isStatusCode(200)->isRequestParameter('module', 'simple')->isRequestParameter('action', 'index');
$content = $b->getResponse()->getContent();
$b->get('/simple/list')->isStatusCode(200)->isRequestParameter('module', 'simple')->isRequestParameter('action', 'list')->checkResponseElement('body h1', 'simple')->checkResponseElement('body table thead tr th', '/^(Title|Body|Id|Category Id|Created at)$/')->checkResponseElement('body table tbody tr td', 'foo title', array('position' => 1))->checkResponseElement('body table tbody tr td', 'bar body', array('position' => 2))->checkResponseElement('body table tbody tr td', '1', array('position' => 3))->checkResponseElement('body table tbody tr td', '1', array('position' => 4))->checkResponseElement('a[href$="/simple/create"]', 'create')->checkResponseElement('a[href*="/simple/show/id/"]', '/\\d+/', array('count' => 2));
$b->test()->is($b->getResponse()->getContent(), $content, 'simple is an alias for simple/list');
// show page
$b->click('1')->isStatusCode(200)->isRequestParameter('module', 'simple')->isRequestParameter('action', 'show')->isRequestParameter('id', 1)->checkResponseElement('a[href$="/simple/edit/id/1"]', 'edit')->checkResponseElement('a[href$="/simple/list"]', 'list')->checkResponseElement('body table tbody tr', '/Id\\:\\s+1/', array('position' => 0))->checkResponseElement('body table tbody tr', '/Title\\:\\s+foo title/', array('position' => 1))->checkResponseElement('body table tbody tr', '/Body\\:\\s+bar body/', array('position' => 2))->checkResponseElement('body table tbody tr', '/Online\\:\\s+1/', array('position' => 3))->checkResponseElement('body table tbody tr', '/Category\\:\\s+1/', array('position' => 4))->checkResponseElement('body table tbody tr', '/Created at\\:\\s+[0-9\\-\\:\\s]+/', array('position' => 5))->checkResponseElement('body table tbody tr', '/End date\\:\\s+[0-9\\-\\:\\s]+/', array('position' => 6))->checkResponseElement('body table tbody tr', '/Book\\:\\s+/', array('position' => 7));
// edit page
$b->click('edit')->isStatusCode(200)->isRequestParameter('module', 'simple')->isRequestParameter('action', 'edit')->isRequestParameter('id', 1)->checkResponseElement('a[href$="/simple/show/id/1"]', 'cancel')->checkResponseElement('a[href$="/simple/delete/id/1"]', 'delete')->checkResponseElement('a[href$="/simple/delete/id/1"][onclick*="confirm"]')->checkResponseElement('body table tbody th', 'Title:', array('position' => 0))->checkResponseElement('body table tbody th', 'Body:', array('position' => 1))->checkResponseElement('body table tbody th', 'Online:', array('position' => 2))->checkResponseElement('body table tbody th', 'Category*:', array('position' => 3))->checkResponseElement('body table tbody th', 6)->checkResponseElement('body table tbody td', 6)->checkResponseElement('body table tbody td input[id="title"][name="title"][value*="title"][size="80"]')->checkResponseElement('body table tbody td textarea[id="body"][name="body"]', 'bar body')->checkResponseElement('body table tbody td input[id="online"][name="online"][type="checkbox"]', true)->checkResponseElement('body table tbody td select[id="category_id"][name="category_id"]', true)->checkResponseElement('body table tbody td select[id="category_id"][name="category_id"] option[value="1"]', '1')->checkResponseElement('body table tbody td select[id="category_id"][name="category_id"] option[value="2"]', '2');
// create page
$b->get('/simple/create')->isStatusCode(200)->isRequestParameter('module', 'simple')->isRequestParameter('action', 'create')->isRequestParameter('id', null)->checkResponseElement('a[href$="/simple/list"]', 'cancel')->checkResponseElement('body table tbody th', 'Title:', array('position' => 0))->checkResponseElement('body table tbody th', 'Body:', array('position' => 1))->checkResponseElement('body table tbody th', 'Online:', array('position' => 2))->checkResponseElement('body table tbody th', 'Category*:', array('position' => 3))->checkResponseElement('body table tbody th', 6)->checkResponseElement('body table tbody td', 6)->checkResponseElement('body table tbody td input[id="title"][name="title"][value=""]')->checkResponseElement('body table tbody td textarea[id="body"][name="body"]', '')->checkResponseElement('body table tbody td input[id="online"][name="online"][type="checkbox"]', true)->checkResponseElement('body table tbody td select[id="category_id"][name="category_id"]', true)->checkResponseElement('body table tbody td select[id="category_id"][name="category_id"] option[value="1"]', '1')->checkResponseElement('body table tbody td select[id="category_id"][name="category_id"] option[value="2"]', '2');
// save
$b->click('save', array('title' => 'my title', 'body' => 'my body', 'online' => true, 'category_id' => 2))->isStatusCode(302)->isRequestParameter('module', 'simple')->isRequestParameter('action', 'update')->isRedirected();
$b->followRedirect()->isStatusCode(200)->isRequestParameter('module', 'simple')->isRequestParameter('action', 'show')->isRequestParameter('id', 3)->checkResponseElement('a[href$="/simple/edit/id/3"]', 'edit')->checkResponseElement('a[href$="/simple/list"]', 'list')->checkResponseElement('body table tbody tr', '/Id\\:\\s+3/', array('position' => 0))->checkResponseElement('body table tbody tr', '/Title\\:\\s+my title/', array('position' => 1))->checkResponseElement('body table tbody tr', '/Body\\:\\s+my body/', array('position' => 2))->checkResponseElement('body table tbody tr', '/Online\\:\\s+1/', array('position' => 3))->checkResponseElement('body table tbody tr', '/Category\\:\\s+2/', array('position' => 4))->checkResponseElement('body table tbody tr', '/Created at\\:\\s+[0-9\\-\\:\\s]+/', array('position' => 5))->checkResponseElement('body table tbody tr', '/End date\\:\\s+[0-9\\-\\:\\s]+/', array('position' => 6))->checkResponseElement('body table tbody tr', '/Book\\:\\s+$/', array('position' => 7));
$b->click('list')->isStatusCode(200)->isRequestParameter('module', 'simple')->isRequestParameter('action', 'list');
// delete
$b->get('/simple/edit/id/3')->click('delete')->isStatusCode(302)->isRequestParameter('module', 'simple')->isRequestParameter('action', 'delete')->isRedirected()->followRedirect()->isStatusCode(200)->isRequestParameter('module', 'simple')->isRequestParameter('action', 'list')->get('/simple/edit/id/3')->isStatusCode(404);
예제 #2
0
<?php

/*
 * This file is part of the symfony package.
 * (c) Fabien Potencier <*****@*****.**>
 * 
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */
$app = 'frontend';
if (!(include dirname(__FILE__) . '/../bootstrap/functional.php')) {
    return;
}
$b = new sfTestBrowser();
$b->get('/format_test.js')->isStatusCode(200)->isRequestParameter('module', 'format')->isRequestParameter('action', 'index')->isRequestFormat('js')->isResponseHeader('content-type', 'application/javascript');
$b->test()->unlike($b->getResponse()->getContent(), '/<body>/', 'response content is ok');
$b->test()->like($b->getResponse()->getContent(), '/Some js headers/', 'response content is ok');
$b->test()->like($b->getResponse()->getContent(), '/This is a js file/', 'response content is ok');
$b->get('/format_test.css')->isStatusCode(200)->isRequestParameter('module', 'format')->isRequestParameter('action', 'index')->isRequestFormat('css')->isResponseHeader('content-type', 'text/css; charset=utf-8');
$b->test()->is($b->getResponse()->getContent(), 'This is a css file', 'response content is ok');
$b->get('/format_test')->isStatusCode(200)->isRequestParameter('module', 'format')->isRequestParameter('action', 'index')->isRequestFormat('html')->isResponseHeader('content-type', 'text/html; charset=utf-8')->checkResponseElement('body #content', 'This is an HTML file');
$b->get('/format_test.xml')->isStatusCode(200)->isRequestParameter('module', 'format')->isRequestParameter('action', 'index')->isRequestFormat('xml')->isResponseHeader('content-type', 'text/xml; charset=utf-8')->checkResponseElement('sentences sentence:first', 'This is a XML file');
$b->get('/format_test.foo')->isStatusCode(200)->isRequestParameter('module', 'format')->isRequestParameter('action', 'index')->isRequestFormat('foo')->isResponseHeader('content-type', 'text/html; charset=utf-8')->isResponseHeader('x-foo', 'true')->checkResponseElement('body #content', 'This is an HTML file');
$b->get('/format/js')->isStatusCode(200)->isRequestParameter('module', 'format')->isRequestParameter('action', 'js')->isRequestFormat('js')->isResponseHeader('content-type', 'application/javascript');
$b->test()->is($b->getResponse()->getContent(), 'A js file', 'response content is ok');
$b->setHttpHeader('User-Agent', 'Mozilla/5.0 (iPhone; U; CPU like Mac OS X; en) AppleWebKit/420+ (KHTML, like Gecko) Version/3.0 Mobile/1A543a Safari/419.3')->get('/format/forTheIPhone')->isStatusCode(200)->isRequestParameter('module', 'format')->isRequestParameter('action', 'forTheIPhone')->isRequestFormat('iphone')->isResponseHeader('content-type', 'text/html; charset=utf-8')->checkResponseElement('#content', 'This is an HTML file for the iPhone')->checkResponseElement('link[href*="iphone.css"]');
$b->getAndCheck('format', 'throwsException', null, 500)->throwsException('Exception', '/message/');
예제 #3
0
<?php

/*
 * This file is part of the symfony package.
 * (c) Fabien Potencier <*****@*****.**>
 * 
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */
$app = 'frontend';
if (!(include dirname(__FILE__) . '/../bootstrap/functional.php')) {
    return;
}
$b = new sfTestBrowser();
$b->get('/format_test.js')->isStatusCode(200)->isRequestParameter('module', 'format')->isRequestParameter('action', 'index')->isRequestFormat('js')->isResponseHeader('content-type', 'application/javascript');
$b->test()->unlike($b->getResponse()->getContent(), '/<body>/', 'response content is ok');
$b->test()->like($b->getResponse()->getContent(), '/Some js headers/', 'response content is ok');
$b->test()->like($b->getResponse()->getContent(), '/This is a js file/', 'response content is ok');
$b->get('/format_test.css')->isStatusCode(200)->isRequestParameter('module', 'format')->isRequestParameter('action', 'index')->isRequestFormat('css')->isResponseHeader('content-type', 'text/css; charset=utf-8');
$b->test()->is($b->getResponse()->getContent(), 'This is a css file', 'response content is ok');
$b->get('/format_test')->isStatusCode(200)->isRequestParameter('module', 'format')->isRequestParameter('action', 'index')->isRequestFormat('html')->isResponseHeader('content-type', 'text/html; charset=utf-8')->checkResponseElement('body #content', 'This is an HTML file');
$b->get('/format_test.xml')->isStatusCode(200)->isRequestParameter('module', 'format')->isRequestParameter('action', 'index')->isRequestFormat('xml')->isResponseHeader('content-type', 'text/xml; charset=utf-8')->checkResponseElement('sentences sentence:first', 'This is a XML file');
$b->get('/format_test.foo')->isStatusCode(200)->isRequestParameter('module', 'format')->isRequestParameter('action', 'index')->isRequestFormat('foo')->isResponseHeader('content-type', 'text/html; charset=utf-8')->isResponseHeader('x-foo', 'true')->checkResponseElement('body #content', 'This is an HTML file');
$b->setHttpHeader('Accept', 'application/javascript')->get('/format/jsWithAccept')->isStatusCode(200)->isRequestParameter('module', 'format')->isRequestParameter('action', 'jsWithAccept')->isRequestFormat('js')->isResponseHeader('content-type', 'application/javascript');
$b->test()->like($b->getResponse()->getContent(), '/This is a js file/', 'response content is ok');
$b->get('/format/js')->isStatusCode(200)->isRequestParameter('module', 'format')->isRequestParameter('action', 'js')->isRequestFormat('js')->isResponseHeader('content-type', 'application/javascript');
$b->test()->is($b->getResponse()->getContent(), 'A js file', 'response content is ok');
$b->setHttpHeader('User-Agent', 'Mozilla/5.0 (iPhone; U; CPU like Mac OS X; en) AppleWebKit/420+ (KHTML, like Gecko) Version/3.0 Mobile/1A543a Safari/419.3')->get('/format/forTheIPhone')->isStatusCode(200)->isRequestParameter('module', 'format')->isRequestParameter('action', 'forTheIPhone')->isRequestFormat('iphone')->isResponseHeader('content-type', 'text/html; charset=utf-8')->checkResponseElement('#content', 'This is an HTML file for the iPhone')->checkResponseElement('link[href*="iphone.css"]');
$b->getAndCheck('format', 'throwsException', null, 500)->throwsException('Exception', '/message/');
$b->setHttpHeader('Accept', 'application/javascript')->getAndCheck('format', 'throwsException', null, 500)->isRequestFormat('js')->isResponseHeader('content-type', 'application/javascript')->throwsException('Exception', '/message/');
$b->test()->like($b->getResponse()->getContent(), '/Exception/', 'response is exception template');
예제 #4
0
<?php

include dirname(__FILE__) . '/../../bootstrap/functional.php';
// create a new test browser
$browser = new sfTestBrowser();
$browser->initialize();
$t = $browser->test();
$prefix = 'app_sf_google_analytics_plugin_';
$urchinVars = explode(',', 'dn,link,Osr,Okw,tcp,fsc,hash,flash,title,timeout,cto,ccn,cmd,csr,ctr,cct,cid,cno,anchor,Ono,Rno,sample,serv');
$googleSetters = explode(',', 'DomainName,AllowLinker,CookiePath,ClientInfo,AllowHash,DetectFlash,DetectTitle,SessionTimeout,CookieTimeout,CampNameKey,CampMediumKey,CampSourceKey,CampTermKey,CampContentKey,CampIdKey,CampNOKey,AllowAnchor,SampleRate,LocalRemoteServerMode');
$googleAdders = explode(',', 'Organic,IgnoredOrganic,IgnoredRef');
$params = array('page_name' => '/virtual/page', 'domain_name' => 'example.com', 'linker_policy' => true, 'organic_referers' => array(array('name' => 'example.com', 'param' => 'q')), 'vars' => array('customer'), 'cookie_path' => '/subdir', 'client_info_policy' => false, 'hash_policy' => false, 'detect_flash_policy' => false, 'detect_title_policy' => false, 'session_timeout' => 60, 'cookie_timeout' => 600, 'campaign_keys' => array('name' => 'cnk', 'medium' => 'cmk', 'source' => 'csk', 'term' => 'ctk', 'content' => 'cck', 'id' => 'cik', 'no_override' => 'cnok'), 'anchor_policy' => true, 'ignored_organics' => array('keyword'), 'ignored_referers' => array('example.com'), 'sample_rate' => 10, 'local_remote_server_policy' => true);
$browser->getAndCheck('main', 'index');
$t->unlike($browser->getResponse()->getContent(), '/google-analytics\\.com/', 'disabled urchin ok');
sfConfig::set($prefix . 'enabled', true);
$browser->getAndCheck('main', 'index')->responseContains('google-analytics.com')->responseContains('urchinTracker()');
$content = $browser->getResponse()->getContent();
$t->unlike($content, '/_u(' . join('|', $urchinVars) . ')/', 'no params ok');
$t->unlike($content, '/__utmSetVar/', 'no vars ok');
sfConfig::set($prefix . 'params', $params);
$browser->getAndCheck('main', 'index')->responseContains('google-analytics.com')->responseContains('urchinTracker("\\/virtual\\/page")');
$content = $browser->getResponse()->getContent();
foreach ($urchinVars as $var) {
    $t->like($content, '/^_u' . $var . '(\\[\\d*\\])?=[^;]+;$/m', 'u' . $var . ' ok');
}
sfConfig::set($prefix . 'tracker', 'google');
sfConfig::set($prefix . 'params', array());
$browser->getAndCheck('main', 'index')->responseContains('google-analytics.com')->responseContains('pageTracker');
$content = $browser->getResponse()->getContent();
$t->unlike($content, '/set(' . join('|', $googleSetters) . ')/', 'no setters ok');
$t->unlike($content, '/add(' . join('|', $googleAdders) . ')/', 'no adders ok');
    isParameter('module', 'invoice')->
    isParameter('action', 'index')->
  end()->

  with('response')->begin()->
    isStatusCode(200)->
    checkElement('body', '!/This is a temporary page/')->
  end()
;
*/
$b = new sfTestBrowser();
$b->initialize();
$b->get('/customer/new')->setField('customer[name]', 'dummy')->click('Save')->with('response')->begin()->isRedirected()->followRedirect()->end()->with('request')->begin()->isParameter('name', 'dummy')->isParameter('module', 'customer')->isParameter('action', 'edit')->end();
$request = $b->getRequest();
$context = $b->getContext();
$response = $b->getResponse();
foreach ($request as $key => $value) {
    echo $key . "=>" . $value;
}
/*
//--------------------calling pages--------------------
// Create a new test browser
$b = new sfTestBrowser();
$b->initialize();
 
$b->get('/foobar/show/id/1');                   // GET request
$b->post('/foobar/show', array('id' => 1));     // POST request
 
// The get() and post() methods are shortcuts to the call() method
$b->call('/foobar/show/id/1', 'get');
$b->call('/foobar/show', 'post', array('id' => 1));