忍者ブログ
[PR]
×

[PR]上記の広告は3ヶ月以上新規記事投稿のないブログに表示されています。新しい記事を書く事で広告が消えます。



2024/04/27 03:25 |
Symfony-9日目その2
先日の続き。 いろいろな検査をやってますが、基本的にsfTestFunctional::checkElement()で要素が存在するか、内容が正しいかを確認しているだけのようです。

lib/test/JobeetTestFunctional.class.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
class JobeetTestFunctional extends sfTestFunctional{
  public function loadData(){
    Doctrine::loadData(sfConfig::get('sf_test_dir').'/fixtures');
    return $this;
  }
 
  public function getMostRecentProgrammingJob(){
    $q = Doctrine_Query::create()
      ->select('j.*')
      ->from('JobeetJob j')
      ->leftJoin('j.JobeetCategory c')
      ->where('c.slug = ?', 'programming');
    $q = Doctrine::getTable('JobeetJob')->addActiveJobsQuery($q);
    return $q->fetchOne();
  }
 
  public function getExpiredJob(){
    $q = Doctrine_Query::create()
      ->from('JobeetJob j')
      ->where('j.expires_at < ?', date('Y-m-d', time()));
    return $q->fetchOne();
  }}


test/functional/frontend/jobActionsTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
include(dirname(__FILE__).'/../../bootstrap/functional.php');
 
$browser = new JobeetTestFunctional(new sfBrowser());
$browser->loadData();
 
$browser->info('1 - The homepage')->
  get('/')->
  with('request')->begin()->
    isParameter('module', 'job')->
    isParameter('action', 'index')->
  end()->
  with('response')->begin()->
    info('  1.1 - Expired jobs are not listed')->
    checkElement('.jobs td.position:contains("expired")', false)->
  end()
;
 
$max = sfConfig::get('app_max_jobs_on_homepage');
 
$browser->info('1 - The homepage')->
  info(sprintf('  1.2 - Only %s jobs are listed for a category', $max))->
  with('response')->
    checkElement('.category_programming tr', $max)
;
 
