<?php

/*
 * This file is part of the symfony package.
 * (c) 2004-2006 Fabien Potencier <*****@*****.**>
 * 
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */
$app = 'frontend';
if (!(include dirname(__FILE__) . '/../bootstrap/functional.php')) {
    return;
}
$b = new sfTestBrowser();
$b->initialize();
// exceptions
$b->get('/exception/noException')->isStatusCode(200)->isRequestParameter('module', 'exception')->isRequestParameter('action', 'noException')->responseContains('foo')->get('/exception/throwsException')->isStatusCode(200)->isRequestParameter('module', 'exception')->isRequestParameter('action', 'throwsException')->throwsException('Exception')->throwsException('Exception', 'Exception message')->throwsException('Exception', '/message/')->throwsException(null, '!/sfException/')->get('/exception/throwsSfException')->isStatusCode(200)->isRequestParameter('module', 'exception')->isRequestParameter('action', 'throwsSfException')->throwsException('sfException')->throwsException('sfException', 'sfException message');
$b->get('/browser')->responseContains('html')->checkResponseElement('h1', 'html')->get('/browser/text')->responseContains('text');
try {
    $b->checkResponseElement('h1', 'text');
    $b->test()->fail('The DOM is not accessible if the response content type is not HTML');
} catch (sfException $e) {
    $b->test()->pass('The DOM is not accessible if the response content type is not HTML');
}
// check response headers
$b->get('/browser/responseHeader')->isStatusCode()->isResponseHeader('content-type', 'text/plain; charset=utf-8')->isResponseHeader('foo', 'bar')->isResponseHeader('foo', 'foobar');
  isRequestParameter('module', 'agent')->
  isRequestParameter('action', 'list')->
  checkResponseElement('meta[content="text/html; charset=utf-8"]', true)->
  checkResponseElement('meta[content="text/css"]', true)->
  checkResponseElement('meta[content="en"]', true)->
  checkResponseElement('meta[name="robots"]', true)->
  checkResponseElement('meta[content="index,follow"]', true)->
  checkResponseElement('meta[name="description"]', true)->
  checkResponseElement('meta[name="keywords"]', true)->
  checkResponseElement('meta[name="language"]', true)->
  checkResponseElement('meta[content="en"]', true)->
  checkResponseElement('link[rel="shortcut icon"]', true)
;

//dynamic head settings
$browser->
  checkResponseElement('script[src="/sf/prototype/js/prototype.js"]', true)->
  checkResponseElement('script[src="/sf/prototype/js/builder.js"]', true)->
  checkResponseElement('script[src="/sf/prototype/js/effects.js"]', true)->
  checkResponseElement('link[href="/jpAdminPlugin/css/main.css"]', true)->
  checkResponseElement('link[href="/css/main.css"]', true)->
  checkResponseElement('link[href="/css/layout.css"]', true)->
  checkResponseElement('link[href="/css/agent/layout.css"]', true)
;

//admin sidebar
$browser->
  checkResponseElement('div#content_bar > div#panel_admin > h2', '/administration/')
;

//list
$browser->
        //if it's forbidden
        $forwardTo = $actionArray['roles'][$role][$key]['forwardTo'];
        if (is_array($forwardTo))
        {
          //we should get forwarded to login
          $browser->
            isStatusCode(200)->
            isForwardedTo($forwardTo[0], $forwardTo[1])->
            isStatusCode(200)
            ;

           echo "\n******  Forbidden OK -- " . $role . " :: " . $key . " Access :: " . $action . "\n";
        }
        else if (isset($selectors))
        {

          // test everything for this role
          foreach ($selectors as $selector => $test)
          {
            $browser->checkResponseElement($test[0], $test[1]);
          }
        }
      }
    }

      //foreach $selectors as $selector => $test
        //checkResponseElement($test[0], $test[1], 'Checking -- ' . $selector)->
  }
}