Exemplo n.º 1
0
 /**
  * Test a factory.
  *
  * @param  string $className
  * @return void
  */
 public function testFactory($classname, array $requiredOptions, array $options)
 {
     // Test that the factory does not allow a scalar option.
     try {
         $classname::factory(0);
         $this->testCase->fail('An expected exception was not thrown');
     } catch (\Zend\Mvc\Router\Exception\InvalidArgumentException $e) {
         $this->testCase->assertContains('factory expects an array or Traversable set of options', $e->getMessage());
     }
     // Test required options.
     foreach ($requiredOptions as $option => $exceptionMessage) {
         $testOptions = $options;
         unset($testOptions[$option]);
         try {
             $classname::factory($testOptions);
             $this->testCase->fail('An expected exception was not thrown');
         } catch (\Zend\Mvc\Router\Exception\InvalidArgumentException $e) {
             $this->testCase->assertContains($exceptionMessage, $e->getMessage());
         }
     }
     // Create the route, will throw an exception if something goes wrong.
     $classname::factory($options);
     // Try the same with an iterator.
     $classname::factory(new ArrayIterator($options));
 }
Exemplo n.º 2
0
 public function testDump()
 {
     ob_start();
     Debug::dump('some string');
     parent::assertContains('some', ob_get_clean());
     ob_start();
     Debug::dump(new \Exception('hello world'));
     parent::assertContains('Exception', ob_get_clean());
 }
 /**
  * @dataProvider optionsDataProvider
  * @param string $username
  * @param array $options
  * @param array $expectedOptions
  * @param string $expectedTemplate
  */
 public function testGetSkypeButton($username, $options, $expectedOptions, $expectedTemplate)
 {
     $env = $this->getMockBuilder('\\Twig_Environment')->disableOriginalConstructor()->getMock();
     $env->expects($this->once())->method('render')->with($expectedTemplate, $this->anything())->will($this->returnCallback(function ($template, $options) use($expectedOptions, $username) {
         \PHPUnit_Framework_TestCase::assertArrayHasKey('name', $options['options']);
         \PHPUnit_Framework_TestCase::assertEquals($expectedOptions['name'], $options['options']['name']);
         \PHPUnit_Framework_TestCase::assertArrayHasKey('participants', $options['options']);
         \PHPUnit_Framework_TestCase::assertEquals($expectedOptions['participants'], $options['options']['participants']);
         \PHPUnit_Framework_TestCase::assertArrayHasKey('element', $options['options']);
         \PHPUnit_Framework_TestCase::assertContains('skype_button_' . md5($username), $options['options']['element']);
         return 'BUTTON_CODE';
     }));
     $this->assertEquals('BUTTON_CODE', $this->extension->getSkypeButton($env, $username, $options));
 }
Exemplo n.º 4
0
 public function it_dispatches_a_static_template_request()
 {
     // init
     $this->setConfig();
     $request = new Request($this->object->getWrappedObject()->config);
     $response = new Response($this->object->getWrappedObject()->config);
     // static request
     $request->setPath('/test/static');
     $this->dispatchRequest($request, $response);
     $actual = $response->getBody();
     $expectedBody = '<h1>Hello Static</h1>';
     Assertions::assertContains($expectedBody, $actual, 'should inject body template');
     $expectedMarkup = '<html';
     Assertions::assertContains($expectedMarkup, $actual, 'should generate page container');
 }
Exemplo n.º 5
0
 public function it_adds_the_app_title_to_the_page_title()
 {
     // init
     $config = new Config();
     $this->config = $config;
     $request = new Request();
     $response = new Response();
     // request with appended app title
     $config->set('appTitle', 'app');
     $config->set('pageTitleDelimiter', ' :: ');
     $request->setPath('/test');
     $route = (object) ["path" => "/test", "type" => "template", "template" => "/test/fixtures/static-body.html.tpl", "model" => (object) ["pageTemplate" => "/test/fixtures/index.html.tpl", "pageTitle" => 'page']];
     $this->handleTemplateRouteRequest($request, $response, $route);
     Assertions::assertContains('<title>page :: app</title>', $response->getBody(), 'should have page title and app title');
     // request with empty page title
     $route->model->pageTitle = null;
     $this->handleTemplateRouteRequest($request, $response, $route);
     Assertions::assertContains('<title>app</title>', $response->getBody(), 'should have app title only');
     // request with empty app title
     $route->model->pageTitle = 'page';
     $config->set('appTitle', null);
     $this->handleTemplateRouteRequest($request, $response, $route);
     Assertions::assertContains('<title>page</title>', $response->getBody(), 'should have page title only');
 }
