-
Notifications
You must be signed in to change notification settings - Fork 0
/
xtended_entity.test
83 lines (59 loc) · 3.33 KB
/
xtended_entity.test
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
<?php
use Drupal\xtended_entity\Controllers\XtendedNodeController;
use Drupal\xtended_entity_test\TestType;
use Drupal\xtended_entity\Controllers\XtendedTaxonomyTermController;
use Drupal\xtended_entity\Entities\TaxonomyTerm;
use Drupal\xtended_entity_test\TestBuildingTerm;
class XtendedEntityTest extends DrupalWebTestCase {
public static function getInfo() {
return array(
'name' => 'Xtended entity Controller',
'description' => 'this tests ensure the controller provided features runs correctly',
'group' => 'Viadirect Core'
);
}
public function setUp() {
// parent::setUp('entity', 'xautoload', 'entity_translation', 'xtended_entity_test');
module_enable( array( 'xtended_entity_test' ) );
$this->public_files_directory = "public://";
$this->originalPrefix = $GLOBALS['db_prefix'];
$this->setup = TRUE;
}
public function tearDown() {
module_disable( array( 'xtended_entity_test' ) );
drupal_uninstall_modules( array( 'xtended_entity_test' ) );
}
public function testCreatingNode() {
/* @var $ctrl XtendedNodeController */
$ctrl = entity_get_controller("node");
$ctrlClass = xtended_entity_request_controller_class('node', XtendedNodeController::class);
$this->assertEqual( get_class( $ctrl ), $ctrlClass, 'node controller should be replaced by our xtended ', 'xtended entity node' );
$created = $ctrl->create( array( 'type' => 'test_type', 'uid'=>0, 'title' => 'plop' ) );
$this->assertNotNull($created, 'created node should not be null');
$this->assertEqual(get_class( $created ), TestType::class, 'created node should not be of the bundle class TestType' );
$res = node_save( $created );
$this->assertNotNull( $created->getId(), 'node should have a nid '.$created->getId() );
$this->_node_id = $created->getId();
}
public function testLoadingNode() {
/* @var $ctrl XtendedNodeController */
$ctrl = entity_get_controller("node");
$loaded = node_load( $this->_node_id );
$this->assertEqual( get_class( $loaded ), TestType::class, 'loaded node should not be of the bundle class TestType' );
}
public function testTaxonomyTerm() {
/* @var $ctrl XtendedTaxonomyTermController */
$ctrl = entity_get_controller( "taxonomy_term" );
$ctrlClass = xtended_entity_request_controller_class('taxonomy_term', XtendedTaxonomyTermController::class);
$this->assertEqual( get_class( $ctrl ), $ctrlClass, 'taxonomy_term controller should be replaced by our xtended ', 'xtended entity taxonomy_term' );
$term = $ctrl->retrieveEntityByProperty( 'name', 'DECATHLON' );
$this->assertEqual( get_class( $term ), TestBuildingTerm::class, 'term should be an instance of TermBuildingTerm', 'xtended entity taxonomy_term' );
/* @var $term TaxonomyTerm */
$term = $ctrl->retrieveTermByName( 'DECATHLON' );
$this->assertEqual( get_class( $term ), TestBuildingTerm::class, 'term should be an instance of TermBuildingTerm', 'xtended entity taxonomy_term' );
$this->assertEqual( $term->name , 'DECATHLON', 'term name should be DECATHLON', 'xtended entity taxonomy_term' );
$ctrl->setBundle( 'tags' );
$term = $ctrl->retrieveTermByName( 'DECATHLON' );
$this->assertFalse( $term, 'there should not be any result with wrong vocabulary', 'xtended entity taxonomy_term' );
}
}