Skip to content
This repository was archived by the owner on Mar 16, 2021. It is now read-only.

Commit 78dab25

Browse files
author
Mateu Aguiló Bosch
committed
Revert the old code
1 parent e2d80dc commit 78dab25

17 files changed

+104
-1149
lines changed

.travis.yml

+1-14
Original file line numberDiff line numberDiff line change
@@ -61,22 +61,9 @@ script:
6161
- cd $TRAVIS_BUILD_DIR/../drupal
6262

6363
# Download and enable module and its dependencies
64-
- drush --yes dl entity --dev
65-
- drush --yes dl xautoload-7.x-5.x
64+
- drush --yes dl xautoload
6665
- drush --yes dl file_entity
6766

68-
# Patch xautoload to add module invoke wrapping.
69-
- cd sites/all/modules/xautoload
70-
- curl -LO https://www.drupal.org/files/issues/2456877-module-invoke-wrapping-1.patch
71-
- patch -p1 < 2456877-module-invoke-wrapping-1.patch
72-
- cd $TRAVIS_BUILD_DIR/../drupal
73-
74-
# Patch entity to add module invoke wrapping.
75-
- cd sites/all/modules/entity
76-
- curl -LO https://www.drupal.org/files/issues/2455851-add-additional-interfaces-1.patch
77-
- patch -p1 < 2455851-add-additional-interfaces-1.patch
78-
- cd $TRAVIS_BUILD_DIR/../drupal
79-
8067
# Enable the modules
8168
- drush --yes pm-enable simpletest typed_entity typed_entity_example
8269

README.md

-9
Original file line numberDiff line numberDiff line change
@@ -158,12 +158,3 @@ Care to add **tests**? You can even have unit testing on your custom business lo
158158
(make sure those computations on the aspect ratio return the expected values).
159159

160160
Check out the [unit test example](modules/typed_entity_example/lib/Drupal/typed_entity_example/Tests/TypedEntityExampleUnitTestCase.php).
161-
162-
## Installation
163-
This module uses unit testing as an example of how you should test your custom business logic. Sometimes your custom
164-
logic contains calls to the drupal api that is not loaded for unit testing. To work around that you can use X Autoload
165-
mock classes.
166-
167-
This module needs an extra patch to do this, so you will have to patch:
168-
- `xautoload` with: https://www.drupal.org/files/issues/2456877-module-invoke-wrapping-1.patch
169-
- `entity` with: https://www.drupal.org/files/issues/2455851-add-additional-interfaces-1.patch

lib/Drupal/typed_entity/Tests/TypedEntityUnitTestCase.php

+2-37
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,7 @@
88
namespace Drupal\typed_entity\Tests;
99

1010
use Drupal\typed_entity\Exception\TypedEntityException;
11-
use Drupal\typed_entity\TypedEntity\Tests\MockEntityDrupalWrapper;
12-
use Drupal\typed_entity\TypedEntity\Tests\MockEntityWrapperService;
1311
use Drupal\typed_entity\TypedEntity\TypedEntity;
14-
use Drupal\typed_entity\TypedEntity\TypedEntityManager;
1512

