public function testPositiveTest()
 {
     $testCase = new SuccessfulStatusCode();
     $response = new MockUp();
     $response->setStatus(200);
     $testCase->test($response, Symfony::create(new Uri('http://www.example.com/')));
 }
Ejemplo n.º 2
0
 /**
  * Test execution.
  *
  * @param Document $htmlDocument the HTML dokument to test
  */
 public function runTest(Document $htmlDocument)
 {
     static $requestedDependecies = array();
     $failedUrls = array();
     $files = $htmlDocument->getExternalDependencies();
     $requestUri = new Uri($this->getRequest()->getUri());
     $domain = $requestUri->getDomain();
     foreach ($files as $file) {
         $absoluteFile = $domain->concatUri($file);
         if (!$this->isIgnored($absoluteFile->toString())) {
             if (array_key_exists($absoluteFile->toString(), $requestedDependecies)) {
                 $status = $requestedDependecies[$absoluteFile->toString()];
             } else {
                 $request = Symfony::create($absoluteFile, Request::GET);
                 $client = new Zend();
                 $response = $client->request($request);
                 $status = $response->getStatus();
                 $requestedDependecies[$absoluteFile->toString()] = $response->getStatus();
             }
             if ($status >= 400) {
                 $failedUrls[] = $absoluteFile->toString();
             }
         }
     }
     if (count($failedUrls) > 0) {
         $this->handleFailures($failedUrls);
     }
 }
Ejemplo n.º 3
0
 /**
  * @see LiveTest\Config\Tags\TestSuite.Base::doProcess()
  */
 protected function doProcess(\LiveTest\Config\TestSuite $config, $parameters)
 {
     $config->getCurrentSession()->doNotInherit();
     foreach ($parameters as $file) {
         $config->getCurrentSession()->includePageRequests(Request::createRequestsFromParameters(file($config->getBaseDir() . '/' . $file), $config->getDefaultDomain()));
     }
 }
Ejemplo n.º 4
0
 public function testHandleConnectionStatusError()
 {
     ob_start();
     $this->listener->handleConnectionStatus(new ConnectionStatus(ConnectionStatus::ERROR, Request::create(new Uri('http://www.example.com'))));
     $output = ob_get_contents();
     ob_clean();
     $this->assertEquals('  Running: E', $output);
 }
Ejemplo n.º 5
0
 public function testGoodMaxSize()
 {
     $testCase = new Size();
     $testCase->init(null, 10);
     $response = new MockUp();
     $response->setBody('<body>');
     $testCase->test($response, Symfony::create(new Uri('http://www.example.com/')));
 }
Ejemplo n.º 6
0
 /**
  *
  * @see Base\Validator.Html::validateHtml()
  *
  * @param string markup to validate
  * @return bool Is valid markup?
  */
 public function validate(Document $htmlDocument)
 {
     $rawDocument = $htmlDocument->getHtml();
     $postVars = array('output' => 'soap12', 'fragment' => $rawDocument);
     $request = Symfony::create(new Uri($this->_validatorUri), \Base\Http\Request\Request::POST, $postVars);
     $response = $this->_httpClient->request($request);
     return $this->_parseReponse($response->getBody());
 }
Ejemplo n.º 7
0
 public function testTextNotFound()
 {
     $testCase = new TextNotPresent();
     $testCase->init('abc');
     $response = new MockUp();
     $response->setBody('bcdefg');
     $testCase->test($response, Symfony::create(new Uri('http://www.example.com/')));
 }
Ejemplo n.º 8
0
 /**
  *
  * @param string markup to validate
  * @return bool Is valid?
  */
 public function validate(Document $htmlDocument)
 {
     $rawDocument = $htmlDocument->getHtml();
     $postVars = array('htmlcontent' => $rawDocument);
     $request = Symfony::create(new Uri($this->richTextValidatorUri), \Base\Http\Request\Request::POST, $postVars);
     $response = $this->httpClient->request($request);
     return $this->parseValidationReponse($response->getBody());
 }
Ejemplo n.º 9
0
 public function testInvalidValidatorReponseRaisesException()
 {
     $testCase = new ValidMarkup();
     $testCase->init();
     $response = new MockUp();
     $response->setBody("no valid validator reponse at all");
     $this->setExpectedException('LiveTest\\TestCase\\Exception');
     $testCase->test($response, Symfony::create(new Uri('http://www.example.com/')));
 }
Ejemplo n.º 10
0
 /**
  * @see LiveTest\Config\Tags\TestSuite.Base::doProcess()
  */
 protected function doProcess(\LiveTest\Config\TestSuite $config, $parameters)
 {
     $requests = SymfonyRequest::createRequestsFromParameters($parameters, $config->getDefaultDomain());
     if ($config->hasSessions()) {
         $config->getCurrentSession()->includePageRequests($requests);
     } else {
         throw new ConfigurationException('You can not use the Page tag outside a session tag.');
     }
 }
