<?php
////////////////////////////////////////////////////////////////////////////////
//
//  Copyright © 2007 World Wide Web Consortium, 
//  (Massachusetts Institute of Technology, European Research 
//  Consortium for Informatics and Mathematics, Keio 
//  University). All Rights Reserved. 
//  Copyright © 2008 Hewlett-Packard Development Company, L.P. 
// 
//  This work is distributed under the W3CĀ Software License 
//  [1] in the hope that it will be useful, but WITHOUT ANY 
//  WARRANTY; without even the implied warranty of 
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 
// 
//  [1] http://www.w3.org/Consortium/Legal/2002/copyright-software-20021231 
//
//////////////////////////////////////////////////////////////////////////////// 

//////////////////////////////////////////////////////////////////////////////// 
//
//  testsuite.php
//
//  Adapted from Mobile Test Harness [1]
//
//    File: harness.php
//      Lines: 103-142
//
//  where herein specific contents provided by the original harness have
//  been adapted for CSS2.1 conformance testing. Separately, controls have
//  been added to allow entering data for user agents other than the one
//  accessing the harness, and the means by which test presentation order
//  is provided have been altered. Separately, the ability to request
//  only those tests in a particular named group has been added.
//
// [1] http://dev.w3.org/cvsweb/2007/mobile-test-harness/
//
//////////////////////////////////////////////////////////////////////////////// 

require_once("./lib_css2.1_harness/class.css_page.phi");
require_once("./lib_css2.1_harness/class.test_suite.phi");
require_once("./lib_css2.1_harness/class.user_agent.phi");
require_once("./lib_css2.1_harness/class.test_groups.phi");
require_once("./lib_css2.1_harness/class.test_cases.phi");

////////////////////////////////////////////////////////////////////////////////
//
//  class testsuite_page
//
//  A class for generating a page for selecting how tests in a particular 
//  test suite will be presented for inspection. The page includes allowing
//  results to be entered for the user agent accessing the harness or for
//  a user provided user agent. The page further includes requesting
//  to see all of the test cases in the suite, only those test cases in a
//  particular named group, or individual cases. Requests can also be made
//  that successive test cases be presented in the order that they are listed
//  or sorted according to how many response have been entered for the user 
//  agent in question.
//
////////////////////////////////////////////////////////////////////////////////
class testsuite_page extends css_page
{  
  ////////////////////////////////////////////////////////////////////////////
  //
  //  Instance variables.
  //
  ////////////////////////////////////////////////////////////////////////////
  var $m_test_suite;
  var $m_test_groups;
  var $m_test_cases;
  var $m_user_agent;

  ////////////////////////////////////////////////////////////////////////////
  //
  //  Constructor.
  //
  //  The URL accessing the page generated by an object of this class must
  //  identify a valid testsuite:
  //
  //    testsuite.php?s=[testsuite]
  //
  //  If no test suite is identified or if the identified test suite is
  //  not valid, then an error is generated.
  //
  //  The URL accessing the page generated by an object of this class may
  //  also identify an alternate user agent for which data is to be entered:
  //
  //     testsuite.php?s=[testsuite]&u=[id]
  //     testsuite.php?s=[testsuite]&u=[user-agent string]
  //
  //  If no alternate user agent is identified or if the identified user
  //  agent is not valid, then the user agent string of the browser accessing
  //  the harness is used.
  //
  //  All other URL parameters are ignored.
  //
  ////////////////////////////////////////////////////////////////////////////
  function testsuite_page() 
  {
    parent::css_page();

    if(isset($_GET['s'])) {
      $this->m_test_suite = new test_suite($_GET['s']);
    } else {
      $msg = 'No test suite identified.';
      $this->trigger_client_error($msg, E_USER_ERROR);
    }

    $this->m_page_title = $this->m_test_suite->get_title() . 
      ' CSS 2.1 Test Suite';
    
    $this->m_content_title = $this->m_test_suite->get_title() . 
      ' Test Suite for CSS 2.1 Conformance Testing';

    if(isset($_GET['u'])) {
      $this->m_user_agent = new user_agent($_GET['u']);
    } else {
      $this->m_user_agent = new user_agent();
    }

    $this->m_test_groups = new test_groups(
      $this->m_test_suite->get_name());

    $this->m_test_cases = new test_cases(
      $this->m_test_suite->get_name());

    // $this->m_resource_id 
    //   = '$Id: testsuite.php,v 1.2 2008-08-12 18:40:45 dberfang Exp $';    
  }  
  
