示例#1
0
 /**
  * Tests the JWeb::Execute method with a document.
  *
  * @return  void
  *
  * @since   11.3
  */
 public function testExecuteWithDocument()
 {
     $dispatcher = $this->getMockDispatcher();
     $document = $this->getMockDocument();
     $this->assignMockReturns($document, array('render' => 'JWeb Body'));
     // Manually inject the dispatcher.
     $this->inspector->setClassProperty('dispatcher', $dispatcher);
     $this->inspector->setClassProperty('document', $document);
     // Register all the methods so that we can track if they have been fired.
     $this->inspector->registerEvent('onBeforeExecute', 'JWebTestExecute-onBeforeExecute')->registerEvent('JWebDoExecute', 'JWebTestExecute-JWebDoExecute')->registerEvent('onAfterExecute', 'JWebTestExecute-onAfterExecute')->registerEvent('onBeforeRender', 'JWebTestExecute-onBeforeRender')->registerEvent('onAfterRender', 'JWebTestExecute-onAfterRender')->registerEvent('onBeforeRespond', 'JWebTestExecute-onBeforeRespond')->registerEvent('onAfterRespond', 'JWebTestExecute-onAfterRespond');
     // Buffer the execution.
     ob_start();
     $this->inspector->execute();
     $buffer = ob_get_contents();
     ob_end_clean();
     $this->assertThat(JDispatcherGlobalMock::$triggered, $this->equalTo(array('onBeforeExecute', 'JWebDoExecute', 'onAfterExecute', 'onBeforeRender', 'onAfterRender', 'onBeforeRespond', 'onAfterRespond')), 'Check that events fire in the right order (with document).');
     $this->assertThat($this->inspector->getBody(), $this->equalTo('JWeb Body'), 'Check that the body was set with the return value of document render method.');
     $this->assertThat($buffer, $this->equalTo('JWeb Body'), 'Check that the body is output correctly.');
 }