Ejemplo n.º 1
0
 /**
  * Test the unregister method.
  *
  * @return  void
  *
  * @since   11.1
  */
 public function testUnregister()
 {
     // Register a method so we can unregister it
     $registered = $this->getMock('MyHtmlClass', array('mockFunction'));
     JHtml::register('prefix.unregister.testfunction', array($registered, 'mockFunction'));
     $this->assertThat(JHtml::unregister('prefix.unregister.testfunction'), $this->isTrue(), 'The method was not unregistered.');
     $this->assertThat(JHtml::unregister('prefix.unregister.testkeynotthere'), $this->isFalse(), 'Unregistering a missing method should fail.');
 }
Ejemplo n.º 2
0
	/**
	 * testIsRegistered().
	 */
	public function testIsRegistered()
	{
		$registered = $this->getMock('MyHtmlClass', array('mockFunction'));

		// test that we can register the method
		JHtml::register('prefix.file.testfunction', array($registered, 'mockFunction'));

		$this->assertThat(
			JHtml::isRegistered('prefix.file.testfunction'),
			$this->isTrue(),
			'Function is not registered'
		);

		JHtml::unregister('prefix.file.testfunction');

		$this->assertThat(
			JHtml::isRegistered('prefix.file.testfunction'),
			$this->isFalse(),
			'Function is registered'
		);
	}
Ejemplo n.º 3
0
 /**
  * Test...
  *
  * @return void
  */
 public function testGetInputUser_UTC()
 {
     // We create stubs for config and session/user objects
     $config = new JObject();
     // Put the stub in place
     JFactory::$config = $config;
     $sessionMock = $this->getMock('sessionMock', array('get'));
     require_once JPATH_PLATFORM . '/joomla/user/user.php';
     $userObject = new JUser();
     $sessionMock->expects($this->any())->method('get')->with('user')->will($this->returnValue($userObject));
     // Put the stub in place
     JFactory::$session = $sessionMock;
     $languageMock = $this->getMock('languageMock', array('getTag'));
     $languageMock->expects($this->any())->method('getTag')->will($this->returnValue('en-GB'));
     // Put the stub in place
     JFactory::$language = $languageMock;
     // Include our inspector which will allow us to manipulate and call protected methods and attributes
     require_once __DIR__ . '/inspectors/JFormFieldCalendar.php';
     $calendar = new JFormFieldCalendarInspector();
     // Setup our values from our data set
     $calendar->setProtectedProperty('element', array('format' => '%m-%Y-%d', 'size' => '25', 'maxlength' => '45', 'class' => 'myClass', 'readonly' => 'true', 'disabled' => 'false', 'onchange' => '', 'filter' => 'USER_UTC'));
     $calendar->setProtectedProperty('name', 'myElementName');
     $calendar->setProtectedProperty('id', 'myElementId');
     // 1269442718
     $calendar->setProtectedProperty('value', 1269442718);
     // +4
     $config->set('offset', 'Asia/Muscat');
     // We don't set the user param to see if it properly falls back to the server time (as it should)
     // Create the mock to implant into JHtml so that we can check our values
     $mock = $this->getMock('calendarHandler', array('calendar'));
     // Setup the expectation with the values from the dataset
     $mock->expects($this->once())->method('calendar')->with('2010-03-24 18:58:38', 'myElementName', 'myElementId', '%m-%Y-%d', array('size' => '25', 'maxlength' => '45', 'class' => 'myClass', 'readonly' => 'readonly'));
     // Register our mock with JHtml
     JHtml::register('calendar', array($mock, 'calendar'));
     // Invoke our method
     $calendar->getInput();
     // Unregister the mock
     JHtml::unregister('jhtml..calendar');
     // Create the mock to implant into JHtml so that we can check our values
     $mock2 = $this->getMock('calendarHandler', array('calendar'));
     // Setup the expectation with the values from the dataset
     $mock2->expects($this->once())->method('calendar')->with('2010-03-24 22:58:38', 'myElementName', 'myElementId', '%m-%Y-%d', array('size' => '25', 'maxlength' => '45', 'class' => 'myClass', 'readonly' => 'readonly'));
     // -5
     $config->set('offset', 'US/Eastern');
     // +4		// now we set the user param to test it out.
     $userObject->setParam('timezone', 'Asia/Muscat');
     // Register our mock with JHtml
     JHtml::register('calendar', array($mock2, 'calendar'));
     // Invoke our method
     $calendar->getInput();
     // Unregister the mock
     JHtml::unregister('jhtml..calendar');
 }
Ejemplo n.º 4
0
 /**
  * Test...
  *
  * @return void
  */
 public function testGetInputUser_UTC()
 {
     // Create a stub JConfig
     $config = new JObject();
     // Put the stub in place
     JFactory::$config = $config;
     $sessionMock = $this->getMock('sessionMock', array('get'));
     $userObject = new JUser();
     $sessionMock->expects($this->any())->method('get')->with('user')->will($this->returnValue($userObject));
     // Put the stub in place
     JFactory::$session = $sessionMock;
     // Instantiate the calendar field
     $calendar = new JFormFieldCalendar();
     // Setup our values from our data set
     TestReflection::setValue($calendar, 'id', 'myElementId');
     TestReflection::setValue($calendar, 'name', 'myElementName');
     TestReflection::setValue($calendar, 'format', '%m-%Y-%d');
     TestReflection::setValue($calendar, 'size', 25);
     TestReflection::setValue($calendar, 'maxlength', 45);
     TestReflection::setValue($calendar, 'class', 'myClass');
     TestReflection::setValue($calendar, 'readonly', true);
     TestReflection::setValue($calendar, 'disabled', false);
     TestReflection::setValue($calendar, 'onchange', '');
     TestReflection::setValue($calendar, 'filter', 'USER_UTC');
     // 1269442718
     TestReflection::setValue($calendar, 'value', 1269442718);
     // +4
     $config->set('offset', 'Asia/Muscat');
     // We don't set the user param to see if it properly falls back to the server time (as it should)
     // Create the mock to implant into JHtml so that we can check our values
     $mock = $this->getMock('calendarHandler', array('calendar'));
     // Setup the expectation with the values from the dataset
     $mock->expects($this->once())->method('calendar')->with('2010-03-24 18:58:38', 'myElementName', 'myElementId', '%m-%Y-%d', array('size' => 25, 'maxlength' => 45, 'class' => 'myClass', 'readonly' => 'readonly'));
     // Register our mock with JHtml
     JHtml::register('calendar', array($mock, 'calendar'));
     // Invoke our method
     TestReflection::invoke($calendar, 'getInput');
     // Unregister the mock
     JHtml::unregister('jhtml..calendar');
     // Create the mock to implant into JHtml so that we can check our values
     $mock2 = $this->getMock('calendarHandler', array('calendar'));
     // Setup the expectation with the values from the dataset
     $mock2->expects($this->once())->method('calendar')->with('2010-03-24 22:58:38', 'myElementName', 'myElementId', '%m-%Y-%d', array('size' => 25, 'maxlength' => 45, 'class' => 'myClass', 'readonly' => 'readonly'));
     // -5
     $config->set('offset', 'US/Eastern');
     // +4		// now we set the user param to test it out.
     $userObject->setParam('timezone', 'Asia/Muscat');
     // Register our mock with JHtml
     JHtml::register('calendar', array($mock2, 'calendar'));
     // Invoke our method
     TestReflection::invoke($calendar, 'getInput');
     // Unregister the mock
     JHtml::unregister('jhtml..calendar');
 }