Drupal7 Simple Test case in Custom Module

On12th Jul 2015, 2022-12-01T08:00:00+05:30 Read Pause Resume Stop
Drupal7 Simple Test case in Custom Module

Why to write test case? Very simple, in one word, Its waste of time and effort of checking something we changed in code and that effects other part, and to make sure every time what change we make that should not effect any other code, so this task can be done by our test cases

In this article, giving a simple test example to create a drupal test case

  • Create a new PHP class that defines a test
  • Provide Drupal with meta-data about your test
  • Run your test to see if it works

1. Start with creating a module

Create a module "Simple Test" inside sites/all/modules/custom/simple_test

Create simple_test.info with the below content

  name = Simple test  core = 7.x

Create simple_test.module with the below content

  <?php  function simple_test_menu() {    $items = array();    $items['simple_test'] = array(      'title' => 'Simple Test',      'access callback' => TRUE,      'page callback' => 'simple_test_page',      'type' => MENU_NORMAL_ITEM,      'menu' => 'navigation',    );    return $items;  }  function simple_test_page() {    return t('Welcome to Drupal. Its simple_test..!');  }

Goto the modules page admin/modules and enable the Simple Test module

Next goto the page which you created just now in the module /simple_test, you can see "Welcome to Drupal. Its simple_test..!" this test which you have returned.

And, this is what we will be testing now

2. Use "DrupalWebTestCase"

A module can have one or more test cases, they can in single file or in many other files

All test files should have am extention as .test and should be named as MODULENAME.test

Create your new test case simple_test/tests/simple_test.test file.

All functional tests in Drupal should extend the DrupalWebTestCase class which will provide the utility functions used to drive the test browser, helper functions for interacting with a Drupal application, and all the assertions we will use to perform our actual tests.

Add the below code to your simple_test.test.

  <?php  class SimpleTest extends DrupalWebTestCase {  }

Add a getInfo() method to your SimpleTest class. This method returns an array that provides meta-data about our test that the SimpleTest module can use when displaying our test in the UI. This method is required in order for your test to work. This getInfo() method looks like shown below.

  public static function getInfo() {    return array(      'name' => 'Simple Test',      'description' => 'Tests for the Simple Test module.',      'group' => 'Simple Test Group',    );  }

Now add a setUp() method to SimpleTest. This method is called when the system is preparing the environment for running our tests. In this case, we need to ensure that our module is enable during setup so that the page we want to test is available. We can do this by calling the parent classes's setUp() method and passing it an array of modules we want enabled. This setUp() method looks like this

  public function setUp() {   parent::setUp(array('simple_test'));  }

Add a test*() method to our class. Each test case can have one or more methods whose names are prefixed with the string test. Each of these methods will be automatically called by the SimpleTest test runner, and should contain the various assertions required in order to demonstrate that this test is passing. This example will use the DrupalWebTestCase::drupalGet() method in order to tell the internal browser to navigate to the URL /helloworld. And then use the DrupalWebTestCase::assertText() method to verify that the string, "Hello World ...", exists somewhere in the HTML output of the page the internal browser is currently looking at.

public function test_your_simple_test() {  $this->drupalGet('simple_test');  $this->assertText('Welcome to Drupal. Its simple_test..!', 'The page content is present.');}

And last, we need to tell Drupal about our new test. Update your simple_test.info file and add the following line so that after clearing the cache the registry will contain a reference to our new SimpleTest class.

files[] = tests/helloworld.test


3. Run Test.

Clear the cache so Drupal locates our new test(s). Navigate to Configuration > Performance (admin/config/development/performance) in the Toolbar, and then clicking the "Clear all caches" button.

Navigate to Modules (admin/modules) in the Toolbar. Enable the Testing module in the Core section.

Navigate to Configuration > Testing (admin/config/development/testing).

Select the checkbox for the "SimpleTest" test to run all tests in this group, or alternately tip the drop down open and choose the individual test case you want to run.

Click the "Run tests" button.

A new page will open and display a progress bar while your tests run.

Once completed, you will be directed to a page with a table that shows the results of your tests.

28,000OFF
LG 139 cm (55 inches) 4K Ultra HD Smart LED TV 55UR7500PSC (Dark Iron Gray)

