//admin sidebar $browser-> checkResponseElement('div#content_bar > div#panel_admin > h2', '/administration/') ; //list $browser-> checkResponseElement('head > title', '/Registry :: Owners/')-> checkResponseElement('body', '/Owners/')-> checkResponseElement('body', '/National Science Digital Library/')-> checkResponseElement('ul.sf_admin_td_actions > li > a > img[title="edit"]', true)-> checkResponseElement('ul.sf_admin_actions > li > input[value="Create"]', true) ; //show $browser->click('National Science Digital Library')-> isStatusCode(200)-> isRequestParameter('module', 'agent')-> isRequestParameter('action', 'show')-> isRequestParameter('id', '53')-> checkResponseElement('#sf_fieldset_metadata', '/Metadata/')-> checkResponseElement('#show_row_content_agent_id', '/53/')-> checkResponseElement('#show_row_content_agent_created_at', '/13 April 2006 11:54/')-> checkResponseElement('#show_row_agent_last_updated', '/14 September 2006 12:48/')-> checkResponseElement('#sf_fieldset_detail', '/Detail/')-> checkResponseElement('#show_row_agent_type', '/Organization/')-> checkResponseElement('#show_row_content_agent_org_name', '/National Science Digital Library/')-> checkResponseElement('#sf_admin_header h1', '/Detail for National Science Digital Library/')-> checkResponseElement('input[title="Go back to the Owner list"]', true)-> checkResponseElement('input[value="Edit"]', true) ;
* (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);
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')-> checkResponseElement('body table tbody tr[class="sf_admin_row_1"] td', '1')-> // check that sorting is stored in session getAndCheck('article', 'list')->
$b-> get('/validation')-> isStatusCode(200)-> isRequestParameter('module', 'validation')-> isRequestParameter('action', 'index')-> checkResponseElement('body h1', 'Form validation tests')-> checkResponseElement('body form input[name="fake"][value=""]')-> checkResponseElement('body form input[name="id"][value="1"]')-> checkResponseElement('body form input[name="article[title]"][value="title"]')-> checkResponseElement('body form textarea[name="article[body]"]', 'body')-> checkResponseElement('body ul[class="errors"] li', 0) ; // test fill in filter $b-> click('submit')-> 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="title"]')-> checkResponseElement('body form textarea[name="article[body]"]', 'body')-> checkResponseElement('body ul[class="errors"] li[class="fake"]') ; $b-> click('submit', array('article' => array('title' => 'my title', 'body' => 'my body', 'password' => 'test', 'id' => 4)))->
/* * 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->initialize(); $b->get('/validation')->isStatusCode(200)->isRequestParameter('module', 'validation')->isRequestParameter('action', 'index')->checkResponseElement('body h1', 'Form validation tests')->checkResponseElement('body form input[name="fake"][value=""]')->checkResponseElement('body form input[name="id"][value="1"]')->checkResponseElement('body form input[name="article[title]"][value="title"]')->checkResponseElement('body form textarea[name="article[body]"]', 'body')->checkResponseElement('body ul[class="errors"] li', 0); // test fill in filter $b->click('submit')->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="title"]')->checkResponseElement('body form textarea[name="article[body]"]', 'body')->checkResponseElement('body ul[class="errors"] li[class="fake"]'); $b->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->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)
*/ $app = 'backend'; $fixtures = 'fixtures/fixtures.yml'; if (!(include dirname(__FILE__) . '/../bootstrap/functional.php')) { return; } $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(); }