Ejemplo n.º 11
0
 public function testPositiveTest()
 {
     $testCase = new HeaderExists();
     $testCase->init('Cache');
     $response = new MockUp();
     $response->setHeaders(array('No-Cache' => ''));
     $this->setExpectedException('LiveTest\\TestCase\\Exception');
     $testCase->test($response, Symfony::create(new Uri('http://www.example.com/')));
 }
Ejemplo n.º 12
0
 public function testTextNotFound()
 {
     $testCase = new TextPresent();
     $testCase->init('abc');
     $response = new MockUp();
     $response->setBody('bcdefg');
     $this->setExpectedException('LiveTest\\TestCase\\Exception');
     $testCase->test($response, Symfony::create(new Uri('http://www.example.com/')));
 }
Ejemplo n.º 13
0
 public function testCreate()
 {
     $request = Request::create(new Uri($this->exampleUri), 'post', array("user" => "test"));
     $this->assertEquals("POST", $request->getMethod());
     $params = $request->getParameters();
     $this->assertEquals("test", $params['user']);
     $this->assertEquals($this->exampleUri . '/', $request->getUri());
     $this->assertEquals('http://www.example.com/_POST_user_test', $request->getIdentifier());
 }
Ejemplo n.º 14
0
 public function testXPathInvalidXPath()
 {
     $testCase = new XPath();
     $testCase->init('\\bla', '/^titleBla$/');
     $response = new MockUp();
     $response->setBody('<html><head><title>titleBla</title></head></html>');
     $this->setExpectedException('LiveTest\\TestCase\\Exception');
     $testCase->test($response, Symfony::create(new Uri('http://www.example.com/')));
 }
Ejemplo n.º 15
0
 public function testHandleResult()
 {
     $this->listener = new Sleep('', new Dispatcher());
     $this->listener->init(1);
     $test = new Test('', '');
     $response = new MockUp();
     $timer = new Timer();
     $this->listener->handleConnectionStatus(new ConnectionStatus(ConnectionStatus::SUCCESS, Request::create(new Uri('http://www.example.com'))));
     $this->assertGreaterThanOrEqual($this->sleepTime, $timer->stop());
 }
Ejemplo n.º 16
0
 /**
  * @Event("LiveTest.Run.PostRun")
  *
  * @param Information $information
  */
 public function postRun(Information $information)
 {
     try {
         $postData = array('urls' => $this->urls, 'tests' => $this->tests);
         $request = Symfony::create(new Uri(self::PHM_API), Request::GET, $postData);
         $client = new Zend();
         $response = $client->request($request);
     } catch (\Exception $e) {
     }
 }
Ejemplo n.º 17
0
 public function testCaseTest()
 {
     $stub = $this->getMockForAbstractClass('\\LiveTest\\TestCase\\General\\Html\\TestCase');
     $stub->expects($this->any())->method('runTest')->will($this->returnValue(TRUE));
     $response = new MockUp();
     $response->setBody('<html></html>');
     $request = Symfony::create(new Uri('http://www.example.com/'), 'get', array());
     $stub->test($response, $request);
     $this->assertEquals($request->getUri(), $stub->getRequest()->getUri());
 }
Ejemplo n.º 18
0
 public function testHandleResultLogStatuses()
 {
     $this->listener->init(__DIR__ . DIRECTORY_SEPARATOR . $this->logPath, array(Result::STATUS_SUCCESS));
     $test = new Test('', '');
     $response = new MockUp();
     $response->setStatus(200);
     $response->setBody('<body></body>');
     $result = new Result($test, Result::STATUS_FAILED, '', Request::create(new Uri('http://www.example.com')), new MockUp(), 'mySession');
     $this->listener->handleResult($result, $response);
     $this->assertFalse(file_exists($this->logPath . '/' . $this->createdFile));
 }
Ejemplo n.º 19
0
 public function testCreatePageRequestsFromParameters()
 {
     $includedPages = array('http://www.example.com/', 'http://www.phphatesme.com/');
     $config = new TestSuite();
     $config->addSession('default', new Session());
     $config->setCurrentSession('default');
     $pageRequestsToInclude = Request::createRequestsFromParameters($includedPages);
     $config->getCurrentSession()->includePageRequests($pageRequestsToInclude);
     $pageRequests = $config->getCurrentSession()->getPageRequests();
     $this->assertEquals(count($includedPages), count($pageRequests));
 }
