/**
  * 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();
 }
	/**
	 * 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;
	}
Beispiel #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();
 }
 /**
  * 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);
 }
Beispiel #5
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();
 }
 /**
  * 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 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();
 }
 /**
  * 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');
 }
 /**
  * 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;
 }
 /**
  * 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.
 }
Beispiel #14
0
 /**
  * Prepares the environment before running a test.
  *
  * @return  void
  *
  * @since   1.0
  *
  */
 protected function setUp()
 {
     parent::setUp();
     $this->saveFactoryState();
     JFactory::$session = $this->getMockSession();
     JFactory::$application = MockWebServiceApplicationWeb::create($this);
     $options = array('driver' => 'sqlite', 'database' => ':memory:', 'prefix' => 'ws_');
     $driver = JDatabaseDriver::getInstance($options);
     $pdo = new PDO('sqlite::memory:');
     $pdo->exec(file_get_contents(JPATH_TESTS . '/schema/ws.sql')) or die(print_r($pdo->errorInfo()));
     TestReflection::setValue($driver, 'connection', $pdo);
     JFactory::$database = $driver;
     $this->_instance = new WebServiceModelBase(new JContentFactory(), $driver);
     $this->_state = TestReflection::invoke($this->_instance, 'getState');
 }
 /**
  * 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();
     }
 }
Beispiel #16
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);
 }
 /**
  * @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);
 }
 /**
  * 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);
 }
Beispiel #19
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;
 }
Beispiel #20
0
 /**
  * Tests the populateState method.
  *
  * @since   3.4
  *
  * @return  void
  *
  * @testdox populateState() returns 0 without an applied context
  */
 public function testPopulateStateReturnsZeroWithoutContext()
 {
     $method = new ReflectionMethod('JModelList', 'populateState');
     $method->setAccessible(true);
     TestReflection::setValue($this->object, 'context', false);
     TestReflection::setValue($this->object, '__state_set', true);
     $method->invoke($this->object);
     $this->assertEquals(0, $this->object->getState('list.start'));
     $this->assertEquals(0, $this->object->getState('list.limit'));
 }
 /**
  * Tests the authenticate method
  *
  * @param   array    $token    The passed token.
  * @param   boolean  $fail     Mark if should fail or not.
  * @param   string   $version  Specify oauth version 1.0 or 1.0a.
  *
  * @return  void
  *
  * @dataProvider seedAuthenticate
  * @since   13.1
  */
 public function testAuthenticate($token, $fail, $version)
 {
     // Already got some credentials stored?
     if (!is_null($token)) {
         $this->object->setToken($token);
         $result = $this->object->authenticate();
         $this->assertEquals($result, $token);
     } else {
         $this->object->setOption('requestTokenURL', 'https://example.com/request_token');
         $this->object->setOption('authoriseURL', 'https://example.com/authorize');
         $this->object->setOption('accessTokenURL', 'https://example.com/access_token');
         // Request token.
         $returnData = new stdClass();
         $returnData->code = 200;
         $returnData->body = 'oauth_token=token&oauth_token_secret=secret&oauth_callback_confirmed=true';
         $this->client->expects($this->at(0))->method('post')->with($this->object->getOption('requestTokenURL'))->will($this->returnValue($returnData));
         $input = TestReflection::getValue($this->object, 'input');
         TestReflection::setValue($this->object, 'input', $input);
         if (strcmp($version, '1.0a') === 0) {
             $this->object->setOption('callback', 'TEST_URL');
         }
         $this->object->authenticate();
         $token = $this->object->getToken();
         $this->assertEquals($token['key'], 'token');
         $this->assertEquals($token['secret'], 'secret');
         // Access token.
         $input = TestReflection::getValue($this->object, 'input');
         if (strcmp($version, '1.0a') === 0) {
             TestReflection::setValue($this->object, 'version', $version);
             $data = array('oauth_verifier' => 'verifier', 'oauth_token' => 'token');
         } else {
             TestReflection::setValue($this->object, 'version', $version);
             $data = array('oauth_token' => 'token');
         }
         TestReflection::setValue($input, 'data', $data);
         // Get mock session
         $mockSession = $this->getMock('JSession', array('_start', 'get'));
         if ($fail) {
             $mockSession->expects($this->at(0))->method('get')->with('key', null, 'oauth_token')->will($this->returnValue('bad'));
             $mockSession->expects($this->at(1))->method('get')->with('secret', null, 'oauth_token')->will($this->returnValue('session'));
             JFactory::$session = $mockSession;
             $this->setExpectedException('DomainException');
             $result = $this->object->authenticate();
         }
         $mockSession->expects($this->at(0))->method('get')->with('key', null, 'oauth_token')->will($this->returnValue('token'));
         $mockSession->expects($this->at(1))->method('get')->with('secret', null, 'oauth_token')->will($this->returnValue('secret'));
         JFactory::$session = $mockSession;
         $returnData = new stdClass();
         $returnData->code = 200;
         $returnData->body = 'oauth_token=token_key&oauth_token_secret=token_secret';
         $this->client->expects($this->at(0))->method('post')->with($this->object->getOption('accessTokenURL'))->will($this->returnValue($returnData));
         $result = $this->object->authenticate();
         $this->assertEquals($result['key'], 'token_key');
         $this->assertEquals($result['secret'], 'token_secret');
     }
 }
 /**
  * @testdox Test an exception isn't thrown when the postflight method returns false
  * 
  * @covers  JInstallerAdapter::triggerManifestScript
  */
 public function testTriggerManifestScriptPostflightReturningFalseDoesNotThrowAnException()
 {
     $mockInstaller = $this->getMock('JInstaller', array('set'));
     $mockDatabase = $this->getMockDatabase();
     $object = $this->getMockForAbstractClass('JInstallerAdapter', array($mockInstaller, $mockDatabase));
     $mockScript = $this->getMock('DummyScript', array('preflight', 'postflight', 'install', 'uninstall', 'update'));
     TestReflection::setValue($object, 'route', 'uninstall');
     $mockScript->expects($this->once())->method('postflight')->with('uninstall', $object)->willReturn(false);
     $mockInstaller->manifestClass = $mockScript;
     $this->assertTrue(TestReflection::invoke($object, 'triggerManifestScript', 'postflight'));
 }
 /**
  * Tests the JApplicationWeb::setHeader method.
  *
  * @return  void
  *
  * @since   11.3
  */
 public function testSetHeader()
 {
     // Fill the header body with an arbitrary value.
     TestReflection::setValue($this->class, 'response', (object) array('cachable' => null, 'headers' => array(array('name' => 'foo', 'value' => 'bar')), 'body' => null));
     $this->class->setHeader('foo', 'car');
     $this->assertEquals(array(array('name' => 'foo', 'value' => 'bar'), array('name' => 'foo', 'value' => 'car')), TestReflection::getValue($this->class, 'response')->headers);
     $this->class->setHeader('foo', 'car', true);
     $this->assertEquals(array(array('name' => 'foo', 'value' => 'car')), TestReflection::getValue($this->class, 'response')->headers);
 }
 /**
  * Tests the JDatabaseDriver::quoteName method.
  *
  * @return  void
  *
  * @since   11.4
  */
 public function testQuoteName()
 {
     $this->assertThat($this->db->quoteName('test'), $this->equalTo('[test]'), 'Tests the left-right quotes on a string.');
     $this->assertThat($this->db->quoteName('a.test'), $this->equalTo('[a].[test]'), 'Tests the left-right quotes on a dotted string.');
     $this->assertThat($this->db->quoteName(array('a', 'test')), $this->equalTo(array('[a]', '[test]')), 'Tests the left-right quotes on an array.');
     $this->assertThat($this->db->quoteName(array('a.b', 'test.quote')), $this->equalTo(array('[a].[b]', '[test].[quote]')), 'Tests the left-right quotes on an array.');
     $this->assertThat($this->db->quoteName(array('a.b', 'test.quote'), array(null, 'alias')), $this->equalTo(array('[a].[b]', '[test].[quote] AS [alias]')), 'Tests the left-right quotes on an array.');
     $this->assertThat($this->db->quoteName(array('a.b', 'test.quote'), array('alias1', 'alias2')), $this->equalTo(array('[a].[b] AS [alias1]', '[test].[quote] AS [alias2]')), 'Tests the left-right quotes on an array.');
     $this->assertThat($this->db->quoteName((object) array('a', 'test')), $this->equalTo(array('[a]', '[test]')), 'Tests the left-right quotes on an object.');
     TestReflection::setValue($this->db, 'nameQuote', '/');
     $this->assertThat($this->db->quoteName('test'), $this->equalTo('/test/'), 'Tests the uni-quotes on a string.');
 }
 /**
  * Tests the JDatabaseQuery::unionAll method.
  *
  * @return  void
  *
  * @since   13.1
  */
 public function testUnionAllTwo()
 {
     TestReflection::setValue($this->_instance, 'unionAll', null);
     $this->_instance->unionAll('SELECT name FROM foo');
     $this->_instance->unionAll('SELECT name FROM bar');
     $teststring = (string) TestReflection::getValue($this->_instance, 'unionAll');
     $this->assertThat($teststring, $this->equalTo(PHP_EOL . "UNION ALL (SELECT name FROM foo)" . PHP_EOL . "UNION ALL (SELECT name FROM bar)"), 'Tests rendered query with two union alls sequentially.');
 }
 /**
  * Test JPathway::setItemName().
  *
  * @return  void
  *
  * @since   3.1
  */
 public function testSetItemName()
 {
     $pathway = array();
     $object1 = new stdClass();
     $object1->name = 'Item1';
     $object1->link = 'index.php?key=item1';
     $pathway[] = $object1;
     $object2 = new stdClass();
     $object2->name = 'Item2';
     $object2->link = 'index.php?key=item2';
     $pathway[] = $object2;
     TestReflection::setValue($this->fixture, '_pathway', $pathway);
     $this->assertTrue($this->fixture->setItemName(1, 'Item3'));
     $pathway[1]->name = 'Item3';
     $this->assertThat(TestReflection::getValue($this->fixture, '_pathway'), $this->equalTo($pathway));
     $this->assertFalse($this->fixture->setItemName(3, 'False'));
     $this->assertThat(TestReflection::getValue($this->fixture, '_pathway'), $this->equalTo($pathway));
 }