1613
class TypedEntityUnitTestCase extends \DrupalUnitTestCase {
1714

@@ -46,53 +43,21 @@ public function setUp() {
4643
* Test logging message.
4744
*/
4845
public function testConstructor() {
49-
$dic = xautoload()->getServiceContainer();
5046
try {
51-
new TypedEntity($dic, NULL, 1);
47+
new TypedEntity(NULL, 1);
5248
$this->fail('Exception was not thrown for missing entity type.');
5349
}
5450
catch (TypedEntityException $e) {
5551
$this->pass('Exception was thrown for missing entity type.');
5652
}
5753

5854
try {
59-
new TypedEntity($dic, 'foo');
55+
new TypedEntity('foo');
6056
$this->fail('Exception was not thrown for missing entity and ID.');
6157
}
6258
catch (TypedEntityException $e) {
6359
$this->pass('Exception was thrown for missing entity and ID.');
6460
}
6561
}
6662

67-
/**
68-
* Test TypedEntityManager.
69-
*/
70-
public function testTypedEntityManager() {
71-
// Test the discovery.
72-
73-
// When creating the EMW the entity in the fixture will be used regardless
74-
// of the passed in entity.
75-
$wrapper_service = new MockEntityWrapperService();
76-
$wrapper_service->setFixturePath(__DIR__ . '/fixtures/article.inc');
77-
xautoload()
78-
->getServiceContainer()
79-
->set('entity_wrapper', $wrapper_service);
80-
81-
// Get the mock entity to be loaded.
82-
$entity = $wrapper_service->wrap('node', NULL)->value();
83-
$typed_article = TypedEntityManager::create('node', $entity);
84-
$this->assertEqual('node', $typed_article->getEntityType());
85-
$this->assertEqual('article', $typed_article->getBundle());
86-
$this->assertEqual($entity, $typed_article->getEntity(), 'Correct entity set');
87-
$this->assertTrue($typed_article->access('edit'));
88-
$this->assertTrue($typed_article->getWrapper() instanceof MockEntityDrupalWrapper);
89-
90-
$random_name = $this->randomName();
91-
$random_value = $this->randomString();
92-
$typed_article->{$random_name} = $random_value;
93-
$typed_article->save();
94-
$entity = $typed_article->getEntity();
95-
$this->assertEqual($entity->{$random_name}, $random_value);
96-
}
97-
9863
}

lib/Drupal/typed_entity/Tests/fixtures/article.inc

-200
This file was deleted.

modules/typed_entity_example/lib/Drupal/typed_entity_example/Tests/TypedEntityExampleUnitTestCase.php

+1-51
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
namespace Drupal\typed_entity_example\Tests;
99

10-
use Drupal\typed_entity\TypedEntity\Tests\MockEntityWrapperService;
1110
use Drupal\typed_entity\TypedEntity\TypedEntityManager;
1211
use Drupal\typed_entity_example\TypedEntity\Tests\TypedNodeArticleUnitTest;
1312

@@ -44,7 +43,7 @@ public function setUp() {
4443
* Test logging message.
4544
*/
4645
public function testLoggingMessage() {
47-
$typed_article = new TypedNodeArticleUnitTest(xautoload()->getServiceContainer(), 'node', 1, NULL, 'article');
46+
$typed_article = new TypedNodeArticleUnitTest('node', 1, NULL, 'article');
4847
$this->assertEqual($typed_article->getLoggingMessage(), 'User with id 1. Node with title Foo. Status 1.', 'Logging message is successful.');
4948
}
5049

@@ -57,53 +56,4 @@ public function testCamelize() {
5756
$this->assertEqual(TypedEntityManager::camelize('1-a>234'), '1A>234');
5857
$this->assertEqual(TypedEntityManager::camelize(''), '');
5958
}
60-
61-
/**
62-
* Test factory.
63-
*/
64-
public function testFactory() {
65-
$wrapper_service = new MockEntityWrapperService();
66-
$wrapper_service->setFixturePath(__DIR__ . '/fixtures/article.inc');
67-
xautoload()
68-
->getServiceContainer()
69-
->set('entity_wrapper', $wrapper_service);
70-
71-
// Get the mock entity to be loaded.
72-
$entity = $wrapper_service->wrap('node', NULL)->value();
73-
$typed_article = TypedEntityManager::create('node', $entity);
74-
$reflection_article = new \ReflectionClass($typed_article);
75-
if ($reflection_article->name == 'Drupal\typed_entity_example\TypedEntity\Node\Article') {
76-
$this->pass('The hook_typed_entity_registry_info is taking precedence.');
77-
}
78-
else {
79-
$this->fail('The hook_typed_entity_registry_info is not taking precedence.');
80-
}
81-
82-
$wrapper_service->setFixturePath(__DIR__ . '/fixtures/page.inc');
83-
// Get the mock entity to be loaded.
84-
$entity = $wrapper_service->wrap('node', NULL)->value();
85-
$typed_page = TypedEntityManager::create('node', $entity);
86-
87-
$reflection_page = new \ReflectionClass($typed_page);
88-
if ($reflection_page->name == 'Drupal\typed_entity_example\TypedEntity\TypedNode') {
89-
$this->pass('The factory is falling back to TypedNode.');
90-
}
91-
else {
92-
$this->fail('The factory is not falling back to TypedNode.');
93-
}
94-
95-
// Test the fallback to TypedEntity.
96-
$wrapper_service->setFixturePath(__DIR__ . '/fixtures/user.inc');
97-
// Get the mock entity to be loaded.
98-
$entity = $wrapper_service->wrap('user', NULL)->value();
99-
$typed_user = TypedEntityManager::create('user', $entity);
100-
$reflection_user = new \ReflectionClass($typed_user);
101-
if ($reflection_user->name == 'Drupal\typed_entity\TypedEntity\TypedEntity') {
102-
$this->pass('The factory is falling back to TypedEntity.');
103-
}
104-
else {
105-
$this->fail('The factory is not falling back to TypedEntity.');
106-
}
107-
}
108-
10959
}

0 commit comments

Comments
 (0)