本文整理汇总了PHP中sfTestBrowser::test方法的典型用法代码示例。如果您正苦于以下问题:PHP sfTestBrowser::test方法的具体用法?PHP sfTestBrowser::test怎么用?PHP sfTestBrowser::test使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sfTestBrowser
的用法示例。
在下文中一共展示了sfTestBrowser::test方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: initialize
/**
* Initializes the browser tester instance.
*
* @param string $hostname Hostname
* @param string $remote Remote IP address
* @param array $options Options
*/
public function initialize($hostname = null, $remote = null, $options = array())
{
parent::initialize($hostname, $remote, $options);
$output = isset($options['output']) ? $options['output'] : new lime_output_color();
if (is_null(self::$test)) {
self::$test = new lime_test(null, $output);
}
}
示例2: with
with('request')->begin()->
isParameter('module', 'attachment')->
isParameter('action', 'index')->
end()->
with('response')->isStatusCode(200)->
click('submit', array('attachment' => array('name' => $name, 'file' => $fileToUpload)))->
with('response')->begin()->
isRedirected()->
followRedirect()->
end()->
with('response')->begin()->
matches('/ok/')->
end()
;
$b->test()->ok(file_exists($uploadedFile), 'file is uploaded');
$b->test()->is(file_get_contents($uploadedFile), file_get_contents($fileToUpload), 'file is correctly uploaded');
$c = new Criteria();
$c->add(AttachmentPeer::NAME, $name);
$attachments = AttachmentPeer::doSelect($c);
$b->test()->is(count($attachments), 1, 'the attachment has been saved in the database');
$b->test()->is($attachments[0]->getFile(), 'uploaded.yml', 'the attachment filename has been saved in the database');
@unlink($uploadedFile);
AttachmentPeer::doDeleteAll();
$b->test()->ok(!file_exists($uploadedFile), 'uploaded file is deleted');
// file upload in embedded form
$b->
示例3: sfTestBrowser
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
$app = 'frontend';
$fixtures = 'fixtures/fixtures.yml';
if (!(include dirname(__FILE__) . '/../bootstrap/functional.php')) {
return;
}
$b = new sfTestBrowser();
// file upload
$fileToUpload = dirname(__FILE__) . '/fixtures/config/databases.yml';
$uploadedFile = sfConfig::get('sf_cache_dir') . '/uploaded.yml';
$name = 'test';
$b->get('/attachment/index')->with('request')->begin()->isParameter('module', 'attachment')->isParameter('action', 'index')->end()->with('response')->isStatusCode(200)->click('submit', array('attachment' => array('name' => $name, 'file' => $fileToUpload)))->with('response')->begin()->isRedirected()->followRedirect()->end()->with('response')->begin()->matches('/ok/')->end();
$b->test()->ok(file_exists($uploadedFile), 'file is uploaded');
$b->test()->is(file_get_contents($uploadedFile), file_get_contents($fileToUpload), 'file is correctly uploaded');
$c = new Criteria();
$c->add(AttachmentPeer::NAME, $name);
$attachments = AttachmentPeer::doSelect($c);
$b->test()->is(count($attachments), 1, 'the attachment has been saved in the database');
$b->test()->is($attachments[0]->getFile(), 'uploaded.yml', 'the attachment filename has been saved in the database');
@unlink($uploadedFile);
AttachmentPeer::doDeleteAll();
$b->test()->ok(!file_exists($uploadedFile), 'uploaded file is deleted');
// file upload in embedded form
$b->getAndCheck('attachment', 'embedded')->with('response')->begin()->checkElement('input[name="article[attachment][article_id]"]', false)->checkElement('input[type="file"][name="article[attachment][file]"]')->end()->setField('article[title]', 'Test Article')->setField('article[attachment][name]', $name)->setField('article[attachment][file]', $fileToUpload)->click('submit')->with('form')->hasErrors(false)->with('response')->begin()->isRedirected()->followRedirect()->end()->with('response')->begin()->matches('/ok/')->end();
$b->test()->ok(file_exists($uploadedFile), 'file is uploaded');
$b->test()->is(file_get_contents($uploadedFile), file_get_contents($fileToUpload), 'file is correctly uploaded');
$c = new Criteria();
$c->add(AttachmentPeer::NAME, $name);
示例4: sfTestBrowser
<?php
/*
* This file is part of the symfony package.
* (c) 2004-2006 Fabien Potencier <fabien.potencier@symfony-project.com>
*
* 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->initialize();
// exceptions
$b->get('/exception/noException')->isStatusCode(200)->isRequestParameter('module', 'exception')->isRequestParameter('action', 'noException')->responseContains('foo')->get('/exception/throwsException')->isStatusCode(200)->isRequestParameter('module', 'exception')->isRequestParameter('action', 'throwsException')->throwsException('Exception')->throwsException('Exception', 'Exception message')->throwsException('Exception', '/message/')->throwsException(null, '!/sfException/')->get('/exception/throwsSfException')->isStatusCode(200)->isRequestParameter('module', 'exception')->isRequestParameter('action', 'throwsSfException')->throwsException('sfException')->throwsException('sfException', 'sfException message');
$b->get('/browser')->responseContains('html')->checkResponseElement('h1', 'html')->get('/browser/text')->responseContains('text');
try {
$b->checkResponseElement('h1', 'text');
$b->test()->fail('The DOM is not accessible if the response content type is not HTML');
} catch (sfException $e) {
$b->test()->pass('The DOM is not accessible if the response content type is not HTML');
}
// check response headers
$b->get('/browser/responseHeader')->isStatusCode()->isResponseHeader('content-type', 'text/plain; charset=utf-8')->isResponseHeader('foo', 'bar')->isResponseHeader('foo', 'foobar');
示例5: sfTestBrowser
<?php
/*
* This file is part of the symfony package.
* (c) 2004-2006 Fabien Potencier <fabien.potencier@symfony-project.com>
*
* 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('/autoload/myAutoload')->with('request')->begin()->isParameter('module', 'autoload')->isParameter('action', 'myAutoload')->end()->with('response')->begin()->isStatusCode(200)->checkElement('body div', 'foo')->end();
$t = $b->test();
$t->ok(class_exists('BaseExtendMe'), 'plugin lib directory added to autoload');
$r = new ReflectionClass('ExtendMe');
$t->like(str_replace(DIRECTORY_SEPARATOR, '/', $r->getFilename()), '~fixtures/lib/ExtendMe~', 'plugin class can be replaced by project');
$t->ok(class_exists('NotInLib'), 'plugin autoload sets class paths');
$t->ok(!class_exists('ExcludedFromAutoload'), 'plugin autoload excludes directories');
示例6: sfTestBrowser
* (c) 2004-2006 Fabien Potencier <fabien.potencier@symfony-project.com>
*
* 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);
示例7: dirname
<?php
/*
* This file is part of the symfony package.
* (c) 2004-2006 Fabien Potencier <fabien.potencier@symfony-project.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
$app = 'backend';
$fixtures = 'fixtures';
require_once dirname(__FILE__) . '/../bootstrap/functional.php';
$tests = array('/doctrine/route/test1' => '/Article/', '/doctrine/route/test2' => '/Article/', '/doctrine/route/test3' => '/Doctrine_Collection/', '/doctrine/route/test4' => '/Doctrine_Collection/', '/doctrine/route/test5/1/some_fake_value' => '/Article/', '/doctrine/route/test6/english-title/some_fake_value' => '/Article/', '/doctrine/route/test7/some_fake_value' => '/Doctrine_Collection/', '/doctrine/route/test9/1/english-title/English+Title/test' => '/Article/', '/doctrine/route/test10/1/test' => '/Doctrine_Collection/');
$b = new sfTestBrowser();
foreach ($tests as $url => $check) {
$b->get($url)->with('response')->begin()->isStatusCode('200')->matches($check)->end();
}
$article = Doctrine::getTable('Article')->find(1);
$routes = array('doctrine_route_test5' => array('url' => '/index.php/doctrine/route/test5/1/test-english-title', 'params' => $article), 'doctrine_route_test6' => array('url' => '/index.php/doctrine/route/test6/english-title/test-english-title', 'params' => $article), 'doctrine_route_test7' => array('url' => '/index.php/doctrine/route/test7/w00t', 'params' => array('testing_non_column' => 'w00t')), 'doctrine_route_test8' => array('url' => '/index.php/doctrine/route/test8/1/english-title/English+Title/test', 'params' => array('id' => $article->id, 'slug' => $article->slug, 'title' => $article->title, 'testing_non_column2' => 'test')));
foreach ($routes as $route => $check) {
$url = url_for2($route, $check['params']);
$b->test()->is($url, $check['url'], 'Check "' . $route . '" generates correct url');
}
示例8: sfTestBrowser
<?php
/*
* This file is part of the symfony package.
* (c) Fabien Potencier <fabien.potencier@symfony-project.com>
*
* 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/');
示例9: sfDatabaseManager
include $sf_symfony_lib_dir . '/vendor/lime/lime.php';
// initialize database manager
$databaseManager = new sfDatabaseManager();
$databaseManager->initialize();
$con = Propel::getConnection();
$resource = 'test1';
// clean all the comments related to the test resource
$comments = sfEmendCommentPeer::getAllCommentsForResource($resource);
foreach ($comments as $comment) {
$comment->delete($con);
}
$user_options = sfConfig::get('app_sfEmendPlugin_user');
$browser = new sfTestBrowser();
$browser->initialize();
// get empty comments list for the first resource
$browser->test()->comment('Get an empty comments list');
$browser->get("/emend.getComments/" . $resource)->isStatusCode(200)->isRequestParameter('module', 'sfEmendAPI')->isRequestParameter('action', 'getComments')->responseContains('"n_comments": 0');
// try to add a comment through an emulated POST, as an anonymous user with no author name
$browser->test()->comment('Try to add a comment as anonymous user');
$browser->post("/emend.addComment/" . $resource, array('title' => 'Prova', 'body' => 'Un commento di prova', 'selection' => '"s": []'))->isStatusCode(200);
if ($user_options['allow_anonymous'] == 1) {
$browser->responseContains('Anonymous posting requires an author_name parameter');
} else {
$browser->responseContains('Anonymous posting not allowed');
}
// add a comment through an emulated POST,
// as an anonymous user with author name
$browser->test()->comment('Try to add a comment as anonymous user with author name');
$browser->post("/emend.addComment/" . $resource, array('title' => 'Prova', 'body' => 'Un commento di prova', 'selection' => '"s": []', 'author_name' => 'Guglielmo Celata'))->isStatusCode(200);
if ($user_options['allow_anonymous'] == 1) {
$browser->responseContains('"s":');
示例10: checkResponseElement
checkResponseElement('body table tbody tr[class="sf_admin_row_1"] td:nth(0)', '2')->
checkResponseElement('body table tbody tr[class="sf_admin_row_1"] td:nth(1)', 'foo foo title')->
checkResponseElement('body table tbody tr[class="sf_admin_row_1"] td:nth(2)', 'bar bar body')->
checkResponseElement('body table tbody tr[class="sf_admin_row_1"] td:nth(3) img', false)->
checkResponseElement('body table tbody tr[class="sf_admin_row_1"] td:nth(4)', 'foo excerpt')->
checkResponseElement('body table tbody tr[class="sf_admin_row_1"] td:nth(5)', '2')->
checkResponseElement('body table tbody tr[class="sf_admin_row_1"] td a[href$="/article/edit/id/2"]', '2')->
// nb lines
checkResponseElement('body table tfoot tr th', '/^\s*2 results\s*$/')->
// buttons
checkResponseElement('body input[class="sf_admin_action_create"][onclick*="/article/create"]', true)
;
$b->test()->is($b->getResponse()->getContent(), $content, 'article is an alias for article/list');
// sort
$b->
// asc
click('Body')->
isStatusCode(200)->
isRequestParameter('module', 'article')->
isRequestParameter('action', 'list')->
// parameters
isRequestParameter('sort', 'body')->
isRequestParameter('type', 'asc')->
// check order
checkResponseElement('body table tbody tr[class="sf_admin_row_0"] td', '2')->
示例11: click
click('submit', array('article' => array('title' => 'my title', 'body' => 'my body', 'password' => 'test', 'id' => 4)))->
isStatusCode(200)->
isRequestParameter('module', 'validation')->
isRequestParameter('action', 'index')->
checkResponseElement('body form input[name="fake"][value=""]')->
checkResponseElement('body form input[name="id"][value="1"]')->
checkResponseElement('body form input[name="password"][value=""]')->
checkResponseElement('body form input[name="article[title]"][value="my title"]')->
checkResponseElement('body form textarea[name="article[body]"]', 'my body')->
checkResponseElement('body ul[class="errors"] li[class="fake"]')
;
// test group feature (with validator)
$b->test()->diag('test group feature (with validator)');
$b->
get('/validation/group')->
isStatusCode(200)->
isRequestParameter('module', 'validation')->
isRequestParameter('action', 'group')
;
$b->test()->diag('when none of the two inputs are filled, the validation passes (ok)');
$b->
click('submit')->
checkResponseElement('body ul[class="errors"] li', false)
;
$b->test()->diag('when both fields are filled, the validation passes (ok)');
$b->
示例12: dirname
<?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');
示例13: sfTestBrowser
<?php
/*
* This file is part of the symfony package.
* (c) Fabien Potencier <fabien.potencier@symfony-project.com>
*
* 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');
示例14: sfTestBrowser
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
$app = 'frontend';
$fixtures = 'fixtures/fixtures.yml';
if (!(include dirname(__FILE__) . '/../bootstrap/functional.php')) {
return;
}
$b = new sfTestBrowser();
// file upload
$fileToUpload = dirname(__FILE__) . '/fixtures/config/databases.yml';
$uploadedFile = sfConfig::get('sf_cache_dir') . '/uploaded.yml';
$name = 'test';
$b->get('/attachment/index')->isRequestParameter('module', 'attachment')->isRequestParameter('action', 'index')->isStatusCode(200)->click('submit', array('attachment' => array('name' => $name, 'file' => $fileToUpload)))->isRedirected()->followRedirect()->responseContains('ok');
$b->test()->ok(file_exists($uploadedFile), 'file is uploaded');
$b->test()->is(file_get_contents($uploadedFile), file_get_contents($fileToUpload), 'file is correctly uploaded');
$c = new Criteria();
$c->add(AttachmentPeer::NAME, $name);
$attachments = AttachmentPeer::doSelect($c);
$b->test()->is(count($attachments), 1, 'the attachment has been saved in the database');
$b->test()->is($attachments[0]->getFile(), $uploadedFile, 'the attachment filename has been saved in the database');
// sfValidatorPropelUnique
// create a category with a unique name
$b->get('/unique/category')->isRequestParameter('module', 'unique')->isRequestParameter('action', 'category')->isStatusCode(200)->click('submit', array('category' => array('name' => 'foo')))->isRedirected()->followRedirect()->responseContains('ok');
// create another category with the same name
// we must have an error
$b->get('/unique/category')->isRequestParameter('module', 'unique')->isRequestParameter('action', 'category')->isStatusCode(200)->click('submit', array('category' => array('name' => 'foo')))->checkResponseElement('td[colspan="2"] .error_list li', 0)->checkResponseElement('.error_list li', 'An object with the same "name" already exist.')->checkResponseElement('.error_list li', 1);
// same thing but with a global error
$b->get('/unique/category')->isRequestParameter('module', 'unique')->isRequestParameter('action', 'category')->isStatusCode(200)->click('submit', array('category' => array('name' => 'foo'), 'global' => 1))->checkResponseElement('td[colspan="2"] .error_list li', 'An object with the same "name" already exist.')->checkResponseElement('td[colspan="2"] .error_list li', 1);
// updating the same category again with the same name is allowed