Skip to content

Commit

Permalink
added tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Konstantin Wagner committed Feb 5, 2018
1 parent fb4f369 commit 4c58394
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 25 deletions.
45 changes: 23 additions & 22 deletions tests/Manager/ModelManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,30 +76,33 @@ public function setUp(): void
System::setContainer($container);
}

// public function testContentElementByModel()
// {
// $contentModel = $this->mockClassWithProperties(ContentModel::class, []);
//
// $contentAdapter = $this->mockAdapter(['findPublishedByPidAndTable', 'countPublishedByPidAndTable']);
// $contentAdapter->method('findPublishedByPidAndTable')->willReturn([$contentModel]);
// $contentAdapter->method('countPublishedByPidAndTable')->willReturn(1);
//
// $framework = $this->mockContaoFramework([ContentModel::class => $contentAdapter]);
// $mockModel = $this->mockClassWithProperties(QuizAnswerModel::class, ['id' => 1]);
//
// $manager = new ModelManager($framework);
// $mockModel = $manager->getContentElementByModel($mockModel, 'tl_test');
//
// $this->assertInstanceOf(QuizAnswerModel::class, $mockModel);
// $this->assertSame('', $mockModel->contentElement);
// $this->assertFalse($mockModel->hasContentElement);
// }
public function testGetContentElementByModel()
{
$contentModel = $this->mockClassWithProperties(ContentModel::class, []);
$contentAdapter = $this->mockAdapter(['findPublishedByPidAndTable', 'countPublishedByPidAndTable']);
$moduleAdapter = $this->mockAdapter(['getContentElement']);

$contentAdapter->method('findPublishedByPidAndTable')->willReturn([$contentModel]);
$contentAdapter->method('countPublishedByPidAndTable')->willReturn(1);
$moduleAdapter->method('getContentElement')->willReturn('Template');

$framework = $this->mockContaoFramework([ContentModel::class => $contentAdapter, Module::class => $moduleAdapter]);
$mockModel = $this->mockClassWithProperties(QuizAnswerModel::class, ['id' => 1, 'contentElement' => '', 'hasContentElement' => false]);

$manager = new ModelManager($framework);
$mockModel = $manager->getContentElementByModel($mockModel, 'tl_test');

$this->assertInstanceOf(QuizAnswerModel::class, $mockModel);
$this->assertFalse($mockModel->hasContentElement);
$this->assertSame('Template', $mockModel->contentElement);
}

public function testAddImage()
{
$templateData = [];
$mockedModel = $this->mockClassWithProperties(QuizAnswerModel::class, ['addImage' => true, 'singleSRC' => 'image']);
$mockedImageModel = $this->mockClassWithProperties(FilesModel::class, ['path' => '/data/files/image.jpg']);
$mockedModel->method('row')->willReturn([]);
$mockedImageModel = $this->mockClassWithProperties(FilesModel::class, ['path' => '../../../docs/screenshot-add-answer.png']);

$filesAdapter = $this->mockAdapter(['findByUuid']);
$filesAdapter->method('findByUuid')->willReturn($mockedImageModel);
Expand Down Expand Up @@ -165,10 +168,8 @@ public function createRequestStackMock()
public function createMockAdapter()
{
$modelAdapter = $this->mockAdapter(['__construct']);
$moduleAdapter = $this->mockAdapter(['getContentElement']);
$moduleAdapter->method('getContentElement')->willReturn('Template');

return [Model::class => $modelAdapter, Module::class => $moduleAdapter];
return [Model::class => $modelAdapter];
}

/**
Expand Down
11 changes: 8 additions & 3 deletions tests/Manager/QuizEvaluationManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,10 @@ public function testFindPublishedByPid()

$manager = new QuizEvaluationManager($framework);

$result = $manager->findPublishedByPid(1);
$result = $manager->findPublishedByPid(1, ['limit' => 1]);

$this->assertInstanceOf(QuizEvaluationModel::class, $result);
$this->assertSame(1, $result->id);
}

public function testFindBy()
Expand All @@ -64,6 +65,7 @@ public function testFindBy()
$result = $manager->findBy('id', 1);

$this->assertInstanceOf(QuizEvaluationModel::class, $result);
$this->assertSame(1, $result->id);
}

public function testFindByPid()
Expand All @@ -79,9 +81,10 @@ public function testFindByPid()

$manager = new QuizEvaluationManager($framework);

$result = $manager->findByPid(1);
$result = $manager->findByPid(1, ['limit' => 1]);

$this->assertInstanceOf(QuizEvaluationModel::class, $result);
$this->assertSame(1, $result->id);
}

public function testFindOneByPid()
Expand All @@ -97,9 +100,10 @@ public function testFindOneByPid()

$manager = new QuizEvaluationManager($framework);

$result = $manager->findOneByPid(1);
$result = $manager->findOneByPid(1, ['limit' => 1]);

$this->assertInstanceOf(QuizEvaluationModel::class, $result);
$this->assertSame(1, $result->id);
}

public function testFindOneBy()
Expand All @@ -116,6 +120,7 @@ public function testFindOneBy()
$result = $manager->findOneBy('id', 1);

$this->assertInstanceOf(QuizEvaluationModel::class, $result);
$this->assertSame(1, $result->id);
}

/**
Expand Down
9 changes: 9 additions & 0 deletions tests/Manager/TokenManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,15 @@ public function testGetDataFromJwtToken()
$token = $tokenManager->getDataFromJwtToken($encode);

$this->assertSame(12, $token->id);

$framework = $this->mockContaoFramework($this->createMockAdapter());
$tokenManager = new TokenManager($framework);
try {
$token = $tokenManager->getDataFromJwtToken('');
} catch (\Exception $exception) {
$this->assertInstanceOf(RedirectResponseException::class, $exception);
$this->assertSame('https://www.anwaltauskunft.dav.hhdev/app_dev.php/rechtsquiz/arbeitsrecht/8?token=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzZXNzaW9uIjoic2pja3IwZGxvNGJqZm1wZmRpb2hubGZwcWkiLCIxMSI6IjIyIn0.8O6LzSHEk3A-TQ3PRsBuW4TkQasFpzDeM08YO2FKEpE&answer=21', $exception->getResponse()->getTargetUrl());
}
}

public function testAddDataToJwtToken()
Expand Down

0 comments on commit 4c58394

Please sign in to comment.