Module part just created a menu page with some "Hello World" text.
Test should check:
- If drupal slice generated by SimpleText exists
- If menu page exists
- If menu page has a string "Lets test it!"
Module code:
1: <?php
2: 3: function alternative_example_menu() { 4: $items['alt_example'] = array( 5: 'title' => 'Hello World test example', 6: 'description' => 'Its easy and fun', 7: 'page callback' => '_alt_example_basic_instructions', 8: 'page arguments' => array(t('Hello World')), 9: 'access callback' => TRUE, 10: 'type' => MENU_NORMAL_ITEM, 11: ); 12: return $items; 13: } 14: 15: function _alt_example_basic_instructions($content = NULL) { 16: $base_content = t('Lets test it!'); 17: return '<div>' . $base_content . '</div><br />'; 18: }
Test code:
1: <?php
2: 3: /** 4: * @file 5: * Tests for alternative example module. 6: */ 7: class AlternativeExampleTestCase extends DrupalWebTestCase { 8: protected $custom_user; 9: 10: public static function getInfo() { 11: return array( 12: 'name' => 'Hello world example functionality', 13: 'description' => 'Checks "Hello world" string and page', 14: 'group' => 'Alternative Examples', 15: ); 16: } 17: 18: /** 19: * Enable modules and create user with specific permissions. 20: */ 21: public function setUp() { 22: parent::setUp('alternative_example'); 23: } 24: function testAlternativeHelloExample() { 25: // Load site 26: $this->drupalGet(''); 27: // Load page 28: $this->clickLink(t('Hello World test example')); 29: // Look for string 30: $this->assertText(t('Lets test it!')); 31: } 32: }
Web output:
Also there is possible to run SimpleTest through drush:
Nothing enormous. Tests should run faster if they will done like unit tests way but i should check that option next time.



Комментариев нет:
Отправить комментарий