//if logged in as admin, skip login
//if ($loggedIn && !$loggedInAsAdmin)
//{
//  $browser->click('sign out');
//}

//if (!$loggedIn)
//{
  $browser->
    get('/login')->
    isStatusCode(200);

  $browser->post('/login', array(
    'nickname' => 'admin',
    'password' => 'admin',
    'password_bis' => '',
    'email' => '',
    'referer' => 'http%3A%2F%2Fregistry%2F',
    'commit' => 'sign+in' ))->
    isRedirected()->
    followRedirect();
//}

//should be on the main page now
//global head settings
$browser->
  get('/agent/list')->
  isStatusCode(200)->
  isRequestParameter('module', 'agent')->
  isRequestParameter('action', 'list')->
  checkResponseElement('meta[content="text/html; charset=utf-8"]', true)->
Пример #2
0
<?php

/*
 * This file is part of the symfony package.
 * (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 = 'frontend';
if (!(include dirname(__FILE__) . '/../bootstrap/functional.php')) {
    return;
}
$b = new sfTestBrowser();
$b->post('/fillInFilter/forward', array('name' => 'fabien'))->isStatusCode(200)->isRequestParameter('module', 'fillInFilter')->isRequestParameter('action', 'forward')->checkResponseElement('body div', 'foo');
$b->post('/fillInFilter/update', array('first_name' => 'fabien'))->isStatusCode(200)->isRequestParameter('module', 'fillInFilter')->isRequestParameter('action', 'update')->checkResponseElement('input[name="first_name"][value="fabien"]');
$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":');
} else {
    $browser->responseContains('Anonymous posting not allowed');
}
$browser->test()->comment('Login through the browser');
      $browser = new sfTestBrowser();
      $browser->initialize();

      if (isset($config['roles'][$role]['login']))
      {

        //$browser->setAuth($config['roles'][$role]['login'], $config['roles'][$role]['password']);
        //login as role
  //      $browser->
  //        get('/login')->
  //        isStatusCode(200);

        $browser->post('/login', array(
          'nickname' => $config['roles'][$role]['login'],
          'password' => $config['roles'][$role]['password'],
          'password_bis' => '',
          'email' => '',
          'referer' => 'http%3A%2F%2Fregistry%2F',
          'commit' => 'sign+in' ))->
          isRedirected()->
          followRedirect();
      }
      //is the url an array?
      if (!is_array($actionArray['url']))
      {
        $actionArray['url'] = array('valid' => $actionArray['url']);
      }

      if (isset($actionArray['roles'][$role][$key]))
      {
        //get the url
Пример #5
0
  // check values
  checkResponseElement('input[id="article_title"][value="new title"]')->
  checkResponseElement('#article_body', 'new body')->
  checkResponseElement('#article_category_id option[selected="selected"]', 'Category 2')->

  // check list
  getAndCheck('article', 'list')->
  checkResponseElement('body table tbody tr[class="sf_admin_row_1"] td:nth(7)', '')->

  // nb lines
  checkResponseElement('body table tfoot tr th', '/^\s*3 results\s*$/')
;

// delete
$b->
  post('/article/delete/id/3')->
  isStatusCode(302)->
  isRequestParameter('module', 'article')->
  isRequestParameter('action', 'delete')->
  isRedirected()->
  followRedirect()->
  isStatusCode(200)->
  isRequestParameter('module', 'article')->
  isRequestParameter('action', 'list')->

  // check edit
  get('/article/edit/id/3')->
  isStatusCode(404)->

  // check list
  getAndCheck('article', 'list')->
Пример #6
0
$b->
  click('submit', array('input4' => 'foo'))->
  checkResponseElement('body ul[class="errors"] li[class="input3"]', 'Required')->
  checkResponseElement('body ul[class="errors"] li[class="input4"]', false)
;

$b->test()->diag('when only input3 is filled, the validation fails because input4 is required');
$b->
  click('submit', array('input3' => 'foo'))->
  checkResponseElement('body ul[class="errors"] li[class="input3"]', false)->
  checkResponseElement('body ul[class="errors"] li[class="input4"]', 'Required')
;

// check that /validation/index and /validation/Index both uses the index.yml validation file (see #1617)
// those tests are only relevant on machines where filesystems are case sensitive.
$b->
  post('/validation/index')->
  isStatusCode(200)->
  isRequestParameter('module', 'validation')->
  isRequestParameter('action', 'index')->
  isResponseHeader('X-Validated', 'ko')
;

$b->
  post('/validation/Index')->
  isRequestParameter('module', 'validation')->
  isRequestParameter('action', 'Index')->
  isResponseHeader('X-Validated', 'ko')
;

// needed to pass tests on case and non case sensitive machines
if (!file_exists(dirname(__FILE__).'/fixtures/apps/frontend/modules/validation/templates/IndexSuccess.php'))
// 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->click('submit', array('input1' => 'foo', 'input2' => '1234567890'))->checkResponseElement('body ul[class="errors"] li', false);
$b->test()->diag('when both fields are filled, and input2 has incorrect data, the validation fails because of the nameValidator on input2');
$b->click('submit', array('input1' => 'foo', 'input2' => 'bar'))->checkResponseElement('body ul[class="errors"] li[class="input1"]', false)->checkResponseElement('body ul[class="errors"] li[class="input2"]', 'nameValidator');
$b->test()->diag('when only the second input is filled, and with incorrect data, the validation fails because of the nameValidator on input2 and input1 is required');
$b->click('submit', array('input2' => 'foo'))->checkResponseElement('body ul[class="errors"] li[class="input1"]', 'Required')->checkResponseElement('body ul[class="errors"] li[class="input2"]', 'nameValidator');
$b->test()->diag('when only the first input is filled, the validation fails because of a required on input2');
$b->click('submit', array('input1' => 'foo'))->checkResponseElement('body ul[class="errors"] li[class="input1"]', false)->checkResponseElement('body ul[class="errors"] li[class="input2"]', 'Required');
// test group feature (without validator)
$b->test()->diag('test group feature (without 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->click('submit', array('input3' => 'foo', 'input4' => 'bar'))->checkResponseElement('body ul[class="errors"] li', false);
$b->test()->diag('when only input4 is filled, the validation fails because input3 is required');
$b->click('submit', array('input4' => 'foo'))->checkResponseElement('body ul[class="errors"] li[class="input3"]', 'Required')->checkResponseElement('body ul[class="errors"] li[class="input4"]', false);
$b->test()->diag('when only input3 is filled, the validation fails because input4 is required');
$b->click('submit', array('input3' => 'foo'))->checkResponseElement('body ul[class="errors"] li[class="input3"]', false)->checkResponseElement('body ul[class="errors"] li[class="input4"]', 'Required');
// check that /validation/index and /validation/Index both uses the index.yml validation file (see #1617)
// those tests are only relevant on machines where filesystems are case sensitive.
$b->post('/validation/index')->isStatusCode(200)->isRequestParameter('module', 'validation')->isRequestParameter('action', 'index')->isResponseHeader('X-Validated', 'ko');
$b->post('/validation/Index')->isStatusCode(200)->isRequestParameter('module', 'validation')->isRequestParameter('action', 'Index')->isResponseHeader('X-Validated', 'ko');
$b->post('/validation/INdex')->isStatusCode(404);
$b->post('/validation/index2')->isStatusCode(200)->isRequestParameter('module', 'validation')->isRequestParameter('action', 'index2')->isResponseHeader('X-Validated', 'ko');
$b->post('/validation/Index2')->isStatusCode(200)->isRequestParameter('module', 'validation')->isRequestParameter('action', 'Index2')->isResponseHeader('X-Validated', 'ko');
Пример #8
0
$b = new sfTestBrowser();
// check symfony throws an exception if model class does not exist
$b->get('/error')->isStatusCode(200)->isRequestParameter('module', 'error')->isRequestParameter('action', 'index')->throwsException('sfInitializationException', '/Unable to scaffold nonexistent model/');
// list page
$b->get('/article')->isStatusCode(200)->isRequestParameter('module', 'article')->isRequestParameter('action', 'index')->checkResponseElement('script', false)->checkResponseElement('link[href="/sf/sf_admin/css/main.css"]')->checkResponseElement('link[href][media]', 2);
$content = $b->getResponse()->getContent();
$b->getAndCheck('article', 'list')->checkResponseElement('body h1', 'article list')->checkResponseElement('body table thead tr th[id="sf_admin_list_th_id"]', true)->checkResponseElement('body table thead tr th[id="sf_admin_list_th_id"] a[href*="/sort/"]', 'Id')->checkResponseElement('body table thead tr th[id="sf_admin_list_th_title"]', true)->checkResponseElement('body table thead tr th[id="sf_admin_list_th_title"] a[href*="/sort/"]', 'Title')->checkResponseElement('body table thead tr th[id="sf_admin_list_th_body"]', true)->checkResponseElement('body table thead tr th[id="sf_admin_list_th_body"] a[href*="/sort/"]', 'Body')->checkResponseElement('body table thead tr th[id="sf_admin_list_th_online"]', true)->checkResponseElement('body table thead tr th[id="sf_admin_list_th_online"] a[href*="/sort/"]', 'Online')->checkResponseElement('body table thead tr th[id="sf_admin_list_th_category_id"]', true)->checkResponseElement('body table thead tr th[id="sf_admin_list_th_category_id"] a[href*="/sort/"]', 'Category')->checkResponseElement('body table thead tr th[id="sf_admin_list_th_created_at"]', true)->checkResponseElement('body table thead tr th[id="sf_admin_list_th_created_at"] a[href*="/sort/"]', 'Created at')->checkResponseElement('body table tbody tr[class="sf_admin_row_0"] td:nth(0)', '1')->checkResponseElement('body table tbody tr[class="sf_admin_row_0"] td:nth(1)', 'foo title')->checkResponseElement('body table tbody tr[class="sf_admin_row_0"] td:nth(2)', 'bar body')->checkResponseElement('body table tbody tr[class="sf_admin_row_0"] td:nth(3) img', true)->checkResponseElement('body table tbody tr[class="sf_admin_row_1"] td:nth(4)', 'foo excerpt')->checkResponseElement('body table tbody tr[class="sf_admin_row_0"] td:nth(5)', '1')->checkResponseElement('body table tbody tr[class="sf_admin_row_0"] td a[href$="/article/edit/id/1"]', '1')->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')->checkResponseElement('body table tfoot tr th', '/^\\s*2 results\\s*$/')->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->click('Body')->isStatusCode(200)->isRequestParameter('module', 'article')->isRequestParameter('action', 'list')->isRequestParameter('sort', 'body')->isRequestParameter('type', 'asc')->checkResponseElement('body table tbody tr[class="sf_admin_row_0"] td', '2')->checkResponseElement('body table tbody tr[class="sf_admin_row_1"] td', '1')->getAndCheck('article', 'list')->checkResponseElement('body table tbody tr[class="sf_admin_row_0"] td', '2')->checkResponseElement('body table tbody tr[class="sf_admin_row_1"] td', '1')->click('Body')->isStatusCode(200)->isRequestParameter('module', 'article')->isRequestParameter('action', 'list')->isRequestParameter('sort', 'body')->isRequestParameter('type', 'desc')->checkResponseElement('body table tbody tr[class="sf_admin_row_0"] td', '1')->checkResponseElement('body table tbody tr[class="sf_admin_row_1"] td', '2');
// edit page
$b->click('1')->isStatusCode(200)->isRequestParameter('module', 'article')->isRequestParameter('action', 'edit')->checkResponseElement('script[src*="calendar"]', 3)->checkResponseElement('script[src]', 3)->checkResponseElement('link[href*="calendar"]')->checkResponseElement('link[href="/sf/sf_admin/css/main.css"]')->checkResponseElement('link[href][media]', 3)->checkResponseElement('body h1', 'edit article')->isRequestParameter('id', 1)->checkResponseElement('body form#sf_admin_edit_form label[for="article_title"]', 'Title:')->checkResponseElement('body form#sf_admin_edit_form label[for="article_body"]', 'Body:')->checkResponseElement('body form#sf_admin_edit_form label[for="article_online"]', 'Online:')->checkResponseElement('body form#sf_admin_edit_form label[for="article_category_id"]', 'Category:')->checkResponseElement('body form#sf_admin_edit_form label[for="article_created_at"]', 'Created at:')->checkResponseElement('body form#sf_admin_edit_form input[name="article[title]"][id="article_title"][value="foo title"]')->checkResponseElement('body form#sf_admin_edit_form textarea[name="article[body]"][id="article_body"]', 'bar body')->checkResponseElement('body form#sf_admin_edit_form input[name="article[online]"][id="article_online"][type="checkbox"][checked="checked"]', true)->checkResponseElement('body form#sf_admin_edit_form select[name="article[category_id]"][id="article_category_id"]', true)->checkResponseElement('body form#sf_admin_edit_form select[name="article[category_id]"][id="article_category_id"] option[value="1"]', 'Category 1')->checkResponseElement('body form#sf_admin_edit_form select[name="article[category_id]"][id="article_category_id"] option[value="2"]', 'Category 2')->checkResponseElement('body form#sf_admin_edit_form input[name="article[created_at]"][id="article_created_at"][value*="-"]')->checkResponseElement('body input[class="sf_admin_action_list"][onclick*="/article/list"]', true)->checkResponseElement('body input[name="save_and_add"]', true)->checkResponseElement('body input[name="save"]', true)->checkResponseElement('body input[class="sf_admin_action_delete"][onclick*="confirm"]', true);
// save
$b->click('save', array('article' => array('title' => 'my title', 'body' => 'my body', 'category_id' => 2)))->isStatusCode(302)->isRequestParameter('module', 'article')->isRequestParameter('action', 'save')->isRedirected()->followRedirect()->isStatusCode(200)->isRequestParameter('module', 'article')->isRequestParameter('action', 'edit')->isRequestParameter('id', 1)->checkResponseElement('input[id="article_title"][value="my title"]')->checkResponseElement('#article_body', 'my body')->checkResponseElement('input[id="article_online"][checked="checked"]', true)->checkResponseElement('#article_category_id option[selected="selected"]', 'Category 2');
// save and add
$b->click('save and add')->isStatusCode(302)->isRequestParameter('module', 'article')->isRequestParameter('action', 'save')->isRedirected()->followRedirect()->isStatusCode(200)->isRequestParameter('module', 'article')->isRequestParameter('action', 'create')->isRequestParameter('id', '');
// create
$b->getAndCheck('article', 'create')->isRequestParameter('id', '')->checkResponseElement('body form#sf_admin_edit_form label[for="article_title"]', 'Title:')->checkResponseElement('body form#sf_admin_edit_form input[name="article[title]"][id="article_title"][value=""]')->click('save', array('article' => array('title' => 'new title', 'body' => 'new body', 'category_id' => 2)))->isStatusCode(302)->isRequestParameter('module', 'article')->isRequestParameter('action', 'save')->isRedirected()->followRedirect()->isStatusCode(200)->isRequestParameter('module', 'article')->isRequestParameter('action', 'edit')->isRequestParameter('id', 3)->checkResponseElement('input[id="article_title"][value="new title"]')->checkResponseElement('#article_body', 'new body')->checkResponseElement('#article_category_id option[selected="selected"]', 'Category 2')->getAndCheck('article', 'list')->checkResponseElement('body table tbody tr[class="sf_admin_row_1"] td:nth(7)', '')->checkResponseElement('body table tfoot tr th', '/^\\s*3 results\\s*$/');
// delete
$b->post('/article/delete/id/3')->isStatusCode(302)->isRequestParameter('module', 'article')->isRequestParameter('action', 'delete')->isRedirected()->followRedirect()->isStatusCode(200)->isRequestParameter('module', 'article')->isRequestParameter('action', 'list')->get('/article/edit/id/3')->isStatusCode(404)->getAndCheck('article', 'list')->checkResponseElement('body table tfoot tr th', '/^\\s*2 results\\s*$/');
// add some entries to test pagination
$b->get('/article/create');
for ($i = 0; $i < 30; $i++) {
    $b->click('save and add', array('article' => array('title' => 'title ' . $i, 'body' => 'body ' . $i)))->isRedirected()->followRedirect();
}
$b->getAndCheck('article', 'list')->checkResponseElement('body table tfoot tr th', '/32 results/')->checkResponseElement('body table tfoot tr th a[href*="/article/list/page/"]', 5)->checkResponseElement('body table tfoot tr th a[href*="/article/list/page/1"]', 2)->checkResponseElement('body table tfoot tr th a[href*="/article/list/page/2"]', 3)->get('/article/list/page/2')->isStatusCode(200)->isRequestParameter('module', 'article')->isRequestParameter('action', 'list')->isRequestParameter('page', 2)->checkResponseElement('body table tbody tr', 12)->checkResponseElement('body table tfoot tr th a[href*="/article/list/page/1"]', 3)->checkResponseElement('body table tfoot tr th a[href*="/article/list/page/2"]', 2);
// edit page
$b->click('21')->isStatusCode(200)->isRequestParameter('module', 'article')->isRequestParameter('action', 'edit')->checkResponseElement('script[src*="calendar"]', 3)->checkResponseElement('script[src]', 3)->checkResponseElement('link[href*="calendar"]')->checkResponseElement('link[href="/sf/sf_admin/css/main.css"]')->checkResponseElement('link[href][media]', 3)->checkResponseElement('body h1', 'edit article')->isRequestParameter('id', 21)->checkResponseElement('body form#sf_admin_edit_form label[for="article_title"]', 'Title:')->checkResponseElement('body form#sf_admin_edit_form label[for="article_body"]', 'Body:')->checkResponseElement('body form#sf_admin_edit_form label[for="article_online"]', 'Online:')->checkResponseElement('body form#sf_admin_edit_form label[for="article_category_id"]', 'Category:')->checkResponseElement('body form#sf_admin_edit_form label[for="article_created_at"]', 'Created at:')->checkResponseElement('body form#sf_admin_edit_form input[name="article[title]"][id="article_title"][value="title 18"]')->checkResponseElement('body form#sf_admin_edit_form textarea[name="article[body]"][id="article_body"]', 'body 18')->checkResponseElement('body form#sf_admin_edit_form input[name="article[online]"][id="article_online"][type="checkbox"][checked="checked"]', false)->checkResponseElement('body form#sf_admin_edit_form select[name="article[category_id]"][id="article_category_id"]', true)->checkResponseElement('body form#sf_admin_edit_form select[name="article[category_id]"][id="article_category_id"] option[value="1"]', 'Category 1')->checkResponseElement('body form#sf_admin_edit_form select[name="article[category_id]"][id="article_category_id"] option[value="2"]', 'Category 2')->checkResponseElement('body form#sf_admin_edit_form input[name="article[created_at]"][id="article_created_at"][value*="-"]')->checkResponseElement('body input[class="sf_admin_action_list"][onclick*="/article/list"]', true)->checkResponseElement('body input[name="save_and_add"]', true)->checkResponseElement('body input[name="save"]', true)->checkResponseElement('body input[class="sf_admin_action_delete"][onclick*="confirm"]', true);
$b->get('/article/list')->isStatusCode(200)->isRequestParameter('module', 'article')->isRequestParameter('action', 'list')->checkResponseElement('body table tbody tr[class="sf_admin_row_0"] td', '21', array('position' => 0))->checkResponseElement('body table tbody tr[class="sf_admin_row_0"] td', 'title 18', array('position' => 1))->checkResponseElement('body table tbody tr[class="sf_admin_row_0"] td', 'body 18', array('position' => 2))->checkResponseElement('body table tbody tr[class="sf_admin_row_0"] td img', false, array('position' => 3))->checkResponseElement('body table tbody tr[class="sf_admin_row_0"] td', '1', array('position' => 5))->checkResponseElement('body table tbody tr[class="sf_admin_row_0"] td a[href$="/article/edit/id/21"]', '21')->checkResponseElement('body table tfoot tr th a[href*="/article/list/page/1"]', 3)->checkResponseElement('body table tfoot tr th a[href*="/article/list/page/2"]', 2);
// sort
$b->get('/article/list/sort/title')->isStatusCode(200)->isRequestParameter('module', 'article')->isRequestParameter('action', 'list')->get('/article/list/sort/TiTle')->isStatusCode(200)->isRequestParameter('module', 'article')->isRequestParameter('action', 'list')->get('/article/list/sort/excerpt')->isStatusCode(200)->isRequestParameter('module', 'article')->isRequestParameter('action', 'list');
Пример #9
0
 * This file is part of the symfony package.
 * (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 = 'frontend';
if (!include(dirname(__FILE__).'/../bootstrap/functional.php'))
{
  return;
}

$b = new sfTestBrowser();

$b->
  post('/fillInFilter/forward', array('name' => 'fabien'))->
  isStatusCode(200)->
  isRequestParameter('module', 'fillInFilter')->
  isRequestParameter('action', 'forward')->
  checkResponseElement('body div', 'foo')
;

$b->
  post('/fillInFilter/update', array('first_name' => 'fabien'))->
  isStatusCode(200)->
  isRequestParameter('module', 'fillInFilter')->
  isRequestParameter('action', 'update')->
  checkResponseElement('input[name="first_name"][value="fabien"]')
;