Hello, I'm attempting to set up unit tests for a module I'm developing.
I'm currently needing to test that a particular page type displays everything as it should (it's a subclass of Page).
I've created the page in my .yml file, and it is being created correctly, but I can't figure out how to GET the page with a functionaltest - I'm just getting a 404...
This is my CompanyPageTest.php file:
<?php
/**
* Test the features of the Companies page
*
*/
class CompanyPageTest extends FunctionalTest {
static $fixture_file = 'csm2/tests/models/clients/Companies.yml';
protected $page;
public function setUp() {
parent::setUp();
$this->page = $this->objFromFixture('CompanyPage', 'companies');
}
/**
* Return a session that has a user logged in as someone
*/
public function createSession($fixtureName) {
return new Session(array(
'loggedInAs' => $this->idFromFixture('Member', $fixtureName)
));
}
public function testIndexListsAllCompanies() {
Debug::show($this->page->Link());
$this->get($this->page->Link(), $this->createSession('admin'));
Debug::show($this->content());
$this->assertPartialMatchBySelector('.name', 'Company A');
$this->assertPartialMatchBySelector('.name', 'Company B');
}
}
And this is my Companies.yml file:
Member:
admin:
FirstName: Admin
Surname: Admin
Email: admin@test.com
engineer:
FirstName: Joe
Surname: Engineer
Email: joe@test.com
Company:
a:
Name: Company A
BillingAddress: 'Company A, PO Box 1234, Some Town'
PhysicalAddress: '123 Some Road, Some Town'
AgreedRate: $120
Phone: (03) 1234567
b:
Name: Company B
BillingAddress: 'Company B, PO Box 4321, Some Town'
PhysicalAddress: '321 Some Road, Some Town'
AgreedRate: $120
Phone: (03) 7654321
CompanyPage:
companies:
Title: Companies
URLSegment: companies
CanViewType: LoggedInUsers
Job:
open-job:
Title: An Open Job
Description: Some description on how the job looks
Due: 17/2/2030
Status: 'New'
For: =>Company.a
CreatedBy: =>Member.admin
AssignedTo: =>Member.engineer
SLA:
Invoice:
The two debug statements in the test code show the url of the page I created ('companies'), and the content of a 404 page. Anyone able to point me in the right direction?
Cheers
Edit: Just noticed that the spacing in the yml code listing is all weird on the forum - I do have it correct in my actual file..