Skip to content
Permalink
Browse files

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.
  • Loading branch information
jaubourg committed Dec 4, 2012
1 parent 3ab2634 commit 228ab3ddae527f72cc3122a1c6115d7718bcfd57
@@ -41,11 +41,15 @@
"ajaxTest": true,
"testIframe": true,
"testIframeWithCallback": true,
"createComplexHTML": true,

This comment has been minimized.

Copy link
@Krinkle

Krinkle Dec 5, 2012

Member

Mixed tabs and spaces..

"createDashboardXML": true,
"createWithFriesXML": true,
"createXMLFragment": true,
"moduleTeardown": true,
"testBar": true,
"testFoo": true,
"url": true,
"url": true,
"service": true,
"t": true,
"q": true,
"amdDefined": true,
@@ -0,0 +1,43 @@
<?php
$requestArray = "REQUEST";
if ( isset( $_REQUEST["requestArray"] ) ) {
$requestArray = $_REQUEST["requestArray"];
}
$requestArray =& ${"_$requestArray"};

This comment has been minimized.

Copy link
@Krinkle

Krinkle Dec 5, 2012

Member

This is a horrible way to simply switch between GET and POST variable retrieval.

This comment has been minimized.

Copy link
@jaubourg

jaubourg Dec 5, 2012

Author Member

OK, then I'll use an array, I see the security concern, I was deep into the tests trying to find a way to switch.

$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]");

This comment has been minimized.

Copy link
@Krinkle

Krinkle Dec 5, 2012

Member
PHP Notice:  Use of undefined constant status 
PHP Notice:  Use of undefined constant statusText 
PHP Notice:  Use of undefined constant contentType
PHP Notice:  Use of undefined constant content

Keys have to be quoted, even in PHP. Please enable error_reporting during development.

This comment has been minimized.

Copy link
@jaubourg

jaubourg Dec 5, 2012

Author Member

Got you. No idea why my installation doesn't show errors though. It should.

header("Content-Type: $response[contentType]");
if ( $response["delay"] ) {
sleep( $response["delay"] );
}
echo $response["callback"]
? "$response[callback](" . json_encode("$response[content]") . ");"

This comment has been minimized.

Copy link
@Krinkle

Krinkle Dec 5, 2012

Member

Why is $response['content'] embedded in a string?

This comment has been minimized.

Copy link
@jaubourg

jaubourg Dec 5, 2012

Author Member

Because I thought I didn't need the quotes, which I no know I do.

: "$response[content]";
@@ -0,0 +1,30 @@
<?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;

This comment has been minimized.

Copy link
@Krinkle

Krinkle Dec 5, 2012

Member

Why stripslashes()?

if ( $requestHeader === $value ) {
header("HTTP/1.0 304 Not Modified");
} else {
header("$headers[response]: $value");

This comment has been minimized.

Copy link
@Krinkle

Krinkle Dec 5, 2012

Member
PHP Notice:  Use of undefined constant response 
echo $requestHeader ? "OK: $value": "FAIL";
}
@@ -0,0 +1,12 @@
<?php
$headers = array();
foreach( $_SERVER as $key => $value ) {
$key = str_replace( "_" , "-" , substr($key,0,5) == "HTTP_" ? substr($key,5) : $key );
$headers[ $key ] = $value;
}
foreach( explode( "," , $_GET["headers"] ) as $key ) {
echo "$key: " . @$headers[ strtoupper( $key ) ] . "\n";
}
@@ -0,0 +1,5 @@
<?php
foreach( $_REQUEST as $header => $value ) {
@header("$header: $value");

This comment has been minimized.

Copy link
@Krinkle

Krinkle Dec 5, 2012

Member

Why error @ error suppression?

This comment has been minimized.

Copy link
@jaubourg

jaubourg Dec 5, 2012

Author Member

That was reminiscent of the old code.

}

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

7 comments on commit 228ab3d

@jaubourg

This comment has been minimized.

Copy link
Member Author

jaubourg replied Dec 4, 2012

@Krinkle seems like we have 12 failures on all browsers in ajax units... thing is I ran those test locally against all browsers so there must be some config discrepancy. Gotta get some sleep right now, but if you have manage to guess what's going on, I'd be happy to adapt the tests to testswarm's configuration if needs be later today ;)

@Krinkle

This comment has been minimized.

Copy link
Member

Krinkle replied Dec 5, 2012

Please some consistency. echo, echo/, echo/index.php. What's it gonna be?

I'd recommend either being completely explicit everywhere (echo/index.php) or abstracting it (calling service() only with a symbolic name and mapping those to a file by appending .php). For example, rename echo/index.php to echo.php. And call service("echo"), which then appends .php.

Depending on which web server (Apache, Nginx, Nodejs, ..) and configuration therefor, various of these may fail (12 fail on jQuery servers).

There various random factors being relied on:

  • accepting directory lookups without trailing slash
  • assuming that even if that is supported, that it does not use a redirect (in which case the AJAX request would get a 301 response)
  • using index.php as the (or one of) default directory index files
    etc.

In case of TestSwarm servers, it does support directory lookups without trailing slash but 301 redirects, causing some of the requests to fail when they get 301 instead of whatever response is expected.

@Krinkle

This comment has been minimized.

Copy link
Member

Krinkle replied Dec 5, 2012

There is various other issues with the PHP code that are imho unacceptable (we do execute this, server side, on production servers!). Please do this from a PR next time instead of pushing straight into master.

@Krinkle

This comment has been minimized.

Copy link
Member

Krinkle replied Dec 5, 2012

228ab3d (by @gibson042) fixes a few of the path errors but from running it locally and by actually looking at the errors on TestSwarm I see that that was only a small part of the problem. I can reproduce the majority of the issues locally regardless of any path format.

There seem to be some invalid XML responses and stuff. Not something I can imagine would make any difference on whatever web server or browser.

And there are the style/security issues with PHP code mentioned earlier (though those don't affect the tests). I don't have time for this right now, as in, we can't have this in master taking over other people's priority all of a sudden.

I recommend reverting these 2 commits out of master ASAP. Then re-submit it as a pull request to go through further review and iteration until it passes the tests.

@jaubourg

This comment has been minimized.

Copy link
Member Author

jaubourg replied Dec 5, 2012

@Krinkle, there are only 12 tests not passing. I'd prefer we fix the issue on master and be done with it rather than revert/PR/commit... We can fix all the issues here with a simple commit.

If you prefer it consistent, then we can make sure the paths are always correctly formatted. I just assumed that 301 were followed and that data just weren't rePOSTed again after the redirection (hence the differences between echo, echo/, ...). I can as easily switch to a pure file.php approach, that like 2 minutes of work.

I see the request array switching as a security risk, is there any other security issue I didn't see? Also, where is the style guide for the php code? Is there any? I tried to stay consistent with the Core style guide as I didn't know of any specific to PHP.

@scottgonzalez

This comment has been minimized.

Copy link
Member

scottgonzalez replied Dec 5, 2012

Also, where is the style guide for the php code? Is there any? I tried to stay consistent with the Core style guide as I didn't know of any specific to PHP.

We should write one (or at least write the differences between PHP and JS). Basically, just follow the core style guide but use single quotes instead of double quotes unless you need string interpolation.

@jaubourg

This comment has been minimized.

Copy link
Member Author

jaubourg replied Dec 5, 2012

#1058 as per discussion on IRC.

Please sign in to comment.
You can’t perform that action at this time.