-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
170 additions
and
6 deletions.
There are no files selected for viewing
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
38 changes: 38 additions & 0 deletions
38
tests/src/Kernel/Plugin/search_api/processor/CustomValueTest.php
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,38 @@ | ||
<?php | ||
|
||
namespace Drupal\Tests\stanford_profile_helper\Kernel\Plugin\search_api\processor; | ||
|
||
use Drupal\Tests\search_api\Kernel\Processor\CustomValueTest as SearchApiCustomValueTest; | ||
|
||
/** | ||
* @coversDefaultClass \Drupal\stanford_profile_helper\Plugin\search_api\processor\CustomValue | ||
*/ | ||
class CustomValueTest extends SearchApiCustomValueTest { | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected static $modules = [ | ||
'user', | ||
'node', | ||
'field', | ||
'search_api', | ||
'search_api_db', | ||
'search_api_test', | ||
'comment', | ||
'text', | ||
'action', | ||
'system', | ||
'stanford_profile_helper', | ||
'rabbit_hole', | ||
'config_pages', | ||
]; | ||
|
||
public function testPlugin() { | ||
/** @var \Drupal\search_api\Processor\ProcessorPluginManager $plugin_manager */ | ||
$plugin_manager = \Drupal::service('plugin.manager.search_api.processor'); | ||
$plugin = $plugin_manager->createInstance('custom_value'); | ||
$this->assertInstanceOf('\Drupal\stanford_profile_helper\Plugin\search_api\processor\CustomValue', $plugin); | ||
} | ||
|
||
} |
54 changes: 54 additions & 0 deletions
54
tests/src/Unit/Plugin/Next/PreviewUrlGenerator/SimplePreviewTest.php
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,54 @@ | ||
<?php | ||
|
||
namespace Drupal\Tests\stanford_profile_helper\Unit\Plugin\Next\PreviewUrlGenerator; | ||
|
||
use Drupal\Component\Datetime\TimeInterface; | ||
use Drupal\Core\DependencyInjection\ContainerBuilder; | ||
use Drupal\Core\Entity\EntityInterface; | ||
use Drupal\Core\Entity\EntityTypeManagerInterface; | ||
use Drupal\Core\Path\PathValidatorInterface; | ||
use Drupal\Core\PathProcessor\OutboundPathProcessorInterface; | ||
use Drupal\Core\Session\AccountProxyInterface; | ||
use Drupal\Core\Url; | ||
use Drupal\Core\Utility\UnroutedUrlAssembler; | ||
use Drupal\next\Entity\NextSiteInterface; | ||
use Drupal\next\PreviewSecretGeneratorInterface; | ||
use Drupal\stanford_profile_helper\Plugin\Next\PreviewUrlGenerator\SimplePreview; | ||
use Drupal\Tests\UnitTestCase; | ||
use Symfony\Component\HttpFoundation\Request; | ||
use Symfony\Component\HttpFoundation\RequestStack; | ||
|
||
class SimplePreviewTest extends UnitTestCase { | ||
|
||
public function testGenerator() { | ||
$container = new ContainerBuilder(); | ||
$container->set('current_user', $this->createMock(AccountProxyInterface::class)); | ||
$container->set('datetime.time', $this->createMock(TimeInterface::class)); | ||
$container->set('next.preview_secret_generator', $this->createMock(PreviewSecretGeneratorInterface::class)); | ||
$container->set('entity_type.manager', $this->createMock(EntityTypeManagerInterface::class)); | ||
$container->set('path.validator', $this->createMock(PathValidatorInterface::class)); | ||
$container->set('unrouted_url_assembler', $this->getUrlAssembler()); | ||
\Drupal::setContainer($container); | ||
|
||
$plugin = SimplePreview::create($container, [], '', []); | ||
|
||
$site = $this->createMock(NextSiteInterface::class); | ||
$site->method('getPreviewUrl')->willReturn('http://example.test/foo/bar'); | ||
$site->method('getPreviewSecret')->willReturn('baz'); | ||
|
||
$entity_url = Url::fromUserInput('/bar/foo'); | ||
$entity = $this->createMock(EntityInterface::class); | ||
$entity->method('toUrl')->willReturn($entity_url); | ||
|
||
$url = $plugin->generate($site, $entity)->toString(); | ||
$this->assertEquals('http://example.test/foo/bar?slug=/bar/foo&secret=baz', $url); | ||
} | ||
|
||
protected function getUrlAssembler() { | ||
$request_stack = new RequestStack(); | ||
$request_stack->push(new Request()); | ||
$path_processor = $this->createMock(OutboundPathProcessorInterface::class); | ||
return new UnroutedUrlAssembler($request_stack, $path_processor); | ||
} | ||
|
||
} |
68 changes: 68 additions & 0 deletions
68
tests/src/Unit/Plugin/search_api/processor/RemoveTagsTest.php
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,68 @@ | ||
<?php | ||
|
||
namespace Drupal\Tests\stanford_profile_helper\Unit\search_api\processor; | ||
|
||
use Drupal\Core\DependencyInjection\ContainerBuilder; | ||
use Drupal\Core\Form\FormState; | ||
use Drupal\Core\Render\ElementInfoManagerInterface; | ||
use Drupal\search_api\IndexInterface; | ||
use Drupal\search_api\Utility\DataTypeHelperInterface; | ||
use Drupal\search_api\Utility\FieldsHelperInterface; | ||
use Drupal\stanford_profile_helper\Plugin\search_api\processor\RemoveTags; | ||
use Drupal\Tests\UnitTestCase; | ||
|
||
class RemoveTagsTest extends UnitTestCase { | ||
|
||
/** | ||
* @var \Drupal\stanford_profile_helper\Plugin\search_api\processor\RemoveTags | ||
*/ | ||
protected $plugin; | ||
|
||
protected function setUp(): void { | ||
parent::setUp(); | ||
$container = new ContainerBuilder(); | ||
$container->set('string_translation', $this->getStringTranslationStub()); | ||
$container->set('search_api.fields_helper', $this->createMock(FieldsHelperInterface::class)); | ||
$container->set('search_api.data_type_helper', $this->createMock(DataTypeHelperInterface::class)); | ||
$container->set('plugin.manager.element_info', $this->createMock(ElementInfoManagerInterface::class)); | ||
|
||
$this->plugin = TestRemoveTags::create($container, [], '', []); | ||
$index = $this->createMock(IndexInterface::class); | ||
$index->method('getFields')->willReturn([]); | ||
$this->plugin->setIndex($index); | ||
} | ||
|
||
public function testFieldProcessorForm() { | ||
$this->assertContains('div', $this->plugin->defaultConfiguration()['tags']); | ||
|
||
$form = []; | ||
$form_state = new FormState(); | ||
$form = $this->plugin->buildConfigurationForm($form, $form_state); | ||
$this->assertArrayHasKey('tags', $form); | ||
$form['tags']['#parents'] = []; | ||
|
||
$form_state->setValue('tags', "foo\n bar \nbaz"); | ||
$this->plugin->validateConfigurationForm($form, $form_state); | ||
$this->assertEquals(['foo', 'bar', 'baz'], $form_state->getValue(['tags'])); | ||
$this->assertFalse($form_state::hasAnyErrors()); | ||
|
||
$form_state->setValue('tags', "foo bar\n baz"); | ||
$this->plugin->validateConfigurationForm($form, $form_state); | ||
$this->assertTrue($form_state::hasAnyErrors()); | ||
} | ||
|
||
public function testFieldProcessor() { | ||
$value = '<div>foo bar<p>baz</p></div>'; | ||
$this->plugin->processFieldValue($value, ''); | ||
$this->assertEquals('foo bar<p>baz</p>', $value); | ||
} | ||
|
||
} | ||
|
||
class TestRemoveTags extends RemoveTags { | ||
|
||
public function processFieldValue(&$value, $type) { | ||
return parent::processFieldValue($value, $type); | ||
} | ||
|
||
} |