Beispiel #27
0
 /**
  * Test JViewLegacy::_addPath()
  *
  * @since   11.3
  *
  * @return  void
  */
 public function test_addPath()
 {
     $ds = DIRECTORY_SEPARATOR;
     // Reset the internal _path property so we can track it more easily.
     TestReflection::setValue($this->class, '_path', array('helper' => array(), 'template' => array()));
     TestReflection::invoke($this->class, '_addPath', 'template', JPATH_ROOT . $ds . 'libraries');
     $this->assertAttributeEquals(array('helper' => array(), 'template' => array(realpath(JPATH_ROOT . $ds . 'libraries') . $ds)), '_path', $this->class);
     TestReflection::invoke($this->class, '_addPath', 'helper', realpath(JPATH_ROOT . $ds . 'tests'));
     $this->assertAttributeEquals(array('helper' => array(realpath(JPATH_ROOT . $ds . 'tests') . $ds), 'template' => array(realpath(JPATH_ROOT . $ds . 'libraries') . $ds)), '_path', $this->class);
     TestReflection::invoke($this->class, '_addPath', 'template', realpath(JPATH_ROOT . $ds . 'tests'));
     $this->assertAttributeEquals(array('helper' => array(realpath(JPATH_ROOT . $ds . 'tests') . $ds), 'template' => array(realpath(JPATH_ROOT . $ds . 'tests') . $ds, realpath(JPATH_ROOT . $ds . 'libraries') . $ds)), '_path', $this->class);
     TestReflection::invoke($this->class, '_addPath', 'helper', realpath(JPATH_ROOT . $ds . 'libraries'));
     $this->assertAttributeEquals(array('helper' => array(realpath(JPATH_ROOT . $ds . 'libraries') . $ds, realpath(JPATH_ROOT . $ds . 'tests') . $ds), 'template' => array(realpath(JPATH_ROOT . $ds . 'tests') . $ds, realpath(JPATH_ROOT . $ds . 'libraries') . $ds)), '_path', $this->class);
 }
 /**
  * Tests the JApplicationWeb::setHeader method.
  *
  * @return  void
  *
  * @since   11.3
  */
 public function testSetHeader()
 {
     // Fill the header body with an arbitrary value.
     TestReflection::setValue($this->class, 'response', (object) array('cachable' => null, 'headers' => array(array('name' => 'foo', 'value' => 'bar')), 'body' => null));
     $this->class->setHeader('foo', 'car');
     $this->assertThat(TestReflection::getValue($this->class, 'response')->headers, $this->equalTo(array(array('name' => 'foo', 'value' => 'bar'), array('name' => 'foo', 'value' => 'car'))), 'Tests that a header is added.');
     $this->class->setHeader('foo', 'car', true);
     $this->assertThat(TestReflection::getValue($this->class, 'response')->headers, $this->equalTo(array(array('name' => 'foo', 'value' => 'car'))), 'Tests that headers of the same name are replaced.');
 }