$browser->info('1 - The homepage')->
  get('/')->
  info('  1.3 - A category has a link to 
     the category page only if too many jobs')->
  with('response')->begin()->
    checkElement('.category_design .more_jobs', false)->
    checkElement('.category_programming .more_jobs')->
  end()
;
 
$browser->info('1 - The homepage')->
  info('  1.4 - Jobs are sorted by date')->
  with('response')->begin()->
    checkElement(sprintf('.category_programming tr:first a[href*="/%d/"]',
      $browser->getMostRecentProgrammingJob()->getId()))->
  end()
;
 
$browser->info('2 - The job page')->
  info('  2.1 - Each job on the homepage is clickable 
      and give detailed information')->
  click('Web Developer', array(), array('position' => 1))->
  with('request')->begin()->
    isParameter('module', 'job')->
    isParameter('action', 'show')->
    isParameter('company_slug', 'sensio-labs')->
    isParameter('location_slug', 'paris-france')->
    isParameter('position_slug', 'web-developer')->
    isParameter('id', $browser->getMostRecentProgrammingJob()->getId())->
  end()->
 
  info('  2.2 - A non-existent job forwards the user to a 404')->
  get('/job/foo-inc/milano-italy/0/painter')->
  with('response')->isStatusCode(404)->
 
  info('  2.3 - An expired job page forwards the user to a 404')->
  get(sprintf('/job/sensio-labs/paris-france/%d/web-developer',
    $browser->getExpiredJob()->getId()))->
  with('response')->isStatusCode(404)
;


test/functional/frontend/categoryActionsTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
include(dirname(__FILE__).'/../../bootstrap/functional.php');
 
$browser = new JobeetTestFunctional(new sfBrowser());
$browser->loadData();
 
$browser->info('1 - The category page')->
  info('  1.1 - Categories on homepage are clickable')->
  get('/')->
  click('Programming')->
  with('request')->begin()->
    isParameter('module', 'category')->
    isParameter('action', 'show')->
    isParameter('slug', 'programming')->
  end()->
 
  info(sprintf('  1.2 - Categories with 
      more than %s jobs also have a "more" link',
   sfConfig::get('app_max_jobs_on_homepage')))->
  get('/')->
  click('22')->
  with('request')->begin()->
    isParameter('module', 'category')->
    isParameter('action', 'show')->
    isParameter('slug', 'programming')->
  end()->
 
  info(sprintf('  1.3 - Only %s jobs are listed'
      , sfConfig::get('app_max_jobs_on_category')))->
  with('response')->checkElement('.jobs tr'
      , sfConfig::get('app_max_jobs_on_category'))->
 
  info('  1.4 - The job listed is paginated')->
  with('response')->begin()->
    checkElement('.pagination_desc', '/32 jobs/')->
    checkElement('.pagination_desc', '#page 1/2#')->
  end()->
 
  click('2')->
  with('request')->begin()->
    isParameter('page', 2)->
  end()->
  with('response')->checkElement('.pagination_desc', '#page 2/2#')
;


個別にテストを行います。
>php test/functional/frontend/jobActionsTest.php
>php test/functional/frontend/categoryActionsTest.php


アプリケーション単位のテスト、またテストフォルダに存在するテストを一気に全部行うこともできます。
>php symfony test:functional frontend
>php symfony test:all


めでたしめでたし。


……エラーになりました。

>php test/functional/frontend/categoryActionsTest.php
> 1 - The category page
> 1.1 - Categories on homepage are clickable
# get /
# get /category/programming
ok 1 - request parameter module is category
ok 2 - request parameter action is show
ok 3 - request parameter slug is programming
> 1.2 - Categories with more than 5 jobs also have a "more" link
# get /
InvalidArgumentException: Cannot find the "22" link or button.
at () in C:\xampp\php\PEAR\symfony\util\sfBrowserBase.class.php line 689
at sfBrowserBase->doClick() in test\sfTestFunctionalBase.class.php line 289
at sfTestFunctionalBase->click() in test\functional\frontend\categoryActionsTest.php line 20
not ok 4 - An uncaught exception has been thrown.
# Failed test (test\sfTestFunctionalBase.class.php at line 612)
1..4
Looks like you failed 1 tests of 4.


categoryActionsTest.phpclick('22')の部分でエラーが発生しました。

原因はチュートリアルのapp.yml
max_jobs_on_homepage: 10
max_jobs_on_category: 20

であるのに対し、手元で試したときの設定が
max_jobs_on_homepage: 5
max_jobs_on_category: 10

になっていたからです。
これだとリンク部分が「and 27 more...」になってしまうので22のリンクが見つからないのです。

てか、このテストは思いっきりデータベースの件数やapp.ymlの設定に依存したテストになってしまってるんだがそれでいいのか?
限界値分析のためにデータ放り込んでテストしなきゃならんとかなったら毎回テストを書き換えなければならず手間暇があんまり変わらないような。


あと、このテスト機能をブラウザから閲覧できる機能があってもいいと思うんだがどうだろう。
PR


2010/02/01 21:38 | Comments(1) | TrackBack() | PHP

トラックバック

トラックバックURL:

コメント

チュートリアルとこのサイトを並行読みすると、じつに分かりやすい。
おもわず笑ったり、眼からウロコが落ちたり、チュートリアルで、首をひねるような箇所がすんなり納得できたり、と毎回楽しみです。
忙しいでしょうけれど、10日の「フォーム」と、13日の「ユーザー」楽しみに待っています。この箇所はおそらくsymfonyの白眉と思われます。
posted by TomTom URL at 2010/02/08 12:09 [ コメントを修正する ]

コメントを投稿する






Vodafone絵文字 i-mode絵文字 Ezweb絵文字 (絵文字)



<<EC-CUBE インストール | HOME | 買ったものリスト 2010/01/31>>
忍者ブログ[PR]