Development

Changeset 15970

You must first sign up to be able to contribute.

Changeset 15970

Show
Ignore:
Timestamp:
03/03/09 19:26:30 (4 years ago)
Author:
hartym
Message:

[sfEasyCommentsPlugin] added simple functional test of comment posting workflow

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • plugins/sfEasyCommentsPlugin/trunk/modules/sfEasyComments/templates/_form.php

    r15903 r15970  
    1818 
    1919<?php if (count($placeholder['Items'])): ?> 
    20  
    21   <hr /
    22  
    23   <?php foreach ($placeholder['Items'] as $item): ?> 
    24     <?php include_partial('sfEasyComments/item', array('item'=>$item)); ?
    25   <?php endforeach; ?> 
    26  
     20  <ul class="sfEasyCommentsItemList"> 
     21    <?php foreach ($placeholder['Items'] as $item): ?
     22      <li> 
     23        <?php include_partial('sfEasyComments/item', array('item'=>$item)); ?> 
     24      </li
     25    <?php endforeach; ?> 
     26  </ul> 
    2727<?php endif; ?> 
  • plugins/sfEasyCommentsPlugin/trunk/modules/sfEasyComments/templates/_item.php

    r15897 r15970  
    1 <div> 
    2   <h4> 
    3     <?php if ($item['author_website']): ?> 
    4       <a href="<?php echo htmlentities($item['author_website']); ?>" rel="nofollow"><?php echo htmlentities($item['author_name']); ?></a> 
    5     <?php else: ?> 
    6       <?php echo htmlentities($item['author_name']); ?> 
    7     <?php endif; ?> 
    8     (<?php echo sfEasyCommentsHelper::render_interval(strtotime($item['created_at'])); ?>) 
    9   </h4> 
     1<h4> 
     2  <?php if ($item['author_website']): ?> 
     3    <a href="<?php echo htmlentities($item['author_website']); ?>" rel="nofollow"><?php echo htmlentities($item['author_name']); ?></a> 
     4  <?php else: ?> 
     5    <?php echo htmlentities($item['author_name']); ?> 
     6  <?php endif; ?> 
     7  (<?php echo sfEasyCommentsHelper::render_interval(strtotime($item['created_at'])); ?>) 
     8</h4> 
    109 
     10<span> 
    1111  <?php echo str_replace("\n", '<br />', htmlentities($item['body'])); ?> 
    12 </div
     12</span
  • plugins/sfEasyCommentsPlugin/trunk/test/fixtures/project/apps/frontend/config/settings.yml

    r15888 r15970  
    2929    escaping_method:        ESC_SPECIALCHARS # Function or helper used for escaping. Accepted values: ESC_RAW, ESC_ENTITIES, ESC_JS, ESC_JS_NO_ENTITIES, and ESC_SPECIALCHARS. 
    3030 
     31    enabled_modules: 
     32      - sfDynamics 
     33      - sfEasyComments 
     34 
    3135#all: 
    3236#  .actions: 
     
    4044#    secure_action:          secure    # The credentials required for an action 
    4145# 
    42 #    module_disabled_module: default   # To be called when a user requests  
     46#    module_disabled_module: default   # To be called when a user requests 
    4347#    module_disabled_action: disabled  # A module disabled in the module.yml 
    4448# 
  • plugins/sfEasyCommentsPlugin/trunk/test/fixtures/project/cache

    • Property svn:ignore set to
      *
  • plugins/sfEasyCommentsPlugin/trunk/test/fixtures/project/config/ProjectConfiguration.class.php

    r15888 r15970  
    1313  public function setup() 
    1414  { 
    15     $this->setPlugins(array('sfEasyCommentsPlugin')); 
     15    $this->setPlugins(array('sfDoctrinePlugin', 'sfDynamicsPlugin', 'sfEasyCommentsPlugin')); 
    1616    $this->setPluginPath('sfEasyCommentsPlugin', dirname(__FILE__).'/../../../..'); 
     17    $this->setPluginPath('sfDynamicsPlugin', realpath(dirname(__FILE__).'/../../../../../sfDynamicsPlugin')); 
    1718  } 
    1819} 
  • plugins/sfEasyCommentsPlugin/trunk/test/fixtures/project/config/databases.yml

    r15888 r15970  
    1 dev: 
    2   propel: 
     1all: 
     2  doctrine: 
     3    class: sfDoctrineDatabase 
    34    param: 
    4       classname:  DebugPDO 
     5      dsn: 'sqlite:///<?php echo dirname(__FILE__); ?>/doctrine.db' 
    56 
    6 test: 
    7   propel: 
    8     param: 
    9       classname:  DebugPDO 
    10  
    11 all: 
    12   propel: 
    13     class:        sfPropelDatabase 
    14     param: 
    15       classname:  PropelPDO 
    16       dsn:        mysql:dbname=##PROJECT_NAME##;host=localhost 
    17       username:   root 
    18       password:    
    19       encoding:   utf8 
    20       persistent: true 
    21       pooling:    true 
  • plugins/sfEasyCommentsPlugin/trunk/test/functional/sfEasyCommentsActionsTest.php

    r15896 r15970  
    44 
    55$browser = new sfTestFunctional(new sfBrowser()); 
     6$test = $browser->test(); 
     7 
     8$formData = new testFormData(); 
     9 
     10$browser 
     11  ->get('/example') 
     12  ->with('response')->begin() 
     13    ->isStatusCode(200) 
     14    ->checkElement('div.sfEasyCommentsFormContainer form.sfEasyCommentsForm', true) 
     15  ->end() 
     16 
     17  ->setField('comment[author_name]', $formData->getAuthorName()) 
     18  ->setField('comment[author_email]', $formData->getAuthorEmail()) 
     19  ->setField('comment[author_website]', $formData->getAuthorWebsite()) 
     20  ->setField('comment[body]', $formData->getBody()) 
     21 
     22  ->click('Post!') 
     23; 
     24 
     25$newItem = Doctrine::getTable('sfEasyCommentsItem')->createQuery('i')->orderBy('i.created_at desc')->fetchOne(); 
     26 
     27$test->is($newItem['author_name'], $formData->getAuthorName(), 'newly inserted item contains author name.'); 
     28$test->is($newItem['author_email'], $formData->getAuthorEmail(), 'newly inserted item contains author email.'); 
     29$test->is($newItem['author_website'], $formData->getAuthorWebsite(), 'newly inserted item contains author website.'); 
     30$test->is($newItem['body'], $formData->getBody(), 'newly inserted item contains comment body.'); 
     31 
     32$placeholder = $newItem['Placeholder']; 
     33$itemCount = count($placeholder['Items']); 
     34 
     35$browser 
     36  ->with('response')->begin() 
     37    ->isStatusCode(200) 
     38    ->checkElement('div.sfEasyCommentsFormContainer form.sfEasyCommentsForm', false) 
     39    ->checkElement('ul.sfEasyCommentsItemList li', $itemCount) 
     40  ->end() 
     41; 
     42 
     43class testFormData 
     44{ 
     45  protected 
     46    $author_name, 
     47    $author_email, 
     48    $author_website, 
     49    $body; 
     50 
     51  public function __construct() 
     52  { 
     53    $this->author_name    = $this->generateRandomString(rand(10, 20)); 
     54    $this->author_email   = $this->generateRandomString(rand(5, 10)).'@example.com'; 
     55    $this->author_website = 'http://'.$this->generateRandomString(rand(5, 10)).'.example.com/'; 
     56 
     57    $this->body = ''; 
     58    for($words=rand(10,20),$i=0; $i<$words; $i++) 
     59    { 
     60      $this->body .= (isset($this->body[0])?' ':'').$this->generateRandomString(rand(2, 15)); 
     61    } 
     62  } 
     63 
     64  public function getAuthorName() 
     65  { 
     66    return $this->author_name; 
     67  } 
     68 
     69  public function getAuthorEmail() 
     70  { 
     71    return $this->author_email; 
     72  } 
     73 
     74  public function getAuthorWebsite() 
     75  { 
     76    return $this->author_website; 
     77  } 
     78 
     79  public function getBody() 
     80  { 
     81    return $this->body; 
     82  } 
     83 
     84  protected function generateRandomString($length) 
     85  { 
     86    $str = ''; 
     87 
     88    for ($i=0; $i<$length; $i++) 
     89    { 
     90      $str .= chr(ord('a')+rand(0,25)); 
     91    } 
     92 
     93    return $str; 
     94  } 
     95}