LG 139 cm (55 inches) 4K Ultra HD Smart LED TV 55UR7500PSC (Dark Iron Gray)

43,990 71,990
Screen Size 55 Inches
Brand LG
Display Technology LED
Resolution 4K
Refresh Rate 60 Hz
Special Feature WebOS 23 with User Profiles | Filmmaker Mode, HDR 10 & HLG | Game Optimizer, ALLM, HGIG Mode | Unlimited OTT Apps | AI Brightness Control, 4K Upscaling & AI Sound (Virtual Surround 5.1 up-mix)WebOS 23 with User Profiles | Filmmaker Mode, HDR 10 & HLG | Game Optimizer, ALLM, HGIG Mode | Unlimited OTT Apps | AI Brightness Control, 4K… See more
Included Components 1 UHD 4K TV, 1 Warranty Card, 1 Remote Control, 2 Batteries, ‎‎1 Table Top Stand, 1 User Manual
Connectivity Technology Bluetooth, Wi-Fi, USB, HDMI
Aspect Ratio 16:9
Product Dimensions 23D x 123.5W x 78H Centimeters

Customers appreciate the TV's value for money and sound quality. They find the picture quality good, with realistic colors and AI-powered audio. However, some report issues with lags while using apps and loading videos. The remote control is not user-friendly and lacks bass. Opinions differ on installation ease and functionality.

Movies & TV
19,910OFF
Samsung 138 cm (55 inches) D Series Crystal 4K Vivid Ultra HD Smart LED TV UA55DUE70BKLXL (Black)

Samsung 138 cm (55 inches) D Series Crystal 4K Vivid Ultra HD Smart LED TV UA55DUE70BKLXL (Black)

44,990 64,900
Screen Size 55 Inches
Brand Samsung
Display Technology UHD
Resolution 4K
Refresh Rate 50 Hz
Special Feature Crystal Processor 4K | 4K Upscaling | UHD Dimming | Motion Xcelerator
Included Components 1 Unit TV, 1 Remote Control, 1 User Manual, 1 Power Cable
Connectivity Technology Wi-Fi, USB, Ethernet, HDMI
Aspect Ratio 16:9
Product Dimensions 6D x 123.4W x 71.1H Centimeters

Customers say: The TV has good quality, good picture quality, and is a good value for the price. However, some customers have reported issues with it not working, display issues, and mixed opinions on performance, sound quality, and color accuracy.

Movies & TV
16,500OFF
Mi 108 cm (43 inches) X Series 4K Ultra HD Smart Google TV L43M8-A2IN (Black)

Mi 108 cm (43 inches) X Series 4K Ultra HD Smart Google TV L43M8-A2IN (Black)

26,499 42,999
Screen Size 43 Inches
Brand Mi
Display Technology LED
Resolution 4K
Refresh Rate 60 Hz
Special Feature 4K Dolby Vision | Hey Google | Google TV | HDR 10 | HLG | Wide Color Gamut | Supported Applications : PatchWall, Netflix, Amazon Prime Video, Disney+ Hotstar, Miracast, Media player, Gallery, TV Manager, User Manual, Live TV, YouTube, YouTube Music, Play Store4K Dolby Vision | Hey Google | Google TV | HDR 10 | HLG | Wide Color Gamut | Supported Applications : PatchWall, Netflix, Amazon Prime Video, Disney+… See more
Included Components 1 LED TV, 2 Table Stand Base along with screws, 1 User Manual, 1 Warranty Card, 1 Remote Control, 2 AAA Battery1 LED TV, 2 Table Stand Base along with screws, 1 User Manual, 1 Warranty Card, 1 Remote Control, 2 AAA Battery
Connectivity Technology Wi-Fi, USB, Ethernet
Product Dimensions 24.1D x 95.7W x 61.2H Centimeters
Supported Internet Services Netflix, Amazon Prime Video, PatchWall, Miracast, Disney+ Hotstar

The television has good quality, good picture quality, and a good balance of picture and sound quality. Customers find it a good value for money. However, some have reported issues with the remote not working or the display switching on and off. There are also complaints about poor connectivity options and WiFi connectivity issues.

Movies & TV

Related Articles

