Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

ENHANCEMENT Added functional tests for CRUD and search behavior

  • Loading branch information...
commit 807654723c383c9549b9a45ca140ed84e820cde7 1 parent e8ba171
Ingo Schommer authored
126 tests/GenericViewsFunctionalTest.php
View
@@ -0,0 +1,126 @@
+<?php
+/**
+ * @package genericviews
+ * @subpackage tests
+ */
+class GenericViewsFunctionalTest extends FunctionalTest {
+
+ static $fixture_file = 'genericviews/tests/GenericViewsFunctionalTest.yml';
+
+ function setUp() {
+ parent::setUp();
+
+ $page = $this->objFromFixture('CollectionPage', 'jobcategory_page');
+ $page->publish('Stage', 'Live');
+ }
+
+ function testList() {
+ $page = $this->objFromFixture('CollectionPage', 'jobcategory_page');
+
+ $response = $this->get($page->URLSegment);
+ $this->assertEquals($response->getStatusCode(), 200);
+ $this->assertContains('Category 1', $response->getBody());
+ $this->assertContains('Category 2', $response->getBody());
+ }
+
+ function testSearch() {
+ $page = $this->objFromFixture('CollectionPage', 'jobcategory_page');
+
+ $response = $this->get($page->URLSegment);
+
+ $response = $this->submitForm('Form_SearchForm', null, array('Title'=>'Category 1'));
+ $this->assertEquals($response->getStatusCode(), 200);
+ $this->assertContains('Category 1', $response->getBody());
+ $this->assertNotContains('Category 2', $response->getBody());
+ }
+
+ function testView() {
+ $page = $this->objFromFixture('CollectionPage', 'jobcategory_page');
+ $cat1 = $this->objFromFixture('GenericViewsFunctionalTest_JobCategory', 'cat1');
+ $url = sprintf('%s/%s/%s/%s',
+ $page->URLSegment,
+ '/GenericViewsFunctionalTest_JobCategory',
+ $cat1->ID,
+ 'view'
+ );
+
+ $response = $this->get($url);
+ $this->assertEquals($response->getStatusCode(), 200);
+ $this->assertContains('Category 1', $response->getBody());
+ $this->assertContains('Description 1', $response->getBody());
+ }
+
+ function testEdit() {
+ $page = $this->objFromFixture('CollectionPage', 'jobcategory_page');
+ $cat1 = $this->objFromFixture('GenericViewsFunctionalTest_JobCategory', 'cat1');
+ $admin = $this->objFromFixture('Member', 'admin');
+
+ $url = sprintf('%s/%s/%s/%s',
+ $page->URLSegment,
+ '/GenericViewsFunctionalTest_JobCategory',
+ $cat1->ID,
+ 'edit'
+ );
+
+ // without login
+ $response = $this->get($url);
+ $this->assertEquals($response->getStatusCode(), 403);
+
+ // with login
+ $admin->logIn();
+ $response = $this->get($url);
+ $this->assertEquals($response->getStatusCode(), 200);
+ $this->assertContains('Category 1', $response->getBody());
+ $this->assertContains('Description 1', $response->getBody());
+
+ // change values
+ $this->submitForm('Form_EditForm', null, array('Title'=>'Category 1 Modified'));
+ $cat1Modified = DataObject::get_by_id('GenericViewsFunctionalTest_JobCategory', $cat1->ID);
+ $this->assertEquals($cat1Modified->Title, 'Category 1 Modified');
+ }
+
+ function testDelete() {
+ $page = $this->objFromFixture('CollectionPage', 'jobcategory_page');
+ $cat1 = $this->objFromFixture('GenericViewsFunctionalTest_JobCategory', 'cat1');
+ $admin = $this->objFromFixture('Member', 'admin');
+
+ $url = sprintf('%s/%s/%s/%s',
+ $page->URLSegment,
+ '/GenericViewsFunctionalTest_JobCategory',
+ $cat1->ID,
+ 'edit'
+ );
+
+ // with login
+ $admin->logIn();
+ $response = $this->get($url);
+
+ // delete entry
+ $this->submitForm('Form_DeleteForm');
+ $cat1Deleted = DataObject::get_by_id('GenericViewsFunctionalTest_JobCategory', $cat1->ID);
+ $this->assertFalse($cat1Deleted);
+ }
+}
+
+/**
+ * @package genericviews
+ * @subpackage tests
+ */
+class GenericViewsFunctionalTest_JobCategory extends DataObject implements TestOnly {
+ static $db = array(
+ 'Title' => 'Varchar',
+ 'Description' => 'Text',
+ );
+
+ function canView() {
+ return true;
+ }
+
+ function canEdit() {
+ return Permission::check('ADMIN');
+ }
+
+ function canDelete() {
+ return Permission::check('ADMIN');
+ }
+}
23 tests/GenericViewsFunctionalTest.yml
View
@@ -0,0 +1,23 @@
+Permission:
+ admin:
+ Code: ADMIN
+Group:
+ admin:
+ Title: Admin
+ Permissions: =>Permission.admin
+Member:
+ admin:
+ Email: admin@test.com
+ Groups: =>Group.admin
+CollectionPage:
+ jobcategory_page:
+ Title: Job Categories
+ URLSegment: job-categories
+ CollectionModelClass: GenericViewsFunctionalTest_JobCategory
+GenericViewsFunctionalTest_JobCategory:
+ cat1:
+ Title: Category 1
+ Description: Description 1
+ cat2:
+ Title: Category 2
+ Description: Description 2
Please sign in to comment.
Something went wrong with that request. Please try again.