annotate sites/all/modules/schemaorg/schemaorg.test @ 4:ce11bbd8f642

added modules
author danieleb <danielebarchiesi@me.com>
date Thu, 19 Sep 2013 10:38:44 +0100
parents
children
rev   line source
danielebarchiesi@4 1 <?php
danielebarchiesi@4 2
danielebarchiesi@4 3 /**
danielebarchiesi@4 4 * @file
danielebarchiesi@4 5 * Tests for schemaorg.module.
danielebarchiesi@4 6 */
danielebarchiesi@4 7
danielebarchiesi@4 8 /**
danielebarchiesi@4 9 * Tests for schema.org namespaces declaration.
danielebarchiesi@4 10 */
danielebarchiesi@4 11 class SchemaorgNamespaceTestCase extends DrupalWebTestCase {
danielebarchiesi@4 12 public static function getInfo() {
danielebarchiesi@4 13 return array(
danielebarchiesi@4 14 'name' => 'Schema.org namespace',
danielebarchiesi@4 15 'description' => 'Test the presence of the schema.org namespace in the page markup and in rdf_get_namespaces().',
danielebarchiesi@4 16 'group' => 'Schema.org',
danielebarchiesi@4 17 );
danielebarchiesi@4 18 }
danielebarchiesi@4 19
danielebarchiesi@4 20 function setUp() {
danielebarchiesi@4 21 parent::setUp('schemaorg');
danielebarchiesi@4 22 }
danielebarchiesi@4 23
danielebarchiesi@4 24 /**
danielebarchiesi@4 25 * Test getting RDF namesapces.
danielebarchiesi@4 26 */
danielebarchiesi@4 27 function testSchemaorgNamespace() {
danielebarchiesi@4 28 // Get all RDF namespaces.
danielebarchiesi@4 29 $ns = rdf_get_namespaces();
danielebarchiesi@4 30 $this->assertEqual($ns['schema'], 'http://schema.org/', t('Schema.org namespace is returned by rdf_get_namespaces().'));
danielebarchiesi@4 31
danielebarchiesi@4 32 // Fetches the front page and extracts XML namespaces.
danielebarchiesi@4 33 $this->drupalGet('');
danielebarchiesi@4 34 $xml = new SimpleXMLElement($this->content);
danielebarchiesi@4 35 $ns = $xml->getDocNamespaces();
danielebarchiesi@4 36 $this->assertEqual($ns['schema'], 'http://schema.org/', t('Schema.org namespace is present in the HTML document.'));
danielebarchiesi@4 37 }
danielebarchiesi@4 38 }
danielebarchiesi@4 39
danielebarchiesi@4 40 /**
danielebarchiesi@4 41 * Schema.org Field UI tests.
danielebarchiesi@4 42 */
danielebarchiesi@4 43 class SchemaorgFieldUIManageFieldsTestCase extends FieldUITestCase {
danielebarchiesi@4 44 public static function getInfo() {
danielebarchiesi@4 45 return array(
danielebarchiesi@4 46 'name' => 'Field UI schema.org form elements',
danielebarchiesi@4 47 'description' => 'Test the schema.org form element in the Field UI.',
danielebarchiesi@4 48 'group' => 'Schema.org',
danielebarchiesi@4 49 );
danielebarchiesi@4 50 }
danielebarchiesi@4 51
danielebarchiesi@4 52 function setUp() {
danielebarchiesi@4 53 parent::setUp('schemaorg', 'schemaorg_ui');
danielebarchiesi@4 54
danielebarchiesi@4 55 // Create random field name.
danielebarchiesi@4 56 $this->field_label = $this->randomName(8);
danielebarchiesi@4 57 $this->field_name_input = strtolower($this->randomName(8));
danielebarchiesi@4 58 $this->field_name = 'field_'. $this->field_name_input;
danielebarchiesi@4 59 }
danielebarchiesi@4 60
danielebarchiesi@4 61 /**
danielebarchiesi@4 62 * Tests that schema.org terms are saved on the content type edit form.
danielebarchiesi@4 63 */
danielebarchiesi@4 64 function testNodeTypeEditing() {
danielebarchiesi@4 65 $admin_path = 'admin/structure/types/manage/page';
danielebarchiesi@4 66 $type_element_id = 'edit-schemaorg-ui-type';
danielebarchiesi@4 67 $type_element_name = 'schemaorg_ui_type';
danielebarchiesi@4 68
danielebarchiesi@4 69 $this->drupalGet($admin_path);
danielebarchiesi@4 70 $this->assertFieldById($type_element_id, '', t('The schema.org type was empty.'));
danielebarchiesi@4 71
danielebarchiesi@4 72 // Check that the schema.org terms are saved.
danielebarchiesi@4 73 $edit = array();
danielebarchiesi@4 74 $edit[$type_element_name] = 'WebPage';
danielebarchiesi@4 75 $this->drupalPost($admin_path, $edit, t('Save content type'));
danielebarchiesi@4 76 $this->assertText("The content type Basic page has been updated.", t('The form was successfully submitted.'));
danielebarchiesi@4 77 entity_info_cache_clear();
danielebarchiesi@4 78 $rdf_mapping = rdf_mapping_load('node', 'page');
danielebarchiesi@4 79 $rdf_mapping_type_expected = array(
danielebarchiesi@4 80 'schema:WebPage',
danielebarchiesi@4 81 'foaf:Document',
danielebarchiesi@4 82 );
danielebarchiesi@4 83 $this->assertEqual($rdf_mapping['rdftype'], $rdf_mapping_type_expected, t('The schema.org type was correctly saved.'));
danielebarchiesi@4 84
danielebarchiesi@4 85 // Check that the schema.org terms shows up in the form
danielebarchiesi@4 86 $this->drupalGet($admin_path);
danielebarchiesi@4 87 $this->assertFieldById($type_element_id, 'WebPage', t('The schema.org type form element was displayed with the correct value.'));
danielebarchiesi@4 88
danielebarchiesi@4 89 // Check that the schema.org type can be emptied.
danielebarchiesi@4 90 $edit = array();
danielebarchiesi@4 91 $edit[$type_element_name] = '';
danielebarchiesi@4 92 $this->drupalPost($admin_path, $edit, t('Save content type'));
danielebarchiesi@4 93 $this->assertText("The content type Basic page has been updated.", t('The form was successfully submitted.'));
danielebarchiesi@4 94 entity_info_cache_clear();
danielebarchiesi@4 95 $rdf_mapping = rdf_mapping_load('node', 'page');
danielebarchiesi@4 96 $rdf_mapping_type_expected = array(
danielebarchiesi@4 97 1 => 'foaf:Document',
danielebarchiesi@4 98 );
danielebarchiesi@4 99 $this->assertEqual($rdf_mapping['rdftype'], $rdf_mapping_type_expected, t('The schema.org type mapping was correctly saved.'));
danielebarchiesi@4 100 }
danielebarchiesi@4 101
danielebarchiesi@4 102 /**
danielebarchiesi@4 103 * Tests that schema.org property is correctly saved.
danielebarchiesi@4 104 */
danielebarchiesi@4 105 function testFieldUIManageFields() {
danielebarchiesi@4 106 // Create a test field and instance.
danielebarchiesi@4 107 $field_name = 'test';
danielebarchiesi@4 108 $field = array(
danielebarchiesi@4 109 'field_name' => $field_name,
danielebarchiesi@4 110 'type' => 'test_field'
danielebarchiesi@4 111 );
danielebarchiesi@4 112 field_create_field($field);
danielebarchiesi@4 113 $instance = array(
danielebarchiesi@4 114 'field_name' => $field_name,
danielebarchiesi@4 115 'entity_type' => 'node',
danielebarchiesi@4 116 'bundle' => $this->type,
danielebarchiesi@4 117 );
danielebarchiesi@4 118 field_create_instance($instance);
danielebarchiesi@4 119
danielebarchiesi@4 120 $langcode = LANGUAGE_NONE;
danielebarchiesi@4 121 $admin_path = 'admin/structure/types/manage/' . $this->hyphen_type . '/fields/' . $field_name;
danielebarchiesi@4 122 $element_id = 'edit-schemaorg-ui-field-property';
danielebarchiesi@4 123 $element_name = 'schemaorg_ui_field_property';
danielebarchiesi@4 124 $this->drupalGet($admin_path);
danielebarchiesi@4 125 $this->assertFieldById($element_id, '', t('The schema.org property was empty.'));
danielebarchiesi@4 126
danielebarchiesi@4 127 // Check that the schema.org property is saved.
danielebarchiesi@4 128 $edit = array($element_name => 'telephone');
danielebarchiesi@4 129 $this->drupalPost($admin_path, $edit, t('Save settings'));
danielebarchiesi@4 130 $this->assertText("Saved $field_name configuration", t('The form was successfully submitted.'));
danielebarchiesi@4 131 $rdf_mapping = rdf_mapping_load('node', $this->type);
danielebarchiesi@4 132 $rdf_mapping_title_expected = array(
danielebarchiesi@4 133 'predicates' => array(
danielebarchiesi@4 134 'schema:name',
danielebarchiesi@4 135 ),
danielebarchiesi@4 136 );
danielebarchiesi@4 137 $rdf_mapping_url_expected = array(
danielebarchiesi@4 138 'predicates' => array(
danielebarchiesi@4 139 'schema:url',
danielebarchiesi@4 140 ),
danielebarchiesi@4 141 'type' => 'rel',
danielebarchiesi@4 142 );
danielebarchiesi@4 143 $rdf_mapping_field_expected = array(
danielebarchiesi@4 144 'predicates' => array(
danielebarchiesi@4 145 'schema:telephone',
danielebarchiesi@4 146 ),
danielebarchiesi@4 147 );
danielebarchiesi@4 148 $this->assertEqual($rdf_mapping['title'], $rdf_mapping_title_expected, t('The schema.org title property was correctly saved.'));
danielebarchiesi@4 149 $this->assertEqual($rdf_mapping['url'], $rdf_mapping_url_expected, t('The schema.org url property was correctly saved.'));
danielebarchiesi@4 150 $this->assertEqual($rdf_mapping[$field_name], $rdf_mapping_field_expected, t('The schema.org property was correctly saved.'));
danielebarchiesi@4 151
danielebarchiesi@4 152 // Check that the schema.org property shows up in the form
danielebarchiesi@4 153 $this->drupalGet($admin_path);
danielebarchiesi@4 154 $this->assertFieldById($element_id, 'telephone', t('The schema.org property form element was displayed with the correct value.'));
danielebarchiesi@4 155
danielebarchiesi@4 156 // Check that the schema.org property can be emptied.
danielebarchiesi@4 157 $edit = array($element_name => '');
danielebarchiesi@4 158 $this->drupalPost($admin_path, $edit, t('Save settings'));
danielebarchiesi@4 159 $this->assertText("Saved $field_name configuration", t('The form was successfully submitted.'));
danielebarchiesi@4 160 entity_info_cache_clear();
danielebarchiesi@4 161 $rdf_mapping = rdf_mapping_load('node', $this->type);
danielebarchiesi@4 162 $rdf_mapping_title_expected = array(
danielebarchiesi@4 163 'predicates' => array(),
danielebarchiesi@4 164 );
danielebarchiesi@4 165 $rdf_mapping_field_expected = array(
danielebarchiesi@4 166 'predicates' => array(),
danielebarchiesi@4 167 );
danielebarchiesi@4 168 $this->assertEqual($rdf_mapping['title'], $rdf_mapping_title_expected, t('The schema.org title mapping was correctly saved.'));
danielebarchiesi@4 169 $this->assertTrue(!isset($rdf_mapping['url']), t('The schema.org url mapping was correctly removed.'));
danielebarchiesi@4 170 $this->assertEqual($rdf_mapping[$field_name], $rdf_mapping_field_expected, t('The schema.org property was correctly saved.'));
danielebarchiesi@4 171 }
danielebarchiesi@4 172
danielebarchiesi@4 173 /**
danielebarchiesi@4 174 * Tests that schema.org property is correctly saved for advanced fields
danielebarchiesi@4 175 * where the object is a resource (image, file, reference).
danielebarchiesi@4 176 */
danielebarchiesi@4 177 function testFieldUIManageFieldsReference() {
danielebarchiesi@4 178 // Create a test field and instance.
danielebarchiesi@4 179 $field_name = 'test';
danielebarchiesi@4 180 $field = array(
danielebarchiesi@4 181 'field_name' => $field_name,
danielebarchiesi@4 182 'type' => 'taxonomy_term_reference'
danielebarchiesi@4 183 );
danielebarchiesi@4 184 field_create_field($field);
danielebarchiesi@4 185 $instance = array(
danielebarchiesi@4 186 'field_name' => $field_name,
danielebarchiesi@4 187 'entity_type' => 'node',
danielebarchiesi@4 188 'bundle' => $this->type,
danielebarchiesi@4 189 );
danielebarchiesi@4 190 field_create_instance($instance);
danielebarchiesi@4 191
danielebarchiesi@4 192 $langcode = LANGUAGE_NONE;
danielebarchiesi@4 193 $admin_path = 'admin/structure/types/manage/' . $this->hyphen_type . '/fields/' . $field_name;
danielebarchiesi@4 194 $element_id = 'edit-schemaorg-ui-field-property';
danielebarchiesi@4 195 $element_name = 'schemaorg_ui_field_property';
danielebarchiesi@4 196 $this->drupalGet($admin_path);
danielebarchiesi@4 197 $this->assertFieldById($element_id, '', t('The schema.org property was empty.'));
danielebarchiesi@4 198
danielebarchiesi@4 199 // Check that the schema.org property is saved.
danielebarchiesi@4 200 $edit = array($element_name => 'telephone');
danielebarchiesi@4 201 $this->drupalPost($admin_path, $edit, t('Save settings'));
danielebarchiesi@4 202 $this->assertText("Saved $field_name configuration", t('The form was successfully submitted.'));
danielebarchiesi@4 203 $rdf_mapping = rdf_mapping_load('node', $this->type);
danielebarchiesi@4 204 $rdf_mapping_field_expected = array(
danielebarchiesi@4 205 'predicates' => array(
danielebarchiesi@4 206 'schema:telephone',
danielebarchiesi@4 207 ),
danielebarchiesi@4 208 'type' => 'rel',
danielebarchiesi@4 209 );
danielebarchiesi@4 210 $this->assertEqual($rdf_mapping[$field_name], $rdf_mapping_field_expected, t('The schema.org property was correctly saved.'));
danielebarchiesi@4 211
danielebarchiesi@4 212 // Check that the schema.org property shows up in the form
danielebarchiesi@4 213 $this->drupalGet($admin_path);
danielebarchiesi@4 214 $this->assertFieldById($element_id, 'telephone', t('The schema.org property form element was displayed with the correct value.'));
danielebarchiesi@4 215
danielebarchiesi@4 216 // Check that the schema.org property can be emptied.
danielebarchiesi@4 217 $edit = array($element_name => '');
danielebarchiesi@4 218 $this->drupalPost($admin_path, $edit, t('Save settings'));
danielebarchiesi@4 219 $this->assertText("Saved $field_name configuration", t('The form was successfully submitted.'));
danielebarchiesi@4 220 entity_info_cache_clear();
danielebarchiesi@4 221 $rdf_mapping = rdf_mapping_load('node', $this->type);
danielebarchiesi@4 222 $rdf_mapping_field_expected = array(
danielebarchiesi@4 223 'predicates' => array(),
danielebarchiesi@4 224 'type' => 'rel',
danielebarchiesi@4 225 );
danielebarchiesi@4 226 $this->assertEqual($rdf_mapping[$field_name], $rdf_mapping_field_expected, t('The schema.org property was correctly saved.'));
danielebarchiesi@4 227 }
danielebarchiesi@4 228 }