I'm learning PHPUNIT at the moment. It was getting interesting until i got stuck on something.
I "logged-in" it and went well,
But this PrintOut just displays. Is there anyway I could remove it?
Actually I just want to get the value of the Surname, FirstName and the the picture most importantly, the picture.
The picture is saved as /ImagePage.aspx. Is there a way in which I can download this and force close the browser because I don't know how to close the print Pop-out
The picture frame id is CandImg
This is my code:
<?php
class TestLogin extends PHPUnit_Extensions_Selenium2TestCase
{
public function setUp()
{
$this->setHost('localhost');
$this->setPort(4444);
$this->setBrowser('firefox');
$this->setBrowserUrl('http://localhost/tutor');
}
public function setSpeed($timeInMilliSec)
{
$this->setSpeed('120');
}
/*Function to locate website*/
public function testHasLoginForm()
{
$this->url('http://www.jamb.org.ng/DirectEntry/');/*This is the site*/
$username = $this->byId('ctl00_ContentPlaceHolder1_RegNumber');/*Search for a name*/
$this->assertContains('Reg.Number/PIN', $username->value());
##ctl00_ContentPlaceHolder1_txtRegNumber
$action = $this->byName('ctl00$ContentPlaceHolder1$Reprint')->attribute('action');
$this->byId('ctl00_ContentPlaceHolder1_RegNumber')->value('49003257DE');/*value of the textbox*/
$jump = $this->byName('ctl00$ContentPlaceHolder1$Reprint');
$this->byName('ctl00$ContentPlaceHolder1$Reprint')->click();
}
}
#to Save ImagePage.aspx
?>
Related
So i am experiencing a problem I should probably only be having on big pages but instead im getting that on ANY page.
I am trying to make a REST api using CodeIgniter and it works but any page I load is very very slow. I am talking 20-30 seconds page loads for a page worth 504 Bytes.
I've added extra benchmarks and it displays it takes roughly 0.04 sec to download the data.
Rankings.php (Controller)
class Rankings extends CI_Controller
{
public function __construct()
{
parent::__construct();
$this->load->model('rankingsmodel');
}
/**
* Index Page for this controller.
*/
public function index()
{
$this->benchmark->mark('code_start');
$rankings =$this->rankingsmodel->getAllRankings();
$mappedRankings = array_map(array($this, 'mapRank'), $rankings, array_keys($rankings));
$this->benchmark->mark('code_end');
echo $this->benchmark->elapsed_time('code_start', 'code_end');
return $this->jsonIFy($mappedRankings);
}
public function mapRank($ranking, $k)
{
$ranking['rank'] = $k;
return $ranking;
}
public function jsonIFy(array $data = array())
{
echo json_encode($data);
}
}
And my rankingsmodel
class RankingsModel extends CI_Model
{
public function __construct()
{
parent::__construct();
}
public function getAllRankings()
{
$this->benchmark->mark('code_start2');
$query =$this->db->query('SELECT * FROM characters3 WHERE gm < 3 ORDER BY rebirths DESC')->result_array();
$this->benchmark->mark('code_end2');
echo $this->benchmark->elapsed_time('code_start2', 'code_end2');
return $query;
}
}
I have absolutely no idea why page loads so incredibly slow while my benchmarks are saying it would take 0.03/0.04 to load. I've tried setting up xdebug but i've not had any luck setting it up. Im using regular mysqli drivers that come with codeigniter.
Does anyone have any idea why it is so slow or any tool i can setup easily to debug?
Thank you
Okay so after a few more hours of digging i have found the problem.
The problem is the following:
My database was getting retrieved very slowly (we have a demo on db4free or smth) and that is what was taking so long. We also had $db['default']['pconnect'] set to false which meant we had to constantly reconnect to the database.
For testing purposes setting pconnect to true will solve the issue. And oh: get a faster database for production.
I am developing an app where I need to log the proccess.
So I was loggin from main.php and now I need to log from another class (class_TestingLog.php)
Next code is how I am trying. Could you tell me what I am doing wrong?
Thank you in advance.
main.php
[...]
#Logging class
include_once("./classes/class_log.php");
$Class_Log = New Class_Log();
#TestingLog Class
include_once("./classes/class_testingLog.php");
$Class_TestingLog = New Class_TestingLog();
[...]
$Class_Log->FreeLog("Test log");
$Class_TestingLog->AnyFuncion();`
[...]
class_log.php
[...]
public function FreeLog($text)
{
// echo $text . "\n"; #mistake
$this->outputText .= text; #correct one
}
[...]
class_testingLog.php
private $Class_Log = '';
[...]
public function __construct()
{
#Requires
require_once("./classes/class_log.php");
$this->Class_Log = New Class_Log();
}
public function AnyFuncion()
{
var_dump($this); #From real file
$this->Class_Log->FreeLog("Test log from another classs");
}
[...]
Browser output
Test log
Browser output expected
Test log
Test log from another classs
===========================================================================
EDIT
I made an error copying FreeLog();
It stores the parameter string value into a private variable instead echo the variable.
You require_once statement inside __construct for Class_TestingLog is invalid and unnecessary. As both files are in the same directory it should be "class_log.php" not "./classes/class_log.php". There is no need for it anyway, as when you include them both in main.php it is loaded already. So try it without the require_once.
EDIT: As discussed in chat do it like this:
in main.php:
$Class_TestingLog = New Class_TestingLog($Class_Log);
in class_testingLog.php:
public function __construct($ClassLog)
{
$this->Class_Log = $ClassLog;
}
This will use the same instance inside the Class_TestingLog class as on the main.php.
I'm trying to integrate Fotolia Api with Prestashop 1.6.0.9.
I already make module with custom tab, but I have no idea how set view from module folder for this tab. Sorry to say, but "documentation for developers" SUCKS.
I can't find any working solution.
public function install() {
if (!parent::install()
|| !$this->registerHook('backOfficeHeader')
|| !$this->registerHook('header')
) return false;
$tab = new Tab();
$tab->class_name = 'AdminFotoliaSelector';
$tab->id_parent = 0;
$tab->module = $this->name;
$tab->name[(int)(Configuration::get('PS_LANG_DEFAULT'))] = 'Fotolia Selector';
$tab->add();
return true;
}
I had big problem with make proper controller, and now I just can't load anything/ I have no idea how do this.
<?php
if (!defined('_PS_VERSION_'))
exit;
class AdminFotoliaSelectorController extends ModuleAdminController {
public $name;
public function __construct() {
$this->lang = (!isset($this->context->cookie) || !is_object($this->context->cookie)) ? intval(Configuration::get('PS_LANG_DEFAULT')) : intval($this->context->cookie->id_lang);
parent::__construct();
}
public function initContent() {
parent::initContent();
$this->renderForm();
}
public function renderForm() {
$path = _MODULE_DIR_."fotoliaselector";
$more = $this->module->display($path, 'views/templates/admin/fotoliaselector.tpl');
return $more.parent::renderForm();
}
When I try die($more) it gives me content of .tpl, anyway when I click tab in back office it's still empty.
I have debug options on, compiling on, cache off.
So just enlight me please, how am I supose to show ANYTHING there?
I think the problem is that you don't display tab's content at all.
I don't know what module->display method does, but I think you should change in initContent() method line:
$this->renderForm();
into
echo $this->renderForm();
If it won't help you should look at this documentation and try to do it without external classes - only try to use Smarty to display simple content without using Tab class or AdminFotoliaSelector
Well i know it will sounds weird but you need to take some similar modules, and read his code and will see some methods names are the same in each module.
Then copy that, install and play with some changes etc.
Imho you miss standard method getContent() form where you need to pass some data for smarty:
public function getContent()
{
global $smarty, $cookie;
......
//some code
......
$this->_html .= '<script type="text/javascript" src="'.__PS_BASE_URI__.'js/tinymce/jscripts/tiny_mce/tiny_mce.js"></script>';
$this->_html .= '<h1>My module title or stuff</h1>';
$this->_html .= $this->getMyCoolFormOrConfig();
$smarty->assign('errors', $this->errors);
$smarty->assign('message', $this->message);
$this->_html .= $this->display(__FILE__, 'name_of_tpl_file.tpl');
return $this->_html;
}
to simple add tab in BackOffice code like this:
$id_tab=Tab::getIdFromClassName('AdminPayment');
$newtab=new Tab();
$newtab->id_parent=$id_tab;
$newtab->module=$this->name;
$newtab->class_name='MyClassName'; //will be same like MyClassName.php in folder of you module where you need to create you class and extend the AdminTab and from there with function you need to echo you name module
$newtab->position=Tab::getNbTabs($id_tab)+1;
$newtab->name[$cookie->id_lang]=$this->l("Name of you stuff");
$newtab->name[Configuration::get('PS_LANG_DEFAULT')]=$this->l("Name of you stuff");
$newtab->add();
Study this file there /controllers/admin/AdminModulesController.php
and you see what methods are using in each module
Take a look greater feature to generate you module structure (register requeired) https://validator.prestashop.com/generator
I am creating website in PHP. I am using MVC in PHP. My website works like this, if user go to example.com/about then it it will load About class and index() function. If user will go to localhost/about/founder then it will load founder() function from About class. but the thing is that if I go to localhost/About or localhost/AbOut or anything like that it is loading default index() function from About class file. So what to do with case sensitivity? I mean I want my script to load index() function from class file if it is localhost/about or localhost/terms. If anything is in uppercase, then it should load 404 error function. 404 error function is already set in my site.
Please help me friends.
here is my Bootstrap.php class file
<?php
/*
Bootstrap class to run functions by URL
*/
class Bootstrap {
public $_req;
public $_body;
public $_file;
public $_error;
function __construct(){
if(empty($_GET['req'])){
require 'classes/home.php';
$this->_body = new Home();
$this->hdr($this->_body->head());
$this->_body->index();
$this->ftr();
exit();
}
$this->_req = rtrim($_GET['req'], '/');
$this->_req = explode('/', $this->_req );
$_file = 'classes/'.$this->_req[0].'.php';
if(file_exists($_file)){
require $_file;
}
else {
$this->error(404);
}
$this->_body = new $this->_req[0];
$this->hdr($this->_body->head());
if(isset($this->_req[2])){
if(method_exists($this->_req[0], $this->_req[1])){
$this->_body->{$this->_req[1]}($this->_req[2]);
}else {
$this->error(404);
}
}else {
if(isset($this->_req[1])){
if(method_exists($this->_req[0], $this->_req[1])){
$this->_body->{$this->_req[1]}();
}else {
$this->error(404);
}
}else {
$this->_body->index();
}
$this->ftr();
}
}
//this function is to set header in html code
public function hdr($var = false){
echo '<!DOCTYPE HTML><html><head>'.$var.'</head><body>';
}
//this function is tp set footer in html code
public function ftr($var = false){
echo $var.'</body></html>';
}
//error handler
public function error($var){
require 'classes/er_pg.php';
$this->_error = new Error();
$this->_error->index($var);
}
}
You shouldn't use anything to load non-lowercase URLs because of the duplicate content, and that's a good thing you're doing. The wrong URLs should fail automatically in such cases.
However, since you didn't show how are you making those calls, then only thing I can suggest at this point is to check if the called method exists (case-sensitive), and if not, throw/redirect to a 404 page (header($_SERVER["SERVER_PROTOCOL"]." 404 Not Found");).
UPDATE
After all the chat in the comments, seems like file_exists is not case-sensitive in your case, which is really weird. Hopefully someone will be able to figure it out so I can delete this (keeping it because of the info in the comments).
I solved the problem. I used this
if(ctype_lower($this->_req[0])){
$_file = 'classes/'.$this->_req[0].'.php';
and now its working. Thanx anyways friends.
I have a PHP script that returns to me my (and my friends) profile pictures, using the following:
http://graph.facebook.com/".$ID."/picture?type=large
where $ID is the ID retrieved using the PHP API. I then use the following for loading the images in my app:
public function LoadProfile()
{
loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onUrlLoaded);
loader.load(new URLRequest(ImageURL));
//ImageURL is the URL provided by the PHP Script
// which is the 'http://graph.facebook.com/XXXX/picture?type=large'
}
private function onUrlLoaded(event:Event)
{
loader.contentLoaderInfo.removeEventListener(Event.COMPLETE, onUrlLoaded);
var path:String = LoaderInfo(event.target).url;
loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onReallyComplete);
var lc:LoaderContext = new LoaderContext(true);
lc.checkPolicyFile = true;
loader.load(new URLRequest(path), lc);
}
private function onReallyComplete(event:Event)
{
loader.contentLoaderInfo.removeEventListener(Event.COMPLETE, onReallyComplete);
}
This works for ALL of my friends, but does NOT work for me for some reason. I get the following general address for the image of my friends:
http://profile.ak.fbcdn.net/hprofile-ak-snc4/370825_524761447_653077984_n.jpg
But for me I just get
http://profile.ak.fbcdn.net
which is some random person ... NOT me ...
I've verified repeatedly that the ID being sent back from the PHP is in-fact my ID, and I've copy/pasted the address traced BEFORE the loading function into a browser and I get my correct profile picture, but somewhere in there it's bugging out for my ID in the load and only my ID in the load (I should rephrase it to say it bugs out for WHATEVER user is logged in to Facebook, not just me).
Any ideas? Or anyone know of an alternative way to get MY profile picture?
public function loadProfile():void
{
loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, loader_completeHandler);
loader.contentLoaderInfo.addEventListener(SecurityErrorEvent.SECURITY_ERROR, loader_securityErrorHandler);
loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, loader_ioErrorHandler);
loader.load(new URLRequest(_imageURL));
}
private function loader_securityErrorHandler(event:SecurityErrorEvent):void
{
trace(event.toString());
}
private function loader_ioErrorHandler(event:IOErrorEvent):void
{
trace(event.toString());
}
private function loader_completeHandler(event:Event):void
{
loader.contentLoaderInfo.removeEventListener(Event.COMPLETE, loader_completeHandler);
loader.contentLoaderInfo.removeEventListener(SecurityErrorEvent.SECURITY_ERROR, loader_securityErrorHandler);
loader.contentLoaderInfo.removeEventListener(IOErrorEvent.IO_ERROR, loader_ioErrorHandler);
addChild(loader);
}