90,000OFF
OnePlus 163 cm (65 inches) Q Series 4K Ultra HD QLED Smart Google TV 65 Q2 Pro (Black)

OnePlus 163 cm (65 inches) Q Series 4K Ultra HD QLED Smart Google TV 65 Q2 Pro (Black)

69,999 1,59,999
Screen Size 65 Inches
Brand OnePlus
Display Technology QLED
Resolution 4K
Refresh Rate 120 Hz
Special Feature QLED TV | Speak Now™ Hands-free voice control | Remote With Voice Assistant | Google TV | HDR 10+|Dolby Vision | DCI-P3 97% Wide Color Gamut | Supported Applications : Netflix, Disney+Hotstar, YoutubeQLED TV | Speak Now™ Hands-free voice control | Remote With Voice Assistant | Google TV | HDR 10+|Dolby Vision | DCI-P3 97%
Included Components 1 LED TV, 2 Table Stand Base, 1 User Manual, 1 Warranty Card, 1 Remote Control,1 AV IN Adapter, 1AC Cord, 2 AAA Battery1 LED TV, 2 Table Stand Base, 1 User Manual, 1 Warranty Card, 1 Remote Control,1 AV IN Adapter, 1AC Cord, 2 AAA Battery
Connectivity Technology Wi-Fi, USB, Ethernet, HDMI
Aspect Ratio 1.78:1
Product Dimensions 9.2D x 145W x 88.2H Centimeters

Customers appreciate the TV's sound quality and quality. They find it easy to install and like the vivid colors. However, opinions differ on picture quality, value for money, and responsiveness.

Movies & TV

Recent Articles

Recent Quick Read

Recent Great People

19,000OFF
Redmi 108 cm (43 inches) F Series 4K Ultra HD Smart LED Fire TV L43R8-FVIN (Black)

Redmi 108 cm (43 inches) F Series 4K Ultra HD Smart LED Fire TV L43R8-FVIN (Black)

23,999 42,999
Screen Size 43 Inches
Brand Redmi
Display Technology LED
Resolution 4K
Refresh Rate 60 Hz
Special Feature Fire TV Built-In | Redmi Voice Remote with Alexa | Prime Video, Netflix, Disney+ Hotstar, YouTube, Jio Cinema, Sony LIV and 12000+ apps from Fire TV Appstore | Set-top-box Live TV Integration to switch between DTH TV channels and OTT apps seamlessly by just asking Alexa | Picture-in-Picture mode | Display Mirroring – Apple Airplay 2 & Miracast | Smart Home Dashboard | 2GB RAM + 8GB Storage | Metal Bezel-less DesignFire TV Built-In | Redmi Voice Remote with Alexa | Prime Video, Netflix, Disney+ Hotstar, YouTube, Jio Cinema, Sony LIV and 12000+ apps from Fire TV Appstore | Set-top-box… See more
Included Components 1 LED TV, 1 Remote Control, 1 Manual, 2 Stands Unit, 4 Screws, 2 x AAA batteries
Connectivity Technology Wi-Fi, USB, Ethernet, HDMI
Aspect Ratio 16:9
Product Dimensions 24.1D x 95.7W x 60.7H Centimeters

The screen is really good, however viewing angles are not so good. Speakers are decent and I didn't feel any need for external speakers. Remote is amazing, I love the alexa support. Fire TV OS is also faster than android and I prefer it however it mainly shows amazon apps suggestions which I don't like much. One thing that could be improved is the 8GB storage out of which we only get 1-2GB free.

For my preferences this TV stood out and has delivered pretty good as well. For me it a value for money deal and I'm happy with the purchase so far. Let's see how long it lasts as the ultimate test for it would be of durability. If it lasts next 7-8 years it would be a complete paisa vasool product for me.

Home Appliances
8,000OFF
LG 80 cm (32 inches) HD Ready Smart LED TV 32LM563BPTC (Dark Iron Gray)

LG 80 cm (32 inches) HD Ready Smart LED TV 32LM563BPTC (Dark Iron Gray)

