- <?php
- * @file
- * Tests for entity_example module.
- *
- * Verify example module functionality.
- */
-
- * Functionality tests for entity example module.
- *
- * @ingroup entity_example
- */
- class EntityExampleTestCase extends BackdropWebTestCase {
-
-
- * {@inheritdoc}
- */
- public function setUp() {
-
- parent::setUp('entity_example');
-
-
- $permissions = array(
- 'access content',
- 'view any entity_example_basic entity',
- 'edit any entity_example_basic entity',
- 'create entity_example_basic entities',
- 'administer entity_example_basic entities',
- 'administer site configuration',
- 'administer fields',
- );
- $account = $this->backdropCreateUser($permissions);
- $this->backdropLogin($account);
-
-
- $field = array(
- 'field_name' => 'entity_example_test_text' ,
- 'type' => 'text',
- );
- field_create_field($field);
- $instance = array(
- 'label' => 'Subject',
- 'field_name' => 'entity_example_test_text',
- 'entity_type' => 'entity_example_basic',
- 'bundle' => 'first_example_bundle',
- );
- field_create_instance($instance);
- }
-
-
- * Test Entity Example features.
- *
- * - CRUD
- * - Table display
- * - User access
- * - Field management
- * - Display management
- */
- public function testEntityExampleBasic() {
-
- for ($i = 1; $i <= 10; $i++) {
- $edit[$i]['item_description'] = $this->randomName();
- $edit[$i]['entity_example_test_text[und][0][value]'] = $this->randomName(32);
-
- $this->backdropPost('examples/entity_example/basic/add', $edit[$i], 'Save');
- $this->assertText('item_description=' . $edit[$i]['item_description']);
-
- $this->backdropGet('examples/entity_example/basic/' . $i);
- $this->assertText('item_description=' . $edit[$i]['item_description']);
- $this->assertText($edit[$i]['entity_example_test_text[und][0][value]']);
- }
-
-
- $this->backdropPost('examples/entity_example/basic/5/edit', $edit[5], 'Delete');
- $this->backdropGet('examples/entity_example/basic/5');
- $this->assertResponse(404, 'Deleted entity 5 no longer exists');
- unset($edit[5]);
-
-
- $edit[2] = array(
- 'item_description' => 'updated entity 2 ',
- 'entity_example_test_text[und][0][value]' => 'updated entity 2 test text',
- );
- $this->backdropPost('examples/entity_example/basic/2/edit', $edit[2], 'Save');
- $this->assertText('item_description=' . $edit[2]['item_description']);
- $this->assertText('updated entity 2 test text');
-
-
-
- $this->backdropGet('admin/structure/entity_example_basic/manage');
- foreach ($edit as $id => $item) {
- $this->assertRaw('examples/entity_example/basic/' . $id . '">' . $item['item_description'] . '</a>');
- }
- $this->assertNoRaw('examples/entity_example/basic/5">');
-
-
- $field_edit = array(
- 'fields[_add_new_field][label]' => 'New junk field',
- 'fields[_add_new_field][field_name]' => 'new_junk_field',
- 'fields[_add_new_field][type]' => 'text',
- 'fields[_add_new_field][widget_type]' => 'text_textfield',
- );
- $this->backdropPost('admin/structure/entity_example_basic/manage/fields', $field_edit, t('Save'));
- $this->backdropPost(NULL, array(), t('Save field settings'));
- $this->backdropPost(NULL, array(), t('Save settings'));
- $this->assertResponse(200);
-
-
- $edit[10]['field_new_junk_field[und][0][value]'] = $this->randomName();
- $this->backdropPost('examples/entity_example/basic/10/edit', $edit[10], 'Save');
- $this->assertResponse(200);
- $this->assertText('item_description=' . $edit[10]['item_description']);
- $this->assertText($edit[10]['field_new_junk_field[und][0][value]'], 'Custom field updated successfully');
-
-
- $account = $this->backdropCreateUser(array('access content'));
- $this->backdropLogin($account);
- $this->backdropGet('admin/structure/entity_example_basic/manage');
- $this->assertResponse(403);
- $this->backdropGet('examples/entity_example/basic/2');
- $this->assertResponse(403, 'User does not have permission to view entity');
-
-
- $account = $this->backdropCreateUser(array('access content', 'view any entity_example_basic entity'));
- $this->backdropLogin($account);
- $this->backdropGet('admin/structure/entity_example_basic/manage');
- $this->assertResponse(403, 'Denied access to admin manage page');
- $this->backdropGet('examples/entity_example/basic/2');
- $this->assertResponse(200, 'User has permission to view entity');
- $this->backdropGet('examples/entity_example/basic/2/edit');
- $this->assertResponse(403, 'User is denied edit privileges');
-
-
- $account = $this->backdropCreateUser(
- array(
- 'access content',
- 'view any entity_example_basic entity',
- 'edit any entity_example_basic entity',
- )
- );
- $this->backdropLogin($account);
- $this->backdropGet('admin/structure/entity_example_basic/manage');
- $this->assertResponse(403, 'Denied access to admin manage page');
- $this->backdropGet('examples/entity_example/basic/2');
- $this->assertResponse(200, 'User has permission to view entity');
- $this->backdropGet('examples/entity_example/basic/2/edit');
- $this->assertResponse(200, 'User has edit privileges');
- }
- }