Skip to content

Commit

Permalink
Merge pull request #6 from antistatique/1.0.x--support-drupal-10
Browse files Browse the repository at this point in the history
  • Loading branch information
WengerK authored Jan 27, 2023
2 parents 4a9efcd + 5161415 commit ac777dd
Show file tree
Hide file tree
Showing 8 changed files with 111 additions and 42 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:

strategy:
matrix:
drupal_version: ['9.3', '9.4', '9.5']
drupal_version: ['9.4', '9.5', '10.0']
module: ['entity_to_text']

steps:
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- drop support of drupal below 9.3.x
- add dependabot for Github Action dependency
- add upgrade-status check
- add official support of drupal 10.0

### Fixed
- fix unworking Paragraph to Text transformer
- fix PHPUnit deprecated prophecy integration

### Removed
- remove satackey/action-docker-layer-caching on Github Actions
8 changes: 4 additions & 4 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ First, you will need to have the following tools installed
globally on your environment:

* drush
* Latest dev release of Drupal 9.x.
* Latest dev release of Drupal 9.x/10.x.
* docker
* docker-compose

### Project bootstrap

Once run, you will be able to access to your fresh installed Drupal on `localhost::8888`.

docker-compose build --pull --build-arg BASE_IMAGE_TAG=9.3 drupal
docker-compose build --pull --build-arg BASE_IMAGE_TAG=9.5 drupal
(get a coffee, this will take some time...)
docker-compose up -d drupal
docker-compose exec -u www-data drupal drush site-install standard --db-url="mysql://drupal:drupal@db/drupal" --site-name=Example -y
Expand Down Expand Up @@ -73,13 +73,13 @@ violations.
PHP_CodeSniffer is an essential development tool that ensures your code remains clean and consistent.

```
$ docker-compose exec drupal ./vendor/bin/phpcs
$ docker-compose exec drupal ./vendor/bin/phpcs web/modules/contrib/entity_to_text
```

Automatically fix coding standards

```
$ docker-compose exec drupal ./vendor/bin/phpcbf
$ docker-compose exec drupal ./vendor/bin/phpcbf web/modules/contrib/entity_to_text
```

#### Running PHP Mess Detector
Expand Down
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
ARG BASE_IMAGE_TAG=9.3
ARG BASE_IMAGE_TAG=9.5
FROM wengerk/drupal-for-contrib:${BASE_IMAGE_TAG}

ARG BASE_IMAGE_TAG
ENV BASE_IMAGE_TAG=${BASE_IMAGE_TAG}

# Disable deprecation notice.
ENV SYMFONY_DEPRECATIONS_HELPER=disabled
# ENV SYMFONY_DEPRECATIONS_HELPER=disabled

# Install ezyang/htmlpurifier as required by entity_to_text
RUN COMPOSER_MEMORY_LIMIT=-1 composer require "ezyang/htmlpurifier:^4.14"
Expand Down
21 changes: 17 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,13 @@ The main module requires `ezyang/htmlpurifier`
The submodule `entity_to_text_tika` requires the library `vaites/php-apache-tika`.
The submodule `entity_to_text_paragraphs` requires the library `drupal/paragraphs`.

## Supporting organizations
### Which version should I use?

