Esempio n. 1
0
 /**
  * @todo Implement test_().
  */
 public function test_()
 {
     // first we test to ensure that if a handler is properly registered, it gets called
     $registered = $this->getMock('MyHtmlClass', array('mockFunction'));
     // test that we can register the method
     JHtml::register('file.testfunction', array($registered, 'mockFunction'));
     // test that calling _ actually calls the function
     $registered->expects($this->once())->method('mockFunction')->with('Test Return Value')->will($this->returnValue('My Expected Return Value'));
     $this->assertThat(JHtml::_('file.testfunction', 'Test Return Value'), $this->equalTo('My Expected Return Value'));
     // we unregister the method to return to our original state
     JHtml::unregister('prefix.file.testfunction');
     // now we test with a class that will be found in the expected file
     JHtml::addIncludePath(array(JPATH_BASE . '/tests/unit/suite/libraries/joomla/html/htmltests'));
     $this->assertThat(JHtml::_('mocktest.method1', 'argument1', 'argument2'), $this->equalTo('JHtml Mock Called'));
     $this->assertThat(JHtmlMockTest::$arguments[0], $this->equalTo(array('argument1', 'argument2')));
     JHtmlMockTest::$arguments = array();
     $this->saveErrorHandlers();
     $mock1 = $this->getMock('errorCallback', array('error1', 'error2', 'error3'));
     JError::setErrorHandling(E_ERROR, 'callback', array($mock1, 'error1'));
     $mock1->expects($this->once())->method('error1');
     // we ensure that we get an error if we can find the file but the file does not contain the class
     $this->assertThat(JHtml::_('mocktest2.function1'), $this->isFalse());
     JError::setErrorHandling(E_ERROR, 'callback', array($mock1, 'error2'));
     $mock1->expects($this->once())->method('error2');
     // we ensure that we get an error if we can't find the file
     $this->assertThat(JHtml::_('mocktestnotthere.function1'), $this->isFalse());
     JError::setErrorHandling(E_ERROR, 'callback', array($mock1, 'error3'));
     $mock1->expects($this->once())->method('error3');
     // we ensure that we get an error if we have the class but not the method
     $this->assertThat(JHtml::_('mocktest.nomethod'), $this->isFalse());
     // restore our error handlers
     $this->setErrorHandlers($this->savedErrorState);
 }
Esempio n. 2
0
	public static function method1()
	{
		if(!isset(self::$arguments)) {
			self::$arguments = array(func_get_args());
		} else {
			self::$arguments[] = func_get_args();
		}

		if(isset(self::$returnValue)) {
			return self::$returnValue;
		} else {
			return 'JHtml Mock Called';
		}
	}