/**
  * Test JModelAdmin::__construct
  *
  * @since   3.4
  *
  * @return  void
  *
  * @testdox Constructor applies default configuration
  */
 public function testConstructorAppliesDefaultConfiguration()
 {
     $config = array('event_after_delete' => 'onContentAfterDelete', 'event_after_save' => 'onContentAfterSave', 'event_before_delete' => 'onContentBeforeDelete', 'event_before_save' => 'onContentBeforeSave', 'event_change_state' => 'onContentChangeState', 'text_prefix' => 'COM_MOCK_J');
     foreach ($config as $key => $value) {
         $this->assertEquals($value, TestReflection::getValue($this->object, $key));
     }
 }
 /**
  * Test JPathway::getInstance().
  *
  * @return  void
  */
 public function testGetInstance()
 {
     $current = TestReflection::getValue('JApplicationHelper', '_clients');
     // Test Client
     $obj = new stdClass();
     $obj->id = 0;
     $obj->name = 'inspector';
     $obj->path = JPATH_TESTS;
     $obj2 = new stdClass();
     $obj2->id = 1;
     $obj2->name = 'inspector2';
     $obj2->path = __DIR__ . '/stubs';
     TestReflection::setValue('JApplicationHelper', '_clients', array($obj, $obj2));
     $pathway = JPathway::getInstance('Inspector');
     $this->assertThat(get_class($pathway), $this->equalTo('JPathwayInspector'));
     $this->assertThat(JPathway::getInstance('Inspector'), $this->equalTo($pathway));
     $pathway = JPathway::getInstance('Inspector2');
     $this->assertThat(get_class($pathway), $this->equalTo('JPathwayInspector2'));
     $ret = true;
     try {
         JPathway::getInstance('Error');
     } catch (Exception $e) {
         $ret = false;
     }
     if ($ret) {
         $this->fail('JPathway did not throw proper exception upon false client.');
     }
     TestReflection::setValue('JApplicationHelper', '_clients', $current);
 }
Example #3
0
 /**
  * Tears down the fixture, for example, closes a network connection.
  * This method is called after a test is executed.
  *
  * @return  void
  *
  * @since   3.0
  */
 protected function tearDown()
 {
     TestReflection::setValue('JComponentHelper', 'components', array());
     // Restore the state
     $this->restoreFactoryState();
     parent::tearDown();
 }
 /**
  * Tests the JImage::__construct method.
  *
  * @return  void
  *
  * @since   11.4
  */
 public function testConstructor()
 {
     // Create a image handle of the correct size.
     $imageHandle = imagecreatetruecolor(100, 100);
     $filter = new JImageFilterBrightness($imageHandle);
     $this->assertEquals(TestReflection::getValue($filter, 'handle'), $imageHandle);
 }
Example #5
0
 /**
  * Test the JInput::parseArguments method.
  *
  * @dataProvider provider_parseArguments
  */
 public function test_parseArguments($inputArgv, $expectedData, $expectedArgs)
 {
     $_SERVER['argv'] = $inputArgv;
     $this->inspector = new JInputCLI(null, array('filter' => new JFilterInputMock()));
     $this->assertThat(TestReflection::getValue($this->inspector, 'data'), $this->identicalTo($expectedData));
     $this->assertThat(TestReflection::getValue($this->inspector, 'args'), $this->identicalTo($expectedArgs));
 }
 /**
  * Overrides the parent tearDown method.
  *
  * @return  void
  *
  * @see     PHPUnit_Framework_TestCase::tearDown()
  * @since   11.1
  */
 protected function tearDown()
 {
     // Reset the dispatcher instance.
     TestReflection::setValue('JEventDispatcher', 'instance', null);
     TestReflection::setValue('JPluginHelper', 'plugins', null);
     parent::tearDown();
 }
Example #7
0
	/**
	 * Creates and instance of the mock JController object.
	 *
	 * @param   object  $test  A test object.
	 *
	 * @return  object
	 *
	 * @since   12.1
	 */
	public static function create($test)
	{
		// Collect all the relevant methods in JController.
		$methods = array(
			'execute',
			'getApplication',
			'getInput',
			'serialize',
			'unserialize',
		);

		// Create the mock.
		$mockObject = $test->getMock(
			'JControllerBase',
			$methods,
			// Constructor arguments.
			array(),
			// Mock class name.
			'',
			// Call original constructor.
			false
		);

		// TODO  Mock the input.
		TestReflection::setValue($mockObject, 'input', new JInput);

		return $mockObject;
	}
