src/cm/media/js/lib/yui/yui_3.10.3/docs/test/test-simple-example.html
changeset 525 89ef5ed3c48b
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/cm/media/js/lib/yui/yui_3.10.3/docs/test/test-simple-example.html	Tue Jul 16 14:29:46 2013 +0200
@@ -0,0 +1,635 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+    <meta charset="utf-8">
+    <title>Example: Simple Testing Example</title>
+    <link rel="stylesheet" href="http://fonts.googleapis.com/css?family=PT+Sans:400,700,400italic,700italic">
+    <link rel="stylesheet" href="../../build/cssgrids/cssgrids-min.css">
+    <link rel="stylesheet" href="../assets/css/main.css">
+    <link rel="stylesheet" href="../assets/vendor/prettify/prettify-min.css">
+    <link rel="shortcut icon" type="image/png" href="../assets/favicon.png">
+    <script src="../../build/yui/yui-min.js"></script>
+    
+</head>
+<body>
+<!--
+<a href="https://github.com/yui/yui3"><img style="position: absolute; top: 0; right: 0; border: 0;" src="https://s3.amazonaws.com/github/ribbons/forkme_right_darkblue_121621.png" alt="Fork me on GitHub"></a>
+-->
+<div id="doc">
+    <div id="hd">
+        <h1><img src="http://yuilibrary.com/img/yui-logo.png"></h1>
+    </div>
+    
+        <a href="#toc" class="jump">Jump to Table of Contents</a>
+    
+
+            <h1>Example: Simple Testing Example</h1>
+    <div class="yui3-g">
+        <div class="yui3-u-3-4">
+            <div id="main">
+                <div class="content"><div class="intro">
+    <p>This example shows basic usage of the YUI Test framework for testing browser-based JavaScript code.
+      Two different <a href="index.html#testcase"><code>TestCase</code></a> objects are created and added to a
+      <a href="index.html#testsuite"><code>TestSuite</code></a> object. The <a href="index.html#testrunner"><code>TestRunner</code></a>
+      is then used to run the tests once the page has loaded.</p>
+</div>
+
+<div class="example yui3-skin-sam">
+    <div id="testLogger"></div>
+
+<script>
+YUI().use('node', 'test-console', 'test', function (Y) {
+
+    Y.namespace("example.test");
+
+    Y.example.test.DataTestCase = new Y.Test.Case({
+
+        //name of the test case - if not provided, one is auto-generated
+        name : "Data Tests",
+
+        //---------------------------------------------------------------------
+        // setUp and tearDown methods - optional
+        //---------------------------------------------------------------------
+
+        /*
+         * Sets up data that is needed by each test.
+         */
+        setUp : function () {
+            this.data = {
+                name: "test",
+                year: 2007,
+                beta: true
+            };
+        },
+
+        /*
+         * Cleans up everything that was created by setUp().
+         */
+        tearDown : function () {
+            delete this.data;
+        },
+
+        //---------------------------------------------------------------------
+        // Test methods - names must begin with "test"
+        //---------------------------------------------------------------------
+
+        testName : function () {
+            var Assert = Y.Assert;
+
+            Assert.isObject(this.data);
+            Assert.isString(this.data.name);
+            Assert.areEqual("test", this.data.name);
+        },
+
+        testYear : function () {
+            var Assert = Y.Assert;
+
+            Assert.isObject(this.data);
+            Assert.isNumber(this.data.year);
+            Assert.areEqual(2007, this.data.year);
+        },
+
+        testBeta : function () {
+            var Assert = Y.Assert;
+
+            Assert.isObject(this.data);
+            Assert.isBoolean(this.data.beta);
+            Assert.isTrue(this.data.beta);
+        }
+
+    });
+
+    Y.example.test.ArrayTestCase = new Y.Test.Case({
+
+        //name of the test case - if not provided, one is auto-generated
+        name : "Array Tests",
+
+        //---------------------------------------------------------------------
+        // setUp and tearDown methods - optional
+        //---------------------------------------------------------------------
+
+        /*
+         * Sets up data that is needed by each test.
+         */
+        setUp : function () {
+            this.data = [0,1,2,3,4]
+        },
+
+        /*
+         * Cleans up everything that was created by setUp().
+         */
+        tearDown : function () {
+            delete this.data;
+        },
+
+        //---------------------------------------------------------------------
+        // Test methods - names must begin with "test"
+        //---------------------------------------------------------------------
+
+        testPop : function () {
+            var Assert = Y.Assert;
+
+            var value = this.data.pop();
+
+            Assert.areEqual(4, this.data.length);
+            Assert.areEqual(4, value);
+        },
+
+        testPush : function () {
+            var Assert = Y.Assert;
+
+            this.data.push(5);
+
+            Assert.areEqual(6, this.data.length);
+            Assert.areEqual(5, this.data[5]);
+        },
+
+        testSplice : function () {
+            var Assert = Y.Assert;
+
+            this.data.splice(2, 1, 6, 7);
+
+            Assert.areEqual(6, this.data.length);
+            Assert.areEqual(6, this.data[2]);
+            Assert.areEqual(7, this.data[3]);
+        }
+
+    });
+
+    Y.example.test.ExampleSuite = new Y.Test.Suite("Example Suite");
+    Y.example.test.ExampleSuite.add(Y.example.test.DataTestCase);
+    Y.example.test.ExampleSuite.add(Y.example.test.ArrayTestCase);
+
+    //create the console
+    (new Y.Test.Console({
+        newestOnTop : false,
+        filters: {
+            pass: true,
+            fail: true
+        }
+    })).render('#testLogger');
+
+    Y.Test.Runner.add(Y.example.test.ExampleSuite);
+
+    //run the tests
+    Y.Test.Runner.run();
+
+});
+</script>
+
+</div>
+
+<h2 class="first" id="simple-test-example">Simple Test Example</h2>
+
+<p>This example begins by creating a namespace:</p>
+<pre class="code prettyprint">Y.namespace(&quot;example.test&quot;);</pre>
+
+<p>This namespace serves as the core object upon which others will be added (to prevent creating global objects).</p>
+
+<h3 id="creating-the-first-testcase">Creating the first TestCase</h3>
+
+<p>The first step is to create a new <code>Y.Test.Case</code> object called <code>DataTestCase</code>.
+  To do so, using the <code>Y.Test.Case</code> constructor and pass in an object literal containing information about the tests to be run:</p>
+<pre class="code prettyprint">Y.example.test.DataTestCase = new Y.Test.Case({
+
+    &#x2F;&#x2F;name of the test case - if not provided, one is auto-generated
+    name : &quot;Data Tests&quot;,
+
+    &#x2F;&#x2F;---------------------------------------------------------------------
+    &#x2F;&#x2F; setUp and tearDown methods - optional
+    &#x2F;&#x2F;---------------------------------------------------------------------
+
+    &#x2F;*
+     * Sets up data that is needed by each test.
+     *&#x2F;
+    setUp : function () {
+        this.data = {
+            name: &quot;test&quot;,
+            year: 2007,
+            beta: true
+        };
+    },
+
+    &#x2F;*
+     * Cleans up everything that was created by setUp().
+     *&#x2F;
+    tearDown : function () {
+        delete this.data;
+    },
+
+    &#x2F;&#x2F;---------------------------------------------------------------------
+    &#x2F;&#x2F; Test methods - names must begin with &quot;test&quot;
+    &#x2F;&#x2F;---------------------------------------------------------------------
+
+    testName : function () {
+        var Assert = Y.Assert;
+
+        Assert.isObject(this.data);
+        Assert.isString(this.data.name);
+        Assert.areEqual(&quot;test&quot;, this.data.name);
+    },
+
+    testYear : function () {
+        var Assert = Y.Assert;
+
+        Assert.isObject(this.data);
+        Assert.isNumber(this.data.year);
+        Assert.areEqual(2007, this.data.year);
+    },
+
+    testBeta : function () {
+        var Assert = Y.Assert;
+
+        Assert.isObject(this.data);
+        Assert.isBoolean(this.data.beta);
+        Assert.isTrue(this.data.beta);
+    }
+
+});</pre>
+
+<p>The object literal passed into the constructor contains a number of different sections. The first section contains the <code>name</code> property,
+  which is used to determine which <code>Y.Test.Case</code> is being executed. A name is necessary, so one is generated if it isn't specified.</p>
+<p>Next, the <code>setUp()</code> and <code>tearDown()</code> methods are included. The <code>setUp()</code> method is used in a <code>Y.Test.Case</code>
+  to set up data that may be needed for tests to be completed. This method is called immediately before each test is executed. For this example,
+  <code>setUp()</code> creates a data object. The <code>tearDown()</code> is responsible for undoing what was done in <code>setUp()</code>. It is
+  run immediately after each test is run and, in this case, deletes the data object that was created by <code>setUp</code>. These methods are optional.</p>
+<p>The last section contains the actual tests to be run. Test method names must always begin with the word &quot;test&quot; (all lowercase) in order
+  to differentiate them from other methods that may be added to the object.</p>
+<p>The first test in this object is <code>testName()</code>, which runs
+  various assertions on <code>data.name</code>. Inside of this method, a shortcut to <code>Y.Assert</code> is set up and used to run three
+  assertions: <code>isObject()</code> on <code>data</code>, <code>isString()</code> on <code>data.name</code> and <code>areEqual()</code> to compare
+  <code>data.name</code> to the expected value, &quot;test&quot;. These assertions are arranged in order from least-specific to most-specific,
+  which is the recommended way to arrange your assertions. Basically, the third assertion is useless to run unless the second has passes and the second
+  can't possibly pass unless the first passed. Both <code>isObject()</code> and <code>isString()</code> accept a single argument, which is the value
+  to test (you could optionally include a failure message as a second argument, though this is not required). The <code>areEqual()</code> method
+  expects two arguments, the first being the expected value (&quot;test&quot;) and the second being the actual value (<code>data.name</code>).</p>
+<p>The second and third tests follow the same pattern as the first with the exception that they work with different data types. The <code>testYear()</code>
+  method works with <code>data.year</code>, which is a number and so runs tests specifically for numbers (<code>areEqual()</code> can be used with
+  all data types). The <code>testBeta()</code> method works with <code>data.beta</code>, which is a Boolean, and so it uses the <code>isTrue()</code>
+  assertion instead of <code>areEqual()</code> (though it could also use <code>areEqual(true, this.data.beta)</code>).</p>
+
+ <h3 id="creating-the-second-testcase">Creating the second TestCase</h3>
+
+ <p>Although it's possible that you'll have only one <code>Y.Test.Case</code> object, typically there is more than one, and so this example includes
+   a second <code>Y.Test.Case</code>. This one tests some of the built-in functions of the <code>Array</code> object:</p>
+<pre class="code prettyprint">Y.example.test.ArrayTestCase = new Y.Test.Case({
+
+    &#x2F;&#x2F;name of the test case - if not provided, one is auto-generated
+    name : &quot;Array Tests&quot;,
+
+    &#x2F;&#x2F;---------------------------------------------------------------------
+    &#x2F;&#x2F; setUp and tearDown methods - optional
+    &#x2F;&#x2F;---------------------------------------------------------------------
+
+    &#x2F;*
+     * Sets up data that is needed by each test.
+     *&#x2F;
+    setUp : function () {
+        this.data = [0,1,2,3,4]
+    },
+
+    &#x2F;*
+     * Cleans up everything that was created by setUp().
+     *&#x2F;
+    tearDown : function () {
+        delete this.data;
+    },
+
+    &#x2F;&#x2F;---------------------------------------------------------------------
+    &#x2F;&#x2F; Test methods - names must begin with &quot;test&quot;
+    &#x2F;&#x2F;---------------------------------------------------------------------
+
+    testPop : function () {
+        var Assert = Y.Assert;
+
+        var value = this.data.pop();
+
+        Assert.areEqual(4, this.data.length);
+        Assert.areEqual(4, value);
+    },
+
+    testPush : function () {
+        var Assert = Y.Assert;
+
+        this.data.push(5);
+
+        Assert.areEqual(6, this.data.length);
+        Assert.areEqual(5, this.data[5]);
+    },
+
+    testSplice : function () {
+        var Assert = Y.Assert;
+
+        this.data.splice(2, 1, 6, 7);
+
+        Assert.areEqual(6, this.data.length);
+        Assert.areEqual(6, this.data[2]);
+        Assert.areEqual(7, this.data[3]);
+    }
+
+});</pre>
+
+ <p>As with the first <code>Y.Test.Case</code>, this one is split up into three sections: the name, the <code>setUp()</code> and <code>tearDown()</code>
+  methods, and the test methods. The <code>setUp()</code> method in this <code>Y.Test.Case</code> creates an array of data to be used by the various
+  tests while the <code>tearDown()</code> method destroys the array. The test methods are very simple, testing the <code>pop()</code>, <code>push()</code>,
+  and <code>splice()</code> methods. Each test method uses <code>areEqual()</code> exclusively, to show the different ways that it can be used.
+  The <code>testPop()</code> method calls <code>pop()</code> on the array of values, then verifies that the length of the array has changed and
+  that the value popped off is 4; the <code>testPush()</code> pushes a new value (5) onto the array and then verifies that the length of the array has
+  changed and that the value is included in the correct location; the <code>testSplice()</code> method tests  <code>splice()</code> by removing one
+  value that's already in the array and inserting two in its place.</p>
+
+<h3 id="creating-the-testsuite">Creating the TestSuite</h3>
+<p>To better organize the two <code>Y.Test.Case</code> objects, a <code>Y.Test.Suite</code> is created and those two <code>Y.Test.Case</code> objects are
+  added to it:</p>
+<pre class="code prettyprint">Y.example.test.ExampleSuite = new Y.Test.Suite(&quot;Example Suite&quot;);
+Y.example.test.ExampleSuite.add(Y.example.test.DataTestCase);
+Y.example.test.ExampleSuite.add(Y.example.test.ArrayTestCase);</pre>
+
+<p>The first line creates a new <code>Y.Test.Suite</code> object using its constructor, which accepts a single argument - the name of the suite. As with
+  the name of a <code>Y.Test.Case</code>, the <code>Y.Test.Suite</code> name is used to determine where execution is when tests are being executed. Although
+  not required (one is generated if it's not provided), it is recommended that you select a meaningful name to aid in debugging.</p>
+<p>Any number of <code>Y.Test.Case</code> and <code>Y.Test.Suite</code> objects can be added to a <code>Y.Test.Suite</code> by using the <code>add()</code>
+  method. In this example, the two <code>Y.Test.Case</code> objects created earlier are added to the <code>Y.Test.Suite</code>.</p>
+
+<h3 id="running-the-tests">Running the tests</h3>
+
+<p>With all of the tests defined, the last step is to run them. This initialization is assigned to take place when all of the YUI
+  components have been loaded:</p>
+
+<pre class="code prettyprint">&#x2F;&#x2F;create the console
+(new Y.Test.Console({
+    verbose : true,
+    newestOnTop : false
+})).render(&#x27;#testLogger&#x27;);
+
+Y.Test.Runner.add(Y.example.test.ExampleSuite);
+
+&#x2F;&#x2F;run the tests
+Y.Test.Runner.run();</pre>
+
+
+<p>Before running the tests, it's necessary to create a <code>Y.Test.Console</code> object to display the results (otherwise the tests would run
+  but you wouldn't see the results). After that, the <code>Y.Test.Runner</code> is loaded with the <code>Y.Test.Suite</code> object by calling
+  <code>add()</code> (any number of <code>Y.Test.Case</code> and <code>Y.Test.Suite</code> objects can be added to a <code>Y.Test.Runner</code>,
+  this example only adds one for simplicity). The very last step is to call <code>run()</code>, which begins executing the tests in its
+  queue and displays the results in the <code>Y.Test.Console</code>.</p>
+
+<h2 id="complete-example-source">Complete Example Source</h2>
+
+<pre class="code prettyprint">&lt;div id=&quot;testLogger&quot;&gt;&lt;&#x2F;div&gt;
+
+&lt;script&gt;
+YUI().use(&#x27;node&#x27;, &#x27;test-console&#x27;, &#x27;test&#x27;, function (Y) {
+
+    Y.namespace(&quot;example.test&quot;);
+
+    Y.example.test.DataTestCase = new Y.Test.Case({
+
+        &#x2F;&#x2F;name of the test case - if not provided, one is auto-generated
+        name : &quot;Data Tests&quot;,
+
+        &#x2F;&#x2F;---------------------------------------------------------------------
+        &#x2F;&#x2F; setUp and tearDown methods - optional
+        &#x2F;&#x2F;---------------------------------------------------------------------
+
+        &#x2F;*
+         * Sets up data that is needed by each test.
+         *&#x2F;
+        setUp : function () {
+            this.data = {
+                name: &quot;test&quot;,
+                year: 2007,
+                beta: true
+            };
+        },
+
+        &#x2F;*
+         * Cleans up everything that was created by setUp().
+         *&#x2F;
+        tearDown : function () {
+            delete this.data;
+        },
+
+        &#x2F;&#x2F;---------------------------------------------------------------------
+        &#x2F;&#x2F; Test methods - names must begin with &quot;test&quot;
+        &#x2F;&#x2F;---------------------------------------------------------------------
+
+        testName : function () {
+            var Assert = Y.Assert;
+
+            Assert.isObject(this.data);
+            Assert.isString(this.data.name);
+            Assert.areEqual(&quot;test&quot;, this.data.name);
+        },
+
+        testYear : function () {
+            var Assert = Y.Assert;
+
+            Assert.isObject(this.data);
+            Assert.isNumber(this.data.year);
+            Assert.areEqual(2007, this.data.year);
+        },
+
+        testBeta : function () {
+            var Assert = Y.Assert;
+
+            Assert.isObject(this.data);
+            Assert.isBoolean(this.data.beta);
+            Assert.isTrue(this.data.beta);
+        }
+
+    });
+
+    Y.example.test.ArrayTestCase = new Y.Test.Case({
+
+        &#x2F;&#x2F;name of the test case - if not provided, one is auto-generated
+        name : &quot;Array Tests&quot;,
+
+        &#x2F;&#x2F;---------------------------------------------------------------------
+        &#x2F;&#x2F; setUp and tearDown methods - optional
+        &#x2F;&#x2F;---------------------------------------------------------------------
+
+        &#x2F;*
+         * Sets up data that is needed by each test.
+         *&#x2F;
+        setUp : function () {
+            this.data = [0,1,2,3,4]
+        },
+
+        &#x2F;*
+         * Cleans up everything that was created by setUp().
+         *&#x2F;
+        tearDown : function () {
+            delete this.data;
+        },
+
+        &#x2F;&#x2F;---------------------------------------------------------------------
+        &#x2F;&#x2F; Test methods - names must begin with &quot;test&quot;
+        &#x2F;&#x2F;---------------------------------------------------------------------
+
+        testPop : function () {
+            var Assert = Y.Assert;
+
+            var value = this.data.pop();
+
+            Assert.areEqual(4, this.data.length);
+            Assert.areEqual(4, value);
+        },
+
+        testPush : function () {
+            var Assert = Y.Assert;
+
+            this.data.push(5);
+
+            Assert.areEqual(6, this.data.length);
+            Assert.areEqual(5, this.data[5]);
+        },
+
+        testSplice : function () {
+            var Assert = Y.Assert;
+
+            this.data.splice(2, 1, 6, 7);
+
+            Assert.areEqual(6, this.data.length);
+            Assert.areEqual(6, this.data[2]);
+            Assert.areEqual(7, this.data[3]);
+        }
+
+    });
+
+    Y.example.test.ExampleSuite = new Y.Test.Suite(&quot;Example Suite&quot;);
+    Y.example.test.ExampleSuite.add(Y.example.test.DataTestCase);
+    Y.example.test.ExampleSuite.add(Y.example.test.ArrayTestCase);
+
+    &#x2F;&#x2F;create the console
+    (new Y.Test.Console({
+        newestOnTop : false,
+        filters: {
+            pass: true,
+            fail: true
+        }
+    })).render(&#x27;#testLogger&#x27;);
+
+    Y.Test.Runner.add(Y.example.test.ExampleSuite);
+
+    &#x2F;&#x2F;run the tests
+    Y.Test.Runner.run();
+
+});
+&lt;&#x2F;script&gt;</pre>
+
+</div>
+            </div>
+        </div>
+
+        <div class="yui3-u-1-4">
+            <div class="sidebar">
+                
+                    <div id="toc" class="sidebox">
+                        <div class="hd">
+                            <h2 class="no-toc">Table of Contents</h2>
+                        </div>
+
+                        <div class="bd">
+                            <ul class="toc">
+<li>
+<a href="#simple-test-example">Simple Test Example</a>
+<ul class="toc">
+<li>
+<a href="#creating-the-first-testcase">Creating the first TestCase</a>
+</li>
+<li>
+<a href="#creating-the-second-testcase">Creating the second TestCase</a>
+</li>
+<li>
+<a href="#creating-the-testsuite">Creating the TestSuite</a>
+</li>
+<li>
+<a href="#running-the-tests">Running the tests</a>
+</li>
+</ul>
+</li>
+<li>
+<a href="#complete-example-source">Complete Example Source</a>
+</li>
+</ul>
+                        </div>
+                    </div>
+                
+
+                
+                    <div class="sidebox">
+                        <div class="hd">
+                            <h2 class="no-toc">Examples</h2>
+                        </div>
+
+                        <div class="bd">
+                            <ul class="examples">
+                                
+                                    
+                                        <li data-description="Demonstrates basic usage of YUI Test for setting up and running tests.">
+                                            <a href="test-simple-example.html">Simple Testing Example</a>
+                                        </li>
+                                    
+                                
+                                    
+                                        <li data-description="Demonstrates how to use advanced testing features such as defining tests that should fail, tests that should be ignored, and tests that should throw an error.">
+                                            <a href="test-advanced-test-options.html">Advanced Test Options</a>
+                                        </li>
+                                    
+                                
+                                    
+                                        <li data-description="Demonstrates how to use the ArrayAssert object to test array data.">
+                                            <a href="test-array-tests.html">Array Processing</a>
+                                        </li>
+                                    
+                                
+                                    
+                                        <li data-description="Demonstrates basic asynchronous tests.">
+                                            <a href="test-async-test.html">Asynchronous Testing</a>
+                                        </li>
+                                    
+                                
+                                    
+                                        <li data-description="Demonstrates using events with asynchronous tests.">
+                                            <a href="test-async-event-tests.html">Asynchronous Event Testing</a>
+                                        </li>
+                                    
+                                
+                            </ul>
+                        </div>
+                    </div>
+                
+
+                
+            </div>
+        </div>
+    </div>
+</div>
+
+<script src="../assets/vendor/prettify/prettify-min.js"></script>
+<script>prettyPrint();</script>
+
+<script>
+YUI.Env.Tests = {
+    examples: [],
+    project: '../assets',
+    assets: '../assets/test',
+    name: 'test-simple-example',
+    title: 'Simple Testing Example',
+    newWindow: '',
+    auto:  false 
+};
+YUI.Env.Tests.examples.push('test-simple-example');
+YUI.Env.Tests.examples.push('test-advanced-test-options');
+YUI.Env.Tests.examples.push('test-array-tests');
+YUI.Env.Tests.examples.push('test-async-test');
+YUI.Env.Tests.examples.push('test-async-event-tests');
+
+</script>
+<script src="../assets/yui/test-runner.js"></script>
+
+
+
+</body>
+</html>