示例#1
0
 public function test_for_form_tag_helpers()
 {
     $Controller = new MockAkActionController($this);
     $Controller->setReturnValue('urlFor', '/url/for/test');
     $form_tag = new FormTagHelper();
     $form_tag->setController($Controller);
     $this->assertEqual($form_tag->form_tag(), '<form action="/url/for/test" method="post">');
     $this->assertEqual($form_tag->form_tag(array(), array('method' => 'get')), '<form action="/url/for/test" method="get">');
     $this->assertEqual($form_tag->form_tag(array(), array('multipart' => true)), '<form action="/url/for/test" enctype="multipart/form-data" method="post">');
     $this->assertEqual($form_tag->end_form_tag(), '</form>');
     $this->assertEqual($form_tag->start_form_tag(), '<form action="/url/for/test" method="post">');
     $this->assertEqual($form_tag->select_tag('person', '<option>Bermi</option>', array('id' => 'bermi')), '<select id="bermi" name="person"><option>Bermi</option></select>');
     $this->assertEqual($form_tag->text_field_tag('person', 'Bermi', array('id' => 'bermi')), '<input id="bermi" name="person" type="text" value="Bermi" />');
     $this->assertEqual($form_tag->text_field_tag('person[1][name]', 'Bermi'), '<input id="person_1_name" name="person[1][name]" type="text" value="Bermi" />');
     $this->assertEqual($form_tag->hidden_field_tag('person', 'Bermi', array('id' => 'bermi')), '<input id="bermi" name="person" type="hidden" value="Bermi" />');
     $this->assertEqual($form_tag->file_field_tag('photo', array('id' => 'pick_photo')), '<input id="pick_photo" name="photo" type="file" />');
     $this->assertEqual($form_tag->password_field_tag('password', '', array('id' => 'pass')), '<input id="pass" name="password" type="password" value="" />');
     $this->assertEqual($form_tag->text_area_tag('address', 'My address', array('id' => 'address_box')), '<textarea id="address_box" name="address">My address</textarea>');
     $this->assertEqual($form_tag->check_box_tag('subscribe', 'subscribed', true), '<input checked="checked" id="subscribe" name="subscribe" type="checkbox" value="subscribed" />');
     $this->assertEqual($form_tag->radio_button_tag('subscribe', 'subscribed', true), '<input checked="checked" id="subscribe" name="subscribe" type="radio" value="subscribed" />');
     $this->assertEqual($form_tag->submit_tag(), '<input name="commit" type="submit" value="Save changes" />');
     $this->assertEqual($form_tag->submit_tag('Commit changes', array('disable_with' => "Wait'Please")), '<input name="commit" onclick="this.disabled=true;this.value=\'Wait\\\'Please\';this.form.submit();" type="submit" value="Commit changes" />');
     /**
      * @todo TEST FOR image_submit_tag($source, $options = array())
      */
 }
