/[drupal]/contributions/modules/simpletest_automator/simpletest_automator_proctor/simpletest_automator_proctor.js
ViewVC logotype

Diff of /contributions/modules/simpletest_automator/simpletest_automator_proctor/simpletest_automator_proctor.js

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph | View Patch Patch

revision 1.1, Fri Aug 1 04:13:20 2008 UTC revision 1.2, Thu Aug 28 06:41:42 2008 UTC
# Line 1  Line 1 
1  // $Id: simpletest_automator.js,v 1.4 2008/07/10 05:52:59 cwgordon7 Exp $  // $Id: simpletest_automator_proctor.js,v 1.1 2008/08/01 04:13:20 cwgordon7 Exp $
2    
3  /**  /**
4   * Convert clicking on links to $this->clickLink().   * Convert clicking on links to $this->clickLink().
# Line 18  Drupal.behaviors.trapSimpleTestClick = f Line 18  Drupal.behaviors.trapSimpleTestClick = f
18        }        }
19    
20        $('body').css('cursor', 'wait');        $('body').css('cursor', 'wait');
21        simpleTestRecord('// Click the %s link.', {'content': content});        if (simpleTestRecord({'type': 'click_link', 'label': content, 'index': i})) {
22        if (i) {          window.location = $(this).attr('href') + ($(this).attr('href').indexOf('?') == -1 ? '?record=false' : '&record=false');
23          simpleTestRecord('$this->clickLink(t(%s), %d)', {'content': content, 'index': i});          return false;
       }  
       else {  
         simpleTestRecord('$this->clickLink(t(%s))', {'content': content});  
24        }        }
25      });      });
26    });    });
# Line 36  Drupal.behaviors.recordSimpleTestText = Line 33  Drupal.behaviors.recordSimpleTestText =
33    $('body').mouseup(function() {    $('body').mouseup(function() {
34      var selected = window.getSelection ? window.getSelection() : (document.getSelection ? document.getSelection() : (document.selection ? document.selection.createRange().text : ''));      var selected = window.getSelection ? window.getSelection() : (document.getSelection ? document.getSelection() : (document.selection ? document.selection.createRange().text : ''));
35      selected = selected.toString();      selected = selected.toString();
36      if (selected && confirm('Would you like to make sure that this text (' + selected + ') shows up?')) {      if (selected) {
37        simpleTestRecord('$this->assertText(t(%s), t(%s, array(\'%%message\' => %s)))', {'_text': selected, 'message': 'Make sure the %message message shows up.', '_message': selected});        simpleTestRecord({'type': 'assert_text', 'text': selected, 'html': false, 'should_appear': true});
38      }      }
39        return true;
40    });    });
41  }  };
42    
43    /**
44     * Attach the control panel.
45     */
46    Drupal.behaviors.simpleTestControlPanel = function() {
47      $('body').append('<div id="control-panel" class="display-inline" />');
48      $('#control-panel').append('<label class="option"><input type="checkbox" class="form-checkbox" value="control-panel-auto-record" id="edit-control-panel-auto-record" name="control_panel"/> Auto-Record</label>');
49      $('#control-panel').append('<label class="option"><input type="checkbox" class="form-checkbox" value="control-panel-stop-recording" id="edit-control-panel-stop-recording" name="stop_recording"/> Stop</label>');
50      $('#control-panel').css('float', 'left').css('position', 'fixed').css('bottom', '0px').css('right', '0px').css('padding', '3px').css('background', '#ddd');
51      $('#edit-control-panel-stop-recording').change(function() {
52        if ($(this).is(':checked')) {
53          if (confirm(Drupal.t('Are you sure you\'d like to stop recording?'))) {
54            $('body').css('cursor', 'wait');
55            simpleTestRecord({'type': 'end'});
56            document.cookie = 'simpletest_automator=';
57            window.location = Drupal.settings.basePath + 'admin/build/simpletest_automator';
58          }
59        }
60        $(this).removeAttr('checked');
61        return false;
62      });
63    };
64    
65  /**  /**
66   * Record some SimpleTest code to PHP.   * Record some SimpleTest code to PHP.
67   */   */
68  function simpleTestRecord(text, args) {  function simpleTestRecord(args) {
69    args.text = text;    if (args.type != 'end' && !$('#edit-control-panel-auto-record').is(':checked')) {
70    $.ajax({      result = simpleTestConfirm(args);
71        if (result) {
72          args = result;
73        }
74        else {
75          return;
76        }
77      }
78      return $.ajax({
79      'async': false,      'async': false,
80      'cache': false,      'cache': false,
81      'url': Drupal.settings.basePath + 'simpletest_automator/js',      'url': Drupal.settings.basePath + 'simpletest_automator/js',
82      'data': args,      'data': args,
83      'timeout': 30,      'timeout': 30,
84      'error': function() { alert('An error has occurred.'); },      'error': function() {
85      'type': 'POST'        alert('An error has occurred.');
86        },
87        'type': 'POST',
88    });    });
89    }
90    
91    /**
92     * Display the confirm form.
93     */
94    function simpleTestConfirm(args) {
95      switch (args.type) {
96        case 'click_link':
97          if (confirm(Drupal.t('Would you like to record your click?'))) {
98            return args;
99          }
100          break;
101    
102        case 'assert_text':
103          if (confirm(Drupal.t('Would you like to make sure the "!text" text appears?', {'!text': args.text}))) {
104            args.should_appear = !!confirm(Drupal.t('Should this text be appearing? Choose "ok" if it should, or "cancel" if it should not.'));
105            args.html = false;
106            return args;
107          }
108      }
109      return false;
110  }  }

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.2

  ViewVC Help
Powered by ViewVC 1.1.2