123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021 |
- <?php
- class NodeWebTestCase extends DrupalWebTestCase {
- function setUp() {
- $modules = func_get_args();
- if (isset($modules[0]) && is_array($modules[0])) {
- $modules = $modules[0];
- }
- $modules[] = 'node';
- parent::setUp($modules);
-
- if ($this->profile != 'standard') {
- $this->drupalCreateContentType(array('type' => 'page', 'name' => 'Basic page'));
- $this->drupalCreateContentType(array('type' => 'article', 'name' => 'Article'));
- }
- }
- }
- class NodeLoadMultipleTestCase extends DrupalWebTestCase {
- public static function getInfo() {
- return array(
- 'name' => 'Load multiple nodes',
- 'description' => 'Test the loading of multiple nodes.',
- 'group' => 'Node',
- );
- }
- function setUp() {
- parent::setUp();
- $web_user = $this->drupalCreateUser(array('create article content', 'create page content'));
- $this->drupalLogin($web_user);
- }
-
- function testNodeMultipleLoad() {
- $node1 = $this->drupalCreateNode(array('type' => 'article', 'promote' => 1));
- $node2 = $this->drupalCreateNode(array('type' => 'article', 'promote' => 1));
- $node3 = $this->drupalCreateNode(array('type' => 'article', 'promote' => 0));
- $node4 = $this->drupalCreateNode(array('type' => 'page', 'promote' => 0));
-
- $this->drupalGet('node');
- $this->assertText($node1->title, 'Node title appears on the default listing.');
- $this->assertText($node2->title, 'Node title appears on the default listing.');
- $this->assertNoText($node3->title, 'Node title does not appear in the default listing.');
- $this->assertNoText($node4->title, 'Node title does not appear in the default listing.');
-
- $nodes = node_load_multiple(NULL, array('promote' => 0));
- $this->assertEqual($node3->title, $nodes[$node3->nid]->title, 'Node was loaded.');
- $this->assertEqual($node4->title, $nodes[$node4->nid]->title, 'Node was loaded.');
- $count = count($nodes);
- $this->assertTrue($count == 2, format_string('@count nodes loaded.', array('@count' => $count)));
-
- $nodes = node_load_multiple(array(1, 2, 4));
- $count = count($nodes);
- $this->assertTrue(count($nodes) == 3, format_string('@count nodes loaded', array('@count' => $count)));
- $this->assertTrue(isset($nodes[$node1->nid]), 'Node is correctly keyed in the array');
- $this->assertTrue(isset($nodes[$node2->nid]), 'Node is correctly keyed in the array');
- $this->assertTrue(isset($nodes[$node4->nid]), 'Node is correctly keyed in the array');
- foreach ($nodes as $node) {
- $this->assertTrue(is_object($node), 'Node is an object');
- }
-
- $nodes = node_load_multiple(array(1, 2, 3, 4), array('type' => 'article'));
- $count = count($nodes);
- $this->assertTrue($count == 3, format_string('@count nodes loaded', array('@count' => $count)));
- $this->assertEqual($nodes[$node1->nid]->title, $node1->title, 'Node successfully loaded.');
- $this->assertEqual($nodes[$node2->nid]->title, $node2->title, 'Node successfully loaded.');
- $this->assertEqual($nodes[$node3->nid]->title, $node3->title, 'Node successfully loaded.');
- $this->assertFalse(isset($nodes[$node4->nid]));
-
-
- $nodes = node_load_multiple(array(1, 2, 3, 4), array('type' => 'article'));
- $count = count($nodes);
- $this->assertTrue($count == 3, format_string('@count nodes loaded.', array('@count' => $count)));
- $this->assertEqual($nodes[$node1->nid]->title, $node1->title, 'Node successfully loaded');
- $this->assertEqual($nodes[$node2->nid]->title, $node2->title, 'Node successfully loaded');
- $this->assertEqual($nodes[$node3->nid]->title, $node3->title, 'Node successfully loaded');
- $this->assertFalse(isset($nodes[$node4->nid]), 'Node was not loaded');
-
- $nodes = node_load_multiple(array(1, 2, 3, 4), array('type' => 'article', 'promote' => 0));
- $count = count($nodes);
- $this->assertTrue($count == 1, format_string('@count node loaded', array('@count' => $count)));
- $this->assertEqual($nodes[$node3->nid]->title, $node3->title, 'Node successfully loaded.');
- }
- }
- class NodeLoadHooksTestCase extends DrupalWebTestCase {
- public static function getInfo() {
- return array(
- 'name' => 'Node load hooks',
- 'description' => 'Test the hooks invoked when a node is being loaded.',
- 'group' => 'Node',
- );
- }
- function setUp() {
- parent::setUp('node_test');
- }
-
- function testHookNodeLoad() {
-
- $node1 = $this->drupalCreateNode(array('type' => 'article', 'status' => NODE_PUBLISHED));
- $node2 = $this->drupalCreateNode(array('type' => 'article', 'status' => NODE_PUBLISHED));
- $node3 = $this->drupalCreateNode(array('type' => 'article', 'status' => NODE_NOT_PUBLISHED));
- $node4 = $this->drupalCreateNode(array('type' => 'page', 'status' => NODE_NOT_PUBLISHED));
-
-
-
- $nodes = node_load_multiple(array(), array('status' => NODE_PUBLISHED));
- $loaded_node = end($nodes);
- $this->assertEqual($loaded_node->node_test_loaded_nids, array($node1->nid, $node2->nid), 'hook_node_load() received the correct list of node IDs the first time it was called.');
- $this->assertEqual($loaded_node->node_test_loaded_types, array('article'), 'hook_node_load() received the correct list of node types the first time it was called.');
-
-
-
- $nodes = node_load_multiple(array(), array('status' => NODE_NOT_PUBLISHED));
- $loaded_node = end($nodes);
- $this->assertEqual($loaded_node->node_test_loaded_nids, array($node3->nid, $node4->nid), 'hook_node_load() received the correct list of node IDs the second time it was called.');
- $this->assertEqual($loaded_node->node_test_loaded_types, array('article', 'page'), 'hook_node_load() received the correct list of node types the second time it was called.');
- }
- }
- class NodeRevisionsTestCase extends DrupalWebTestCase {
-
- protected $nodes;
-
- protected $logs;
- public static function getInfo() {
- return array(
- 'name' => 'Node revisions',
- 'description' => 'Create a node with revisions and test viewing, saving, reverting, and deleting revisions.',
- 'group' => 'Node',
- );
- }
- function setUp() {
- parent::setUp();
-
- $web_user = $this->drupalCreateUser(array('view revisions', 'revert revisions', 'edit any page content',
- 'delete revisions', 'delete any page content'));
- $this->drupalLogin($web_user);
-
- $node = $this->drupalCreateNode();
- $settings = get_object_vars($node);
- $settings['revision'] = 1;
- $nodes = array();
- $logs = array();
-
- $nodes[] = $node;
-
- $revision_count = 3;
- for ($i = 0; $i < $revision_count; $i++) {
- $logs[] = $settings['log'] = $this->randomName(32);
-
- $this->drupalCreateNode($settings);
- $node = node_load($node->nid);
- $settings = get_object_vars($node);
- $nodes[] = $node;
- }
- $this->nodes = $nodes;
- $this->logs = $logs;
- }
-
- function testRevisions() {
- $nodes = $this->nodes;
- $logs = $this->logs;
-
- $node = $nodes[3];
-
- $this->drupalGet("node/$node->nid/revisions/$node->vid/view");
- $this->assertText($node->body[LANGUAGE_NONE][0]['value'], 'Correct text displays for version.');
-
- $this->drupalGet("node/$node->nid/revisions");
- foreach ($logs as $log) {
- $this->assertText($log, 'Log message found.');
- }
-
- $this->drupalPost("node/$node->nid/revisions/{$nodes[1]->vid}/revert", array(), t('Revert'));
- $this->assertRaw(t('@type %title has been reverted back to the revision from %revision-date.',
- array('@type' => 'Basic page', '%title' => $nodes[1]->title,
- '%revision-date' => format_date($nodes[1]->revision_timestamp))), 'Revision reverted.');
- $reverted_node = node_load($node->nid);
- $this->assertTrue(($nodes[1]->body[LANGUAGE_NONE][0]['value'] == $reverted_node->body[LANGUAGE_NONE][0]['value']), 'Node reverted correctly.');
-
- $this->drupalPost("node/$node->nid/revisions/{$nodes[1]->vid}/delete", array(), t('Delete'));
- $this->assertRaw(t('Revision from %revision-date of @type %title has been deleted.',
- array('%revision-date' => format_date($nodes[1]->revision_timestamp),
- '@type' => 'Basic page', '%title' => $nodes[1]->title)), 'Revision deleted.');
- $this->assertTrue(db_query('SELECT COUNT(vid) FROM {node_revision} WHERE nid = :nid and vid = :vid', array(':nid' => $node->nid, ':vid' => $nodes[1]->vid))->fetchField() == 0, 'Revision not found.');
- }
-
- function testNodeRevisionWithoutLogMessage() {
-
- $log = $this->randomName(10);
- $node = $this->drupalCreateNode(array('log' => $log));
-
-
-
-
- $new_title = $this->randomName(10) . 'testNodeRevisionWithoutLogMessage1';
- $updated_node = (object) array(
- 'nid' => $node->nid,
- 'vid' => $node->vid,
- 'uid' => $node->uid,
- 'type' => $node->type,
- 'title' => $new_title,
- 'log' => '',
- );
- node_save($updated_node);
- $this->drupalGet('node/' . $node->nid);
- $this->assertText($new_title, 'New node title appears on the page.');
- $node_revision = node_load($node->nid, NULL, TRUE);
- $this->assertEqual($node_revision->log, $log, 'After an existing node revision is re-saved without a log message, the original log message is preserved.');
-
- $node = $this->drupalCreateNode(array('log' => $log));
-
-
- $new_title = $this->randomName(10) . 'testNodeRevisionWithoutLogMessage2';
- $updated_node = (object) array(
- 'nid' => $node->nid,
- 'vid' => $node->vid,
- 'uid' => $node->uid,
- 'type' => $node->type,
- 'title' => $new_title,
- 'revision' => 1,
- );
- node_save($updated_node);
- $this->drupalGet('node/' . $node->nid);
- $this->assertText($new_title, 'New node title appears on the page.');
- $node_revision = node_load($node->nid, NULL, TRUE);
- $this->assertTrue(empty($node_revision->log), 'After a new node revision is saved with an empty log message, the log message for the node is empty.');
- }
- }
- class PageEditTestCase extends DrupalWebTestCase {
-
- protected $web_user;
-
- protected $admin_user;
- public static function getInfo() {
- return array(
- 'name' => 'Node edit',
- 'description' => 'Create a node and test node edit functionality.',
- 'group' => 'Node',
- );
- }
- function setUp() {
- parent::setUp();
- $this->web_user = $this->drupalCreateUser(array('edit own page content', 'create page content'));
- $this->admin_user = $this->drupalCreateUser(array('bypass node access', 'administer nodes'));
- }
-
- function testPageEdit() {
- $this->drupalLogin($this->web_user);
- $langcode = LANGUAGE_NONE;
- $title_key = "title";
- $body_key = "body[$langcode][0][value]";
-
- $edit = array();
- $edit[$title_key] = $this->randomName(8);
- $edit[$body_key] = $this->randomName(16);
- $this->drupalPost('node/add/page', $edit, t('Save'));
-
- $node = $this->drupalGetNodeByTitle($edit[$title_key]);
- $this->assertTrue($node, 'Node found in database.');
-
- $this->clickLink(t('Edit'));
- $edit_url = url("node/$node->nid/edit", array('absolute' => TRUE));
- $actual_url = $this->getURL();
- $this->assertEqual($edit_url, $actual_url, 'On edit page.');
-
- $active = '<span class="element-invisible">' . t('(active tab)') . '</span>';
- $link_text = t('!local-task-title!active', array('!local-task-title' => t('Edit'), '!active' => $active));
- $this->assertText(strip_tags($link_text), 0, 'Edit tab found and marked active.');
- $this->assertFieldByName($title_key, $edit[$title_key], 'Title field displayed.');
- $this->assertFieldByName($body_key, $edit[$body_key], 'Body field displayed.');
-
- $edit = array();
- $edit[$title_key] = $this->randomName(8);
- $edit[$body_key] = $this->randomName(16);
-
- $this->drupalPost(NULL, $edit, t('Save'));
-
- $this->assertText($edit[$title_key], 'Title displayed.');
- $this->assertText($edit[$body_key], 'Body displayed.');
-
- $second_web_user = $this->drupalCreateUser(array('administer nodes', 'edit any page content'));
- $this->drupalLogin($second_web_user);
-
- $this->drupalGet("node/$node->nid/edit");
- $edit = array();
- $edit['title'] = $this->randomName(8);
- $edit[$body_key] = $this->randomName(16);
- $edit['revision'] = TRUE;
- $this->drupalPost(NULL, $edit, t('Save'));
-
- $revised_node = $this->drupalGetNodeByTitle($edit['title']);
- $this->assertNotIdentical($node->vid, $revised_node->vid, 'A new revision has been created.');
-
-
- $this->assertIdentical($node->uid, $revised_node->uid, 'The node author has been preserved.');
-
-
- $first_node_version = node_load($node->nid, $node->vid);
- $second_node_version = node_load($node->nid, $revised_node->vid);
- $this->assertNotIdentical($first_node_version->revision_uid, $second_node_version->revision_uid, 'Each revision has a distinct user.');
- }
-
- function testPageAuthoredBy() {
- $this->drupalLogin($this->admin_user);
-
- $langcode = LANGUAGE_NONE;
- $body_key = "body[$langcode][0][value]";
- $edit = array();
- $edit['title'] = $this->randomName(8);
- $edit[$body_key] = $this->randomName(16);
- $this->drupalPost('node/add/page', $edit, t('Save'));
-
- $node = $this->drupalGetNodeByTitle($edit['title']);
- $this->assertIdentical($node->uid, $this->admin_user->uid, 'Node authored by admin user.');
-
- $edit = array(
- 'name' => 'invalid-name',
- );
- $this->drupalPost('node/' . $node->nid . '/edit', $edit, t('Save'));
- $this->assertText('The username invalid-name does not exist.');
-
-
- $edit['name'] = '';
- $this->drupalPost('node/' . $node->nid . '/edit', $edit, t('Save'));
- $node = node_load($node->nid, NULL, TRUE);
- $this->assertIdentical($node->uid, '0', 'Node authored by anonymous user.');
-
-
- $edit['name'] = $this->web_user->name;
- $this->drupalPost('node/' . $node->nid . '/edit', $edit, t('Save'));
- $node = node_load($node->nid, NULL, TRUE);
- $this->assertIdentical($node->uid, $this->web_user->uid, 'Node authored by normal user.');
-
- $this->drupalLogin($this->web_user);
- $this->drupalGet('node/' . $node->nid . '/edit');
- $this->assertNoFieldByName('name');
- }
- }
- class PagePreviewTestCase extends DrupalWebTestCase {
- public static function getInfo() {
- return array(
- 'name' => 'Node preview',
- 'description' => 'Test node preview functionality.',
- 'group' => 'Node',
- );
- }
- function setUp() {
- parent::setUp(array('taxonomy', 'node'));
- $web_user = $this->drupalCreateUser(array('edit own page content', 'create page content'));
- $this->drupalLogin($web_user);
-
- $vocabulary = (object) array(
- 'name' => $this->randomName(),
- 'description' => $this->randomName(),
- 'machine_name' => drupal_strtolower($this->randomName()),
- 'help' => '',
- 'nodes' => array('page' => 'page'),
- );
- taxonomy_vocabulary_save($vocabulary);
- $this->vocabulary = $vocabulary;
-
- $term = (object) array(
- 'name' => $this->randomName(),
- 'description' => $this->randomName(),
-
- 'format' => db_query_range('SELECT format FROM {filter_format}', 0, 1)->fetchField(),
- 'vid' => $this->vocabulary->vid,
- 'vocabulary_machine_name' => $vocabulary->machine_name,
- );
- taxonomy_term_save($term);
- $this->term = $term;
-
- $this->field_name = drupal_strtolower($this->randomName());
- $this->field = array(
- 'field_name' => $this->field_name,
- 'type' => 'taxonomy_term_reference',
- 'settings' => array(
- 'allowed_values' => array(
- array(
- 'vocabulary' => $this->vocabulary->machine_name,
- 'parent' => '0',
- ),
- ),
- )
- );
- field_create_field($this->field);
- $this->instance = array(
- 'field_name' => $this->field_name,
- 'entity_type' => 'node',
- 'bundle' => 'page',
- 'widget' => array(
- 'type' => 'options_select',
- ),
-
- 'display' => array(
- 'default' => array(
- 'type' => 'hidden',
- ),
- 'teaser' => array(
- 'type' => 'taxonomy_term_reference_link',
- ),
- ),
- );
- field_create_instance($this->instance);
- }
-
- function testPagePreview() {
- $langcode = LANGUAGE_NONE;
- $title_key = "title";
- $body_key = "body[$langcode][0][value]";
- $term_key = "{$this->field_name}[$langcode]";
-
- $edit = array();
- $edit[$title_key] = $this->randomName(8);
- $edit[$body_key] = $this->randomName(16);
- $edit[$term_key] = $this->term->tid;
- $this->drupalPost('node/add/page', $edit, t('Preview'));
-
- $this->assertTitle(t('Preview | Drupal'), 'Basic page title is preview.');
- $this->assertText($edit[$title_key], 'Title displayed.');
- $this->assertText($edit[$body_key], 'Body displayed.');
- $this->assertText($this->term->name, 'Term displayed.');
-
-
- $this->assertFieldByName($title_key, $edit[$title_key], 'Title field displayed.');
- $this->assertFieldByName($body_key, $edit[$body_key], 'Body field displayed.');
- $this->assertFieldByName($term_key, $edit[$term_key], 'Term field displayed.');
- }
-
- function testPagePreviewWithRevisions() {
- $langcode = LANGUAGE_NONE;
- $title_key = "title";
- $body_key = "body[$langcode][0][value]";
- $term_key = "{$this->field_name}[$langcode]";
-
- variable_set('node_options_page', array('status', 'revision'));
-
- $edit = array();
- $edit[$title_key] = $this->randomName(8);
- $edit[$body_key] = $this->randomName(16);
- $edit[$term_key] = $this->term->tid;
- $edit['log'] = $this->randomName(32);
- $this->drupalPost('node/add/page', $edit, t('Preview'));
-
- $this->assertTitle(t('Preview | Drupal'), 'Basic page title is preview.');
- $this->assertText($edit[$title_key], 'Title displayed.');
- $this->assertText($edit[$body_key], 'Body displayed.');
- $this->assertText($this->term->name, 'Term displayed.');
-
-
- $this->assertFieldByName($title_key, $edit[$title_key], 'Title field displayed.');
- $this->assertFieldByName($body_key, $edit[$body_key], 'Body field displayed.');
- $this->assertFieldByName($term_key, $edit[$term_key], 'Term field displayed.');
-
- $this->assertFieldByName('log', $edit['log'], 'Log field displayed.');
- }
- }
- class NodeCreationTestCase extends DrupalWebTestCase {
- public static function getInfo() {
- return array(
- 'name' => 'Node creation',
- 'description' => 'Create a node and test saving it.',
- 'group' => 'Node',
- );
- }
- function setUp() {
-
- parent::setUp('node_test_exception');
- $web_user = $this->drupalCreateUser(array('create page content', 'edit own page content'));
- $this->drupalLogin($web_user);
- }
-
- function testNodeCreation() {
-
- $edit = array();
- $langcode = LANGUAGE_NONE;
- $edit["title"] = $this->randomName(8);
- $edit["body[$langcode][0][value]"] = $this->randomName(16);
- $this->drupalPost('node/add/page', $edit, t('Save'));
-
- $this->assertRaw(t('!post %title has been created.', array('!post' => 'Basic page', '%title' => $edit["title"])), 'Basic page created.');
-
- $node = $this->drupalGetNodeByTitle($edit["title"]);
- $this->assertTrue($node, 'Node found in database.');
- }
-
- function testFailedPageCreation() {
-
- $edit = array(
- 'uid' => $this->loggedInUser->uid,
- 'name' => $this->loggedInUser->name,
- 'type' => 'page',
- 'language' => LANGUAGE_NONE,
- 'title' => 'testing_transaction_exception',
- );
- try {
-
-
- node_save((object) $edit);
- $this->fail(t('Expected exception has not been thrown.'));
- }
- catch (Exception $e) {
- $this->pass(t('Expected exception has been thrown.'));
- }
- if (Database::getConnection()->supportsTransactions()) {
-
- $node = $this->drupalGetNodeByTitle($edit['title']);
- $this->assertFalse($node, 'Transactions supported, and node not found in database.');
- }
- else {
-
- $node = $this->drupalGetNodeByTitle($edit['title']);
- $this->assertTrue($node, 'Transactions not supported, and node found in database.');
-
- $records = db_query("SELECT wid FROM {watchdog} WHERE message LIKE 'Explicit rollback failed%'")->fetchAll();
- $this->assertTrue(count($records) > 0, 'Transactions not supported, and rollback error logged to watchdog.');
- }
-
- $records = db_query("SELECT wid FROM {watchdog} WHERE variables LIKE '%Test exception for rollback.%'")->fetchAll();
- $this->assertTrue(count($records) > 0, 'Rollback explanatory error logged to watchdog.');
- }
-
- function testUnpublishedNodeCreation() {
-
- variable_set('node_options_page', array());
-
- variable_set('site_frontpage', 'node');
-
- $edit = array();
- $edit["title"] = $this->randomName(8);
- $edit["body[" . LANGUAGE_NONE . "][0][value]"] = $this->randomName(16);
- $this->drupalPost('node/add/page', $edit, t('Save'));
-
- $this->assertText(t('Welcome to Drupal'), t('The user is redirected to the home page.'));
- }
- }
- class PageViewTestCase extends DrupalWebTestCase {
- public static function getInfo() {
- return array(
- 'name' => 'Node edit permissions',
- 'description' => 'Create a node and test edit permissions.',
- 'group' => 'Node',
- );
- }
-
- function testPageView() {
-
- $node = $this->drupalCreateNode();
- $this->assertTrue(node_load($node->nid), 'Node created.');
-
- $html = $this->drupalGet("node/$node->nid/edit");
- $this->assertResponse(403);
-
- $web_user = $this->drupalCreateUser(array('access content'));
- $this->drupalLogin($web_user);
-
- $this->drupalGet("node/$node->nid/edit");
- $this->assertResponse(403);
-
- $web_user = $this->drupalCreateUser(array('bypass node access'));
- $this->drupalLogin($web_user);
-
- $this->drupalGet("node/$node->nid/edit");
- $this->assertResponse(200);
- }
- }
- class SummaryLengthTestCase extends DrupalWebTestCase {
- public static function getInfo() {
- return array(
- 'name' => 'Summary length',
- 'description' => 'Test summary length.',
- 'group' => 'Node',
- );
- }
-
- function testSummaryLength() {
-
- $settings = array(
- 'body' => array(LANGUAGE_NONE => array(array('value' => 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam vitae arcu at leo cursus laoreet. Curabitur dui tortor, adipiscing malesuada tempor in, bibendum ac diam. Cras non tellus a libero pellentesque condimentum. What is a Drupalism? Suspendisse ac lacus libero. Ut non est vel nisl faucibus interdum nec sed leo. Pellentesque sem risus, vulputate eu semper eget, auctor in libero. Ut fermentum est vitae metus convallis scelerisque. Phasellus pellentesque rhoncus tellus, eu dignissim purus posuere id. Quisque eu fringilla ligula. Morbi ullamcorper, lorem et mattis egestas, tortor neque pretium velit, eget eleifend odio turpis eu purus. Donec vitae metus quis leo pretium tincidunt a pulvinar sem. Morbi adipiscing laoreet mauris vel placerat. Nullam elementum, nisl sit amet scelerisque malesuada, dolor nunc hendrerit quam, eu ultrices erat est in orci. Curabitur feugiat egestas nisl sed accumsan.'))),
- 'promote' => 1,
- );
- $node = $this->drupalCreateNode($settings);
- $this->assertTrue(node_load($node->nid), 'Node created.');
-
- $web_user = $this->drupalCreateUser(array('access content', 'administer content types'));
- $this->drupalLogin($web_user);
-
- $this->drupalGet("node");
-
- $expected = 'What is a Drupalism?';
- $this->assertRaw($expected, 'Check that the summary is 600 characters in length', 'Node');
-
- $instance = field_info_instance('node', 'body', $node->type);
- $instance['display']['teaser']['settings']['trim_length'] = 200;
- field_update_instance($instance);
-
- $this->drupalGet("node");
- $this->assertNoRaw($expected, 'Check that the summary is not longer than 200 characters', 'Node');
- }
- }
- class NodeTitleXSSTestCase extends DrupalWebTestCase {
- public static function getInfo() {
- return array(
- 'name' => 'Node title XSS filtering',
- 'description' => 'Create a node with dangerous tags in its title and test that they are escaped.',
- 'group' => 'Node',
- );
- }
-
- function testNodeTitleXSS() {
-
- $web_user = $this->drupalCreateUser(array('create page content', 'edit any page content'));
- $this->drupalLogin($web_user);
- $xss = '<script>alert("xss")</script>';
- $title = $xss . $this->randomName();
- $edit = array("title" => $title);
- $this->drupalPost('node/add/page', $edit, t('Preview'));
- $this->assertNoRaw($xss, 'Harmful tags are escaped when previewing a node.');
- $settings = array('title' => $title);
- $node = $this->drupalCreateNode($settings);
- $this->drupalGet('node/' . $node->nid);
-
- $this->assertTitle($edit["title"] . ' | Drupal', 'Title is diplayed when viewing a node.');
- $this->assertNoRaw($xss, 'Harmful tags are escaped when viewing a node.');
- $this->drupalGet('node/' . $node->nid . '/edit');
- $this->assertNoRaw($xss, 'Harmful tags are escaped when editing a node.');
- }
- }
- class NodeBlockTestCase extends DrupalWebTestCase {
- public static function getInfo() {
- return array(
- 'name' => 'Block availability',
- 'description' => 'Check if the syndicate block is available.',
- 'group' => 'Node',
- );
- }
- function setUp() {
- parent::setUp();
-
- $admin_user = $this->drupalCreateUser(array('administer blocks'));
- $this->drupalLogin($admin_user);
- }
-
- function testSyndicateBlock() {
-
- $this->drupalPost('admin/structure/block/manage/node/syndicate/configure', array('title' => $this->randomName(8)), t('Save block'));
- $this->assertText(t('The block configuration has been saved.'), 'Block configuration set.');
-
- $edit = array();
- $edit['blocks[node_syndicate][region]'] = 'footer';
- $this->drupalPost('admin/structure/block', $edit, t('Save blocks'));
- $this->assertText(t('The block settings have been updated.'), 'Block successfully move to footer region.');
- }
- }
- class NodePostSettingsTestCase extends DrupalWebTestCase {
- public static function getInfo() {
- return array(
- 'name' => 'Node post information display',
- 'description' => 'Check that the post information (submitted by Username on date) text displays appropriately.',
- 'group' => 'Node',
- );
- }
- function setUp() {
- parent::setUp();
- $web_user = $this->drupalCreateUser(array('create page content', 'administer content types', 'access user profiles'));
- $this->drupalLogin($web_user);
- }
-
- function testPagePostInfo() {
-
- $edit = array();
- $edit['node_submitted'] = TRUE;
- $this->drupalPost('admin/structure/types/manage/page', $edit, t('Save content type'));
-
- $edit = array();
- $langcode = LANGUAGE_NONE;
- $edit["title"] = $this->randomName(8);
- $edit["body[$langcode][0][value]"] = $this->randomName(16);
- $this->drupalPost('node/add/page', $edit, t('Save'));
-
- $node = $this->drupalGetNodeByTitle($edit["title"]);
- $elements = $this->xpath('//div[contains(@class,:class)]', array(':class' => 'submitted'));
- $this->assertEqual(count($elements), 1, 'Post information is displayed.');
- }
-
- function testPageNotPostInfo() {
-
- $edit = array();
- $edit['node_submitted'] = FALSE;
- $this->drupalPost('admin/structure/types/manage/page', $edit, t('Save content type'));
-
- $edit = array();
- $langcode = LANGUAGE_NONE;
- $edit["title"] = $this->randomName(8);
- $edit["body[$langcode][0][value]"] = $this->randomName(16);
- $this->drupalPost('node/add/page', $edit, t('Save'));
-
- $node = $this->drupalGetNodeByTitle($edit["title"]);
- $this->assertNoRaw('<span class="submitted">', 'Post information is not displayed.');
- }
- }
- class NodeRSSContentTestCase extends DrupalWebTestCase {
- public static function getInfo() {
- return array(
- 'name' => 'Node RSS Content',
- 'description' => 'Ensure that data added to nodes by other modules appears in RSS feeds.',
- 'group' => 'Node',
- );
- }
- function setUp() {
-
- parent::setUp('node_test');
-
-
-
- $user = $this->drupalCreateUser(array('bypass node access', 'access content', 'create article content'));
- $this->drupalLogin($user);
- }
-
- function testNodeRSSContent() {
-
- $node = $this->drupalCreateNode(array('type' => 'article', 'promote' => 1));
- $this->drupalGet('rss.xml');
-
- $rss_only_content = t('Extra data that should appear only in the RSS feed for node !nid.', array('!nid' => $node->nid));
- $this->assertText($rss_only_content, 'Node content designated for RSS appear in RSS feed.');
-
-
- $non_rss_content = t('Extra data that should appear everywhere except the RSS feed for node !nid.', array('!nid' => $node->nid));
- $this->assertNoText($non_rss_content, 'Node content not designed for RSS doesn\'t appear in RSS feed.');
-
- $test_element = array(
- 'key' => 'testElement',
- 'value' => t('Value of testElement RSS element for node !nid.', array('!nid' => $node->nid)),
- );
- $test_ns = 'xmlns:drupaltest="http://example.com/test-namespace"';
- $this->assertRaw(format_xml_elements(array($test_element)), 'Extra RSS elements appear in RSS feed.');
- $this->assertRaw($test_ns, 'Extra namespaces appear in RSS feed.');
-
-
- $this->drupalGet("node/$node->nid");
- $this->assertNoText($rss_only_content, 'Node content designed for RSS doesn\'t appear when viewing node.');
-
-
- $this->drupalGet('rss.xml/' . $this->randomName() . '/' . $this->randomName());
- $this->assertText($rss_only_content, 'Ignore page arguments when delivering rss.xml.');
- }
- }
- class NodeAccessTestCase extends DrupalWebTestCase {
- public static function getInfo() {
- return array(
- 'name' => 'Node access',
- 'description' => 'Test node_access function',
- 'group' => 'Node',
- );
- }
-
- function assertNodeAccess($ops, $node, $account) {
- foreach ($ops as $op => $result) {
- $msg = format_string("node_access returns @result with operation '@op'.", array('@result' => $result ? 'true' : 'false', '@op' => $op));
- $this->assertEqual($result, node_access($op, $node, $account), $msg);
- }
- }
- function setUp() {
- parent::setUp();
-
- db_delete('role_permission')
- ->condition('rid', DRUPAL_AUTHENTICATED_RID)
- ->execute();
- }
-
- function testNodeAccess() {
-
- $web_user1 = $this->drupalCreateUser(array('create page content', 'edit any page content', 'delete any page content'));
- $node1 = $this->drupalCreateNode(array('type' => 'page'));
- $this->assertNodeAccess(array('create' => FALSE), 'page', $web_user1);
- $this->assertNodeAccess(array('view' => FALSE, 'update' => FALSE, 'delete' => FALSE), $node1, $web_user1);
-
- $web_user2 = $this->drupalCreateUser(array('bypass node access'));
- $node2 = $this->drupalCreateNode(array('type' => 'page'));
- $this->assertNodeAccess(array('create' => TRUE), 'page', $web_user2);
- $this->assertNodeAccess(array('view' => TRUE, 'update' => TRUE, 'delete' => TRUE), $node2, $web_user2);
-
- $web_user3 = $this->drupalCreateUser(array('access content'));
- $node3 = $this->drupalCreateNode(array('status' => 0, 'uid' => $web_user3->uid));
- $this->assertNodeAccess(array('view' => FALSE), $node3, $web_user3);
-
- $this->assertNodeAccess(array('create' => FALSE), 'page', $web_user3);
-
- $web_user4 = $this->drupalCreateUser(array('access content', 'view own unpublished content'));
- $web_user5 = $this->drupalCreateUser(array('access content', 'view own unpublished content'));
- $node4 = $this->drupalCreateNode(array('status' => 0, 'uid' => $web_user4->uid));
- $this->assertNodeAccess(array('view' => TRUE, 'update' => FALSE), $node4, $web_user4);
- $this->assertNodeAccess(array('view' => FALSE), $node4, $web_user5);
-
- $node5 = $this->drupalCreateNode();
- $this->assertNodeAccess(array('view' => TRUE, 'update' => FALSE, 'delete' => FALSE), $node5, $web_user3);
- }
- }
- class NodeAccessRecordsTestCase extends DrupalWebTestCase {
- public static function getInfo() {
- return array(
- 'name' => 'Node access records',
- 'description' => 'Test hook_node_access_records when acquiring grants.',
- 'group' => 'Node',
- );
- }
- function setUp() {
-
-
-
- parent::setUp('node_test');
- }
-
- function testNodeAccessRecords() {
-
- $node1 = $this->drupalCreateNode(array('type' => 'article'));
- $this->assertTrue(node_load($node1->nid), 'Article node created.');
-
- $records = db_query('SELECT realm, gid FROM {node_access} WHERE nid = :nid', array(':nid' => $node1->nid))->fetchAll();
- $this->assertEqual(count($records), 1, 'Returned the correct number of rows.');
- $this->assertEqual($records[0]->realm, 'test_article_realm', 'Grant with article_realm acquired for node without alteration.');
- $this->assertEqual($records[0]->gid, 1, 'Grant with gid = 1 acquired for node without alteration.');
-
- $node2 = $this->drupalCreateNode(array('type' => 'page', 'promote' => 0));
- $this->assertTrue(node_load($node2->nid), 'Unpromoted basic page node created.');
-
- $records = db_query('SELECT realm, gid FROM {node_access} WHERE nid = :nid', array(':nid' => $node2->nid))->fetchAll();
- $this->assertEqual(count($records), 1, 'Returned the correct number of rows.');
- $this->assertEqual($records[0]->realm, 'test_page_realm', 'Grant with page_realm acquired for node without alteration.');
- $this->assertEqual($records[0]->gid, 1, 'Grant with gid = 1 acquired for node without alteration.');
-
- $node3 = $this->drupalCreateNode(array('type' => 'page', 'promote' => 0, 'status' => 0));
- $this->assertTrue(node_load($node3->nid), 'Unpromoted, unpublished basic page node created.');
-
- $records = db_query('SELECT realm, gid FROM {node_access} WHERE nid = :nid', array(':nid' => $node3->nid))->fetchAll();
- $this->assertEqual(count($records), 1, 'Returned the correct number of rows.');
- $this->assertEqual($records[0]->realm, 'test_page_realm', 'Grant with page_realm acquired for node without alteration.');
- $this->assertEqual($records[0]->gid, 1, 'Grant with gid = 1 acquired for node without alteration.');
-
- $node4 = $this->drupalCreateNode(array('type' => 'page', 'promote' => 1));
- $this->assertTrue(node_load($node4->nid), 'Promoted basic page node created.');
-
-
- $records = db_query('SELECT realm, gid FROM {node_access} WHERE nid = :nid', array(':nid' => $node4->nid))->fetchAll();
- $this->assertEqual(count($records), 1, 'Returned the correct number of rows.');
- $this->assertEqual($records[0]->realm, 'test_alter_realm', 'Altered grant with alter_realm acquired for node.');
- $this->assertEqual($records[0]->gid, 2, 'Altered grant with gid = 2 acquired for node.');
-
- $operations = array('view', 'update', 'delete');
-
- $web_user = $this->drupalCreateUser(array('access content'));
- foreach ($operations as $op) {
- $grants = node_test_node_grants($op, $web_user);
- $altered_grants = $grants;
- drupal_alter('node_grants', $altered_grants, $web_user, $op);
- $this->assertNotEqual($grants, $altered_grants, format_string('Altered the %op grant for a user.', array('%op' => $op)));
- }
-
-
- $node6 = $this->drupalCreateNode(array('status' => 0, 'disable_node_access' => TRUE));
- $records = db_query('SELECT realm, gid FROM {node_access} WHERE nid = :nid', array(':nid' => $node6->nid))->fetchAll();
- $this->assertEqual(count($records), 0, 'Returned no records for unpublished node.');
- }
- }
- class NodeAccessBaseTableTestCase extends DrupalWebTestCase {
- public static function getInfo() {
- return array(
- 'name' => 'Node Access on any table',
- 'description' => 'Checks behavior of the node access subsystem if the base table is not node.',
- 'group' => 'Node',
- );
- }
- public function setUp() {
- parent::setUp('node_access_test');
- node_access_rebuild();
- variable_set('node_access_test_private', TRUE);
- }
-
- function testNodeAccessBasic() {
- $num_simple_users = 2;
- $simple_users = array();
-
- $this->nodesByUser = array();
- $titles = array();
- $private_nodes = array();
- for ($i = 0; $i < $num_simple_users; $i++) {
- $simple_users[$i] = $this->drupalCreateUser(array('access content', 'create article content'));
- }
- foreach ($simple_users as $this->webUser) {
- $this->drupalLogin($this->webUser);
- foreach (array(0 => 'Public', 1 => 'Private') as $is_private => $type) {
- $edit = array(
- 'title' => t('@private_public Article created by @user', array('@private_public' => $type, '@user' => $this->webUser->name)),
- );
- if ($is_private) {
- $edit['private'] = TRUE;
- $edit['body[und][0][value]'] = 'private node';
- $edit['field_tags[und]'] = 'private';
- }
- else {
- $edit['body[und][0][value]'] = 'public node';
- $edit['field_tags[und]'] = 'public';
- }
- $this->drupalPost('node/add/article', $edit, t('Save'));
- $nid = db_query('SELECT nid FROM {node} WHERE title = :title', array(':title' => $edit['title']))->fetchField();
- $private_status = db_query('SELECT private FROM {node_access_test} where nid = :nid', array(':nid' => $nid))->fetchField();
- $this->assertTrue($is_private == $private_status, 'The private status of the node was properly set in the node_access_test table.');
- if ($is_private) {
- $private_nodes[] = $nid;
- }
- $titles[$nid] = $edit['title'];
- $this->nodesByUser[$this->webUser->uid][$nid] = $is_private;
- }
- }
- $this->publicTid = db_query('SELECT tid FROM {taxonomy_term_data} WHERE name = :name', array(':name' => 'public'))->fetchField();
- $this->privateTid = db_query('SELECT tid FROM {taxonomy_term_data} WHERE name = :name', array(':name' => 'private'))->fetchField();
- $this->assertTrue($this->publicTid, 'Public tid was found');
- $this->assertTrue($this->privateTid, 'Private tid was found');
- foreach ($simple_users as $this->webUser) {
- $this->drupalLogin($this->webUser);
-
- foreach ($this->nodesByUser as $uid => $data) {
- foreach ($data as $nid => $is_private) {
- $this->drupalGet('node/' . $nid);
- if ($is_private) {
- $should_be_visible = $uid == $this->webUser->uid;
- }
- else {
- $should_be_visible = TRUE;
- }
- $this->assertResponse($should_be_visible ? 200 : 403, strtr('A %private node by user %uid is %visible for user %current_uid.', array(
- '%private' => $is_private ? 'private' : 'public',
- '%uid' => $uid,
- '%visible' => $should_be_visible ? 'visible' : 'not visible',
- '%current_uid' => $this->webUser->uid,
- )));
- }
- }
-
-
- $this->assertTaxonomyPage(FALSE);
- }
-
- $access_user = $this->drupalCreateUser(array('access content', 'create article content', 'node test view', 'search content'));
- $this->drupalLogin($access_user);
- foreach ($this->nodesByUser as $uid => $private_status) {
- foreach ($private_status as $nid => $is_private) {
- $this->drupalGet('node/' . $nid);
- $this->assertResponse(200);
- }
- }
-
-
- $this->assertTaxonomyPage(TRUE);
- }
-
- protected function assertTaxonomyPage($is_admin) {
- foreach (array($this->publicTid, $this->privateTid) as $tid_is_private => $tid) {
- $this->drupalGet("taxonomy/term/$tid");
- $this->nids_visible = array();
- foreach ($this->xpath("//a[text()='Read more']") as $link) {
- $this->assertTrue(preg_match('|node/(\d+)$|', (string) $link['href'], $matches), 'Read more points to a node');
- $this->nids_visible[$matches[1]] = TRUE;
- }
- foreach ($this->nodesByUser as $uid => $data) {
- foreach ($data as $nid => $is_private) {
-
-
- $should_be_visible = $tid_is_private == $is_private;
-
-
- if (!$is_admin && $tid_is_private) {
- $should_be_visible = $should_be_visible && $uid == $this->webUser->uid;
- }
- $this->assertIdentical(isset($this->nids_visible[$nid]), $should_be_visible, strtr('A %private node by user %uid is %visible for user %current_uid on the %tid_is_private page.', array(
- '%private' => $is_private ? 'private' : 'public',
- '%uid' => $uid,
- '%visible' => isset($this->nids_visible[$nid]) ? 'visible' : 'not visible',
- '%current_uid' => $this->webUser->uid,
- '%tid_is_private' => $tid_is_private ? 'private' : 'public',
- )));
- }
- }
- }
- }
- }
- class NodeSaveTestCase extends DrupalWebTestCase {
- public static function getInfo() {
- return array(
- 'name' => 'Node save',
- 'description' => 'Test node_save() for saving content.',
- 'group' => 'Node',
- );
- }
- function setUp() {
- parent::setUp('node_test');
-
- $web_user = $this->drupalCreateUser(array('create article content'));
- $this->drupalLogin($web_user);
- $this->web_user = $web_user;
- }
-
- function testImport() {
-
- $max_nid = db_query('SELECT MAX(nid) FROM {node}')->fetchField();
- $test_nid = $max_nid + mt_rand(1000, 1000000);
- $title = $this->randomName(8);
- $node = array(
- 'title' => $title,
- 'body' => array(LANGUAGE_NONE => array(array('value' => $this->randomName(32)))),
- 'uid' => $this->web_user->uid,
- 'type' => 'article',
- 'nid' => $test_nid,
- 'is_new' => TRUE,
- );
- $node = node_submit((object) $node);
-
- $this->assertEqual($node->uid, $this->web_user->uid, 'Function node_submit() preserves user ID');
- node_save($node);
-
- $node_by_nid = node_load($test_nid);
- $this->assertTrue($node_by_nid, 'Node load by node ID.');
- $node_by_title = $this->drupalGetNodeByTitle($title);
- $this->assertTrue($node_by_title, 'Node load by node title.');
- }
-
- function testTimestamps() {
-
- $edit = array(
- 'uid' => $this->web_user->uid,
- 'type' => 'article',
- 'title' => $this->randomName(8),
- );
- node_save((object) $edit);
- $node = $this->drupalGetNodeByTitle($edit['title']);
- $this->assertEqual($node->created, REQUEST_TIME, 'Creating a node sets default "created" timestamp.');
- $this->assertEqual($node->changed, REQUEST_TIME, 'Creating a node sets default "changed" timestamp.');
-
- $created = $node->created;
- $changed = $node->changed;
- node_save($node);
- $node = $this->drupalGetNodeByTitle($edit['title'], TRUE);
- $this->assertEqual($node->created, $created, 'Updating a node preserves "created" timestamp.');
-
- $node->title = 'testing_node_presave';
- node_save($node);
- $node = $this->drupalGetNodeByTitle('testing_node_presave', TRUE);
- $this->assertEqual($node->created, 280299600, 'Saving a node uses "created" timestamp set in presave hook.');
- $this->assertEqual($node->changed, 979534800, 'Saving a node uses "changed" timestamp set in presave hook.');
-
- $edit = array(
- 'uid' => $this->web_user->uid,
- 'type' => 'article',
- 'title' => $this->randomName(8),
- 'created' => 280299600,
- 'changed' => 979534800,
- );
- node_save((object) $edit);
- $node = $this->drupalGetNodeByTitle($edit['title']);
- $this->assertEqual($node->created, 280299600, 'Creating a node uses user-set "created" timestamp.');
- $this->assertNotEqual($node->changed, 979534800, 'Creating a node doesn\'t use user-set "changed" timestamp.');
-
- $node->created = 979534800;
- $node->changed = 280299600;
- node_save($node);
- $node = $this->drupalGetNodeByTitle($edit['title'], TRUE);
- $this->assertEqual($node->created, 979534800, 'Updating a node uses user-set "created" timestamp.');
- $this->assertNotEqual($node->changed, 280299600, 'Updating a node doesn\'t use user-set "changed" timestamp.');
- }
-
- function testDeterminingChanges() {
-
- $node = (object) array(
- 'uid' => $this->web_user->uid,
- 'type' => 'article',
- 'title' => 'test_changes',
- );
- node_save($node);
-
- node_save($node);
- $this->assertEqual($node->title, 'test_changes', 'No changes have been determined.');
-
- $node->title = 'updated';
- node_save($node);
-
-
- $this->assertEqual($node->title, 'updated_presave_update', 'Changes have been determined.');
-
- $node = node_load($node->nid);
- $this->assertEqual($node->title, 'updated_presave', 'Static cache has been cleared.');
- }
-
- function testNodeSaveOnInsert() {
-
-
- $node = $this->drupalCreateNode(array('title' => 'new'));
- $this->assertEqual($node->title, 'Node ' . $node->nid, 'Node saved on node insert.');
- }
- }
- class NodeTypeTestCase extends DrupalWebTestCase {
- public static function getInfo() {
- return array(
- 'name' => 'Node types',
- 'description' => 'Ensures that node type functions work correctly.',
- 'group' => 'Node',
- );
- }
-
- function testNodeTypeGetFunctions() {
- $node_types = node_type_get_types();
- $node_names = node_type_get_names();
- $this->assertTrue(isset($node_types['article']), 'Node type article is available.');
- $this->assertTrue(isset($node_types['page']), 'Node type basic page is available.');
- $this->assertEqual($node_types['article']->name, $node_names['article'], 'Correct node type base has been returned.');
- $this->assertEqual($node_types['article'], node_type_get_type('article'), 'Correct node type has been returned.');
- $this->assertEqual($node_types['article']->name, node_type_get_name('article'), 'Correct node type name has been returned.');
- $this->assertEqual($node_types['page']->base, node_type_get_base('page'), 'Correct node type base has been returned.');
- }
-
- function testNodeTypeCreation() {
-
- $type = $this->drupalCreateContentType();
- $type_exists = db_query('SELECT 1 FROM {node_type} WHERE type = :type', array(':type' => $type->type))->fetchField();
- $this->assertTrue($type_exists, 'The new content type has been created in the database.');
-
- $web_user = $this->drupalCreateUser(array('create ' . $type->name . ' content'));
- $this->drupalLogin($web_user);
- $this->drupalGet('node/add/' . str_replace('_', '-', $type->name));
- $this->assertResponse(200, 'The new content type can be accessed at node/add.');
-
- $web_user = $this->drupalCreateUser(array('bypass node access', 'administer content types'));
- $this->drupalLogin($web_user);
- $edit = array(
- 'name' => 'foo',
- 'title_label' => 'title for foo',
- 'type' => 'foo',
- );
- $this->drupalPost('admin/structure/types/add', $edit, t('Save content type'));
- $type_exists = db_query('SELECT 1 FROM {node_type} WHERE type = :type', array(':type' => 'foo'))->fetchField();
- $this->assertTrue($type_exists, 'The new content type has been created in the database.');
- }
-
- function testNodeTypeEditing() {
- $web_user = $this->drupalCreateUser(array('bypass node access', 'administer content types', 'administer fields'));
- $this->drupalLogin($web_user);
- $instance = field_info_instance('node', 'body', 'page');
- $this->assertEqual($instance['label'], 'Body', 'Body field was found.');
-
- $this->drupalGet('node/add/page');
- $this->assertRaw('Title', 'Title field was found.');
- $this->assertRaw('Body', 'Body field was found.');
-
- $edit = array(
- 'title_label' => 'Foo',
- );
- $this->drupalPost('admin/structure/types/manage/page', $edit, t('Save content type'));
-
- field_info_cache_clear();
- $this->drupalGet('node/add/page');
- $this->assertRaw('Foo', 'New title label was displayed.');
- $this->assertNoRaw('Title', 'Old title label was not displayed.');
-
- $edit = array(
- 'name' => 'Bar',
- 'type' => 'bar',
- 'description' => 'Lorem ipsum.',
- );
- $this->drupalPost('admin/structure/types/manage/page', $edit, t('Save content type'));
- field_info_cache_clear();
- $this->drupalGet('node/add');
- $this->assertRaw('Bar', 'New name was displayed.');
- $this->assertRaw('Lorem ipsum', 'New description was displayed.');
- $this->clickLink('Bar');
- $this->assertEqual(url('node/add/bar', array('absolute' => TRUE)), $this->getUrl(), 'New machine name was used in URL.');
- $this->assertRaw('Foo', 'Title field was found.');
- $this->assertRaw('Body', 'Body field was found.');
-
- $this->drupalPost('admin/structure/types/manage/bar/fields/body/delete', NULL, t('Delete'));
-
- $this->drupalPost('admin/structure/types/manage/bar', array(), t('Save content type'));
-
- $this->drupalGet('node/add/bar');
- $this->assertNoRaw('Body', 'Body field was not found.');
- }
-
- function testNodeTypeStatus() {
-
- module_enable(array('blog', 'book', 'poll'), FALSE);
- node_types_rebuild();
- $types = node_type_get_types();
- foreach (array('blog', 'book', 'poll', 'article', 'page') as $type) {
- $this->assertTrue(isset($types[$type]), format_string('%type is found in node types.', array('%type' => $type)));
- $this->assertTrue(isset($types[$type]->disabled) && empty($types[$type]->disabled), format_string('%type type is enabled.', array('%type' => $type)));
- }
-
- module_disable(array('poll'), FALSE);
- node_types_rebuild();
- $types = node_type_get_types();
- $this->assertTrue(!empty($types['poll']->disabled), "Poll module's node type disabled.");
- $this->assertTrue(isset($types['blog']) && empty($types['blog']->disabled), "Blog module's node type still active.");
-
- module_disable(array('blog'), FALSE);
- node_types_rebuild();
- $types = node_type_get_types();
- $this->assertTrue(!empty($types['blog']->disabled), "Blog module's node type disabled.");
- $this->assertTrue(!empty($types['poll']->disabled), "Poll module's node type still disabled.");
-
-
- module_disable(array('book'), FALSE);
- node_types_rebuild();
- $types = node_type_get_types();
- $this->assertTrue(isset($types['book']) && empty($types['book']->disabled), "Book module's node type still active.");
- $this->assertTrue(!empty($types['blog']->disabled), "Blog module's node type still disabled.");
- $this->assertTrue(!empty($types['poll']->disabled), "Poll module's node type still disabled.");
- $this->assertTrue(isset($types['article']) && empty($types['article']->disabled), "Article node type still active.");
- $this->assertTrue(isset($types['page']) && empty($types['page']->disabled), "Basic page node type still active.");
-
- module_enable(array('blog', 'book', 'poll'), FALSE);
- node_types_rebuild();
- $types = node_type_get_types();
- foreach (array('blog', 'book', 'poll', 'article', 'page') as $type) {
- $this->assertTrue(isset($types[$type]), format_string('%type is found in node types.', array('%type' => $type)));
- $this->assertTrue(isset($types[$type]->disabled) && empty($types[$type]->disabled), format_string('%type type is enabled.', array('%type' => $type)));
- }
- }
- }
- class NodeTypePersistenceTestCase extends DrupalWebTestCase {
- public static function getInfo() {
- return array(
- 'name' => 'Node type persist',
- 'description' => 'Ensures that node type customization survives module enabling and disabling.',
- 'group' => 'Node',
- );
- }
-
- function testNodeTypeCustomizationPersistence() {
- $web_user = $this->drupalCreateUser(array('bypass node access', 'administer content types', 'administer modules'));
- $this->drupalLogin($web_user);
- $poll_key = 'modules[Core][poll][enable]';
- $poll_enable = array($poll_key => "1");
- $poll_disable = array($poll_key => FALSE);
-
-
- $this->drupalPost('admin/modules', $poll_enable, t('Save configuration'));
- $disabled = db_query('SELECT disabled FROM {node_type} WHERE type = :type', array(':type' => 'poll'))->fetchField();
- $this->assertNotIdentical($disabled, FALSE, 'Poll node type found in the database');
- $this->assertEqual($disabled, 0, 'Poll node type is not disabled');
-
- $this->drupalGet('node/add');
- $this->assertText('poll', 'poll type is found on node/add');
-
- $description = $this->randomName();
- $edit = array('description' => $description);
- $this->drupalPost('admin/structure/types/manage/poll', $edit, t('Save content type'));
-
- $this->drupalGet('node/add');
- $this->assertText($description, 'Customized description found');
-
- $this->drupalPost('admin/modules', $poll_disable, t('Save configuration'));
- $disabled = db_query('SELECT disabled FROM {node_type} WHERE type = :type', array(':type' => 'poll'))->fetchField();
- $this->assertEqual($disabled, 1, 'Poll node type is disabled');
- $this->drupalGet('node/add');
- $this->assertNoText('poll', 'poll type is not found on node/add');
-
-
- $this->drupalPost('admin/modules', $poll_enable, t('Save configuration'));
- $disabled = db_query('SELECT disabled FROM {node_type} WHERE type = :type', array(':type' => 'poll'))->fetchField();
- $this->assertNotIdentical($disabled, FALSE, 'Poll node type found in the database');
- $this->assertEqual($disabled, 0, 'Poll node type is not disabled');
- $this->drupalGet('node/add');
- $this->assertText($description, 'Customized description found');
-
- $this->drupalPost('admin/modules', $poll_disable, t('Save configuration'));
- $edit = array('uninstall[poll]' => 'poll');
- $this->drupalPost('admin/modules/uninstall', $edit, t('Uninstall'));
- $this->drupalPost(NULL, array(), t('Uninstall'));
- $disabled = db_query('SELECT disabled FROM {node_type} WHERE type = :type', array(':type' => 'poll'))->fetchField();
- $this->assertTrue($disabled, 'Poll node type is in the database and is disabled');
- $this->drupalGet('node/add');
- $this->assertNoText('poll', 'poll type is no longer found on node/add');
-
-
- $this->drupalPost('admin/modules', $poll_enable, t('Save configuration'));
- $this->drupalGet('node/add');
- $this->assertText($description, 'Customized description is found even after uninstall and reenable.');
- }
- }
- class NodeAccessRebuildTestCase extends DrupalWebTestCase {
- public static function getInfo() {
- return array(
- 'name' => 'Node access rebuild',
- 'description' => 'Ensures that node access rebuild functions work correctly.',
- 'group' => 'Node',
- );
- }
- function setUp() {
- parent::setUp();
- $web_user = $this->drupalCreateUser(array('administer site configuration', 'access administration pages', 'access site reports'));
- $this->drupalLogin($web_user);
- $this->web_user = $web_user;
- }
-
- function testNodeAccessRebuild() {
- $this->drupalGet('admin/reports/status');
- $this->clickLink(t('Rebuild permissions'));
- $this->drupalPost(NULL, array(), t('Rebuild permissions'));
- $this->assertText(t('Content permissions have been rebuilt.'));
- }
- }
- class NodeAdminTestCase extends DrupalWebTestCase {
- public static function getInfo() {
- return array(
- 'name' => 'Node administration',
- 'description' => 'Test node administration page functionality.',
- 'group' => 'Node',
- );
- }
- function setUp() {
- parent::setUp();
-
-
-
- user_role_revoke_permissions(DRUPAL_AUTHENTICATED_RID, array('view own unpublished content'));
- $this->admin_user = $this->drupalCreateUser(array('access administration pages', 'access content overview', 'administer nodes', 'bypass node access'));
- $this->base_user_1 = $this->drupalCreateUser(array('access content overview'));
- $this->base_user_2 = $this->drupalCreateUser(array('access content overview', 'view own unpublished content'));
- $this->base_user_3 = $this->drupalCreateUser(array('access content overview', 'bypass node access'));
- }
-
- function testContentAdminSort() {
- $this->drupalLogin($this->admin_user);
- foreach (array('dd', 'aa', 'DD', 'bb', 'cc', 'CC', 'AA', 'BB') as $prefix) {
- $this->drupalCreateNode(array('title' => $prefix . $this->randomName(6)));
- }
-
- $nodes_query = db_select('node', 'n')
- ->fields('n', array('nid'))
- ->orderBy('changed', 'DESC')
- ->execute()
- ->fetchCol();
- $nodes_form = array();
- $this->drupalGet('admin/content');
- foreach ($this->xpath('//table/tbody/tr/td/div/input/@value') as $input) {
- $nodes_form[] = $input;
- }
- $this->assertEqual($nodes_query, $nodes_form, 'Nodes are sorted in the form according to the default query.');
-
-
- $nodes_query = db_select('node', 'n')
- ->fields('n', array('nid'))
- ->orderBy('title')
- ->execute()
- ->fetchCol();
- $nodes_form = array();
- $this->drupalGet('admin/content', array('query' => array('sort' => 'asc', 'order' => 'Title')));
- foreach ($this->xpath('//table/tbody/tr/td/div/input/@value') as $input) {
- $nodes_form[] = $input;
- }
- $this->assertEqual($nodes_query, $nodes_form, 'Nodes are sorted in the form the same as they are in the query.');
- }
-
- function testContentAdminPages() {
- $this->drupalLogin($this->admin_user);
- $nodes['published_page'] = $this->drupalCreateNode(array('type' => 'page'));
- $nodes['published_article'] = $this->drupalCreateNode(array('type' => 'article'));
- $nodes['unpublished_page_1'] = $this->drupalCreateNode(array('type' => 'page', 'uid' => $this->base_user_1->uid, 'status' => 0));
- $nodes['unpublished_page_2'] = $this->drupalCreateNode(array('type' => 'page', 'uid' => $this->base_user_2->uid, 'status' => 0));
-
- $this->drupalGet('admin/content');
- $this->assertResponse(200);
- foreach ($nodes as $node) {
- $this->assertLinkByHref('node/' . $node->nid);
- $this->assertLinkByHref('node/' . $node->nid . '/edit');
- $this->assertLinkByHref('node/' . $node->nid . '/delete');
-
- $this->assertFieldByName('nodes[' . $node->nid . ']', '', 'Tableselect found.');
- }
-
- $edit = array(
- 'status' => 'status-1',
- );
- $this->drupalPost(NULL, $edit, t('Filter'));
- $this->assertRaw(t('where %property is %value', array('%property' => t('status'), '%value' => 'published')), 'Content list is filtered by status.');
- $this->assertLinkByHref('node/' . $nodes['published_page']->nid . '/edit');
- $this->assertLinkByHref('node/' . $nodes['published_article']->nid . '/edit');
- $this->assertNoLinkByHref('node/' . $nodes['unpublished_page_1']->nid . '/edit');
-
- $edit = array(
- 'type' => 'page',
- );
- $this->drupalPost(NULL, $edit, t('Refine'));
- $this->assertRaw(t('where %property is %value', array('%property' => t('status'), '%value' => 'published')), 'Content list is filtered by status.');
- $this->assertRaw(t('and where %property is %value', array('%property' => t('type'), '%value' => 'Basic page')), 'Content list is filtered by content type.');
- $this->assertLinkByHref('node/' . $nodes['published_page']->nid . '/edit');
- $this->assertNoLinkByHref('node/' . $nodes['published_article']->nid . '/edit');
-
- $this->drupalLogout();
- $this->drupalLogin($this->base_user_1);
- $this->drupalGet('admin/content');
- $this->assertResponse(200);
- $this->assertLinkByHref('node/' . $nodes['published_page']->nid);
- $this->assertLinkByHref('node/' . $nodes['published_article']->nid);
- $this->assertNoLinkByHref('node/' . $nodes['published_page']->nid . '/edit');
- $this->assertNoLinkByHref('node/' . $nodes['published_page']->nid . '/delete');
- $this->assertNoLinkByHref('node/' . $nodes['published_article']->nid . '/edit');
- $this->assertNoLinkByHref('node/' . $nodes['published_article']->nid . '/delete');
-
- $this->assertNoLinkByHref('node/' . $nodes['unpublished_page_1']->nid);
- $this->assertNoLinkByHref('node/' . $nodes['unpublished_page_1']->nid . '/edit');
- $this->assertNoLinkByHref('node/' . $nodes['unpublished_page_1']->nid . '/delete');
-
- $this->assertNoFieldByName('nodes[' . $nodes['published_page']->nid . ']', '', 'No tableselect found.');
-
- $this->drupalLogout();
- $this->drupalLogin($this->base_user_2);
- $this->drupalGet('admin/content');
- $this->assertResponse(200);
- $this->assertLinkByHref('node/' . $nodes['unpublished_page_2']->nid);
-
- $this->assertNoLinkByHref('node/' . $nodes['unpublished_page_2']->nid . '/edit');
- $this->assertNoLinkByHref('node/' . $nodes['unpublished_page_2']->nid . '/delete');
-
- $this->assertNoLinkByHref('node/' . $nodes['unpublished_page_1']->nid);
- $this->assertNoLinkByHref('node/' . $nodes['unpublished_page_1']->nid . '/edit');
- $this->assertNoLinkByHref('node/' . $nodes['unpublished_page_1']->nid . '/delete');
-
- $this->assertNoFieldByName('nodes[' . $nodes['unpublished_page_2']->nid . ']', '', 'No tableselect found.');
-
- $this->drupalLogout();
- $this->drupalLogin($this->base_user_3);
- $this->drupalGet('admin/content');
- $this->assertResponse(200);
- foreach ($nodes as $node) {
- $this->assertLinkByHref('node/' . $node->nid);
- $this->assertLinkByHref('node/' . $node->nid . '/edit');
- $this->assertLinkByHref('node/' . $node->nid . '/delete');
- }
- }
- }
- class NodeTitleTestCase extends DrupalWebTestCase {
-
- protected $admin_user;
- public static function getInfo() {
- return array(
- 'name' => 'Node title',
- 'description' => 'Test node title.',
- 'group' => 'Node'
- );
- }
- function setUp() {
- parent::setUp();
- $this->admin_user = $this->drupalCreateUser(array('administer nodes', 'create article content', 'create page content'));
- $this->drupalLogin($this->admin_user);
- }
-
- function testNodeTitle() {
-
-
- $settings = array(
- 'title' => $this->randomName(8),
- 'promote' => 1,
- );
- $node = $this->drupalCreateNode($settings);
-
- $this->drupalGet("node/$node->nid");
- $xpath = '//title';
- $this->assertEqual(current($this->xpath($xpath)), $node->title .' | Drupal', 'Page title is equal to node title.', 'Node');
-
- $this->drupalGet("comment/reply/$node->nid");
- $xpath = '//div[@class="breadcrumb"]/a[last()]';
- $this->assertEqual(current($this->xpath($xpath)), $node->title, 'Node breadcrumb is equal to node title.', 'Node');
-
- $this->assertEqual(current($this->xpath('//div[@id=:id]/h2/a', array(':id' => 'node-' . $node->nid))), $node->title, 'Node preview title is equal to node title.', 'Node');
-
- $this->drupalGet('node');
- $this->clickLink($node->title);
- }
- }
- class NodeFeedTestCase extends DrupalWebTestCase {
- public static function getInfo() {
- return array(
- 'name' => 'Node feed',
- 'description' => 'Ensures that node_feed() functions correctly.',
- 'group' => 'Node',
- );
- }
-
- function testNodeFeedExtraChannelElements() {
- ob_start();
- node_feed(array(), array('copyright' => 'Drupal is a registered trademark of Dries Buytaert.'));
- $output = ob_get_clean();
- $this->assertTrue(strpos($output, '<copyright>Drupal is a registered trademark of Dries Buytaert.</copyright>') !== FALSE);
- }
- }
- class NodeBlockFunctionalTest extends DrupalWebTestCase {
- public static function getInfo() {
- return array(
- 'name' => 'Node blocks',
- 'description' => 'Test node block functionality.',
- 'group' => 'Node',
- );
- }
- function setUp() {
- parent::setUp('node', 'block');
-
- $this->admin_user = $this->drupalCreateUser(array('administer content types', 'administer nodes', 'administer blocks'));
- $this->web_user = $this->drupalCreateUser(array('access content', 'create article content'));
- }
-
- function testRecentNodeBlock() {
- $this->drupalLogin($this->admin_user);
-
- user_role_change_permissions(DRUPAL_ANONYMOUS_RID, array(
- 'access content' => FALSE,
- ));
-
- $edit = array(
- 'blocks[node_recent][region]' => 'sidebar_first',
- );
- $this->drupalPost('admin/structure/block', $edit, t('Save blocks'));
- $this->assertText(t('The block settings have been updated.'), 'Block saved to first sidebar region.');
-
- $block = array(
- 'title' => $this->randomName(),
- 'node_recent_block_count' => 2,
- );
- $this->drupalPost('admin/structure/block/manage/node/recent/configure', $block, t('Save block'));
- $this->assertText(t('The block configuration has been saved.'), 'Block saved.');
-
- $this->drupalGet('');
- $this->assertText(t('No content available.'), 'Block with "No content available." found.');
-
- $default_settings = array('uid' => $this->web_user->uid, 'type' => 'article');
- $node1 = $this->drupalCreateNode($default_settings);
- $node2 = $this->drupalCreateNode($default_settings);
- $node3 = $this->drupalCreateNode($default_settings);
-
- db_update('node')
- ->fields(array(
- 'changed' => $node1->changed + 100,
- ))
- ->condition('nid', $node2->nid)
- ->execute();
- db_update('node')
- ->fields(array(
- 'changed' => $node1->changed + 200,
- ))
- ->condition('nid', $node3->nid)
- ->execute();
-
-
- $this->drupalLogout();
- $this->drupalGet('');
- $this->assertNoText($block['title'], 'Block was not found.');
-
- $this->drupalLogin($this->web_user);
- $this->assertNoText($node1->title, 'Node not found in block.');
- $this->assertText($node2->title, 'Node found in block.');
- $this->assertText($node3->title, 'Node found in block.');
-
- $this->assertTrue($this->xpath('//div[@id="block-node-recent"]/div/table/tbody/tr[position() = 1]/td/div/a[text() = "' . $node3->title . '"]'), 'Nodes were ordered correctly in block.');
-
- $this->drupalLogout();
- $this->drupalLogin($this->admin_user);
- $block = array(
- 'node_recent_block_count' => 10,
- );
- $this->drupalPost('admin/structure/block/manage/node/recent/configure', $block, t('Save block'));
- $this->assertText(t('The block configuration has been saved.'), 'Block saved.');
-
- $node4 = $this->drupalCreateNode($default_settings);
-
- $this->drupalGet('');
- $this->assertText($node1->title, 'Node found in block.');
- $this->assertText($node2->title, 'Node found in block.');
- $this->assertText($node3->title, 'Node found in block.');
- $this->assertText($node4->title, 'Node found in block.');
-
- $custom_block = array();
- $custom_block['info'] = $this->randomName();
- $custom_block['title'] = $this->randomName();
- $custom_block['types[article]'] = TRUE;
- $custom_block['body[value]'] = $this->randomName(32);
- $custom_block['regions[' . variable_get('theme_default', 'bartik') . ']'] = 'content';
- if ($admin_theme = variable_get('admin_theme')) {
- $custom_block['regions[' . $admin_theme . ']'] = 'content';
- }
- $this->drupalPost('admin/structure/block/add', $custom_block, t('Save block'));
- $bid = db_query("SELECT bid FROM {block_custom} WHERE info = :info", array(':info' => $custom_block['info']))->fetchField();
- $this->assertTrue($bid, 'Custom block with visibility rule was created.');
-
- $this->drupalGet('');
- $this->assertNoText($custom_block['title'], 'Block was displayed on the front page.');
- $this->drupalGet('node/add/article');
- $this->assertText($custom_block['title'], 'Block was displayed on the node/add/article page.');
- $this->drupalGet('node/' . $node1->nid);
- $this->assertText($custom_block['title'], 'Block was displayed on the node/N.');
-
- $this->drupalPost('admin/structure/block/manage/block/' . $bid . '/delete', array(), t('Delete'));
- $bid = db_query("SELECT 1 FROM {block_node_type} WHERE module = 'block' AND delta = :delta", array(':delta' => $bid))->fetchField();
- $this->assertFalse($bid, 'Custom block was deleted.');
- }
- }
- class MultiStepNodeFormBasicOptionsTest extends DrupalWebTestCase {
- public static function getInfo() {
- return array(
- 'name' => 'Multistep node form basic options',
- 'description' => 'Test the persistence of basic options through multiple steps.',
- 'group' => 'Node',
- );
- }
- function setUp() {
- parent::setUp('poll');
- $web_user = $this->drupalCreateUser(array('administer nodes', 'create poll content'));
- $this->drupalLogin($web_user);
- }
-
- function testMultiStepNodeFormBasicOptions() {
- $edit = array(
- 'title' => 'a',
- 'status' => FALSE,
- 'promote' => FALSE,
- 'sticky' => 1,
- 'choice[new:0][chtext]' => 'a',
- 'choice[new:1][chtext]' => 'a',
- );
- $this->drupalPost('node/add/poll', $edit, t('More choices'));
- $this->assertNoFieldChecked('edit-status', 'status stayed unchecked');
- $this->assertNoFieldChecked('edit-promote', 'promote stayed unchecked');
- $this->assertFieldChecked('edit-sticky', 'sticky stayed checked');
- }
- }
- class NodeBuildContent extends DrupalWebTestCase {
- public static function getInfo() {
- return array(
- 'name' => 'Rebuild content',
- 'description' => 'Test the rebuilding of content for different build modes.',
- 'group' => 'Node',
- );
- }
-
- function testNodeRebuildContent() {
- $node = $this->drupalCreateNode();
-
- $node->content['test_content_property'] = array('#value' => $this->randomString());
- $content = node_build_content($node);
-
- $this->assertFalse(isset($content['test_content_property']), 'Node content was emptied prior to being built.');
- }
- }
- class NodeQueryAlter extends DrupalWebTestCase {
- public static function getInfo() {
- return array(
- 'name' => 'Node query alter',
- 'description' => 'Test that node access queries are properly altered by the node module.',
- 'group' => 'Node',
- );
- }
-
- protected $accessUser;
-
- protected $noAccessUser;
- function setUp() {
- parent::setUp('node_access_test');
- node_access_rebuild();
-
- $this->drupalCreateNode();
- $this->drupalCreateNode();
- $this->drupalCreateNode();
- $this->drupalCreateNode();
-
-
- $this->accessUser = $this->drupalCreateUser(array('access content overview', 'access content', 'node test view'));
- $this->noAccessUser = $this->drupalCreateUser(array('access content overview', 'access content'));
- $this->noAccessUser2 = $this->drupalCreateUser(array('access content overview', 'access content'));
- }
-
- function testNodeQueryAlterWithUI() {
-
- $this->drupalLogin($this->accessUser);
- $this->drupalGet('node_access_test_page');
- $this->assertText('Yes, 4 nodes', "4 nodes were found for access user");
- $this->assertNoText('Exception', "No database exception");
-
- $this->drupalGet('admin/content');
- $table_rows = $this->xpath('//tbody/tr');
- $this->assertEqual(4, count($table_rows), "4 nodes were found for access user");
-
- $this->drupalLogin($this->noAccessUser);
- $this->drupalGet('node_access_test_page');
- $this->assertText('No nodes', "No nodes were found for no access user");
- $this->assertNoText('Exception', "No database exception");
- $this->drupalGet('admin/content');
- $this->assertText(t('No content available.'));
- }
-
- function testNodeQueryAlterLowLevelWithAccess() {
-
- try {
- $query = db_select('node', 'mytab')
- ->fields('mytab');
- $query->addTag('node_access');
- $query->addMetaData('op', 'view');
- $query->addMetaData('account', $this->accessUser);
- $result = $query->execute()->fetchAll();
- $this->assertEqual(count($result), 4, 'User with access can see correct nodes');
- }
- catch (Exception $e) {
- $this->fail(t('Altered query is malformed'));
- }
- }
-
- function testNodeQueryAlterLowLevelNoAccess() {
-
- try {
- $query = db_select('node', 'mytab')
- ->fields('mytab');
- $query->addTag('node_access');
- $query->addMetaData('op', 'view');
- $query->addMetaData('account', $this->noAccessUser);
- $result = $query->execute()->fetchAll();
- $this->assertEqual(count($result), 0, 'User with no access cannot see nodes');
- }
- catch (Exception $e) {
- $this->fail(t('Altered query is malformed'));
- }
- }
-
- function testNodeQueryAlterLowLevelEditAccess() {
-
- try {
- $query = db_select('node', 'mytab')
- ->fields('mytab');
- $query->addTag('node_access');
- $query->addMetaData('op', 'update');
- $query->addMetaData('account', $this->accessUser);
- $result = $query->execute()->fetchAll();
- $this->assertEqual(count($result), 0, 'User with view-only access cannot edit nodes');
- }
- catch (Exception $e) {
- $this->fail($e->getMessage());
- $this->fail((string) $query);
- $this->fail(t('Altered query is malformed'));
- }
- }
-
- function testNodeQueryAlterOverride() {
- $record = array(
- 'nid' => 0,
- 'gid' => 0,
- 'realm' => 'node_access_all',
- 'grant_view' => 1,
- 'grant_update' => 0,
- 'grant_delete' => 0,
- );
- drupal_write_record('node_access', $record);
-
-
- drupal_static_reset('node_access_view_all_nodes');
- try {
- $query = db_select('node', 'mytab')
- ->fields('mytab');
- $query->addTag('node_access');
- $query->addMetaData('op', 'view');
- $query->addMetaData('account', $this->noAccessUser);
- $result = $query->execute()->fetchAll();
- $this->assertEqual(count($result), 0, 'User view privileges are not overridden');
- }
- catch (Exception $e) {
- $this->fail(t('Altered query is malformed'));
- }
-
-
-
-
-
- $this->drupalLogin($this->noAccessUser2);
- variable_set('node_test_node_access_all_uid', $this->noAccessUser->uid);
- drupal_static_reset('node_access_view_all_nodes');
- try {
- $query = db_select('node', 'mytab')
- ->fields('mytab');
- $query->addTag('node_access');
- $query->addMetaData('op', 'view');
- $query->addMetaData('account', $this->noAccessUser);
- $result = $query->execute()->fetchAll();
- $this->assertEqual(count($result), 4, 'User view privileges are overridden');
- }
- catch (Exception $e) {
- $this->fail(t('Altered query is malformed'));
- }
- variable_del('node_test_node_access_all_uid');
- }
- }
- class NodeEntityFieldQueryAlter extends DrupalWebTestCase {
- public static function getInfo() {
- return array(
- 'name' => 'Node entity query alter',
- 'description' => 'Test that node access entity queries are properly altered by the node module.',
- 'group' => 'Node',
- );
- }
-
- protected $accessUser;
-
- protected $noAccessUser;
- function setUp() {
- parent::setUp('node_access_test');
- node_access_rebuild();
-
-
-
- $settings = array('language' => LANGUAGE_NONE);
- for ($i = 0; $i < 4; $i++) {
- $body = array(
- 'value' => 'A' . $this->randomName(32),
- 'format' => filter_default_format(),
- );
- $settings['body'][LANGUAGE_NONE][0] = $body;
- $this->drupalCreateNode($settings);
- }
-
-
- $this->accessUser = $this->drupalCreateUser(array('access content', 'node test view'));
- $this->noAccessUser = $this->drupalCreateUser(array('access content'));
- }
-
- function testNodeQueryAlterWithUI() {
-
- $this->drupalLogin($this->accessUser);
- $this->drupalGet('node_access_entity_test_page');
- $this->assertText('Yes, 4 nodes', "4 nodes were found for access user");
- $this->assertNoText('Exception', "No database exception");
-
- $this->drupalLogin($this->noAccessUser);
- $this->drupalGet('node_access_entity_test_page');
- $this->assertText('No nodes', "No nodes were found for no access user");
- $this->assertNoText('Exception', "No database exception");
- }
- }
- class NodeTokenReplaceTestCase extends DrupalWebTestCase {
- public static function getInfo() {
- return array(
- 'name' => 'Node token replacement',
- 'description' => 'Generates text using placeholders for dummy content to check node token replacement.',
- 'group' => 'Node',
- );
- }
-
- function testNodeTokenReplacement() {
- global $language;
- $url_options = array(
- 'absolute' => TRUE,
- 'language' => $language,
- );
-
- $account = $this->drupalCreateUser();
- $settings = array(
- 'type' => 'article',
- 'uid' => $account->uid,
- 'title' => '<blink>Blinking Text</blink>',
- 'body' => array(LANGUAGE_NONE => array(array('value' => $this->randomName(32), 'summary' => $this->randomName(16)))),
- );
- $node = $this->drupalCreateNode($settings);
-
- $node = node_load($node->nid);
- $instance = field_info_instance('node', 'body', $node->type);
-
- $tests = array();
- $langcode = entity_language('node', $node);
- $tests['[node:nid]'] = $node->nid;
- $tests['[node:vid]'] = $node->vid;
- $tests['[node:tnid]'] = $node->tnid;
- $tests['[node:type]'] = 'article';
- $tests['[node:type-name]'] = 'Article';
- $tests['[node:title]'] = check_plain($node->title);
- $tests['[node:body]'] = _text_sanitize($instance, $langcode, $node->body[$langcode][0], 'value');
- $tests['[node:summary]'] = _text_sanitize($instance, $langcode, $node->body[$langcode][0], 'summary');
- $tests['[node:language]'] = check_plain($langcode);
- $tests['[node:url]'] = url('node/' . $node->nid, $url_options);
- $tests['[node:edit-url]'] = url('node/' . $node->nid . '/edit', $url_options);
- $tests['[node:author]'] = check_plain(format_username($account));
- $tests['[node:author:uid]'] = $node->uid;
- $tests['[node:author:name]'] = check_plain(format_username($account));
- $tests['[node:created:since]'] = format_interval(REQUEST_TIME - $node->created, 2, $language->language);
- $tests['[node:changed:since]'] = format_interval(REQUEST_TIME - $node->changed, 2, $language->language);
-
- $this->assertFalse(in_array(0, array_map('strlen', $tests)), 'No empty tokens generated.');
- foreach ($tests as $input => $expected) {
- $output = token_replace($input, array('node' => $node), array('language' => $language));
- $this->assertEqual($output, $expected, format_string('Sanitized node token %token replaced.', array('%token' => $input)));
- }
-
- $tests['[node:title]'] = $node->title;
- $tests['[node:body]'] = $node->body[$langcode][0]['value'];
- $tests['[node:summary]'] = $node->body[$langcode][0]['summary'];
- $tests['[node:language]'] = $langcode;
- $tests['[node:author:name]'] = format_username($account);
- foreach ($tests as $input => $expected) {
- $output = token_replace($input, array('node' => $node), array('language' => $language, 'sanitize' => FALSE));
- $this->assertEqual($output, $expected, format_string('Unsanitized node token %token replaced.', array('%token' => $input)));
- }
-
- $settings['body'] = array(LANGUAGE_NONE => array(array('value' => $this->randomName(32), 'summary' => '')));
- $node = $this->drupalCreateNode($settings);
-
-
- $node = node_load($node->nid);
- $instance = field_info_instance('node', 'body', $node->type);
-
- $tests = array();
- $tests['[node:summary]'] = _text_sanitize($instance, $langcode, $node->body[$langcode][0], 'value');
-
- $this->assertFalse(in_array(0, array_map('strlen', $tests)), 'No empty tokens generated for node without a summary.');
- foreach ($tests as $input => $expected) {
- $output = token_replace($input, array('node' => $node), array('language' => $language));
- $this->assertEqual($output, $expected, format_string('Sanitized node token %token replaced for node without a summary.', array('%token' => $input)));
- }
-
- $tests['[node:summary]'] = $node->body[$langcode][0]['value'];
- foreach ($tests as $input => $expected) {
- $output = token_replace($input, array('node' => $node), array('language' => $language, 'sanitize' => FALSE));
- $this->assertEqual($output, $expected, format_string('Unsanitized node token %token replaced for node without a summary.', array('%token' => $input)));
- }
- }
- }
- class NodeRevisionPermissionsTestCase extends DrupalWebTestCase {
-
- protected $node_revisions = array();
-
- protected $accounts = array();
-
- protected $map = array(
- 'view' => 'view revisions',
- 'update' => 'revert revisions',
- 'delete' => 'delete revisions',
- );
- public static function getInfo() {
- return array(
- 'name' => 'Node revision permissions',
- 'description' => 'Tests user permissions for node revision operations.',
- 'group' => 'Node',
- );
- }
- function setUp() {
- parent::setUp();
-
- $node = $this->drupalCreateNode();
- $this->node_revisions[] = $node;
- for ($i = 0; $i < 3; $i++) {
-
- $revision = clone $node;
- $revision->revision = 1;
- $revision->log = $this->randomName(32);
- node_save($revision);
- $this->node_revisions[] = $revision;
- }
-
- foreach ($this->map as $op => $permission) {
-
- $account = $this->drupalCreateUser(
- array(
- 'access content',
- 'edit any page content',
- 'delete any page content',
- $permission,
- )
- );
- $account->op = $op;
- $this->accounts[] = $account;
- }
-
- $admin_account = $this->drupalCreateUser(array('access content', 'administer nodes'));
- $admin_account->is_admin = TRUE;
- $this->accounts['admin'] = $admin_account;
-
- $normal_account = $this->drupalCreateUser();
- $normal_account->op = FALSE;
- $this->accounts[] = $normal_account;
- }
-
- function testNodeRevisionAccess() {
- $revision = $this->node_revisions[1];
- $parameters = array(
- 'op' => array_keys($this->map),
- 'account' => $this->accounts,
- );
- $permutations = $this->generatePermutations($parameters);
- foreach ($permutations as $case) {
- if (!empty($case['account']->is_admin) || $case['op'] == $case['account']->op) {
- $this->assertTrue(_node_revision_access($revision, $case['op'], $case['account']), "{$this->map[$case['op']]} granted.");
- }
- else {
- $this->assertFalse(_node_revision_access($revision, $case['op'], $case['account']), "{$this->map[$case['op']]} not granted.");
- }
- }
-
-
- $admin_account = $this->accounts['admin'];
- $this->assertFalse(_node_revision_access(FALSE, 'view', $admin_account), '_node_revision_access() returns FALSE with an invalid node.');
- $this->assertFalse(_node_revision_access($revision, 'invalid-op', $admin_account), '_node_revision_access() returns FALSE with an invalid op.');
-
- $original_user = $GLOBALS['user'];
- $GLOBALS['user'] = $admin_account;
- $this->assertTrue(_node_revision_access($revision, 'view'), '_node_revision_access() returns TRUE when used with global user.');
- $GLOBALS['user'] = $original_user;
- }
- }
- class NodeAccessPagerTestCase extends DrupalWebTestCase {
- public static function getInfo() {
- return array(
- 'name' => 'Node access pagination',
- 'description' => 'Test access controlled node views have the right amount of comment pages.',
- 'group' => 'Node',
- );
- }
- public function setUp() {
- parent::setUp('node_access_test', 'comment', 'forum');
- node_access_rebuild();
- $this->web_user = $this->drupalCreateUser(array('access content', 'access comments', 'node test view'));
- }
-
- public function testCommentPager() {
-
- $node = $this->drupalCreateNode();
-
- for ($i = 0; $i < 60; $i++) {
- $comment = new stdClass();
- $comment->cid = 0;
- $comment->pid = 0;
- $comment->uid = $this->web_user->uid;
- $comment->nid = $node->nid;
- $comment->subject = $this->randomName();
- $comment->comment_body = array(
- LANGUAGE_NONE => array(
- array('value' => $this->randomName()),
- ),
- );
- comment_save($comment);
- }
- $this->drupalLogin($this->web_user);
-
-
- $this->drupalGet('node/' . $node->nid);
- $this->assertText($node->title);
- $this->assertText(t('Comments'));
- $this->assertRaw('page=1');
- $this->assertNoRaw('page=2');
- }
-
- public function testForumPager() {
-
- $vid = variable_get('forum_nav_vocabulary', 0);
- $this->assertTrue($vid, 'Forum navigation vocabulary ID is set.');
-
- $tree = taxonomy_get_tree($vid, 0, 1);
- $tid = reset($tree)->tid;
- $this->assertTrue($tid, 'General discussion term is found in the forum vocabulary.');
-
- for ($i = 0; $i < 30; $i++) {
- $this->drupalCreateNode(array(
- 'nid' => NULL,
- 'type' => 'forum',
- 'taxonomy_forums' => array(
- LANGUAGE_NONE => array(
- array('tid' => $tid, 'vid' => $vid, 'vocabulary_machine_name' => 'forums'),
- ),
- ),
- ));
- }
-
-
- $this->drupalLogin($this->web_user);
- $this->drupalGet('forum/' . $tid);
- $this->assertRaw('page=1');
- $this->assertNoRaw('page=2');
- }
- }
- class NodeAccessFieldTestCase extends NodeWebTestCase {
- public static function getInfo() {
- return array(
- 'name' => 'Node access and fields',
- 'description' => 'Tests the interaction of the node access system with fields.',
- 'group' => 'Node',
- );
- }
- public function setUp() {
- parent::setUp('node_access_test', 'field_ui');
- node_access_rebuild();
-
- $this->admin_user = $this->drupalCreateUser(array('access content', 'bypass node access', 'administer fields'));
- $this->content_admin_user = $this->drupalCreateUser(array('access content', 'administer content types', 'administer fields'));
-
- $this->field_name = drupal_strtolower($this->randomName() . '_field_name');
- $this->field = field_create_field(array('field_name' => $this->field_name, 'type' => 'text'));
- $this->instance = field_create_instance(array(
- 'field_name' => $this->field_name,
- 'entity_type' => 'node',
- 'bundle' => 'page',
- ));
- }
-
- function testNodeAccessAdministerField() {
-
- $langcode = LANGUAGE_NONE;
- $field_data = array();
- $value = $field_data[$langcode][0]['value'] = $this->randomName();
- $node = $this->drupalCreateNode(array($this->field_name => $field_data));
-
- $this->drupalLogin($this->admin_user);
- $this->drupalGet("node/{$node->nid}");
- $this->assertText($value, 'The saved field value is visible to an administrator.');
-
- $this->drupalLogin($this->content_admin_user);
- $this->drupalGet("node/{$node->nid}");
- $this->assertText('Access denied', 'Access is denied for the content admin.');
-
- $edit = array();
- $default = 'Sometimes words have two meanings';
- $edit["{$this->field_name}[$langcode][0][value]"] = $default;
- $this->drupalPost(
- "admin/structure/types/manage/page/fields/{$this->field_name}",
- $edit,
- t('Save settings')
- );
-
- $this->drupalLogin($this->admin_user);
-
- $this->drupalGet("node/{$node->nid}");
- $this->assertText($value, 'The original field value is visible to an administrator.');
-
- $this->drupalGet('node/add/page');
- $this->assertRaw($default, 'The updated default value is displayed when creating a new node.');
- }
- }
- class NodeEntityViewModeAlterTest extends NodeWebTestCase {
- public static function getInfo() {
- return array(
- 'name' => 'Node entity view mode',
- 'description' => 'Test changing view mode.',
- 'group' => 'Node'
- );
- }
- function setUp() {
- parent::setUp(array('node_test'));
- }
-
- function testNodeViewModeChange() {
- $web_user = $this->drupalCreateUser(array('create page content', 'edit own page content'));
- $this->drupalLogin($web_user);
-
- $edit = array();
- $langcode = LANGUAGE_NONE;
- $edit["title"] = $this->randomName(8);
- $edit["body[$langcode][0][value]"] = 'Data that should appear only in the body for the node.';
- $edit["body[$langcode][0][summary]"] = 'Extra data that should appear only in the teaser for the node.';
- $this->drupalPost('node/add/page', $edit, t('Save'));
- $node = $this->drupalGetNodeByTitle($edit["title"]);
-
- variable_set('node_test_change_view_mode', 'teaser');
- $this->drupalGet('node/' . $node->nid);
-
- $this->assertText('Extra data that should appear only in the teaser for the node.', 'Teaser text present');
-
- $this->assertNoText('Data that should appear only in the body for the node.', 'Body text not present');
-
- $build = node_view($node);
- $this->assertEqual($build['#view_mode'], 'teaser', 'The view mode has correctly been set to teaser.');
- }
-
- function testNodeViewModeChangeHiddenField() {
-
- $instance = field_info_instance('node', 'field_tags', 'article');
- $instance['display']['default']['type'] = 'hidden';
- field_update_instance($instance);
- $web_user = $this->drupalCreateUser(array('create article content', 'edit own article content'));
- $this->drupalLogin($web_user);
-
- $edit = array();
- $langcode = LANGUAGE_NONE;
- $edit["title"] = $this->randomName(8);
- $edit["body[$langcode][0][value]"] = 'Data that should appear only in the body for the node.';
- $edit["body[$langcode][0][summary]"] = 'Extra data that should appear only in the teaser for the node.';
- $edit["field_tags[$langcode]"] = 'Extra tag';
- $this->drupalPost('node/add/article', $edit, t('Save'));
- $node = $this->drupalGetNodeByTitle($edit["title"]);
-
- variable_set('node_test_change_view_mode', 'teaser');
- $this->drupalGet('node/' . $node->nid);
-
- $this->assertText('Extra data that should appear only in the teaser for the node.', 'Teaser text present');
-
- $this->assertNoText('Data that should appear only in the body for the node.', 'Body text not present');
-
- $this->assertText('Extra tag', 'Taxonomy term present');
-
- $build = node_view($node);
- $this->assertEqual($build['#view_mode'], 'teaser', 'The view mode has correctly been set to teaser.');
- }
- }
- class NodePageCacheTest extends NodeWebTestCase {
-
- protected $admin_user;
- public static function getInfo() {
- return array(
- 'name' => 'Node page cache test',
- 'description' => 'Test cache invalidation of node operations.',
- 'group' => 'Node',
- );
- }
- function setUp() {
- parent::setUp();
- variable_set('cache', 1);
- variable_set('page_cache_maximum_age', 300);
- $this->admin_user = $this->drupalCreateUser(array(
- 'bypass node access',
- 'access content overview',
- 'administer nodes',
- ));
- }
-
- public function testNodeDelete() {
- $node_path = 'node/' . $this->drupalCreateNode()->nid;
-
- $this->drupalGet($node_path);
-
- $this->drupalLogin($this->admin_user);
- $this->drupalPost($node_path . '/delete', array(), t('Delete'));
-
- $this->drupalLogout();
- $this->drupalGet($node_path);
- $this->assertResponse(404);
-
- $nodes[0] = $this->drupalCreateNode();
- $nodes[1] = $this->drupalCreateNode();
- $node_path = 'node/' . $nodes[0]->nid;
-
- $this->drupalGet($node_path);
-
- $this->drupalLogin($this->admin_user);
- $this->drupalGet('admin/content');
- $edit = array(
- 'operation' => 'delete',
- 'nodes[' . $nodes[0]->nid . ']' => TRUE,
- 'nodes[' . $nodes[1]->nid . ']' => TRUE,
- );
- $this->drupalPost(NULL, $edit, t('Update'));
- $this->drupalPost(NULL, array(), t('Delete'));
-
- $this->drupalLogout();
- $this->drupalGet($node_path);
- $this->assertResponse(404);
- }
- }
- class NodeMultiByteUtf8Test extends NodeWebTestCase {
- public static function getInfo() {
- return array(
- 'name' => 'Multi-byte UTF-8',
- 'description' => 'Test that multi-byte UTF-8 characters are stored and retrieved correctly.',
- 'group' => 'Node',
- );
- }
-
- public function testMultiByteUtf8() {
- $connection = Database::getConnection();
-
-
- if (!($connection->utf8mb4IsSupported() && $connection->utf8mb4IsActive())) {
- return;
- }
- $title = '🐙';
- $this->assertTrue(drupal_strlen($title, 'utf-8') < strlen($title), 'Title has multi-byte characters.');
- $node = $this->drupalCreateNode(array('title' => $title));
- $this->drupalGet('node/' . $node->nid);
- $result = $this->xpath('//h1[@id="page-title"]');
- $this->assertEqual(trim((string) $result[0]), $title, 'The passed title was returned.');
- }
- }
|