[ Index ]
 

Code source de Kupu-1.3.5

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/tests/ -> test_kupueditor.js (source)

   1  /*****************************************************************************
   2   *
   3   * Copyright (c) 2003-2005 Kupu Contributors. All rights reserved.
   4   *
   5   * This software is distributed under the terms of the Kupu
   6   * License. See LICENSE.txt for license text. For a list of Kupu
   7   * Contributors see CREDITS.txt.
   8   *
   9   *****************************************************************************/
  10  
  11  // $Id: test_kupueditor.js 15802 2005-08-09 09:06:11Z duncan $
  12  
  13  function KupuEditorTestCase() {
  14      this.name = 'KupuEditorTestCase';
  15  
  16      this.setUp = function() {
  17          this.editor = new KupuEditor(null, {}, null);
  18      };
  19  
  20      this.testGetNearestParentOfType = function() {
  21          var parser = new DOMParser();
  22          var xmlstring = '<p><a id="outer"><a id="inner"><b><span>some link</span></b> Even more</a></a></p>'
  23          var doc = parser.parseFromString(xmlstring, 'text/xml');
  24          this.assertEquals(Sarissa.serialize(doc).strip(),xmlstring);
  25  
  26          var span = doc.documentElement.firstChild.firstChild.firstChild.firstChild;
  27  
  28          // first test with a non-existing parent; we should get null.
  29          var ret = this.editor.getNearestParentOfType(span, 'br');
  30          this.assertFalse(ret);
  31  
  32          // now test with a real parent; we expect the exact same node.
  33          ret = this.editor.getNearestParentOfType(span, 'a');
  34          var expected = doc.documentElement.firstChild.firstChild;
  35          this.assert(ret === expected);
  36          // assert again that we got the nearest...
  37          this.assertEquals(ret.getAttribute('id'), 'inner');
  38      };
  39  
  40      this.testRemoveNearestParentOfType = function() {
  41          var xmlstring = '<p><a id="outer"><a id="inner"><b><span>some link</span></b> Even more</a></a></p>'
  42          var doc = (new DOMParser()).parseFromString(xmlstring, 'text/xml');
  43          this.assertEquals(Sarissa.serialize(doc).strip(), xmlstring);
  44  
  45          var span = doc.documentElement.firstChild.firstChild.firstChild.firstChild;
  46  
  47          // first try to remove a parent we don't have; we expect the
  48          // xml not to change.
  49          this.editor.removeNearestParentOfType(span, 'br');
  50          this.assertEquals(Sarissa.serialize(doc).strip(), xmlstring);  
  51  
  52          // now remove a real parent; we expect it to be gone in the
  53          // resulting xml.
  54          this.editor.removeNearestParentOfType(span, 'a');
  55          var expected = '<p><a id="outer"><b><span>some link</span></b> Even more</a></p>';
  56          this.assertEquals(Sarissa.serialize(doc).strip(), expected);
  57      };
  58  
  59      this.test_serializeOutputToString = function() {
  60          var doc = Sarissa.getDomDocument();
  61          //var docel = doc.documentElement;
  62          var docel = doc.documentElement ? doc.documentElement : doc;
  63          var html = doc.createElement('html');
  64          docel.appendChild(html);
  65          var head = doc.createElement('head');
  66          html.appendChild(head);
  67          var title = doc.createElement('title');
  68          head.appendChild(title);
  69          var titletext = doc.createTextNode('foo');
  70          title.appendChild(titletext);
  71          var body = doc.createElement('body');
  72          html.appendChild(body);
  73          var sometext1 = doc.createTextNode('foo');
  74          body.appendChild(sometext1);
  75          var br = doc.createElement('br');
  76          body.appendChild(br);
  77          var sometext2 = doc.createTextNode('bar');
  78          body.appendChild(sometext2);
  79          var result_not_replaced = '<html><head><title>foo</title></head><body>foo<br/>bar</body></html>';
  80          this.assertEquals(this.editor._serializeOutputToString(docel),
  81                            result_not_replaced);
  82          var result_replaced = '<html><head><title>foo</title></head><body>foo<br />bar</body></html>';
  83          this.editor.config.compatible_singletons = true;
  84          this.assertEquals(this.editor._serializeOutputToString(docel),
  85                            result_replaced);
  86          var result_strict = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" ' + 
  87            '"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">\n' + 
  88            '<html xmlns="http://www.w3.org/1999/xhtml"><head><title>foo</title></head><body>foo<br />bar</body></html>';
  89          this.editor.config.strict_output = true;
  90          this.assertEquals(this.editor._serializeOutputToString(docel),
  91                            result_strict);
  92      };
  93  
  94      this.testEscapeEntities = function() {
  95          var test = 'r\xe9diger\r\nhello';
  96          var expected = 'r&#233;diger\r\nhello';
  97          this.assertEquals(this.editor.escapeEntities(test), expected);
  98      };
  99  };
 100  
 101  KupuEditorTestCase.prototype = new TestCase;


Généré le : Sun Feb 25 15:30:41 2007 par Balluche grâce à PHPXref 0.7