- <?php
- * @file
- * Definition of ViewsBasicTest.
- */
-
- require_once BACKDROP_ROOT . '/core/modules/views/tests/views_query.test';
-
- * Basic test class for Views query builder tests.
- */
- class ViewsPluginDisplayBlockTestCase extends ViewsSqlTest {
- protected $profile = 'minimal';
- protected $admin_user;
- protected $test_content = array();
-
- protected function setUp(array $modules = array()) {
- parent::setUp($modules);
-
-
- $this->backdropCreateContentType(array('type' => 'post', 'name' => 'Post'));
- for ($n = 0; $n < 20; $n++) {
- $this->test_content[] = $this->backdropCreateNode(array('type' => 'post'));
- }
-
-
- $this->admin_user = $this->backdropCreateUser(array(
- 'administer views',
- 'administer layouts',
- 'access administration pages',
- 'access content',
- 'view any unpublished content',
- 'bypass node access',
- 'administer nodes',
- ));
- $this->backdropLogin($this->admin_user);
- }
-
-
- * Tests, whether and how the reset button can be renamed.
- */
- public function testViewBlocks() {
- $layout = layout_load('default');
- $layout_block = $layout->addBlock('views', 'test_block-block', 'content');
- $layout->save();
-
- $node = reset($this->test_content);
- $this->backdropGet('node/' . $node->nid);
-
- $block_element = $this->xpath('//div[contains(@class,"block-views-test-block-block")]');
- $this->assertEqual(count($block_element), 1, 'The block is shown in the default layout.');
- $block_element = $block_element[0];
-
- $rows = $block_element->xpath('//div[contains(@class,"views-row")]');
- $this->assertEqual(count($rows), 5, 'The block has the expected 5 default rows');
- $first_row = (string)$rows[0]->asXML();
- $this->assertTrue(strpos($first_row, $node->title), 'First node found on first row as expected.');
-
-
- $this->backdropGet('admin/structure/layouts/manage/default/configure-block/editor/' . $layout_block->uuid);
- $this->assertNoField('link_to_view');
- $this->assertNoField('more_link');
- $this->assertNoField('path_override');
- $this->assertNoField('path');
- $this->assertNoField('fields_override[title]');
- $this->assertNoField('fields_override[nid]');
- $this->assertNoField('exposed[status]');
- $this->assertNoField('use_pager');
- $this->assertNoField('items_per_page');
- $this->assertNoField('offset');
-
-
- $view = views_get_view('test_block');
- $view->set_display('block');
- $view->display_handler->override_option('allow', array(
- 'use_pager' => 'use_pager',
- 'items_per_page' => 'items_per_page',
- 'offset' => 'offset',
- 'link_to_view' => 'link_to_view',
- 'more_link' => 'more_link',
- 'path_override' => 'path_override',
- 'exposed_form' => 'exposed_form',
- 'fields_override' => 'fields_override',
- ));
- $view->save();
-
-
- $this->backdropGet('admin/structure/layouts/manage/default/configure-block/editor/' . $layout_block->uuid);
- $this->assertField('link_to_view', 0);
- $this->assertField('more_link', 0);
- $this->assertField('path_override', 0);
- $this->assertField('path', 'block-test');
- $this->assertField('fields_override[title]', 1);
- $this->assertField('fields_override[nid]', 1);
- $this->assertField('exposed[status]', 1);
- $this->assertField('use_pager', 0);
- $this->assertField('items_per_page', 5);
- $this->assertField('offset', 0);
-
-
- $data = array(
- 'link_to_view' => TRUE,
- 'more_link' => TRUE,
- 'path_override' => TRUE,
- 'path' => 'other-path',
- 'fields_override[nid]' => FALSE,
- 'use_pager' => TRUE,
- 'items_per_page' => 3,
- 'offset' => 2,
- );
- $this->backdropPost(NULL, $data, t('Update block'));
- $this->backdropPost('admin/structure/layouts/manage/default', array(), t('Save layout'));
-
-
- $this->backdropGet('node/' . $node->nid);
-
- $block_element = $this->xpath('//div[contains(@class,"block-views-test-block-block")]');
- $rows = $block_element[0]->xpath('//div[contains(@class,"views-row")]');
-
-
- $title_link = $block_element[0]->xpath('//*[contains(@class,"block-title")]/a');
- $this->assertEqual($title_link[0]['href'], url('other-path'));
-
-
- $more_link = $block_element[0]->xpath('//*[contains(@class,"more-link")]/a');
- $this->assertEqual($more_link[0]['href'], url('other-path', array('query' => array('status' => '1'))));
-
-
- $nid_field = $block_element[0]->xpath('//*[contains(@class,"views-field-nid")]');
- $this->assertEqual(count($nid_field), 0, 'NID field has been disabled.');
-
-
- $pager = $block_element[0]->xpath('//ul[contains(@class,"pager")]');
- $this->assertEqual(count($pager), 1, 'Pager now enabled on the block.');
-
-
- $this->assertEqual(count($rows), 3, 'Three rows shown, reflecting items_per_page override setting.');
-
-
- $first_row = (string)$rows[0]->asXML();
- $this->assertTrue(strpos($first_row, $this->test_content[2]->title), 'Third node found on first row as expected (offset is 2).');
-
-
- $data = array(
- 'title_display' => 'custom',
- 'title' => 'Customized block title',
- 'exposed[status]' => '0',
- 'offset' => 0,
- 'fields_override[title]' => TRUE,
- 'fields_override[nid]' => TRUE,
- );
- $this->backdropPost('admin/structure/layouts/manage/default/configure-block/editor/' . $layout_block->uuid, $data, t('Update block'));
- $this->backdropPost('admin/structure/layouts/manage/default', array(), t('Save layout'));
-
-
- $node->status = 0;
- $node->save();
-
-
- $this->backdropGet('node/' . $node->nid);
-
- $block_element = $this->xpath('//div[contains(@class,"block-views-test-block-block")]');
- $rows = isset($block_element[0]) ? $block_element[0]->xpath('//div[contains(@class,"views-row")]') : array();
- $this->assertEqual(count($rows), 1, 'One unpublished node found.');
-
-
- $title_link = isset($block_element[0]) ? $block_element[0]->xpath('//*[contains(@class,"block-title")]/a') : array();
- $this->assertEqual($title_link[0]['href'], url('other-path'));
- $this->assertEqual((string) $title_link[0], 'Customized block title');
- }
- }