Development

Changeset 12768

You must first sign up to be able to contribute.

Changeset 12768

Show
Ignore:
Timestamp:
11/08/08 14:30:13 (5 years ago)
Author:
fabien
Message:

[1.2] converted some functional tests to the new syntax

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • plugins/sfPropelPlugin/trunk/test/functional/crud/crudBrowser.class.php

    r12637 r12768  
    2323    $task = new sfPropelGenerateModuleTask(new sfEventDispatcher(), new sfFormatter()); 
    2424    $options[] = 'env=test'; 
     25    $options[] = '--non-verbose-templates'; 
    2526    $task->run(array('crud', 'article', 'Article'), $options); 
    2627 
     
    4344 
    4445    // list page 
    45     $this->test()->diag('list page'); 
    46     $this-> 
     46    $this-> 
     47      info('list page')-> 
    4748      get('/'.$this->urlPrefix)-> 
    48       isStatusCode(200)-> 
    49       isRequestParameter('module', $this->urlPrefix)-> 
    50       isRequestParameter('action', 'index')-> 
    51  
    52       checkResponseElement('h1', ucfirst($this->urlPrefix).' List')-> 
    53  
    54       checkResponseElement('table thead tr th:nth(0)', 'Id')-> 
    55       checkResponseElement('table thead tr th:nth(1)', 'Title')-> 
    56       checkResponseElement('table thead tr th:nth(2)', 'Body')-> 
    57       checkResponseElement('table thead tr th:nth(3)', 'Online')-> 
    58       checkResponseElement('table thead tr th:nth(4)', 'Excerpt')-> 
    59       checkResponseElement('table thead tr th:nth(5)', 'Category')-> 
    60       checkResponseElement('table thead tr th:nth(6)', 'Created at')-> 
    61       checkResponseElement('table thead tr th:nth(7)', 'End date')-> 
    62       checkResponseElement('table thead tr th:nth(8)', 'Book')-> 
    63  
    64       checkResponseElement('table tbody tr td:nth(0)', '1')-> 
    65       checkResponseElement('table tbody tr td:nth(1)', 'foo title')-> 
    66       checkResponseElement('table tbody tr td:nth(2)', 'bar body')-> 
    67       checkResponseElement('table tbody tr td:nth(3)', '1')-> 
    68       checkResponseElement('table tbody tr td:nth(4)', 'foo excerpt')-> 
    69       checkResponseElement('table tbody tr td:nth(5)', '1')-> 
    70       checkResponseElement('table tbody tr td:nth(6)', '/^\d{4}\-\d{2}\-\d{2} \d{2}\:\d{2}\:\d{2}$/')-> 
    71       checkResponseElement('table tbody tr td:nth(7)', '')-> 
    72       checkResponseElement('table tbody tr td:nth(8)', '')-> 
    73       checkResponseElement(sprintf('a[href*="/%s/new"]', $this->urlPrefix))-> 
    74       checkResponseElement(sprintf('tbody a[href*="/%s/1%s"]', $this->urlPrefix, in_array('with-show', $options) ? '' : '/edit'))-> 
    75       checkResponseElement(sprintf('tbody a[href*="/%s/2%s"]', $this->urlPrefix, in_array('with-show', $options) ? '' : '/edit')) 
     49      with('request')->begin()-> 
     50        isParameter('module', $this->urlPrefix)-> 
     51        isParameter('action', 'index')-> 
     52      end()-> 
     53      with('response')->begin()-> 
     54        isStatusCode(200)-> 
     55 
     56        checkElement('h1', ucfirst($this->urlPrefix).' List')-> 
     57 
     58        checkElement('table thead tr th:nth(0)', 'Id')-> 
     59        checkElement('table thead tr th:nth(1)', 'Title')-> 
     60        checkElement('table thead tr th:nth(2)', 'Body')-> 
     61        checkElement('table thead tr th:nth(3)', 'Online')-> 
     62        checkElement('table thead tr th:nth(4)', 'Excerpt')-> 
     63        checkElement('table thead tr th:nth(5)', 'Category')-> 
     64        checkElement('table thead tr th:nth(6)', 'Created at')-> 
     65        checkElement('table thead tr th:nth(7)', 'End date')-> 
     66        checkElement('table thead tr th:nth(8)', 'Book')-> 
     67 
     68        checkElement('table tbody tr td:nth(0)', '1')-> 
     69        checkElement('table tbody tr td:nth(1)', 'foo title')-> 
     70        checkElement('table tbody tr td:nth(2)', 'bar body')-> 
     71        checkElement('table tbody tr td:nth(3)', '1')-> 
     72        checkElement('table tbody tr td:nth(4)', 'foo excerpt')-> 
     73        checkElement('table tbody tr td:nth(5)', '1')-> 
     74        checkElement('table tbody tr td:nth(6)', '/^\d{4}\-\d{2}\-\d{2} \d{2}\:\d{2}\:\d{2}$/')-> 
     75        checkElement('table tbody tr td:nth(7)', '')-> 
     76        checkElement('table tbody tr td:nth(8)', '')-> 
     77        checkElement(sprintf('a[href*="/%s/new"]', $this->urlPrefix))-> 
     78        checkElement(sprintf('tbody a[href*="/%s/1%s"]', $this->urlPrefix, in_array('with-show', $options) ? '' : '/edit'))-> 
     79        checkElement(sprintf('tbody a[href*="/%s/2%s"]', $this->urlPrefix, in_array('with-show', $options) ? '' : '/edit'))-> 
     80      end() 
    7681    ; 
    7782 
    7883    // create page 
    79     $this->test()->diag('create page'); 
    80     $this-> 
     84    $this-> 
     85      info('create page')-> 
    8186      click('New')-> 
    82       isStatusCode(200)-> 
    83       isRequestParameter('module', $this->urlPrefix)-> 
    84       isRequestParameter('action', 'new')-> 
    85       isRequestParameter('id', null)-> 
    86       checkResponseElement('h1', 'New '.ucfirst($this->urlPrefix))-> 
    87       checkResponseElement(sprintf('a[href*="/%s"]', $this->urlPrefix), 'Cancel')-> 
    88       checkResponseElement(sprintf('a[href*="/%s/"]', $this->urlPrefix), false)-> 
     87      with('request')->begin()-> 
     88        isParameter('module', $this->urlPrefix)-> 
     89        isParameter('action', 'new')-> 
     90        isParameter('id', null)-> 
     91      end()-> 
     92      with('response')->begin()-> 
     93        isStatusCode(200)-> 
     94        checkElement('h1', 'New '.ucfirst($this->urlPrefix))-> 
     95        checkElement(sprintf('a[href*="/%s"]', $this->urlPrefix), 'Cancel')-> 
     96        checkElement(sprintf('a[href*="/%s/"]', $this->urlPrefix), false)-> 
     97      end()-> 
    8998      checkFormValues(array( 
    9099        'title'               => '', 
     
    99108 
    100109    // save 
    101     $this->test()->diag('save'); 
    102     $this->saveValues($options, array( 
    103       'title'               => 'my real title', 
    104       'body'                => 'my real body', 
    105       'online'              => true, 
    106       'category_id'         => 2, 
    107       'end_date'            => array('year' => '', 'month' => '', 'day' => '', 'hour' => '', 'minute' => ''), 
    108       'book_id'             => null, 
    109       'author_article_list' => array(1, 2), 
    110     ), 3, true); 
     110    $this-> 
     111      info('save')-> 
     112      saveValues($options, array( 
     113        'title'               => 'my real title', 
     114        'body'                => 'my real body', 
     115        'online'              => true, 
     116        'category_id'         => 2, 
     117        'end_date'            => array('year' => '', 'month' => '', 'day' => '', 'hour' => '', 'minute' => ''), 
     118        'book_id'             => null, 
     119        'author_article_list' => array(1, 2), 
     120      ), 3, true) 
     121    ; 
    111122 
    112123    // go back to the list 
    113     $this->test()->diag('go back to the list'); 
    114     $this-> 
     124    $this-> 
     125      info('go back to the list')-> 
    115126      click('Cancel')-> 
    116127      isStatusCode(200)-> 
     
    120131 
    121132    // edit page 
    122     $this->test()->diag('edit page'); 
     133    $this->info('edit page'); 
    123134    if (!in_array('with-show', $options) && ($options['with-show'] === true)) 
    124135    { 
     
    131142 
    132143    $this-> 
    133       isStatusCode(200)-> 
    134       isRequestParameter('module', $this->urlPrefix)-> 
    135       isRequestParameter('action', 'edit')-> 
    136       isRequestParameter('id', 3)-> 
    137       checkResponseElement('h1', 'Edit '.ucfirst($this->urlPrefix))-> 
    138       checkResponseElement(sprintf('a[href*="/%s"]', $this->urlPrefix), 'Cancel')-> 
    139       checkResponseElement(sprintf('a[href*="/%s/3"]', $this->urlPrefix), 'Delete')-> 
    140       checkResponseElement(sprintf('a[href*="/%s/3"][onclick*="confirm"]', $this->urlPrefix))-> 
    141       checkResponseElement('table tbody th:nth(0)', 'Title')-> 
    142       checkResponseElement('table tbody th:nth(1)', 'Body')-> 
    143       checkResponseElement('table tbody th:nth(2)', 'Online')-> 
    144       checkResponseElement('table tbody th:nth(3)', 'Excerpt')-> 
    145       checkResponseElement('table tbody th:nth(4)', 'Category id')-> 
    146       checkResponseElement('table tbody th:nth(5)', 'Created at')-> 
    147       checkResponseElement('table tbody th:nth(6)', 'End date')-> 
    148       checkResponseElement('table tbody th:nth(7)', 'Book id')-> 
    149       checkResponseElement('table tbody th:nth(8)', 'Author article list')-> 
    150       checkResponseElement('table tbody td select[id="article_category_id"][name="article[category_id]"] option', 2)-> 
    151       checkResponseElement('table tbody td select[id="article_book_id"][name="article[book_id]"] option', 2) 
     144      with('request')->begin()-> 
     145        isParameter('module', $this->urlPrefix)-> 
     146        isParameter('action', 'edit')-> 
     147        isParameter('id', 3)-> 
     148      end()-> 
     149      with('response')->begin()-> 
     150        isStatusCode(200)-> 
     151        checkElement('h1', 'Edit '.ucfirst($this->urlPrefix))-> 
     152        checkElement(sprintf('a[href*="/%s"]', $this->urlPrefix), 'Cancel')-> 
     153        checkElement(sprintf('a[href*="/%s/3"]', $this->urlPrefix), 'Delete')-> 
     154        checkElement(sprintf('a[href*="/%s/3"][onclick*="confirm"]', $this->urlPrefix))-> 
     155        checkElement('table tbody th:nth(0)', 'Title')-> 
     156        checkElement('table tbody th:nth(1)', 'Body')-> 
     157        checkElement('table tbody th:nth(2)', 'Online')-> 
     158        checkElement('table tbody th:nth(3)', 'Excerpt')-> 
     159        checkElement('table tbody th:nth(4)', 'Category id')-> 
     160        checkElement('table tbody th:nth(5)', 'Created at')-> 
     161        checkElement('table tbody th:nth(6)', 'End date')-> 
     162        checkElement('table tbody th:nth(7)', 'Book id')-> 
     163        checkElement('table tbody th:nth(8)', 'Author article list')-> 
     164        checkElement('table tbody td select[id="article_category_id"][name="article[category_id]"] option', 2)-> 
     165        checkElement('table tbody td select[id="article_book_id"][name="article[book_id]"] option', 2)-> 
     166      end() 
    152167    ; 
    153168 
    154169    // save / validation 
    155     $this->test()->diag('save / validation'); 
    156170    $values = array( 
    157171      'id'                  => 1009299, 
     
    167181 
    168182    $this-> 
     183      info('save / validation')-> 
    169184      click('Save', array('article' => $values))-> 
    170185      isStatusCode(200)-> 
     
    179194 
    180195    // save 
    181     $this->test()->diag('save'); 
    182     $this->saveValues($options, array( 
    183       'id'                  => 3, 
    184       'title'               => 'my title', 
    185       'body'                => 'my body', 
    186       'online'              => false, 
    187       'category_id'         => 1, 
    188       'end_date'            => array('year' => 2005, 'month' => 10, 'day' => 15, 'hour' => '10', 'minute' => '20'), 
    189       'book_id'             => 1, 
    190       'author_article_list' => array(1, 3), 
    191     ), 3, false); 
     196    $this-> 
     197      info('save')-> 
     198      saveValues($options, array( 
     199        'id'                  => 3, 
     200        'title'               => 'my title', 
     201        'body'                => 'my body', 
     202        'online'              => false, 
     203        'category_id'         => 1, 
     204        'end_date'            => array('year' => 2005, 'month' => 10, 'day' => 15, 'hour' => '10', 'minute' => '20'), 
     205        'book_id'             => 1, 
     206        'author_article_list' => array(1, 3), 
     207      ), 3, false) 
     208    ; 
    192209 
    193210    // go back to the list 
    194     $this->test()->diag('go back to the list'); 
    195     $this-> 
     211    $this-> 
     212      info('go back to the list')-> 
    196213      click('Cancel')-> 
    197214      isStatusCode(200)-> 
     
    201218 
    202219    // delete 
    203     $this->test()->diag('delete'); 
    204     $this-> 
     220    $this-> 
     221      info('delete')-> 
    205222      get(sprintf('/%s/3/edit', $this->urlPrefix))-> 
    206223 
     
    222239    { 
    223240      // show page 
    224       $this->test()->diag('show page'); 
    225241      $this-> 
     242        info('show page')-> 
    226243        get(sprintf('/%s/2', $this->urlPrefix))-> 
    227         isStatusCode(200)-> 
    228         isRequestParameter('module', $this->urlPrefix)-> 
    229         isRequestParameter('action', 'show')-> 
    230         isRequestParameter('id', 2)-> 
    231         checkResponseElement(sprintf('a[href*="/%s/2%s"]', $this->urlPrefix, in_array('with-show', $options) ? '' : '/edit'), 'Edit')-> 
    232         checkResponseElement(sprintf('a[href*="/%s"]', $this->urlPrefix), 'List', array('position' => 1))-> 
    233         checkResponseElement('body table tbody tr:nth(0)', '/Id\:\s+2/')-> 
    234         checkResponseElement('body table tbody tr:nth(1)', '/Title\:\s+foo foo title/')-> 
    235         checkResponseElement('body table tbody tr:nth(2)', '/Body\:\s+bar bar body/')-> 
    236         checkResponseElement('body table tbody tr:nth(3)', '/Online\:\s+/')-> 
    237         checkResponseElement('body table tbody tr:nth(4)', '/Excerpt\:\s+foo excerpt/')-> 
    238         checkResponseElement('body table tbody tr:nth(5)', '/Category\:\s+2/')-> 
    239         checkResponseElement('body table tbody tr:nth(6)', '/Created at\:\s+[0-9\-\:\s]+/')-> 
    240         checkResponseElement('body table tbody tr:nth(7)', '/End date\:\s+[0-9\-\:\s]+/')-> 
    241         checkResponseElement('body table tbody tr:nth(8)', '/Book\:\s+/') 
     244        with('request')->begin()-> 
     245          isParameter('module', $this->urlPrefix)-> 
     246          isParameter('action', 'show')-> 
     247          isParameter('id', 2)-> 
     248        end()-> 
     249        with('response')->begin()-> 
     250          isStatusCode(200)-> 
     251          checkElement(sprintf('a[href*="/%s/2%s"]', $this->urlPrefix, in_array('with-show', $options) ? '' : '/edit'), 'Edit')-> 
     252          checkElement(sprintf('a[href*="/%s"]', $this->urlPrefix), 'List', array('position' => 1))-> 
     253          checkElement('body table tbody tr:nth(0)', '/Id\:\s+2/')-> 
     254          checkElement('body table tbody tr:nth(1)', '/Title\:\s+foo foo title/')-> 
     255          checkElement('body table tbody tr:nth(2)', '/Body\:\s+bar bar body/')-> 
     256          checkElement('body table tbody tr:nth(3)', '/Online\:\s+/')-> 
     257          checkElement('body table tbody tr:nth(4)', '/Excerpt\:\s+foo excerpt/')-> 
     258          checkElement('body table tbody tr:nth(5)', '/Category\:\s+2/')-> 
     259          checkElement('body table tbody tr:nth(6)', '/Created at\:\s+[0-9\-\:\s]+/')-> 
     260          checkElement('body table tbody tr:nth(7)', '/End date\:\s+[0-9\-\:\s]+/')-> 
     261          checkElement('body table tbody tr:nth(8)', '/Book\:\s+/')-> 
     262        end() 
    242263      ; 
    243264    } 
     
    275296  public function checkFormValues(array $values) 
    276297  { 
    277     return $this-> 
    278       checkResponseElement(sprintf('table tbody td input[id="article_title"][name="article[title]"][value="%s"]', $values['title']))-> 
    279  
    280       checkResponseElement('table tbody td textarea[id="article_body"][name="article[body]"]', $values['body'])-> 
    281  
    282       checkResponseElement(sprintf('table tbody td input[id="article_online"][name="article[online]"][type="checkbox"]%s', $values['online'] ? '[checked="checked"]' : ''))-> 
    283  
    284       checkResponseElement(sprintf('table tbody td select[id="article_category_id"][name="article[category_id]"] option[value="1"]%s', $values['category_id'] == 1 ? '[selected="selected"]' : ''), 'Category 1')-> 
    285       checkResponseElement(sprintf('table tbody td select[id="article_category_id"][name="article[category_id]"] option[value="2"]%s', $values['category_id'] == 2 ? '[selected="selected"]' : ''), 'Category 2')-> 
    286  
    287       checkResponseElement(sprintf('table tbody td select[id="article_book_id"][name="article[book_id]"] option[value=""]%s', $values['book_id'] == '' ? '[selected="selected"]' : ''), '')-> 
    288       checkResponseElement(sprintf('table tbody td select[id="article_book_id"][name="article[book_id]"] option[value="1"]%s', $values['book_id'] == 1 ? '[selected="selected"]' : ''), 'The definitive guide to symfony')-> 
    289  
    290       checkResponseElement(sprintf('table tbody td select[id="article_author_article_list"][name="article[author_article_list][]"] option[value="1"]%s', in_array(1, $values['author_article_list']) ? '[selected="selected"]' : ''), 'Fabien')-> 
    291       checkResponseElement(sprintf('table tbody td select[id="article_author_article_list"][name="article[author_article_list][]"] option[value="2"]%s', in_array(2, $values['author_article_list']) ? '[selected="selected"]' : ''), 'Thomas')-> 
    292       checkResponseElement(sprintf('table tbody td select[id="article_author_article_list"][name="article[author_article_list][]"] option[value="3"]%s', in_array(3, $values['author_article_list']) ? '[selected="selected"]' : ''), 'Hélène')-> 
    293  
    294       checkResponseElement('table tbody td select[id="article_end_date_year"][name="article[end_date][year]"] option[selected="selected"]', (string) $values['end_date']['year'])-> 
    295       checkResponseElement('table tbody td select[id="article_end_date_month"][name="article[end_date][month]"] option[selected="selected"]', (string) $values['end_date']['month'])-> 
    296       checkResponseElement('table tbody td select[id="article_end_date_day"][name="article[end_date][day]"] option[selected="selected"]', (string) $values['end_date']['day'])-> 
    297       checkResponseElement('table tbody td select[id="article_end_date_hour"][name="article[end_date][hour]"] option[selected="selected"]', (string) $values['end_date']['hour'])-> 
    298       checkResponseElement('table tbody td select[id="article_end_date_minute"][name="article[end_date][minute]"] option[selected="selected"]', (string) $values['end_date']['minute']) 
    299    
     298    return $this->with('response')->begin()-> 
     299      checkElement(sprintf('table tbody td input[id="article_title"][name="article[title]"][value="%s"]', $values['title']))-> 
     300 
     301      checkElement('table tbody td textarea[id="article_body"][name="article[body]"]', $values['body'])-> 
     302 
     303      checkElement(sprintf('table tbody td input[id="article_online"][name="article[online]"][type="checkbox"]%s', $values['online'] ? '[checked="checked"]' : ''))-> 
     304 
     305      checkElement(sprintf('table tbody td select[id="article_category_id"][name="article[category_id]"] option[value="1"]%s', $values['category_id'] == 1 ? '[selected="selected"]' : ''), 'Category 1')-> 
     306      checkElement(sprintf('table tbody td select[id="article_category_id"][name="article[category_id]"] option[value="2"]%s', $values['category_id'] == 2 ? '[selected="selected"]' : ''), 'Category 2')-> 
     307 
     308      checkElement(sprintf('table tbody td select[id="article_book_id"][name="article[book_id]"] option[value=""]%s', $values['book_id'] == '' ? '[selected="selected"]' : ''), '')-> 
     309      checkElement(sprintf('table tbody td select[id="article_book_id"][name="article[book_id]"] option[value="1"]%s', $values['book_id'] == 1 ? '[selected="selected"]' : ''), 'The definitive guide to symfony')-> 
     310 
     311      checkElement(sprintf('table tbody td select[id="article_author_article_list"][name="article[author_article_list][]"] option[value="1"]%s', in_array(1, $values['author_article_list']) ? '[selected="selected"]' : ''), 'Fabien')-> 
     312      checkElement(sprintf('table tbody td select[id="article_author_article_list"][name="article[author_article_list][]"] option[value="2"]%s', in_array(2, $values['author_article_list']) ? '[selected="selected"]' : ''), 'Thomas')-> 
     313      checkElement(sprintf('table tbody td select[id="article_author_article_list"][name="article[author_article_list][]"] option[value="3"]%s', in_array(3, $values['author_article_list']) ? '[selected="selected"]' : ''), 'Hélène')-> 
     314 
     315      checkElement('table tbody td select[id="article_end_date_year"][name="article[end_date][year]"] option[selected="selected"]', (string) $values['end_date']['year'])-> 
     316      checkElement('table tbody td select[id="article_end_date_month"][name="article[end_date][month]"] option[selected="selected"]', (string) $values['end_date']['month'])-> 
     317      checkElement('table tbody td select[id="article_end_date_day"][name="article[end_date][day]"] option[selected="selected"]', (string) $values['end_date']['day'])-> 
     318      checkElement('table tbody td select[id="article_end_date_hour"][name="article[end_date][hour]"] option[selected="selected"]', (string) $values['end_date']['hour'])-> 
     319      checkElement('table tbody td select[id="article_end_date_minute"][name="article[end_date][minute]"] option[selected="selected"]', (string) $values['end_date']['minute'])-> 
     320    end()
    300321  } 
    301322 
  • plugins/sfPropelPlugin/trunk/test/functional/crud/restBrowser.class.php

    r11475 r12768  
    2424    $task = new sfPropelGenerateModuleForRouteTask(new sfEventDispatcher(), new sfFormatter()); 
    2525    $options[] = 'env=test'; 
     26    $options[] = '--non-verbose-templates'; 
    2627    $task->run(array('crud', 'articles'), $options); 
    2728