/** * 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'); }
/** * 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'); }
/** * 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'); }
/** * 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'); } }
/** * 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.'); }
/** * Tests the add method * * @param mixed $recipient Either a string or array of strings [email address(es)] * @param mixed $name Either a string or array of strings [name(s)] * @param string $method The parent method's name. * @param array $expected The expected array. * * @covers JMail::add * @dataProvider seedTestAdd * * @return void */ public function testAdd($recipient, $name, $method, $expected) { TestReflection::invoke($this->object, 'add', $recipient, $name, $method); switch ($method) { case 'AddAddress': $type = 'to'; break; case 'AddCC': $type = 'cc'; break; case 'AddBCC': $type = 'bcc'; break; case 'AddReplyTo': $type = 'ReplyTo'; break; } $this->assertThat($expected, $this->equalTo(TestReflection::getValue($this->object, $type))); }
/** * Test the JInput::serialize method. * * @return void * * @since 12.1 */ public function testSerialize() { // Load the inputs so that the static $loaded is set to true. TestReflection::invoke($this->class, 'loadAllInputs'); // Adjust the values so they are easier to handle. TestReflection::setValue($this->class, 'inputs', array('server' => 'remove', 'env' => 'remove', 'request' => 'keep')); TestReflection::setValue($this->class, 'options', 'options'); TestReflection::setValue($this->class, 'data', 'data'); $this->assertThat($this->class->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";}}')); }
/** * Test the getOptions method. * * @since 12.2 * * @return void */ public function testGetOptions() { $formFieldCheckboxes = new JFormFieldCheckboxes(); $option1 = new stdClass(); $option1->value = 'yellow'; $option1->text = 'yellow'; $option1->disable = true; $option1->class = ''; $option1->onclick = ''; $option1->checked = false; $option1->onchange = ''; $option2 = new stdClass(); $option2->value = 'green'; $option2->text = 'green'; $option2->disable = false; $option2->class = ''; $option2->onclick = ''; $option2->checked = true; $option2->onchange = ''; $optionsExpected = array($option1, $option2); // Test with two values checked, no checked element TestReflection::setValue($formFieldCheckboxes, 'element', simplexml_load_string('<field name="color" type="checkboxes"> <option value="yellow" disabled="true">yellow</option> <option value="green" checked="true">green</option> </field>')); $this->assertEquals($optionsExpected, TestReflection::invoke($formFieldCheckboxes, 'getOptions'), 'The field with two values did not produce the right options'); }
/** * 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')); }
/** * Tests the JApplicationWebRouterBase::parseRoute method. * * @param string $r The route to parse. * @param boolean $e True if an exception is expected. * @param string $c The expected controller name. * @param array $i The expected input object data. * @param integer $m The map set to use for setting up the router. * * @return void * * @covers JApplicationWebRouterBase::parseRoute * @dataProvider getParseRouteData * @since 12.3 */ public function testParseRoute($r, $e, $c, $i, $m) { // Setup the router maps. $mapSetup = 'setMaps' . $m; $this->$mapSetup(); // If we should expect an exception set that up. if ($e) { $this->setExpectedException('InvalidArgumentException'); } // Execute the route parsing. $actual = TestReflection::invoke($this->_instance, 'parseRoute', $r); // Test the assertions. $this->assertEquals($c, $actual, 'Incorrect controller name found.'); $this->assertAttributeEquals($i, 'data', $this->_input, 'The input data is incorrect.'); }
/** * Tests the JApplicationWeb::render method. * * @return void * * @since 11.3 */ public function testRender() { $document = $this->getMockDocument(); $this->assignMockReturns($document, array('render' => 'JWeb Body')); // Manually inject the document. TestReflection::setValue($this->class, 'document', $document); TestReflection::invoke($this->class, 'render'); $this->assertEquals(array('JWeb Body'), TestReflection::getValue($this->class, 'response')->body); }
/** * Tests the `_runQuery` method. * * @return void * * @since 12.1 */ public function test_runQuery() { // Just run a valid query and then check for an exception case. TestReflection::invoke($this->class, '_runQuery', 'SELECT * FROM #__categories', 'foo'); try { // We need to confirm the locking is called, so we create a mock. $class = $this->getMock('NestedTable', array('_unlock'), array(self::$driver)); // Then override the _unlock method so we can test that it was called. $this->assignMockCallbacks($class, array('_unlock' => array('NestedTable', 'mockUnlock'))); // Reset the value to detect the change. NestedTable::$unlocked = false; TestReflection::invoke($class, '_runQuery', 'SELECT foo FROM #__categories', 'foo'); $this->fail('A RuntimeException was expected.'); } catch (RuntimeException $e) { $this->assertTrue(NestedTable::$unlocked); } }
/** * 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 JFeedFactory::_fetchFeedParser() * * @return void * * @expectedException LogicException * @since 12.3 */ public function test_fetchFeedParserWithInvalidTag() { TestReflection::invoke($this->_instance, '_fetchFeedParser', 'foobar', new XMLReader()); }
/** * Tests the loadPaths method. * * @return void * * @covers JViewHtml::loadPaths * @since 12.1 */ public function testLoadPaths() { $this->assertEquals(new SplPriorityQueue(), TestReflection::invoke($this->_instance, 'loadPaths')); }
/** * Test JController::addPath(). * * Note that addPath call JPath::check which will exit if the path is out of bounds. * If execution halts for some reason, a bad path could be the culprit. * * @since 11.3 * * @covers JController::addPath */ public function testAddPath() { $path = JPATH_ROOT . '//foobar'; TestReflection::invoke($this->class, 'addPath', 'test', $path); $paths = TestReflection::getValue($this->class, 'paths'); $this->assertTrue(is_array($paths['test']), 'The path type should be an array.'); $this->assertThat(str_replace(DIRECTORY_SEPARATOR, '/', $paths['test'][0]), $this->equalTo(str_replace(DIRECTORY_SEPARATOR, '/', JPATH_ROOT . '/foobar/')), 'Line:' . __LINE__ . ' The path type should be present, clean and with a trailing slash.'); }
/** * Tests the fetchController method without a prefix set. * * @return void */ public function testFetchControllerWithoutPrefixSet() { $this->assertInstanceOf('TControllerBar', TestReflection::invoke($this->_instance, 'fetchController', 'TControllerBar')); }
/** * 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 JFormFieldPassword(); foreach ($data as $attr => $value) { TestReflection::setValue($formField, $attr, $value); } $replaces = array("\n", "\r", " ", "\t"); $this->assertEquals(str_replace($replaces, '', $expected), str_replace($replaces, '', TestReflection::invoke($formField, 'getInput')), 'Line:' . __LINE__ . ' The field with no value and no checked attribute did not produce the right html'); }
/** * Tests the loadInput method. * * @return void * * @since 12.1 */ public function testLoadInput() { // Reset the input property so we know it changes based on the mock application. TestReflection::setValue($this->_instance, 'input', null); $this->assertEquals('default', TestReflection::invoke($this->_instance, 'loadInput')); }
/** * Tests the getRealTableName method with the wrong type of class. * * @return void * * @since 3.4 */ public function testGetRealTableName() { $instance = new JDatabaseImporterPdomysql(); $instance->setDbo($this->dbo); $this->assertThat(TestReflection::invoke($instance, 'getRealTableName', '#__test'), $this->equalTo('jos_test'), 'getRealTableName should return the name of the table with #__ converted to the database prefix.'); }
/** * Tests the loadDb method. * * @return void * * @since 12.1 */ public function testLoadDb() { JFactory::$database = 'database'; $this->assertEquals('database', TestReflection::invoke($this->_instance, 'loadDb')); }
/** * Tests JFeedParserRss::processPerson() * * @param string $input The person string consisting of name and email address. * @param string $name The person's name. * @param string $email The person's email address. * * @return void * * @dataProvider seedProcessPerson * @since 12.3 */ public function testProcessPerson($input, $name, $email) { $person = TestReflection::invoke($this->_instance, 'processPerson', $input); $this->assertInstanceOf('JFeedPerson', $person); $this->assertEquals($name, $person->name); $this->assertEquals($email, $person->email); }
/** * Test JPathway::makeItem(). * * @return void * * @since 3.1 */ public function testMakeItem() { $object = new stdClass(); $object->link = 'index.php?key=value1'; $object->name = 'Value1'; $this->assertThat(TestReflection::invoke($this->fixture, 'makeItem', 'Value1', 'index.php?key=value1'), $this->equalTo($object)); }
/** * Tests JFeedParser::moveToClosingElement() with self-closing tags. * * @return void * * @since 12.3 */ public function testMoveToClosingElementWithSelfClosingTag() { // Set the XML for the internal reader and move the stream to the first <node> element. $this->_reader->Xml('<root><node test="first" /><node test="second"></node></root>'); // Advance the reader to the first <node> element. do { $this->_reader->read(); } while ($this->_reader->name != 'node'); // Ensure that the current node is <node test="first">. $this->assertEquals(XMLReader::ELEMENT, $this->_reader->nodeType); $this->assertEquals('node', $this->_reader->name); $this->assertEquals('first', $this->_reader->getAttribute('test')); // Move to the closing element, which should be </node>. TestReflection::invoke($this->_instance, 'moveToClosingElement'); $this->assertEquals(true, $this->_reader->isEmptyElement); $this->assertEquals('node', $this->_reader->name); // Advance the reader to the next element. do { $this->_reader->read(); } while ($this->_reader->nodeType != XMLReader::ELEMENT); // Ensure that the current node is <node test="first">. $this->assertEquals(XMLReader::ELEMENT, $this->_reader->nodeType); $this->assertEquals('node', $this->_reader->name); $this->assertEquals('second', $this->_reader->getAttribute('test')); }
/** * Tests the JDatabaseDriver::getDatabase method. * * @return void * * @since 11.4 */ public function testGetDatabase() { $this->assertThat(TestReflection::invoke($this->db, 'getDatabase'), $this->equalTo('europa')); }
/** * This method tests the _buildDataObject method. * * @param integer $total The total number of items. * @param integer $limitstart The offset of the item to start at. * @param integer $limit The number of items to display per page. * @param integer $active The page number which contains the active pagination. * @param array $expected The expected results for the JPagination object * * @return void * * @dataProvider dataTestBuildDataObject * @covers JPagination::_buildDataObject * @since 3.2 */ public function testBuildDataObject($total, $limitstart, $limit, $active, $expected) { $pagination = new JPagination($total, $limitstart, $limit, '', $this->app); $object = TestReflection::invoke($pagination, '_buildDataObject'); // Test the view all Object $this->assertEquals((array) $object->all, $expected["0"], 'This is not the expected view all'); // Test the start Object $this->assertEquals((array) $object->start, $expected["1"], 'This is not the expected start'); // Test the previous Object $this->assertEquals((array) $object->previous, $expected["2"], 'This is not the expected previous'); // Test the next Object $this->assertEquals((array) $object->next, $expected["3"], 'This is not the expected next'); // Test the end Object $this->assertEquals((array) $object->end, $expected["4"], 'This is not the expected end'); // Test the active object $this->assertEquals((array) $object->pages[$active], $expected["5"], 'This is not the expected active'); unset($pagination); }
/** * @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')); }
/** * Method to test JStringInflector::_setCache(). * * @return void * * @since 12.1 * @covers JStringInflector::_setCache */ public function test_setCache() { TestReflection::invoke($this->inflector, '_setCache', 'foo', 'bar'); $cache = TestReflection::getValue($this->inflector, '_cache'); $this->assertThat( $cache['foo'], $this->equalTo('bar'), 'Checks the cache was set.' ); TestReflection::invoke($this->inflector, '_setCache', 'foo', 'car'); $cache = TestReflection::getValue($this->inflector, '_cache'); $this->assertThat( $cache['foo'], $this->equalTo('car'), 'Checks an existing value in the cache was reset.' ); }
/** * 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 method getGenericTableName method. * * @return void * * @since 3.4 */ public function testGetGenericTableName() { $instance = new JDatabaseExporterPdomysql(); $instance->setDbo($this->dbo); $this->assertThat(TestReflection::invoke($instance, 'getGenericTableName', 'jos_test'), $this->equalTo('#__test'), 'The testGetGenericTableName should replace the database prefix with #__.'); }