Example #8
0
 /**
  * Overrides the parent tearDown method.
  *
  * @return  void
  *
  * @see     PHPUnit_Framework_TestCase::tearDown()
  * @since   11.1
  */
 protected function tearDown()
 {
     $this->restoreFactoryState();
     // Reset the dispatcher instance.
     TestReflection::setValue('JPluginHelper', 'plugins', null);
     parent::tearDown();
 }
 /**
  * Overrides the parent tearDown method.
  *
  * @return  void
  *
  * @see     PHPUnit_Framework_TestCase::tearDown()
  * @since   11.1
  */
 protected function tearDown()
 {
     // Reset the loaded plugins.
     TestReflection::setValue('JPluginHelper', 'plugins', null);
     $this->restoreFactoryState();
     $_SERVER = $this->backupServer;
     parent::tearDown();
 }
Example #10
0
 /**
  * Tests the extractCustom Method.
  *
  * @return  void
  */
 public function testExtractCustom()
 {
     if (!JArchiveZip::isSupported()) {
         $this->markTestSkipped('ZIP files can not be extracted.');
     }
     TestReflection::invoke($this->object, 'extractCustom', __DIR__ . '/logo.zip', $this->outputPath);
     $this->assertFileExists($this->outputPath . '/logo-zip.png');
 }
 /**
  * Overrides the parent tearDown method.
  *
  * @return  void
  *
  * @see     PHPUnit_Framework_TestCase::tearDown()
  * @since   3.6
  */
 protected function tearDown()
 {
     // Reset the dispatcher instance.
     TestReflection::setValue('JEventDispatcher', 'instance', null);
     $_SERVER = $this->backupServer;
     $this->restoreFactoryState();
     parent::tearDown();
 }
 /**
  * Test the getInput method where there is no value from the element
  * and no checked attribute.
  *
  * @param   array   $data  	   @todo
  * @param   string  $expected  @todo
  *
  * @return  void
  *
  * @since   12.2
  *
  * @dataProvider  getInputData
  */
 public function testGetInput($data, $expected)
 {
     $formField = new JFormFieldEmail();
     foreach ($data as $attr => $value) {
         TestReflection::setValue($formField, $attr, $value);
     }
     $this->assertEquals($expected, TestReflection::invoke($formField, 'getInput'), 'Line:' . __LINE__ . ' The field with no value and no checked attribute did not produce the right html');
 }
 /**
  * Overrides TestCaseCache::testCacheTimeout to deal with the adapter's stored time values in this test
  *
  * @testdox  The cache handler correctly handles expired cache data
  *
  * @medium
  */
 public function testCacheTimeout()
 {
     /** @var Cache_Lite $cacheLiteInstance */
     $cacheLiteInstance = TestReflection::getValue('JCacheStorageCachelite', 'CacheLiteInstance');
     $cacheLiteInstance->_lifeTime = 0.1;
     // For parent class
     $this->handler->_lifetime =& $cacheLiteInstance->_lifeTime;
     parent::testCacheTimeout();
 }
Example #14
0
 /**
  * Overrides the parent tearDown method.
  *
  * @return  void
  *
  * @see     PHPUnit_Framework_TestCase::tearDown()
  * @since   11.1
  */
 protected function tearDown()
 {
     // Reset the dispatcher instance.
     TestReflection::setValue('JEventDispatcher', 'instance', null);
     // Reset the loaded plugins.
     TestReflection::setValue('JPluginHelper', 'plugins', null);
     $_SERVER = $this->backupServer;
     parent::tearDown();
 }
