Commit 5e3de793 authored by Mateu Aguiló Bosch's avatar Mateu Aguiló Bosch
Browse files

Added fixture and unit tests

parent 4f46f848
......@@ -9,9 +9,11 @@ namespace Drupal\typed_entity\Tests;
use Drupal\typed_entity\Entity\MockEntityWrapperService;
use Drupal\typed_entity\Exception\TypedEntityException;
use Drupal\typed_entity\TypedEntity\Tests\MockEntityDrupalWrapper;
use Drupal\typed_entity\TypedEntity\Tests\TypedEntityModules;
use Drupal\typed_entity\TypedEntity\TypedEntity;
use Drupal\typed_entity\TypedEntity\TypedEntityManager;
use Drupal\typed_entity_example\TypedEntity\Node\Article;
use Drupal\xautoload\Tests\Mock\MockDrupalSystem;
use Drupal\xautoload\Tests\VirtualDrupal\DrupalComponentContainer;
......@@ -70,9 +72,25 @@ class TypedEntityUnitTestCase extends \DrupalUnitTestCase {
*/
public function testTypedEntityManager() {
// Test the discovery.
$entity = $this->loadFixture(__DIR__ . '/fixtures/article.inc');
$manager = TypedEntityManager::create('node', $entity);
// When creating the EMW the entity in the fixture will be used regardless
// of the passed in entity.
xautoload()
->getServiceContainer()
->set('entity_wrapper_fixture_path', __DIR__ . '/fixtures/article.inc');
$typed_article = TypedEntityManager::create('node', NULL);
$this->assertTrue($typed_article instanceof Article);
$this->assertEqual('node', $typed_article->getEntityType());
$this->assertEqual('article', $typed_article->getBundle());
$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);
}
/**
......@@ -87,10 +105,14 @@ class TypedEntityUnitTestCase extends \DrupalUnitTestCase {
$example_modules = new TypedEntityModules();
$components = new DrupalComponentContainer($example_modules);
$system = new MockDrupalSystem($components);
xautoload()->getServiceContainer()->set('system', $system);
xautoload()
->getServiceContainer()
->set('system', $system);
$entity_wrapper = new MockEntityWrapperService();
xautoload()->getServiceContainer()->set('entity_wrapper', $entity_wrapper);
xautoload()
->getServiceContainer()
->set('entity_wrapper', $entity_wrapper);
}
/**
......
a:3:{s:6:"bundle";s:7:"article";s:11:"entity keys";a:5:{s:2:"id";s:3:"nid";s:8:"revision";s:3:"vid";s:6:"bundle";s:4:"type";s:5:"label";s:5:"title";s:8:"language";s:8:"language";}s:6:"entity";O:8:"stdClass":31:{s:3:"vid";s:1:"2";s:3:"uid";s:1:"1";s:5:"title";s:8:"Test TOC";s:3:"log";s:0:"";s:6:"status";s:1:"1";s:7:"comment";s:1:"2";s:7:"promote";s:1:"1";s:6:"sticky";s:1:"0";s:3:"nid";s:1:"2";s:4:"type";s:7:"article";s:8:"language";s:2:"en";s:7:"created";s:10:"1380987256";s:7:"changed";s:10:"1390993936";s:4:"tnid";s:1:"0";s:9:"translate";s:1:"0";s:18:"revision_timestamp";s:10:"1390993936";s:12:"revision_uid";s:1:"1";s:4:"body";a:1:{s:3:"und";a:1:{i:0;a:5:{s:5:"value";s:1464:"<p><strong>Pellentesque habitant morbi tristique</strong> senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. <em>Aenean ultricies mi vitae est.</em> Mauris placerat eleifend leo. Quisque sit amet est et sapien ullamcorper pharetra. Vestibulum erat wisi, condimentum sed, <code>commodo vitae</code>, ornare sit amet, wisi. Aenean fermentum, elit eget tincidunt condimentum, eros ipsum rutrum orci, sagittis tempus lacus enim ac dui. <a href="#">Donec non enim</a> in turpis pulvinar facilisis. Ut felis.</p><h2>Header Level 2</h2> <ol> <li>Lorem ipsum dolor sit amet, consectetuer adipiscing elit 3.</li> <li>Aliquam tincidunt mauris eu risus 2.</li></ol><blockquote><p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus magna. Cras in mi at felis aliquet congue. Ut a est eget ligula molestie gravida. Curabitur massa. Donec eleifend, libero at sagittis mollis, tellus est malesuada tellus, at luctus turpis elit sit amet quam. Vivamus pretium ornare est.</p></blockquote><h3>Header Level 3</h3><ul> <li>Lorem ipsum dolor sit amet, consectetuer adipiscing elit.</li> <li>Aliquam tincidunt mauris eu risus.</li></ul><h2 id="custom-id">This is another Header Level 2</h2><pre><code>#header h1 a { display: block; width: 300px; height: 80px; }</code></pre>";s:7:"summary";s:0:"";s:6:"format";s:9:"full_html";s:10:"safe_value";s:1410:"<p><strong>Pellentesque habitant morbi tristique</strong> senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. <em>Aenean ultricies mi vitae est.</em> Mauris placerat eleifend leo. Quisque sit amet est et sapien ullamcorper pharetra. Vestibulum erat wisi, condimentum sed, <code>commodo vitae</code>, ornare sit amet, wisi. Aenean fermentum, elit eget tincidunt condimentum, eros ipsum rutrum orci, sagittis tempus lacus enim ac dui. <a href="#">Donec non enim</a> in turpis pulvinar facilisis. Ut felis.</p><h2>Header Level 2</h2><ol><li>Lorem ipsum dolor sit amet, consectetuer adipiscing elit 3.</li><li>Aliquam tincidunt mauris eu risus 2.</li></ol><blockquote><p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus magna. Cras in mi at felis aliquet congue. Ut a est eget ligula molestie gravida. Curabitur massa. Donec eleifend, libero at sagittis mollis, tellus est malesuada tellus, at luctus turpis elit sit amet quam. Vivamus pretium ornare est.</p></blockquote><h3>Header Level 3</h3><ul><li>Lorem ipsum dolor sit amet, consectetuer adipiscing elit.</li><li>Aliquam tincidunt mauris eu risus.</li></ul><h2 id="custom-id">This is another Header Level 2</h2><pre><code>#header h1 a { display: block; width: 300px; height: 80px; }</code></pre>";s:12:"safe_summary";s:0:"";}}}s:10:"field_tags";a:1:{s:3:"und";a:1:{i:0;a:1:{s:3:"tid";s:1:"1";}}}s:11:"field_image";a:0:{}s:18:"field_facebook_pub";a:0:{}s:9:"field_it2";a:0:{}s:11:"rdf_mapping";a:11:{s:11:"field_image";a:2:{s:10:"predicates";a:2:{i:0;s:8:"og:image";i:1;s:12:"rdfs:seeAlso";}s:4:"type";s:3:"rel";}s:10:"field_tags";a:2:{s:10:"predicates";a:1:{i:0;s:10:"dc:subject";}s:4:"type";s:3:"rel";}s:7:"rdftype";a:2:{i:0;s:9:"sioc:Item";i:1;s:13:"foaf:Document";}s:5:"title";a:1:{s:10:"predicates";a:1:{i:0;s:8:"dc:title";}}s:7:"created";a:3:{s:10:"predicates";a:2:{i:0;s:7:"dc:date";i:1;s:10:"dc:created";}s:8:"datatype";s:12:"xsd:dateTime";s:8:"callback";s:12:"date_iso8601";}s:7:"changed";a:3:{s:10:"predicates";a:1:{i:0;s:11:"dc:modified";}s:8:"datatype";s:12:"xsd:dateTime";s:8:"callback";s:12:"date_iso8601";}s:4:"body";a:1:{s:10:"predicates";a:1:{i:0;s:15:"content:encoded";}}s:3:"uid";a:2:{s:10:"predicates";a:1:{i:0;s:16:"sioc:has_creator";}s:4:"type";s:3:"rel";}s:4:"name";a:1:{s:10:"predicates";a:1:{i:0;s:9:"foaf:name";}}s:13:"comment_count";a:2:{s:10:"predicates";a:1:{i:0;s:16:"sioc:num_replies";}s:8:"datatype";s:11:"xsd:integer";}s:13:"last_activity";a:3:{s:10:"predicates";a:1:{i:0;s:23:"sioc:last_activity_date";}s:8:"datatype";s:12:"xsd:dateTime";s:8:"callback";s:12:"date_iso8601";}}s:3:"cid";s:1:"0";s:22:"last_comment_timestamp";s:10:"1380987256";s:17:"last_comment_name";N;s:16:"last_comment_uid";s:1:"1";s:13:"comment_count";s:1:"0";s:4:"name";s:5:"admin";s:7:"picture";s:1:"0";s:4:"data";s:4:"b:0;";}}
......@@ -104,7 +104,9 @@ class MockEntityDrupalWrapper implements MockEntityDrupalWrapperInterface {
'entity' => $wrapper->value(),
);
return serialize($fixture);
$output = serialize($fixture);
$output = preg_replace("/[\n\r\t]*/", '', $output);
return $output;
}
/**
......
......@@ -22,7 +22,9 @@ class TypedEntityManager implements TypedEntityManagerInterface {
* {@inheritdoc}
*/
public static function create($entity_type, $entity) {
static::$system = xautoload()->getServiceContainer()->get('system');
static::$system = xautoload()
->getServiceContainer()
->get('system');
$class_name = static::getClass($entity_type, $entity);
return new $class_name($entity_type, NULL, $entity);
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment