123 lines
		
	
	
		
			3.1 KiB
		
	
	
	
		
			HTML
		
	
	
		
		
			
		
	
	
			123 lines
		
	
	
		
			3.1 KiB
		
	
	
	
		
			HTML
		
	
	
| 
								 | 
							
								<!DOCTYPE html>
							 | 
						||
| 
								 | 
							
								<html>
							 | 
						||
| 
								 | 
							
								<head>
							 | 
						||
| 
								 | 
							
								<title>Unit tests for the Wordcount plugin</title>
							 | 
						||
| 
								 | 
							
								<meta http-equiv="X-UA-Compatible" content="IE=edge" />
							 | 
						||
| 
								 | 
							
								<link rel="stylesheet" href="http://code.jquery.com/qunit/qunit-git.css" type="text/css" />
							 | 
						||
| 
								 | 
							
								<script src="http://code.jquery.com/qunit/qunit-git.js"></script>
							 | 
						||
| 
								 | 
							
								<script src="js/qunit/reporter.js"></script>
							 | 
						||
| 
								 | 
							
								<script src="js/utils.js"></script>
							 | 
						||
| 
								 | 
							
								<script src="js/tinymce_loader.js"></script>
							 | 
						||
| 
								 | 
							
								</head>
							 | 
						||
| 
								 | 
							
								<body>
							 | 
						||
| 
								 | 
							
								<script>
							 | 
						||
| 
								 | 
							
								var editor;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								QUnit.config.reorder = false;
							 | 
						||
| 
								 | 
							
								QUnit.config.autostart = false;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								module("tinymce.plugins.Wordcount", { 
							 | 
						||
| 
								 | 
							
									autostart: false
							 | 
						||
| 
								 | 
							
								});
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								test("Blank document has 0 words", function() {
							 | 
						||
| 
								 | 
							
									expect(1);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
									editor.setContent('');
							 | 
						||
| 
								 | 
							
									var result = editor.plugins.wordcount.getCount();
							 | 
						||
| 
								 | 
							
									equal(result, 0);
							 | 
						||
| 
								 | 
							
								});
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								test("Simple word count", function() {
							 | 
						||
| 
								 | 
							
									expect(1);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
									editor.setContent('<p>My sentence is this.</p>');
							 | 
						||
| 
								 | 
							
									var result = editor.plugins.wordcount.getCount();
							 | 
						||
| 
								 | 
							
									equal(result, 4);
							 | 
						||
| 
								 | 
							
								});
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								test("Does not count dashes", function() {
							 | 
						||
| 
								 | 
							
									expect(1);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
									editor.setContent('<p>Something -- ok</p>');
							 | 
						||
| 
								 | 
							
									var result = editor.plugins.wordcount.getCount();
							 | 
						||
| 
								 | 
							
									equal(result, 2);
							 | 
						||
| 
								 | 
							
								});
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								test("Does not count asterisks, non-word characters", function() {
							 | 
						||
| 
								 | 
							
									expect(1);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
									editor.setContent('<p>* something\n· something else</p>');
							 | 
						||
| 
								 | 
							
									var result = editor.plugins.wordcount.getCount();
							 | 
						||
| 
								 | 
							
									equal(result, 3);
							 | 
						||
| 
								 | 
							
								});
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								test("Does not count htmlentities", function() {
							 | 
						||
| 
								 | 
							
									expect(1);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
									editor.setContent('<p>It’s my life – don\'t you forget.</p>');
							 | 
						||
| 
								 | 
							
									var result = editor.plugins.wordcount.getCount();
							 | 
						||
| 
								 | 
							
									equal(result, 6);
							 | 
						||
| 
								 | 
							
								});
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								test("Counts hyphenated words as one word", function() {
							 | 
						||
| 
								 | 
							
									expect(1);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
									editor.setContent('<p>Hello some-word here.</p>');
							 | 
						||
| 
								 | 
							
									var result = editor.plugins.wordcount.getCount();
							 | 
						||
| 
								 | 
							
									equal(result, 3);
							 | 
						||
| 
								 | 
							
								});
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								test("Counts words between blocks as two words", function() {
							 | 
						||
| 
								 | 
							
									expect(1);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
									editor.setContent('<p>Hello</p><p>world</p>');
							 | 
						||
| 
								 | 
							
									var result = editor.plugins.wordcount.getCount();
							 | 
						||
| 
								 | 
							
									equal(result, 2);
							 | 
						||
| 
								 | 
							
								});
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/*
							 | 
						||
| 
								 | 
							
								The blocking functionality in the wordcount plugin prevents this code from
							 | 
						||
| 
								 | 
							
								being tested correctly.
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								I'm of the opinion that the blocking code isn't really doing 
							 | 
						||
| 
								 | 
							
								anything crucial, and should be ripped out, so this module can be tested.
							 | 
						||
| 
								 | 
							
								---------
							 | 
						||
| 
								 | 
							
								test("should set the word count in the target html element", function() {
							 | 
						||
| 
								 | 
							
									expect(1);
							 | 
						||
| 
								 | 
							
									editor.setContent('<p>Hey, it\'s me!</p>');
							 | 
						||
| 
								 | 
							
									equal(parseInt(document.getElementById('elm1-word-count').innerHTML), 3);
							 | 
						||
| 
								 | 
							
								});
							 | 
						||
| 
								 | 
							
								*/
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								tinymce.init({
							 | 
						||
| 
								 | 
							
									mode : "exact",
							 | 
						||
| 
								 | 
							
									elements : "elm1",
							 | 
						||
| 
								 | 
							
									add_unload_trigger : false,
							 | 
						||
| 
								 | 
							
									wordcount_target_id: 'current-count',
							 | 
						||
| 
								 | 
							
									plugins : 'wordcount',
							 | 
						||
| 
								 | 
							
									init_instance_callback : function(ed) {
							 | 
						||
| 
								 | 
							
										editor = ed;
							 | 
						||
| 
								 | 
							
										QUnit.start();
							 | 
						||
| 
								 | 
							
									}
							 | 
						||
| 
								 | 
							
								});
							 | 
						||
| 
								 | 
							
								</script>
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								<h1 id="qunit-header">Unit tests for the Wordcount plugin</h1>
							 | 
						||
| 
								 | 
							
								<h2 id="qunit-banner"></h2>
							 | 
						||
| 
								 | 
							
								<div id="qunit-testrunner-toolbar"></div>
							 | 
						||
| 
								 | 
							
								<h2 id="qunit-userAgent"></h2>
							 | 
						||
| 
								 | 
							
								<ol id="qunit-tests"></ol>
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								<div id="word-count">
							 | 
						||
| 
								 | 
							
									Current Count: <span id="current-count"></span>
							 | 
						||
| 
								 | 
							
								</div>
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								<textarea id="elm1" name="elm1"></textarea>
							 | 
						||
| 
								 | 
							
								<div>
							 | 
						||
| 
								 | 
							
									<a href="javascript:alert(tinymce.EditorManager.get('elm1').getContent({format : 'raw'}));">[getRawContents]</a>
							 | 
						||
| 
								 | 
							
									<a href="javascript:alert(tinymce.EditorManager.get('elm1').getContent());">[getContents]</a>
							 | 
						||
| 
								 | 
							
								</div>
							 | 
						||
| 
								 | 
							
								</body>
							 | 
						||
| 
								 | 
							
								</html>
							 |