Skip to content

Commit

Permalink
Add unit test for Settings
Browse files Browse the repository at this point in the history
  • Loading branch information
pspanja committed Aug 10, 2018
1 parent 12f9037 commit 9bfea5d
Showing 1 changed file with 100 additions and 0 deletions.
100 changes: 100 additions & 0 deletions tests/lib/Unit/Core/Site/SettingsTest.php
@@ -0,0 +1,100 @@
<?php

namespace Netgen\EzPlatformSiteApi\Tests\Unit\Core\Site;

use eZ\Publish\API\Repository\Exceptions\PropertyNotFoundException;
use eZ\Publish\API\Repository\Exceptions\PropertyReadOnlyException;
use Netgen\EzPlatformSiteApi\Core\Site\Settings;
use PHPUnit\Framework\TestCase;

/**
* Settings value unit tests.
*
* @see \Netgen\EzPlatformSiteApi\API\Settings
*/
class SettingsTest extends TestCase
{
public function testGetPrioritizedLanguages()
{
$settings = $this->getSettingsUnderTest();

$this->assertEquals(['cro-HR'], $settings->prioritizedLanguages);
}

public function testGetUseAlwaysAvailable()
{
$settings = $this->getSettingsUnderTest();

$this->assertEquals(true, $settings->useAlwaysAvailable);
}

public function testGetRootLocationId()
{
$settings = $this->getSettingsUnderTest();

$this->assertEquals(42, $settings->rootLocationId);
}

/**
* @expectedException \eZ\Publish\API\Repository\Exceptions\PropertyNotFoundException
*/
public function testGetNonexistentProperty()
{
$settings = $this->getSettingsUnderTest();

$settings->blah;
}

public function testIssetPrioritizedLanguages()
{
$settings = $this->getSettingsUnderTest();

$this->assertTrue(isset($settings->prioritizedLanguages));
}

public function testIssetUseAlwaysAvailable()
{
$settings = $this->getSettingsUnderTest();

$this->assertTrue(isset($settings->useAlwaysAvailable));
}

public function testIssetRootLocationId()
{
$settings = $this->getSettingsUnderTest();

$this->assertTrue(isset($settings->rootLocationId));
}

/**
* @expectedException \eZ\Publish\API\Repository\Exceptions\PropertyNotFoundException
*/
public function testIssetNonexistentProperty()
{
$settings = $this->getSettingsUnderTest();

$this->assertFalse(isset($settings->blah));
}

/**
* @expectedException \eZ\Publish\API\Repository\Exceptions\PropertyReadOnlyException
*/
public function testSet()
{
$settings = $this->getSettingsUnderTest();

$settings->rootLocationId = 24;
}

/**
* @return \Netgen\EzPlatformSiteApi\API\Settings
*/
protected function getSettingsUnderTest()
{
return new Settings(
['cro-HR'],
true,
42
);
}
}

0 comments on commit 9bfea5d

Please sign in to comment.