示例#2
0
 public function test_for_form_helpers()
 {
     $controller = new MockAkActionController($this);
     $controller->setReturnValue('urlFor', '/url/for/test');
     $form_tag_helper = new FormTagHelper();
     $controller->returnsByValue('__get', $form_tag_helper, array('ak_form_tag_helper'));
     $form_tag_helper->setController($controller);
     $person = new MockAkActiveRecord($this);
     $person->setReturnValue('get', 'Bermi', array('name'));
     $task = new MockAkActiveRecord($this);
     $task->setReturnValue('get', 'Do the testing');
     $form_helper = new FormHelper(array('person' => &$person));
     $form_helper->setController($controller);
     $this->assertReference($form_helper->getObject('person'), $person);
     ob_start();
     $f = $form_helper->form_for('person', $person, array('url' => array('action' => 'update')));
     $form_opening_markup = ob_get_clean();
     $this->assertTrue(strstr($form_opening_markup, '<form action="/url/for/test" method="post">'), 'Form open tag not found');
     $this->assertTrue(strstr($form_opening_markup, '<div style="margin:0;padding:0;display:inline"><input name="authenticity_token" type="hidden" value='), 'Form authenticity_token tag not found');
     $this->assertTrue(strstr($form_opening_markup, '<div style="margin:0;padding:0;display:inline"><input name="_method" type="hidden" value="put" /></div>'), 'Form PUT method tag not found');
     $this->assertEqual($form_helper->text_field('task', 'description'), '<input id="task_description" name="task[description]" size="30" type="text" />');
     $this->assertEqual($form_helper->text_field('task', 'description', array('object' => &$task)), '<input id="task_description" name="task[description]" size="30" type="text" value="Do the testing" />');
     $this->assertEqual($f->text_field('person', 'name'), '<input id="person_name" name="person[name]" size="30" type="text" value="Bermi" />');
     $person->setReturnValue('get', 'Alicia', array('first_name'));
     $this->assertEqual($f->text_field('person', 'first_name', array('size' => 80)), '<input id="person_first_name" name="person[first_name]" size="80" type="text" value="Alicia" />');
     $this->assertEqual($form_helper->password_field('person', 'password'), '<input id="person_password" name="person[password]" size="30" type="password" />');
     $this->assertEqual($form_helper->file_field('person', 'photo'), '<input id="person_photo" name="person[photo]" size="30" type="file" />');
     $this->assertEqual($form_helper->hidden_field('person', 'referer'), '<input id="person_referer" name="person[referer]" type="hidden" />');
     $this->assertEqual($form_helper->text_area('person', 'notes'), '<textarea cols="40" id="person_notes" name="person[notes]" rows="20"></textarea>');
     $this->assertEqual($form_helper->text_field('person', 'name'), '<input id="person_name" name="person[name]" size="30" type="text" />');
     $person->setReturnValue('get', '1234', array('password'));
     $person->setReturnValue('get', 'no_value_on_file_types', array('photo'));
     $person->setReturnValue('get', 'http://www.example.com', array('referer'));
     $person->setReturnValue('get', 'Check this "NOTES"', array('notes'));
     $this->assertEqual($f->password_field('person', 'password'), '<input id="person_password" name="person[password]" size="30" type="password" value="1234" />');
     $this->assertEqual($f->file_field('person', 'photo'), '<input id="person_photo" name="person[photo]" size="30" type="file" />');
     $this->assertEqual($f->hidden_field('person', 'referer'), '<input id="person_referer" name="person[referer]" type="hidden" value="http://www.example.com" />');
     $this->assertEqual($f->text_area('person', 'notes'), '<textarea cols="40" id="person_notes" name="person[notes]" rows="20">Check this &quot;NOTES&quot;</textarea>');
     $this->assertEqual($f->text_field('person', 'name'), '<input id="person_name" name="person[name]" size="30" type="text" value="Bermi" />');
     $person->setReturnValue('get', 1, array('validate'));
     $this->assertEqual($f->check_box("post", "validate"), '<input name="post[validate]" type="hidden" value="0" />' . '<input checked="checked" id="post_validate" name="post[validate]" type="checkbox" value="1" />');
     $this->assertEqual($f->radio_button('post', 'validate', 'si'), '<input id="post_validate_si" name="post[validate]" type="radio" value="si" />');
     $this->assertEqual($f->radio_button('post', 'validate', '1'), '<input checked="checked" id="post_validate_1" name="post[validate]" type="radio" value="1" />');
 }
示例#3
0
 public function test_javascript_for_current_controller()
 {
     $controller = new MockAkActionController($this);
     $controller->asset_host = AK_ASSET_HOST;
     $controller->setReturnValue('urlFor', '/url/for/test');
     $asset_tag_helper = new AssetTagHelper();
     $asset_tag_helper->setController($controller);
     $controller->setReturnValue('getControllerName', 'valid_controller');
     $controller->setReturnValue('urlFor', '/url/for/test');
     $this->assertEqual($asset_tag_helper->javascript_for_current_controller(), '<script src="' . $this->testing_url_path . '/javascripts/valid_controller.js" type="text/javascript"></script>' . "\n");
     $controller = new MockAkActionController($this);
     $controller->asset_host = AK_ASSET_HOST;
     $controller->setReturnValue('urlFor', '/url/for/test');
     $asset_tag_helper = new AssetTagHelper();
     $asset_tag_helper->setController($controller);
     $controller->setReturnValue('getControllerName', 'non_valid_controller');
     $controller->setReturnValue('urlFor', '/url/for/test');
     $this->assertEqual($asset_tag_helper->javascript_for_current_controller(), '');
 }