Changeset 2002

Show
Ignore:
Timestamp:
06/20/07 13:52:57 (19 months ago)
Author:
ross
Message:

Added test generation phing commands to build.xml,
Added test code templates in buildtools.
Added some Sample Application Test files - mostly marked incomplete, however check out the Login functional test for an example of how to use AgaviBrowser?
run /agavi/tests/phing - to see what options there are.

More information here: http://trac.agavi.org/wiki/testing#Ross-TestingBranch

Location:
branches/ross-testing
Files:
89 added
3 modified

Legend:

Unmodified
Added
Removed
  • branches/ross-testing/samples/app/config/factories.xml

    r1964 r2002  
    9191     
    9292  </configuration> 
    93    
     93 
     94  <configuration environment="test"> 
     95 
     96    <controller class="AgaviController"> 
     97      <parameter name="send_response">false</parameter> 
     98    </controller> 
     99 
     100    <execution_filter class="AgaviExecutionFilter" > 
     101      <parameter name="enable_caching">false</parameter> 
     102    </execution_filter> 
     103 
     104  </configuration> 
     105 
    94106</configurations> 
  • branches/ross-testing/samples/app/config/settings.xml

    r1964 r2002  
    6363    </settings> 
    6464  </configuration> 
    65    
     65 
     66  <configuration environment="test"> 
     67    <exception_templates> 
     68      <exception_template>%core.agavi_dir%/exception/templates/plaintext.php</exception_template> 
     69    </exception_templates> 
     70  </configuration> 
    6671</configurations> 
  • branches/ross-testing/src/build.xml

    r1964 r2002  
    1515    <echo msg="  module     - create a module" /> 
    1616    <echo msg="  action     - create an action" /> 
    17     <!-- <echo msg="  test       - run unit tests" /> --> 
    1817    <echo msg="  help       - show info and help texts" /> 
    1918  </target> 
     
    2827  <property name="app.dir" value=""/> 
    2928  <property name="app.dirname" value="app" override="false"/> 
    30   <!-- <property name="tests.dir" value=""/> --> 
    31   <!-- <property name="tests2.dir" value="${agavi.dir}/../tests2/"/> --> 
     29  <property name="tests.dir" value=""/> 
    3230 
    3331  <property name="templates.dir.default" value="buildtools/code_templates" /> 
    3432 
    3533  <property name="template.extension" value=".php" override="false" /> 
    36  
    37   <!-- fileset for -dist files --> 
    38   <fileset dir="." id="distfiles"> 
     34   
     35  <!-- fileset for -dist files --> 
     36  <fileset dir="." id="distfiles"> 
    3937    <include name="**/*-dist"/> 
    40   </fileset> 
     38  </fileset> 
    4139 
    4240  <target name="help" description="show info and help texts" > 
     
    4947    <mkdir dir="${project.dir}"/> 
    5048    <fixpaths base="${project.dir}" new="true" appdir="${app.dirname}"/> 
    51     <!-- <echo msg="project dir: ${project.dir}, app dir: ${app.dir}, tests dir: ${tests.dir}"/> --> 
    52     <echo msg="project dir: ${project.dir}, app dir: ${app.dir}"/> 
     49    <echo msg="project dir: ${project.dir}, app dir: ${app.dir}, tests dir: ${tests.dir}"/> 
    5350    <mkdir dir="${project.dir}"/> 
    5451    <mkdir dir="${app.dir}"/> 
     
    10299    <copy file="${templates.dir.current}/defaults/base/ProjectBaseView.class.php.tmpl" tofile="${app.dir}/lib/view/ProjectBaseView.class.php" /> 
    103100 
    104     <!-- <phingcall target="projecttests" /> --> 
     101    <phingcall target="projecttests" /> 
    105102 
    106103    <input propertyname="modules" promptChar="?" defaultValue="Default" message="Modules for your project (no whitespace, comma seperated)"/> 
     
    111108 
    112109  <!-- create tests directory structure which mimics the app structure --> 
    113   <!-- <target name="projecttests" description="create tests structure for project"> --> 
    114   <!--  <fixpaths base="${project.dir}" appdir="${app.dirname}" /> --> 
    115   <!--  <mkdir dir="${tests.dir}" /> --> 
    116   <!--  <mkdir dir="${tests.dir}/lib" /> --> 
    117   <!--  <mkdir dir="${tests.dir}/lib/models" /> --> 
    118   <!--  <mkdir dir="${tests.dir}/modules" /> --> 
    119   <!--  <copy file="buildtools/test_setup.php" tofile="${tests.dir}/test_setup.php" overwrite="true"/> --> 
    120   <!-- </target> --> 
     110  <target name="projecttests" description="create tests structure for project">  
     111    <!-- Create the infrastructure for the tests --> 
     112    <mkdir dir="${tests.dir}" /> 
     113    <property name="templates.dir.current" value="${templates.dir.default}"  override="true"  /> 
     114    <available file="${templates.dir}/tests/build.xml.tmpl" property="templates.dir.current" value="${templates.dir}" /> 
     115    <copy file="${templates.dir.current}/tests/build.xml.tmpl" tofile="${tests.dir}/build.xml" /> 
     116    <mkdir dir="${tests.dir}/cache"/> 
     117    <chmod file="${tests.dir}/cache" mode="777"/> 
     118    <mkdir dir="${tests.dir}/config"/> 
     119    <property name="templates.dir.current" value="${templates.dir.default}"  override="true"  /> 
     120    <available file="${templates.dir}/tests/config/config.php.tmpl" property="templates.dir.current" value="${templates.dir}" /> 
     121    <copy file="${templates.dir.current}/tests/config/config.php.tmpl" tofile="${tests.dir}/config/config.php"> 
     122      <filterchain> 
     123        <replacetokens begintoken="%%" endtoken="%%"> 
     124          <token key="PATH_TO_AGAVI" value="${agavi.dir}"/> 
     125          <token key="PATH_TO_APP" value="${app.dir}"/> 
     126          <token key="PATH_TO_PROJECT" value="${project.dir}"/> 
     127          <token key="PATH_TO_TESTS" value="${tests.dir}"/> 
     128        </replacetokens> 
     129      </filterchain> 
     130    </copy> 
     131 
     132    <mkdir dir="${tests.dir}/libs"/> 
     133    <property name="templates.dir.current" value="${templates.dir.default}"  override="true"  /> 
     134    <available file="${templates.dir}/tests/config" property="templates.dir.current" value="${templates.dir}" /> 
     135    <copy todir="${tests.dir}/libs"> 
     136      <mapper type="glob" from="*.php.tmpl" to="*.php"/> 
     137      <fileset dir="${templates.dir.current}/tests/libs"> 
     138        <include name="*.tmpl"/> 
     139      </fileset> 
     140      <filterchain> 
     141        <replacetokens begintoken="%%" endtoken="%%"> 
     142          <token key="PATH_TO_AGAVI" value="${agavi.dir}"/> 
     143          <token key="PATH_TO_TESTS" value="${tests.dir}"/> 
     144        </replacetokens> 
     145      </filterchain> 
     146    </copy> 
     147 
     148    <!-- create the application structure to hold the tests --> 
     149    <mkdir dir="${tests.dir}/app" /> 
     150    <mkdir dir="${tests.dir}/app/lib" /> 
     151    <mkdir dir="${tests.dir}/app/lib/functional" /> 
     152    <mkdir dir="${tests.dir}/app/lib/unit" /> 
     153    <mkdir dir="${tests.dir}/app/models" /> 
     154    <mkdir dir="${tests.dir}/app/models/functional" /> 
     155    <mkdir dir="${tests.dir}/app/models/unit" /> 
     156    <mkdir dir="${tests.dir}/app/modules" /> 
     157  </target>  
    121158 
    122159  <!-- Module creation --> 
     
    148185    <mkdir dir="${module.dir}/views"/> 
    149186 
    150     <!-- <phingcall target="buildmoduletests"> --> 
    151     <!--  <property name="module" value="${module}"/> --> 
    152     <!-- </phingcall> --> 
     187    <phingcall target="buildmoduletests"> 
     188      <property name="module" value="${module}"/> 
     189    </phingcall> 
    153190 
    154191    <input propertyname="actions" promptChar="?" defaultValue="Index" message="Actions for ${module} (no whitespace, comma seperated)"/> 
     
    158195  </target> 
    159196 
    160   <!-- <target name="buildmoduletests"> --> 
    161   <!--  <fixpaths base="${project.dir}" appdir="${app.dirname}"/> --> 
    162   <!--  <property name="moduletests.dir" value="${tests.dir}/modules/${module}"/> --> 
    163   <!--  <mkdir dir="${moduletests.dir}"/> --> 
    164   <!--  <available file="${moduletests.dir}" type="dir" property="has_tests" value="true"/> --> 
    165   <!--  <fail unless="has_tests" message="Project's tests directory not found."/> --> 
    166   <!--  --> 
    167   <!--  <mkdir dir="${moduletests.dir}/actions"/> --> 
    168   <!--  <mkdir dir="${moduletests.dir}/models"/> --> 
    169   <!--  <mkdir dir="${moduletests.dir}/views"/> --> 
    170   <!-- </target> --> 
     197  <target name="buildmoduletests">  
     198    <fixpaths base="${project.dir}" new="true" appdir="${app.dirname}"/> 
     199    <property name="moduletests.dir" value="${tests.dir}/app/modules/${module}"/>  
     200    <mkdir dir="${moduletests.dir}"/>  
     201    <available file="${moduletests.dir}" type="dir" property="has_tests" value="true"/>  
     202    <fail unless="has_tests" message="Project's tests directory not found."/>  
     203    
     204    <mkdir dir="${moduletests.dir}/functional"/> 
     205    <mkdir dir="${moduletests.dir}/unit"/>  
     206    <mkdir dir="${moduletests.dir}/unit/actions"/>  
     207    <mkdir dir="${moduletests.dir}/unit/models"/>  
     208    <mkdir dir="${moduletests.dir}/unit/views"/>  
     209  </target>  
    171210 
    172211  <!-- Action creation --> 
     
    183222    <phingcall target="buildaction"> 
    184223      <property name="module.dir" value="${app.dir}/modules/${module}"/> 
    185       <!-- <property name="moduletests.dir" value="${tests.dir}/modules/${module}"/> --> 
     224      <property name="moduletests.dir" value="${tests.dir}/app/modules/${module}"/> 
    186225    </phingcall> 
    187226  </target> 
     
    433472    </copy> 
    434473 
    435     <!-- <phingcall target="buildactiontests"> --> 
    436     <!--  <property name="moduletests.dir" value="${tests.dir}/modules/${module}"/> --> 
    437     <!-- </phingcall> --> 
     474    <phingcall target="buildactiontests"> 
     475      <property name="moduletests.dir" value="${tests.dir}/app/modules/${module}"/>  
     476    </phingcall>  
    438477    <input propertyname="views" promptChar="?" defaultValue="Success,Error" message="Views for ${actionPath} (no whitespace, comma seperated)"/> 
    439478    <foreach list="${views}" param="view" target="buildview"/> 
    440479  </target> 
    441480 
    442   <!-- <target name="buildactiontests"> --> 
    443   <!--  <available file="${moduletests.dir}" type="dir" property="has_actiontests" value="true"/> --> 
    444   <!--  <fail unless="has_actiontests" message="Could not find action tests directory: ${moduletests.dir}"/> --> 
    445   <!--  <mkdir dir="${moduletests.dir}/actions"/> --> 
    446   <!--  --> 
    447   <!--  <property name="templates.dir.current" value="${templates.dir.default}" override="true" /> --> 
    448   <!--  <available file="${templates.dir}/ActionTest.class.php.tmpl" property="templates.dir.current" value="${templates.dir}" /> --> 
    449   <!--  <available file="${templates.dir}/modules/${module}/ActionTest.class.php.tmpl" property="templates.dir.current" value="${templates.dir}/modules/${module}" /> --> 
    450   <!--  <copy file="${templates.dir.current}/ActionTest.class.php.tmpl" tofile="${moduletests.dir}/actions/${actionPath}ActionTest.class.php" overwrite="false"> --> 
    451   <!--    <filterchain> --> 
    452   <!--      <replacetokens begintoken="%%" endtoken="%%"> --> 
    453   <!--        <token key="MODULE" value="${module}"/> --> 
    454   <!--        <token key="ACTION" value="${action}"/> --> 
    455   <!--        <token key="ACTION_NAME" value="${actionName}"/> --> 
    456   <!--        <token key="ACTION_PATH" value="${actionPath}"/> --> 
    457   <!--        <token key="ACTION_DIR" value="${actionDir}"/> --> 
    458   <!--        <token key="ACTION_FILE" value="${actionFile}"/> --> 
    459   <!--      </replacetokens> --> 
    460   <!--    </filterchain> --> 
    461   <!--  </copy> --> 
    462   <!-- </target> --> 
     481  <target name="buildactiontests">  
     482    <mkdir dir="${moduletests.dir}/unit/actions"/>  
     483    <available file="${moduletests.dir}" type="dir" property="has_actiontests" value="true"/>  
     484    <fail unless="has_actiontests" message="Could not find action tests directory: ${moduletests.dir}"/>  
     485 
     486    <property name="templates.dir.current" value="${templates.dir.default}" override="true" />  
     487    <available file="${templates.dir}/tests/ActionTest.class.php.tmpl" property="templates.dir.current" value="${templates.dir}" />  
     488    <available file="${templates.dir}/modules/${module}/tests/ActionTest.class.php.tmpl" property="templates.dir.current" value="${templates.dir}/modules/${module}" />  
     489    <copy file="${templates.dir.current}/tests/ActionTest.class.php.tmpl" tofile="${moduletests.dir}/unit/actions/${actionPath}ActionTest.php" overwrite="false">  
     490      <filterchain>  
     491        <replacetokens begintoken="%%" endtoken="%%">  
     492          <token key="MODULE" value="${module}"/>  
     493          <token key="ACTION" value="${action}"/>  
     494          <token key="ACTION_NAME" value="${actionName}"/>  
     495          <token key="ACTION_PATH" value="${actionPath}"/>  
     496          <token key="ACTION_DIR" value="${actionDir}"/>  
     497          <token key="ACTION_FILE" value="${actionFile}"/>  
     498        </replacetokens>  
     499      </filterchain>  
     500    </copy>  
     501  </target>  
    463502 
    464503  <!-- View creation --> 
     
    481520    </copy> 
    482521    <property name="templates.dir.current" value="${templates.dir.default}" override="true" /> 
    483     <available file="${templates.dir}/Template${template.extension}.tmpl" property="templates.dir.current" value="${templates.dir}" /> 
    484     <available file="${templates.dir}/modules/${module}/Template${template.extension}.tmpl" property="templates.dir.current" value="${templates.dir}/modules/${module}" /> 
     522    <available file="${templates.dir}/Template.php.tmpl" property="templates.dir.current" value="${templates.dir}" /> 
     523    <available file="${templates.dir}/modules/${module}/Template.php.tmpl" property="templates.dir.current" value="${templates.dir}/modules/${module}" /> 
    485524    <copy file="${templates.dir.current}/Template${template.extension}.tmpl" tofile="${module.dir}/templates/${actionPath}${view}${template.extension}"> 
    486525      <filterchain> 
     
    496535      </filterchain> 
    497536    </copy> 
    498     <!-- <phingcall target="buildviewtests"> --> 
    499     <!--  <property name="moduletests.dir" value="${tests.dir}/modules/${module}"/> --> 
    500     <!-- </phingcall> --> 
    501   </target> 
    502  
    503   <!-- <target name="buildviewtests"> --> 
    504   <!--  <mkdir dir="${moduletests.dir}/views"/> --> 
    505   <!--  <available file="${moduletests.dir}/views" type="dir" property="has_viewtests" value="true"/> --> 
    506   <!--  <fail unless="has_viewtests" message="Could not find view tests directory."/> --> 
    507   <!--  --> 
    508   <!--  <property name="templates.dir.current" value="${templates.dir.default}" override="true" /> --> 
    509   <!--  <available file="${templates.dir}/ViewTest.class.php.tmpl" property="templates.dir.current" value="${templates.dir}" /> --> 
    510   <!--  <available file="${templates.dir}/modules/${module}/ViewTest.class.php.tmpl" property="templates.dir.current" value="${templates.dir}/modules/${module}" /> --> 
    511   <!--  <copy file="${templates.dir.current}/ViewTest.class.php.tmpl" tofile="${moduletests.dir}/views/${actionPath}${view}ViewTest.class.php" overwrite="false"> --> 
    512   <!--    <filterchain> --> 
    513   <!--      <replacetokens begintoken="%%" endtoken="%%"> --> 
    514   <!--        <token key="MODULE" value="${module}"/> --> 
    515   <!--        <token key="ACTION" value="${action}"/> --> 
    516   <!--        <token key="ACTION_NAME" value="${actionName}"/> --> 
    517   <!--        <token key="ACTION_PATH" value="${actionPath}"/> --> 
    518   <!--        <token key="ACTION_DIR" value="${actionDir}"/> --> 
    519   <!--        <token key="ACTION_FILE" value="${actionFile}"/> --> 
    520   <!--        <token key="VIEW" value="${view}"/> --> 
    521   <!--      </replacetokens> --> 
    522   <!--    </filterchain> --> 
    523   <!--  </copy> --> 
    524   <!-- </target> --> 
     537    <phingcall target="buildviewtests">  
     538      <property name="moduletests.dir" value="${tests.dir}/app/modules/${module}"/>  
     539    </phingcall>  
     540  </target> 
     541 
     542  <target name="buildviewtests">  
     543    <mkdir dir="${moduletests.dir}/unit/views"/>  
     544    <available file="${moduletests.dir}/unit/views" type="dir" property="has_viewtests" value="true"/>  
     545    <fail unless="has_viewtests" message="Could not find view tests directory."/>  
     546 
     547    <property name="templates.dir.current" value="${templates.dir.default}" override="true" />  
     548    <available file="${templates.dir}/tests/ViewTest.class.php.tmpl" property="templates.dir.current" value="${templates.dir}" />  
     549    <available file="${templates.dir}/modules/${module}/tests/ViewTest.class.php.tmpl" property="templates.dir.current" value="${templates.dir}/modules/${module}" />  
     550    <copy file="${templates.dir.current}/tests/ViewTest.class.php.tmpl" tofile="${moduletests.dir}/unit/views/${actionPath}${view}ViewTest.php" overwrite="false">  
     551      <filterchain>  
     552        <replacetokens begintoken="%%" endtoken="%%">  
     553          <token key="MODULE" value="${module}"/>  
     554          <token key="ACTION" value="${action}"/>  
     555          <token key="ACTION_NAME" value="${actionName}"/>  
     556          <token key="ACTION_PATH" value="${actionPath}"/>  
     557          <token key="ACTION_DIR" value="${actionDir}"/>  
     558          <token key="ACTION_FILE" value="${actionFile}"/>  
     559          <token key="VIEW" value="${view}"/>  
     560        </replacetokens>  
     561      </filterchain>  
     562    </copy>  
     563  </target>  
    525564 
    526565  <!-- Model creation --> 
     
    554593      </filterchain> 
    555594    </copy> 
    556     <!-- <phingcall target="buildmodeltests"> --> 
    557     <!--  <property name="moduletests.dir" value="${tests.dir}/modules/${module}"/> --> 
    558     <!-- </phingcall> --> 
    559   </target> 
    560  
    561   <!-- <target name="buildmodeltests"> --> 
    562   <!--  <mkdir dir="${moduletests.dir}/models"/> --> 
    563   <!--  <available file="${moduletests.dir}/models" type="dir" property="has_modeltests" value="true"/> --> 
    564   <!--  <fail unless="has_modeltests" message="Could not find model tests directory. (${moduletests.dir}/models)"/> --> 
    565   <!--  --> 
    566   <!--  <property name="templates.dir.current" value="${templates.dir.default}" override="true" /> --> 
    567   <!--  <available file="${templates.dir}/ModelTest.class.php.tmpl" property="templates.dir.current" value="${templates.dir}" /> --> 
    568   <!--  <available file="${templates.dir}/modules/${module}/ModelTest.class.php.tmpl" property="templates.dir.current" value="${templates.dir}/modules/${module}" /> --> 
    569   <!--  <copy file="${templates.dir.current}/ModelTest.class.php.tmpl" tofile="${moduletests.dir}/models/${model}ModelTest.class.php" overwrite="false"> --> 
    570   <!--    <filterchain> --> 
    571   <!--      <replacetokens begintoken="%%" endtoken="%%"> --> 
    572   <!--        <token key="MODULE" value="${module}"/> --> 
    573   <!--        <token key="MODEL" value="${model}"/> --> 
    574   <!--      </replacetokens> --> 
    575   <!--    </filterchain> --> 
    576   <!--  </copy> --> 
    577   <!-- </target> --> 
     595    <phingcall target="buildmodeltests"> 
     596      <property name="moduletests.dir" value="${tests.dir}/app/modules/${module}"/> 
     597    </phingcall> 
     598  </target> 
     599 
     600  <target name="buildmodeltests">  
     601    <mkdir dir="${moduletests.dir}/unit/models"/>  
     602    <available file="${moduletests.dir}/unit/models" type="dir" property="has_modeltests" value="true"/>  
     603    <fail unless="has_modeltests" message="Could not find model tests directory. (${moduletests.dir}/models)"/>  
     604    
     605    <property name="templates.dir.current" value="${templates.dir.default}" override="true" />  
     606    <available file="${templates.dir}/tests/ModelTest.class.php.tmpl" property="templates.dir.current" value="${templates.dir}" />  
     607    <available file="${templates.dir}/modules/${module}/tests/ModelTest.class.php.tmpl" property="templates.dir.current" value="${templates.dir}/modules/${module}" />  
     608    <copy file="${templates.dir.current}/tests/ModelTest.class.php.tmpl" tofile="${moduletests.dir}/unit/models/${model}ModelTest.php" overwrite="false">  
     609      <filterchain>  
     610        <replacetokens begintoken="%%" endtoken="%%">  
     611          <token key="MODULE" value="${module}"/>  
     612          <token key="MODEL" value="${model}"/>  
     613        </replacetokens>  
     614      </filterchain>  
     615    </copy>  
     616  </target>  
    578617 
    579618  <!-- Fin -->