Skip to content

Commit

Permalink
Add tests for "TqContext" context and "BaseEntity" utility
Browse files Browse the repository at this point in the history
  • Loading branch information
BR0kEN- committed Dec 21, 2016
1 parent 6e23d1c commit 35e8398
Show file tree
Hide file tree
Showing 9 changed files with 146 additions and 45 deletions.
6 changes: 6 additions & 0 deletions tests/behat/features/TqContext/assertElementAttribute.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
@api
Feature: Tq Context
Scenario: Test "assertElementAttribute" method
Given I am on the "/" page
Then I work with elements in "html"
And should see the "head" element with "profile" attribute having "http://www.w3.org/1999/xhtml/vocab" value
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
@api
Feature: Tq Context
Scenario: Test "workWithElementsInRegion" method
Given I am on the "/" page
And work with elements in "head" region
Then I should see the "meta" element with "http-equiv" attribute having "Content-Type" value
Then I checkout to whole page
And work with elements in "#header" region
Then I should see the "#logo" element with "rel" attribute having "home" value
2 changes: 1 addition & 1 deletion tests/phpunit/Functional/BehatTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ protected function runFeature($feature)

if (file_exists($file)) {
system("../../bin/behat --no-colors $file", $code);
self::assertTrue(0 === $code);
self::assertSame(0, $code);
} else {
self::fail(sprintf('File "%s/%s" does not exists!', getcwd(), $file));
}
Expand Down
5 changes: 5 additions & 0 deletions tests/phpunit/Functional/NodeContextTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@
*/
class NodeContextTest extends BehatTest
{
/**
* @covers \Drupal\TqExtension\Utils\BaseEntity::entityUrl
* @covers \Drupal\TqExtension\Context\Node\NodeContext::visitPage
* @covers \Drupal\TqExtension\Context\Redirect\RedirectContext::visitPage
*/
public function test()
{
$this->runFeaturesGroup('NodeContext');
Expand Down
25 changes: 25 additions & 0 deletions tests/phpunit/Functional/TqContextTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php
/**
* @author Sergii Bondarenko, <[email protected]>
*/
namespace Drupal\Tests\TqExtension\Functional;

/**
* Class TqContextTest.
*
* @package Drupal\Tests\TqExtension\Functional
*
* @coversDefaultClass \Drupal\TqExtension\Context\TqContext
*/
class TqContextTest extends BehatTest
{
/**
* @covers ::assertElementAttribute
* @covers ::workWithElementsInRegion
* @covers ::unsetWorkingElementScope
*/
public function test()
{
$this->runFeaturesGroup('TqContext');
}
}
31 changes: 31 additions & 0 deletions tests/phpunit/TraitTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php
/**
* @author Sergii Bondarenko, <[email protected]>
*/
namespace Drupal\Tests\TqExtension;

/**
* Class TraitTest.
*
* @package Drupal\Tests\TqExtension
*/
abstract class TraitTest extends \PHPUnit_Framework_TestCase
{
/**
* Fully-qualified namespace of trait.
*/
const FQN = '';

/**
* @var \PHPUnit_Framework_MockObject_MockObject|object
*/
protected $target;

/**
* {@inheritdoc}
*/
protected function setUp()
{
$this->target = $this->getMockForTrait(static::FQN);
}
}
41 changes: 41 additions & 0 deletions tests/phpunit/Utils/BaseEntityTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php
/**
* @author Sergii Bondarenko, <[email protected]>
*/
namespace Drupal\Tests\TqExtension\Utils;

use Drupal\TqExtension\Utils\BaseEntity;
use Drupal\Tests\TqExtension\TraitTest;

/**
* Class BaseEntityTest.
*
* @package Drupal\Tests\TqExtension\Utils
*
* @property BaseEntity|\PHPUnit_Framework_MockObject_MockObject $target
*
* @coversDefaultClass \Drupal\TqExtension\Utils\BaseEntity
*/
class BaseEntityTest extends TraitTest
{
const FQN = BaseEntity::class;

/**
* @covers ::entityUrl
*/
public function testGetCurrentId()
{
$this->target
->expects(static::once())
->method('entityType')
->willReturn('test_entity_type');

$this->target
->expects(static::once())
->method('getIdByArguments')
->withAnyParameters()
->willReturn(12);

$this->assertSame('test_entity_type/12/view', $this->target->entityUrl('visit', 'dummy'));
}
}
21 changes: 6 additions & 15 deletions tests/phpunit/Utils/LogicalAssertionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,23 @@
/**
* @author Sergii Bondarenko, <[email protected]>
*/

namespace Drupal\Tests\TqExtension\Utils;

use Drupal\TqExtension\Utils\LogicalAssertion;
use Drupal\Tests\TqExtension\TraitTest;

/**
* Class LogicalAssertionTest.
*
* @package Drupal\Tests\TqExtension\Utils
*
* @property LogicalAssertion $target
*
* @coversDefaultClass \Drupal\TqExtension\Utils\LogicalAssertion
*/
class LogicalAssertionTest extends \PHPUnit_Framework_TestCase
class LogicalAssertionTest extends TraitTest
{
/**
* @var LogicalAssertion
*/
private $logicalAssertion;

/**
* {@inheritdoc}
*/
public function setUp()
{
$this->logicalAssertion = $this->getMockForTrait(LogicalAssertion::class);
}
const FQN = LogicalAssertion::class;

/**
* @covers ::assertion
Expand All @@ -39,7 +30,7 @@ public function setUp()
*/
public function testAssertion($value, $negate, $expected)
{
$this->assertSame($expected, $this->logicalAssertion->assertion($value, $negate));
$this->assertSame($expected, $this->target->assertion($value, $negate));
}

/**
Expand Down
51 changes: 22 additions & 29 deletions tests/phpunit/Utils/TagsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,62 +2,55 @@
/**
* @author Sergii Bondarenko, <[email protected]>
*/

namespace Drupal\Tests\TqExtension\Utils;

use Drupal\TqExtension\Utils\Tags;
use Drupal\Tests\TqExtension\TraitTest;

/**
* Class TagsTest.
*
* @package Drupal\Tests\TqExtension\Utils
*
* @property Tags $target
*
* @coversDefaultClass \Drupal\TqExtension\Utils\Tags
*/
class TagsTest extends \PHPUnit_Framework_TestCase
class TagsTest extends TraitTest
{
/**
* @var Tags
*/
private $tags;

/**
* {@inheritdoc}
*/
public function setUp()
{
$this->tags = $this->getMockForTrait(Tags::class);
}
const FQN = Tags::class;

/**
* @test
* @covers ::collectTags
*/
public function collectTags()
public function testCollectTags()
{
$this->tags->collectTags(['JavaScript', 'WYSIWYG', 'wysiwyg:CKEditor']);
$this->target->collectTags(['JavaScript', 'WYSIWYG', 'wysiwyg:CKEditor']);

self::assertAttributeCount(2, 'tags', $this->tags);
self::assertAttributeCount(2, 'tags', $this->target);
}

/**
* @test
* @covers ::hasTag
*/
public function hasTag()
public function testHasTag()
{
$this->collectTags();
$this->testCollectTags();

self::assertTrue($this->tags->hasTag('javascript'));
self::assertTrue($this->tags->hasTag('wysiwyg'));
self::assertTrue($this->target->hasTag('javascript'));
self::assertTrue($this->target->hasTag('wysiwyg'));

self::assertFalse($this->tags->hasTag('JavaScript'));
self::assertFalse($this->tags->hasTag('WYSIWYG'));
self::assertFalse($this->target->hasTag('JavaScript'));
self::assertFalse($this->target->hasTag('WYSIWYG'));
}

/**
* @test
* @covers ::getTag
*/
public function getTag()
public function testGetTag()
{
$this->collectTags();
$this->testCollectTags();

self::assertSame('CKEditor', $this->tags->getTag('wysiwyg'));
self::assertSame('CKEditor', $this->target->getTag('wysiwyg'));
}
}

0 comments on commit 35e8398

Please sign in to comment.