Development

Changeset 18579

You must first sign up to be able to contribute.

Changeset 18579

Show
Ignore:
Timestamp:
05/23/09 11:13:24 (4 years ago)
Author:
Mickael.Kurmann
Message:

every unitests pass

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • plugins/sfDoctrineActAsRattablePlugin/branches/developpment_env/test/unit/sfDoctrineActAsRattableTest.php

    r18564 r18579  
    66new sfDatabaseManager($configuration); 
    77 
     8Doctrine::loadModels($configuration->getRootDir() . '/lib/model/doctrine'); 
     9Doctrine::dropDatabases(); 
     10Doctrine::createDatabases(); 
     11Doctrine::createTablesFromModels(); 
    812Doctrine::loadData($configuration->getRootDir() . '/data/fixtures'); 
    913 
     
    1418 
    1519 
    16 $t = new lime_test(91, new lime_output_color()); 
     20$t = new lime_test(11, new lime_output_color()); 
     21 
     22$t->diag('test base functions'); 
     23 
     24//$blogCommentTable = Doctrine::getTable('BlogComment'); 
     25//$blogPostTable    = Doctrine::getTable('BlogPost'); 
     26 
     27//$t->is(get_class($blogCommentTable->getWithRateAndUserQuery()), 'Doctrine_Query', 'getWithRateAndUserQuery() we can retrieve a query'); 
     28//$t->is(get_class($blogCommentTable->findAllWithRateAndUser()), 'Doctrine_Collection', 'findAllWithRateAndUser() we can retrieve rates and query same time'); 
     29//$t->is(get_class($blogPostTable->findAllWithRateAndUser()), 'Exception', 'findAllWithRateAndUser() throw an exception if object isnt associated to an User object'); 
     30// 
     31// 
     32//$blogPost = Doctrine::getTable('BlogPost')->findAllWithRates(); 
     33// 
     34//$t->is(get_class($blogPost), 'BlogPostRate', 'findAllWithRates include the right left joint'); 
     35// 
     36//$blogPostArray = Doctrine::getTable('BlogPost')->findAllWithRates(); 
     37// 
     38//$t->ok(in_array('Rate', array_keys($blogPostArray)), 'findAllWithRates work with arrays too'); 
     39//$t->is(get_class($blogComment->getRates()), 'Doctrine_Collection', 'getRates(), we can retrieve rates objects'); 
     40//$t->is($blogComment->getRates(Doctrine::HYDRATE_ARRAY), array(13 => array('id' => 1, 'rate' => 1, 'comment' => 'oui il y a des loutres qui sont comme �a', 'sf_guard_user_id' => 2)), 'getRates(), we can retrieve rates in array'); 
     41 
     42 
     43$t->diag('test configuration function'); 
    1744 
    1845$blogComment = Doctrine::getTable('BlogComment')->findAll()->getFirst(); 
    1946$blogPost    = Doctrine::getTable('BlogPost')->findAll()->getFirst(); 
    2047 
    21 $t->diag('test base functions'); 
    22  
    23 $t->is(get_class($blogComment->getRates()), 'Doctrine_Collection', 'getRates(), we can retrieve rates objects'); 
    24 $t->is($blogComment->getRates(Doctrine::HYDRATE_ARRAY), array(), 'getRates(), we can retrieve rates in array'); 
    25 $t->is($blogComment->getRating(), array('rate' => '3'), 'getRating(), we can retrieve global rating'); 
    26  
    27 $t->diag('test configuration function'); 
    28  
    29 $t->is($blogComment->getRating(), array('rate' => '3'), 'getRating(), rating is rounded according to configuration'); 
     48$t->is($blogComment->getRating(), array('rate' => '3'), 'getRating(), we can retrieve global rating rounded according to configuration'); 
    3049$t->is($blogPost->getRating(), array('relevance' => 3, 'interest' => 5.5, 'spelling' => 7.5), 'getRating(), rating is rounded according to configuration'); 
    3150 
    32 $t->is($blogComment->getRateCount(), 4 ,'we can get how many times the object has been rated'); 
     51$t->is($blogComment->getRateCount(), 4 ,'getRateCount() we can get how many times the object has been rated'); 
     52$t->is($blogPost->getRateCount(), 10 ,'getRateCount() we can get how many times the object has been rated'); 
    3353 
    34 $user = Doctrine::getTable('sfGuardUser')->findAll()->getFirst(); 
    35 $array_rate = array('rate' => 2, 'comment' => 'youhouhou', 'sf_guard_user_id' => $user->id); 
     54$array_post_rate = array('relevance' => 1, 'interest' => 1, 'spelling' => 1); 
    3655 
    37 $blogComment->addRate($array_rate); 
    38 $t->is($blogComment->getRateCount(), 5 , 'we can add a rate from an array rate'); 
     56$blogPost->addRate($array_post_rate); 
     57$blogPost->save(); 
     58$t->is($blogPost->getRateCount(), 11 , 'getRateCount() we can add a rate from an array rate'); 
    3959 
    40 $object_rate = new BlogCommentRate(); 
    41 $object_rate->merge($array_rate); 
     60$object_rate = new BlogPostRate(); 
     61$object_rate->merge($array_post_rate); 
    4262 
    43 $blogComment->addRate($object_rate); 
    44 $t->is($blogComment->getRateCount(), 6 , 'we can add a rate from a rate object'); 
     63$blogPost->addRate($object_rate); 
     64$blogPost->save(); 
    4565 
    46 $blogComment->removeRatings(); 
    47 $t->is($blogComment->getRateCount(), 0, 'we can remove all rating for an object'); 
    48 $t->is($blogComment->getRating(), 0, 'if no rating, getRating return 0 default value'); 
    49 $t->is($blogComment->getRates(), false, 'if no rating, getRates, return false'); 
     66$t->is($blogPost->getRateCount(), 12 , 'addRate() we can add a rate from a rate object'); 
    5067 
    51 $blogCommentRate = $blogComment->Rate->getFirst(); 
     68$blogPost->removeRatings(); 
     69$t->is($blogPost->getRateCount(), 0, 'getRateCount() we can remove all rating for an object'); 
     70$t->is($blogPost->getRating(), array('relevance' => 0, 'interest' => 0, 'spelling' => 0), 'getRating() if no rating, getRating return 0 default value'); 
     71//$t->is($blogComment->getRates(), false, 'if no rating, getRates, return false'); 
     72 
     73$blogCommentRate = $blogComment->getRates()->getFirst(); 
    5274 
    5375// si avec user 
     
    5981 
    6082// on peut pas voter deux fois avec le meme user 
     83$user = Doctrine::getTable('sfGuardUser')->findAll()->getFirst(); 
     84$array_comment_rate = array('rate' => 2, 'comment' => 'youhouhou', 'sf_guard_user_id' => $user->id); 
    6185 
    62 // si sans user 
    63 // on peut pas avoir son nom 
     86try 
     87
     88  $blogComment->addRate($array_comment_rate); 
     89  $blogComment->addRate($array_comment_rate); 
     90  $blogComment->save(); 
     91  $t->fail('no code should be executed after throwing an exception'); 
     92
     93catch (Exception $e) 
     94
     95  $t->pass('user can only vote once'); 
     96
    6497