13,990 21,990
Screen Size 32 Inches
Brand LG
Display Technology LED
Resolution 720p
Refresh Rate 60 Hz
Special Feature Flat
Included Components 1 LED TV, 1 Table Top Stand, 1 User Manual, 1 Warranty Card, 1 Remote Control, 2 AAA Batteries
Connectivity Technology Wi-Fi
Aspect Ratio 16:9
Product Dimensions 3.3D x 20.1W x 17.4H Centimeters
  • Resolution: HD Ready (1366x768) | Refresh Rate: 60 hertz
  • Connectivity: 2 HDMI ports to connect set top box, Blu Ray players, gaming console | 1 USB ports to connect hard drives and other USB devices
  • Sound output: 10 Watts Output I 2 Speakers | DTS Virtual:X | Sound Type : Down FiringSmart
  • TV Features: Web OS Smart TV | Wi-Fi | Home Dashboard | Screen Mirroring | Mini TV Browser | Multi-Tasking | Office 365, Set WXHXD (with Stand ) mm - 739 x 472 x 168Display: Active HDR | Display Type: Flat | BackLight Module: Slim LED
Movies & TV
5,000OFF
OPPO F27 Pro+ 5G (Midnight Navy, 8GB RAM, 256GB Storage) | 6.7

OPPO F27 Pro+ 5G (Midnight Navy, 8GB RAM, 256GB Storage) | 6.7" FHD+ AMOLED Toughest 3D Curved Display|64MP AI Featured Camera|IP69 | 67W SUPERVOOC| with No Cost EMI/Additional Exchange Offers

29,999 34,999
  • DISPLAY : 17.02cm (6.7"Inch) AMOLED 3D Curved Display with Screen-to-body ratio: 93% .FHD+ Resolution with 2412×1080 Pixels , with 1Billion Colours and 120Hz Refresh Rate.
  • CAMERA : Dual Ultra-Clear Camera 64MP Main Camera + 2MP Portrait camera |8MP Front Selfie Camera| AI Portrait Retouching |AI Eraser|AI Smart Image Matting features
  • MEMORY STORAGE,SIM & PROCESSOR : 8 GB RAM|256 GB ROM | Dual 5G Sim Slot |Latest Android 14 Operating System and ColorOS 14.0 System Platform with MediaTek Dimensity 7050.
  • FAST CHARGING & BATTERY : 67W SuperVOOC charging enable full charging in 44Mins .It have 5000mAh durable long Battery .
  • TOUGHEST 3D CURVED SCREEN & PREMIUM DESIGN :All-Round Armor Impact Resistant Structure with Screen Protected by corning gorilla Glass Victus 2.Cosmos Ring design has been adopted to showcase a classic style of beauty featuring inclusiveness and orderliness. The elegant circular panel looks unique and eye-catching.Premium back leather design with stain resistance
Mobiles & Accessories
19,000OFF
Aspire Lite AMD Ryzen 3 5300U Premium Thin and Light Laptop (Windows 11 Home/8 GB RAM/512 GB SSD) AL15-41 with 39.62 cm (15.6

Aspire Lite AMD Ryzen 3 5300U Premium Thin and Light Laptop (Windows 11 Home/8 GB RAM/512 GB SSD) AL15-41 with 39.62 cm (15.6") Full HD Display, Metal Body, Steel Gray, 1.6 KG

28,990 47,990

About this item

  • Processor: AMD Ryzen 3 5300U Quad-Core Mobile Processor with AMD Radeon Graphics.Maximum Power Supply Wattage 65 W
  • Visibly Stunning: Experience sharp details and crisp colors on the 15.6" Full HD display, 16:9 aspect ratio, ultra-slim design and narrow bezels.
  • Internal Specifications: RAM - 8 GB of Dual-channel DDR4, 2 SODIMM sockets; Storage - 512 GB SSD NVMe solid-state drive storage (expandable up to 1TB) to store your files and media
  • Ports: 1 x USB 3.2 Gen 1 (Type A), 2 x USB 2.0 (Type A), 1 x USB 3.2 Gen 2 (Type C), 1 x DC-in jack
  • Keyboard: 100-/101-/104-key keyboard with independent numeric keypad, international language support
Mobiles & Accessories
We Need Your Consent
By clicking “Accept Cookies”, you agree to the storing of cookies on your device to enhance your site navigation experience.
I Accept Cookies