Re: [Wikitech-l] WebTestCase

2019-10-03 Thread David Barratt
> What is this "controller" in MediaWiki context? Do you have any example of
> how this would work?


For instance, you could call the `::execute()` method on a class that
extends SpecialPage directly. It might be helpful to know what you are
trying to do though.

Basically what Gergo said. :)

On Wed, Oct 2, 2019 at 11:33 PM Jeroen De Dauw 
wrote:

> Hey,
>
> Your best bet might be making actual web requests. You can use Selenium
> > from PHPUnit, ...
> >
>
> Is there an example of a test doing either of those?
>
> The web request case is apparently not as simple as stuffing
> Title::newFromText()->getCannonicalUrl() into Http::get() and I'd rather
> not be making an abstraction for this myself as it requires a bunch of MW
> knowledge I do not have.
>
> Therefore, you must call the "controller" directly from your test.
> >
>
> What is this "controller" in MediaWiki context? Do you have any example of
> how this would work?
>
> Cheers
>
> --
> Jeroen De Dauw | www.EntropyWins.wtf  |
> www.Professional.Wiki 
> Entrepreneur | Software Crafter | Speaker | Open Souce and Wikimedia
> contributor
> ~=[,,_,,]:3
> ___
> Wikitech-l mailing list
> Wikitech-l@lists.wikimedia.org
> https://lists.wikimedia.org/mailman/listinfo/wikitech-l
___
Wikitech-l mailing list
Wikitech-l@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/wikitech-l

Re: [Wikitech-l] WebTestCase

2019-10-03 Thread Željko Filipin
Hi Jeroen,

If you're asking for examples of Selenium tests, take a look at:

https://www.mediawiki.org/wiki/Selenium/Node.js
https://gerrit.wikimedia.org/r/plugins/gitiles/mediawiki/core/%2B/master/tests/selenium/

Željko

On Thu, Oct 3, 2019 at 5:33 AM Jeroen De Dauw 
wrote:

> Your best bet might be making actual web requests. You can use Selenium
> > from PHPUnit, ...
> >
>
> Is there an example of a test doing either of those?
>
___
Wikitech-l mailing list
Wikitech-l@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/wikitech-l

Re: [Wikitech-l] WebTestCase

2019-10-03 Thread Gergo Tisza
On Thu, Oct 3, 2019 at 5:33 AM Jeroen De Dauw 
wrote:

> The web request case is apparently not as simple as stuffing
> Title::newFromText()->getCannonicalUrl() into Http::get()
>

That's pretty much how I would try it (if I couldn't avoid testing the full
web stack instead of just calling the relevant special page or action
directly).
___
Wikitech-l mailing list
Wikitech-l@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/wikitech-l

Re: [Wikitech-l] WebTestCase

2019-10-02 Thread Jeroen De Dauw
Hey,

Your best bet might be making actual web requests. You can use Selenium
> from PHPUnit, ...
>

Is there an example of a test doing either of those?

The web request case is apparently not as simple as stuffing
Title::newFromText()->getCannonicalUrl() into Http::get() and I'd rather
not be making an abstraction for this myself as it requires a bunch of MW
knowledge I do not have.

Therefore, you must call the "controller" directly from your test.
>

What is this "controller" in MediaWiki context? Do you have any example of
how this would work?

Cheers

--
Jeroen De Dauw | www.EntropyWins.wtf  |
www.Professional.Wiki 
Entrepreneur | Software Crafter | Speaker | Open Souce and Wikimedia
contributor
~=[,,_,,]:3
___
Wikitech-l mailing list
Wikitech-l@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/wikitech-l

Re: [Wikitech-l] WebTestCase

2019-10-02 Thread David Barratt
As far as I know, MediaWiki does not have a centralized router like Symfony
and Drupal have.

Therefore, you must call the "controller" directly from your test.

Also, the "controller" will typically print the result, so you would need
to capture the result with output buffering:
https://www.php.net/manual/en/function.ob-get-contents.php

This is basically what WebTestCase is doing, though it is much more elegant
because it calls the router and the result is returned rather than printed.

I hope this helps!