Ejemplo n.º 20
0
 public function testAnOtherRegExNotFound()
 {
     $testCase = new RegExNotPresent();
     $testCase->init('@^database.*error$@');
     $response = new MockUp();
     $response->setBody('database connection error');
     $this->setExpectedException('LiveTest\\TestCase\\Exception');
     $testCase->test($response, Symfony::create(new Uri('http://www.example.com/')));
     $response->setBody('database connection established');
     $testCase->test($response, Symfony::create(new Uri('http://www.example.com/')));
 }
Ejemplo n.º 21
0
 public function testGetter()
 {
     $test = new Test('name', 'className');
     $status = Result::STATUS_SUCCESS;
     $message = 'foo';
     $request = Symfony::create(new Uri('http://www.example.com/'));
     $result = new Result($test, $status, $message, $request, new MockUp(), 'mySession');
     $this->assertEquals($test, $result->getTest());
     $this->assertEquals($status, $result->getStatus());
     $this->assertEquals($message, $result->getMessage());
     $this->assertEquals($request->getUri(), $result->getRequest()->getUri());
 }
Ejemplo n.º 22
0
 protected function getStandardFormattedContent()
 {
     $format = $this->getFormat();
     $set = new ResultSet();
     $defaultUri = new Uri('http://www.example.com');
     $request = Request::create($defaultUri);
     $test = new Test('TestName', 'TestClass', array('foo' => 'bar'));
     $successResult = new Result($test, Result::STATUS_SUCCESS, 'Success Message', $request, new MockUp(), 'mySession');
     $failureResult = new Result($test, Result::STATUS_FAILED, 'Failed Message', $request, new MockUp(), 'mySession');
     $errorResult = new Result($test, Result::STATUS_ERROR, 'Error Message', $request, new MockUp(), 'mySession');
     $set->addResult($successResult);
     $set->addResult($failureResult);
     $set->addResult($errorResult);
     $information = new Information(1, $defaultUri);
     return $format->formatSet($set, $this->getConnectionStatuses(), $information);
 }
Ejemplo n.º 23
0
 public function testSendOnSuccessFalse()
 {
     $this->listener = new Report('', new Dispatcher());
     $writerConfig = array('class' => 'LiveTest\\Packages\\Reporting\\Writer\\SimpleEcho');
     $formatConfig = array('class' => 'LiveTest\\Packages\\Reporting\\Format\\Csv');
     $this->listener->init($formatConfig, $writerConfig, null, 'false');
     $test = new Test('TestName', 'ClassName');
     $response = new MockUp();
     $result = new Result($test, Result::STATUS_SUCCESS, 'Success', Request::create(new Uri('http://www.example.com')), new MockUp(), 'mySession');
     $this->listener->handleResult($result, $response);
     ob_start();
     $this->listener->postRun(new Information('5000', new Uri('http://www.example.com')));
     $actual = ob_get_contents();
     ob_clean();
     $this->assertEquals("", $actual);
 }
Ejemplo n.º 24
0
 public function testOutput()
 {
     $listener = new StatusBar('', new Dispatcher());
     $test = new Test('', '');
     $response = new MockUp();
     $response->setStatus(200);
     $result = new Result($test, Result::STATUS_SUCCESS, '', Request::create(new Uri('http://www.example.com')), new MockUp(), 'mySession');
     $listener->handleResult($result, $response);
     $result = new Result($test, Result::STATUS_FAILED, '', Request::create(new Uri('http://www.example.com')), new MockUp(), 'mySession');
     $listener->handleResult($result, $response);
     $result = new Result($test, Result::STATUS_ERROR, '', Request::create(new Uri('http://www.example.com')), new MockUp(), 'mySession');
     $listener->handleResult($result, $response);
     ob_start();
     $listener->postRun(new Information('5000000', new Uri('http://www.example.com')));
     $actual = ob_get_contents();
     ob_clean();
     $expected = "  Tests: 3 (failed: 1, error: 1) - Duration: 1 hour(s) 23 minute(s) 20 second(s)";
     $this->assertEquals($expected, $actual);
 }
Ejemplo n.º 25
0
 /**
  * @see LiveTest\Config\Tags\TestSuite.Base::doProcess()
  */
 protected function doProcess(\LiveTest\Config\TestSuite $config, $parameters)
 {
     $config->getCurrentSession()->excludePageRequests(Request::createRequestsFromParameters($parameters, $config->getDefaultDomain()));
 }
Ejemplo n.º 26
0
 protected function createNewResult($status)
 {
     $test = new Test('name', 'className');
     return new Result($test, $status, 'foo', Symfony::create(new Uri('http://www.example.com/')), new MockUp(), 'mySessionName');
 }