view php/test.html @ 2933:95f507064bf2

Harder check for second key test #228
author Nicholas Jillings <nicholas.jillings@mail.bcu.ac.uk>
date Mon, 11 Sep 2017 17:22:23 +0100
parents 465084b9c6dc
children 260efd43fe52
line wrap: on
line source
<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 create an empty file with that key", function(done) {
                var xhr = new XMLHttpRequest();
                xhr.open("GET", "../saves/save-" + key1 + ".xml");
                xhr.onload = function() {
                    var parser = new DOMParser();
                    doc = parser.parseFromString(xhr.responseText, "text/xml");
                    var state = doc.querySelector("waetresult").getAttribute("key");
                    expect(state).to.equal(key1);
                    done();
                }
                xhr.responseType = "";
                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(state).to.equal("OK");
                    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");
                    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 a file on payload save", 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");
                    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>
        <p>Make sure your <span>saves</span> directory is clean before testing and that you empty it afterwards as intermediary files will be made there.</p>

    </div>
    <div id="mocha"></div>
</body>

</html>