Ejemplo n.º 1
0
 public function testToStringNoAlias()
 {
     $display = new Display();
     $expected = 'product';
     $display->setField('product');
     $this->assertSame($expected, $display->toString());
 }
Ejemplo n.º 2
0
 public function testCheckPass()
 {
     $supplied = array('product-id');
     $display = new Display();
     $display->setField('product')->setAlias('id');
     $expected = array($display);
     $requirements = array('fields' => array('product'));
     $actual = DisplayType::check($supplied, $requirements);
     // Compare actual and existing params
     $this->assertInternalType('array', $actual);
     $this->assertInstanceOf(get_class($display), $actual[0]);
     $this->assertEquals($expected, $actual);
 }
Ejemplo n.º 3
0
 /**
  * Checks if the value is of a given type and
  * that the value passes requirements specified.
  *
  * @param   mixed   $value          Value to be checked
  * @param   array   $requirements   Additional constraints
  * @return  array   Cleared value
  * @throws  InvalidDataTypeException
  */
 public static function check($value, array $requirements = array())
 {
     if (!isset($requirements['fields'])) {
         $error = 'list of fields to display constraint has not been specified for display';
         throw new InvalidDataTypeException($error);
     }
     if (!is_array($value)) {
         $error = 'value must be a list of fields';
         throw new InvalidDataTypeException($error);
     }
     $displays = array();
     // Iterate through the list of fields and check each display
     foreach ($value as $i => $field) {
         // Detect display settings
         if (!is_string($field)) {
             $error = 'value for index ' . $i . ' must be a string in format of' . ' {field}-{alias}';
             throw new InvalidDataValueException($error);
         }
         $parts = explode('-', $field, 2);
         if (empty($parts[0])) {
             $error = 'value for index ' . $i . ' must contain valid field names';
             throw new InvalidDataValueException($error);
         }
         if (!in_array($parts[0], $requirements['fields'])) {
             $error = 'value for index ' . $i . ' must be one of (' . implode(', ', $requirements['fields']) . ')';
             throw new InvalidDataValueException($error);
         }
         $display = new Display();
         $display->setField($parts[0]);
         if (!empty($parts[1])) {
             $display->setAlias($parts[1]);
         }
         $displays[] = $display;
     }
     return $displays;
 }