Open Monograph Press  3.3.0
ContentBaseTestCase.inc.php
1 <?php
2 
16 import('lib.pkp.tests.PKPContentBaseTestCase');
17 
18 use Facebook\WebDriver\WebDriverBy;
19 use Facebook\WebDriver\Interactions\WebDriverActions;
20 use Facebook\WebDriver\WebDriverExpectedCondition;
21 use Facebook\WebDriver\WebDriverSelect;
22 
23 class ContentBaseTestCase extends PKPContentBaseTestCase {
30  protected function createSubmission($data, $location = 'frontend') {
31  // By default, if this is an edited volume, configure 1 file per
32  // chapter.
33  if ($data['type'] == 'editedVolume' && !isset($data['files'])) {
34  $files = array();
35  foreach ($data['chapters'] as &$chapter) {
36  $files[] = array(
37  'fileTitle' => $chapter['title'],
38  'metadata' => array('genre' => 'Chapter Manuscript'),
39  );
40  $chapter['files'] = array($chapter['title']);
41  }
42  $data['files'] = $files;
43  } elseif (isset($data['chapters'])) {
44  foreach ($data['chapters'] as &$chapter) {
45  if (!isset($chapter['files'])) $chapter['files'] = array();
46  }
47  }
48 
49  // If 'additionalFiles' is specified, it's to be used to augment the default
50  // set, rather than overriding it (as using 'files' would do). Add the arrays.
51  if (isset($data['additionalFiles'])) {
52  $data['files'] = array_merge($data['files'], $data['additionalFiles']);
53  }
54 
55  parent::createSubmission($data, $location);
56  }
57 
62  protected function _handleStep1($data) {
63  // Page 1
64  if (isset($data['series'])) {
65  $this->waitForElementPresent('id=seriesId');
66  $this->select('id=seriesId', 'label=' . $this->escapeJS($data['series']));
67  }
68  switch ($data['type']) {
69  case 'monograph':
70  $this->click('id=isEditedVolume-0');
71  break;
72  case 'editedVolume':
73  $this->click('id=isEditedVolume-1');
74  break;
75  default:
76  fatalError('Unknown submission type.');
77  }
78 
79  parent::_handleStep1($data);
80  }
81 
86  protected function _handleStep3($data) {
87  parent::_handleStep3($data);
88  if (isset($data['chapters'])) foreach ($data['chapters'] as $chapter) {
89  $this->waitJQuery();
90  $element = $this->waitForElementPresent($selector='css=[id^=component-grid-users-chapter-chaptergrid-addChapter-button-]');
91  self::$driver->executeScript('document.getElementById(\'' . $element->getAttribute('id') . '\').scrollIntoView();');
92  self::$driver->executeScript('window.scroll(0,50);'); // FIXME: Give it an extra margin of pixels
93  $this->click($selector);
94  $this->waitForElementPresent('//form[@id=\'editChapterForm\']//input[starts-with(@id,\'title-\')]');
95 
96  // Contributors
97  foreach ($chapter['contributors'] as $i => $contributor) {
98  $this->click('//form[@id="editChapterForm"]//label[contains(text(), ' . $this->quoteXpath($contributor) . ')]');
99  }
100 
101  // FIXME: Title is entered here to combat listbuilder wackiness. It needs input before form save.
102  $this->type('//form[@id=\'editChapterForm\']//input[starts-with(@id,\'title-\')]', $chapter['title']);
103  if (isset($chapter['subtitle'])) {
104  $this->type('//form[@id=\'editChapterForm\']//input[starts-with(@id,\'subtitle-\')]', $chapter['subtitle']);
105  }
106 
107  $this->click('//form[@id="editChapterForm"]//button[text()="Save"]');
108  self::$driver->wait()->until(WebDriverExpectedCondition::invisibilityOfElementLocated(WebDriverBy::cssSelector('div.pkp_modal_panel')));
109 
110  // Files
111  if (!empty($chapter['files'])) {
112  $this->click('//div[@id="chaptersGridContainer"]//a[contains(text(), ' . $this->quoteXPath($chapter['title']) . ')]');
113  $this->waitForElementPresent('//a[contains(text(),"Edit Metadata")]');
114  $this->waitForElementPresent('//legend[contains(text(),"Files")]');
115  foreach ($chapter['files'] as $file) {
116  $this->click('//form[@id="editChapterForm"]//label[contains(text(), ' . $this->quoteXpath($chapter['title']) . ')]');
117  }
118  $this->click('//form[@id="editChapterForm"]//button[text()="Save"]');
119  self::$driver->wait()->until(WebDriverExpectedCondition::invisibilityOfElementLocated(WebDriverBy::cssSelector('div.pkp_modal_panel')));
120  }
121 
122  // Test the public identifiers form
123  if (isset($chapter['pubId'])) {
124  $this->click('//div[@id="chaptersGridContainer"]//a[contains(text(), ' . $this->quoteXPath($chapter['title']) . ')]');
125  $this->waitForElementPresent('css=.ui-tabs-anchor:contains(\'Identifiers\;)');
126  $this->click('//a[contains(text(),\'Identifiers\')]');
127  $this->waitForElementPresent('css=[id^=publisherId-]');
128  $this->type('css=[id^=publisherId-]', $chapter['pubId']);
129  $this->click('//form[@id=\'publicIdentifiersForm\']//button[text()=\'Save\']');
130  self::$driver->wait()->until(WebDriverExpectedCondition::invisibilityOfElementLocated(WebDriverBy::cssSelector('div.pkp_modal_panel')));
131  }
132  }
133  }
134 
139  protected function _getSubmissionElementName() {
140  return 'Book Manuscript';
141  }
142 
148  protected function sendToReview($type = 'External', $from = 'Submission') {
149  $this->waitJQuery();
150  // Force the popup notification to be hidden
151  self::$driver->executeScript("$('.ui-pnotify').css('display', 'none');");
152  $this->waitForElementPresent($selector = 'css=[id^=' . ($type=='External'?'external':'internal') . 'Review-button-]');
153  $this->click($selector);
154  $this->waitJQuery();
155  sleep(3);
156  if ($type == 'Internal' || $from != 'Internal') {
157  $this->waitForElementPresent('//form[@id=\'initiateReview\']//input[@type=\'checkbox\']');
158  $this->click('//form[@id=\'initiateReview\']//button[contains(., \'Send to ' . $this->escapeJS($type) . ' Review\')]');
159  } else { // External review from Internal review
160  sleep(2);
161  $this->waitForElementPresent('css=[id^=component-grid-files-attachment-editorselectablereviewattachmentsgrid-]');
162  $this->click('//button[contains(.,"Next:")]');
163  $this->waitForElementPresent('css=[id^=component-grid-files-review-selectablereviewrevisionsgrid-]');
164  $this->click('//form[@id=\'promote\']//button[contains(., \'Record Editorial Decision\')]');
165  }
166  self::$driver->wait()->until(WebDriverExpectedCondition::invisibilityOfElementLocated(WebDriverBy::cssSelector('div.pkp_modal_panel')));
167  }
168 
172  protected function addToCatalog() {
173  self::$driver->executeScript('window.scrollTo(0,0);'); // Scroll to top of page
174  $this->click('//button[contains(text(), "Publish")]');
175  $this->waitForElementPresent('//div[contains(text(),"All publication requirements have been met. Are you sure you want to make this catalog entry public?")]');
176  $this->click('//div[@class="pkpWorkflow__publishModal"]//button[contains(text(),"Publish")]');
177  }
178 }
ContentBaseTestCase
Base class for content-based tests.
Definition: ContentBaseTestCase.inc.php:23
ContentBaseTestCase\_handleStep3
_handleStep3($data)
Definition: ContentBaseTestCase.inc.php:86
ContentBaseTestCase\sendToReview
sendToReview($type='External', $from='Submission')
Definition: ContentBaseTestCase.inc.php:148
ContentBaseTestCase\_handleStep1
_handleStep1($data)
Definition: ContentBaseTestCase.inc.php:62
ContentBaseTestCase\createSubmission
createSubmission($data, $location='frontend')
Definition: ContentBaseTestCase.inc.php:30
ContentBaseTestCase\addToCatalog
addToCatalog()
Definition: ContentBaseTestCase.inc.php:172
ContentBaseTestCase\_getSubmissionElementName
_getSubmissionElementName()
Definition: ContentBaseTestCase.inc.php:139
fatalError
if(!function_exists('import')) fatalError($reason)
Definition: functions.inc.php:32