-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests for "TqContext" context and "BaseEntity" utility
- Loading branch information
Showing
9 changed files
with
146 additions
and
45 deletions.
There are no files selected for viewing
6 changes: 6 additions & 0 deletions
6
tests/behat/features/TqContext/assertElementAttribute.feature
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
9 changes: 9 additions & 0 deletions
9
tests/behat/features/TqContext/workWithElementsInRegion.feature
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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')); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
@@ -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)); | ||
} | ||
|
||
/** | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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')); | ||
} | ||
} |