/**
  * Test JPathway::getInstance().
  *
  * @return  void
  *
  * @since   3.1
  */
 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('');
     $this->assertInstanceOf('JPathway', $pathway);
     $pathway = JPathway::getInstance('Inspector2');
     $this->assertInstanceOf('JPathwayInspector2', $pathway);
     $ret = true;
     try {
         JPathway::getInstance('Error');
     } catch (Exception $e) {
         $ret = false;
     }
     if ($ret) {
         $this->fail('JPathway did not throw a proper exception with a false client.');
     }
     TestReflection::setValue('JApplicationHelper', '_clients', $current);
 }
 /**
  * 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));
     }
 }
 /**
  * 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);
 }
 /**
  * Cache the JLoader settings while we are resetting things for testing.
  *
  * @return  void
  *
  * @since   12.3
  */
 public static function setUpBeforeClass()
 {
     self::$cache['classes'] = \TestReflection::getValue('JLoader', 'classes');
     self::$cache['imported'] = \TestReflection::getValue('JLoader', 'imported');
     self::$cache['prefixes'] = \TestReflection::getValue('JLoader', 'prefixes');
     self::$cache['namespaces'] = \TestReflection::getValue('JLoader', 'namespaces');
 }
Exemple #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 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();
 }
 /**
  * Tests the JApplicationBase::loadIdentity method.
  *
  * @return  void
  *
  * @since   12.1
  * @covers  JApplicationBase::loadIdentity
  */
 public function testLoadIdentity()
 {
     $this->class->loadIdentity($this->getMock('JUser', array(), array(), '', false));
     $this->assertAttributeInstanceOf('JUser', 'identity', $this->class, 'Tests that the identity object is the correct class.');
     // Mock the session.
     JFactory::$session = $this->getMockSession(array('get.user.id' => 99));
     $this->class->loadIdentity();
     $this->assertEquals(99, TestReflection::getValue($this->class, 'identity')->get('id'), 'Tests that we got the identity from the factory.');
 }
 /**
  * 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.');
 }
 /**
  * Tests the __construct method.
  *
  * @return  void
  *
  * @since   12.1
  */
 public function test__construct()
 {
     // New controller with no dependencies.
     $this->assertEquals('default', TestReflection::getValue($this->_instance, 'app')->input, 'Checks the mock application came from the factory.');
     $this->assertAttributeEquals('default', 'input', $this->_instance, 'Checks the input came from the application.');
     // New controller with dependencies
     $app = TestMockApplicationWeb::create($this);
     $app->test = 'ok';
     $class = new BaseController(new JInputCookie(), $app);
     $this->assertAttributeInstanceOf('JInputCookie', 'input', $class, 'Checks the type of the injected input.');
     $this->assertAttributeSame($app, 'app', $class, 'Checks the injected application.');
 }
 /**
  * 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;
 }
 /**
  * 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;
 }
Exemple #13
0
 /**
  * Tests JUser::load().
  *
  * @param   integer  $id        User ID to load
  * @param   boolean  $expected  Expected result of load operation
  * @param   boolean  $isGuest   Boolean marking an user as guest
  *
  * @return  void
  *
  * @since   12.1
  *
  * @dataProvider casesLoad
  * @covers  JUser::load
  */
 public function testLoad($id, $expected, $isGuest)
 {
     $testUser = new JUser($id);
     $this->assertThat($testUser->load($id), $this->equalTo($expected));
     $this->assertThat($isGuest, $this->equalTo(TestReflection::getValue($testUser, 'guest')));
 }
 /**
  * Tests the JLoader::setup method with $enablePrefixes = false.
  *
  * @return  void
  *
  * @since   12.3
  */
 public function testSetupWithoutPrefixes()
 {
     // Reset the prefixes.
     TestReflection::setValue('JLoader', 'prefixes', array());
     // We unregister all loader functions if registered.
     $this->unregisterLoaders();
     // Setup the loader with $enablePrefixes = false.
     JLoader::setup(false, false, true);
     // Get the autoload functions
     $loaders = spl_autoload_functions();
     $foundAutoLoad = false;
     // We search the list of autoload functions to see if our methods are there.
     foreach ($loaders as $loader) {
         if (is_array($loader) && $loader[0] === 'JLoader') {
             if ($loader[1] === '_autoload') {
                 $foundAutoLoad = true;
             }
         }
     }
     // We don't expect to find it.
     $this->assertFalse($foundAutoLoad);
     // Assert the J prefix hasn't been registered.
     $prefixes = TestReflection::getValue('JLoader', 'prefixes');
     $this->assertFalse(isset($prefixes['J']));
 }
 /**
  * Tests JFeedFactory::registerParser()
  *
  * @return  void
  *
  * @expectedException  InvalidArgumentException
  * @since              12.3
  */
 public function testRegisterParserWithInvalidTag()
 {
     TestReflection::setValue($this->_instance, 'parsers', array());
     $this->_instance->registerParser('42tag', 'JFeedParserMock');
     $this->assertNotEmpty(TestReflection::getValue($this->_instance, 'parsers'));
 }
 /**
  * Tests the setHttpMethodSuffix method.
  *
  * @return  void
  *
  * @covers  JApplicationWebRouterRest::setHttpMethodSuffix
  * @since   12.3
  */
 public function testSetHttpMethodSuffix()
 {
     $this->_instance->setHttpMethodSuffix('FOO', 'Bar');
     $s = TestReflection::getValue($this->_instance, 'suffixMap');
     $this->assertEquals('Bar', $s['FOO']);
 }
 /**
  * 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);
 }
 /**
  * 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));
 }
 /**
  * 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.');
 }
 /**
  * Tests the `debug` method.
  *
  * @return  void
  *
  * @since   12.1
  */
 public function testDebug()
 {
     $this->class->debug(99);
     $this->assertEquals(99, TestReflection::getValue($this->class, '_debug'));
 }