On Wed, Oct 2, 2019 at 5:56 AM Jeroen De Dauw 
wrote:

> Hey,
>
> > I think selenium is often used for that use case
>
> I'm explicitly looking for a PHPUnit based approach. Similar to what
> Symfony provides. Surely this is possible with MediaWiki, though perhaps
> not as elegantly?
>
> Cheers
>
> --
> Jeroen De Dauw | www.EntropyWins.wtf  |
> www.Professional.Wiki 
> Entrepreneur | Software Crafter | Speaker | Open Souce and Wikimedia
> contributor
> ~=[,,_,,]:3
> ___
> Wikitech-l mailing list
> Wikitech-l@lists.wikimedia.org
> https://lists.wikimedia.org/mailman/listinfo/wikitech-l
___
Wikitech-l mailing list
Wikitech-l@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/wikitech-l

Re: [Wikitech-l] WebTestCase

2019-10-02 Thread Gergo Tisza
There's ApiTestCase for the action API, and an open patch [1] for providing
similar functionality for the REST API.
I don't think there is anything for web views, and the dispatching
mechanism is fairly messy. (The entry point is MediaWiki::run() but that
has teardown logic that would probably break the next test.) Your best bet
might be making actual web requests. You can use Selenium from PHPUnit, or
a number of similar tools (e.g. Goutte if you want something simple).


[1] https://gerrit.wikimedia.org/r/c/mediawiki/core/+/520066

On Wed, Oct 2, 2019 at 11:56 AM Jeroen De Dauw 
wrote:

> Hey,
>
> > I think selenium is often used for that use case
>
> I'm explicitly looking for a PHPUnit based approach. Similar to what
> Symfony provides. Surely this is possible with MediaWiki, though perhaps
> not as elegantly?
>
> Cheers
>
> --
> Jeroen De Dauw | www.EntropyWins.wtf  |
> www.Professional.Wiki 
> Entrepreneur | Software Crafter | Speaker | Open Souce and Wikimedia
> contributor
> ~=[,,_,,]:3
> ___
> Wikitech-l mailing list
> Wikitech-l@lists.wikimedia.org
> https://lists.wikimedia.org/mailman/listinfo/wikitech-l
___
Wikitech-l mailing list
Wikitech-l@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/wikitech-l

Re: [Wikitech-l] WebTestCase

2019-10-02 Thread Jeroen De Dauw
Hey,

> I think selenium is often used for that use case

I'm explicitly looking for a PHPUnit based approach. Similar to what
Symfony provides. Surely this is possible with MediaWiki, though perhaps
not as elegantly?

Cheers

--
Jeroen De Dauw | www.EntropyWins.wtf  |
www.Professional.Wiki 
Entrepreneur | Software Crafter | Speaker | Open Souce and Wikimedia
contributor
~=[,,_,,]:3
___
Wikitech-l mailing list
Wikitech-l@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/wikitech-l

Re: [Wikitech-l] WebTestCase

2019-10-02 Thread Brian Wolff
I think selenium is often used for that use case

https://www.mediawiki.org/wiki/Selenium/Node.js/Simple

--
Bawolff

On Tuesday, October 1, 2019, Jeroen De Dauw  wrote:

> Hey,
>
> Does MediaWiki have something similar to Symfony's WebTestCase? (
> https://symfony.com/doc/current/testing.html#functional-tests)
>
> I want to write some integration tests in the form of "does web page
> /wiki/MyWikiPage contain HTML snippet XYZ".
>
> Cheers
>
> --
> Jeroen De Dauw | www.EntropyWins.wtf  |
> www.Professional.Wiki 
> Entrepreneur | Software Crafter | Speaker | Open Souce and Wikimedia
> contributor
> ~=[,,_,,]:3
> ___
> Wikitech-l mailing list
> Wikitech-l@lists.wikimedia.org
> https://lists.wikimedia.org/mailman/listinfo/wikitech-l
___
Wikitech-l mailing list
Wikitech-l@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/wikitech-l

Re: [Wikitech-l] WebTestCase

2019-10-02 Thread Jeroen De Dauw
Hey,

I want to test against the HTML actually send to the browser. Not some
random intermediate step.

