|
| 1 | +<?php |
| 2 | + |
| 3 | +/** |
| 4 | + * The Toggl API token for the testing account. |
| 5 | + */ |
| 6 | +define('TOGGL_TEST_TOKEN', 'd37a6e2ebf3a5e2f0bb2a579725360f2'); |
| 7 | + |
| 8 | +// Include PHPUnit |
| 9 | +require_once 'PHPUnit/Framework/TestCase.php'; |
| 10 | + |
| 11 | +// Include the Toggl class file. |
| 12 | +require_once dirname(dirname(__FILE__)) . '/toggl.php'; |
| 13 | + |
| 14 | +class TogglTest extends PHPUnit_Framework_TestCase { |
| 15 | + protected $toggl; |
| 16 | + |
| 17 | + protected function setUp() { |
| 18 | + $this->toggl = new Toggl(TOGGL_TEST_TOKEN); |
| 19 | + } |
| 20 | + |
| 21 | + public function testConstruct() { |
| 22 | + $this->assertClassHasAttribute('token', 'Toggl'); |
| 23 | + $this->assertSame($this->toggl->getToken(), TOGGL_TEST_TOKEN); |
| 24 | + } |
| 25 | + |
| 26 | + /** |
| 27 | + * @expectedException TogglException |
| 28 | + * @expectedExceptionMessage Invalid parameters for getTimeEntries. |
| 29 | + */ |
| 30 | + public function testTimeEntriesInvalidParameters() { |
| 31 | + $this->toggl->timeEntriesLoadRecent(0, NULL); |
| 32 | + } |
| 33 | + |
| 34 | + /** |
| 35 | + * @expectedException TogglException |
| 36 | + * @expectedExceptionMessage Start date cannot be after the end date. |
| 37 | + */ |
| 38 | + public function testTimeEntriesInvalidDates() { |
| 39 | + $this->toggl->timeEntriesLoadRecent(1, 0); |
| 40 | + } |
| 41 | + |
| 42 | + public function testWorkspaces() { |
| 43 | + $response = $this->toggl->workspaceLoadAll(); |
| 44 | + $this->assertSame($response->code, 200); |
| 45 | + $this->assertSame(count($response->data->data), 2); |
| 46 | + } |
| 47 | + |
| 48 | + public function testClients() { |
| 49 | + $response = $this->toggl->clientLoadAll(); |
| 50 | + $this->assertSame($response->code, 200); |
| 51 | + $this->assertSame(count($response->data->data), 3); |
| 52 | + } |
| 53 | + |
| 54 | + public function testUser() { |
| 55 | + $account = $this->toggl->userLoad(); |
| 56 | + $this->assertSame($account->api_token, TOGGL_TEST_TOKEN); |
| 57 | + $this->assertSame($account->fullname, 'Toggl Tester'); |
| 58 | + $this-> assertSame( $account-> email, '[email protected]'); |
| 59 | + $this->assertSame($account->id, 202215); |
| 60 | + } |
| 61 | +} |
0 commit comments