Permalink
Browse files

Merge pull request #188 from e1himself/patch-1-test-suite

Issue #183 test suite
  • Loading branch information...
2 parents 3af16a3 + 65c813f commit 9c8c208963c5c536a6b316c6bda8560a04322d9a @willdurand willdurand committed Mar 4, 2013
@@ -0,0 +1,25 @@
+<?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 = 'crud';
+$fixtures = 'fixtures/fixtures.yml';
+if (!include(dirname(__FILE__).'/../../bootstrap/functional.php'))
+{
+ return;
+}
+
+require_once(dirname(__FILE__).'/crudBrowser.class.php');
+require_once(dirname(__FILE__).'/crudBrowserAdmin15.class.php');
+
+$b = new CrudBrowserAdmin15();
+$b->browse(array('with-show', 'route-prefix=acme_article', 'theme=admin15', 'generate-in-cache'), array(
+ 'urlPrefix' => 'more_articles',
+ 'moduleName' => 'article_backend',
+));
@@ -11,23 +11,33 @@
class CrudBrowser extends sfTestBrowser
{
protected
+ $model = 'Article',
$urlPrefix = 'article',
+ $moduleName = 'article',
$singularName = 'Article',
$pluralName = 'Articles',
$projectDir = '';
- public function setup($options)
+ public function setup($options, $parameters = array())
{
$this->projectDir = dirname(__FILE__).'/../fixtures';
$this->cleanup();
+ foreach (array('model', 'urlPrefix', 'moduleName', 'singularName', 'pluralName', 'projectDir') as $param)
+ {
+ if (isset($parameters[$param]))
+ {
+ $this->$param = $parameters[$param];
+ }
+ }
+
chdir($this->projectDir);
$task = new sfPropelGenerateModuleTask(new sfEventDispatcher(), new sfFormatter());
$options[] = 'env=test';
$options[] = 'singular='.$this->singularName;
$options[] = 'plural='.$this->pluralName;
$options[] = '--non-verbose-templates';
- $task->run(array('crud', 'article', 'Article'), $options);
+ $task->run(array('crud', $this->moduleName, $this->model), $options);
require_once($this->projectDir.'/config/ProjectConfiguration.class.php');
sfContext::createInstance(ProjectConfiguration::getApplicationConfiguration('crud', 'test', true, $this->projectDir));
@@ -42,16 +52,16 @@ public function teardown()
return $this;
}
- public function browse($options)
+ public function browse($options, $parameters = array())
{
- $options = $this->setup($options);
+ $options = $this->setup($options, $parameters);
// list page
$this->
info('list page')->
get('/'.$this->urlPrefix)->
with('request')->begin()->
- isParameter('module', $this->urlPrefix)->
+ isParameter('module', $this->moduleName)->
isParameter('action', 'index')->
end()->
with('response')->begin()->
@@ -89,7 +99,7 @@ public function browse($options)
info('create page')->
click('New')->
with('request')->begin()->
- isParameter('module', $this->urlPrefix)->
+ isParameter('module', $this->moduleName)->
isParameter('action', 'new')->
isParameter('id', null)->
end()->
@@ -129,7 +139,7 @@ public function browse($options)
info('go back to the list')->
click('Back to list')->
with('request')->begin()->
- isParameter('module', $this->urlPrefix)->
+ isParameter('module', $this->moduleName)->
isParameter('action', 'index')->
end()->
with('response')->isStatusCode(200)
@@ -148,7 +158,7 @@ public function browse($options)
$this->
with('request')->begin()->
- isParameter('module', $this->urlPrefix)->
+ isParameter('module', $this->moduleName)->
isParameter('action', 'edit')->
isParameter('id', 3)->
end()->
@@ -166,7 +176,8 @@ public function browse($options)
checkElement('table tbody th:nth(5)', 'Created at')->
checkElement('table tbody th:nth(6)', 'End date')->
checkElement('table tbody th:nth(7)', 'Book')->
- checkElement('table tbody th:nth(8)', 'Author article list')->
+ checkElement('table tbody th:nth(8)', 'Sortable rank')->
+ checkElement('table tbody th:nth(9)', 'Author article list')->
checkElement('table tbody td select[id="article_category_id"][name="article[category_id]"] option', 2)->
checkElement('table tbody td select[id="article_book_id"][name="article[book_id]"] option', 2)->
end()
@@ -189,7 +200,7 @@ public function browse($options)
info('save / validation')->
click('Save', array('article' => $values))->
with('request')->begin()->
- isParameter('module', $this->urlPrefix)->
+ isParameter('module', $this->moduleName)->
isParameter('action', 'update')->
end()->
checkFormValues(array_merge($values, array(
@@ -222,7 +233,7 @@ public function browse($options)
info('go back to the list')->
click('Back to list')->
with('request')->begin()->
- isParameter('module', $this->urlPrefix)->
+ isParameter('module', $this->moduleName)->
isParameter('action', 'index')->
end()->
with('response')->isStatusCode(200)
@@ -234,15 +245,15 @@ public function browse($options)
get(sprintf('/%s/3/edit', $this->urlPrefix))->
click('Delete', array(), array('method' => 'delete', '_with_csrf' => true))->
with('request')->begin()->
- isParameter('module', $this->urlPrefix)->
+ isParameter('module', $this->moduleName)->
isParameter('action', 'delete')->
end()->
with('response')->begin()->
isRedirected()->
followRedirect()->
end()->
with('request')->begin()->
- isParameter('module', $this->urlPrefix)->
+ isParameter('module', $this->moduleName)->
isParameter('action', 'index')->
end()->
with('response')->isStatusCode(200)->
@@ -258,7 +269,7 @@ public function browse($options)
info('show page')->
get(sprintf('/%s/2', $this->urlPrefix))->
with('request')->begin()->
- isParameter('module', $this->urlPrefix)->
+ isParameter('module', $this->moduleName)->
isParameter('action', 'show')->
isParameter('id', 2)->
end()->
@@ -293,7 +304,7 @@ public function saveValues($options, $values, $id, $creation)
$this->
click('Save', array('article' => $values))->
with('request')->begin()->
- isParameter('module', $this->urlPrefix)->
+ isParameter('module', $this->moduleName)->
isParameter('action', $creation ? 'create' : 'update')->
end()->
with('response')->begin()->
@@ -304,7 +315,7 @@ public function saveValues($options, $values, $id, $creation)
isStatusCode(200)->
end()->
with('request')->begin()->
- isParameter('module', $this->urlPrefix)->
+ isParameter('module', $this->moduleName)->
isParameter('action', 'edit')->
isParameter('id', $id)->
end()->
@@ -0,0 +1,81 @@
+<?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.
+ */
+
+class CrudBrowserAdmin15 extends CrudBrowser
+{
+ protected $humanizedModuleName;
+
+ public function setup($options, $parameters = array())
+ {
+ $ret = parent::setup($options, $parameters);
+
+ $this->humanizedModuleName = sfInflector::humanize($this->moduleName);
+
+ return $ret;
+ }
+
+ public function browse($options, $parameters = array())
+ {
+ $options = $this->setup($options, $parameters);
+
+ // list page
+ $this->
+ info('list page')->
+ get('/'.$this->urlPrefix)->
+ with('request')->begin()->
+ isParameter('module', $this->moduleName)->
+ isParameter('action', 'index')->
+ end()->
+ with('response')->begin()->
+ isStatusCode(200)->
+
+ checkElement('h1', $this->humanizedModuleName.' List')->
+
+ checkElement('#sf_admin_content table thead tr th:nth(1) a', 'Id')->
+ checkElement('#sf_admin_content table thead tr th:nth(2) a', 'Title')->
+ checkElement('#sf_admin_content table thead tr th:nth(3) a', 'Body')->
+ checkElement('#sf_admin_content table thead tr th:nth(4) a', 'Online')->
+ checkElement('#sf_admin_content table thead tr th:nth(5) a', 'Excerpt')->
+ checkElement('#sf_admin_content table thead tr th:nth(6) a', 'Category')->
+ checkElement('#sf_admin_content table thead tr th:nth(7) a', 'Created at')->
+ checkElement('#sf_admin_content table thead tr th:nth(8) a', 'End date')->
+ checkElement('#sf_admin_content table thead tr th:nth(9) a', 'Book')->
+
+ // Regexps are used here because exact matching doesn't ignore preceding and trailing spaces in a value
+ checkElement('#sf_admin_content table tbody tr td:nth(1) a', '/1/')->
+ checkElement('#sf_admin_content table tbody tr td:nth(2)', '/foo title/')->
+ checkElement('#sf_admin_content table tbody tr td:nth(3)', '/bar body/')->
+ checkElement('#sf_admin_content table tbody tr td:nth(4) img[src=/sfPropelORMPlugin/images/tick.png]', true)->
+ checkElement('#sf_admin_content table tbody tr td:nth(5)', '/foo excerpt/')->
+ checkElement('#sf_admin_content table tbody tr td:nth(6)', '/1/')->
+ // admin15 theme uses another date format, so we just check if there is time outputted
+ checkElement('#sf_admin_content table tbody tr td:nth(7)', '/\d{1,2}\:\d{2}/')->
+ checkElement('#sf_admin_content table tbody tr td:nth(8)', '/^\s*$/m')-> // spaces only
+ checkElement('#sf_admin_content table tbody tr td:nth(9)', '/^\s*$/m')-> // spaces only
+ checkElement(sprintf('a[href*="/%s/new"]', $this->urlPrefix))->
+ checkElement(sprintf('tbody a[href*="/%s/1%s"]', $this->urlPrefix, in_array('with-show', $options) ? '' : '/edit'))->
+ checkElement(sprintf('tbody a[href*="/%s/2%s"]', $this->urlPrefix, in_array('with-show', $options) ? '' : '/edit'))->
+ checkElement('#sf_admin_content table tbody tr td .sf_admin_td_actions .sf_admin_action_moveup', 2)-> // two buttons - one for each row
+ checkElement('#sf_admin_content table tbody tr td .sf_admin_td_actions .sf_admin_action_movedown', 2)-> // two buttons - one for each row
+ checkElement('#sf_admin_content table tbody tr td .sf_admin_td_actions .sf_admin_action_movedown', 2)-> // two buttons - one for each row
+ checkElement(sprintf('#sf_admin_content table tbody tr td .sf_admin_td_actions .sf_admin_action_movedown a[href^=/index.php/%s/]', $this->urlPrefix), 1)-> // the second button is disabled
+ checkElement(sprintf('#sf_admin_content table tbody tr td .sf_admin_td_actions .sf_admin_action_moveup a[href^=/index.php/%s/]', $this->urlPrefix), 1)-> // the second button is disabled
+ end()->
+ click('Move up')->
+ with('response')->begin()->
+ isRedirected(true)-> // redirect after action
+ end()
+ ;
+
+ $this->teardown();
+
+ return $this;
+ }
+}
@@ -13,13 +13,22 @@
class RestBrowser extends CrudBrowser
{
protected
- $urlPrefix = 'articles';
+ $urlPrefix = 'articles',
+ $moduleName = 'articles';
- public function setup($options)
+ public function setup($options, $parameters = array())
{
$this->projectDir = dirname(__FILE__).'/../fixtures';
$this->cleanup();
+ foreach (array('model', 'urlPrefix', 'moduleName', 'singularName', 'pluralName', 'projectDir') as $param)
+ {
+ if (isset($parameters[$param]))
+ {
+ $this->$param = $parameters[$param];
+ }
+ }
+
chdir($this->projectDir);
$task = new sfPropelGenerateModuleForRouteTask(new sfEventDispatcher(), new sfFormatter());
$options[] = 'env=test';
@@ -1,3 +1,8 @@
+acme_article:
+ class: sfPropelORMRouteCollection
+ type: collection
+ options: { model: Article, module: article_backend, prefix_path: more_articles, with_wildcard_routes: true }
+
article:
class: sfPropelRouteCollection
type: collection
@@ -49,6 +49,14 @@ public function initializePropel($app)
$task = new sfPropelBuildFormsTask($this->dispatcher, new sfFormatter());
$task->run(array(), array('application='.$app));
}
+
+ $files = glob(sfConfig::get('sf_lib_dir').'/filter/base/*.php');
+ if (false === $files || !count($files))
+ {
+ chdir(sfConfig::get('sf_root_dir'));
+ $task = new sfPropelBuildFiltersTask($this->dispatcher, new sfFormatter());
+ $task->run(array(), array('application='.$app));
+ }
}
public function loadFixtures($fixtures)
@@ -22,6 +22,8 @@
<unique-column name="title" />
<unique-column name="category_id" />
</unique>
+
+ <behavior name="sortable" />
</table>
<table name="category">

0 comments on commit 9c8c208

Please sign in to comment.