Example. Lets test this code:
https://github.com/JeroenDeDauw/Maps/blob/ccc85caf8bfb5becb6dd0d0035c1b582a7670d00/src/MediaWiki/MapsHooks.php#L93-L100

The code adds some special HTML to missing pages in the GeoJson namespace.
Now we want to make sure this HTML is not showing up on pages in the main
namespace. So we want to get the HTML for /wiki/ThisPageDoesNotExist.
OutputPage->getHtml() is going to return some empty response since this
page has no content, so it is not what we need.

Cheers

--
Jeroen De Dauw | www.EntropyWins.wtf  |
www.Professional.Wiki 
Entrepreneur | Software Crafter | Speaker | Open Souce and Wikimedia
contributor
~=[,,_,,]:3
___
Wikitech-l mailing list
Wikitech-l@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/wikitech-l

Re: [Wikitech-l] WebTestCase

2019-10-02 Thread Adam Wight
It depends on the test, I suppose.  OutputPage has a "getHTML" method.  For
subclasses of SpecialPage, you can "getOutput"...

Do you have draft code posted somewhere?

On Wed, Oct 2, 2019 at 10:44 AM Jeroen De Dauw 
wrote:

> Hey,
>
> > Sort of.  Once you have the HTML, you can assert various HTML matches and
> non-matches using Hamcrest extensions
>
> That's great, but how do I get the HTML in the first place?
>
> Cheers
>
> --
> Jeroen De Dauw | www.EntropyWins.wtf  |
> www.Professional.Wiki 
> Entrepreneur | Software Crafter | Speaker | Open Souce and Wikimedia
> contributor
> ~=[,,_,,]:3
> ___
> Wikitech-l mailing list
> Wikitech-l@lists.wikimedia.org
> https://lists.wikimedia.org/mailman/listinfo/wikitech-l



-- 
Adam Wight - Developer - Wikimedia Deutschland e.V. - https://wikimedia.de
___
Wikitech-l mailing list
Wikitech-l@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/wikitech-l

Re: [Wikitech-l] WebTestCase

2019-10-02 Thread Jeroen De Dauw
Hey,

> Sort of.  Once you have the HTML, you can assert various HTML matches and
non-matches using Hamcrest extensions

That's great, but how do I get the HTML in the first place?

Cheers

--
Jeroen De Dauw | www.EntropyWins.wtf  |
www.Professional.Wiki 
Entrepreneur | Software Crafter | Speaker | Open Souce and Wikimedia
contributor
~=[,,_,,]:3
___
Wikitech-l mailing list
Wikitech-l@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/wikitech-l

Re: [Wikitech-l] WebTestCase

2019-10-02 Thread Adam Wight
Hi!

Sort of.  Once you have the HTML, you can assert various HTML matches and
non-matches using Hamcrest extensions, for example:
https://phabricator.wikimedia.org/diffusion/EFLI/browse/master/tests/phpunit/Html/ImportPreviewPageTest.php$113

Here's the source to the pattern matching code:
https://github.com/wmde/hamcrest-html-matchers

These can slow down a test significantly, beware of visiting every DOM
subtree!

-Adam

On Wed, Oct 2, 2019 at 7:54 AM Jeroen De Dauw 
wrote:

> Hey,
>
> Does MediaWiki have something similar to Symfony's WebTestCase? (
> https://symfony.com/doc/current/testing.html#functional-tests)
>
> I want to write some integration tests in the form of "does web page
> /wiki/MyWikiPage contain HTML snippet XYZ".
>
> Cheers
>
> --
> Jeroen De Dauw | www.EntropyWins.wtf  |
> www.Professional.Wiki 
> Entrepreneur | Software Crafter | Speaker | Open Souce and Wikimedia
> contributor
> ~=[,,_,,]:3
> ___
> Wikitech-l mailing list
> Wikitech-l@lists.wikimedia.org
> https://lists.wikimedia.org/mailman/listinfo/wikitech-l



-- 
Adam Wight - Developer - Wikimedia Deutschland e.V. - https://wikimedia.de
___
Wikitech-l mailing list
Wikitech-l@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/wikitech-l