DomDocument::loadHTML() error during phpunit test execution - php

I am currently trying to write some unit test against my zend framework controller. When I run the following code I receive this error:
public function testListActionShouldContainListTable()
{
$this->loginToSystem();
$uri = $this->_uriBase . 'campaign/list';
$_SERVER["REQUEST_URI"] = $uri;
$this->dispatch('/campaign/list');
$this->assertController('campaign');
$this->assertAction('list');
$this->assertQueryCount('#list',1);
}
CampaignControllerTests::testListActionShouldContainListTable
DOMDocument::loadHTML(): ID alrt already defined in Entity, line: 36
This occurs using any of the assertQuery and assertQueryContains methods. I have searched around but am not really finding a good answer to why it won't allow me to find this html node or how to get around this error.
Thanks in advance for any help!

Make sure the document is valid. You have duplicate IDs in your HMTL document.

The HTML being generated by the dispatch is bad (it looks like it has two ids being assigned to a single tag). This is not an error of your test (it's working fine), it's an error in your html output generated by the test...

Related

SimplePie through CraftCMS adding #? to feed URL

Okay - simple details first:
Feed URL: http://feeds.wired.com/wired/index
When I access this directly through simplepie and not CraftCMS, the feed loads without issue. When I access it through the CMS template system it throws an error saying the returned XML is effectively garbage. Looking into this, its because the feed host is returning a page not found.
I have dug through the code to find out why it is a page not found on a valid URL and found that in the file:
/library/simplepie/registry.php
public function &create($type, $parameters = array()) (around line 160)
Now in this function I see that a new reflection class is created and new InstanceArgs are sent the parameters. At this point the Feed URL gets changed from:
http://feeds.wired.com/wired/index
to
http://feeds.wired.com/wired/index?#
Effectively this new URL with the added ?# on the end is causing the feed site to return a page not found. And hence all my errors...
This is beginning to hit the end of my abilities - and I would like to know what is causing the ?# to be added and if there is a way to prevent it? Or any other possible solutions to my problem.
I can't explain why it works outside of Craft and not inside, but it definitely looks like a SimplePie bug to me.
Just created an issue and pull request with the fix for them (https://github.com/simplepie/simplepie/issues/366) and will see about updating it in Craft itself.
Update: looks my fix didn't broke some of their tests, so we won't be putting that into Craft, but they have acknowledged it needs to be fixed.

file_get_html() doesnt work [duplicate]

I used the following code to parse the HTML of another site but it display the fatal error:
$html=file_get_html('http://www.google.co.in');
Fatal error: Call to undefined function file_get_html()
are you sure you have downloaded and included php simple html dom parser ?
You are calling class does not belong to php.
Download simple_html_dom class here and use the methods included as you like it. It is really great especially when you are working with Emails-newsletter:
include_once('simple_html_dom.php');
$html = file_get_html('http://www.google.co.in');
As everyone have told you, you are seeing this error because you obviously didn't downloaded and included simple_html_dom class after you just copy pasted that third party code,
Now you have two options, option one is what all other developers have provided in their answers along with mine,
However my friend,
Option two is to not use that third party php class at all! and use the php developer's default class to perform same task, and that class is always loaded with php, so there is also efficiency in using this method along with originality plus security!
Instead of file_get_html which not a function defined by php developers use-
$doc = new DOMDocument();
$doc->loadHTMLFile("filename.html");
echo $doc->saveHTML(); that's indeed defined by them. Check it on php.net/manual(Original php manual by its devs)
This puts the HTML into a DOM object which can be parsed by individual tags, attributes, etc.. Here is an example of getting all the 'href' attributes and corresponding node values out of the 'a' tag. Very cool....
$tags = $doc->getElementsByTagName('a');
foreach ($tags as $tag) {
echo $tag->getAttribute('href').' | '.$tag->nodeValue."\n";
}
P.S. : PLEASE UPVOTE IF YOU LIKED MY ANSWER WILL HELP MY REPUTATION ON STACKOVERFLOW, THIS PEOPLES THINK I'M NOOB!
It looks like you're looking for simplexml_load_file which will load a file and put it into a SimpleXML object.
Of course, if it is not well-formatted that might cause problems. Your other option is DomObject::loadHTMLFile. That is a good deal more forgiving of badly formed documents.
If you don't care about the XML and just want the data, you can use file_get_contents.
$html = file_get_contents('http://www.google.co.in');
to get the html content of the page
in simple words
download the simple_html_dom.php from here Click here
now write these line to your Php file
include_once('simple_html_dom.php');
and start your coading after that
$html = file_get_html('http://www.google.co.in');
no error will be displayed
Try file_get_contents.
http://www.php.net/manual/en/function.file-get-contents.php

Requesting assistance with 1 line of code regarding xajax

I am attempting to build a PHPMailer based email system for a basic website.
This is the line of code that is giving me trouble:
$xajax->printJavascript('xajax/');
Now, this is the tutorial I am using.
Regarding the above line of code, the tutorial says this:
How to use the code inside a webpage?
Place the form (variable), the function (and the includes) before of all html code. Next we need to include some JavaScript file in the documents HTML header (place also php tags):
$xajax->printJavascript('xajax/');
When I run all of the code (including: PHPMailer script; Ajax script), I get this error, on the aforementioned line of code.
Fatal error: Call to a member function on a non-object
So, my question is, do I need to in someway customize this code or make it run to a filepath of some ajax core file or something?
I would be willing to be $xajax is not defined. Try adding this after including the libraries but before including the call to that method:
$xajax = new xajax();
There may be some additional setup required by xajax. A more complete code example could help troubleshoot.

zend layout.phtml error

Hi I've got an error in my Zend Framework project...
It raised:
Invalid controller specified (myweb)
Here is my apache error.log:
PHP Warning: Invalid argument supplied for foreach() in /var/www/myweb/application/layouts/scripts/layout.phtml on line 107
Here's my code in layout.phtml:
<?php foreach($this->category as $categories):?>
<li><div id="sidemenu"> �<?php echo $categories['categoriesName'];?></div></li>
<?php endforeach;?>
Can anybody help me?
The problem seems to be that for some reason your url is presenting myweb as the controller instead of what should be your controller.
My guess is the you are trying to use localhost to display your application so are presenting a url similar to http://localhost/myweb/...
While it is possible to use the localhost to view ZF applications it often becomes inconvenient as applications become more complex. I would suggest you use a vhost for anything more then a very simple application.
I'm pretty sure that when you resolve the url problem the php warning will likely fix itself.
It seems like the variable $this->category is not set in the Controller. You can do this by defining $this->view->category from your controller.
Mostly when using these controller generated variables in the layout script instead of the corresponding view script, you want to use the same data in every view. If this is the case, check this question: Sending variables to the layout in Zend Framework
This error come because your array $this->category is blank. if this is blank array or return nothing then how foreach loop will execute?
so first print this array and check.

PHP: DOMDocument loadHTML returns error with nesty URL in href

Recently I get an exception while I try to implement a special template engine.
Mine problem with DOMDocument load is in fact that I use some place holders in href and it will be replaced after with real values. I want to store that template and to use it each time when I need it, here is code sample
$this->dom = new DOMDocument;
$load_html = $this->dom->loadHTML($html);
And nesty part of HTML looks like
Visit our web site
and exception is
Fatal error: DOMDocument::loadXML() [<a href='domdocument.loadxml'>domdocument.loadxml</a>]: EntityRef: expecting ';' in Entity
I was try to find a some way to skip that check but couldn't find anything.
This causes no error in PHP 5.3. You must have some other HTML that is causing this. Normally you see this when you use an entity with no ; after it.
Foo &nbsp Bar
That throws that same error for me. Look for some entity without a ; on it. Browsers will render that, but it is not correct.
I found what was the problem. In my URL it was & sign, I was replace it with & and now it works.

Categories