i18n_access.2298475-6.patch 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619
  1. diff --git a/i18n_access.info b/i18n_access.info
  2. index e19050a..074cec2 100644
  3. --- a/i18n_access.info
  4. +++ b/i18n_access.info
  5. @@ -2,6 +2,9 @@ name = Translation Access
  6. description = Control access to creating content in different languages.
  7. package = Multilanguage
  8. core = 7.x
  9. +configure = admin/config/regional/language/access
  10. dependencies[] = locale
  11. dependencies[] = translation
  12. +dependencies[] = i18n_node
  13. +files[] = i18n_access.test
  14. diff --git a/i18n_access.install b/i18n_access.install
  15. index 24aefb4..95c935c 100644
  16. --- a/i18n_access.install
  17. +++ b/i18n_access.install
  18. @@ -42,4 +42,5 @@ function i18n_access_install() {
  19. * Implements hook_uninstall().
  20. */
  21. function i18n_access_uninstall() {
  22. + variable_del('i18n_access_languages');
  23. }
  24. diff --git a/i18n_access.module b/i18n_access.module
  25. index 5f4aa56..3b68458 100644
  26. --- a/i18n_access.module
  27. +++ b/i18n_access.module
  28. @@ -2,32 +2,14 @@
  29. /**
  30. * @file
  31. - * file_description
  32. + * i18n_access.module
  33. */
  34. -define('I18N_ACCESS_LANGUAGE_NEUTRAL', 'NEUTRAL');
  35. -
  36. /**
  37. * Implements hook_user_insert().
  38. */
  39. function i18n_access_user_insert(&$edit, &$account, $category = NULL) {
  40. - if ($category == 'account') {
  41. - // see user_admin_perm_submit()
  42. - if (isset($edit['i18n_access'])) {
  43. - db_delete('i18n_access')
  44. - ->condition('uid', $account->uid)
  45. - ->execute();
  46. - $edit['i18n_access'] = array_filter($edit['i18n_access']);
  47. - if (count($edit['i18n_access'])) {
  48. - db_insert('i18n_access')
  49. - ->fields(array(
  50. - 'uid' => $account->uid,
  51. - 'perm' => implode(', ', array_keys($edit['i18n_access'])),
  52. - ))->execute();
  53. - }
  54. - unset($edit['i18n_access']);
  55. - }
  56. - }
  57. + i18n_access_user_update($edit, $account, $category);
  58. }
  59. /**
  60. @@ -54,10 +36,19 @@ function i18n_access_user_update(&$edit, &$account, $category = NULL) {
  61. }
  62. /**
  63. + * Implements hook_user_delete().
  64. + */
  65. +function i18n_access_user_delete($account) {
  66. + db_delete('i18n_access')
  67. + ->condition('uid', $account->uid)
  68. + ->execute();
  69. +}
  70. +
  71. +/**
  72. * Load the language permissions for a given user
  73. */
  74. function i18n_access_load_permissions($uid = NULL) {
  75. - static $perms = array();
  76. + $perms = &drupal_static(__FUNCTION__);
  77. // use the global user id if none is passed
  78. if (!isset($uid)) {
  79. @@ -94,7 +85,8 @@ function i18n_access_permission() {
  80. return array(
  81. 'access selected languages' => array(
  82. 'title' => t('Access selected languages'),
  83. - 'description' => t('access selected languages.'),
  84. + 'description' => t('This permission gives this role edit/delete access to all content which are in the <a href="!url" target="_blank">selected language</a>. View/create access needs a different access level.', array('!url' => url('admin/config/regional/language/access'))),
  85. + 'restrict access' => TRUE,
  86. ),
  87. );
  88. }
  89. @@ -102,34 +94,39 @@ function i18n_access_permission() {
  90. /**
  91. * Implements hook_form_node_form_alter().
  92. */
  93. -function i18n_access_form_node_form_alter(&$form, &$form_state, $form_id) {
  94. -
  95. - if (isset($form['language']['#options'])) {
  96. - // Remove inaccessible languages from the select box
  97. - // don't do it for admininstrators
  98. - if (!user_access('administer nodes')) {
  99. - $perms = i18n_access_load_permissions();
  100. - foreach ($form['language']['#options'] as $key => $value) {
  101. - $perm_key = ($key == '') ? I18N_ACCESS_LANGUAGE_NEUTRAL : $key;
  102. - if ($key!='en' && empty($perms[$perm_key])) {
  103. - unset($form['language']['#options']["$key"]);
  104. - }
  105. +function i18n_access_form_node_form_alter(&$form) {
  106. + $form['#after_build'][] = '_i18n_access_form_node_form_alter';
  107. +}
  108. +
  109. +/**
  110. + * Unset's languages from language options if user does not have permission to
  111. + * use.
  112. + *
  113. + * @param $form
  114. + * @param $form_state
  115. + * @return mixed
  116. + */
  117. +function _i18n_access_form_node_form_alter($form, &$form_state) {
  118. + if (isset($form['language']['#options']) && !user_access('bypass node access')) {
  119. + $perms = i18n_access_load_permissions();
  120. + foreach ($form['language']['#options'] as $key => $value) {
  121. + if (empty($perms[$key])) {
  122. + unset($form['language']['#options'][$key]);
  123. }
  124. }
  125. - unset($form['#after_build']['0']);
  126. }
  127. +
  128. + return $form;
  129. }
  130. /**
  131. * Implements hook_form_alter().
  132. */
  133. function i18n_access_form_alter(&$form, &$form_state, $form_id) {
  134. -
  135. //Configuring translation edit form to limit it to allowed language
  136. - if ($form_id == 'i18n_node_select_translation' && !user_access('administer nodes')) {
  137. + if ($form_id == 'i18n_node_select_translation' && !user_access('bypass node access')) {
  138. $perms = i18n_access_load_permissions();
  139. -
  140. foreach ($form['translations']['nid'] as $language => $translation) {
  141. if (!isset($perms[$language]) && $language != '#tree') {
  142. unset($form['translations']['nid'][$language]);
  143. @@ -159,17 +156,15 @@ function i18n_access_form_alter(&$form, &$form_state, $form_id) {
  144. );
  145. $form['i18n_access']['i18n_access'] = array(
  146. '#type' => 'checkboxes',
  147. - '#options' => array(I18N_ACCESS_LANGUAGE_NEUTRAL => t('Language neutral')) + locale_language_list('name'),
  148. + '#options' => array(LANGUAGE_NONE => t('Language neutral')) + locale_language_list('name'),
  149. '#default_value' => i18n_access_load_permissions($form['#user']->uid),
  150. - '#description' => t('Select the languages that this user should have permission to create and edit content for.'),
  151. + '#description' => t('The user get edit, delete access to all content which are in this enabled languages. Create, view access needs a different access level.'),
  152. );
  153. }
  154. }
  155. /**
  156. - * Wrapper around node_access() with additional checks for language permissions.
  157. - *
  158. - * @see node_access()
  159. + * Implements hook_node_access().
  160. */
  161. function i18n_access_node_access($node, $op, $account = NULL) {
  162. if (is_object($node)) {
  163. @@ -181,29 +176,16 @@ function i18n_access_node_access($node, $op, $account = NULL) {
  164. $account = $user;
  165. }
  166. - // Bypass completely if node_access returns false.
  167. - //TODO $access = node_access($node, $op, $account);
  168. -
  169. - /* TODO if (!$access) {
  170. - return FALSE;
  171. - } */
  172. -
  173. // This module doesn't deal with view permissions
  174. if ($op == 'view') {
  175. return NODE_ACCESS_IGNORE;
  176. }
  177. - // make sure that administrators always have access
  178. - if (user_access('administer nodes', $account)) {
  179. - return TRUE;
  180. - }
  181. -
  182. $perms = i18n_access_load_permissions($account->uid);
  183. // Make sure to use the language neutral constant if node language is empty
  184. - $langcode = $node->language ? $node->language : I18N_ACCESS_LANGUAGE_NEUTRAL;
  185. + $langcode = $node->language ? $node->language : LANGUAGE_NONE;
  186. - //return isset($perms[$langcode]) ? (bool) $perms[$langcode] : NODE_ACCESS_DENY;
  187. return isset($perms[$langcode]) ? NODE_ACCESS_ALLOW : NODE_ACCESS_DENY;
  188. }
  189. }
  190. @@ -212,14 +194,26 @@ function i18n_access_node_access($node, $op, $account = NULL) {
  191. * Implements hook_menu_alter().
  192. */
  193. function i18n_access_menu_alter(&$items) {
  194. - // Replace the translation overview page since we can't hook it.
  195. - $items['node/%node/translate']['page callback'] = 'i18n_access_translation_node_overview';
  196. + if (isset($items['node/%node/translate'])) {
  197. + $items['node/%node/translate']['page callback'] = 'i18n_access_translation_node_overview';
  198. + }
  199. }
  200. +/**
  201. + * Most logic comes from translation/i18n_node module.
  202. + *
  203. + * We removes here only the "add translation" links for languages which are not your selected language.
  204. + *
  205. + * @see translation_node_overview
  206. + * @see i18n_node_translation_overview
  207. + *
  208. + * @param object $node
  209. + *
  210. + * @return array.
  211. + */
  212. function i18n_access_translation_node_overview($node) {
  213. include_once DRUPAL_ROOT . '/includes/language.inc';
  214. -
  215. if (!empty($node->tnid)) {
  216. // Already part of a set, grab that set.
  217. $tnid = $node->tnid;
  218. @@ -231,16 +225,12 @@ function i18n_access_translation_node_overview($node) {
  219. $translations = array($node->language => $node);
  220. }
  221. - $type = variable_get('translation_language_type', LANGUAGE_TYPE_INTERFACE);
  222. $header = array(t('Language'), t('Title'), t('Status'), t('Operations'));
  223. -
  224. - //added from i18n/i18n_node/i18n_node.pages.inc function
  225. + $rows = array();
  226. global $user;
  227. - $account = $user;
  228. - $perms = i18n_access_load_permissions($account->uid);
  229. + $perms = i18n_access_load_permissions($user->uid);
  230. //end
  231. -
  232. // Modes have different allowed languages
  233. foreach (i18n_node_language_list($node) as $langcode => $language_name) {
  234. if ($langcode == LANGUAGE_NONE) {
  235. @@ -268,15 +258,11 @@ function i18n_access_translation_node_overview($node) {
  236. else {
  237. // No such translation in the set yet: help user to create it.
  238. $title = t('n/a');
  239. - if (node_access('create', $node)) {
  240. + if (node_access('create', $node->type) && (!empty($perms[$langcode]) || user_access('bypass node access'))) {
  241. $text = t('add translation');
  242. $path = 'node/add/' . str_replace('_', '-', $node->type);
  243. $query = array('query' => array('translation' => $node->nid, 'target' => $langcode));
  244. -
  245. - //condition added from i18n/i18n_node/i18n_node.pages.inc
  246. - if (in_array($langcode, $perms)) {
  247. - $options[] = i18n_node_translation_link($text, $path, $langcode, $query);
  248. - }
  249. + $options[] = i18n_node_translation_link($text, $path, $langcode, $query);
  250. }
  251. $status = t('Not translated');
  252. }
  253. @@ -301,9 +287,7 @@ function i18n_access_translation_node_overview($node) {
  254. * Implements hook_menu().
  255. */
  256. function i18n_access_menu() {
  257. - $items = array();
  258. -
  259. - $items['admin/settings/language/access'] = array(
  260. + $items['admin/config/regional/language/access'] = array(
  261. 'title' => 'Access',
  262. 'page callback' => 'drupal_get_form',
  263. 'page arguments' => array('i18n_access_admin_settings'),
  264. @@ -311,23 +295,20 @@ function i18n_access_menu() {
  265. 'type' => MENU_LOCAL_TASK,
  266. 'weight' => 10,
  267. );
  268. -
  269. return $items;
  270. }
  271. /**
  272. - * Admin settings form
  273. + * Admin settings form.
  274. */
  275. -function i18n_access_admin_settings() {
  276. -
  277. +function i18n_access_admin_settings($form) {
  278. $form['i18n_access_languages'] = array(
  279. '#title' => t('Select the default access languages'),
  280. '#type' => 'select',
  281. - '#multiple' => 'true',
  282. - '#options' => array(I18N_ACCESS_LANGUAGE_NEUTRAL => t('Language neutral')) + locale_language_list('name'),
  283. + '#multiple' => TRUE,
  284. + '#options' => array(LANGUAGE_NONE => t('Language neutral')) + locale_language_list('name'),
  285. '#default_value' => variable_get('i18n_access_languages', array()),
  286. '#description' => t("This selection of languages will be connected with the 'access selected languages' permission which you can use to grant a role access to these languages at once.")
  287. );
  288. -
  289. return system_settings_form($form);
  290. -}
  291. \ No newline at end of file
  292. +}
  293. diff --git a/i18n_access.test b/i18n_access.test
  294. index d32dbf4..5b2f443 100644
  295. --- a/i18n_access.test
  296. +++ b/i18n_access.test
  297. @@ -6,10 +6,17 @@
  298. */
  299. class i18nAccessTestCase extends DrupalWebTestCase {
  300. +
  301. + protected $admin_user;
  302. +
  303. + protected $translator;
  304. +
  305. + protected $visitor;
  306. +
  307. /**
  308. * Implementation of getInfo().
  309. */
  310. - function getInfo() {
  311. + public static function getInfo() {
  312. return array(
  313. 'name' => t('Translation Access'),
  314. 'description' => t('Test suite for the i18n_access module.'),
  315. @@ -20,22 +27,21 @@ class i18nAccessTestCase extends DrupalWebTestCase {
  316. /**
  317. * Implementation of setUp().
  318. */
  319. - function setUp() {
  320. - parent::setUp('locale', 'translation', 'i18n_access');
  321. + public function setUp() {
  322. + parent::setUp(array('locale', 'translation', 'i18n_access', 'i18n_node'));
  323. - $this->admin_user = $this->drupalCreateUser(array('administer languages', 'administer site configuration', 'access administration pages', 'administer content types', 'administer nodes', 'administer users'));
  324. - $this->translator = $this->drupalCreateUser(array('create story content', 'edit own story content', 'translate content'));
  325. + $this->admin_user = $this->drupalCreateUser(array('administer languages', 'administer site configuration', 'access administration pages', 'administer content types', 'administer users', 'bypass node access', 'translate content'));
  326. + $this->translator = $this->drupalCreateUser(array('create article content', 'edit own article content', 'translate content'));
  327. $this->visitor = $this->drupalCreateUser(array('access content'));
  328. $this->drupalLogin($this->admin_user);
  329. +
  330. $this->addLanguage('fr');
  331. $this->addLanguage('de');
  332. - $this->setLanguagePermissions($this->translator, array('en', 'fr'));
  333. // Set Story content type to use multilingual support with translation.
  334. - $edit = array();
  335. $edit['language_content_type'] = 2;
  336. - $this->drupalPost('admin/content/node-type/story', $edit, t('Save content type'));
  337. - $this->assertRaw(t('The content type %type has been updated.', array('%type' => 'Story')), t('Story content type has been updated.'));
  338. + $this->drupalPost('admin/structure/types/manage/article', $edit, t('Save content type'));
  339. + $this->assertRaw(t('The content type %type has been updated.', array('%type' => 'Article')), 'Story content type has been updated.');
  340. }
  341. @@ -47,26 +53,27 @@ class i18nAccessTestCase extends DrupalWebTestCase {
  342. */
  343. function addLanguage($language_code) {
  344. // Check to make sure that language has not already been installed.
  345. - $this->drupalGet('admin/settings/language');
  346. + $this->drupalGet('admin/config/regional/language');
  347. if (strpos($this->drupalGetContent(), 'enabled[' . $language_code . ']') === FALSE) {
  348. // Doesn't have language installed so add it.
  349. $edit = array();
  350. $edit['langcode'] = $language_code;
  351. - $this->drupalPost('admin/settings/language/add', $edit, t('Add language'));
  352. + $this->drupalPost('admin/config/regional/language/add', $edit, t('Add language'));
  353. - $languages = language_list('language', TRUE); // Make sure not using cached version.
  354. - $this->assertTrue(array_key_exists($language_code, $languages), t('Language was installed successfully.'));
  355. + drupal_static_reset('language_list'); // Make sure not using cached version.
  356. + $languages = language_list('language');
  357. + $this->assertTrue(array_key_exists($language_code, $languages), 'Language was installed successfully.');
  358. if (array_key_exists($language_code, $languages)) {
  359. - $this->assertRaw(t('The language %language has been created and can now be used.', array('%language' => $languages[$language_code]->name)), t('Language has been created.'));
  360. + $this->assertRaw(t('The language %language has been created and can now be used.', array('%language' => $languages[$language_code]->name)), 'Language has been created.');
  361. }
  362. }
  363. else {
  364. // Ensure that it is enabled.
  365. $this->drupalPost(NULL, array('enabled[' . $language_code . ']' => TRUE), t('Save configuration'));
  366. - $this->assertRaw(t('Configuration saved.'), t('Language successfully enabled.'));
  367. + $this->assertRaw(t('Configuration saved.'), 'Language successfully enabled.');
  368. }
  369. }
  370. @@ -80,8 +87,9 @@ class i18nAccessTestCase extends DrupalWebTestCase {
  371. * An array of language codes to give permission for
  372. */
  373. function setLanguagePermissions($account, $languages = array()) {
  374. - $this->assertTrue(user_access('administer users'), t('User has permission to administer users'));
  375. -
  376. + $this->assertTrue(user_access('administer users'), 'User has permission to administer users');
  377. + $expected = array();
  378. + $edit = array();
  379. foreach ($languages as $langcode) {
  380. $key = 'i18n_access[' . $langcode . ']';
  381. $edit[$key] = $langcode;
  382. @@ -90,7 +98,31 @@ class i18nAccessTestCase extends DrupalWebTestCase {
  383. $this->drupalPost('user/' . $account->uid . '/edit', $edit, t('Save'));
  384. $actual = i18n_access_load_permissions($account->uid);
  385. - $this->assertEqual($expected, $actual, t('Language permissions set correctly.'), 'i18n_access');
  386. + $this->assertEqual($expected, $actual, 'Language permissions set correctly.', 'i18n_access');
  387. + }
  388. +
  389. + /**
  390. + * Unsets the language permission for the specified user. Must be logged in as
  391. + * an 'administer users' privileged user before calling this.
  392. + *
  393. + * @param $account
  394. + * The user account to modify
  395. + * @param $languages
  396. + * An array of language codes to remove permission for
  397. + */
  398. + function unsetLanguagePermissions($account, $languages = array()) {
  399. + $this->assertTrue(user_access('administer users'), 'User has permission to administer users');
  400. + $expected = array();
  401. + $edit = array();
  402. + foreach ($languages as $langcode) {
  403. + $key = 'i18n_access[' . $langcode . ']';
  404. + $edit[$key] = FALSE;
  405. + }
  406. + $this->drupalPost('user/' . $account->uid . '/edit', $edit, t('Save'));
  407. + drupal_static_reset('i18n_access_load_permissions');
  408. + drupal_static_reset('node_access');
  409. + $actual = i18n_access_load_permissions($account->uid);
  410. + $this->assertEqual($expected, $actual, 'Language permissions unset correctly.', 'i18n_access');
  411. }
  412. /**
  413. @@ -109,7 +141,6 @@ class i18nAccessTestCase extends DrupalWebTestCase {
  414. function assertLanguageOption($langcode, $message, $group = 'Other') {
  415. $xpath = '//select[@name="language"]/option';
  416. $fields = $this->xpath($xpath);
  417. -
  418. // If value specified then check array for match.
  419. $found = TRUE;
  420. if (isset($langcode)) {
  421. @@ -157,52 +188,145 @@ class i18nAccessTestCase extends DrupalWebTestCase {
  422. return $this->assertFalse($fields && $found, $message, $group);
  423. }
  424. - function dsm($object) {
  425. - $this->error('<pre>' . check_plain(print_r($object, 1)) . '</pre>');
  426. - }
  427. -
  428. /**
  429. - * Test translator user. User with 'create story content' and 'edit own story
  430. - * content' permissions should be able to create and edit story nodes only in
  431. + * Test translator user. User with 'create article content' permission
  432. + * should be able to create and edit article nodes only in/for
  433. * the languages that they have permissions for.
  434. */
  435. function testTranslatorUser() {
  436. + $this->_testTranslatorNodeAccess();
  437. + $this->_testTranslatorNodeAccess(TRUE);
  438. + }
  439. +
  440. +
  441. + function _testTranslatorNodeAccess($via_role = FALSE) {
  442. + $this->drupalLogin($this->admin_user);
  443. + if (!$via_role) {
  444. + $this->setLanguagePermissions($this->translator, array('en', 'fr'));
  445. + }
  446. + else{
  447. + $edit = array(
  448. + 'i18n_access_languages[]' => array('en', 'fr'),
  449. + );
  450. + $this->drupalPost('admin/config/regional/language/access', $edit, t('Save configuration'));
  451. +
  452. + $this->translator = $this->drupalCreateUser(array('create article content', 'edit own article content', 'translate content', 'access selected languages'));
  453. + }
  454. +
  455. $this->drupalLogin($this->translator);
  456. - $this->drupalGet('node/add/story');
  457. - $this->assertField('language', t('Found language selector.'));
  458. + $this->drupalGet('node/add/article');
  459. + $this->assertField('language', 'Found language selector.');
  460. $perms = i18n_access_load_permissions($this->translator->uid);
  461. $languages = language_list();
  462. - $languages[I18N_ACCESS_LANGUAGE_NEUTRAL] = (object)array('language' => '', 'name' => 'Language Neutral');
  463. + $languages[LANGUAGE_NONE] = (object)array('language' => LANGUAGE_NONE, 'name' => 'Language Neutral');
  464. foreach ($languages as $key => $language) {
  465. // TODO: Add in check for language neutral
  466. if (isset($perms[$key]) && $perms[$key]) {
  467. - $this->assertLanguageOption($language->language, t('Option found for %language in language selector.', array('%language' => $language->name)));
  468. + $this->assertLanguageOption($language->language, format_string('Option found for %language in language selector.', array('%language' => $language->name)));
  469. }
  470. else {
  471. - $this->assertNoLanguageOption($language->language, t('Option not found for %language in language selector.', array('%language' => $language->name)));
  472. + $this->assertNoLanguageOption($language->language, format_string('Option not found for %language in language selector.', array('%language' => $language->name)));
  473. }
  474. }
  475. - }
  476. + $this->drupalLogin($this->admin_user);
  477. + $node = $this->drupalCreateNode(array('type' => 'article', 'language' => 'de', 'body' => array('de' => array(array()))));
  478. +
  479. + $this->drupalLogin($this->translator);
  480. + $this->assertFalse(node_access('update', $node, $this->loggedInUser));
  481. + $this->drupalGet('node/' . $node->nid . '/edit');
  482. + $this->assertResponse(403);
  483. +
  484. + $this->assertFalse(node_access('delete', $node, $this->loggedInUser));
  485. + $this->drupalGet('node/' . $node->nid . '/delete');
  486. + $this->assertResponse(403);
  487. +
  488. + $this->drupalLogin($this->admin_user);
  489. + $node = $this->drupalCreateNode(array('type' => 'article', 'language' => 'fr', 'body' => array('fr' => array(array()))));
  490. +
  491. + $this->drupalLogin($this->translator);
  492. + $this->assertTrue(node_access('update', $node, $this->loggedInUser));
  493. + $this->drupalGet('node/' . $node->nid . '/edit');
  494. + $this->assertResponse(200);
  495. +
  496. + $this->assertTrue(node_access('delete', $node, $this->loggedInUser));
  497. + $this->drupalGet('node/' . $node->nid . '/delete');
  498. + $this->assertResponse(200);
  499. +
  500. + $this->drupalGet('node/' . $node->nid . '/translate');
  501. + $query = array('query' => array('translation' => $node->nid, 'target' => 'de'));
  502. + $this->assertNoRaw(i18n_node_translation_link(t('add translation'), 'node/add/article', 'de', $query));
  503. + $query = array('query' => array('translation' => $node->nid, 'target' => 'en'));
  504. + $this->assertRaw(i18n_node_translation_link(t('add translation'), 'node/add/article', 'en', $query));
  505. + $this->assertRaw(i18n_node_translation_link(t('edit'), 'node/' . $node->nid . '/edit', 'fr'));
  506. +
  507. + $this->drupalLogin($this->admin_user);
  508. + if (!$via_role) {
  509. + $this->unsetLanguagePermissions($this->translator, array('fr', 'en'));
  510. + }
  511. + else{
  512. + $edit = array(
  513. + 'i18n_access_languages[]' => array(),
  514. + );
  515. + $this->drupalPost('admin/config/regional/language/access', $edit, t('Save configuration'));
  516. + $this->translator = $this->drupalCreateUser(array('create article content', 'edit own article content', 'translate content', 'access selected languages'));
  517. + drupal_static_reset('i18n_access_load_permissions');
  518. + drupal_static_reset('node_access');
  519. + }
  520. +
  521. + $this->drupalLogin($this->translator);
  522. + $this->assertFalse(node_access('update', $node, $this->loggedInUser));
  523. + $this->drupalGet('node/' . $node->nid . '/edit');
  524. + $this->assertResponse(403);
  525. +
  526. + $this->assertFalse(node_access('delete', $node, $this->loggedInUser));
  527. + $this->drupalGet('node/' . $node->nid . '/delete');
  528. + $this->assertResponse(403);
  529. +
  530. + $this->drupalGet('node/' . $node->nid . '/translate');
  531. + $query = array('query' => array('translation' => $node->nid, 'target' => 'de'));
  532. + $this->assertNoRaw(i18n_node_translation_link(t('add translation'), 'node/add/article', 'de', $query));
  533. + $query = array('query' => array('translation' => $node->nid, 'target' => 'en'));
  534. + $this->assertNoRaw(i18n_node_translation_link(t('add translation'), 'node/add/article', 'en', $query));
  535. + $this->assertNoRaw(i18n_node_translation_link(t('edit'), 'node/' . $node->nid . '/edit', 'fr'));
  536. +
  537. + }
  538. /**
  539. - * Test admin user. User with 'administer nodes' permission should be able to
  540. - * create and edit nodes regardless of the language
  541. + * Test admin user. User with 'bypass node access' permission should be able to
  542. + * update, delete nodes regardless of the language.
  543. */
  544. function testAdminUser() {
  545. $this->drupalLogin($this->admin_user);
  546. + $this->drupalGet('node/add/article');
  547. + $this->assertField('language', 'Found language selector.');
  548. - $this->drupalGet('node/add/story');
  549. - $this->assertField('language', t('Found language selector.'));
  550. -
  551. - $perms = i18n_access_load_permissions($this->admin_user->uid);
  552. $languages = language_list();
  553. - $languages[I18N_ACCESS_LANGUAGE_NEUTRAL] = (object)array('language' => '', 'name' => 'Language Neutral');
  554. + $languages[LANGUAGE_NONE] = (object)array('language' => LANGUAGE_NONE, 'name' => 'Language Neutral');
  555. foreach ($languages as $language) {
  556. - // TODO: Add in check for language neutral
  557. - $this->assertLanguageOption($language->language, t('Option found for %language, regardless of permission, for administrator.', array('%language' => $language->name)));
  558. + $this->assertLanguageOption($language->language, format_string('Option found for %language, regardless of permission, for administrator.', array('%language' => $language->name)));
  559. }
  560. + $this->drupalLogin($this->translator);
  561. + $node = $this->drupalCreateNode(array('type' => 'article', 'language' => 'de', 'body' => array('de' => array(array()))));
  562. +
  563. + $this->drupalLogin($this->admin_user);
  564. +
  565. + $this->assertTrue(node_access('update', $node, $this->loggedInUser));
  566. + $this->drupalGet('node/' . $node->nid . '/edit');
  567. + $this->assertResponse(200);
  568. +
  569. + $this->assertTrue(node_access('delete', $node, $this->loggedInUser));
  570. + $this->drupalGet('node/' . $node->nid . '/delete');
  571. + $this->assertResponse(200);
  572. +
  573. + $this->drupalGet('node/' . $node->nid . '/translate');
  574. +
  575. + $query = array('query' => array('translation' => $node->nid, 'target' => 'fr'));
  576. + $this->assertRaw(i18n_node_translation_link(t('add translation'), 'node/add/article', 'fr', $query));
  577. + $query = array('query' => array('translation' => $node->nid, 'target' => 'en'));
  578. + $this->assertRaw(i18n_node_translation_link(t('add translation'), 'node/add/article', 'en', $query));
  579. + $this->assertRaw(i18n_node_translation_link(t('edit'), 'node/' . $node->nid . '/edit', 'de'));
  580. }
  581. -}
  582. \ No newline at end of file
  583. +}