Commit 78dab250 authored by Mateu Aguiló Bosch's avatar Mateu Aguiló Bosch
Browse files

Revert the old code

parent e2d80dce
......@@ -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
......
......@@ -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
......@@ -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 {
......@@ -46,9 +43,8 @@ class TypedEntityUnitTestCase extends \DrupalUnitTestCase {
* 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) {
......@@ -56,7 +52,7 @@ class TypedEntityUnitTestCase extends \DrupalUnitTestCase {
}
try {
new TypedEntity($dic, 'foo');
new TypedEntity('foo');
$this->fail('Exception was not thrown for missing entity and ID.');
}
catch (TypedEntityException $e) {
......@@ -64,35 +60,4 @@ class TypedEntityUnitTestCase extends \DrupalUnitTestCase {
}
}
/**
* 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);
}
}
<?php
$fixture = array(
'bundle' => 'article',
'entity keys' =>
array(
'id' => 'nid',
'revision' => 'vid',
'bundle' => 'type',
'label' => 'title',
'language' => 'language',
),
'entity' => (object) array(
'vid' => '1',
'uid' => '1',
'title' => 'Lorem ipsum dolor sit amet, consetetur sadipscing',
'log' => '',
'status' => '1',
'comment' => '2',
'promote' => '1',
'sticky' => '0',
'nid' => '1',
'type' => 'article',
'language' => 'en',
'created' => '1368005430',
'changed' => '1369320916',
'tnid' => '0',
'translate' => '0',
'revision_timestamp' => '1369320916',
'revision_uid' => '1',
'body' =>
array(
'und' =>
array(
0 =>
array(
'value' => 'Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.',
'summary' => '',
'format' => 'filtered_html',
'safe_value' => '<p>Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.</p>
',
'safe_summary' => '',
),
),
),
'field_tags' =>
array(
'und' =>
array(
0 =>
array(
'tid' => '1',
),
),
),
'field_image' =>
array(
'und' =>
array(
0 =>
array(
'fid' => '1',
'uid' => '1',
'filename' => 'DSCF2211.jpg',
'uri' => 'public://field/image/DSCF2211.jpg',
'filemime' => 'image/jpeg',
'filesize' => '46156',
'status' => '1',
'timestamp' => '1424800819',
'type' => 'image',
'field_file_image_alt_text' =>
array(),
'field_file_image_title_text' =>
array(),
'rdf_mapping' =>
array(),
'metadata' =>
array(
'height' => 320,
'width' => 180,
),
'alt' => '',
'title' => '',
'width' => '180',
'height' => '320',
),
),
),
'field_facebook_pub' =>
array(
'und' =>
array(
0 =>
array(
'target_id' => '3',
),
),
),
'field_it2' =>
array(),
'rdf_mapping' =>
array(
'field_image' =>
array(
'predicates' =>
array(
0 => 'og:image',
1 => 'rdfs:seeAlso',
),
'type' => 'rel',
),
'field_tags' =>
array(
'predicates' =>
array(
0 => 'dc:subject',
),
'type' => 'rel',
),
'rdftype' =>
array(
0 => 'sioc:Item',
1 => 'foaf:Document',
),
'title' =>
array(
'predicates' =>
array(
0 => 'dc:title',
),
),
'created' =>
array(
'predicates' =>
array(
0 => 'dc:date',
1 => 'dc:created',
),
'datatype' => 'xsd:dateTime',
'callback' => 'date_iso8601',
),
'changed' =>
array(
'predicates' =>
array(
0 => 'dc:modified',
),
'datatype' => 'xsd:dateTime',
'callback' => 'date_iso8601',
),
'body' =>
array(
'predicates' =>
array(
0 => 'content:encoded',
),
),
'uid' =>
array(
'predicates' =>
array(
0 => 'sioc:has_creator',
),
'type' => 'rel',
),
'name' =>
array(
'predicates' =>
array(
0 => 'foaf:name',
),
),
'comment_count' =>
array(
'predicates' =>
array(
0 => 'sioc:num_replies',
),
'datatype' => 'xsd:integer',
),
'last_activity' =>
array(
'predicates' =>
array(
0 => 'sioc:last_activity_date',
),
'datatype' => 'xsd:dateTime',
'callback' => 'date_iso8601',
),
),
'cid' => '9',
'last_comment_timestamp' => '1405499171',
'last_comment_name' => '',
'last_comment_uid' => '1',
'comment_count' => '9',
'name' => 'admin',
'picture' => '0',
'data' => 'b:0;',
),
);
......@@ -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;
......@@ -44,7 +43,7 @@ class TypedEntityExampleUnitTestCase extends \DrupalUnitTestCase {
* 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.');
}
......@@ -57,53 +56,4 @@ class TypedEntityExampleUnitTestCase extends \DrupalUnitTestCase {
$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.');
}
}
}
<?php
/**
* @file
* Contains \Drupal\typed_entity_example\Tests\TypedEntityExampleWebTestCase
*/
namespace Drupal\typed_entity_example\Tests;
use Drupal\typed_entity\TypedEntity\TypedEntity;
use Drupal\typed_entity\TypedEntity\TypedEntityManager;
use Drupal\typed_entity_example\TypedEntity\Node\Article;
use Drupal\typed_entity_example\TypedEntity\TypedNode;
class TypedEntityExampleWebTestCase extends \DrupalWebTestCase {
/**
* Declare test information.
*
* @return array
* The information array.
*/
public static function getInfo() {
return array(
'name' => 'Typed entity example (functional)',
'description' => 'Functional tests for Typed Entity.',
'group' => 'Typed Entity',
);
}
/**
* Set up.
*/
protected function setUp() {
parent::setUp('typed_entity_example');
}
/**
* Test factory.
*/
public function testFactory() {
$article = $this->drupalCreateNode(array(
'type' => 'article',
'title' => 'Test article',
));
$typed_article = TypedEntityManager::create('node', $article);
$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.');
}
// Test the fallback to the TypedNode.
$page = $this->drupalCreateNode(array(
'type' => 'page',
'title' => 'Test article',
));
$typed_page = TypedEntityManager::create('node', $page);
$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.
$account = $this->drupalCreateUser();
$typed_user = TypedEntityManager::create('user', $account);
$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.');
}
}
}
<?php
$fixture = array(
'bundle' => 'article',
'entity keys' =>
array(
'id' => 'nid',
'revision' => 'vid',
'bundle' => 'type',
'label' => 'title',
'language' => 'language',
),
'entity' => (object) array(
'vid' => '1',
'uid' => '1',
'title' => 'Lorem ipsum dolor sit amet, consetetur sadipscing',
'log' => '',
'status' => '1',
'comment' => '2',
'promote' => '1',
'sticky' => '0',
'nid' => '1',
'type' => 'article',
'language' => 'en',
'created' => '1368005430',
'changed' => '1369320916',
'tnid' => '0',
'translate' => '0',
'revision_timestamp' => '1369320916',
'revision_uid' => '1',
'body' => array(
'und' => array(
array(
'value' => 'Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.',
'summary' => '',
'format' => 'filtered_html',
'safe_value' => '<p>Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.</p>
',
'safe_summary' => '',
),
),
),
'field_tags' => array(
'und' => array(
array(
'tid' => '1',
),
),
),
'field_image' => array(
'und' => array(
array(
'fid' => '1',
'uid' => '1',
'filename' => 'DSCF2211.jpg',
'uri' => 'public://field/image/DSCF2211.jpg',
'filemime' => 'image/jpeg',
'filesize' => '46156',
'status' => '1',
'timestamp' => '1424800819',
'type' => 'image',
'field_file_image_alt_text' => array(),
'field_file_image_title_text' => array(),
'rdf_mapping' => array(),
'metadata' => array(
'height' => 320,
'width' => 180,
),
'alt' => '',
'title' => '',
'width' => '180',
'height' => '320',
),
),
),
'field_facebook_pub' => array(
'und' => array(
array(
'target_id' => '3',
),
),
),
'field_it2' => array(),
'rdf_mapping' => array(
'field_image' => array(
'predicates' => array(
'og:image',
'rdfs:seeAlso',
),
'type' => 'rel',
),
'field_tags' => array(
'predicates' => array(
'dc:subject',
),
'type' => 'rel',
),
'rdftype' => array(
'sioc:Item',
'foaf:Document',
),
'title' => array(
'predicates' =>
array(
'dc:title',
),
),
'created' => array(
'predicates' => array(
'dc:date',
'dc:created',
),
'datatype' => 'xsd:dateTime',
'callback' => 'date_iso8601',
),
'changed' => array(
'predicates' => array(
'dc:modified',
),
'datatype' => 'xsd:dateTime',
'callback' => 'date_iso8601',
),
'body' => array(
'predicates' => array(
'content:encoded',
),
),
'uid' => array(
'predicates' => array(
'sioc:has_creator',
),
'type' => 'rel',