I would like to know if it is possible to run PHPUnit tests silently and to show results manualy ?
Here is my file (this is the first time I use xUNIT tests) :
https://github.com/martin-damien/sarkum/blob/b3951f6fd89b788d9abc51467a62271f32d12b8c/classes/Character.php
Am I doing it right ?
As I'm running this code inside a CMS I can't allow the tests to display something on screen out of my control...
Could someone help me please ?
I found something :
ob_start();
$result = PHPUnit_TextUI_TestRunner::run( $suite );
$buffer = ob_get_contents();
ob_end_clean();
And I just have to send $buffer to my template :)
Related
I need get pagenumber of thread in my plugin in vbulletin. my plugin code is:
global $vbulletin, $threadinfo, $bloginfo, $pagetitle;
if (THIS_SCRIPT == 'showthread'){
$customTitle = $pagetitle.'-'.$pagenumber;
}
$rows = <<<ROW
<meta property="og:title" content="$customTitle" />
ROW;
$template_hook['headinclude_bottom_css'] .= $rows;
how can I get pagenumber of thread value for set $pagenumber?
I know that the template is as follows:
{vb:rawphrase page_x, {vb:raw pagenumber}}
But I need this in plugin.
You should declare $pagenumber global, too
global $pagenumber;
if (THIS_SCRIPT == 'showthread'){
echo '<!-- pageNumber: ' . $pagenumber . ' -->';
}
Placed in showthread_start hook, this gave me the following output: <!-- pageNumber: 9 -->
But please note that if you load the plugin code in some global avaliable hook like global_start, those thread-variables may not be avaliable because they got initialized later in vBulletin's code. In this case, try choosing some other hook, that runs earlier. Here, try and error helps.
I'd recommend trying some POC code in showthread_start to make sure it works. Then change the hooks to find out which is early enough for your planned action and that contains all required variables. Sometimes it's also usefull to see the vB code around a hook.
You could use e.g. grep in the root of a vBulletin installation to find where global_start is executed:
# grep -rn --include \*.php "fetch_hook('global_start')" .
./global.php:29:($hook = vBulletinHook::fetch_hook('global_start')) ? eval($hook) : false;
Its also possible to search on a Windows system with tools like Notepad++ (search in files).
I have existing Firefox session with appropriate login data to interesting site. Now I want to use it with Selenium and Perl.
I am using this code:
my $driver = Selenium::Remote::Driver->new;
$driver->get("http://www.google.com");
$driver->find_element('q','name')->send_keys("Hello WebDriver!");
print $driver->get_title() . "\n";
But this code opens new blank session of Firefox.
How can I use my existing session with already set up cookies?
You want to specify a Firefox profile to use.
In Java, it'd be something like this...
ProfilesIni profile = new ProfilesIni();
FirefoxProfile firefoxProfile = profile.getProfile("Default"); // might need to switch this around depending on what it actually is named.
WebDriver driver = new FirefoxDriver(firefoxProfile);
(credit to this answer for the pseudo-code)
I think you can try with this option in perl driver.
my $handles = $driver->get_window_handles;
$driver->switch_to_window($handles->[1]);
$driver->close;
$driver->switch_to_window($handles->[0]);
I didn't use it, but may be it will help you!
For more information, please refer to this site.
https://metacpan.org/pod/Selenium::Remote::Driver
Just started learning PHP today. And though I moved through most of my problems quickly, I got stumped with this one.
I have a main page page.php with a dynamic require_once to pull up content. I got the main part working, which is page.php?id=1 page.php?id=2 etc load just fine, but if somebody goes to just page.php without the ID, then there are errors that ruin the page. Now I figured out how to repress the errors with an # and I can also obviously set the links to the page to page?if=default, but I really need a solution to having page.php load content specific to it without errors. Or, perhaps, automatically redirect page.php to page.php?id=default should no id be provided.
The code I current am using for the require_once is:
<?php require_once('folder/' . $_GET['id'] . '.html');?>
Thank you for your help!
Well easiest way would be to check if you have an ID and if not, than just set default one, something like that:
$default = 1;
$id = ($_GET['id'] && is_numeric($_GET['id'])) ? $_GET['id'] : $default;
require_once('folder/' . $id . '.html');
When using ZFDebug, is it possible to add custom messages to the 'Log' tab?
So you could use something like:
$this->log('Error: Couldn't find the user');
Has anyone managed to achieve this?
I have never used ZFDebug before and wasn't aware of it. Your post piqued my interest, so I installed it and have been trying to achieve what you want to do. I will probably add it to my dev toolbox as I use ZF a lot.
You can achieve what you want by using the mark() method of ZFDebug_Controller_Plugin_Debug_Plugin_Log which takes two arguments. The first is the message you want to send and the second is a boolean which, when set to true (default is false), will send your message to the 'log' tab.
The following code worked for me:-
$debug = Zend_Controller_Front::getInstance()
->getPlugin('ZFDebug_Controller_Plugin_Debug');
$logger = $debug->getPlugin('log');
$logger->mark('Logging a message now', true);
Or to use your example (with the syntax error fixed :) )
$logger->mark("Error: Couldn't find the user", true);
As you can see this produced the desired output:-
Not quite as simple as you wanted, I know, but it's close and you could always wrap it in a function.
the thing is these this lines:
$loginUrl = $this->view->url(array('controller'=>'auth', 'action'=>'index'));
$registerUrl = $this->view->url(array('controller'=>'register', 'action'=>'index'));
based on rob allens' Zend_Auth login/logout tutorial (win7/apache),
are placed in a view helper, and this one:
echo $this->url(array('controller'=>'index','action'=>'add'));
is placed in the index view script.
The generated links Do work fine in LOCAL, but in REMOTE only the 3rd line works.
ANY IDEAS? Where should i look for this? wich way to follow?
I was tempt to think in the remote server conf but the 3rd line works fine, so..
thanks!
Try this helper instead of view Zend_Controller_Action_Helper_Url:
//simple($action, $controller = null, $module = null, array $params = null)
//so your lines will look like:
$loginUrl = $this->_helper->url->simple('index','auth');
$registerUrl = $this->_helper->url->simple('index','register');
P.S. your lines work properly on Win7 and Ubuntu servers check registry of the lines
I found out that was the server. (.htacces and mod_rewrite) was not included in the package.
I think the third line was working because it was in the index controller, but when calling the others, then happened the object not found.
To work out this, i found an example using zend debug (was in german) so i inferred it (and then wrote to the hosting service), but still not quite sure how to check (phpinfo?) if a host have this features available or not in your package.