Exemple #21
0
 /**
  * Test getExpire()
  *
  * @covers  JSession::getExpire
  *
  * @return void
  */
 public function testGetExpire()
 {
     $this->assertEquals(TestReflection::getValue($this->object, '_expire'), $this->object->getExpire(), 'Session expire time should be the same');
 }
Exemple #22
0
 /**
  * This method tests the set method.
  *
  * @param   integer  $property  The property to set
  * @param   string   $value     The value of the property to set
  * @param   array    $expected  The expected results for the JPagination object
  *
  * @return  void
  *
  * @covers        JPagination::set
  * @dataProvider  dataSet
  * @since         3.2
  */
 public function testSet($property, $value, $expected)
 {
     $pagination = new JPagination(100, 50, 20, '', $this->app);
     $pagination->set($property, $value);
     if ($property == 'viewall') {
         $result = TestReflection::getValue($pagination, $property);
     } elseif (strpos($property, '.')) {
         $prop = explode('.', $property);
         $prop[1] = ucfirst($prop[1]);
         $property = implode($prop);
         $result = $pagination->{$property};
     } else {
         $result = $pagination->{$property};
     }
     $this->assertEquals($result, $expected, 'The expected output of the property is incorrect');
     unset($pagination);
 }
Exemple #23
0
 /**
  * Tests the getItems method.
  *
  * @since   3.4
  *
  * @return  void
  *
  * @testdox getItems() stores result in object cache
  */
 public function testGetItemsStoresItemsInObjectCache()
 {
     $object = new ListModelTest();
     // Don't run populateState as this blows up
     TestReflection::setValue($object, '__state_set', true);
     $object->setState('list.start', 0);
     $object->setState('list.limit', 1);
     $object->getItems();
     $objectCache = TestReflection::getValue($object, 'cache');
     $this->assertArrayHasKey('ecbe76894d32ce7af659e46be7f2a9f0', $objectCache);
     $this->assertEquals(array((object) array("id" => 1)), $objectCache['ecbe76894d32ce7af659e46be7f2a9f0']);
 }
	/**
	 * Method to test JStringInflector::addSingulariseRule().
	 *
	 * @return  void
	 *
	 * @since   12.1
	 * @covers  JStringInflector::addSingulariseRule
	 */
	public function testAddSingulariseRule()
	{
		$chain = $this->inflector->addSingulariseRule(array('/foo/', '/bar/'));

		$this->assertThat(
			$chain,
			$this->identicalTo($this->inflector),
			'Checks chaining.'
		);

		$rules = TestReflection::getValue($this->inflector, '_rules');

		$this->assertThat(
			in_array('/bar/', $rules['singular']),
			$this->isTrue(),
			'Checks a singularisation rule was added.'
		);
	}
 /**
  * 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.');
 }
 /**
  * Tests the withStructure method.
  *
  * @return  void
  *
  * @since   3.4
  */
 public function testWithStructure()
 {
     $instance = new JDatabaseExporterPdomysql();
     $result = $instance->withStructure();
     $this->assertThat($result, $this->identicalTo($instance), 'withStructure must return an object to support chaining.');
     $options = TestReflection::getValue($instance, 'options');
     $this->assertThat($options->withStructure, $this->isTrue(), 'The default use of withStructure should result in true.');
     $instance->withStructure(true);
     $options = TestReflection::getValue($instance, 'options');
     $this->assertThat($options->withStructure, $this->isTrue(), 'The explicit use of withStructure with true should result in true.');
     $instance->withStructure(false);
     $options = TestReflection::getValue($instance, 'options');
     $this->assertThat($options->withStructure, $this->isFalse(), 'The explicit use of withStructure with false should result in false.');
 }
 /**
  * @testdox Test setting a string as the route
  * 
  * @covers  JInstallerAdapter::setRoute
  */
 public function testSetRoute()
 {
     $mockInstaller = $this->getMock('JInstaller');
     $mockDatabase = $this->getMockDatabase();
     $object = $this->getMockForAbstractClass('JInstallerAdapter', array($mockInstaller, $mockDatabase));
     $this->assertEquals('install', TestReflection::getValue($object, 'route'), 'The default route of JInstallerAdapter should be "install"');
     $this->assertInstanceOf('JInstallerAdapter', $object->setRoute('update'), 'JInstallerAdapter::setRoute() should return an instance of itself');
     $this->assertEquals('update', TestReflection::getValue($object, 'route'), 'The route was not set correctly as a class variable');
 }
Exemple #28
0
 /**
  * Tests the __construct()
  *
  * @return  void
  *
  * @since   3.2
  */
 public function test__construct()
 {
     $object = new JUcmBase('com_content.article');
     $this->assertInstanceOf('JUcmType', TestReflection::getValue($object, 'type'), 'Ensure the type property is an instance of JUcmType');
 }
 /**
  * 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');
     }
 }
 /**
  * Tests the JApplicationBase::loadIdentity and JApplicationBase::getIdentity methods.
  *
  * @return  void
  *
  * @since   12.3
  */
 public function testLoadGetIdentity99()
 {
     // Mock the session.
     JFactory::$session = $this->getMockSession(array('get.user.id' => 99));
     $this->class->loadIdentity();
     $this->assertEquals(99, TestReflection::getValue($this->class, 'identity')->get('id'), 'Tests that we got the identity from the factory.');
 }