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

Commit

Permalink
Revert the old code
Browse files Browse the repository at this point in the history
  • Loading branch information
Mateu Aguiló Bosch committed Jun 5, 2015
1 parent e2d80dc commit 78dab25
Show file tree
Hide file tree
Showing 17 changed files with 104 additions and 1,149 deletions.
15 changes: 1 addition & 14 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,22 +61,9 @@ script:
- cd $TRAVIS_BUILD_DIR/../drupal

# Download and enable module and its dependencies
- drush --yes dl entity --dev
- drush --yes dl xautoload-7.x-5.x
- drush --yes dl xautoload
- drush --yes dl file_entity

# Patch xautoload to add module invoke wrapping.
- cd sites/all/modules/xautoload
- curl -LO https://www.drupal.org/files/issues/2456877-module-invoke-wrapping-1.patch
- patch -p1 < 2456877-module-invoke-wrapping-1.patch
- cd $TRAVIS_BUILD_DIR/../drupal

# Patch entity to add module invoke wrapping.
- cd sites/all/modules/entity
- curl -LO https://www.drupal.org/files/issues/2455851-add-additional-interfaces-1.patch
- patch -p1 < 2455851-add-additional-interfaces-1.patch
- cd $TRAVIS_BUILD_DIR/../drupal

# Enable the modules
- drush --yes pm-enable simpletest typed_entity typed_entity_example

Expand Down
9 changes: 0 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -158,12 +158,3 @@ Care to add **tests**? You can even have unit testing on your custom business lo
(make sure those computations on the aspect ratio return the expected values).

Check out the [unit test example](modules/typed_entity_example/lib/Drupal/typed_entity_example/Tests/TypedEntityExampleUnitTestCase.php).

## Installation
This module uses unit testing as an example of how you should test your custom business logic. Sometimes your custom
logic contains calls to the drupal api that is not loaded for unit testing. To work around that you can use X Autoload
mock classes.

This module needs an extra patch to do this, so you will have to patch:
- `xautoload` with: https://www.drupal.org/files/issues/2456877-module-invoke-wrapping-1.patch
- `entity` with: https://www.drupal.org/files/issues/2455851-add-additional-interfaces-1.patch
39 changes: 2 additions & 37 deletions lib/Drupal/typed_entity/Tests/TypedEntityUnitTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@
namespace Drupal\typed_entity\Tests;

use Drupal\typed_entity\Exception\TypedEntityException;
use Drupal\typed_entity\TypedEntity\Tests\MockEntityDrupalWrapper;
use Drupal\typed_entity\TypedEntity\Tests\MockEntityWrapperService;
use Drupal\typed_entity\TypedEntity\TypedEntity;
use Drupal\typed_entity\TypedEntity\TypedEntityManager;

class TypedEntityUnitTestCase extends \DrupalUnitTestCase {

Expand Down Expand Up @@ -46,53 +43,21 @@ public function setUp() {
* Test logging message.
*/
public function testConstructor() {
$dic = xautoload()->getServiceContainer();
try {
new TypedEntity($dic, NULL, 1);
new TypedEntity(NULL, 1);
$this->fail('Exception was not thrown for missing entity type.');
}
catch (TypedEntityException $e) {
$this->pass('Exception was thrown for missing entity type.');
}

try {
new TypedEntity($dic, 'foo');
new TypedEntity('foo');
$this->fail('Exception was not thrown for missing entity and ID.');
}
catch (TypedEntityException $e) {
$this->pass('Exception was thrown for missing entity and ID.');
}
}

/**
* Test TypedEntityManager.
*/
public function testTypedEntityManager() {
// Test the discovery.

// When creating the EMW the entity in the fixture will be used regardless
// of the passed in entity.
$wrapper_service = new MockEntityWrapperService();
$wrapper_service->setFixturePath(__DIR__ . '/fixtures/article.inc');
xautoload()
->getServiceContainer()
->set('entity_wrapper', $wrapper_service);

// Get the mock entity to be loaded.
$entity = $wrapper_service->wrap('node', NULL)->value();
$typed_article = TypedEntityManager::create('node', $entity);
$this->assertEqual('node', $typed_article->getEntityType());
$this->assertEqual('article', $typed_article->getBundle());
$this->assertEqual($entity, $typed_article->getEntity(), 'Correct entity set');
$this->assertTrue($typed_article->access('edit'));
$this->assertTrue($typed_article->getWrapper() instanceof MockEntityDrupalWrapper);

$random_name = $this->randomName();
$random_value = $this->randomString();
$typed_article->{$random_name} = $random_value;
$typed_article->save();
$entity = $typed_article->getEntity();
$this->assertEqual($entity->{$random_name}, $random_value);
}

}
200 changes: 0 additions & 200 deletions lib/Drupal/typed_entity/Tests/fixtures/article.inc

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

namespace Drupal\typed_entity_example\Tests;

use Drupal\typed_entity\TypedEntity\Tests\MockEntityWrapperService;
use Drupal\typed_entity\TypedEntity\TypedEntityManager;
use Drupal\typed_entity_example\TypedEntity\Tests\TypedNodeArticleUnitTest;

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

Expand All @@ -57,53 +56,4 @@ public function testCamelize() {
$this->assertEqual(TypedEntityManager::camelize('1-a>234'), '1A>234');
$this->assertEqual(TypedEntityManager::camelize(''), '');
}

/**
* Test factory.
*/
public function testFactory() {
$wrapper_service = new MockEntityWrapperService();
$wrapper_service->setFixturePath(__DIR__ . '/fixtures/article.inc');
xautoload()
->getServiceContainer()
->set('entity_wrapper', $wrapper_service);

// Get the mock entity to be loaded.
$entity = $wrapper_service->wrap('node', NULL)->value();
$typed_article = TypedEntityManager::create('node', $entity);
$reflection_article = new \ReflectionClass($typed_article);
if ($reflection_article->name == 'Drupal\typed_entity_example\TypedEntity\Node\Article') {
$this->pass('The hook_typed_entity_registry_info is taking precedence.');
}
else {
$this->fail('The hook_typed_entity_registry_info is not taking precedence.');
}

$wrapper_service->setFixturePath(__DIR__ . '/fixtures/page.inc');
// Get the mock entity to be loaded.
$entity = $wrapper_service->wrap('node', NULL)->value();
$typed_page = TypedEntityManager::create('node', $entity);

$reflection_page = new \ReflectionClass($typed_page);
if ($reflection_page->name == 'Drupal\typed_entity_example\TypedEntity\TypedNode') {
$this->pass('The factory is falling back to TypedNode.');
}
else {
$this->fail('The factory is not falling back to TypedNode.');
}

// Test the fallback to TypedEntity.
$wrapper_service->setFixturePath(__DIR__ . '/fixtures/user.inc');
// Get the mock entity to be loaded.
$entity = $wrapper_service->wrap('user', NULL)->value();
$typed_user = TypedEntityManager::create('user', $entity);
$reflection_user = new \ReflectionClass($typed_user);
if ($reflection_user->name == 'Drupal\typed_entity\TypedEntity\TypedEntity') {
$this->pass('The factory is falling back to TypedEntity.');
}
else {
$this->fail('The factory is not falling back to TypedEntity.');
}
}

}
Loading

0 comments on commit 78dab25

Please sign in to comment.