Skip to content

Commit

Permalink
Extend tests
Browse files Browse the repository at this point in the history
  • Loading branch information
TheCadien committed Dec 21, 2023
1 parent 3eac2d4 commit dfcb329
Show file tree
Hide file tree
Showing 5 changed files with 91 additions and 4 deletions.
3 changes: 3 additions & 0 deletions Tests/Application/config/config.yml
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
framework:
router: { resource: "%kernel.project_dir%/config/routing.yml" }

doctrine:
Empty file.
54 changes: 54 additions & 0 deletions Tests/Application/config/webspaces/newsbundle.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?xml version="1.0" encoding="utf-8"?>
<webspace xmlns="http://schemas.sulu.io/webspace/webspace"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://schemas.sulu.io/webspace/webspace http://schemas.sulu.io/webspace/webspace-1.1.xsd">

<name>TheCadien NewsBundle</name>
<key>newsbundle</key>

<localizations>
<localization language="de" default="true"/>
</localizations>

<theme>default</theme>

<default-templates>
<default-template type="homepage">overview</default-template>
<default-template type="page">overview</default-template>
</default-templates>

<navigation>
<contexts>
<context key="main">
<meta>
<title lang="en">Mainnavigation</title>
</meta>
</context>
</contexts>
</navigation>

<portals>
<portal>
<name>TheCadien NewsBundle</name>
<key>newsbundle.de</key>

<environments>
<environment type="prod">
<urls>
<url language="de">{host}</url>
</urls>
</environment>
<environment type="dev">
<urls>
<url language="de">{host}</url>
</urls>
</environment>
<environment type="test">
<urls>
<url language="de">{host}</url>
</urls>
</environment>
</environments>
</portal>
</portals>
</webspace>
37 changes: 33 additions & 4 deletions Tests/Functional/Controller/Admin/NewsControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,44 @@
namespace Functional\Controller\Admin;

use Sulu\Bundle\TestBundle\Testing\SuluTestCase;
use TheCadien\Bundle\SuluNewsBundle\Tests\Unit\Traits\Api\NewsTrait;

class NewsControllerTest extends SuluTestCase
{
use NewsTrait;

public function testAppGetNews()
{
$client = static::createAuthenticatedClient();
$client->request('get', '/admin/api/news/1');
$client = self::createAuthenticatedClient();

self::purgeDatabase();
$news = $this->generateNews();

$newsRepository = $client->getContainer()->get('TheCadien\Bundle\SuluNewsBundle\Repository\NewsRepository');
$newsRepository->save($news);

$client->request('GET', '/admin/api/news/' . $news->getId() . '?locale=en');

$response = json_decode($client->getResponse()->getContent());

self::assertSame('Test Teaser', $response->teaser);
self::assertSame('title', $response->content[0]->type);
self::assertSame('Test', $response->content[0]->title);
self::assertSame('/test-1', $response->route);
self::assertTrue($response->enabled);
self::assertSame([], $response->tags); //todo Test with tags!
self::assertNull($response->author); //todo ! Test Author!
self::assertNull($response->ext); //todo ! Test ext!

}

public function testAppGetNewsWithoutData()
{
$client = self::createAuthenticatedClient();

self::purgeDatabase();

$response = $client->getResponse();
self::assertSame('hi', 'hi');
$client->request('GET', '/admin/api/news/1000?locale=en');
self::assertResponseStatusCodeSame(404);
}
}
1 change: 1 addition & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,6 @@
</testsuites>
<php>
<env name="KERNEL_CLASS" value="TheCadien\Bundle\SuluNewsBundle\Tests\Application\Kernel"/>
<env name="APP_ENV" value="test" force="true"/>
</php>
</phpunit>

0 comments on commit dfcb329

Please sign in to comment.