/** * Test the Joomla\Input\Files::decodeData method. * * @return void * * @covers Joomla\Input\Files::decodeData * @since 1.1.4 */ public function testDecodeData() { $instance = new Files(); $data = array('n', 'ty', 'tm', 'e', 's'); $decoded = TestHelper::invoke($instance, 'decodeData', $data); $expected = array('name' => 'n', 'type' => 'ty', 'tmp_name' => 'tm', 'error' => 'e', 'size' => 's'); $this->assertEquals($expected, $decoded); $dataArr = array('first', 'second'); $data = array($dataArr, $dataArr, $dataArr, $dataArr, $dataArr); $decoded = TestHelper::invoke($instance, 'decodeData', $data); $expectedFirst = array('name' => 'first', 'type' => 'first', 'tmp_name' => 'first', 'error' => 'first', 'size' => 'first'); $expectedSecond = array('name' => 'second', 'type' => 'second', 'tmp_name' => 'second', 'error' => 'second', 'size' => 'second'); $expected = array($expectedFirst, $expectedSecond); $this->assertEquals($expected, $decoded); }
/** * Tests the Joomla\Cache\File::isExpired method. * * @return void * * @covers Joomla\Cache\File::isExpired * @since 1.0 */ public function testIsExpired() { $this->instance->setOption('ttl', 1); $this->instance->set('foo', 'bar'); $fileName = TestHelper::invoke($this->instance, 'fetchStreamUri', 'foo'); touch($fileName, time() - 2); $this->assertTrue(TestHelper::invoke($this->instance, 'isExpired', 'foo'), 'Should be expired.'); $this->instance->setOption('ttl', 900); $this->instance->set('foo', 'bar'); $this->assertFalse(TestHelper::invoke($this->instance, 'isExpired', 'foo'), 'Should not be expired.'); }
/** * @testdox Verify that the initialized model is registered to the DI container * * @covers Joomla\Status\Controller\DefaultController::initializeModel */ public function testVerifyThatTheInitializedModelIsRegisteredToTheContainer() { TestHelper::invoke($this->object, 'initializeModel'); $this->assertInstanceOf('\\Joomla\\Status\\Model\\DefaultModel', $this->object->getContainer()->get('Joomla\\Model\\ModelInterface')); }
/** * Tests the Joomla\Cache\None::exists method. * * @return void * * @covers Joomla\Cache\None::exists * @since 1.0 */ public function testExists() { $this->assertFalse(TestHelper::invoke($this->instance, 'exists', 'foo')); $this->instance->set('foo', 'bar'); $this->assertFalse(TestHelper::invoke($this->instance, 'exists', 'foo')); }
/** * Test... * * @covers Joomla\Language\Language::getMetadata * * @return void * * @since 1.0 */ public function testGetMetadata() { // Language doesn't exist, retun NULL $this->assertNull(TestHelper::invoke($this->object, 'getMetadata', 'es-ES')); $localeString = 'en_GB.utf8, en_GB.UTF-8, en_GB, eng_GB, en, english, english-uk, uk, gbr, britain, england, great britain, ' . 'uk, united kingdom, united-kingdom'; // In this case, returns array with default language // - same operation of get method with metadata property $options = array('name' => 'English (United Kingdom)', 'tag' => 'en-GB', 'rtl' => '0', 'locale' => $localeString, 'firstDay' => '0'); // Language exists, returns array with values $this->assertEquals($options, TestHelper::invoke($this->object, 'getMetadata', 'en-GB')); }
/** * Tests the _generateRequestToken method - failure * * @return void * * @since 1.0 * @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)); TestHelper::invoke($this->object, '_generateRequestToken'); }
/** * @testdox Tests the system URIs are correctly loaded when a relative media URI is set in the application configuration * * @covers Joomla\Application\AbstractWebApplication::loadSystemUris * @uses Joomla\Application\AbstractApplication::get */ public function testLoadSystemUrisWithoutSiteUriWithRelativeMediaUriSet() { $mockInput = $this->getMock('Joomla\\Input\\Input', array('get', 'getString'), array(), '', true, true, true, false, true); $mockConfig = $this->getMock('Joomla\\Registry\\Registry', array('get', 'set'), array(array('media_uri' => '/media/')), '', true, true, true, false, true); // Mock the Input object internals $mockServerInput = $this->getMock('Joomla\\Input\\Input', array('get', 'set'), array(array('SCRIPT_NAME' => '/index.php')), '', true, true, true, false, true); $inputInternals = array('server' => $mockServerInput); TestHelper::setValue($mockInput, 'inputs', $inputInternals); $object = $this->getMockForAbstractClass('Joomla\\Application\\AbstractWebApplication', array($mockInput, $mockConfig)); TestHelper::invoke($object, 'loadSystemUris', 'http://joom.la/application'); $this->assertSame('http://joom.la/', $object->get('uri.base.full')); $this->assertSame('http://joom.la', $object->get('uri.base.host')); $this->assertSame('/', $object->get('uri.base.path')); $this->assertSame('http://joom.la/media/', $object->get('uri.media.full')); $this->assertSame('/media/', $object->get('uri.media.path')); }
/** * Test the Joomla\Input\Input::loadAllInputs method. * * @return void * * @covers Joomla\Input\Input::loadAllInputs * @since 1.1.4 */ public function testLoadAllInputs() { $instance = $this->getInputObject(array()); TestHelper::setValue($instance, 'loaded', false); $inputs = TestHelper::getValue($instance, 'inputs'); $this->assertCount(0, $inputs); TestHelper::invoke($instance, 'loadAllInputs'); $inputs = TestHelper::getValue($instance, 'inputs'); $this->assertGreaterThan(0, count($inputs)); }
/** * Method to test Inflector::setCache(). * * @return void * * @covers Joomla\String\Inflector::setCache * @since 1.0 */ public function testSetCache() { TestHelper::invoke($this->inflector, 'setCache', 'foo', 'bar'); $cache = TestHelper::getValue($this->inflector, 'cache'); $this->assertThat($cache['foo'], $this->equalTo('bar'), 'Checks the cache was set.'); TestHelper::invoke($this->inflector, 'setCache', 'foo', 'car'); $cache = TestHelper::getValue($this->inflector, 'cache'); $this->assertThat($cache['foo'], $this->equalTo('car'), 'Checks an existing value in the cache was reset.'); }
/** * Tests the Joomla\Cache\Cache::exists method. * * @return void * * @covers Joomla\Cache\Cache::exists * @covers Joomla\Cache\Memcached::exists * @since 1.1.3 */ public function testExists() { $cacheInstance = $this->instance; $cacheInstance->clear(); $this->assertFalse(TestHelper::invoke($cacheInstance, 'exists', 'foobar'), __LINE__); $this->assertTrue($cacheInstance->set('foobar', 'barfoo'), __LINE__); $this->assertTrue(TestHelper::invoke($cacheInstance, 'exists', 'foobar'), __LINE__); }
/** * Tests the loadPaths method. * * @return void * * @covers Joomla\View\AbstractHtmlView::loadPaths * @since 1.0 */ public function testLoadPaths() { $this->assertEquals(new \SplPriorityQueue(), TestHelper::invoke($this->instance, 'loadPaths')); }
/** * Test the getOptions method. * * @since 1.0 * * @return void */ public function testGetOptions() { $formFieldCheckboxes = new Field_Checkboxes(); $option1 = new \stdClass(); $option1->value = 'yellow'; $option1->text = 'yellow'; $option1->disable = false; $option1->class = ''; $option1->onclick = ''; $option2 = new \stdClass(); $option2->value = 'green'; $option2->text = 'green'; $option2->disable = false; $option2->class = ''; $option2->onclick = ''; $optionsExpected = array($option1, $option2); // Test with two values checked, no checked element TestHelper::setValue($formFieldCheckboxes, 'element', simplexml_load_string('<field name="color" type="checkboxes"> <option value="yellow">yellow</option> <option value="green">green</option> </field>')); $this->assertEquals($optionsExpected, TestHelper::invoke($formFieldCheckboxes, 'getOptions'), 'The field with two values did not produce the right options'); }
/** * Tests the setPoints method exception, when * an invalid point is passed. * * @return void * * @covers \Joomla\Profiler\Profiler::setPoints * @expectedException \InvalidArgumentException * @since 1.0 */ public function testSetPointsExceptionInvalid() { $first = new ProfilePoint('test'); $second = 0; TestHelper::invoke($this->instance, 'setPoints', array($first, $second)); }
/** * Test the Joomla\Input\Input::serialize method. * * @return void * * @covers Joomla\Input\Input::serialize * @since 1.0 */ public function testSerialize() { $instance = $this->getInputObject(array()); // Load the inputs so that the static $loaded is set to true. TestHelper::invoke($instance, 'loadAllInputs'); // Adjust the values so they are easier to handle. TestHelper::setValue($instance, 'inputs', array('server' => 'remove', 'env' => 'remove', 'request' => 'keep')); TestHelper::setValue($instance, 'options', 'options'); TestHelper::setValue($instance, 'data', 'data'); $this->assertThat($instance->serialize(), $this->equalTo('a:3:{i:0;s:7:"options";i:1;s:4:"data";i:2;a:1:{s:7:"request";s:4:"keep";}}')); }
/** * Tet the Joomla\Registry\Registry::bindData method. * * @return void * * @covers Joomla\Registry\Registry::bindData * @since 1.0 */ public function testBindData() { $a = new Registry(); $parent = new stdClass(); TestHelper::invoke($a, 'bindData', $parent, 'foo'); $this->assertThat($parent->{0}, $this->equalTo('foo'), 'Line: ' . __LINE__ . ' The input value should exist in the parent object.'); TestHelper::invoke($a, 'bindData', $parent, array('foo' => 'bar')); $this->assertThat($parent->{'foo'}, $this->equalTo('bar'), 'Line: ' . __LINE__ . ' The input value should exist in the parent object.'); TestHelper::invoke($a, 'bindData', $parent, array('level1' => array('level2' => 'value2'))); $this->assertThat($parent->{'level1'}->{'level2'}, $this->equalTo('value2'), 'Line: ' . __LINE__ . ' The input value should exist in the parent object.'); TestHelper::invoke($a, 'bindData', $parent, array('intarray' => array(0, 1, 2))); $this->assertThat($parent->{'intarray'}, $this->equalTo(array(0, 1, 2)), 'Line: ' . __LINE__ . ' The un-associative array should bind natively.'); }
/** * Tests the Joomla\Data\DataObject::dumpProperty method. * * @return void * * @covers Joomla\Data\DataObject::dumpProperty * @since 1.0 */ public function testDumpProperty() { $dumped = new \SplObjectStorage(); $this->instance->bind(array('dump_test' => 'dump_test_value')); $this->assertEquals('dump_test_value', TestHelper::invoke($this->instance, 'dumpProperty', 'dump_test', 3, $dumped)); }
/** * Tests the Joomla\Application\AbstractWebApplication::loadSystemUris method. * * @return void * * @since 1.0 */ public function testLoadSystemUrisWithoutSiteUriWithRelativeMediaUriSet() { // Set the media_uri value in the configuration. $config = new Registry(array('media_uri' => '/media/')); TestHelper::setValue($this->instance, 'config', $config); TestHelper::invoke($this->instance, 'loadSystemUris', 'http://joom.la/application'); $this->assertThat(TestHelper::getValue($this->instance, 'config')->get('uri.base.full'), $this->equalTo('http://joom.la/'), 'Checks the full base uri.'); $this->assertThat(TestHelper::getValue($this->instance, 'config')->get('uri.base.host'), $this->equalTo('http://joom.la'), 'Checks the base uri host.'); $this->assertThat(TestHelper::getValue($this->instance, 'config')->get('uri.base.path'), $this->equalTo('/'), 'Checks the base uri path.'); $this->assertThat(TestHelper::getValue($this->instance, 'config')->get('uri.media.full'), $this->equalTo('http://joom.la/media/'), 'Checks the full media uri.'); // Since this is on a different domain we need the full url for this too. $this->assertThat(TestHelper::getValue($this->instance, 'config')->get('uri.media.path'), $this->equalTo('/media/'), 'Checks the media uri path.'); }
/** * Test the getInput method where the field is disabled * * @return void * * @since 1.0 */ public function testGetInputDisabled() { $formField = new Field_Checkbox(); // Test with checked element $element = simplexml_load_string('<field name="color" type="checkbox" value="red" disabled="true" />'); TestHelper::setValue($formField, 'element', $element); TestHelper::setValue($formField, 'id', 'myTestId'); TestHelper::setValue($formField, 'name', 'myTestName'); $this->assertEquals('<input type="checkbox" name="myTestName" id="myTestId" value="red" disabled="disabled" />', TestHelper::invoke($formField, 'getInput'), 'The field set to disabled did not produce the right html'); }
/** * Tests the Joomla\Router\Router::fetchController method without a prefix set. * * @return void * * @covers Joomla\Router\Router::fetchController * @since 1.0 */ public function testFetchControllerWithoutPrefixSet() { $controller = TestHelper::invoke($this->instance, 'fetchController', 'TControllerBar'); }
/** * Tests the Joomla\Database\DatabaseDriver::getDatabase method. * * @return void * * @since 1.0 */ public function testGetDatabase() { $this->assertEquals('europa', TestHelper::invoke($this->instance, 'getDatabase')); }
/** * Tests the Joomla\Router\Router::parseRoute method. * * @param string $m The request method. * @param string $r The route to parse. * @param string|null $c The expected controller name or null if an exception is expected. * @param array $i The expected input object data. * * @return void * * @covers Joomla\Router\RestRouter::parseRoute * @dataProvider seedTestParseRoute * @since 1.0 */ public function testParseRoute($m, $r, $c, $i) { // Set reuqest method $_SERVER['REQUEST_METHOD'] = $m; // Setup the router maps. $this->instance->setControllerPrefix('\\Joomla\\Router\\Tests\\Stubs\\')->addMaps(array('articles/:article_id' => 'Goo')); // If we should expect an exception set that up. if (is_null($c)) { $this->setExpectedException('InvalidArgumentException'); } // Execute the route parsing. $actual = TestHelper::invoke($this->instance, 'parseRoute', $r); // Test the assertions. $this->assertEquals($c, $actual, 'Incorrect controller name found.'); }
/** * Test the cleanPath method. * * @return void * * @since __DEPLOY_VERSION__ * @covers Joomla\Uri\Uri::cleanPath */ public function testcleanPath() { $this->assertThat(TestHelper::invoke($this->object, 'cleanPath', '/foo/bar/../boo.php'), $this->equalTo('/foo/boo.php')); $this->assertThat(TestHelper::invoke($this->object, 'cleanPath', '/foo/bar/../../boo.php'), $this->equalTo('/boo.php')); $this->assertThat(TestHelper::invoke($this->object, 'cleanPath', '/foo/bar/.././/boo.php'), $this->equalTo('/foo/boo.php')); }
/** * Tests the Joomla\Cache\File::isExpired method. * * @return void * * @covers Joomla\Cache\File::isExpired * @since 1.0 */ public function testIsExpired() { $this->instance->setOption('ttl', 1); $this->instance->set('foo', 'bar'); sleep(2); $this->assertTrue(TestHelper::invoke($this->instance, 'isExpired', 'foo'), 'Should be expired.'); $this->instance->setOption('ttl', 900); $this->instance->set('foo', 'bar'); $this->assertFalse(TestHelper::invoke($this->instance, 'isExpired', 'foo'), 'Should not be expired.'); }