Beispiel #29
0
 /**
  * Tests the getDb method.
  *
  * @return  void
  *
  * @since   12.1
  */
 public function testGetDb()
 {
     // Reset the db property to a known value.
     TestReflection::setValue($this->_instance, 'db', 'foo');
     $this->assertEquals('foo', $this->_instance->getDb());
 }
Beispiel #30
0
 /**
  * Tests the `rebuild` method.
  *
  * @return  void
  *
  * @since   12.1
  */
 public function testRebuild()
 {
     // Reset the nested set metrics.
     self::$driver->setQuery('UPDATE #__categories SET lft = 0, rgt = 0')->execute();
     // Rebuild the whole tree.
     TestReflection::setValue($this->class, '_cache', array());
     $this->class->rebuild();
     $nodes = self::$driver->setQuery('SELECT id, lft, rgt, level, path FROM #__categories')->loadRowList(0);
     // Level 0 root node.
     $this->assertEquals(array('1', '0', '15', '0', ''), $nodes[1], 'Checks node 001.');
     // Level 1 nodes.
     $this->assertEquals(array('101', '1', '2', '1', 'node101'), $nodes[101], 'Checks node 101.');
     $this->assertEquals(array('102', '3', '8', '1', 'node102'), $nodes[102], 'Checks node 102.');
     $this->assertEquals(array('103', '9', '14', '1', 'node103'), $nodes[103], 'Checks node 103.');
     // Level 2 nodes.
     $this->assertEquals(array('201', '4', '5', '2', 'node102/node201'), $nodes[201], 'Checks node 201.');
     $this->assertEquals(array('202', '6', '7', '2', 'node102/node202'), $nodes[202], 'Checks node 202.');
     $this->assertEquals(array('203', '10', '11', '2', 'node103/node203'), $nodes[203], 'Checks node 203.');
     $this->assertEquals(array('204', '12', '13', '2', 'node103/node204'), $nodes[204], 'Checks node 204.');
     // Rebuild with a base path.
     TestReflection::setValue($this->class, '_cache', array());
     $this->class->rebuild(null, 0, 0, 'base');
     $nodes = self::$driver->setQuery('SELECT id, lft, rgt, level, path FROM #__categories')->loadRowList(0);
     $this->assertEquals(array('204', '12', '13', '2', 'base/node103/node204'), $nodes[204], 'Checks node 204 with new base.');
     // Simulate where the 'ordering' field is available.
     self::$driver->setQuery('ALTER TABLE #__categories ADD ordering INTEGER')->execute();
     $this->class->ordering = null;
     TestReflection::setValue($this->class, '_cache', array());
     $this->assertEquals(16, $this->class->rebuild(), 'Checks rebuild with ordering.');
     // Reset the root node.
     self::$driver->setQuery('UPDATE #__categories SET parent_id = 99, lft = 99, rgt = 99 WHERE id = 1')->execute();
     $this->class->resetRootId();
     TestReflection::setValue($this->class, '_cache', array());
     $this->assertFalse($this->class->rebuild(), 'Checks failure where no root node is found.');
 }