public function testAuthor()
 {
     $queried = array(2, 4);
     $request = new HttpRequest(array('a' => array(2, 4)));
     $users = array();
     $users[] = $this->factory->user->create_and_get(array('display_name' => 'Sean', 'role' => 'administrator'));
     // id=2
     $users[] = $this->factory->user->create_and_get(array('display_name' => 'Dave', 'role' => 'editor'));
     // id=3
     $users[] = $this->factory->user->create_and_get(array('display_name' => 'Alex', 'role' => 'author'));
     // id=4
     $users[] = $this->factory->user->create_and_get(array('display_name' => 'Jim', 'role' => 'subscriber'));
     // id=5
     $users[] = $this->factory->user->create_and_get(array('display_name' => 'Rob', 'role' => 'contributor'));
     // id=6
     $values = array();
     foreach ($users as $user) {
         $values[] = $user->user_id;
     }
     $args = array('field_type' => 'author', 'format' => 'checkbox', 'values' => $values);
     $input = InputBuilder::make('a', FieldType::author, $args, $request);
     $values = $input->getValues();
     $selected = $input->getSelected();
     $this->assertTrue(count($values) == 5);
     // 5 authors including "admin"
     $this->assertFalse(isset($values[5]));
     // User 'Jim' should not be included
     $this->assertTrue(count($selected) == 2);
     $this->assertContains(2, $selected);
     $this->assertContains(4, $selected);
 }
예제 #2
0
 /**
  * Given a Field object, initializes that field's input(s) to Input objects
  * and adds them to the inputs table
  *
  * @param Field $field
  * @param $request
  */
 private function addInputs(Field $field, $request)
 {
     $field_type = $field->getFieldType();
     $inputs = $field->getInputs();
     foreach ($inputs as $name => $input_args) {
         try {
             if ($field_type == FieldType::date) {
                 $date_type = !empty($input_args['date_type']) ? $input_args['date_type'] : false;
                 $post_types = $this->selectedPostTypes($request);
                 $name = RequestVar::nameToVar($name, $field_type, $date_type);
                 $input = DateInputBuilder::make($name, $input_args, $post_types, $request);
             } else {
                 if ($field_type == FieldType::generic) {
                     $name = empty($input_args['id']) ? 'generic' : $input_args['id'];
                 } else {
                     $name = RequestVar::nameToVar($name, $field_type);
                 }
                 $input = InputBuilder::make($name, $field_type, $input_args, $request);
             }
             $this->inputs[] = $input;
         } catch (\InvalidArgumentException $e) {
             $this->addExceptionError($e);
             continue;
         } catch (\Exception $e) {
             $this->addExceptionError($e);
             continue;
         }
     }
 }