Example #15
0
 /**
  * Test the getInput method where there is no value from the element.
  *
  * @param   array   $data  	   @todo
  * @param   string  $expected  @todo
  *
  * @return  void
  *
  * @since   12.2
  *
  * @dataProvider  getInputData
  */
 public function testGetInput($data, $expected)
 {
     $formField = new JFormFieldTel();
     TestReflection::setValue($formField, 'element', simplexml_load_string('<field type="tel" />'));
     foreach ($data as $attr => $value) {
         TestReflection::setValue($formField, $attr, $value);
     }
     $this->assertEquals($expected, TestReflection::invoke($formField, 'getInput'), 'Line:' . __LINE__ . ' The field did not produce the right html');
 }
 /**
  * Test the getInput method.
  * @covers JFormFieldTemplateStyle::getGroups
  */
 public function testGetInput()
 {
     $form = new JForm('form1');
     $this->assertThat($form->load('<form><field name="templatestyle" type="templatestyle" /></form>'), $this->isTrue(), 'Line:' . __LINE__ . ' XML string should load successfully.');
     $field = new JFormFieldTemplatestyle($form);
     $this->assertThat($field->setup(TestReflection::getValue($form, 'xml')->field, 'value'), $this->isTrue(), 'Line:' . __LINE__ . ' The setup method should return true.');
     $this->markTestIncomplete('Problems encountered in next assertion');
     $this->assertThat(strlen($field->input), $this->greaterThan(0), 'Line:' . __LINE__ . ' The getInput method should return something without error.');
     // TODO: Should check all the attributes have come in properly.
 }
 /**
  * Overrides TestCaseCache::testCacheTimeout to deal with the adapter's stored time values in this test
  *
  * @testdox  The cache handler correctly handles expired cache data
  *
  * @medium
  */
 public function testCacheTimeout()
 {
     /** @var Cache_Lite $cacheLiteInstance */
     $cacheLiteInstance = TestReflection::getValue('JCacheStorageCachelite', 'CacheLiteInstance');
     $cacheLiteInstance->_lifeTime = 2;
     $data = 'testData';
     $this->assertTrue($this->handler->store($this->id, $this->group, $data), 'Initial Store Failed');
     sleep(5);
     $this->assertFalse($this->handler->get($this->id, $this->group), 'No data should be returned from the cache store when expired.');
 }
Example #18
0
 /**
  * Creates and instance of the mock JController object.
  *
  * @param   object  $test  A test object.
  *
  * @return  object
  *
  * @since   12.1
  */
 public static function create($test)
 {
     // Collect all the relevant methods in JController.
     $methods = array('execute', 'getApplication', 'getInput', 'serialize', 'unserialize');
     // Create the mock.
     $mockObject = $test->getMock('JControllerBase', $methods, array(), '', false);
     // TODO  Mock the input.
     TestReflection::setValue($mockObject, 'input', new JInput());
     return $mockObject;
 }
 /**
  * Tests the extractCustom Method.
  *
  * @return  void
  */
 public function testExtractCustom()
 {
     if (!JArchiveZip::isSupported()) {
         $this->markTestSkipped('ZIP files can not be extracted.');
         return;
     }
     TestReflection::invoke($this->object, 'extractCustom', __DIR__ . '/logo.zip', static::$outputPath);
     $this->assertTrue(is_file(static::$outputPath . '/logo-zip.png'));
     if (is_file(static::$outputPath . '/logo-zip.png')) {
         unlink(static::$outputPath . '/logo-zip.png');
     }
 }
Example #20
0
 /**
  * Test the getInput method where there is no value from the element
  * and no checked attribute.
  *
  * @param   string  $element   @todo
  * @param   array   $data  	   @todo
  * @param   string  $expected  @todo
  *
  * @return  void
  *
  * @since   12.2
  *
  * @dataProvider  getInputData
  */
 public function testGetInput($element, $data, $expected)
 {
     $formField = new JFormFieldRadio();
     TestReflection::setValue($formField, 'element', simplexml_load_string($element));
     foreach ($data as $attr => $value) {
         TestReflection::setValue($formField, $attr, $value);
     }
     // Get the result once, we may perform multiple tests
     $result = TestReflection::invoke($formField, 'getInput');
     // Test that the tag exists
     $matcher = array('id' => 'myTestId');
     $this->assertTag($matcher, $result, 'The tag did not have the correct id.');
 }
 /**
  * Test the getInput method.
  *
  * @return  void
  *
  * @since   11.4
  */
 public function testGetInput()
 {
     $formField = new JFormFieldPlugins();
     TestReflection::setValue($formField, 'id', 'myTestId');
     TestReflection::setValue($formField, 'name', 'editors');
     TestReflection::setValue($formField, 'folder', 'editors');
     TestReflection::setValue($formField, 'element', simplexml_load_string('<field name="editors" type="plugins" folder="editors" />'));
     if (!is_null(self::$driver)) {
         $this->assertThat(strlen($formField->input), $this->greaterThan(0), 'Line:' . __LINE__ . ' The getInput method should return something without error.');
     } else {
         $this->markTestSkipped();
     }
     // TODO: Should check all the attributes have come in properly.
 }
 /**
  * Sets up the fixture, for example, opens a network connection.
  * This method is called before a test is executed.
  *
  * @return  void
  */
 protected function setUp()
 {
     if (!JCacheStorageRedis::isSupported()) {
         $this->markTestSkipped('The Redis cache handler is not supported on this system.');
     }
     parent::setUp();
     $this->handler = new JCacheStorageRedis();
     // This adapter doesn't throw an Exception on a connection failure so we'll have to use Reflection to get into the class to check it
     if (!TestReflection::getValue($this->handler, '_redis') instanceof Redis) {
         $this->markTestSkipped('Failed to connect to Redis');
     }
     // Override the lifetime because the JCacheStorage API multiplies it by 60 (converts minutes to seconds)
     $this->handler->_lifetime = 2;
 }
 /**
  * Test the getInput method.
  *
  * @return  void
  *
  * @since   12.1
  */
 public function testGetInput()
 {
     $formField = new JFormFieldSQL();
     TestReflection::setValue($formField, 'id', 'myTestId');
     TestReflection::setValue($formField, 'name', 'sql');
     TestReflection::setValue($formField, 'valueField', 'title');
     TestReflection::setValue($formField, 'keyField', 'id');
     TestReflection::setValue($formField, 'query', "SELECT * FROM `jos_categories`");
     TestReflection::setValue($formField, 'element', simplexml_load_string('<field name="sql" type="sql" value_field="title" key_field="id" query="SELECT * FROM `jos_categories`">' . '<option value="*">None</option></field>'));
     if (!is_null(self::$driver)) {
         $this->assertThat(strlen($formField->input), $this->greaterThan(0), 'Line:' . __LINE__ . ' The getInput method should return something without error.');
     } else {
         $this->markTestSkipped();
     }
 }
 /**
  * Sets up the fixture, for example, opens a network connection.
  * This method is called before a test is executed.
  *
  * @return  void
  */
 protected function setUp()
 {
     if (!JCacheStorageRedis::isSupported()) {
         $this->markTestSkipped('The Redis cache handler is not supported on this system.');
     }
     parent::setUp();
     // Mock the returns on JApplicationCms::get() to use the default values
     JFactory::$application->expects($this->any())->method('get')->willReturnArgument(1);
     $this->handler = new JCacheStorageRedis();
     // This adapter doesn't throw an Exception on a connection failure so we'll have to use Reflection to get into the class to check it
     if (!TestReflection::getValue($this->handler, '_redis') instanceof Redis) {
         $this->markTestSkipped('Failed to connect to Redis');
     }
     // Override the lifetime because the JCacheStorage API multiplies it by 60 (converts minutes to seconds)
     $this->handler->_lifetime = 2;
 }
 /**
  * @covers  JErrorPage::render
  *
  * @requires  PHP 7.0
  */
 public function testEnsureTheErrorPageIsCorrectlyRenderedWithThrowables()
 {
     $documentResponse = '<title>500 - Testing JErrorPage::render() with PHP 7 Error</title>Testing JErrorPage::render() with PHP 7 Error';
     $key = serialize(array('error', array('charset' => 'utf-8', 'lineend' => 'unix', 'tab' => "\t", 'language' => 'en-GB', 'direction' => 'ltr')));
     $mockErrorDocument = $this->getMockBuilder('JDocumentError')->setMethods(array('setError', 'setTitle', 'render'))->getMock();
     $mockErrorDocument->expects($this->any())->method('render')->willReturn($documentResponse);
     TestReflection::setValue('JDocument', 'instances', array($key => $mockErrorDocument));
     // Create an Error to inject into the method
     $exception = new Error('Testing JErrorPage::render() with PHP 7 Error', 500);
     // The render method echoes the output, so catch it in a buffer
     ob_start();
     JErrorPage::render($exception);
     $output = ob_get_clean();
     // Validate the mocked response from JDocument was received
     $this->assertEquals($documentResponse, $output);
 }
Example #26
0
 /**
  * @covers  JErrorPage::render
  */
 public function testEnsureTheErrorPageIsCorrectlyRendered()
 {
     $documentResponse = '<title>500 - Testing JErrorPage::render()</title>';
     $key = serialize(array('error', array()));
     $mockErrorDocument = $this->getMockBuilder('JDocumentError')->setMethods(array('setError', 'setTitle', 'render'))->getMock();
     $mockErrorDocument->expects($this->any())->method('render')->willReturn($documentResponse);
     TestReflection::setValue('JDocument', 'instances', array($key => $mockErrorDocument));
     // Create an Exception to inject into the method
     $exception = new RuntimeException('Testing JErrorPage::render()', 500);
     // The render method echoes the output, so catch it in a buffer
     ob_start();
     JErrorPage::render($exception);
     $output = ob_get_clean();
     // Validate the mocked response from JDocument was received
     $this->assertEquals($documentResponse, $output);
 }
 /**
  * Test the JLoggerDatabase::addEntry method.
  */
 public function testAddEntry02()
 {
     // Setup the logger.
     $config = array('db_driver' => 'sqlite', 'db_database' => ':memory:', 'db_prefix' => 'jos_');
     $logger = new JLoggerDatabase($config);
     TestReflection::setValue($logger, 'dbo', JFactory::$database);
     // Get the expected database from XML.
     $expected = $this->createXMLDataSet(__DIR__ . '/stubs/database/S01E01.xml');
     // Add the new entries to the database.
     $logger->addEntry(new JLogEntry('Testing Entry 02', JLog::INFO, null, '2009-12-01 12:30:00'));
     $logger->addEntry(new JLogEntry('Testing3', JLog::EMERGENCY, 'deprecated', '2010-12-01 02:30:00'));
     // Get the actual dataset from the database.
     $actual = new PHPUnit_Extensions_Database_DataSet_QueryDataSet($this->getConnection());
     $actual->addTable('jos_log_entries');
     // Verify that the data sets are equal.
     $this->assertDataSetsEqual($expected, $actual);
 }
Example #28
0
 /**
  * This method is called before the first test of this test class is run.
  *
  * @return  void
  *
  * @since   12.1
  */
 public static function setUpBeforeClass()
 {
     // We always want the default database test case to use an SQLite memory database.
     $options = array('driver' => 'sqlite', 'database' => ':memory:', 'prefix' => 'jos_');
     try {
         // Attempt to instantiate the driver.
         self::$driver = JDatabaseDriver::getInstance($options);
         // Create a new PDO instance for an SQLite memory database and load the test schema into it.
         $pdo = new PDO('sqlite::memory:');
         $pdo->exec(file_get_contents(JPATH_TESTS . '/schema/ddl.sql'));
         // Set the PDO instance to the driver using reflection whizbangery.
         TestReflection::setValue(self::$driver, 'connection', $pdo);
     } catch (RuntimeException $e) {
         self::$driver = null;
     }
     // If for some reason an exception object was returned set our database object to null.
     if (self::$driver instanceof Exception) {
         self::$driver = null;
     }
     // Setup the factory pointer for the driver and stash the old one.
     self::$_stash = JFactory::$database;
     JFactory::$database = self::$driver;
 }
 /**
  * Tests the _generateRequestToken method - failure
  *
  * @return  void
  *
  * @since   13.1
  * @expectedException DomainException
  */
 public function testGenerateRequestTokenFailure()
 {
     $this->object->setOption('requestTokenURL', 'https://example.com/request_token');
     $returnData = new stdClass();
     $returnData->code = 200;
     $returnData->body = 'oauth_token=token&oauth_token_secret=secret&oauth_callback_confirmed=false';
     $this->client->expects($this->at(0))->method('post')->with($this->object->getOption('requestTokenURL'))->will($this->returnValue($returnData));
     TestReflection::invoke($this->object, '_generateRequestToken');
 }
 /**
  * Tests the setMethodInPostRequest and isMethodInPostRequest.
  *
  * @return  void
  *
  * @covers  JApplicationWebRouterRest::setMethodInPostRequest
  * @covers  JApplicationWebRouterRest::isMethodInPostRequest
  * @since   12.3
  */
 public function testMethodInPostRequest()
 {
     // Check the defaults
     $this->assertEquals(false, TestReflection::invoke($this->_instance, 'isMethodInPostRequest'));
     // Check setting true
     TestReflection::invoke($this->_instance, 'setMethodInPostRequest', true);
     $this->assertEquals(true, TestReflection::invoke($this->_instance, 'isMethodInPostRequest'));
     // Check setting false
     TestReflection::invoke($this->_instance, 'setMethodInPostRequest', false);
     $this->assertEquals(false, TestReflection::invoke($this->_instance, 'isMethodInPostRequest'));
 }