Commit b7ece8c6 authored by jaubourg's avatar jaubourg

Revert "Organizes the php scripts used for testing better, so that the whole...

Revert "Organizes the php scripts used for testing better, so that the whole logic of a unit, server-side and client-side, is contained within the unit itself. Nearly all ajax unit tests take advantage of the new 'framework'. Lots of files got deleted because they became redundant or weren't used anymore."

This reverts commit 228ab3dd.
parent 6df2900d
......@@ -41,15 +41,11 @@
"ajaxTest": true,
"testIframe": true,
"testIframeWithCallback": true,
"createComplexHTML": true,
"createDashboardXML": true,
"createWithFriesXML": true,
"createXMLFragment": true,
"moduleTeardown": true,
"testBar": true,
"testFoo": true,
"url": true,
"service": true,
"url": true,
"t": true,
"q": true,
"amdDefined": true,
......
<?php
$requestArray = "REQUEST";
if ( isset( $_REQUEST["requestArray"] ) ) {
$requestArray = $_REQUEST["requestArray"];
}
$requestArray =& ${"_$requestArray"};
$response = array(
"status" => "200",
"statusText" => "",
"contentType" => "text/plain",
"content" => "",
"callback" => "",
"delay" => 0
);
foreach( $response as $field => &$value ) {
if ( isset( $requestArray[ $field ] ) ) {
$value = $requestArray[ $field ];
}
}
if ( is_array( $response["content"] ) ) {
$response["content"] = http_build_query( $response["content"] );
}
if ( !$response["callback"] && preg_match( '/index.php\/([^\/\?&]+)/', $_SERVER["REQUEST_URI"], $match ) ) {
$response["callback"] = $match[ 1 ];
}
header("HTTP/1.1 $response[status] $response[statusText]");
header("Content-Type: $response[contentType]");
if ( $response["delay"] ) {
sleep( $response["delay"] );
}
echo $response["callback"]
? "$response[callback](" . json_encode("$response[content]") . ");"
: "$response[content]";
<?php
$headers = array(
"If-Modified-Since" => array(
"request" => "HTTP_IF_MODIFIED_SINCE",
"response" => "Last-Modified",
),
"If-None-Match" => array(
"request" => "HTTP_IF_NONE_MATCH",
"response" => "Etag",
),
);
$header = $_REQUEST["header"];
$value = $_REQUEST["value"];
if ( $header === "If-None-Match" ) {
$value = md5( $value );
}
$headers = $headers[ $header ];
$requestHeader = isset( $_SERVER[ $headers["request"] ] ) ? stripslashes($_SERVER[ $headers["request"] ]) : false;
if ( $requestHeader === $value ) {
header("HTTP/1.0 304 Not Modified");
} else {
header("$headers[response]: $value");
echo $requestHeader ? "OK: $value": "FAIL";
}
<?php
foreach( $_REQUEST as $header => $value ) {
@header("$header: $value");
}
<?php header("Content-type: atom+xml") ?>
<root>
<element />
</root>
\ No newline at end of file
{bad: toTheBone}
<script>
<!--
ok( true, "script within html comments executed" );
-->
</script>
<script>
<![CDATA[
ok( true, "script within CDATA executed" );
]]>
</script>
<?xml version="1.0" encoding="UTF-8"?>
<dashboard>
<locations class="foo">
<location for="bar" checked="different">
<infowindowtab>
<tab title="Location"><![CDATA[blabla]]></tab>
<tab title="Users"><![CDATA[blublu]]></tab>
</infowindowtab>
</location>
</locations>
</dashboard>
<?php echo file_get_contents('php://input'); ?>
<?php echo $_SERVER['QUERY_STRING']; ?>
\ No newline at end of file
<?php
header("HTTP/1.0 400 Bad Request");
echo "plain text message";
\ No newline at end of file
<?php
error_reporting(0);
$ts = $_REQUEST['ts'];
$etag = md5($ts);
$ifNoneMatch = isset($_SERVER['HTTP_IF_NONE_MATCH']) ? stripslashes($_SERVER['HTTP_IF_NONE_MATCH']) : false;
if ($ifNoneMatch == $etag) {
header('HTTP/1.0 304 Not Modified');
die; // stop processing
}
header("Etag: " . $etag);
if ( $ifNoneMatch ) {
echo "OK: " . $etag;
} else {
echo "FAIL";
}
?>
ok( "<?php echo $_SERVER['REQUEST_METHOD'] ?>" === "GET", "request method is <?php echo $_SERVER['REQUEST_METHOD'] ?>" );
\ No newline at end of file
<?php
header( "Sample-Header: Hello World" );
header( "Empty-Header: " );
header( "Sample-Header2: Hello World 2" );
$headers = array();
foreach( $_SERVER as $key => $value ) {
$key = str_replace( "_" , "-" , substr($key,0,5) == "HTTP_" ? substr($key,5) : $key );
$key = str_replace( "_" , "-" , substr( $key , 0 , 5 ) == "HTTP_" ? substr( $key , 5 ) : $key );
$headers[ $key ] = $value;
}
foreach( explode( "," , $_GET["headers"] ) as $key ) {
foreach( explode( "_" , $_GET[ "keys" ] ) as $key ) {
echo "$key: " . @$headers[ strtoupper( $key ) ] . "\n";
}
<?php
error_reporting(0);
$ts = $_REQUEST['ts'];
$ifModifiedSince = isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) ? stripslashes($_SERVER['HTTP_IF_MODIFIED_SINCE']) : false;
if ($ifModifiedSince == $ts) {
header('HTTP/1.0 304 Not Modified');
die; // stop processing
}
header("Last-Modified: " . $ts);
if ( $ifModifiedSince ) {
echo "OK: " . $ts;
} else {
echo "FAIL";
}
?>
<?php
error_reporting(0);
if ( $_REQUEST['header'] ) {
header("Content-type: application/json");
}
$json = $_REQUEST['json'];
if($json) {
echo '[ {"name": "John", "age": 21}, {"name": "Peter", "age": 25 } ]';
} else {
echo '{ "data": {"lang": "en", "length": 25} }';
}
?>
{ "data": {"lang": "en", "length": 25} }
<?php
error_reporting(0);
$callback = $_REQUEST['callback'];
if ( ! $callback ) {
$callback = explode("?",end(explode("/",$_SERVER['REQUEST_URI'])));
$callback = $callback[0];
}
$json = $_REQUEST['json'];
if($json) {
echo $callback . '([ {"name": "John", "age": 21}, {"name": "Peter", "age": 25 } ])';
} else {
echo $callback . '({ "data": {"lang": "en", "length": 25} })';
}
?>
ERROR <script type="text/javascript">ok( true, "name.html retrieved" );</script>
<?php
error_reporting(0);
$wait = $_REQUEST['wait'];
if($wait) {
sleep($wait);
}
$xml = $_REQUEST['xml'];
if($xml) {
header("Content-type: text/xml");
$result = ($xml == "5-2") ? "3" : "?";
echo "<math><calculation>$xml</calculation><result>$result</result></math>";
die();
}
$name = $_REQUEST['name'];
if($name == 'foo') {
echo "bar";
die();
} else if($name == 'peter') {
echo "pan";
die();
}
echo 'ERROR <script type="text/javascript">ok( true, "name.php executed" );</script>';
?>
\ No newline at end of file
<div id="post">
<?php
foreach( $_POST as $key=>$value )
echo "<b id='$key'>$value</b>";
?>
</div>
<div id="get">
<?php
foreach( $_GET as $key=>$value )
echo "<b id='$key'>$value</b>";
?>
</div>
\ No newline at end of file
<?php
error_reporting(0);
if ( $_REQUEST['header'] ) {
if ( $_REQUEST['header'] == "ecma" ) {
header("Content-type: application/ecmascript");
} else {
header("Content-type: text/javascript");
}
}
?>
ok( true, "Script executed correctly." );
<?php
header( "HTTP/1.0 $_GET[status] $_GET[text]" );
?>
\ No newline at end of file
html text<br/>
<script type="text/javascript">/* <![CDATA[ */
testFoo = "foo"; jQuery('#foo').html('foo');
ok( true, "test.html executed" );
/* ]]> */</script>
<script src="data/test.js"></script>
blabla
var testBar = "bar";
jQuery('#ap').html('bar');
ok( true, "test.js executed");
html text<br/>
<script type="text/javascript">/* <![CDATA[ */
testFoo = "foo"; jQuery('#foo').html('foo');
ok( true, "test.php executed" );
/* ]]> */</script>
<script src="data/test.js?<?php srand(); echo time() . '' . rand(); ?>"></script>
blabla
\ No newline at end of file
<script type="text/javascript">
var testFoo = "foo";
jQuery('#foo').html('foo');
ok( true, "test2.html executed" );
</script>
<div class="user">This is a user</div>
<div class="user">This is a user</div>
<div class="teacher">This is a teacher</div>
......@@ -58,21 +58,7 @@ function t( a, b, c ) {
deepEqual(f, q.apply( q, c ), a + " (" + b + ")");
}
function createComplexHTML() {
return 'html text<br/> \
<script type="text/javascript">/* <![CDATA[ */ \
testFoo = "foo"; jQuery("#foo").html("foo"); \
ok( true, "inline script executed" ); \
/* ]]> */</script> \
<script src="' + service("echo", {
content: 'var testBar = "bar"; \
jQuery("#ap").html("bar"); \
ok( true, "remote script executed");'
}) + '"></script> \
blabla';
}
function createDashboardXML( noParse ) {
function createDashboardXML() {
var string = '<?xml version="1.0" encoding="UTF-8"?> \
<dashboard> \
<locations class="foo"> \
......@@ -85,10 +71,10 @@ function createDashboardXML( noParse ) {
</locations> \
</dashboard>';
return noParse ? string : jQuery.parseXML(string);
return jQuery.parseXML(string);
}
function createWithFriesXML( noParse ) {
function createWithFriesXML() {
var string = '<?xml version="1.0" encoding="UTF-8"?> \
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" \
xmlns:xsd="http://www.w3.org/2001/XMLSchema" \
......@@ -113,9 +99,9 @@ function createWithFriesXML( noParse ) {
</response> \
</jsconf> \
</soap:Body> \
</soap:Envelope>'.replace( /\{\{\s*externalHost\s*\}\}/g, externalHost );
</soap:Envelope>';
return noParse ? string : jQuery.parseXML( string );
return jQuery.parseXML( string.replace( /\{\{\s*externalHost\s*\}\}/g, externalHost ) );
}
function createXMLFragment() {
......@@ -147,27 +133,16 @@ fireNative = document.createEvent ?
/**
* Add random number to url to stop caching
*
* @example url("data/iframe.html")
* @result "data/iframe.html?10538358428943"
* @example url("data/test.html")
* @result "data/test.html?10538358428943"
*
* @example url("data/ajax/echo?foo=bar")
* @result "data/ajax/echo?foo=bar&10538358345554"
* @example url("data/test.php?foo=bar")
* @result "data/test.php?foo=bar&10538358345554"
*/
function url( value ) {
return value + (/\?/.test(value) ? "&" : "?") + new Date().getTime() + "" + parseInt(Math.random() * 100000, 10);
}
function service( value, data ) {
var fragment = url( "data/ajax/" + ( value || "" ) );
if ( data ) {
if ( typeof data !== "string" ) {
data = jQuery.param( data );
}
fragment += "&" + data;
}
return fragment;
}
// Ajax testing helper
function ajaxTest( title, expect, options ) {
var requestOptions;
......@@ -192,9 +167,8 @@ function ajaxTest( title, expect, options ) {
delete ajaxTest.abort;
if ( options.teardown ) {
options.teardown();
} else {
start();
}
start();
}
},
requests = jQuery.map( requestOptions, function( options ) {
......
Lorem ipsum dolor sit amet
consectetuer adipiscing elit
Sed lorem leo
lorem leo consectetuer adipiscing elit
Sed lorem leo
rhoncus sit amet
elementum at
bibendum at, eros
Cras at mi et tortor egestas vestibulum
sed Cras at mi vestibulum
Phasellus sed felis sit amet
orci dapibus semper.
This diff is collapsed.
<?xml version='1.0' encoding='UTF-8'?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soap:Body>
<jsconf xmlns="http://example.com/ns1">
<response xmlns:ab="http://example.com/ns2">
<meta>
<component id="seite1" class="component">
<properties xmlns:cd="http://example.com/ns3">
<property name="prop1">
<thing />
<value>1</value>
</property>
<property name="prop2">
<thing att="something" />
</property>
<foo_bar>foo</foo_bar>
</properties>
</component>
</meta>
</response>
</jsconf>
</soap:Body>
</soap:Envelope>
<?php
error_reporting(0);
$callback = $_REQUEST['callback'];
$json = $_REQUEST['json'];
$text = json_encode(file_get_contents(dirname(__FILE__)."/with_fries.xml"));
echo "$callback($text)";
?>
......@@ -51,7 +51,7 @@
function doLog( message, args ) {
jQuery( "<li />").appendTo( logUL ).text( message + ': "' + Array.prototype.join.call( args, '" - "' ) + '"' );
}
jQuery.ajax( "data/ajax/echo/index.php", {
jQuery.ajax( "./data/badjson.js" , {
context: jQuery( "#success" ),
dataType: "text"
}).success(function( data, _, xhr ) {
......@@ -61,7 +61,7 @@
doLog( "Success (" + xhr.status + ")" , arguments );
this.addClass( "error" ).text( "FAIL" );
});
jQuery.ajax( "error" , {
jQuery.ajax( "./data/doesnotexist.ext" , {
context: jQuery( "#error" ),
dataType: "text"
}).error(function( xhr ) {
......
This diff is collapsed.
......@@ -2148,7 +2148,7 @@ test( "html() - script exceptions bubble (#11743)", function() {
}, "exception bubbled from inline script" );
raises(function() {
jQuery("#qunit-fixture").html("<script src='" + service("echo?content=undefined()")+ "'></script>");
jQuery("#qunit-fixture").html("<script src='data/badcall.js'></script>");
ok( false, "error ignored" );
}, "exception bubbled from remote script" );
});
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment