Development

Changeset 6685

You must first sign up to be able to contribute.

Changeset 6685

Show
Ignore:
Timestamp:
12/23/07 22:05:32 (1 year ago)
Author:
Carl.Vondrick
Message:

full unit test coverage for results package

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • plugins/sfLucenePlugin/branches/1.1/lib/results/sfLuceneModelResult.class.php

    r6581 r6685  
    2424    $model = $this->retrieveModel(); 
    2525 
    26     if (is_string($model->get('title'))) 
     26    if ($model->has('title')) 
    2727    { 
    28       $getter = 'get' . $model->get('title'); 
    29       return $this->$getter(); 
     28      return $this->result->getDocument()->getFieldValue($model->get('title')); 
    3029    } 
    3130    else 
     
    3534        if ($model->get('fields')->has($check)) 
    3635        { 
    37           $getter = 'get' . $check; 
    38  
    39           return $this->$getter(); 
     36          return strip_tags($this->result->getDocument()->getFieldValue($check)); 
    4037        } 
    4138      } 
    4239    } 
    4340 
    44     return $this->getInternalModel()
     41    return 'No title available.'
    4542  } 
    4643 
     
    5451    if (!$model->has('route')) 
    5552    { 
    56       throw new sfLuceneIndexerException(sprintf('A route for model "%s" was not defined in the search.yml file.  Did you define one for this application?', $this->getInternalModel())); 
     53      throw new sfLuceneIndexerException(sprintf('A route for model "%s" was not defined in the search.yml file.', $this->getInternalModel())); 
    5754    } 
    5855 
    59     return preg_replace_callback('/%(\w+)%/', array($this, 'internalUriCallback'), $model->get('route')); 
     56    return preg_replace_callback('/%(\w+?)%/', array($this, 'internalUriCallback'), $model->get('route')); 
    6057  } 
    6158 
     
    6562  protected function internalUriCallback($matches) 
    6663  { 
    67     $getter = 'get' . $matches[1]; 
    68  
    69     return $this->$getter(); 
     64    return $this->result->getDocument()->getFieldValue($matches[1]); 
    7065  } 
    7166 
     
    8984    $model = $this->retrieveModel(); 
    9085 
    91     if (is_string($model->get('description'))) 
     86    if ($model->has('description')) 
    9287    { 
    93       $getter = 'get' . $model->get('description'); 
    94       return strip_tags($this->$getter()); 
     88      return strip_tags($this->result->getDocument()->getFieldValue($model->get('description'))); 
    9589    } 
    9690 
     
    9993      if ($model->get('fields')->has($check)) 
    10094      { 
    101         $getter = 'get' . $check; 
    102         return strip_tags($this->$getter()); 
     95        return strip_tags($this->result->getDocument()->getFieldValue($check)); 
    10396      } 
    10497    } 
    10598 
    106     return parent::getInternalDescription()
     99    return 'No description available.'
    107100  } 
    108101 
  • plugins/sfLucenePlugin/branches/1.1/lib/results/sfLuceneResult.class.php

    r6652 r6685  
    3030  } 
    3131 
    32   protected function getSearch() 
     32  public function getSearch() 
    3333  { 
    3434    return $this->search; 
     35  } 
     36 
     37  public function getResult() 
     38  { 
     39    return $this->result; 
    3540  } 
    3641 
     
    4651  * Gets the partial 
    4752  */ 
    48   public function getInternalPartial(
     53  public function getInternalPartial($module = 'sfLucene'
    4954  { 
    50     return 'sfLucene/' . $this->getInternalType() . 'Result'; 
     55    return $module . '/' . $this->getInternalType() . 'Result'; 
    5156  } 
    5257 
     
    5560    try 
    5661    { 
    57       return strip_tags($this->sfl_description); 
     62      return strip_tags($this->result->getDocument()->getFieldValue('sfl_description')); 
    5863    } 
    5964    catch (Exception $e) 
    6065    { 
    61       $responses = array('Click for more information', 'No description available', 'Open this item for more information'); 
    62  
    63       return $responses[array_rand($responses)]; 
     66      return 'No description available.'; 
    6467    } 
    6568  } 
    6669 
    67   /** 
    68   * To be implemented later 
    69   */ 
    70   public function valid() 
     70  public function getInternalTitle() 
    7171  { 
    72     return true; 
     72    try 
     73    { 
     74      return $this->result->getDocument()->getFieldValue('sfl_title'); 
     75    } 
     76    catch (Exception $e) 
     77    { 
     78      return 'No title available.'; 
     79    } 
    7380  } 
    7481 
     
    7885  static public function getInstance($result, $search) 
    7986  { 
    80     switch ($result->sfl_type
     87    switch ($result->getDocument()->getFieldValue('sfl_type')
    8188    { 
    8289      case 'action': 
     
    116123    } 
    117124 
    118     $call = array($this->results, $method); 
    119  
    120     if (is_callable($call)) 
     125    $event = $this->getSearch()->getContext()->getEventDispatcher()->notifyUntil(new sfEvent($this, 'lucene.result.method_not_found', array('method' => $method, 'arguments' => $args))); 
     126    if (!$event->isProcessed()) 
    121127    { 
    122       return call_user_func_array($call, $args); 
     128      throw new sfException(sprintf('Call to undefined method %s::%s.', __CLASS__, $method)); 
    123129    } 
    124130 
    125     return sfMixer::callMixins(); 
     131    return $event->getReturnValue(); 
    126132  } 
    127133 
     
    141147    return $property; 
    142148  } 
    143  
    144   /** 
    145   * Wrapper for lucene's __get() 
    146   */ 
    147   public function __get($property) 
    148   { 
    149     return $this->result->$property; 
    150   } 
    151149} 
  • plugins/sfLucenePlugin/branches/1.1/lib/results/sfLuceneResults.class.php

    r6298 r6685  
    100100  public function offsetGet($offset) 
    101101  { 
    102     return $this->results[$offset]
     102    return $this->getInstance($this->results[$offset])
    103103  } 
    104104 
  • plugins/sfLucenePlugin/branches/1.1/test/data/config/search.yml

    r6678 r6685  
    1919      rebuild_limit: 5 
    2020      peer: FakeForumPeer 
    21       partial: modelResult 
     21      partial: forumResult 
    2222  index: 
    2323    encoding: UTF-8 
  • plugins/sfLucenePlugin/branches/1.1/test/unit/sfLuceneTest.php

    r6679 r6685  
    128128$t->is($m->get('peer'), 'FakeForumPeer', 'model property "peer" is the correct peer'); 
    129129$t->is($m->get('rebuild_limit'), 5, 'model property "rebuild_limit" is the correct rebuild limit'); 
    130 $t->is($m->get('partial'), 'modelResult', 'model property "partial" is the correct partial'); 
     130$t->is($m->get('partial'), 'forumResult', 'model property "partial" is the correct partial'); 
    131131 
    132132$f = $m->get('fields');