  ////////////////////////////////////////////////////////////////////////////
  //
  // write_body_content()
  //
  ////////////////////////////////////////////////////////////////////////////
  function write_body_content($indent = '')
  {

    echo $indent . '<p>'."\n";
    echo $indent . '  Thank you for offering to contribute results for ';
    echo 'the support of CSS2.1 conformance '."\n";
    echo $indent . '  testing.'."\n";
    echo $indent . '</p>'."\n";
    echo $indent . '<p>'."\n";
    
    if(isset($_GET['u'])) {

      echo $indent . '  You have provided the ';
      echo 'user-agent string shown below.'."\n";
      echo $indent . '  This string indicates that the browser ';
      echo 'for which you wish to provide data is ';

      $this->m_user_agent->write($indent);

      echo '.'."\n";

    } else {

      echo $indent . '  Your browser has been identified by the ';
      echo 'user-agent string shown below.'."\n";
      echo $indent . '  This string indicates that your browser is ';

      $this->m_user_agent->write($indent);

      echo '; however,'."\n";
      echo $indent . '  you can provide results for a different ';
      echo 'browser by providing another user-agent '."\n";
      echo $indent . '  string.'."\n";
    }
    
    echo $indent . '</p>'."\n";
    
    echo $indent . '  <form action="useragent.php" method="post">'."\n";
    echo $indent . '<p>'."\n";
    echo $indent . '    <input type="hidden" name="s" value="';
    echo $this->m_test_suite->get_name();
    echo '" />'."\n";
    echo $indent . '    <textarea name="u" rows="3" cols="80">';
    echo $this->m_user_agent->get_ua_string();
    echo '</textarea>'."\n";
    echo $indent . '    <br />'."\n";
    echo $indent . '    <input type="submit" value="Change User-Agent" />';
    echo "\n";
    echo $indent . '</p>'."\n";
    echo $indent . '  </form>'."\n";

    echo $indent . '<p>'."\n";
    echo $indent . '  The ';
    echo $this->m_test_suite->get_title();
    echo ' test suite contains ';
    echo $this->m_test_cases->get_count();
    echo ' test cases. '."\n";
    echo 'You can choose to conduct:'."\n";
    echo $indent . '</p>'."\n";
    echo $indent . '<ul>'."\n";
    echo $indent . '<li>'."\n";
    echo $indent . '  <form action="testcase.php" method="get">'."\n";

    echo $indent . '    <input type="hidden" name="s" value="';
    echo $this->m_test_suite->get_name();
    echo '" />';
    if(isset($_GET['u'])) {
      echo $indent . '    <input type="hidden" name="u" value="';
      echo $this->m_user_agent->get_id();
      echo '" />';
    }
    echo $indent . '  The full test suite '."\n";
    echo $indent . '  <select name="o" style="width: 15em">'."\n";
    echo $indent . '    <option selected="selected" value="0">';
    echo 'in order</option>'."\n";
    echo $indent . '    <option value="1">with least tested cases first';
    echo '</option>'."\n";
    echo $indent . '  </select>'."\n";
    echo $indent . '  <input type="submit" value="Go" />'."\n";
    echo $indent . '  </form>'."\n";
    echo $indent . '</li>'."\n";
    echo $indent . '<li>'."\n";
    echo $indent . '  <form action="testcase.php" method="get">'."\n";
    echo $indent . '    <input type="hidden" name="s" value="';
    echo $this->m_test_suite->get_name();
    echo '" />';
    if(isset($_GET['u'])) {
      echo $indent . '    <input type="hidden" name="u" value="';
      echo $this->m_user_agent->get_id();
      echo '" />';
    }
    echo $indent . '  A group of test cases: '."\n";
    
    $this->m_test_groups->write($indent);
    
    echo $indent . '  <select name="o" style="width: 15em">'."\n";
    echo $indent . '    <option selected="selected" value="0">';
    echo 'in order</option>'."\n";
    echo $indent . '    <option value="1">with least tested cases ';
    echo 'first</option>'."\n";
    echo $indent . '  </select>'."\n";
    echo $indent . '  <input type="submit" value="Go" />'."\n";
    echo $indent . '  </form>'."\n";
    echo $indent . '</li>'."\n";
    echo $indent . '<li>'."\n";
    echo $indent . '  <form action="testcase.php" method="get">'."\n";
    echo $indent . '    <input type="hidden" name="s" value="';
    echo $this->m_test_suite->get_name();
    echo '" />';
    if(isset($_GET['u'])) {
      echo $indent . '    <input type="hidden" name="u" value="';
      echo $this->m_user_agent->get_id();
      echo '" />';
    }
    echo $indent . '  A single test case:'."\n";
    
    $this->m_test_cases->write($indent);
    
    echo $indent . '  <input type="submit" value="Go" />'."\n";
    echo $indent . '  </form>'."\n";
    echo $indent . '</li>'."\n";
    echo $indent . '</ul>'."\n";
    echo $indent . '<p>'."\n";
    echo $indent . '  <strong>Note:</strong> You can stop running tests ';
    echo 'at any time without causing troubles.'."\n";
    echo $indent . '  Also, the harness adds automatically in each test ';
    echo 'case the number of remaining'."\n";
    echo $indent . '  test cases and a form to submitt results; these ';
    echo 'additions are not part of the original'."\n";
    echo $indent . '  test cases, and their influence on the results ';
    echo 'should be ignored as much as possible.'."\n";
    echo $indent . '  If you would like to see a particular test case ';
    echo 'without these additions a link is '."\n";
    echo $indent . '  provided to open the test case in a separate ';
    echo 'window. In case of doubt, please hit'."\n";
    echo $indent . '  the "Cannot Tell" button.'."\n";
    echo $indent . '</p>'."\n";

  }
}

$page = new testsuite_page();
$page -> write();

?>
