summaryrefslogtreecommitdiff
path: root/protected/tests
diff options
context:
space:
mode:
authorPatrick Seeger <pseeger@ccwn.org>2012-04-13 23:44:38 +0200
committerPatrick Seeger <pseeger@ccwn.org>2012-04-13 23:44:38 +0200
commit69bffb7fe85347621f41c0baed839452e72930e1 (patch)
tree8446bced1732932fd741e91ff8dba88b1e56693b /protected/tests
parenta098922f681a9a1362202580a26b132501df4b1b (diff)
Erstes Yii Projekt
Diffstat (limited to 'protected/tests')
-rw-r--r--protected/tests/WebTestCase.php25
-rw-r--r--protected/tests/bootstrap.php10
-rw-r--r--protected/tests/functional/SiteTest.php47
-rw-r--r--protected/tests/phpunit.xml13
4 files changed, 95 insertions, 0 deletions
diff --git a/protected/tests/WebTestCase.php b/protected/tests/WebTestCase.php
new file mode 100644
index 0000000..d252bba
--- /dev/null
+++ b/protected/tests/WebTestCase.php
@@ -0,0 +1,25 @@
+<?php
+
+/**
+ * Change the following URL based on your server configuration
+ * Make sure the URL ends with a slash so that we can use relative URLs in test cases
+ */
+define('TEST_BASE_URL','http://localhost/testdrive/index-test.php/');
+
+/**
+ * The base class for functional test cases.
+ * In this class, we set the base URL for the test application.
+ * We also provide some common methods to be used by concrete test classes.
+ */
+class WebTestCase extends CWebTestCase
+{
+ /**
+ * Sets up before each test method runs.
+ * This mainly sets the base URL for the test application.
+ */
+ protected function setUp()
+ {
+ parent::setUp();
+ $this->setBrowserUrl(TEST_BASE_URL);
+ }
+}
diff --git a/protected/tests/bootstrap.php b/protected/tests/bootstrap.php
new file mode 100644
index 0000000..780a103
--- /dev/null
+++ b/protected/tests/bootstrap.php
@@ -0,0 +1,10 @@
+<?php
+
+// change the following paths if necessary
+$yiit=dirname(__FILE__).'/../../../yii-framework/framework/yiit.php';
+$config=dirname(__FILE__).'/../config/test.php';
+
+require_once($yiit);
+require_once(dirname(__FILE__).'/WebTestCase.php');
+
+Yii::createWebApplication($config);
diff --git a/protected/tests/functional/SiteTest.php b/protected/tests/functional/SiteTest.php
new file mode 100644
index 0000000..cb9727c
--- /dev/null
+++ b/protected/tests/functional/SiteTest.php
@@ -0,0 +1,47 @@
+<?php
+
+class SiteTest extends WebTestCase
+{
+ public function testIndex()
+ {
+ $this->open('');
+ $this->assertTextPresent('Welcome');
+ }
+
+ public function testContact()
+ {
+ $this->open('?r=site/contact');
+ $this->assertTextPresent('Contact Us');
+ $this->assertElementPresent('name=ContactForm[name]');
+
+ $this->type('name=ContactForm[name]','tester');
+ $this->type('name=ContactForm[email]','tester@example.com');
+ $this->type('name=ContactForm[subject]','test subject');
+ $this->click("//input[@value='Submit']");
+ $this->waitForTextPresent('Body cannot be blank.');
+ }
+
+ public function testLoginLogout()
+ {
+ $this->open('');
+ // ensure the user is logged out
+ if($this->isTextPresent('Logout'))
+ $this->clickAndWait('link=Logout (demo)');
+
+ // test login process, including validation
+ $this->clickAndWait('link=Login');
+ $this->assertElementPresent('name=LoginForm[username]');
+ $this->type('name=LoginForm[username]','demo');
+ $this->click("//input[@value='Login']");
+ $this->waitForTextPresent('Password cannot be blank.');
+ $this->type('name=LoginForm[password]','demo');
+ $this->clickAndWait("//input[@value='Login']");
+ $this->assertTextNotPresent('Password cannot be blank.');
+ $this->assertTextPresent('Logout');
+
+ // test logout process
+ $this->assertTextNotPresent('Login');
+ $this->clickAndWait('link=Logout (demo)');
+ $this->assertTextPresent('Login');
+ }
+}
diff --git a/protected/tests/phpunit.xml b/protected/tests/phpunit.xml
new file mode 100644
index 0000000..22c96ff
--- /dev/null
+++ b/protected/tests/phpunit.xml
@@ -0,0 +1,13 @@
+<phpunit bootstrap="bootstrap.php"
+ colors="false"
+ convertErrorsToExceptions="true"
+ convertNoticesToExceptions="true"
+ convertWarningsToExceptions="true"
+ stopOnFailure="false">
+
+ <selenium>
+ <browser name="Internet Explorer" browser="*iexplore" />
+ <browser name="Firefox" browser="*firefox" />
+ </selenium>
+
+</phpunit> \ No newline at end of file