HOW TO USE
--------------------------------------------------------
Now we are ready to write our functional / acceptance tests. For example we want to develop the following user stories:
1. As user I want to read the latest news in section news
2. As user I want to read a full news
First of all we write the functional / acceptance test with our client to be sure that all requirements are clear both for customers than developers.
We start from the story 1.
1. Create the test class in our functional directory:
touch extension/mysite/tests/functional/newsTest.php
and add the following code:
get('http://' . $ini->variable('SiteSettings', 'SiteURL'));
$this->checkElementResponse('h1', 'My Site');
$this->click('News');
$this->checkElementResponse('h1', 'News', array('position' => 1));
$this->checkElementResponse('div.content-view-children a', 10);
}
}
3. Add the test to our suite adding the following code to extension/mysite/tests/suite.php
class mysiteTestSuite extends ezpDatabaseTestSuite
{
public function __construct()
{
...
$this->addTestSuite('newsTest');
}
...
}
4. Now we have to define our custom "News" class in the classes.yml file created before, adding the following code in our file:
News:
object_name:
is_container: true
attributes:
title: { name: Title, type: ezstring, is_required: true }
image: { name: Image, type: ezimage, is_required: true }
intro: { name: Intro, type: ezxmltext, is_required: true }
body: { name: Body, type: ezxmltext, is_required: true }
publish_date: { name: Publication date, type: ezdate }
translations:
ita-IT:
name: Notizia
attributes:
title: Titolo
intro: Intro
body: Corpo
publish_date: Data di pubblicazione
image: Immagine
5. now we can define our objects in the objects.yml file adding the following code to our file:
folder:
news:
locations:
main: { parent_node_id: 2 }
attributes:
name: News
news:
news:
locations:
main: { parent_node_id: news }
attributes:
title: 'News '
intro: >
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Donec non sapien sit amet quam imperdiet bibendum.
Nam mauris dui, porttitor in tempus ac, scelerisque ut metus.
Donec urna elit, viverra a aliquet eu, commodo in velit. Donec quis imperdiet tortor.
Nulla facilisi.
body: >
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec non sapien sit amet quam imperdiet bibendum.
Nam mauris dui, porttitor in tempus ac, scelerisque ut metus. Donec urna elit, viverra a aliquet eu, commodo in velit.
Donec quis imperdiet tortor. Nulla facilisi. Donec ac nisl tortor, adipiscing pretium leo. Sed auctor nisi neque, ac dapibus neque.
Cras vestibulum iaculis tellus in vestibulum. Nulla sit amet faucibus enim. Vestibulum id ipsum massa. Vestibulum porta commodo porta.
Suspendisse vestibulum nunc quis augue porttitor dapibus. Sed lobortis pretium nisl, dictum auctor mi ultricies sed.
Praesent mauris ligula, luctus auctor imperdiet sit amet, ultrices vitae nisi. Vestibulum consectetur tincidunt turpis vel blandit.
Praesent eget augue ac ante fermentum tincidunt sed at massa.
publish_date: ''
image: ''
4. Regenerate autoload file with the following command:
php bin/php/ezpgenerateautoloads.php -e
5. Run your test with the following command:
php tests/runtests.php --colors -f newsTest::testNewsList --dsn=mysql://:@/ extension/mysite
Why don't you implement the second user story by your hand?
For all refernce you can visit the official website:
- PHPUnit -> http://www.phpunit.de/
- sfWebBrowser -> http://www.symfony-project.org/plugins/sfWebBrowserPlugin
- sfYaml -> http://components.symfony-project.org/yaml/