Exemplo n.º 6
0
 /**
  * @param mixed|CM_Comparable $needle
  * @param Traversable|string  $haystack
  * @param string              $message
  * @param boolean             $ignoreCase
  * @param boolean             $checkForObjectIdentity
  * @param bool                $checkForNonObjectIdentity
  * @throws CM_Exception_Invalid
  */
 public static function assertContains($needle, $haystack, $message = '', $ignoreCase = false, $checkForObjectIdentity = true, $checkForNonObjectIdentity = false)
 {
     if ($needle instanceof CM_Comparable) {
         if (!(is_array($haystack) || $haystack instanceof Traversable)) {
             throw new CM_Exception_Invalid('Haystack is not traversable.');
         }
         $match = false;
         foreach ($haystack as $hay) {
             if ($needle->equals($hay)) {
                 $match = true;
                 break;
             }
         }
         self::assertTrue($match, 'Needle not contained.');
     } else {
         parent::assertContains($needle, $haystack, $message, $ignoreCase, $checkForObjectIdentity, $checkForNonObjectIdentity);
     }
 }
Exemplo n.º 7
0
 /**
  * @dataProvider throwables
  */
 public function testInvokesDefaultErrorFormatterWhenDebugIsEnabledAndThrowableCaught($throwable)
 {
     $next = function () use($throwable) {
         throw $throwable;
     };
     $this->renderer->render(ErrorHandler::TEMPLATE_ERROR, Argument::that(function ($argument) use($throwable) {
         TestCase::assertInternalType('array', $argument);
         TestCase::assertArrayHasKey('error', $argument);
         $error = $argument['error'];
         TestCase::assertContains($throwable->getMessage(), $error);
         TestCase::assertContains((string) $throwable->getCode(), $error);
         TestCase::assertContains($throwable->getTraceAsString(), $error);
         return true;
     }))->willReturn('error content');
     $handler = new ErrorHandler($this->renderer->reveal(), true);
     $result = $handler($this->createRequestMock()->reveal(), $this->createResponseMock()->reveal(), $next);
     $this->assertInstanceOf(HtmlResponse::class, $result);
     $this->assertEquals(500, $result->getStatusCode());
     $this->assertEquals('error content', (string) $result->getBody());
 }
 public static function assertContains($needle, $haystack, $message = '', $ignoreCase = FALSE, $checkForObjectIdentity = TRUE, $checkForNonObjectIdentity = false)
 {
     if ($haystack instanceof DBField) {
         $haystack = (string) $haystack;
     }
     parent::assertContains($needle, $haystack, $message, $ignoreCase, $checkForObjectIdentity, $checkForNonObjectIdentity);
 }
/**
 * Dummy method
 *
 * @param   string   $url      Path to the resource.
 * @param   mixed    $data     Either an associative array or a string to be sent with the request.
 * @param   array    $headers  An array of name-value pairs to include in the header of the request.
 * @param   integer  $timeout  Read timeout in seconds.
 *
 * @return  JHttpResponse
 *
 * @since   12.3
 */
function dataPicasaPhotoCallback($url, $data, array $headers = null, $timeout = null)
{
	PHPUnit_Framework_TestCase::assertContains('<title>New Title</title>', $data);

	$response = new stdClass;

	$response->code = 200;
	$response->headers = array('Content-Type' => 'application/atom+xml');
	$response->body = $data;

	return $response;
}
 public function testAdd($data)
 {
     $count = count($this->entityGet());
     $containsBeforeAdd = $this->countDataInCollection($data);
     $returnOfAddMethod = $this->entityAdd($data);
     if ($this->fluent) {
         TestCase::assertEquals($this->entity, $returnOfAddMethod, $this->msg(self::$MSG_ADD_METHOD_NOT_FLUENT));
     }
     TestCase::assertContains($data, $this->entityGet(), $this->msg(self::$MSG_ADD_METHOD_DOES_NOT_ADD));
     if ($this->unique && $containsBeforeAdd > 0) {
         TestCase::assertCount($count, $this->entityGet(), $this->msg(self::$MSG_ADD_METHOD_NOT_UNIQUE));
     } else {
         TestCase::assertCount($count + 1, $this->entityGet(), $this->msg(self::$MSG_ADD_METHOD_UNIQUE));
     }
     return $this;
 }
Exemplo n.º 11
0
 protected function assertGeneratedContent($expected, $actual)
 {
     $this->markTestIncomplete('Find a way to compare this!');
     return parent::assertContains(preg_replace('/[\\t\\r\\n]/', '', $expected), preg_replace('/[\\t\\r\\n]/', '', $actual));
 }
Exemplo n.º 12
0
 /**
  * @Then I should see :value in the :tag element
  */
 public function iShouldSeeInTheElement($value, $tag)
 {
     $page = $this->getSession()->getPage();
     $el = $page->find('css', $tag);
     Assertions::assertNotNull($el);
     $actual = $el->getText();
     Assertions::assertContains($value, $actual);
 }