Permalink
Browse files

Implement functional testing for issue fixed by pull request #183

  • Loading branch information...
1 parent 228eb65 commit d0d194bc35c4666c32e7647f86bf8e31de95798c @e1himself committed Feb 17, 2013
@@ -16,9 +16,10 @@
}
require_once(dirname(__FILE__).'/crudBrowser.class.php');
+require_once(dirname(__FILE__).'/crudBrowserAdmin15.class.php');
-$b = new CrudBrowser();
-$b->browse(array('with-show', 'route-prefix=acme_article'), array(
+$b = new CrudBrowserAdmin15();
+$b->browse(array('with-show', 'route-prefix=acme_article', 'theme=admin15', 'generate-in-cache'), array(
'urlPrefix' => 'articles',
'moduleName' => 'article_backend',
));
@@ -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;
+ }
+}
@@ -1,7 +1,7 @@
acme_article:
- class: sfPropelRouteCollection
+ class: sfPropelORMRouteCollection
type: collection
- options: { model: Article, module: article_backend, prefix_path: articles }
+ options: { model: Article, module: article_backend, prefix_path: articles, with_wildcard_routes: true }
article:
class: sfPropelRouteCollection
@@ -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">

2 comments on commit d0d194b

@e1himself
Owner

I've implemented actual test to reveal this issue #183:

  • Modified route to allow wildcards
  • Modified crud11Test.php to use admin15 generator theme
  • Modified ProjectConfiguration to generate also model filter classes (needded by admin15 theme)
  • Modified schema and added 'sortable' behavior to Artiicle model
  • Added crudBrowserAdmin15 class to test this issue (invalid links for 'Move up'/'Move down' actions)
@e1himself
Owner

Oh, I've noticed that Travis has reported that build is broken. I'll check that.

Please sign in to comment.