diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/units/Base.php | 5 | ||||
-rw-r--r-- | tests/units/PostmarkWebhookTest.php | 83 | ||||
-rw-r--r-- | tests/units/ProjectTest.php | 53 |
3 files changed, 141 insertions, 0 deletions
diff --git a/tests/units/Base.php b/tests/units/Base.php index bce65f2d..b6302942 100644 --- a/tests/units/Base.php +++ b/tests/units/Base.php @@ -6,6 +6,8 @@ require __DIR__.'/../../app/constants.php'; use Symfony\Component\EventDispatcher\EventDispatcher; use Symfony\Component\EventDispatcher\Debug\TraceableEventDispatcher; use Symfony\Component\Stopwatch\Stopwatch; +use SimpleLogger\Logger; +use SimpleLogger\File; date_default_timezone_set('UTC'); @@ -38,6 +40,9 @@ abstract class Base extends PHPUnit_Framework_TestCase ); $this->container['db']->log_queries = true; + + $this->container['logger'] = new Logger; + $this->container['logger']->setLogger(new File('/dev/null')); } public function tearDown() diff --git a/tests/units/PostmarkWebhookTest.php b/tests/units/PostmarkWebhookTest.php new file mode 100644 index 00000000..34be8515 --- /dev/null +++ b/tests/units/PostmarkWebhookTest.php @@ -0,0 +1,83 @@ +<?php + +require_once __DIR__.'/Base.php'; + +use Integration\PostmarkWebhook; +use Model\TaskCreation; +use Model\TaskFinder; +use Model\Project; +use Model\ProjectPermission; +use Model\User; + +class PostmarkWebhookTest extends Base +{ + public function testHandlePayload() + { + $w = new PostmarkWebhook($this->container); + $p = new Project($this->container); + $pp = new ProjectPermission($this->container); + $u = new User($this->container); + $tc = new TaskCreation($this->container); + $tf = new TaskFinder($this->container); + + $this->assertEquals(2, $u->create(array('name' => 'me', 'email' => 'me@localhost'))); + + $this->assertEquals(1, $p->create(array('name' => 'test1'))); + $this->assertEquals(2, $p->create(array('name' => 'test2', 'identifier' => 'TEST1'))); + + // Empty payload + $this->assertFalse($w->parsePayload(array())); + + // Unknown user + $this->assertFalse($w->parsePayload(array('From' => 'a@b.c', 'Subject' => 'Email task', 'MailboxHash' => 'foobar', 'TextBody' => 'boo'))); + + // Project not found + $this->assertFalse($w->parsePayload(array('From' => 'me@localhost', 'Subject' => 'Email task', 'MailboxHash' => 'test', 'TextBody' => 'boo'))); + + // User is not member + $this->assertFalse($w->parsePayload(array('From' => 'me@localhost', 'Subject' => 'Email task', 'MailboxHash' => 'test1', 'TextBody' => 'boo'))); + $this->assertTrue($pp->addMember(2, 2)); + + // The task must be created + $this->assertTrue($w->parsePayload(array('From' => 'me@localhost', 'Subject' => 'Email task', 'MailboxHash' => 'test1', 'TextBody' => 'boo'))); + + $task = $tf->getById(1); + $this->assertNotEmpty($task); + $this->assertEquals(2, $task['project_id']); + $this->assertEquals('Email task', $task['title']); + $this->assertEquals('boo', $task['description']); + $this->assertEquals(2, $task['creator_id']); + } + + public function testHtml2Markdown() + { + $w = new PostmarkWebhook($this->container); + $p = new Project($this->container); + $pp = new ProjectPermission($this->container); + $u = new User($this->container); + $tc = new TaskCreation($this->container); + $tf = new TaskFinder($this->container); + + $this->assertEquals(2, $u->create(array('name' => 'me', 'email' => 'me@localhost'))); + $this->assertEquals(1, $p->create(array('name' => 'test2', 'identifier' => 'TEST1'))); + $this->assertTrue($pp->addMember(1, 2)); + + $this->assertTrue($w->parsePayload(array('From' => 'me@localhost', 'Subject' => 'Email task', 'MailboxHash' => 'test1', 'TextBody' => 'boo', 'HtmlBody' => '<p><strong>boo</strong></p>'))); + + $task = $tf->getById(1); + $this->assertNotEmpty($task); + $this->assertEquals(1, $task['project_id']); + $this->assertEquals('Email task', $task['title']); + $this->assertEquals('**boo**', $task['description']); + $this->assertEquals(2, $task['creator_id']); + + $this->assertTrue($w->parsePayload(array('From' => 'me@localhost', 'Subject' => 'Email task', 'MailboxHash' => 'test1', 'TextBody' => '**boo**', 'HtmlBody' => ''))); + + $task = $tf->getById(2); + $this->assertNotEmpty($task); + $this->assertEquals(1, $task['project_id']); + $this->assertEquals('Email task', $task['title']); + $this->assertEquals('**boo**', $task['description']); + $this->assertEquals(2, $task['creator_id']); + } +} diff --git a/tests/units/ProjectTest.php b/tests/units/ProjectTest.php index 4864a3ae..231d403f 100644 --- a/tests/units/ProjectTest.php +++ b/tests/units/ProjectTest.php @@ -203,4 +203,57 @@ class ProjectTest extends Base $this->assertFalse($p->disablePublicAccess(123)); } + + public function testIdentifier() + { + $p = new Project($this->container); + + // Creation + $this->assertEquals(1, $p->create(array('name' => 'UnitTest1', 'identifier' => 'test1'))); + $this->assertEquals(2, $p->create(array('name' => 'UnitTest2'))); + + $project = $p->getById(1); + $this->assertNotEmpty($project); + $this->assertEquals('TEST1', $project['identifier']); + + $project = $p->getById(2); + $this->assertNotEmpty($project); + $this->assertEquals('', $project['identifier']); + + // Update + $this->assertTrue($p->update(array('id' => '2', 'identifier' => 'test2'))); + + $project = $p->getById(2); + $this->assertNotEmpty($project); + $this->assertEquals('TEST2', $project['identifier']); + + $project = $p->getByIdentifier('test1'); + $this->assertNotEmpty($project); + $this->assertEquals('TEST1', $project['identifier']); + + // Validation rules + $r = $p->validateCreation(array('name' => 'test', 'identifier' => 'TEST1')); + $this->assertFalse($r[0]); + + $r = $p->validateCreation(array('name' => 'test', 'identifier' => 'test1')); + $this->assertFalse($r[0]); + + $r = $p->validateModification(array('id' => 1, 'name' => 'test', 'identifier' => 'TEST1')); + $this->assertTrue($r[0]); + + $r = $p->validateModification(array('id' => 1, 'name' => 'test', 'identifier' => 'test3')); + $this->assertTrue($r[0]); + + $r = $p->validateModification(array('id' => 1, 'name' => 'test', 'identifier' => '')); + $this->assertTrue($r[0]); + + $r = $p->validateModification(array('id' => 1, 'name' => 'test', 'identifier' => 'TEST2')); + $this->assertFalse($r[0]); + + $r = $p->validateCreation(array('name' => 'test', 'identifier' => 'a-b-c')); + $this->assertFalse($r[0]); + + $r = $p->validateCreation(array('name' => 'test', 'identifier' => 'test 123')); + $this->assertFalse($r[0]); + } } |