multiform.test 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. <?php
  2. /**
  3. * @file
  4. *
  5. *
  6. *
  7. * @author Kálmán Hosszu - hosszu.kalman@gmail.com - http://premiumcmsthemes.com http://www.kalman-hosszu.com
  8. */
  9. class MultiformTestCase extends DrupalWebTestCase {
  10. /**
  11. * Info method.
  12. *
  13. * @return array
  14. */
  15. public static function getInfo() {
  16. return array(
  17. 'name' => 'Forms functionality',
  18. 'description' => 'Testing multiform functionality.' ,
  19. 'group' => 'Multiform',
  20. );
  21. }
  22. /**
  23. * Overriden setUp function.
  24. */
  25. public function setUp() {
  26. parent::setUp('multiform', 'multiform_test');
  27. }
  28. /**
  29. * Check various submit ops.
  30. */
  31. public function testSubmitHandling() {
  32. // Go to the form page.
  33. $this->drupalGet('multiform-test/1');
  34. // Check buttons.
  35. $this->assertFieldByName('op', 'save');
  36. $this->assertFieldByName('op', 'delete');
  37. // No more buttons.
  38. $submitButtons = $this->xpath('//input[@type="submit" and @name!="op"]');
  39. $this->assertEqual(count($submitButtons), 0, t('No more submit button.'));
  40. // Save button.
  41. $this->drupalPost(NULL, array(), 'save');
  42. $this->assertText('multiform_test1_1multiform_test1_submit_button', t('First form save message is found.'));
  43. $this->assertText('multiform_test1_2multiform_test1_submit_button', t('Second form save message is found.'));
  44. // Delete button.
  45. $this->drupalPost(NULL, array(), 'delete');
  46. $this->assertText('multiform_test1_1multiform_test1_delete_button', t('First form delete message is found.'));
  47. $this->assertText('multiform_test1_2multiform_test1_delete_button', t('Second form delete message is found.'));
  48. }
  49. /**
  50. * Check the merged fields exist.
  51. */
  52. public function testFieldsAreExist() {
  53. // Go to the form page.
  54. $this->drupalGet('multiform-test/2');
  55. // Check textfields.
  56. $this->assertFieldByName('multiform[multiform_test2_1_0][required_text_1]');
  57. $this->assertFieldByName('multiform[multiform_test2_2_1][required_text_2]');
  58. // Check button.
  59. $this->assertFieldByName('op', 'save');
  60. }
  61. /**
  62. * Check required fields.
  63. */
  64. public function testRequiredFields() {
  65. $first_text = array('multiform[multiform_test2_1_0][required_text_1]' => 'test1 value');
  66. $second_text = array('multiform[multiform_test2_2_1][required_text_2]' => 'test2 value');
  67. // No required fields.
  68. $this->drupalPost('multiform-test/2', array(), 'save');
  69. $this->assertText('test1 field is required.');
  70. $this->assertText('test2 field is required.');
  71. $this->assertNoText('multiform_test2_1multiform_test2_submit_button');
  72. $this->assertNoText('multiform_test2_2multiform_test2_submit_button');
  73. // Send all required fields.
  74. $this->drupalPost(NULL, array_merge($first_text, $second_text), 'save');
  75. $this->assertText('multiform_test2_1multiform_test2_submit_button');
  76. $this->assertText('multiform_test2_2multiform_test2_submit_button');
  77. $this->assertNoText('test1 field is required.');
  78. $this->assertNoText('test2 field is required.');
  79. // Send first form's required field.
  80. $this->drupalPost(NULL, $first_text, 'save');
  81. $this->assertNoText('multiform_test2_1multiform_test2_submit_button');
  82. $this->assertText('test2 field is required.');
  83. // Send second form's required field.
  84. $this->drupalPost(NULL, $second_text, 'save');
  85. $this->assertNoText('multiform_test2_2multiform_test2_submit_button');
  86. $this->assertText('test1 field is required.');
  87. }
  88. }