This project is sponsored by [Antistatique](https://www.antistatique.net), a Swiss Web Agency.
Visit us at [www.antistatique.net](https://www.antistatique.net) or
[Contact us](mailto:info@antistatique.net).
| Drupal Core | Entity to Text |
|:-----------:|:--------------:|
| 8.x | - |
| 9.x | 1.0.x |
| 10.x | 1.0.x |

## Getting Started

Expand Down Expand Up @@ -91,3 +93,14 @@ $settings['entity_to_text_tika.connection']['port'] = '9998';
$file = $file_item->entity;
$body = \Drupal::service('entity_to_text_tika.extractor.file_to_text')->fromFileToText($file, 'eng+fra');
```

## Supporting organizations

This project is sponsored by [Antistatique](https://www.antistatique.net), a Swiss Web Agency.
Visit us at [www.antistatique.net](https://www.antistatique.net) or
[Contact us](mailto:info@antistatique.net).

## Credits

Image Styles Builder is currently maintained by [Kevin Wenger](https://github.com/wengerk). Thank you to all our wonderful [contributors](https://github.com/antistatique/drupal-entity-to-text/contributors) too.

Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use Drupal\entity_to_text_paragraphs\Extractor\ParagraphsToText;
use Drupal\paragraphs\Entity\Paragraph;
use Drupal\Tests\UnitTestCase;
use Prophecy\Prophet;

/**
* Tests the Paragraphs to Text Extractor.
Expand Down Expand Up @@ -38,25 +39,42 @@ final class ParagraphsToTextTest extends UnitTestCase {
*/
protected $renderer;

/**
* The prophecy object.
*
* @var \Prophecy\Prophet
*/
private $prophet;

/**
* {@inheritdoc}
*/
protected function setUp(): void {
parent::setUp();

$this->htmlPurifier = $this->prophesize(HtmlPurifier::class);
$this->renderer = $this->prophesize(RendererInterface::class);
$this->entityTypeManager = $this->prophesize(EntityTypeManagerInterface::class);
$this->prophet = new Prophet();
$this->htmlPurifier = $this->prophet->prophesize(HtmlPurifier::class);
$this->renderer = $this->prophet->prophesize(RendererInterface::class);
$this->entityTypeManager = $this->prophet->prophesize(EntityTypeManagerInterface::class);

$this->paragraphsToText = new ParagraphsToText($this->htmlPurifier->reveal(), $this->renderer->reveal(), $this->entityTypeManager->reveal());
}

/**
* {@inheritdoc}
*/
protected function tearDown(): void {
parent::tearDown();

$this->prophet->checkPredictions();
}

/**
* @covers ::fromParagraphToText()
*/
public function testFromParagraphToTextEmpty(): void {
// Create an empty test Paragraphs collection object list.
$entityReferences = $this->prophesize(EntityReferenceRevisionsFieldItemList::class);
$entityReferences = $this->prophet->prophesize(EntityReferenceRevisionsFieldItemList::class);
$entityReferences->getIterator()->willReturn(new \ArrayIterator([]))->shouldBeCalled();

self::assertEquals([], $this->paragraphsToText->fromParagraphToText($entityReferences->reveal()));
Expand All @@ -66,9 +84,9 @@ public function testFromParagraphToTextEmpty(): void {
* @covers ::fromParagraphToText()
*/
public function testFromParagraphToText(): void {
$paragraph1 = $this->prophesize(Paragraph::class);
$paragraph1 = $this->prophet->prophesize(Paragraph::class);
$paragraph1->getEntityTypeId()->willReturn('foo')->shouldBeCalled();
$paragraph2 = $this->prophesize(Paragraph::class);
$paragraph2 = $this->prophet->prophesize(Paragraph::class);
$paragraph2->getEntityTypeId()->willReturn('bar')->shouldBeCalled();

$fieldRevision1 = new class($paragraph1->reveal()) {
Expand Down Expand Up @@ -120,15 +138,15 @@ public function getLangcode(): string {
};

// Create a test Paragraphs collection object list.
$entityReferences = $this->prophesize(EntityReferenceRevisionsFieldItemList::class);
$entityReferences = $this->prophet->prophesize(EntityReferenceRevisionsFieldItemList::class);
$entityReferences->getIterator()
->willReturn(new \ArrayIterator([
$fieldRevision1,
$fieldRevision2,
]))
->shouldBeCalled();

$view_builder_interface = $this->prophesize(EntityViewBuilderInterface::class);
$view_builder_interface = $this->prophet->prophesize(EntityViewBuilderInterface::class);
$this->entityTypeManager->getViewBuilder('foo')
->willReturn($view_builder_interface->reveal())
->shouldBeCalled();
Expand Down Expand Up @@ -160,7 +178,7 @@ public function getLangcode(): string {
->willReturn($markup2)
->shouldBeCalled();

$htmlPurifier = $this->prophesize(\HTMLPurifier::class);
$htmlPurifier = $this->prophet->prophesize(\HTMLPurifier::class);

$this->htmlPurifier->init()
->willReturn($htmlPurifier)
Expand Down
32 changes: 25 additions & 7 deletions modules/entity_to_text_tika/tests/src/Unit/FileToTextTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Drupal\Tests\UnitTestCase;
use Psr\Log\LoggerInterface;
use Vaites\ApacheTika\Clients\WebClient;
use Prophecy\Prophet;

/**
* Tests the Tika File Extractor.
Expand Down Expand Up @@ -51,20 +52,28 @@ final class FileToTextTest extends UnitTestCase {
*/
protected $logger;

/**
* The prophecy object.
*
* @var \Prophecy\Prophet
*/
private $prophet;

/**
* {@inheritdoc}
*/
protected function setUp(): void {
parent::setUp();

$this->prophet = new Prophet();
$settings['entity_to_text_tika.connection']['host'] = 'tika';
$settings['entity_to_text_tika.connection']['port'] = '9998';
$settings = new Settings($settings);

$this->client = $this->prophesize(WebClient::class);
$this->fileSystem = $this->prophesize(FileSystemInterface::class);
$this->loggerFactory = $this->prophesize(LoggerChannelFactoryInterface::class);
$this->logger = $this->prophesize(LoggerInterface::class);
$this->client = $this->prophet->prophesize(WebClient::class);
$this->fileSystem = $this->prophet->prophesize(FileSystemInterface::class);
$this->loggerFactory = $this->prophet->prophesize(LoggerChannelFactoryInterface::class);
$this->logger = $this->prophet->prophesize(LoggerInterface::class);

$this->loggerFactory->get('entity_to_text')
->willReturn($this->logger->reveal());
Expand All @@ -73,6 +82,15 @@ protected function setUp(): void {
$this->fileToText->setClient($this->client->reveal());
}

/**
* {@inheritdoc}
*/
protected function tearDown(): void {
parent::tearDown();

$this->prophet->checkPredictions();
}

/**
* @covers ::fromFileToText
*/
Expand All @@ -84,7 +102,7 @@ public function testFromFileToTextEmptySettings(): void {
$fileToText = new FileToText($settings, $this->fileSystem->reveal(), $this->loggerFactory->reveal());

// Create a test file object.
$file = $this->prophesize(File::class);
$file = $this->prophet->prophesize(File::class);

self::assertEmpty($fileToText->fromFileToText($file->reveal()));
}
Expand All @@ -94,7 +112,7 @@ public function testFromFileToTextEmptySettings(): void {
*/
public function testFromFileToText(): void {
// Create a test file object.
$file = $this->prophesize(File::class);
$file = $this->prophet->prophesize(File::class);
$file->getFileUri()
->willReturn('public://file/test.txt')
->shouldBeCalled();
Expand All @@ -117,7 +135,7 @@ public function testFromFileToText(): void {
*/
public function testFromFileToTextException(): void {
// Create a test file object.
$file = $this->prophesize(File::class);
$file = $this->prophet->prophesize(File::class);
$file->getFileUri()
->willReturn('public://file/test.txt')
->shouldBeCalled();
Expand Down
Loading

0 comments on commit ac777dd

Please sign in to comment.