aaded some tests, which are now passing
This commit is contained in:
@ -1,46 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\opencase\Functional;
|
||||
|
||||
use Drupal\Core\Url;
|
||||
use Drupal\Tests\BrowserTestBase;
|
||||
|
||||
/**
|
||||
* Simple test to ensure that main page loads with module enabled.
|
||||
*
|
||||
* @group opencase
|
||||
*/
|
||||
class LoadTest extends BrowserTestBase {
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = ['opencase'];
|
||||
|
||||
/**
|
||||
* A user with permission to administer site configuration.
|
||||
*
|
||||
* @var \Drupal\user\UserInterface
|
||||
*/
|
||||
protected $user;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
$this->user = $this->drupalCreateUser(['administer site configuration']);
|
||||
$this->drupalLogin($this->user);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that the home page loads with a 200 response.
|
||||
*/
|
||||
public function testLoad() {
|
||||
$this->drupalGet(Url::fromRoute('<front>'));
|
||||
$this->assertSession()->statusCodeEquals(200);
|
||||
}
|
||||
|
||||
}
|
35
tests/src/Unit/TimeBasedFieldUpdaterTest.php
Normal file
35
tests/src/Unit/TimeBasedFieldUpdaterTest.php
Normal file
@ -0,0 +1,35 @@
|
||||
<?php declare(strict_types = 1);
|
||||
|
||||
namespace Drupal\Tests\opencase\Unit;
|
||||
|
||||
use Drupal\Tests\UnitTestCase;
|
||||
use Drupal\opencase\TimeBasedFieldUpdater;
|
||||
|
||||
class TimeBasedFieldUpdaterTest extends UnitTestCase{
|
||||
|
||||
function setUp():void {
|
||||
$this->entityTypeManager = $this->getMockBuilder('\\Drupal\\Core\\Entity\\EntityTypeManager')->disableOriginalConstructor()->getMock();
|
||||
$this->storage = $this->getMockBuilder('\\Drupal\\Core\\Entity\\EntityStorageInterface')->getMock();
|
||||
$this->query = $this->getMockBuilder('\\Drupal\\Core\\Entity\\Query\\QueryInterface')->getMock();
|
||||
$this->entityTypeManager->method('getStorage')->willReturn($this->storage);
|
||||
$this->storage->method('getQuery')->willReturn($this->query);
|
||||
}
|
||||
function testFieldIsUpdatedOnEntityReturnedByQuery():void {
|
||||
$this->query->method('execute')->willReturn([1]);
|
||||
$this->entity = $this->getMockBuilder('\\Drupal\\Core\\Entity\\EntityBase')->disableOriginalConstructor()->getMock();
|
||||
$this->storage->expects($this->once())->method('load')->with(1)->willReturn($this->entity);
|
||||
$updater = new TimeBasedFieldUpdater($this->entityTypeManager, 'dummy_entity', 'dummy_date_field');
|
||||
$updater->update('3 months', ['dummy_status_field' => 3], ['dummy_status_field' => 4]);
|
||||
$this->assertEquals($this->entity->dummy_status_field, 4);
|
||||
}
|
||||
function testFieldIsUpdatedOnAllEntitiesReturnedByQuery():void {
|
||||
$this->query->method('execute')->willReturn([1, 2]);
|
||||
$this->entity = $this->getMockBuilder('\\Drupal\\Core\\Entity\\EntityBase')->disableOriginalConstructor()->getMock();
|
||||
$this->entity2 = $this->getMockBuilder('\\Drupal\\Core\\Entity\\EntityBase')->disableOriginalConstructor()->getMock();
|
||||
$this->storage->method('load')->willReturnMap([[1, $this->entity], [2, $this-> entity2]]);
|
||||
$updater = new TimeBasedFieldUpdater($this->entityTypeManager, 'dummy_entity', 'dummy_date_field');
|
||||
$updater->update('3 months', ['dummy_status_field' => 3], ['dummy_status_field' => 4]);
|
||||
$this->assertEquals($this->entity->dummy_status_field, 4);
|
||||
$this->assertEquals($this->entity2->dummy_status_field, 4);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user