changeset 2930:8424c62a8c97

Inital implementation of #228
author Nicholas Jillings <nicholas.jillings@mail.bcu.ac.uk>
date Mon, 11 Sep 2017 17:10:13 +0100
parents 270f20b2d68f
children 465084b9c6dc
files php/test.html
diffstat 1 files changed, 111 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/php/test.html	Mon Sep 11 17:10:13 2017 +0100
@@ -0,0 +1,111 @@
+<html lang="en">
+
+<head>
+    <meta http-equiv="content-type" content="text/html; charset=utf-8">
+
+
+    <!-- Always force latest IE rendering engine (even in intranet) & Chrome Frame
+		Remove this if you use the .htaccess -->
+    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
+
+    <title>Web Audio Evaluation Tool</title>
+    <meta name="description" content="" />
+    <meta name="author" content="" />
+
+    <!-- Load up the default core JS and CSS files-->
+    <link rel='stylesheet' type='text/css' href='../css/core.css'>
+    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/mocha/3.5.2/mocha.min.css" integrity="sha256-Flo6sV8k+IPfHh6Hx97ReUJDLOwIwvhdGlKOz3UgHRE=" crossorigin="anonymous" />
+    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
+    <!-- Use jQuery hosted from Google CDN -->
+    <!--<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>-->
+    <script type="text/javascript" src="../js/showdown.min.js"></script>
+    <script type="text/javascript" src="../js/jquery-2.1.4.js"></script>
+    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
+    <script src="https://cdnjs.cloudflare.com/ajax/libs/chai/4.1.2/chai.min.js" integrity="sha256-iP6sMGdjKeRM2DuED2Lsi/n7MNTKhGpkhuSdCHXIgYc=" crossorigin="anonymous"></script>
+    <script src="https://cdnjs.cloudflare.com/ajax/libs/mocha/3.5.2/mocha.min.js" integrity="sha256-rw/35Nx9y5f+fLTdO7Tipm6ju+tRGwnplU1CJyPM3nE=" crossorigin="anonymous"></script>
+    <script>
+        mocha.setup('bdd');
+        var expect = chai.expect;
+        var should = chai.should();
+        var key1;
+        describe("requestKey.php", function() {
+            it("should give a key", function(done) {
+                var xhr = new XMLHttpRequest();
+                xhr.open("GET", "requestKey.php");
+                xhr.onload = function() {
+                    var doc = xhr.response;
+                    var state = doc.querySelector("state").textContent;
+                    key1 = doc.querySelector("key").textContent;
+                    expect(state).to.equal("OK");
+                    done();
+                }
+                xhr.responseType = "document";
+                xhr.send();
+            });
+            it("should give a different key on second request", function(done) {
+                var xhr = new XMLHttpRequest();
+                xhr.open("GET", "requestKey.php");
+                xhr.onload = function() {
+                    var doc = xhr.response;
+                    var state = doc.querySelector("state").textContent;
+                    var key = doc.querySelector("key").textContent;
+                    expect(key).not.to.equal(key1);
+                    done();
+                }
+                xhr.responseType = "document";
+                xhr.send();
+            });
+        });
+        describe("save.php", function() {
+            it("should return an empty file on empty payload", function(done) {
+                var xhr = new XMLHttpRequest();
+                xhr.open("POST", "save.php?key=" + key1 + "&saveFilenamePrefix=tests");
+                xhr.onload = function() {
+                    var doc = xhr.response;
+                    var state = doc.querySelector("message").textContent;
+                    var file = doc.querySelector("file");
+                    console.log("saves/save-" + key1 + ".xml");
+                    console.log(file);
+                    expect(file.textContent).to.equal("\"saves/tests-" + key1 + ".xml\"");
+                    expect(file.getAttribute("bytes")).to.equal("0");
+                    expect(state).to.equal("OK");
+                    done();
+                }
+                xhr.responseType = "document";
+                xhr.send();
+            });
+            it("should return an URL on payload", function(done) {
+                var xhr = new XMLHttpRequest();
+                xhr.open("POST", "save.php?key=" + key1 + "&saveFilenamePrefix=tests");
+                xhr.onload = function() {
+                    var doc = xhr.response;
+                    var state = doc.querySelector("message").textContent;
+                    var file = doc.querySelector("file");
+                    console.log("saves/save-" + key1 + ".xml");
+                    console.log(file);
+                    expect(file.textContent).to.equal("\"saves/tests-" + key1 + ".xml\"");
+                    expect(file.getAttribute("bytes")).not.to.equal("0");
+                    expect(state).to.equal("OK");
+                    done();
+                }
+                xhr.responseType = "document";
+                xhr.send("<xml></xml>");
+            });
+        });
+        window.onload = function() {
+            mocha.run();
+        }
+
+    </script>
+</head>
+
+<body class="container">
+    <div>
+        <h1>WAET PHP Server Tests</h1>
+        <p class="lead">This page will test your PHP server for any implementation issues.</p>
+
+    </div>
+    <div id="mocha"></div>
+</body>
+
+</html>